sequant 1.11.0 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/README.md +93 -7
  2. package/dist/bin/cli.js +12 -9
  3. package/dist/src/commands/doctor.js +25 -20
  4. package/dist/src/commands/init.js +152 -65
  5. package/dist/src/commands/logs.js +7 -6
  6. package/dist/src/commands/run.d.ts +13 -1
  7. package/dist/src/commands/run.js +75 -12
  8. package/dist/src/commands/stats.js +67 -48
  9. package/dist/src/commands/status.js +30 -12
  10. package/dist/src/index.d.ts +6 -0
  11. package/dist/src/index.js +4 -0
  12. package/dist/src/lib/ac-linter.d.ts +116 -0
  13. package/dist/src/lib/ac-linter.js +304 -0
  14. package/dist/src/lib/cli-ui.d.ts +196 -0
  15. package/dist/src/lib/cli-ui.js +544 -0
  16. package/dist/src/lib/content-analyzer.d.ts +89 -0
  17. package/dist/src/lib/content-analyzer.js +437 -0
  18. package/dist/src/lib/phase-signal.d.ts +94 -0
  19. package/dist/src/lib/phase-signal.js +171 -0
  20. package/dist/src/lib/plugin-version-sync.d.ts +26 -0
  21. package/dist/src/lib/plugin-version-sync.js +91 -0
  22. package/dist/src/lib/project-name.d.ts +40 -0
  23. package/dist/src/lib/project-name.js +191 -0
  24. package/dist/src/lib/semgrep.d.ts +136 -0
  25. package/dist/src/lib/semgrep.js +406 -0
  26. package/dist/src/lib/solve-comment-parser.d.ts +84 -0
  27. package/dist/src/lib/solve-comment-parser.js +200 -0
  28. package/dist/src/lib/stack-config.d.ts +51 -0
  29. package/dist/src/lib/stack-config.js +77 -0
  30. package/dist/src/lib/stacks.d.ts +66 -0
  31. package/dist/src/lib/stacks.js +332 -0
  32. package/dist/src/lib/templates.d.ts +2 -0
  33. package/dist/src/lib/templates.js +12 -3
  34. package/dist/src/lib/upstream/assessment.d.ts +70 -0
  35. package/dist/src/lib/upstream/assessment.js +385 -0
  36. package/dist/src/lib/upstream/index.d.ts +11 -0
  37. package/dist/src/lib/upstream/index.js +14 -0
  38. package/dist/src/lib/upstream/issues.d.ts +38 -0
  39. package/dist/src/lib/upstream/issues.js +267 -0
  40. package/dist/src/lib/upstream/relevance.d.ts +50 -0
  41. package/dist/src/lib/upstream/relevance.js +209 -0
  42. package/dist/src/lib/upstream/report.d.ts +29 -0
  43. package/dist/src/lib/upstream/report.js +391 -0
  44. package/dist/src/lib/upstream/types.d.ts +207 -0
  45. package/dist/src/lib/upstream/types.js +5 -0
  46. package/dist/src/lib/workflow/log-writer.d.ts +1 -1
  47. package/dist/src/lib/workflow/metrics-schema.d.ts +3 -3
  48. package/dist/src/lib/workflow/qa-cache.d.ts +199 -0
  49. package/dist/src/lib/workflow/qa-cache.js +440 -0
  50. package/dist/src/lib/workflow/run-log-schema.d.ts +34 -6
  51. package/dist/src/lib/workflow/run-log-schema.js +12 -1
  52. package/dist/src/lib/workflow/state-schema.d.ts +4 -4
  53. package/dist/src/lib/workflow/types.d.ts +4 -0
  54. package/package.json +6 -1
  55. package/templates/hooks/pre-tool.sh +6 -0
  56. package/templates/memory/constitution.md +1 -5
  57. package/templates/skills/_shared/references/prompt-templates.md +350 -0
  58. package/templates/skills/_shared/references/subagent-types.md +131 -0
  59. package/templates/skills/exec/SKILL.md +82 -0
  60. package/templates/skills/fullsolve/SKILL.md +19 -2
  61. package/templates/skills/loop/SKILL.md +3 -1
  62. package/templates/skills/qa/SKILL.md +79 -9
  63. package/templates/skills/qa/references/quality-gates.md +85 -1
  64. package/templates/skills/qa/references/semgrep-rules.md +207 -0
  65. package/templates/skills/qa/scripts/quality-checks.sh +525 -15
  66. package/templates/skills/spec/SKILL.md +322 -9
