code-as-plan 2.0.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 (188) hide show
  1. package/LICENSE +21 -0
  2. package/README.ja-JP.md +834 -0
  3. package/README.ko-KR.md +823 -0
  4. package/README.md +1006 -0
  5. package/README.pt-BR.md +452 -0
  6. package/README.zh-CN.md +800 -0
  7. package/agents/cap-brainstormer.md +154 -0
  8. package/agents/cap-debugger.md +221 -0
  9. package/agents/cap-prototyper.md +170 -0
  10. package/agents/cap-reviewer.md +230 -0
  11. package/agents/cap-tester.md +193 -0
  12. package/bin/install.js +5002 -0
  13. package/cap/bin/gsd-tools.cjs +1141 -0
  14. package/cap/bin/lib/arc-scanner.cjs +341 -0
  15. package/cap/bin/lib/cap-feature-map.cjs +506 -0
  16. package/cap/bin/lib/cap-session.cjs +191 -0
  17. package/cap/bin/lib/cap-stack-docs.cjs +598 -0
  18. package/cap/bin/lib/cap-tag-scanner.cjs +458 -0
  19. package/cap/bin/lib/commands.cjs +959 -0
  20. package/cap/bin/lib/config.cjs +466 -0
  21. package/cap/bin/lib/convention-reader.cjs +180 -0
  22. package/cap/bin/lib/core.cjs +1230 -0
  23. package/cap/bin/lib/feature-aggregator.cjs +422 -0
  24. package/cap/bin/lib/frontmatter.cjs +336 -0
  25. package/cap/bin/lib/init.cjs +1442 -0
  26. package/cap/bin/lib/manifest-generator.cjs +381 -0
  27. package/cap/bin/lib/milestone.cjs +252 -0
  28. package/cap/bin/lib/model-profiles.cjs +68 -0
  29. package/cap/bin/lib/monorepo-context.cjs +224 -0
  30. package/cap/bin/lib/monorepo-migrator.cjs +507 -0
  31. package/cap/bin/lib/phase.cjs +888 -0
  32. package/cap/bin/lib/profile-output.cjs +952 -0
  33. package/cap/bin/lib/profile-pipeline.cjs +539 -0
  34. package/cap/bin/lib/roadmap.cjs +329 -0
  35. package/cap/bin/lib/security.cjs +382 -0
  36. package/cap/bin/lib/session-manager.cjs +290 -0
  37. package/cap/bin/lib/skeleton-generator.cjs +177 -0
  38. package/cap/bin/lib/state.cjs +1031 -0
  39. package/cap/bin/lib/template.cjs +222 -0
  40. package/cap/bin/lib/test-detector.cjs +61 -0
  41. package/cap/bin/lib/uat.cjs +282 -0
  42. package/cap/bin/lib/verify.cjs +888 -0
  43. package/cap/bin/lib/workspace-detector.cjs +369 -0
  44. package/cap/bin/lib/workstream.cjs +491 -0
  45. package/cap/commands/gsd/workstreams.md +63 -0
  46. package/cap/references/arc-standard.md +315 -0
  47. package/cap/references/cap-agent-architecture.md +102 -0
  48. package/cap/references/cap-gitignore-template +9 -0
  49. package/cap/references/cap-zero-deps.md +158 -0
  50. package/cap/references/checkpoints.md +778 -0
  51. package/cap/references/continuation-format.md +249 -0
  52. package/cap/references/decimal-phase-calculation.md +64 -0
  53. package/cap/references/feature-map-template.md +25 -0
  54. package/cap/references/git-integration.md +295 -0
  55. package/cap/references/git-planning-commit.md +38 -0
  56. package/cap/references/model-profile-resolution.md +36 -0
  57. package/cap/references/model-profiles.md +139 -0
  58. package/cap/references/phase-argument-parsing.md +61 -0
  59. package/cap/references/planning-config.md +202 -0
  60. package/cap/references/questioning.md +162 -0
  61. package/cap/references/session-template.json +8 -0
  62. package/cap/references/tdd.md +263 -0
  63. package/cap/references/ui-brand.md +160 -0
  64. package/cap/references/user-profiling.md +681 -0
  65. package/cap/references/verification-patterns.md +612 -0
  66. package/cap/references/workstream-flag.md +58 -0
  67. package/cap/templates/DEBUG.md +164 -0
  68. package/cap/templates/UAT.md +265 -0
  69. package/cap/templates/UI-SPEC.md +100 -0
  70. package/cap/templates/VALIDATION.md +76 -0
  71. package/cap/templates/claude-md.md +122 -0
  72. package/cap/templates/codebase/architecture.md +255 -0
  73. package/cap/templates/codebase/concerns.md +310 -0
  74. package/cap/templates/codebase/conventions.md +307 -0
  75. package/cap/templates/codebase/integrations.md +280 -0
  76. package/cap/templates/codebase/stack.md +186 -0
  77. package/cap/templates/codebase/structure.md +285 -0
  78. package/cap/templates/codebase/testing.md +480 -0
  79. package/cap/templates/config.json +44 -0
  80. package/cap/templates/context.md +352 -0
  81. package/cap/templates/continue-here.md +78 -0
  82. package/cap/templates/copilot-instructions.md +7 -0
  83. package/cap/templates/debug-subagent-prompt.md +91 -0
  84. package/cap/templates/dev-preferences.md +21 -0
  85. package/cap/templates/discovery.md +146 -0
  86. package/cap/templates/discussion-log.md +63 -0
  87. package/cap/templates/milestone-archive.md +123 -0
  88. package/cap/templates/milestone.md +115 -0
  89. package/cap/templates/phase-prompt.md +610 -0
  90. package/cap/templates/planner-subagent-prompt.md +117 -0
  91. package/cap/templates/project.md +186 -0
  92. package/cap/templates/requirements.md +231 -0
  93. package/cap/templates/research-project/ARCHITECTURE.md +204 -0
  94. package/cap/templates/research-project/FEATURES.md +147 -0
  95. package/cap/templates/research-project/PITFALLS.md +200 -0
  96. package/cap/templates/research-project/STACK.md +120 -0
  97. package/cap/templates/research-project/SUMMARY.md +170 -0
  98. package/cap/templates/research.md +552 -0
  99. package/cap/templates/retrospective.md +54 -0
  100. package/cap/templates/roadmap.md +202 -0
  101. package/cap/templates/state.md +176 -0
  102. package/cap/templates/summary-complex.md +59 -0
  103. package/cap/templates/summary-minimal.md +41 -0
  104. package/cap/templates/summary-standard.md +48 -0
  105. package/cap/templates/summary.md +248 -0
  106. package/cap/templates/user-profile.md +146 -0
  107. package/cap/templates/user-setup.md +311 -0
  108. package/cap/templates/verification-report.md +322 -0
  109. package/cap/workflows/add-phase.md +112 -0
  110. package/cap/workflows/add-tests.md +351 -0
  111. package/cap/workflows/add-todo.md +158 -0
  112. package/cap/workflows/audit-milestone.md +340 -0
  113. package/cap/workflows/audit-uat.md +109 -0
  114. package/cap/workflows/autonomous.md +891 -0
  115. package/cap/workflows/check-todos.md +177 -0
  116. package/cap/workflows/cleanup.md +152 -0
  117. package/cap/workflows/complete-milestone.md +767 -0
  118. package/cap/workflows/diagnose-issues.md +231 -0
  119. package/cap/workflows/discovery-phase.md +289 -0
  120. package/cap/workflows/discuss-phase-assumptions.md +653 -0
  121. package/cap/workflows/discuss-phase.md +1049 -0
  122. package/cap/workflows/do.md +104 -0
  123. package/cap/workflows/execute-phase.md +846 -0
  124. package/cap/workflows/execute-plan.md +514 -0
  125. package/cap/workflows/fast.md +105 -0
  126. package/cap/workflows/forensics.md +265 -0
  127. package/cap/workflows/health.md +181 -0
  128. package/cap/workflows/help.md +660 -0
  129. package/cap/workflows/insert-phase.md +130 -0
  130. package/cap/workflows/list-phase-assumptions.md +178 -0
  131. package/cap/workflows/list-workspaces.md +56 -0
  132. package/cap/workflows/manager.md +362 -0
  133. package/cap/workflows/map-codebase.md +377 -0
  134. package/cap/workflows/milestone-summary.md +223 -0
  135. package/cap/workflows/new-milestone.md +486 -0
  136. package/cap/workflows/new-project.md +1250 -0
  137. package/cap/workflows/new-workspace.md +237 -0
  138. package/cap/workflows/next.md +97 -0
  139. package/cap/workflows/node-repair.md +92 -0
  140. package/cap/workflows/note.md +156 -0
  141. package/cap/workflows/pause-work.md +176 -0
  142. package/cap/workflows/plan-milestone-gaps.md +273 -0
  143. package/cap/workflows/plan-phase.md +859 -0
  144. package/cap/workflows/plant-seed.md +169 -0
  145. package/cap/workflows/pr-branch.md +129 -0
  146. package/cap/workflows/profile-user.md +450 -0
  147. package/cap/workflows/progress.md +507 -0
  148. package/cap/workflows/quick.md +757 -0
  149. package/cap/workflows/remove-phase.md +155 -0
  150. package/cap/workflows/remove-workspace.md +90 -0
  151. package/cap/workflows/research-phase.md +82 -0
  152. package/cap/workflows/resume-project.md +326 -0
  153. package/cap/workflows/review.md +228 -0
  154. package/cap/workflows/session-report.md +146 -0
  155. package/cap/workflows/settings.md +283 -0
  156. package/cap/workflows/ship.md +228 -0
  157. package/cap/workflows/stats.md +60 -0
  158. package/cap/workflows/transition.md +671 -0
  159. package/cap/workflows/ui-phase.md +302 -0
  160. package/cap/workflows/ui-review.md +165 -0
  161. package/cap/workflows/update.md +323 -0
  162. package/cap/workflows/validate-phase.md +174 -0
  163. package/cap/workflows/verify-phase.md +254 -0
  164. package/cap/workflows/verify-work.md +637 -0
  165. package/commands/cap/annotate.md +165 -0
  166. package/commands/cap/brainstorm.md +238 -0
  167. package/commands/cap/debug.md +297 -0
  168. package/commands/cap/init.md +262 -0
  169. package/commands/cap/iterate.md +234 -0
  170. package/commands/cap/prototype.md +281 -0
  171. package/commands/cap/refresh-docs.md +37 -0
  172. package/commands/cap/review.md +272 -0
  173. package/commands/cap/scan.md +249 -0
  174. package/commands/cap/start.md +234 -0
  175. package/commands/cap/status.md +189 -0
  176. package/commands/cap/test.md +250 -0
  177. package/hooks/dist/gsd-check-update.js +114 -0
  178. package/hooks/dist/gsd-context-monitor.js +156 -0
  179. package/hooks/dist/gsd-prompt-guard.js +96 -0
  180. package/hooks/dist/gsd-statusline.js +119 -0
  181. package/hooks/dist/gsd-workflow-guard.js +94 -0
  182. package/package.json +51 -0
  183. package/scripts/base64-scan.sh +262 -0
  184. package/scripts/build-hooks.js +82 -0
  185. package/scripts/cap-removal-checklist.md +202 -0
  186. package/scripts/prompt-injection-scan.sh +198 -0
  187. package/scripts/run-tests.cjs +29 -0
  188. package/scripts/secret-scan.sh +227 -0
