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,281 @@
1
+ ---
2
+ name: cap:prototype
3
+ description: Feature Map-driven prototype pipeline -- reads FEATURE-MAP.md, confirms ACs with user, spawns cap-prototyper to build annotated code scaffold. Supports --architecture and --annotate modes.
4
+ argument-hint: "[path] [--features NAME] [--architecture] [--annotate] [--interactive] [--non-interactive]"
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 prototype command -- reads Feature Map as primary input (not PRD). Spawns cap-prototyper in one of 4 modes. Auto-runs /cap:scan on completion. -->
17
+ <!-- @gsd-decision Feature Map replaces PRD as prototype input. Feature Map ACs become @cap-todo(ac:FEATURE/AC-N) tags in generated code. -->
18
+ <!-- @gsd-decision Auto-chains to /cap:scan on completion -- keeps Feature Map status in sync after code generation. -->
19
+ <!-- @gsd-pattern --features flag scopes prototype to specific Feature Map entries (replaces --phases scoping from GSD) -->
20
+
21
+ <objective>
22
+ <!-- @gsd-todo(ref:AC-41) /cap:prototype shall invoke the cap-prototyper agent which operates in four modes: prototype, iterate, architecture, and annotate. -->
23
+
24
+ Reads FEATURE-MAP.md, confirms acceptance criteria with the user, then spawns cap-prototyper in the appropriate mode to build annotated code. Each AC becomes a @cap-todo tag in the prototype.
25
+
26
+ On completion, automatically runs `/cap:scan` to update Feature Map status.
27
+
28
+ **Arguments:**
29
+ - `path` -- target directory for prototype output (defaults to project root)
30
+ - `--features NAME` -- scope prototype to specific Feature Map entries (comma-separated)
31
+ - `--architecture` -- skeleton-only mode (folders, interfaces, config, module boundaries)
32
+ - `--annotate` -- retroactively annotate existing code with @cap-feature tags
33
+ - `--interactive` -- pause after each iteration
34
+ - `--non-interactive` -- skip AC confirmation gate (for CI)
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
+ Check `$ARGUMENTS` for:
49
+ - `--features NAME` -- if present, store as `feature_filter` (comma-separated)
50
+ - `--architecture` -- if present, set `mode = "ARCHITECTURE"`
51
+ - `--annotate` -- if present, set `mode = "ANNOTATE"`
52
+ - `--interactive` -- if present, set `interactive_mode = true`
53
+ - `--non-interactive` -- if present, set `non_interactive = true`
54
+ - `path` -- target directory (defaults to `.`)
55
+
56
+ If neither `--architecture` nor `--annotate`: set `mode = "PROTOTYPE"`
57
+
58
+ Log: "cap:prototype | mode: {mode} | features: {feature_filter or 'all'} | interactive: {interactive_mode}"
59
+
60
+ ## Step 1: Read Feature Map and load active feature
61
+
62
+ ```bash
63
+ node -e "
64
+ const fm = require('./cap/bin/lib/cap-feature-map.cjs');
65
+ const session = require('./cap/bin/lib/cap-session.cjs');
66
+ const featureMap = fm.readFeatureMap(process.cwd());
67
+ const s = session.loadSession(process.cwd());
68
+ console.log(JSON.stringify({
69
+ activeFeature: s.activeFeature,
70
+ features: featureMap.features.map(f => ({
71
+ id: f.id, title: f.title, state: f.state,
72
+ acs: f.acs, files: f.files, dependencies: f.dependencies
73
+ }))
74
+ }));
75
+ "
76
+ ```
77
+
78
+ Store as `fm_data`.
79
+
80
+ **Scope features:**
81
+ - If `feature_filter` is set: filter to matching feature IDs
82
+ - Else if `fm_data.activeFeature` is set: use only that feature
83
+ - Else: use all features with state `planned` or `prototyped`
84
+
85
+ Store filtered list as `target_features`.
86
+
87
+ If `target_features` is empty: STOP and report:
88
+ > "No features in scope. Run /cap:brainstorm to discover features, or specify --features."
89
+
90
+ ## Step 2: Present ACs for confirmation
91
+
92
+ **Skip if `non_interactive` or `mode == "ANNOTATE"`.**
93
+
94
+ <!-- @gsd-todo(ref:AC-42) In prototype mode, the agent shall build a working prototype for a feature, annotating code with @cap-feature and @cap-todo tags as it builds. -->
95
+ <!-- @gsd-todo(ref:AC-44) In architecture mode, the agent shall analyze and refactor system-level structure without changing feature behavior. -->
96
+ <!-- @gsd-todo(ref:AC-45) In annotate mode, the agent shall retroactively annotate existing code with @cap-feature and @cap-todo tags. -->
97
+
98
+ Collect all ACs from target_features:
99
+
100
+ ```
101
+ Features to prototype ({target_features.length}):
102
+
103
+ {For each feature:}
104
+ {feature.id}: {feature.title} [{feature.state}]
105
+ {For each AC:}
106
+ {ac.id}: {ac.description} [{ac.status}]
107
+ {End for}
108
+ {End for}
109
+
110
+ Total ACs: {total_ac_count}
111
+ ```
112
+
113
+ Use AskUserQuestion:
114
+ > "Review the {total_ac_count} acceptance criteria above. Proceed with {mode} mode? [yes / provide corrections]"
115
+
116
+ - If `yes`: proceed to Step 3
117
+ - If corrections: incorporate and re-display
118
+
119
+ ## Step 3: Derive project context and spawn cap-prototyper
120
+
121
+ <!-- @gsd-todo(ref:AC-47) cap-prototyper shall derive project context (language, framework, conventions) from actual code on first invocation. -->
122
+ <!-- @gsd-todo(ref:AC-48) cap-prototyper shall follow deviation rules via a shared reference document. -->
123
+
124
+ Detect project conventions:
125
+
126
+ ```bash
127
+ node -e "
128
+ const fs = require('node:fs');
129
+ const path = require('node:path');
130
+ const cwd = process.cwd();
131
+ const conventions = {};
132
+
133
+ // Package.json conventions
134
+ if (fs.existsSync(path.join(cwd, 'package.json'))) {
135
+ const pkg = JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf8'));
136
+ conventions.type = pkg.type || 'commonjs';
137
+ conventions.scripts = Object.keys(pkg.scripts || {});
138
+ }
139
+
140
+ // Check for config files
141
+ conventions.hasEslint = fs.existsSync(path.join(cwd, '.eslintrc.json')) || fs.existsSync(path.join(cwd, '.eslintrc.js'));
142
+ conventions.hasPrettier = fs.existsSync(path.join(cwd, '.prettierrc'));
143
+ conventions.hasTsconfig = fs.existsSync(path.join(cwd, 'tsconfig.json'));
144
+
145
+ // Detect naming patterns from existing files
146
+ const entries = fs.readdirSync(path.join(cwd, 'cap/bin/lib')).filter(f => f.endsWith('.cjs'));
147
+ conventions.namingPattern = entries.length > 0 ? 'kebab-case.cjs' : 'unknown';
148
+
149
+ console.log(JSON.stringify(conventions));
150
+ "
151
+ ```
152
+
153
+ Store as `conventions`.
154
+
155
+ Load .cap/stack-docs/ if available:
156
+
157
+ ```bash
158
+ ls .cap/stack-docs/*.md 2>/dev/null | head -10 || echo "no stack docs"
159
+ ```
160
+
161
+ Spawn `cap-prototyper` via Task tool:
162
+
163
+ **MODE: PROTOTYPE prompt:**
164
+ ```
165
+ $ARGUMENTS
166
+
167
+ **MODE: {mode}**
168
+
169
+ **Target features:**
170
+ {For each target_feature:}
171
+ Feature: {feature.id} - {feature.title} [{feature.state}]
172
+ Dependencies: {feature.dependencies.join(', ') or 'none'}
173
+ {For each AC:}
174
+ {ac.id}: {ac.description}
175
+ {End for}
176
+ {End for}
177
+
178
+ **Project conventions:**
179
+ {JSON.stringify(conventions)}
180
+
181
+ **Tag obligations:**
182
+ - Every significant function/class/module gets @cap-feature(feature:{ID}) linking to FEATURE-MAP.md
183
+ - Every AC gets @cap-todo(ac:{FEATURE-ID}/AC-N) placed where the implementation happens
184
+ - Risk areas get @cap-risk tags
185
+ - Design decisions get @cap-decision tags
186
+
187
+ **Deviation rules:**
188
+ If you need to deviate from the Feature Map specification (e.g., an AC is impractical, dependencies changed), document the deviation with:
189
+ // @cap-decision Deviated from {FEATURE-ID}/AC-N: {reason}
190
+ Do not silently skip ACs. Every AC must have either an implementation tag or a deviation tag.
191
+
192
+ {If mode == "ARCHITECTURE":}
193
+ Generate ONLY structural artifacts:
194
+ 1. Folder structure with index/barrel files at module boundaries
195
+ 2. Config files matching existing project conventions
196
+ 3. Typed interfaces and type definitions for module boundaries
197
+ 4. Entry point stubs
198
+ 5. @cap-decision tags at every module boundary
199
+ ZERO feature implementation code.
200
+ {End if}
201
+
202
+ {If mode == "ANNOTATE":}
203
+ Do NOT create new files. Only EDIT existing files to add @cap-feature and @cap-todo tags.
204
+ Scan the target directory for source files, read each, and add appropriate tags.
205
+ {End if}
206
+
207
+ {If stack docs available:}
208
+ **Stack documentation available in .cap/stack-docs/:**
209
+ {list of available docs}
210
+ Read these before generating code that uses those libraries.
211
+ {End if}
212
+ ```
213
+
214
+ Wait for cap-prototyper to complete.
215
+
216
+ ## Step 4: Update Feature Map state
217
+
218
+ <!-- @gsd-todo(ref:AC-46) cap-prototyper shall update the feature state in FEATURE-MAP.md from planned to prototyped upon completing a prototype. -->
219
+
220
+ If `mode == "PROTOTYPE"`:
221
+
222
+ ```bash
223
+ node -e "
224
+ const fm = require('./cap/bin/lib/cap-feature-map.cjs');
225
+ const targetIds = {JSON.stringify(target_feature_ids)};
226
+ for (const id of targetIds) {
227
+ const result = fm.updateFeatureState(process.cwd(), id, 'prototyped');
228
+ console.log(id + ': ' + (result ? 'updated to prototyped' : 'state unchanged'));
229
+ }
230
+ "
231
+ ```
232
+
233
+ ## Step 5: Auto-run /cap:scan
234
+
235
+ <!-- @gsd-todo(ref:AC-43) In iterate mode, the agent shall refine an existing prototype based on feedback, updating tags and Feature Map state. -->
236
+
237
+ ```bash
238
+ node -e "
239
+ const scanner = require('./cap/bin/lib/cap-tag-scanner.cjs');
240
+ const fm = require('./cap/bin/lib/cap-feature-map.cjs');
241
+ const tags = scanner.scanDirectory(process.cwd());
242
+ const updated = fm.enrichFromTags(process.cwd(), tags);
243
+ const groups = scanner.groupByFeature(tags);
244
+ console.log(JSON.stringify({
245
+ totalTags: tags.length,
246
+ featuresEnriched: updated.features.filter(f => f.files.length > 0).length,
247
+ featureGroups: Object.keys(groups).length
248
+ }));
249
+ "
250
+ ```
251
+
252
+ ## Step 6: Update session and report
253
+
254
+ ```bash
255
+ node -e "
256
+ const session = require('./cap/bin/lib/cap-session.cjs');
257
+ session.updateSession(process.cwd(), {
258
+ lastCommand: '/cap:prototype',
259
+ lastCommandTimestamp: new Date().toISOString(),
260
+ step: 'prototype-complete'
261
+ });
262
+ "
263
+ ```
264
+
265
+ ```
266
+ cap:prototype complete ({mode} mode).
267
+
268
+ Features processed: {target_features.length}
269
+ {For each feature: feature.id: feature.title -> {new_state}}
270
+
271
+ Tag scan results:
272
+ Total @cap-* tags: {scan_result.totalTags}
273
+ Features with file refs: {scan_result.featuresEnriched}
274
+
275
+ Next steps:
276
+ - Run /cap:iterate to refine the prototype
277
+ - Run /cap:test to write tests against the ACs
278
+ - Run /cap:scan for detailed tag report
279
+ ```
280
+
281
+ </process>
@@ -0,0 +1,37 @@
1
+ ---
2
+ name: cap:refresh-docs
3
+ description: Fetch or refresh library documentation via Context7 and store in .cap/stack-docs/ for agent context injection.
4
+ argument-hint: "<library-name> [--query \"question\"]"
5
+ allowed-tools:
6
+ - Read
7
+ - Write
8
+ - Bash
9
+ - Glob
10
+ ---
11
+
12
+ <!-- @gsd-context CAP v2.0 refresh-docs command -- fetches library documentation via Context7 CLI and caches it in .cap/stack-docs/. Agents read these docs for library-specific context without burning tokens on web searches. -->
13
+ <!-- @gsd-decision Uses Context7 CLI (npx ctx7@latest) -- the user's CLAUDE.md already mandates Context7 for library docs. This command makes it a first-class workflow step. -->
14
+ <!-- @gsd-decision Docs cached in .cap/stack-docs/ -- persists across conversations, can be committed for offline use. -->
15
+ <!-- @gsd-pattern Each library gets its own file: .cap/stack-docs/{library-name}.md -->
16
+
17
+ <objective>
18
+ Fetches library documentation via Context7 and stores it in .cap/stack-docs/ for agent context injection.
19
+
20
+ **Arguments:**
21
+ - `library-name` -- the library to fetch docs for (e.g., "react", "express", "prisma")
22
+ - `--query "question"` -- specific question to focus the documentation fetch
23
+ </objective>
24
+
25
+ <context>
26
+ $ARGUMENTS
27
+ </context>
28
+
29
+ <process>
30
+
31
+ <!-- @gsd-todo Implement Step 1: Parse library name and optional query -->
32
+ <!-- @gsd-todo Implement Step 2: Run npx ctx7@latest library <name> to find library ID -->
33
+ <!-- @gsd-todo Implement Step 3: Run npx ctx7@latest docs <id> to fetch documentation -->
34
+ <!-- @gsd-todo Implement Step 4: Write fetched docs to .cap/stack-docs/{library-name}.md -->
35
+ <!-- @gsd-todo Implement Step 5: Report what was cached and how agents can use it -->
36
+
37
+ </process>
@@ -0,0 +1,272 @@
1
+ ---
2
+ name: cap:review
3
+ description: Two-stage code review -- Stage 1 checks Feature Map AC compliance, Stage 2 checks code quality. Stage 2 only runs if Stage 1 passes.
4
+ argument-hint: "[--features NAME] [--stage2-only]"
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 review command -- orchestrates two-stage code review. Collects test results, reads Feature Map ACs, spawns cap-reviewer agent. -->
17
+ <!-- @gsd-decision Stage 2 only runs if Stage 1 passes -- prevents wasted review cycles on code that does not meet spec. -->
18
+ <!-- @gsd-decision Review output goes to .cap/REVIEW.md -- centralized under .cap/ runtime directory. -->
19
+
20
+ <objective>
21
+ <!-- @gsd-todo(ref:AC-58) /cap:review shall invoke the cap-reviewer agent for two-stage review. -->
22
+
23
+ Runs two-stage code review:
24
+ 1. Stage 1: Check Feature Map AC compliance (does the code implement what was promised?)
25
+ 2. Stage 2: Check code quality (security, maintainability, error handling)
26
+
27
+ Stage 2 only runs if Stage 1 passes.
28
+
29
+ **Arguments:**
30
+ - `--features NAME` -- scope review to specific Feature Map entries
31
+ - `--stage2-only` -- skip Stage 1, run only code quality review
32
+ </objective>
33
+
34
+ <context>
35
+ $ARGUMENTS
36
+
37
+ @FEATURE-MAP.md
38
+ @.cap/SESSION.json
39
+ </context>
40
+
41
+ <process>
42
+
43
+ ## Step 0: Parse flags
44
+
45
+ Check `$ARGUMENTS` for:
46
+ - `--features NAME` -- if present, store as `feature_filter`
47
+ - `--stage2-only` -- if present, set `stage2_only = true`
48
+
49
+ ## Step 1: Collect test results
50
+
51
+ Run existing tests to get current pass/fail state:
52
+
53
+ ```bash
54
+ node --test tests/*.test.cjs 2>&1 | tail -30
55
+ ```
56
+
57
+ Store output as `test_output` and exit code as `test_exit_code`.
58
+
59
+ ## Step 2: Read Feature Map ACs for review scope
60
+
61
+ <!-- @gsd-todo(ref:AC-59) Stage 1: cap-reviewer shall verify that the implementation satisfies all acceptance criteria listed in the Feature Map entry. -->
62
+
63
+ ```bash
64
+ node -e "
65
+ const fm = require('./cap/bin/lib/cap-feature-map.cjs');
66
+ const session = require('./cap/bin/lib/cap-session.cjs');
67
+ const scanner = require('./cap/bin/lib/cap-tag-scanner.cjs');
68
+ const featureMap = fm.readFeatureMap(process.cwd());
69
+ const s = session.loadSession(process.cwd());
70
+ const tags = scanner.scanDirectory(process.cwd());
71
+ const groups = scanner.groupByFeature(tags);
72
+
73
+ console.log(JSON.stringify({
74
+ activeFeature: s.activeFeature,
75
+ features: featureMap.features.map(f => ({
76
+ id: f.id, title: f.title, state: f.state,
77
+ acs: f.acs, files: f.files
78
+ })),
79
+ tagGroups: Object.fromEntries(
80
+ Object.entries(groups).map(([k, v]) => [k, v.map(t => ({ type: t.type, file: t.file, line: t.line, description: t.description }))])
81
+ )
82
+ }));
83
+ "
84
+ ```
85
+
86
+ **Scope features:**
87
+ - If `feature_filter`: filter to matching IDs
88
+ - Else if active feature: use only that feature
89
+ - Else: use all features with state `tested`
90
+
91
+ Store as `review_features`.
92
+
93
+ ## Step 3: Spawn cap-reviewer for Stage 1 (AC compliance)
94
+
95
+ <!-- @gsd-todo(ref:AC-61) cap-reviewer shall check that all code implementing the feature has appropriate @cap-feature annotations. -->
96
+
97
+ **Skip Stage 1 if `stage2_only`.**
98
+
99
+ Spawn `cap-reviewer` via Task tool:
100
+
101
+ ```
102
+ **STAGE 1: ACCEPTANCE CRITERIA COMPLIANCE**
103
+
104
+ **Features under review:**
105
+ {For each review_feature:}
106
+ Feature: {feature.id} - {feature.title} [{feature.state}]
107
+ Implementation files: {feature.files.join(', ')}
108
+ Acceptance criteria:
109
+ {For each AC:}
110
+ {ac.id}: {ac.description} [{ac.status}]
111
+ {End for}
112
+ {End for}
113
+
114
+ **Tag evidence:**
115
+ {For each feature in tagGroups:}
116
+ {feature_id}: {tags.length} tags across {unique files}
117
+ {End for}
118
+
119
+ **Test results:**
120
+ {test_output}
121
+ Test exit code: {test_exit_code}
122
+
123
+ **Stage 1 checklist:**
124
+ For each AC in each feature under review:
125
+ 1. Is there code that implements this AC?
126
+ 2. Is the implementing code annotated with @cap-feature(feature:{ID})?
127
+ 3. Is there a test that verifies this AC?
128
+ 4. Does the test pass?
129
+
130
+ **Return format:**
131
+ === STAGE 1 RESULTS ===
132
+ VERDICT: PASS | FAIL
133
+ {For each feature:}
134
+ FEATURE: {id}
135
+ {For each AC:}
136
+ {ac.id}: PASS | FAIL | PARTIAL -- {evidence or reason}
137
+ {End for}
138
+ {End for}
139
+ MISSING_ANNOTATIONS: [list of files implementing features without @cap-feature tags]
140
+ === END STAGE 1 RESULTS ===
141
+ ```
142
+
143
+ Parse the Stage 1 results.
144
+
145
+ **If Stage 1 VERDICT is FAIL and NOT `stage2_only`:**
146
+
147
+ Display Stage 1 failures and STOP:
148
+
149
+ ```
150
+ cap:review Stage 1 FAILED.
151
+
152
+ {For each failing AC:}
153
+ {feature.id}/{ac.id}: FAIL -- {reason}
154
+ {End for}
155
+
156
+ {If missing annotations:}
157
+ Missing @cap-feature annotations:
158
+ {For each file: - file}
159
+ {End if}
160
+
161
+ Stage 2 (code quality) skipped -- fix Stage 1 issues first.
162
+ Run /cap:iterate to address gaps, then re-run /cap:review.
163
+ ```
164
+
165
+ ## Step 4: Spawn cap-reviewer for Stage 2 (code quality)
166
+
167
+ <!-- @gsd-todo(ref:AC-60) Stage 2: cap-reviewer shall perform code quality review (naming, structure, complexity, test coverage, tag completeness). -->
168
+
169
+ Spawn `cap-reviewer` via Task tool:
170
+
171
+ ```
172
+ **STAGE 2: CODE QUALITY REVIEW**
173
+
174
+ {If not stage2_only:}
175
+ Stage 1 passed. All ACs verified.
176
+ {End if}
177
+
178
+ **Features under review:**
179
+ {For each review_feature:}
180
+ Feature: {feature.id} - {feature.title}
181
+ Implementation files: {feature.files.join(', ')}
182
+ {End for}
183
+
184
+ **Review checklist:**
185
+ 1. **Naming:** Are function/variable/file names clear and consistent with project conventions?
186
+ 2. **Structure:** Is the code organized logically? Are modules appropriately sized?
187
+ 3. **Complexity:** Are there functions > 50 lines? Deep nesting > 3 levels? Cyclomatic complexity concerns?
188
+ 4. **Error handling:** Are errors handled gracefully? Are edge cases covered?
189
+ 5. **Security:** Any hardcoded credentials, SQL injection vectors, XSS risks, path traversal?
190
+ 6. **Test coverage:** Are critical paths tested? Are error paths tested?
191
+ 7. **Tag completeness:** Does every significant function have @cap-feature annotation?
192
+ 8. **Dependencies:** Are there unnecessary imports or tight coupling between modules?
193
+
194
+ **Return format:**
195
+ === STAGE 2 RESULTS ===
196
+ VERDICT: PASS | PASS_WITH_NOTES | FAIL
197
+ FINDINGS:
198
+ {numbered list of findings with severity: critical/warning/note}
199
+ TOP_5_ACTIONS:
200
+ 1. {actionable improvement}
201
+ 2. ...
202
+ === END STAGE 2 RESULTS ===
203
+ ```
204
+
205
+ Parse Stage 2 results.
206
+
207
+ ## Step 5: Update Feature Map status
208
+
209
+ <!-- @gsd-todo(ref:AC-62) cap-reviewer shall update the feature state in FEATURE-MAP.md from tested to shipped upon passing both review stages. -->
210
+
211
+ If both stages pass (or Stage 1 skipped with `stage2_only` and Stage 2 passes):
212
+
213
+ ```bash
214
+ node -e "
215
+ const fm = require('./cap/bin/lib/cap-feature-map.cjs');
216
+ const targetIds = {JSON.stringify(target_feature_ids)};
217
+ for (const id of targetIds) {
218
+ const result = fm.updateFeatureState(process.cwd(), id, 'shipped');
219
+ console.log(id + ': ' + (result ? 'updated to shipped' : 'state unchanged'));
220
+ }
221
+ "
222
+ ```
223
+
224
+ Write review report:
225
+
226
+ ```bash
227
+ node -e "
228
+ const fs = require('node:fs');
229
+ const path = require('node:path');
230
+ const capDir = path.join(process.cwd(), '.cap');
231
+ if (!fs.existsSync(capDir)) fs.mkdirSync(capDir, { recursive: true });
232
+ // Write review file (content constructed by command layer from parsed results)
233
+ "
234
+ ```
235
+
236
+ Write `.cap/REVIEW.md` using the Write tool with the combined Stage 1 + Stage 2 findings.
237
+
238
+ Update session:
239
+
240
+ ```bash
241
+ node -e "
242
+ const session = require('./cap/bin/lib/cap-session.cjs');
243
+ session.updateSession(process.cwd(), {
244
+ lastCommand: '/cap:review',
245
+ lastCommandTimestamp: new Date().toISOString(),
246
+ step: 'review-complete'
247
+ });
248
+ "
249
+ ```
250
+
251
+ ## Step 6: Final report
252
+
253
+ ```
254
+ cap:review complete.
255
+
256
+ Stage 1 (AC compliance): {PASS or FAIL or SKIPPED}
257
+ Stage 2 (Code quality): {PASS or PASS_WITH_NOTES or FAIL}
258
+
259
+ {If both pass:}
260
+ Feature state updated: {feature_ids} -> shipped
261
+ Review report: .cap/REVIEW.md
262
+
263
+ Top 5 actions:
264
+ {top_5_actions}
265
+ {End if}
266
+
267
+ {If stage 2 has notes:}
268
+ Review passed with notes. See .cap/REVIEW.md for details.
269
+ {End if}
270
+ ```
271
+
272
+ </process>