@@ -33,9 +33,9 @@ export type Phase = z.infer<typeof PhaseSchema>;
33
33
  * Phase execution status
34
34
  */
35
35
  export declare const PhaseStatusSchema: z.ZodEnum<{
36
- skipped: "skipped";
37
36
  success: "success";
38
37
  failure: "failure";
38
+ skipped: "skipped";
39
39
  timeout: "timeout";
40
40
  }>;
41
41
  export type PhaseStatus = z.infer<typeof PhaseStatusSchema>;
@@ -48,6 +48,16 @@ export declare const IssueStatusSchema: z.ZodEnum<{
48
48
  partial: "partial";
49
49
  }>;
50
50
  export type IssueStatus = z.infer<typeof IssueStatusSchema>;
51
+ /**
52
+ * Valid QA verdicts schema
53
+ */
54
+ export declare const QaVerdictSchema: z.ZodEnum<{
55
+ READY_FOR_MERGE: "READY_FOR_MERGE";
56
+ AC_MET_BUT_NOT_A_PLUS: "AC_MET_BUT_NOT_A_PLUS";
57
+ AC_NOT_MET: "AC_NOT_MET";
58
+ NEEDS_VERIFICATION: "NEEDS_VERIFICATION";
59
+ }>;
60
+ export type QaVerdict = z.infer<typeof QaVerdictSchema>;
51
61
  /**
52
62
  * Log entry for a single phase execution
53
63
  */