@@ -0,0 +1,165 @@
1
+ ---
2
+ name: cap:annotate
3
+ description: "Retroactively annotate existing code with @cap-feature and @cap-todo tags. Invokes cap-prototyper in ANNOTATE mode."
4
+ allowed-tools:
5
+ - Read
6
+ - Write
7
+ - Edit
8
+ - Bash
9
+ - Glob
10
+ - Grep
11
+ - Task
12
+ ---
13
+
14
+ <!-- @gsd-context CAP v2.0 annotate command -- invokes cap-prototyper in annotate mode to add @cap-feature tags to existing unannotated code. Primary entry point after brownfield init. -->
15
+ <!-- @gsd-decision Annotate is a thin command wrapper over cap-prototyper ANNOTATE mode. This avoids a separate agent and keeps all code generation/modification in one agent with mode dispatch. -->
16
+ <!-- @gsd-decision Annotate targets a specific directory or defaults to project root src/. Scoped annotation prevents overwhelming the user with changes across the entire codebase at once. -->
17
+
18
+ <!-- @gsd-todo(ref:AC-89) /cap:annotate shall invoke cap-prototyper in annotate mode -->
19
+
20
+ <objective>
21
+ Add @cap-feature and @cap-todo tags to existing unannotated code by invoking cap-prototyper in ANNOTATE mode. This is the recommended next step after brownfield /cap:init.
22
+
23
+ **Arguments:**
24
+ - `[path]` -- directory or file to annotate (defaults to `src/` or project root)
25
+ - `--feature F-NNN` -- scope annotation to a specific Feature Map entry
26
+ - `--dry-run` -- preview annotations without writing files
27
+
28
+ **Requires:** FEATURE-MAP.md must exist (run /cap:init first).
29
+ </objective>
30
+
31
+ <context>
32
+ $ARGUMENTS
33
+
34
+ @FEATURE-MAP.md
35
+ </context>
36
+
37
+ <process>
38
+
39
+ ## Step 1: Validate prerequisites
40
+
41
+ Check that CAP is initialized:
42
+
43
+ ```bash
44
+ test -d .cap && echo "CAP_INITIALIZED" || echo "NOT_INITIALIZED"
45
+ test -f FEATURE-MAP.md && echo "FEATURE_MAP_EXISTS" || echo "NO_FEATURE_MAP"
46
+ ```
47
+
48
+ If not initialized, abort with: "CAP is not initialized. Run /cap:init first."
49
+
50
+ ## Step 2: Parse arguments
51
+
52
+ - Extract `path` from positional argument (default: `src/` if exists, else `.`)
53
+ - Extract `--feature` flag if present
54
+ - Extract `--dry-run` flag if present
55
+
56
+ ## Step 3: Load context for annotate mode
57
+
58
+ Read FEATURE-MAP.md to understand available features and ACs.
59
+
60
+ Check for existing tags in target path:
61
+
62
+ ```bash
63
+ node -e "
64
+ const scanner = require('./cap/bin/lib/cap-tag-scanner.cjs');
65
+ const tags = scanner.scanDirectory(process.cwd());
66
+ const groups = scanner.groupByFeature(tags);
67
+ console.log(JSON.stringify({
68
+ totalTags: tags.length,
69
+ features: Object.keys(groups),
70
+ filesWithTags: new Set(tags.map(t => t.file)).size
71
+ }));
72
+ "
73
+ ```
74
+
75
+ Load stack docs if available:
76
+
77
+ ```bash
78
+ ls .cap/stack-docs/*.md 2>/dev/null | head -10 || echo "no stack docs"
79
+ ```
80
+
81
+ ## Step 4: Invoke cap-prototyper in ANNOTATE mode
82
+
83
+ Use the Task tool to spawn cap-prototyper with ANNOTATE mode:
84
+
85
+ ```
86
+ Task("cap-prototyper", "
87
+ **MODE: ANNOTATE**
88
+
89
+ **Target path:** {resolved_path}
90
+ **Feature scope:** {feature_id or 'all'}
91
+ **Dry run:** {dry_run}
92
+
93
+ **FEATURE-MAP.md content:**
94
+ {feature_map_content}
95
+
96
+ **Existing tags found:**
97
+ {existing_tag_summary}
98
+
99
+ **Stack docs available:**
100
+ {stack_docs_list}
101
+
102
+ **Instructions:**
103
+ 1. Scan {target_path} for source files without @cap-feature tags
104
+ 2. Read each unannotated file and identify significant functions, classes, modules
105
+ 3. Match code to Feature Map entries based on purpose and file paths
106
+ 4. Use the Edit tool to add @cap-feature tags WITHOUT changing code logic
107
+ 5. Add @cap-todo tags for any unfinished work discovered during annotation
108
+ 6. {If dry_run: 'OUTPUT the proposed changes but do NOT write files'}
109
+ ")
110
+ ```
111
+
112
+ ## Step 5: Run scan after annotation
113
+
114
+ After the prototyper completes, run a scan to update Feature Map:
115
+
116
+ ```bash
117
+ node -e "
118
+ const scanner = require('./cap/bin/lib/cap-tag-scanner.cjs');
119
+ const fm = require('./cap/bin/lib/cap-feature-map.cjs');
120
+ const tags = scanner.scanDirectory(process.cwd());
121
+ const updated = fm.enrichFromTags(process.cwd(), tags);
122
+ console.log(JSON.stringify({
123
+ totalTags: tags.length,
124
+ featuresWithFiles: updated.features.filter(f => f.files.length > 0).length,
125
+ totalFileRefs: updated.features.reduce((sum, f) => sum + f.files.length, 0)
126
+ }));
127
+ "
128
+ ```
129
+
130
+ ## Step 6: Report results
131
+
132
+ ```
133
+ cap:annotate complete.
134
+
135
+ Files annotated: {N}
136
+ Tags added: {N}
137
+ @cap-feature: {N}
138
+ @cap-todo: {N}
139
+ @cap-risk: {N}
140
+ @cap-decision:{N}
141
+
142
+ Feature Map updated:
143
+ Features with file refs: {N}
144
+ Total file references: {N}
145
+
146
+ Next steps:
147
+ /cap:scan -- verify tag coverage
148
+ /cap:prototype -- build out features that need implementation
149
+ /cap:status -- view project dashboard
150
+ ```
151
+
152
+ ## Step 7: Update session
153
+
154
+ ```bash
155
+ node -e "
156
+ const session = require('./cap/bin/lib/cap-session.cjs');
157
+ session.updateSession(process.cwd(), {
158
+ lastCommand: '/cap:annotate',
159
+ lastCommandTimestamp: new Date().toISOString(),
160
+ step: 'annotated'
161
+ });
162
+ "
163
+ ```
164
+
165
+ </process>
@@ -0,0 +1,238 @@
1
+ ---
2
+ name: cap:brainstorm
3
+ description: Interactive feature discovery conversation that produces Feature Map entries with acceptance criteria, feature grouping, and dependency analysis. Spawns cap-brainstormer agent.
4
+ argument-hint: "[--resume] [--multi]"
5
+ allowed-tools:
6
+ - Read
7
+ - Write
8
+ - Edit
9
+ - Bash
10
+ - Task
11
+ - Glob
12
+ - Grep
13
+ - AskUserQuestion
14
+ ---
15
+
16
+ <!-- @gsd-context CAP v2.0 brainstorm command -- orchestrates conversational feature discovery. Spawns cap-brainstormer agent, receives structured Feature Map entries, writes to FEATURE-MAP.md after user approval. -->
17
+ <!-- @gsd-decision Writes directly to FEATURE-MAP.md (not PRD files). Feature Map is the single source of truth in CAP. PRDs are an intermediate artifact that CAP eliminates. -->
18
+ <!-- @gsd-decision Command layer owns all file I/O -- agent is stateless. Proven pattern from GSD brainstorm.md. -->
19
+ <!-- @gsd-constraint No Feature Map entries are written without explicit user approval -- confirmation gate is mandatory -->
20
+
21
+ <objective>
22
+ Spawns the `cap-brainstormer` agent to have a structured conversation about what needs to be built. The agent returns structured Feature Map entries. This command presents the entries for user confirmation, then writes to FEATURE-MAP.md.
23
+
24
+ <!-- @gsd-todo(ref:AC-36) /cap:brainstorm shall invoke the cap-brainstormer agent for conversational feature discovery. -->
25
+
26
+ **Arguments:**
27
+ - `--resume` -- resume a previous brainstorm session using .cap/SESSION.json context
28
+ - `--multi` -- hint that the project has multiple independent feature areas
29
+
30
+ **Key guarantee:** No Feature Map entries are written until the user explicitly approves.
31
+ </objective>
32
+
33
+ <context>
34
+ $ARGUMENTS
35
+
36
+ @FEATURE-MAP.md
37
+ @.cap/SESSION.json
38
+ </context>
39
+
40
+ <process>
41
+
42
+ ## Step 0: Parse flags
43
+
44
+ Check `$ARGUMENTS` for:
45
+ - `--resume` -- if present, set `resume_mode = true`
46
+ - `--multi` -- if present, set `multi_mode = true`
47
+
48
+ Log: "cap:brainstorm | resume: {resume_mode} | multi: {multi_mode}"
49
+
50
+ ## Step 1: Load existing Feature Map and session state
51
+
52
+ Read FEATURE-MAP.md:
53
+
54
+ ```bash
55
+ node -e "
56
+ const fm = require('./cap/bin/lib/cap-feature-map.cjs');
57
+ const featureMap = fm.readFeatureMap(process.cwd());
58
+ console.log(JSON.stringify({
59
+ featureCount: featureMap.features.length,
60
+ existingIds: featureMap.features.map(f => f.id),
61
+ existingTitles: featureMap.features.map(f => f.title)
62
+ }));
63
+ "
64
+ ```
65
+
66
+ Store as `existing_features`.
67
+
68
+ If `resume_mode`:
69
+
70
+ ```bash
71
+ node -e "
72
+ const session = require('./cap/bin/lib/cap-session.cjs');
73
+ const s = session.loadSession(process.cwd());
74
+ console.log(JSON.stringify(s));
75
+ "
76
+ ```
77
+
78
+ Store as `session_context`.
79
+
80
+ ## Step 2: Spawn cap-brainstormer agent
81
+
82
+ <!-- @gsd-todo(ref:AC-37) cap-brainstormer shall produce structured PRD output with numbered acceptance criteria. -->
83
+ <!-- @gsd-todo(ref:AC-39) cap-brainstormer shall assign feature IDs in sequential format (F-001, F-002, ...). -->
84
+
85
+ Spawn `cap-brainstormer` via the Task tool with the following context:
86
+
87
+ ```
88
+ $ARGUMENTS
89
+
90
+ **Session context:**
91
+ Resume mode: {resume_mode}
92
+ Multi-feature hint: {multi_mode}
93
+ Existing features: {existing_features.featureCount} features already in FEATURE-MAP.md
94
+ Existing IDs: {existing_features.existingIds}
95
+ Next available ID: F-{padded next number}
96
+
97
+ {If resume_mode and session_context:}
98
+ **Previous session context:**
99
+ Active feature: {session_context.activeFeature}
100
+ Last step: {session_context.step}
101
+ Last command: {session_context.lastCommand}
102
+ {End if}
103
+
104
+ **Instructions:**
105
+ 1. Have a conversational exchange with the user to understand what needs to be built
106
+ 2. Ask targeted questions ONE AT A TIME -- do not present a list of questions
107
+ 3. After sufficient understanding, cluster features into logical groups
108
+ 4. Surface dependencies between feature groups
109
+ 5. For each feature, draft numbered acceptance criteria in imperative form
110
+ 6. Assign feature IDs starting from {next available ID}
111
+ 7. Return the feature entries in the exact structured format below
112
+
113
+ **Return format (delimited):**
114
+
115
+ === BRAINSTORM OUTPUT ===
116
+ FEATURE_COUNT: N
117
+
118
+ === FEATURE: F-NNN ===
119
+ TITLE: {verb+object title}
120
+ GROUP: {logical group name}
121
+ DEPENDS_ON: {comma-separated F-IDs or "none"}
122
+ AC-1: {imperative description}
123
+ AC-2: {imperative description}
124
+ ...
125
+ === END FEATURE ===
126
+
127
+ {Repeat for each feature}
128
+
129
+ === DECISIONS ===
130
+ - {decision 1}
131
+ - {decision 2}
132
+ === END DECISIONS ===
133
+
134
+ === END BRAINSTORM OUTPUT ===
135
+
136
+ Do NOT write any files -- return structured output only.
137
+ ```
138
+
139
+ Wait for `cap-brainstormer` to complete.
140
+
141
+ **Parse the agent output:**
142
+
143
+ 1. Extract between `=== BRAINSTORM OUTPUT ===` and `=== END BRAINSTORM OUTPUT ===`
144
+ 2. Parse `FEATURE_COUNT:` line
145
+ 3. For each `=== FEATURE: F-NNN ===` block, extract: TITLE, GROUP, DEPENDS_ON, and all AC-N lines
146
+ 4. Extract decisions from `=== DECISIONS ===` block
147
+ 5. Build Feature objects:
148
+
149
+ ```javascript
150
+ {
151
+ id: "F-NNN",
152
+ title: "extracted title",
153
+ state: "planned",
154
+ acs: [{ id: "AC-1", description: "...", status: "pending" }, ...],
155
+ files: [],
156
+ dependencies: ["F-NNN", ...],
157
+ metadata: { group: "group name" }
158
+ }
159
+ ```
160
+
161
+ ## Step 3: Present features for user approval
162
+
163
+ <!-- @gsd-todo(ref:AC-38) cap-brainstormer shall write discovered features directly to FEATURE-MAP.md with state planned. -->
164
+ <!-- @gsd-todo(ref:AC-40) cap-brainstormer output shall be directly consumable by /cap:prototype without manual translation. -->
165
+
166
+ Display the parsed features:
167
+
168
+ ```
169
+ Brainstorm complete. {feature_count} features discovered:
170
+
171
+ {For each feature:}
172
+ {feature.id}: {feature.title} [{feature.state}]
173
+ Group: {group}
174
+ Dependencies: {deps or "none"}
175
+ Acceptance criteria:
176
+ AC-1: {description}
177
+ AC-2: {description}
178
+ ...
179
+ {End for}
180
+
181
+ Decisions made:
182
+ {For each decision:}
183
+ - {decision}
184
+ {End for}
185
+ ```
186
+
187
+ Use AskUserQuestion:
188
+ > "Review the {feature_count} features above. Approve writing to FEATURE-MAP.md? [yes / provide corrections / restart]"
189
+
190
+ - If `yes`, `y`, or `approve`: proceed to Step 4
191
+ - If corrections: Re-spawn `cap-brainstormer` with original context + `**Corrections from user:** {user text}`. Re-parse and re-display. Loop back to approval gate.
192
+ - If `restart`: Clear all parsed data. Go back to Step 2 with fresh Task() call.
193
+
194
+ **IMPORTANT:** No code path reaches Step 4 without explicit user approval.
195
+
196
+ ## Step 4: Write approved features to FEATURE-MAP.md
197
+
198
+ ```bash
199
+ node -e "
200
+ const fm = require('./cap/bin/lib/cap-feature-map.cjs');
201
+ const featureMap = fm.readFeatureMap(process.cwd());
202
+ const newFeatures = {JSON.stringify(parsed_features)};
203
+ const updated = fm.addFeatures(featureMap, newFeatures);
204
+ fm.writeFeatureMap(process.cwd(), updated);
205
+ console.log('Written ' + newFeatures.length + ' features to FEATURE-MAP.md');
206
+ "
207
+ ```
208
+
209
+ ## Step 5: Update session state
210
+
211
+ ```bash
212
+ node -e "
213
+ const session = require('./cap/bin/lib/cap-session.cjs');
214
+ session.updateSession(process.cwd(), {
215
+ lastCommand: '/cap:brainstorm',
216
+ lastCommandTimestamp: new Date().toISOString(),
217
+ step: 'brainstorm-complete'
218
+ });
219
+ "
220
+ ```
221
+
222
+ ## Step 6: Final report
223
+
224
+ ```
225
+ cap:brainstorm complete.
226
+
227
+ Features written to FEATURE-MAP.md: {feature_count}
228
+ {For each feature: feature.id: feature.title}
229
+
230
+ Decisions recorded: {decision_count}
231
+
232
+ Next steps:
233
+ - Run /cap:start to select a feature to work on
234
+ - Run /cap:prototype --features {first_feature_id} to build initial code
235
+ - Run /cap:brainstorm --resume to continue discovery later
236
+ ```
237
+
238
+ </process>
@@ -0,0 +1,297 @@
1
+ ---
2
+ name: cap:debug
3
+ description: Systematic debugging with persistent state across context resets. Spawns cap-debugger agent using scientific method.
4
+ argument-hint: "[issue description]"
5
+ allowed-tools:
6
+ - Read
7
+ - Write
8
+ - Bash
9
+ - Task
10
+ - AskUserQuestion
11
+ ---
12
+
13
+ <!-- @gsd-context CAP v2.0 debug command -- orchestrates scientific debugging. Gathers symptoms, spawns cap-debugger agent, handles checkpoints and continuations. Debug state persists in .cap/debug/. -->
14
+ <!-- @gsd-decision Debug state in .cap/debug/ (not .planning/debug/) -- CAP centralizes all runtime state under .cap/ -->
15
+ <!-- @gsd-pattern Orchestrator gathers symptoms and spawns agent. Fresh context per investigation to avoid context exhaustion. -->
16
+
17
+ <objective>
18
+ <!-- @gsd-todo(ref:AC-63) /cap:debug shall invoke the cap-debugger agent using a scientific method approach. -->
19
+
20
+ Debug issues using scientific method with subagent isolation.
21
+
22
+ **Orchestrator role:** Gather symptoms, spawn cap-debugger agent, handle checkpoints, spawn continuations.
23
+
24
+ **Why subagent:** Investigation burns context fast. Fresh context per investigation. Main context stays lean for user interaction.
25
+ </objective>
26
+
27
+ <context>
28
+ User's issue: $ARGUMENTS
29
+
30
+ Check for active sessions:
31
+ ```bash
32
+ ls .cap/debug/*.md 2>/dev/null | head -5
33
+ ```
34
+ </context>
35
+
36
+ <process>
37
+
38
+ ## Step 0: Load session and project context
39
+
40
+ <!-- @gsd-todo(ref:AC-64) cap-debugger shall maintain persistent debug state across the debug session. -->
41
+
42
+ ```bash
43
+ node -e "
44
+ const session = require('./cap/bin/lib/cap-session.cjs');
45
+ const fs = require('node:fs');
46
+ const path = require('node:path');
47
+ const s = session.loadSession(process.cwd());
48
+ const debugDir = path.join(process.cwd(), '.cap', 'debug');
49
+ let activeSessions = [];
50
+ if (fs.existsSync(debugDir)) {
51
+ activeSessions = fs.readdirSync(debugDir)
52
+ .filter(f => f.startsWith('SESSION-') && f.endsWith('.md'))
53
+ .map(f => {
54
+ const content = fs.readFileSync(path.join(debugDir, f), 'utf8');
55
+ const statusMatch = content.match(/^## Status: (.+)$/m);
56
+ return { file: f, status: statusMatch ? statusMatch[1] : 'unknown' };
57
+ });
58
+ }
59
+ console.log(JSON.stringify({
60
+ activeFeature: s.activeFeature,
61
+ activeDebugSession: s.activeDebugSession,
62
+ existingSessions: activeSessions
63
+ }));
64
+ "
65
+ ```
66
+
67
+ Store as `debug_context`.
68
+
69
+ ## Step 1: Check for active or resumable debug sessions
70
+
71
+ If `debug_context.activeDebugSession` is set:
72
+
73
+ ```bash
74
+ node -e "
75
+ const fs = require('node:fs');
76
+ const path = require('node:path');
77
+ const sessionFile = path.join(process.cwd(), '.cap', 'debug', 'SESSION-{debug_context.activeDebugSession}.md');
78
+ if (fs.existsSync(sessionFile)) {
79
+ console.log(fs.readFileSync(sessionFile, 'utf8'));
80
+ } else {
81
+ console.log('NOT_FOUND');
82
+ }
83
+ "
84
+ ```
85
+
86
+ If active session found, display:
87
+
88
+ ```
89
+ Active debug session found: SESSION-{id}
90
+ Status: {status}
91
+ ```
92
+
93
+ Use AskUserQuestion:
94
+ > "Resume existing debug session SESSION-{id}, or start a new investigation? [resume / new]"
95
+
96
+ - If `resume`: load existing session content, proceed to Step 3 with session context
97
+ - If `new`: generate new session ID, proceed to Step 2
98
+
99
+ If no active session: proceed to Step 2.
100
+
101
+ ## Step 2: Gather symptoms
102
+
103
+ If `$ARGUMENTS` contains an issue description, use it as initial symptoms.
104
+
105
+ If `$ARGUMENTS` is empty, use AskUserQuestion:
106
+ > "Describe the issue you are investigating. Include: what you expected, what actually happened, any error messages, and when this started."
107
+
108
+ Store as `symptoms`.
109
+
110
+ Generate a new debug session ID:
111
+
112
+ ```bash
113
+ node -e "
114
+ const crypto = require('node:crypto');
115
+ const id = crypto.randomBytes(4).toString('hex');
116
+ console.log(id);
117
+ "
118
+ ```
119
+
120
+ Store as `session_id`.
121
+
122
+ Create the debug session file:
123
+
124
+ Write `.cap/debug/SESSION-{session_id}.md` using the Write tool:
125
+
126
+ ```markdown
127
+ # Debug Session: {session_id}
128
+
129
+ ## Status: investigating
130
+
131
+ ## Symptoms
132
+ {symptoms}
133
+
134
+ ## Context
135
+ - Active feature: {debug_context.activeFeature or 'none'}
136
+ - Timestamp: {ISO timestamp}
137
+
138
+ ## Hypotheses
139
+ <!-- Cap-debugger will populate this section -->
140
+
141
+ ## Tests Performed
142
+ <!-- Cap-debugger will populate this section -->
143
+
144
+ ## Findings
145
+ <!-- Cap-debugger will populate this section -->
146
+
147
+ ## Resolution
148
+ <!-- Populated when root cause is found and fix is applied -->
149
+ ```
150
+
151
+ Update session:
152
+
153
+ ```bash
154
+ node -e "
155
+ const session = require('./cap/bin/lib/cap-session.cjs');
156
+ session.updateSession(process.cwd(), {
157
+ activeDebugSession: '{session_id}',
158
+ lastCommand: '/cap:debug',
159
+ lastCommandTimestamp: new Date().toISOString(),
160
+ step: 'debug-investigating'
161
+ });
162
+ "
163
+ ```
164
+
165
+ ## Step 3: Spawn cap-debugger agent
166
+
167
+ <!-- @gsd-todo(ref:AC-65) cap-debugger shall follow a hypothesis -> test -> verify loop, documenting each step. -->
168
+ <!-- @gsd-todo(ref:AC-66) cap-debugger shall not modify production code without explicit developer approval. -->
169
+
170
+ Identify relevant files from the active feature:
171
+
172
+ ```bash
173
+ node -e "
174
+ const fm = require('./cap/bin/lib/cap-feature-map.cjs');
175
+ const session = require('./cap/bin/lib/cap-session.cjs');
176
+ const s = session.loadSession(process.cwd());
177
+ const featureMap = fm.readFeatureMap(process.cwd());
178
+ const feature = s.activeFeature ? featureMap.features.find(f => f.id === s.activeFeature) : null;
179
+ console.log(JSON.stringify({
180
+ files: feature ? feature.files : [],
181
+ title: feature ? feature.title : 'unknown'
182
+ }));
183
+ "
184
+ ```
185
+
186
+ Spawn `cap-debugger` via Task tool:
187
+
188
+ ```
189
+ **DEBUG SESSION: {session_id}**
190
+
191
+ **Symptoms:**
192
+ {symptoms}
193
+
194
+ {If resuming:}
195
+ **Previous session state:**
196
+ {existing session file content}
197
+ {End if}
198
+
199
+ **Active feature:** {feature.title or 'none'}
200
+
201
+ <files_to_read>
202
+ {For each file in feature.files: - file}
203
+ - .cap/debug/SESSION-{session_id}.md
204
+ </files_to_read>
205
+
206
+ **Instructions:**
207
+ 1. Read all files listed above
208
+ 2. Analyze symptoms and form ranked hypotheses
209
+ 3. Test each hypothesis through code reading and execution
210
+ 4. Document each step in the debug session file
211
+ 5. DO NOT modify production code -- only observe and test
212
+ 6. When root cause is found, propose a fix and wait for approval
213
+
214
+ **Return format:**
215
+ === DEBUG RESULT ===
216
+ STATUS: ROOT_CAUSE_FOUND | CHECKPOINT_REACHED | DEBUG_COMPLETE
217
+ SESSION_ID: {session_id}
218
+ {If ROOT_CAUSE_FOUND:}
219
+ ROOT_CAUSE: {description}
220
+ PROPOSED_FIX: {description}
221
+ FILES_TO_MODIFY: [list]
222
+ {End if}
223
+ {If CHECKPOINT_REACHED:}
224
+ CHECKPOINT_REASON: {what user input is needed}
225
+ NEXT_STEPS: {what to investigate next}
226
+ {End if}
227
+ === END DEBUG RESULT ===
228
+ ```
229
+
230
+ Wait for cap-debugger to complete. Parse the result.
231
+
232
+ ## Step 4: Handle agent result
233
+
234
+ **If STATUS == ROOT_CAUSE_FOUND:**
235
+
236
+ Display:
237
+ ```
238
+ Root cause found:
239
+ {root_cause}
240
+
241
+ Proposed fix:
242
+ {proposed_fix}
243
+
244
+ Files to modify:
245
+ {files_to_modify}
246
+ ```
247
+
248
+ Use AskUserQuestion:
249
+ > "Apply the proposed fix? [yes / no / modify: instructions]"
250
+
251
+ - If `yes`: Spawn cap-debugger again with `**MODE: APPLY_FIX**` and the proposed fix details. The agent applies the fix and runs verification.
252
+ - If `no`: Update session file status to `root_cause_found_pending`, end debug session.
253
+ - If `modify: <instructions>`: Spawn cap-debugger again with modified fix instructions.
254
+
255
+ **If STATUS == CHECKPOINT_REACHED:**
256
+
257
+ Display checkpoint reason and next steps.
258
+
259
+ Use AskUserQuestion:
260
+ > "{checkpoint_reason}. Provide the requested information, or type 'stop' to pause the session."
261
+
262
+ - If user provides info: Re-spawn cap-debugger with the new information added to context.
263
+ - If `stop`: Update session file, end session. User can resume later with `/cap:debug`.
264
+
265
+ **If STATUS == DEBUG_COMPLETE:**
266
+
267
+ Log: "Debug session {session_id} complete."
268
+
269
+ ## Step 5: Update session and report
270
+
271
+ Update debug session file with resolution (via Write tool).
272
+
273
+ ```bash
274
+ node -e "
275
+ const session = require('./cap/bin/lib/cap-session.cjs');
276
+ session.updateSession(process.cwd(), {
277
+ activeDebugSession: null,
278
+ lastCommand: '/cap:debug',
279
+ lastCommandTimestamp: new Date().toISOString(),
280
+ step: 'debug-complete'
281
+ });
282
+ "
283
+ ```
284
+
285
+ ```
286
+ cap:debug complete.
287
+
288
+ Session: {session_id}
289
+ Status: {final_status}
290
+ Debug log: .cap/debug/SESSION-{session_id}.md
291
+
292
+ {If fix applied:}
293
+ Fix applied and verified. Run /cap:test to confirm no regressions.
294
+ {End if}
295
+ ```
296
+
297
+ </process>