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,262 @@
1
+ ---
2
+ name: cap:init
3
+ description: "Initialize CAP project -- creates .cap/, FEATURE-MAP.md, detects dependencies via Context7, performs brownfield analysis on existing codebases."
4
+ allowed-tools:
5
+ - Read
6
+ - Write
7
+ - Bash
8
+ - Glob
9
+ - Grep
10
+ ---
11
+
12
+ <!-- @gsd-context CAP v2.0 init command (final pass) -- adds mandatory Context7 integration and brownfield detection on top of the base init flow. -->
13
+ <!-- @gsd-decision Context7 fetch is mandatory at init time per AC-81. If unreachable, warning is emitted but init continues with explicit marker in SESSION.json. -->
14
+ <!-- @gsd-decision Brownfield analysis is ephemeral -- results are used as context for /cap:annotate suggestion, NOT persisted as a separate document (AC-87). -->
15
+ <!-- @gsd-decision No /cap:map command exists. Codebase analysis is part of /cap:init only (AC-90). -->
16
+ <!-- @gsd-constraint No prompts, wizards, or configuration forms. Init completes in a single invocation (AC-4, AC-5). -->
17
+
18
+ <!-- @gsd-todo(ref:AC-81) Detect all dependencies from package.json / requirements.txt / Cargo.toml / go.mod and fetch docs via Context7 -->
19
+ <!-- @gsd-todo(ref:AC-82) Store fetched stack docs in .cap/stack-docs/{library-name}.md compressed to API surface, config, breaking changes -->
20
+ <!-- @gsd-todo(ref:AC-83) Agents receive .cap/stack-docs/ as context input on every invocation -->
21
+ <!-- @gsd-todo(ref:AC-84) Stack-docs carry freshness marker (fetch date). Docs older than 7 days auto-refreshed. Manual refresh via /cap:refresh-docs -->
22
+ <!-- @gsd-todo(ref:AC-85) Context7 fetching is MANDATORY at init. If unreachable, warning emitted and init continues with explicit marker -->
23
+ <!-- @gsd-todo(ref:AC-86) Brownfield init performs one-time codebase analysis: architecture detection, convention detection, test setup detection -->
24
+ <!-- @gsd-todo(ref:AC-87) Brownfield analysis result NOT persisted as separate document -- used as init context for /cap:annotate suggestion -->
25
+ <!-- @gsd-todo(ref:AC-88) After brownfield init, suggest /cap:annotate to retroactively annotate existing code -->
26
+ <!-- @gsd-todo(ref:AC-90) No /cap:map command. Codebase analysis is part of /cap:init -->
27
+ <!-- @gsd-todo(ref:AC-91) To refresh codebase information: /cap:annotate + /cap:refresh-docs -->
28
+ <!-- @gsd-todo(ref:AC-92) The 7 documents from .planning/codebase/ shall NOT be generated in v2.0 -->
29
+
30
+ <objective>
31
+ Initialize the CAP project structure with mandatory Context7 stack documentation fetch and brownfield codebase analysis. This command:
32
+
33
+ 1. Creates `.cap/` directory with subdirectories (stack-docs, debug)
34
+ 2. Creates `.cap/.gitignore` (ignores SESSION.json and debug/)
35
+ 3. Creates `.cap/SESSION.json` with default session state
36
+ 4. Creates `FEATURE-MAP.md` at project root (ONLY if it does not already exist)
37
+ 5. **Detects project dependencies** from manifest files (package.json, requirements.txt, Cargo.toml, go.mod)
38
+ 6. **Fetches stack documentation via Context7** for all detected dependencies
39
+ 7. **Performs brownfield analysis** if existing source code is detected
40
+ 8. Suggests `/cap:annotate` if brownfield code is found
41
+
42
+ **Idempotent:** Safe to run multiple times. Never overwrites existing FEATURE-MAP.md.
43
+ **Non-interactive:** No prompts, no wizards, no configuration forms.
44
+ **Context7 is MANDATORY:** If unreachable, warning emitted and init continues with explicit marker.
45
+ </objective>
46
+
47
+ <context>
48
+ $ARGUMENTS
49
+
50
+ @FEATURE-MAP.md
51
+ </context>
52
+
53
+ <process>
54
+
55
+ ## Step 1: Detect project root and check initialization state
56
+
57
+ Use Bash to check current state:
58
+
59
+ ```bash
60
+ ls -la .cap/ 2>/dev/null && echo "ALREADY_INITIALIZED" || echo "FRESH_PROJECT"
61
+ test -f FEATURE-MAP.md && echo "FEATURE_MAP_EXISTS" || echo "NO_FEATURE_MAP"
62
+ ```
63
+
64
+ ## Step 2: Create .cap/ directory structure
65
+
66
+ ```bash
67
+ mkdir -p .cap/stack-docs .cap/debug
68
+ ```
69
+
70
+ ## Step 3: Write .cap/.gitignore
71
+
72
+ Use the Write tool to create `.cap/.gitignore`:
73
+
74
+ ```
75
+ # CAP ephemeral state -- do not commit
76
+ SESSION.json
77
+ debug/
78
+ ```
79
+
80
+ ## Step 4: Write .cap/SESSION.json (only if not exists)
81
+
82
+ Check if SESSION.json exists first. If not, write default session:
83
+
84
+ ```json
85
+ {
86
+ "version": "2.0.0",
87
+ "lastCommand": "/cap:init",
88
+ "lastCommandTimestamp": "<ISO_NOW>",
89
+ "activeFeature": null,
90
+ "step": "init",
91
+ "startedAt": "<ISO_NOW>",
92
+ "activeDebugSession": null,
93
+ "context7Available": null,
94
+ "metadata": {}
95
+ }
96
+ ```
97
+
98
+ Note the `context7Available` field -- this gets set in Step 6 to indicate whether Context7 was reachable.
99
+
100
+ ## Step 5: Write FEATURE-MAP.md (only if not exists)
101
+
102
+ **CRITICAL: Skip this step if FEATURE-MAP.md already exists.**
103
+
104
+ If FEATURE-MAP.md does NOT exist, write the empty template.
105
+
106
+ ## Step 6: Mandatory Context7 dependency fetch
107
+
108
+ <!-- @gsd-decision Multi-language dependency detection runs in priority order: package.json first, then requirements.txt, then Cargo.toml, then go.mod. First match sets project type. -->
109
+
110
+ ### 6a: Detect dependencies
111
+
112
+ Run dependency detection for all supported manifest files:
113
+
114
+ ```bash
115
+ node -e "
116
+ const stackDocs = require('./cap/bin/lib/cap-stack-docs.cjs');
117
+ const result = stackDocs.detectDependencies(process.cwd());
118
+ console.log(JSON.stringify(result, null, 2));
119
+ "
120
+ ```
121
+
122
+ Store the result as `dep_info`. Log: "Detected {dep_info.type} project with {dep_info.dependencies.length} dependencies."
123
+
124
+ ### 6b: Fetch stack docs via Context7
125
+
126
+ For each dependency in `dep_info.dependencies` (limit to top 10 most important -- skip internal/scoped packages that start with `@company/`):
127
+
128
+ ```bash
129
+ node -e "
130
+ const stackDocs = require('./cap/bin/lib/cap-stack-docs.cjs');
131
+ const depName = process.argv[1];
132
+ const lib = stackDocs.resolveLibrary(depName, 'API surface and configuration');
133
+ if (lib) {
134
+ const result = stackDocs.fetchDocs(process.cwd(), lib.id, 'API surface, configuration, breaking changes');
135
+ console.log(JSON.stringify({ library: depName, ...result }));
136
+ } else {
137
+ console.log(JSON.stringify({ library: depName, success: false, error: 'Library not found in Context7' }));
138
+ }
139
+ " "<DEP_NAME>"
140
+ ```
141
+
142
+ Track results:
143
+ - `fetched_count` -- number of successfully fetched docs
144
+ - `failed_count` -- number of failed fetches
145
+ - `context7_available` -- true if at least one fetch succeeded
146
+
147
+ ### 6c: Handle Context7 unreachable
148
+
149
+ If ALL fetches fail (context7_available = false):
150
+
151
+ 1. Update SESSION.json to set `context7Available: false`
152
+ 2. Emit warning:
153
+ ```
154
+ WARNING: Context7 is unreachable. Stack documentation could not be fetched.
155
+ Init continues without stack docs. Run /cap:refresh-docs when network is available.
156
+ ```
157
+
158
+ If some fetches succeeded:
159
+ 1. Update SESSION.json to set `context7Available: true`
160
+ 2. Log summary: "Fetched docs for {fetched_count} of {total} dependencies."
161
+
162
+ ## Step 7: Brownfield codebase analysis
163
+
164
+ <!-- @gsd-decision Brownfield analysis detects 3 things: (1) architecture pattern, (2) coding conventions, (3) test setup. Results are ephemeral -- used only for the /cap:annotate suggestion. -->
165
+
166
+ ### 7a: Check for existing source code
167
+
168
+ ```bash
169
+ # Count source files by language
170
+ find . -maxdepth 4 -not -path './node_modules/*' -not -path './.git/*' -not -path './.cap/*' \( -name "*.js" -o -name "*.ts" -o -name "*.py" -o -name "*.go" -o -name "*.rs" -o -name "*.java" -o -name "*.rb" \) | head -50
171
+ ```
172
+
173
+ If NO source files are found, this is a greenfield project. Skip to Step 8.
174
+
175
+ ### 7b: Architecture detection (ephemeral)
176
+
177
+ If source files exist, analyze the codebase structure:
178
+
179
+ ```bash
180
+ # Detect directory structure pattern
181
+ ls -d */ 2>/dev/null | head -20
182
+ # Check for common framework indicators
183
+ test -f tsconfig.json && echo "TYPESCRIPT"
184
+ test -f next.config.js -o -f next.config.mjs && echo "NEXTJS"
185
+ test -f vite.config.ts -o -f vite.config.js && echo "VITE"
186
+ test -f Dockerfile && echo "DOCKER"
187
+ test -d src && echo "SRC_DIR"
188
+ test -d lib && echo "LIB_DIR"
189
+ test -d packages && echo "MONOREPO"
190
+ ```
191
+
192
+ ### 7c: Convention detection (ephemeral)
193
+
194
+ ```bash
195
+ # Check for linting/formatting config
196
+ test -f .eslintrc.json -o -f .eslintrc.js -o -f eslint.config.js && echo "ESLINT"
197
+ test -f .prettierrc -o -f .prettierrc.json && echo "PRETTIER"
198
+ test -f .editorconfig && echo "EDITORCONFIG"
199
+ ```
200
+
201
+ ### 7d: Test setup detection (ephemeral)
202
+
203
+ ```bash
204
+ # Check for test frameworks
205
+ test -f jest.config.js -o -f jest.config.ts && echo "JEST"
206
+ test -f vitest.config.ts -o -f vitest.config.js && echo "VITEST"
207
+ test -d __tests__ -o -d tests -o -d test && echo "TEST_DIR_EXISTS"
208
+ ```
209
+
210
+ ### 7e: Suggest /cap:annotate
211
+
212
+ If brownfield code was detected, output:
213
+
214
+ ```
215
+ Existing codebase detected:
216
+ Source files: ~{count} files ({languages})
217
+ Architecture: {detected patterns}
218
+ Test setup: {detected test frameworks}
219
+
220
+ Recommended: Run /cap:annotate to add @cap-feature tags to your existing code.
221
+ This helps CAP track your features across the codebase.
222
+ ```
223
+
224
+ **Do NOT persist the brownfield analysis as a separate document** (AC-87).
225
+
226
+ ## Step 8: Report results
227
+
228
+ ```
229
+ CAP initialized.
230
+
231
+ Created:
232
+ .cap/ -- runtime directory
233
+ .cap/.gitignore -- excludes SESSION.json from git
234
+ .cap/SESSION.json -- ephemeral workflow state
235
+ .cap/stack-docs/ -- cached documentation ({fetched_count} docs fetched)
236
+ .cap/debug/ -- debug session logs
237
+ FEATURE-MAP.md -- feature source of truth (or: already existed, preserved)
238
+
239
+ Stack docs: {fetched_count} fetched, {failed_count} failed{context7_warning}
240
+
241
+ Next steps:
242
+ /cap:brainstorm -- generate features from conversation
243
+ /cap:annotate -- add @cap-feature tags to existing code
244
+ /cap:prototype -- build features from Feature Map
245
+ /cap:status -- view project dashboard
246
+ /cap:refresh-docs -- manually refresh stack documentation
247
+ ```
248
+
249
+ ## Step 9: Update session
250
+
251
+ ```bash
252
+ node -e "
253
+ const session = require('./cap/bin/lib/cap-session.cjs');
254
+ session.updateSession(process.cwd(), {
255
+ lastCommand: '/cap:init',
256
+ lastCommandTimestamp: new Date().toISOString(),
257
+ step: 'initialized'
258
+ });
259
+ "
260
+ ```
261
+
262
+ </process>
@@ -0,0 +1,234 @@
1
+ ---
2
+ name: cap:iterate
3
+ description: Code-first iteration loop -- runs scan, identifies Feature Map gaps, spawns cap-prototyper in ITERATE mode, re-scans, repeats until ACs are satisfied or user stops.
4
+ argument-hint: "[--features NAME] [--max N] [--auto]"
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 iterate command -- the flagship code-first loop. Scan -> identify gaps -> generate code -> re-scan -> repeat. Human approval gate between each iteration unless --auto is specified. -->
17
+ <!-- @gsd-decision Iteration loop is scan-driven: /cap:scan output determines what to build next. No upfront planning step. -->
18
+ <!-- @gsd-decision Human approval gate between iterations by default. --auto flag enables autonomous loop with --max N safety limit. -->
19
+ <!-- @gsd-constraint --auto mode requires --max N to prevent runaway loops. Default max is 5 if --auto specified without --max. -->
20
+
21
+ <objective>
22
+ <!-- @gsd-todo(ref:AC-49) /cap:iterate shall invoke cap-prototyper in iterate mode. -->
23
+
24
+ The core code-first iteration loop:
25
+ 1. Run /cap:scan to assess current Feature Map status
26
+ 2. Identify incomplete ACs and unimplemented features
27
+ 3. Spawn cap-prototyper in ITERATE mode to address gaps
28
+ 4. Re-scan to verify progress
29
+ 5. Present results to user, ask to continue or stop
30
+
31
+ **Arguments:**
32
+ - `--features NAME` -- scope iteration to specific Feature Map entries
33
+ - `--max N` -- maximum number of iterations (default 5 with --auto)
34
+ - `--auto` -- autonomous mode, no approval gate between iterations
35
+ </objective>
36
+
37
+ <context>
38
+ $ARGUMENTS
39
+
40
+ @FEATURE-MAP.md
41
+ @.cap/SESSION.json
42
+ </context>
43
+
44
+ <process>
45
+
46
+ ## Step 0: Parse flags
47
+
48
+ <!-- @gsd-todo(ref:AC-50) /cap:iterate shall support a --auto flag for multi-iteration autonomous loops. -->
49
+
50
+ Check `$ARGUMENTS` for:
51
+ - `--features NAME` -- if present, store as `feature_filter`
52
+ - `--max N` -- if present, store as `max_iterations` (default: 5)
53
+ - `--auto` -- if present, set `auto_mode = true`
54
+
55
+ If `auto_mode` is true and `max_iterations` is not set: `max_iterations = 5`
56
+
57
+ Log: "cap:iterate | mode: {auto or manual} | max: {max_iterations} | features: {feature_filter or 'all'}"
58
+
59
+ ## Step 1: Load active feature from session
60
+
61
+ <!-- @gsd-todo(ref:AC-51) /cap:iterate shall read the current feature from SESSION.json and refine the associated prototype. -->
62
+
63
+ ```bash
64
+ node -e "
65
+ const session = require('./cap/bin/lib/cap-session.cjs');
66
+ const fm = require('./cap/bin/lib/cap-feature-map.cjs');
67
+ const s = session.loadSession(process.cwd());
68
+ const featureMap = fm.readFeatureMap(process.cwd());
69
+ console.log(JSON.stringify({
70
+ activeFeature: s.activeFeature,
71
+ features: featureMap.features.map(f => ({
72
+ id: f.id, title: f.title, state: f.state,
73
+ acs: f.acs, files: f.files, dependencies: f.dependencies
74
+ }))
75
+ }));
76
+ "
77
+ ```
78
+
79
+ **Scope features:**
80
+ - If `feature_filter` is set: filter to matching IDs
81
+ - Else if active feature is set: use only that feature
82
+ - Else: use all features not in `shipped` state
83
+
84
+ Store as `target_features`.
85
+
86
+ Initialize: `ITERATION = 0`
87
+
88
+ ## Step 2: Run scan and identify gaps (loop start)
89
+
90
+ ```bash
91
+ node -e "
92
+ const scanner = require('./cap/bin/lib/cap-tag-scanner.cjs');
93
+ const fm = require('./cap/bin/lib/cap-feature-map.cjs');
94
+ const tags = scanner.scanDirectory(process.cwd());
95
+ const featureMap = fm.readFeatureMap(process.cwd());
96
+
97
+ // Identify ACs that are still pending
98
+ const gaps = [];
99
+ const targetIds = new Set({JSON.stringify(target_feature_ids)});
100
+ for (const f of featureMap.features) {
101
+ if (!targetIds.has(f.id)) continue;
102
+ for (const ac of f.acs) {
103
+ if (ac.status === 'pending') {
104
+ gaps.push({ featureId: f.id, featureTitle: f.title, acId: ac.id, acDesc: ac.description });
105
+ }
106
+ }
107
+ }
108
+
109
+ // Count @cap-todo tags
110
+ const todoTags = tags.filter(t => t.type === 'todo');
111
+
112
+ console.log(JSON.stringify({
113
+ totalTags: tags.length,
114
+ todoCount: todoTags.length,
115
+ gapCount: gaps.length,
116
+ gaps: gaps
117
+ }));
118
+ "
119
+ ```
120
+
121
+ Store as `scan_result`.
122
+
123
+ **If `scan_result.gapCount == 0`:**
124
+ Log: "All acceptance criteria resolved after {ITERATION} iteration(s)."
125
+ Proceed to Step 6.
126
+
127
+ **If `ITERATION == max_iterations`:**
128
+ Log: "Iteration cap ({max_iterations}) reached. {scan_result.gapCount} ACs remain unresolved."
129
+ Proceed to Step 6.
130
+
131
+ ## Step 3: Spawn cap-prototyper in ITERATE mode
132
+
133
+ Increment `ITERATION`.
134
+
135
+ Log: "--- Iteration {ITERATION}/{max_iterations} --- ({scan_result.gapCount} ACs remaining)"
136
+
137
+ Spawn `cap-prototyper` via Task tool:
138
+
139
+ ```
140
+ $ARGUMENTS
141
+
142
+ **MODE: ITERATE**
143
+
144
+ **Iteration {ITERATION} of {max_iterations}**
145
+
146
+ **Gaps to address (unresolved ACs):**
147
+ {For each gap:}
148
+ {gap.featureId}/{gap.acId}: {gap.acDesc}
149
+ {End for}
150
+
151
+ **Target features:**
152
+ {For each target_feature:}
153
+ Feature: {feature.id} - {feature.title} [{feature.state}]
154
+ Files: {feature.files.join(', ') or 'none yet'}
155
+ {For each AC:}
156
+ {ac.id}: {ac.description} [{ac.status}]
157
+ {End for}
158
+ {End for}
159
+
160
+ **Instructions:**
161
+ 1. Read the existing code files listed under each feature
162
+ 2. Address the unresolved ACs by implementing or refining code
163
+ 3. Add @cap-feature(feature:{ID}) tags to new code
164
+ 4. Add @cap-todo(ac:{FEATURE-ID}/AC-N) tags where ACs are implemented
165
+ 5. Update existing @cap-todo tags that are now resolved
166
+ 6. Do NOT break existing passing tests
167
+
168
+ **ALWAYS use the Write tool to create files** -- never use heredoc commands.
169
+ ```
170
+
171
+ Wait for cap-prototyper to complete.
172
+
173
+ ## Step 4: Re-scan after iteration
174
+
175
+ ```bash
176
+ node -e "
177
+ const scanner = require('./cap/bin/lib/cap-tag-scanner.cjs');
178
+ const fm = require('./cap/bin/lib/cap-feature-map.cjs');
179
+ const tags = scanner.scanDirectory(process.cwd());
180
+ fm.enrichFromTags(process.cwd(), tags);
181
+ const featureMap = fm.readFeatureMap(process.cwd());
182
+ const targetIds = new Set({JSON.stringify(target_feature_ids)});
183
+ let remaining = 0;
184
+ for (const f of featureMap.features) {
185
+ if (!targetIds.has(f.id)) continue;
186
+ remaining += f.acs.filter(a => a.status === 'pending').length;
187
+ }
188
+ console.log(JSON.stringify({ totalTags: tags.length, acsRemaining: remaining }));
189
+ "
190
+ ```
191
+
192
+ Log: "Iteration {ITERATION} complete. ACs remaining: {acsRemaining}"
193
+
194
+ ## Step 5: Approval gate or auto-continue
195
+
196
+ **If `auto_mode`:** Loop back to Step 2.
197
+
198
+ **If NOT `auto_mode`:**
199
+
200
+ Use AskUserQuestion:
201
+ > "Iteration {ITERATION} complete. {acsRemaining} ACs remaining. Continue to next iteration? [yes / stop / redirect: instructions]"
202
+
203
+ - If `yes`: Loop back to Step 2
204
+ - If `stop`: Proceed to Step 6
205
+ - If `redirect: <instructions>`: Store instructions as additional context for next iteration, loop back to Step 2
206
+
207
+ ## Step 6: Final report
208
+
209
+ ```bash
210
+ node -e "
211
+ const session = require('./cap/bin/lib/cap-session.cjs');
212
+ session.updateSession(process.cwd(), {
213
+ lastCommand: '/cap:iterate',
214
+ lastCommandTimestamp: new Date().toISOString(),
215
+ step: 'iterate-complete'
216
+ });
217
+ "
218
+ ```
219
+
220
+ ```
221
+ cap:iterate complete.
222
+
223
+ Mode: {auto or manual}
224
+ Iterations used: {ITERATION} of {max_iterations}
225
+ ACs remaining: {acsRemaining}
226
+
227
+ {If acsRemaining > 0:}
228
+ Run /cap:iterate to continue, or /cap:iterate --auto for autonomous mode.
229
+ {Else:}
230
+ All ACs resolved. Run /cap:test to write tests, or /cap:review to verify.
231
+ {End if}
232
+ ```
233
+
234
+ </process>