@@ -66,9 +76,9 @@ export declare const PhaseLogSchema: z.ZodObject<{
66
76
  endTime: z.ZodString;
67
77
  durationSeconds: z.ZodNumber;
68
78
  status: z.ZodEnum<{
69
- skipped: "skipped";
70
79
  success: "success";
71
80
  failure: "failure";
81
+ skipped: "skipped";
72
82
  timeout: "timeout";
73
83
  }>;
74
84
  error: z.ZodOptional<z.ZodString>;
@@ -76,6 +86,12 @@ export declare const PhaseLogSchema: z.ZodObject<{
76
86
  filesModified: z.ZodOptional<z.ZodArray<z.ZodString>>;
77
87
  testsRun: z.ZodOptional<z.ZodNumber>;
78
88
  testsPassed: z.ZodOptional<z.ZodNumber>;
89
+ verdict: z.ZodOptional<z.ZodEnum<{
90
+ READY_FOR_MERGE: "READY_FOR_MERGE";
91
+ AC_MET_BUT_NOT_A_PLUS: "AC_MET_BUT_NOT_A_PLUS";
92
+ AC_NOT_MET: "AC_NOT_MET";
93
+ NEEDS_VERIFICATION: "NEEDS_VERIFICATION";
94
+ }>>;
79
95
  }, z.core.$strip>;
80
96
  export type PhaseLog = z.infer<typeof PhaseLogSchema>;
81
97
  /**
@@ -105,9 +121,9 @@ export declare const IssueLogSchema: z.ZodObject<{
105
121
  endTime: z.ZodString;
106
122
  durationSeconds: z.ZodNumber;
107
123
  status: z.ZodEnum<{
108
- skipped: "skipped";
109
124
  success: "success";
110
125
  failure: "failure";
126
+ skipped: "skipped";
111
127
  timeout: "timeout";
112
128
  }>;
113
129
  error: z.ZodOptional<z.ZodString>;
@@ -115,6 +131,12 @@ export declare const IssueLogSchema: z.ZodObject<{
115
131
  filesModified: z.ZodOptional<z.ZodArray<z.ZodString>>;
116
132
  testsRun: z.ZodOptional<z.ZodNumber>;
117
133
  testsPassed: z.ZodOptional<z.ZodNumber>;
134
+ verdict: z.ZodOptional<z.ZodEnum<{
135
+ READY_FOR_MERGE: "READY_FOR_MERGE";
136
+ AC_MET_BUT_NOT_A_PLUS: "AC_MET_BUT_NOT_A_PLUS";
137
+ AC_NOT_MET: "AC_NOT_MET";
138
+ NEEDS_VERIFICATION: "NEEDS_VERIFICATION";
139
+ }>>;
118
140
  }, z.core.$strip>>;
119
141
  totalDurationSeconds: z.ZodNumber;
120
142
  }, z.core.$strip>;
@@ -195,9 +217,9 @@ export declare const RunLogSchema: z.ZodObject<{
195
217
  endTime: z.ZodString;
196
218
  durationSeconds: z.ZodNumber;
197
219
  status: z.ZodEnum<{
198
- skipped: "skipped";
199
220
  success: "success";
200
221
  failure: "failure";
222
+ skipped: "skipped";
201
223
  timeout: "timeout";
202
224
  }>;
203
225
  error: z.ZodOptional<z.ZodString>;
@@ -205,6 +227,12 @@ export declare const RunLogSchema: z.ZodObject<{
205
227
  filesModified: z.ZodOptional<z.ZodArray<z.ZodString>>;
206
228
  testsRun: z.ZodOptional<z.ZodNumber>;
207
229
  testsPassed: z.ZodOptional<z.ZodNumber>;
230
+ verdict: z.ZodOptional<z.ZodEnum<{
231
+ READY_FOR_MERGE: "READY_FOR_MERGE";
232
+ AC_MET_BUT_NOT_A_PLUS: "AC_MET_BUT_NOT_A_PLUS";
233
+ AC_NOT_MET: "AC_NOT_MET";
234
+ NEEDS_VERIFICATION: "NEEDS_VERIFICATION";
235
+ }>>;
208
236
  }, z.core.$strip>>;
209
237
  totalDurationSeconds: z.ZodNumber;
210
238
  }, z.core.$strip>>;
@@ -253,10 +281,10 @@ export declare function createPhaseLog(phase: Phase, issueNumber: number): Omit<
253
281
  *
254
282
  * @param phaseLog - Partial phase log
255
283
  * @param status - Final status
256
- * @param options - Additional fields (error, filesModified, etc.)
284
+ * @param options - Additional fields (error, filesModified, verdict, etc.)
257
285
  * @returns Complete PhaseLog
258
286
  */
259
- export declare function completePhaseLog(phaseLog: Omit<PhaseLog, "endTime" | "durationSeconds" | "status">, status: PhaseStatus, options?: Partial<Pick<PhaseLog, "error" | "iterations" | "filesModified" | "testsRun" | "testsPassed">>): PhaseLog;
287
+ export declare function completePhaseLog(phaseLog: Omit<PhaseLog, "endTime" | "durationSeconds" | "status">, status: PhaseStatus, options?: Partial<Pick<PhaseLog, "error" | "iterations" | "filesModified" | "testsRun" | "testsPassed" | "verdict">>): PhaseLog;
260
288
  /**
261
289
  * Finalize a run log with summary statistics
262
290
  *
@@ -42,6 +42,15 @@ export const PhaseStatusSchema = z.enum([
42
42
  * Issue execution status
43
43
  */
44
44
  export const IssueStatusSchema = z.enum(["success", "failure", "partial"]);
45
+ /**
46
+ * Valid QA verdicts schema
47
+ */
48
+ export const QaVerdictSchema = z.enum([
49
+ "READY_FOR_MERGE",
50
+ "AC_MET_BUT_NOT_A_PLUS",
51
+ "AC_NOT_MET",
52
+ "NEEDS_VERIFICATION",
53
+ ]);
45
54
  /**
46
55
  * Log entry for a single phase execution
47
56
  */
@@ -68,6 +77,8 @@ export const PhaseLogSchema = z.object({
68
77
  testsRun: z.number().int().nonnegative().optional(),
69
78
  /** Number of tests passed */
70
79
  testsPassed: z.number().int().nonnegative().optional(),
80
+ /** Parsed QA verdict (only for qa phase) */
81
+ verdict: QaVerdictSchema.optional(),
71
82
  });
72
83
  /**
73
84
  * Complete execution record for a single issue
@@ -195,7 +206,7 @@ export function createPhaseLog(phase, issueNumber) {
195
206
  *
196
207
  * @param phaseLog - Partial phase log
197
208
  * @param status - Final status
198
- * @param options - Additional fields (error, filesModified, etc.)
209
+ * @param options - Additional fields (error, filesModified, verdict, etc.)
199
210
  * @returns Complete PhaseLog
200
211
  */
201
212
  export function completePhaseLog(phaseLog, status, options) {
@@ -25,9 +25,9 @@ export declare const WORKFLOW_PHASES: readonly ["spec", "security-review", "exec
25
25
  * Phase status - tracks individual phase progress
26
26
  */
27
27
  export declare const PhaseStatusSchema: z.ZodEnum<{
28
+ pending: "pending";
28
29
  skipped: "skipped";
29
30
  completed: "completed";
30
- pending: "pending";
31
31
  in_progress: "in_progress";
32
32
  failed: "failed";
33
33
  }>;
@@ -65,9 +65,9 @@ export type Phase = z.infer<typeof PhaseSchema>;
65
65
  */
66
66
  export declare const PhaseStateSchema: z.ZodObject<{
67
67
  status: z.ZodEnum<{
68
+ pending: "pending";
68
69
  skipped: "skipped";
69
70
  completed: "completed";
70
- pending: "pending";
71
71
  in_progress: "in_progress";
72
72
  failed: "failed";
73
73
  }>;
@@ -198,9 +198,9 @@ export declare const IssueStateSchema: z.ZodObject<{
198
198
  }>>;
199
199
  phases: z.ZodRecord<z.ZodString, z.ZodObject<{
200
200
  status: z.ZodEnum<{
201
+ pending: "pending";
201
202
  skipped: "skipped";
202
203
  completed: "completed";
203
- pending: "pending";
204
204
  in_progress: "in_progress";
205
205
  failed: "failed";
206
206
  }>;
@@ -286,9 +286,9 @@ export declare const WorkflowStateSchema: z.ZodObject<{
286
286
  }>>;
287
287
  phases: z.ZodRecord<z.ZodString, z.ZodObject<{
288
288
  status: z.ZodEnum<{
289
+ pending: "pending";
289
290
  skipped: "skipped";
290
291
  completed: "completed";
291
- pending: "pending";
292
292
  in_progress: "in_progress";
293
293
  failed: "failed";
294
294
  }>;
@@ -40,6 +40,8 @@ export interface ExecutionConfig {
40
40
  * Default execution configuration
41
41
  */
42
42
  export declare const DEFAULT_CONFIG: ExecutionConfig;
43
+ import type { QaVerdict } from "./run-log-schema.js";
44
+ export type { QaVerdict } from "./run-log-schema.js";
43
45
  /**
44
46
  * Result of executing a single phase
45
47
  */
@@ -50,6 +52,8 @@ export interface PhaseResult {
50
52
  error?: string;
51
53
  /** Captured output from the phase (used for parsing spec recommendations) */
52
54
  output?: string;
55
+ /** Parsed QA verdict (only for qa phase) */
56
+ verdict?: QaVerdict;
53
57
  }
54
58
  /**
55
59
  * Result of executing all phases for an issue
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sequant",
3
- "version": "1.11.0",
3
+ "version": "1.13.0",
4
4
  "description": "Quantize your development workflow - Sequential AI phases with quality gates",
5
5
  "type": "module",
6
6
  "bin": {
@@ -56,19 +56,24 @@
56
56
  "dependencies": {
57
57
  "@anthropic-ai/claude-agent-sdk": "^0.2.11",
58
58
  "@hono/node-server": "^1.19.9",
59
+ "boxen": "^8.0.1",
59
60
  "chalk": "^5.3.0",
60
61
  "chokidar": "^5.0.0",
62
+ "cli-table3": "^0.6.5",
61
63
  "commander": "^12.1.0",
62
64
  "diff": "^7.0.0",
65
+ "gradient-string": "^3.0.0",
63
66
  "hono": "^4.11.4",
64
67
  "inquirer": "^12.3.2",
65
68
  "open": "^11.0.0",
69
+ "ora": "^8.2.0",
66
70
  "yaml": "^2.7.0",
67
71
  "zod": "^4.3.5"
68
72
  },
69
73
  "devDependencies": {
70
74
  "@eslint/js": "^9.39.2",
71
75
  "@types/diff": "^7.0.0",
76
+ "@types/gradient-string": "^1.1.6",
72
77
  "@types/inquirer": "^9.0.7",
73
78
  "@types/node": "^22.10.5",
74
79
  "@typescript-eslint/eslint-plugin": "^8.52.0",
@@ -309,6 +309,12 @@ if [[ "$TOOL_NAME" == "Bash" ]] && echo "$TOOL_INPUT" | grep -qE 'git commit'; t
309
309
  {
310
310
  echo "HOOK_BLOCKED: Commit must follow conventional commits format"
311
311
  echo " Expected: type(scope): description"
312
+ # AC-1 & AC-2 (Issue #198): Detect merge commits and provide helpful suggestion
313
+ if [[ "$MSG" == Merge\ * ]]; then
314
+ echo ""
315
+ echo " 💡 For merge commits, use: chore: merge main into feature branch"
316
+ echo ""
317
+ fi
312
318
  echo " Types: feat|fix|docs|style|refactor|test|chore|ci|build|perf"
313
319
  echo " Got: $MSG"
314
320
  } | tee -a /tmp/claude-hook.log >&2
@@ -56,11 +56,7 @@ This document defines the core principles and patterns for AI-assisted developme
56
56
 
57
57
  ## Stack-Specific Notes
58
58
 
59
- ### Astro Projects
60
- - Astro projects may not have `test` or `lint` scripts configured by default
61
- - If tests are needed, consider adding Vitest (`npm install -D vitest`)
62
- - For linting, consider ESLint with the Astro plugin (`npm install -D eslint eslint-plugin-astro`)
63
- - Build output goes to `dist/` by default
59
+ {{STACK_NOTES}}
64
60
 
65
61
  ## Project-Specific Notes
66
62
 
@@ -0,0 +1,350 @@
1
+ # Sub-Agent Prompt Templates
2
+
3
+ Reference for task-specific prompt templates when spawning sub-agents via the `Task` tool during parallel execution.
4
+
5
+ ## Overview
6
+
7
+ When spawning sub-agents for implementation tasks, use these templates to provide structured, task-specific guidance. Templates include:
8
+ - Task-specific requirements and constraints
9
+ - Best practices for that task type
10
+ - Expected deliverables and reporting format
11
+
12
+ ## Template Selection
13
+
14
+ ### Automatic Selection (Keywords)
15
+
16
+ The template is selected based on keywords in the task description:
17
+
18
+ | Keywords | Template |
19
+ |----------|----------|
20
+ | `component`, `Component`, `React` | [Component Template](#component-template) |
21
+ | `type`, `interface`, `types/` | [Type Definition Template](#type-definition-template) |
22
+ | `CLI`, `command`, `script`, `bin/` | [CLI/Script Template](#cliscript-template) |
23
+ | `test`, `spec`, `.test.` | [Test Template](#test-template) |
24
+ | `refactor`, `restructure`, `migrate` | [Refactor Template](#refactor-template) |
25
+ | (none matched) | [Generic Template](#generic-template) |
26
+
27
+ ### Explicit Annotation Override
28
+
29
+ You can force a specific template using the `[template: X]` annotation at the start of the task:
30
+
31
+ ```
32
+ [template: component] Create UserCard in components/admin/
33
+ [template: cli] Add export command to scripts/
34
+ [template: type] Define MetricEvent interface
35
+ ```
36
+
37
+ **Annotation takes precedence** over keyword detection.
38
+
39
+ ---
40
+
41
+ ## Task Templates
42
+
43
+ ### Component Template
44
+
45
+ **Use for:** React components, UI elements, admin panels
46
+
47
+ ```markdown
48
+ ## Task: Create React Component
49
+
50
+ **Component:** [name]
51
+ **Location:** [path]
52
+
53
+ **Requirements:**
54
+ - [ ] TypeScript with proper prop types (interface or type)
55
+ - [ ] Follow existing component patterns in the codebase
56
+ - [ ] Include displayName for debugging: `Component.displayName = 'ComponentName'`
57
+ - [ ] No inline styles - use existing CSS/Tailwind patterns
58
+ - [ ] Export component as named export
59
+
60
+ **Best Practices:**
61
+ - Check `components/` for similar components to follow patterns
62
+ - Use existing hooks from `lib/hooks/` if applicable
63
+ - Prefer composition over prop drilling
64
+ - Keep components focused - single responsibility
65
+
66
+ **Constraints:**
67
+ - Working directory: [worktree path]
68
+ - Do NOT create test files (handled separately)
69
+ - Do NOT add new dependencies without explicit approval
70
+
71
+ **Deliverable:**
72
+ Report: files created, component name, props interface
73
+ ```
74
+
75
+ ---
76
+
77
+ ### Type Definition Template
78
+
79
+ **Use for:** TypeScript types, interfaces, enums, type utilities
80
+
81
+ ```markdown
82
+ ## Task: Create Type Definitions
83
+
84
+ **File:** [path]
85
+ **Types needed:** [list]
86
+
87
+ **Requirements:**
88
+ - [ ] Export all types (no internal-only types)
89
+ - [ ] Use strict types - avoid `any`, prefer `unknown` if needed
90
+ - [ ] Add JSDoc comments for complex types explaining purpose
91
+ - [ ] Match database schema if types represent DB entities
92
+ - [ ] Use consistent naming: `PascalCase` for types/interfaces
93
+
94
+ **Best Practices:**
95
+ - Check `types/` for existing type patterns
96
+ - Prefer interfaces for object shapes (extendable)
97
+ - Use type aliases for unions, intersections, utilities
98
+ - Export from index file if creating new type module
99
+
100
+ **Constraints:**
101
+ - Working directory: [worktree path]
102
+ - Verify types compile: `npx tsc --noEmit [file]`
103
+
104
+ **Deliverable:**
105
+ Report: types created, file path, any dependencies on other types
106
+ ```
107
+
108
+ ---
109
+
110
+ ### CLI/Script Template
111
+
112
+ **Use for:** CLI commands, scripts, automation tools
113
+
114
+ ```markdown
115
+ ## Task: Implement CLI Command/Script
116
+
117
+ **Command:** [name]
118
+ **File:** [path]
119
+
120
+ **Requirements:**
121
+ - [ ] Use commander.js patterns from existing commands (if CLI)
122
+ - [ ] Include descriptive --help text
123
+ - [ ] Handle errors gracefully with appropriate exit codes
124
+ - [ ] Add to command index if this is a new CLI command
125
+ - [ ] Support both programmatic and CLI usage if applicable
126
+
127
+ **Best Practices:**
128
+ - Check `scripts/` or `src/cli/` for existing patterns
129
+ - Use `process.exit(0)` for success, `process.exit(1)` for errors
130
+ - Log errors to stderr: `console.error()`
131
+ - Provide progress feedback for long-running operations
132
+
133
+ **Constraints:**
134
+ - Working directory: [worktree path]
135
+ - Scripts should be executable: `chmod +x [file]`
136
+ - Add shebang for shell scripts: `#!/usr/bin/env bash` or `#!/usr/bin/env node`
137
+
138
+ **Deliverable:**
139
+ Report: script created, command usage, exit codes
140
+ ```
141
+
142
+ ---
143
+
144
+ ### Test Template
145
+
146
+ **Use for:** Unit tests, integration tests, test utilities
147
+
148
+ ```markdown
149
+ ## Task: Create Tests
150
+
151
+ **Test file:** [path]
152
+ **Testing:** [component/module being tested]
153
+
154
+ **Requirements:**
155
+ - [ ] Use existing test framework patterns (vitest/jest)
156
+ - [ ] Include setup and teardown if needed
157
+ - [ ] Test both success and error cases
158
+ - [ ] Use descriptive test names: `it('should X when Y')`
159
+ - [ ] Mock external dependencies appropriately
160
+
161
+ **Best Practices:**
162
+ - Check `__tests__/` or `*.test.ts` files for patterns
163
+ - Group related tests with `describe()` blocks
164
+ - Test behavior, not implementation details
165
+ - Aim for meaningful coverage, not 100% line coverage
166
+
167
+ **Constraints:**
168
+ - Working directory: [worktree path]
169
+ - Run tests after creation: `npm test [file]`
170
+ - Do NOT skip or disable existing tests
171
+
172
+ **Deliverable:**
173
+ Report: test file created, number of test cases, pass/fail status
174
+ ```
175
+
176
+ ---
177
+
178
+ ### Refactor Template
179
+
180
+ **Use for:** Code restructuring, file reorganization, pattern migrations
181
+
182
+ ```markdown
183
+ ## Task: Refactor Code
184
+
185
+ **Target:** [file or module]
186
+ **Goal:** [what the refactor achieves]
187
+
188
+ **Requirements:**
189
+ - [ ] Preserve all existing functionality (no behavior changes)
190
+ - [ ] Maintain or improve type safety
191
+ - [ ] Update all imports/exports affected by moves
192
+ - [ ] Ensure tests still pass after refactor
193
+
194
+ **Best Practices:**
195
+ - Make incremental changes, verify after each step
196
+ - Use IDE rename features when available
197
+ - Update barrel exports (index.ts) if file locations change
198
+ - Check for circular dependencies after restructuring
199
+
200
+ **Constraints:**
201
+ - Working directory: [worktree path]
202
+ - Run full test suite after refactor: `npm test`
203
+ - Run type check: `npx tsc --noEmit`
204
+
205
+ **Deliverable:**
206
+ Report: files changed, imports updated, test results
207
+ ```
208
+
209
+ ---
210
+
211
+ ### Generic Template
212
+
213
+ **Use for:** Tasks that don't fit other categories
214
+
215
+ ```markdown
216
+ ## Task: [Task Description]
217
+
218
+ **Goal:** [what needs to be accomplished]
219
+ **Files involved:** [expected files]
220
+
221
+ **Requirements:**
222
+ - [ ] Complete the task as specified
223
+ - [ ] Follow existing codebase patterns
224
+ - [ ] Maintain type safety
225
+ - [ ] Do not break existing functionality
226
+
227
+ **Constraints:**
228
+ - Working directory: [worktree path]
229
+ - Run relevant checks after completion
230
+
231
+ **Deliverable:**
232
+ Report: files created/modified, summary of changes
233
+ ```
234
+
235
+ ---
236
+
237
+ ## Error Recovery Template
238
+
239
+ **Use for:** Retrying failed tasks with enhanced context
240
+
241
+ When a task fails, use this template to provide diagnostic context for the retry:
242
+
243
+ ```markdown
244
+ ## RETRY: Previous Attempt Failed
245
+
246
+ **Original Task:** [task description]
247
+ **Attempt:** [N] of [max]
248
+ **Previous Error:**
249
+ ```
250
+ [error message from TaskOutput]
251
+ ```
252
+
253
+ **Diagnosis Checklist:**
254
+ - [ ] Check imports are correct and files exist
255
+ - [ ] Verify file paths use the worktree directory
256
+ - [ ] Confirm types match expected signatures
257
+ - [ ] Look for typos in identifiers
258
+ - [ ] Check for missing dependencies
259
+
260
+ **Fix Strategy:**
261
+ 1. Read the failing file to understand current state
262
+ 2. Identify the specific error location (line number if available)
263
+ 3. Apply minimal, targeted fix
264
+ 4. Verify fix compiles: `npx tsc --noEmit [file]`
265
+
266
+ **Critical Constraints (re-emphasized):**
267
+ - You MUST use the worktree path: [worktree path]
268
+ - Do NOT edit files outside the worktree
269
+ - Complete the task with fewer tool calls than previous attempt
270
+ - If the same error occurs, report it clearly rather than retrying
271
+
272
+ **Deliverable:**
273
+ Report: fix applied, verification result, files changed
274
+ ```
275
+
276
+ ---
277
+
278
+ ## Template Customization
279
+
280
+ ### Adding New Templates
281
+
282
+ To add a custom template:
283
+
284
+ 1. Define the template in this file following the structure above
285
+ 2. Add keywords for automatic selection to the keyword table
286
+ 3. Document the use case and best practices
287
+
288
+ ### Overriding Templates
289
+
290
+ Projects can override templates by:
291
+
292
+ 1. Creating `.claude/skills/_shared/references/prompt-templates.local.md`
293
+ 2. Defining custom templates with the same headers
294
+ 3. Local templates take precedence over defaults
295
+
296
+ ### Template Variables
297
+
298
+ Templates support these placeholders:
299
+
300
+ | Variable | Description |
301
+ |----------|-------------|
302
+ | `[name]` | Component/module name from task |
303
+ | `[path]` | File path from task |
304
+ | `[worktree path]` | Current worktree directory |
305
+ | `[task description]` | Original task text |
306
+
307
+ ---
308
+
309
+ ## Usage Example
310
+
311
+ **Task:** "Create MetricsCard component in components/admin/metrics/"
312
+
313
+ **Keyword detected:** "component" → Component Template
314
+
315
+ **Rendered prompt:**
316
+ ```markdown
317
+ ## Task: Create React Component
318
+
319
+ **Component:** MetricsCard
320
+ **Location:** components/admin/metrics/MetricsCard.tsx
321
+
322
+ **Requirements:**
323
+ - [ ] TypeScript with proper prop types (interface or type)
324
+ - [ ] Follow existing component patterns in the codebase
325
+ - [ ] Include displayName for debugging: `MetricsCard.displayName = 'MetricsCard'`
326
+ - [ ] No inline styles - use existing CSS/Tailwind patterns
327
+ - [ ] Export component as named export
328
+
329
+ **Best Practices:**
330
+ - Check `components/` for similar components to follow patterns
331
+ - Use existing hooks from `lib/hooks/` if applicable
332
+ - Prefer composition over prop drilling
333
+ - Keep components focused - single responsibility
334
+
335
+ **Constraints:**
336
+ - Working directory: /path/to/worktrees/feature/123-metrics/
337
+ - Do NOT create test files (handled separately)
338
+ - Do NOT add new dependencies without explicit approval
339
+
340
+ **Deliverable:**
341
+ Report: files created, component name, props interface
342
+ ```
343
+
344
+ ---
345
+
346
+ ## References
347
+
348
+ - [Subagent Types](./subagent-types.md) - Valid subagent types for Task tool
349
+ - `/exec` skill - Parallel execution documentation
350
+ - `/spec` skill - Parallel groups format