(ctx: TemplateContext, args?: string[])
| 21 | const QUERY_SAFE_RE = /^[A-Za-z0-9 _-]+$/; |
| 22 | |
| 23 | export function generateLearningsSearch(ctx: TemplateContext, args?: string[]): string { |
| 24 | // Parse query= arg. Empty value falls through to no-query (principle of least surprise: |
| 25 | // a stray {{LEARNINGS_SEARCH:query=}} placeholder gets today's behavior, not a build error). |
| 26 | const queryArg = (args || []) |
| 27 | .filter(a => a.startsWith('query=')) |
| 28 | .map(a => a.slice(6)) |
| 29 | .filter(Boolean)[0]; |
| 30 | if (queryArg && !QUERY_SAFE_RE.test(queryArg)) { |
| 31 | throw new Error( |
| 32 | `{{LEARNINGS_SEARCH:query=...}} value must match ${QUERY_SAFE_RE} (alphanumeric, space, hyphen, underscore). Got: ${JSON.stringify(queryArg)}` |
| 33 | ); |
| 34 | } |
| 35 | const queryFlag = queryArg ? ` --query "${queryArg}"` : ''; |
| 36 | |
| 37 | if (ctx.host === 'codex') { |
| 38 | // Codex: simpler version, no cross-project, uses $GSTACK_BIN |
| 39 | return `## Prior Learnings |
| 40 | |
| 41 | Search for relevant learnings from previous sessions on this project: |
| 42 | |
| 43 | \`\`\`bash |
| 44 | $GSTACK_BIN/gstack-learnings-search --limit 10${queryFlag} 2>/dev/null || true |
| 45 | \`\`\` |
| 46 | |
| 47 | If learnings are found, incorporate them into your analysis. When a review finding |
| 48 | matches a past learning, note it: "Prior learning applied: [key] (confidence N, from [date])"`; |
| 49 | } |
| 50 | |
| 51 | return `## Prior Learnings |
| 52 | |
| 53 | Search for relevant learnings from previous sessions: |
| 54 | |
| 55 | \`\`\`bash |
| 56 | _CROSS_PROJ=$(${ctx.paths.binDir}/gstack-config get cross_project_learnings 2>/dev/null || echo "unset") |
| 57 | echo "CROSS_PROJECT: $_CROSS_PROJ" |
| 58 | if [ "$_CROSS_PROJ" = "true" ]; then |
| 59 | ${ctx.paths.binDir}/gstack-learnings-search --limit 10${queryFlag} --cross-project 2>/dev/null || true |
| 60 | else |
| 61 | ${ctx.paths.binDir}/gstack-learnings-search --limit 10${queryFlag} 2>/dev/null || true |
| 62 | fi |
| 63 | \`\`\` |
| 64 | |
| 65 | If \`CROSS_PROJECT\` is \`unset\` (first time): Use AskUserQuestion: |
| 66 | |
| 67 | > gstack can search learnings from your other projects on this machine to find |
| 68 | > patterns that might apply here. This stays local (no data leaves your machine). |
| 69 | > Recommended for solo developers. Skip if you work on multiple client codebases |
| 70 | > where cross-contamination would be a concern. |
| 71 | |
| 72 | Options: |
| 73 | - A) Enable cross-project learnings (recommended) |
| 74 | - B) Keep learnings project-scoped only |
| 75 | |
| 76 | If A: run \`${ctx.paths.binDir}/gstack-config set cross_project_learnings true\` |
| 77 | If B: run \`${ctx.paths.binDir}/gstack-config set cross_project_learnings false\` |
| 78 | |
| 79 | Then re-run the search with the appropriate flag. |
| 80 |
no outgoing calls
no test coverage detected