cap-pro 1.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 (275) hide show
  1. package/.claude-plugin/README.md +26 -0
  2. package/.claude-plugin/marketplace.json +24 -0
  3. package/.claude-plugin/plugin.json +24 -0
  4. package/LICENSE +21 -0
  5. package/README.ja-JP.md +834 -0
  6. package/README.ko-KR.md +823 -0
  7. package/README.md +806 -0
  8. package/README.pt-BR.md +452 -0
  9. package/README.zh-CN.md +800 -0
  10. package/agents/cap-architect.md +269 -0
  11. package/agents/cap-brainstormer.md +207 -0
  12. package/agents/cap-curator.md +276 -0
  13. package/agents/cap-debugger.md +365 -0
  14. package/agents/cap-designer.md +246 -0
  15. package/agents/cap-historian.md +464 -0
  16. package/agents/cap-migrator.md +291 -0
  17. package/agents/cap-prototyper.md +197 -0
  18. package/agents/cap-validator.md +308 -0
  19. package/bin/install.js +5433 -0
  20. package/cap/bin/cap-tools.cjs +853 -0
  21. package/cap/bin/lib/arc-scanner.cjs +344 -0
  22. package/cap/bin/lib/cap-affinity-engine.cjs +862 -0
  23. package/cap/bin/lib/cap-anchor.cjs +228 -0
  24. package/cap/bin/lib/cap-annotation-writer.cjs +340 -0
  25. package/cap/bin/lib/cap-checkpoint.cjs +434 -0
  26. package/cap/bin/lib/cap-cluster-detect.cjs +945 -0
  27. package/cap/bin/lib/cap-cluster-display.cjs +52 -0
  28. package/cap/bin/lib/cap-cluster-format.cjs +245 -0
  29. package/cap/bin/lib/cap-cluster-helpers.cjs +295 -0
  30. package/cap/bin/lib/cap-cluster-io.cjs +212 -0
  31. package/cap/bin/lib/cap-completeness.cjs +540 -0
  32. package/cap/bin/lib/cap-deps.cjs +583 -0
  33. package/cap/bin/lib/cap-design-families.cjs +332 -0
  34. package/cap/bin/lib/cap-design.cjs +966 -0
  35. package/cap/bin/lib/cap-divergence-detector.cjs +400 -0
  36. package/cap/bin/lib/cap-doctor.cjs +752 -0
  37. package/cap/bin/lib/cap-feature-map-internals.cjs +19 -0
  38. package/cap/bin/lib/cap-feature-map-migrate.cjs +335 -0
  39. package/cap/bin/lib/cap-feature-map-monorepo.cjs +885 -0
  40. package/cap/bin/lib/cap-feature-map-shard.cjs +315 -0
  41. package/cap/bin/lib/cap-feature-map.cjs +1943 -0
  42. package/cap/bin/lib/cap-fitness-score.cjs +1075 -0
  43. package/cap/bin/lib/cap-impact-analysis.cjs +652 -0
  44. package/cap/bin/lib/cap-learn-review.cjs +1072 -0
  45. package/cap/bin/lib/cap-learning-signals.cjs +627 -0
  46. package/cap/bin/lib/cap-loader.cjs +227 -0
  47. package/cap/bin/lib/cap-logger.cjs +57 -0
  48. package/cap/bin/lib/cap-memory-bridge.cjs +764 -0
  49. package/cap/bin/lib/cap-memory-confidence.cjs +452 -0
  50. package/cap/bin/lib/cap-memory-dir.cjs +987 -0
  51. package/cap/bin/lib/cap-memory-engine.cjs +698 -0
  52. package/cap/bin/lib/cap-memory-extends.cjs +398 -0
  53. package/cap/bin/lib/cap-memory-graph.cjs +790 -0
  54. package/cap/bin/lib/cap-memory-migrate.cjs +2015 -0
  55. package/cap/bin/lib/cap-memory-pin.cjs +183 -0
  56. package/cap/bin/lib/cap-memory-platform.cjs +490 -0
  57. package/cap/bin/lib/cap-memory-prune.cjs +707 -0
  58. package/cap/bin/lib/cap-memory-schema.cjs +812 -0
  59. package/cap/bin/lib/cap-migrate-tags.cjs +309 -0
  60. package/cap/bin/lib/cap-migrate.cjs +540 -0
  61. package/cap/bin/lib/cap-pattern-apply.cjs +1203 -0
  62. package/cap/bin/lib/cap-pattern-pipeline.cjs +1034 -0
  63. package/cap/bin/lib/cap-plugin-manifest.cjs +80 -0
  64. package/cap/bin/lib/cap-realtime-affinity.cjs +399 -0
  65. package/cap/bin/lib/cap-reconcile.cjs +570 -0
  66. package/cap/bin/lib/cap-research-gate.cjs +218 -0
  67. package/cap/bin/lib/cap-scope-filter.cjs +402 -0
  68. package/cap/bin/lib/cap-semantic-pipeline.cjs +1038 -0
  69. package/cap/bin/lib/cap-session-extract.cjs +987 -0
  70. package/cap/bin/lib/cap-session.cjs +445 -0
  71. package/cap/bin/lib/cap-snapshot-linkage.cjs +963 -0
  72. package/cap/bin/lib/cap-stack-docs.cjs +646 -0
  73. package/cap/bin/lib/cap-tag-observer.cjs +371 -0
  74. package/cap/bin/lib/cap-tag-scanner.cjs +1766 -0
  75. package/cap/bin/lib/cap-telemetry.cjs +466 -0
  76. package/cap/bin/lib/cap-test-audit.cjs +1438 -0
  77. package/cap/bin/lib/cap-thread-migrator.cjs +307 -0
  78. package/cap/bin/lib/cap-thread-synthesis.cjs +545 -0
  79. package/cap/bin/lib/cap-thread-tracker.cjs +519 -0
  80. package/cap/bin/lib/cap-trace.cjs +399 -0
  81. package/cap/bin/lib/cap-trust-mode.cjs +336 -0
  82. package/cap/bin/lib/cap-ui-design-editor.cjs +642 -0
  83. package/cap/bin/lib/cap-ui-mind-map.cjs +712 -0
  84. package/cap/bin/lib/cap-ui-thread-nav.cjs +693 -0
  85. package/cap/bin/lib/cap-ui.cjs +1245 -0
  86. package/cap/bin/lib/cap-upgrade.cjs +1028 -0
  87. package/cap/bin/lib/cli/arg-helpers.cjs +49 -0
  88. package/cap/bin/lib/cli/frontmatter-router.cjs +31 -0
  89. package/cap/bin/lib/cli/init-router.cjs +68 -0
  90. package/cap/bin/lib/cli/phase-router.cjs +102 -0
  91. package/cap/bin/lib/cli/state-router.cjs +61 -0
  92. package/cap/bin/lib/cli/template-router.cjs +37 -0
  93. package/cap/bin/lib/cli/uat-router.cjs +29 -0
  94. package/cap/bin/lib/cli/validation-router.cjs +26 -0
  95. package/cap/bin/lib/cli/verification-router.cjs +31 -0
  96. package/cap/bin/lib/cli/workstream-router.cjs +39 -0
  97. package/cap/bin/lib/commands.cjs +961 -0
  98. package/cap/bin/lib/config.cjs +467 -0
  99. package/cap/bin/lib/convention-reader.cjs +258 -0
  100. package/cap/bin/lib/core.cjs +1241 -0
  101. package/cap/bin/lib/feature-aggregator.cjs +423 -0
  102. package/cap/bin/lib/frontmatter.cjs +337 -0
  103. package/cap/bin/lib/init.cjs +1443 -0
  104. package/cap/bin/lib/manifest-generator.cjs +383 -0
  105. package/cap/bin/lib/milestone.cjs +253 -0
  106. package/cap/bin/lib/model-profiles.cjs +69 -0
  107. package/cap/bin/lib/monorepo-context.cjs +226 -0
  108. package/cap/bin/lib/monorepo-migrator.cjs +509 -0
  109. package/cap/bin/lib/phase.cjs +889 -0
  110. package/cap/bin/lib/profile-output.cjs +989 -0
  111. package/cap/bin/lib/profile-pipeline.cjs +540 -0
  112. package/cap/bin/lib/roadmap.cjs +330 -0
  113. package/cap/bin/lib/security.cjs +394 -0
  114. package/cap/bin/lib/session-manager.cjs +292 -0
  115. package/cap/bin/lib/skeleton-generator.cjs +179 -0
  116. package/cap/bin/lib/state.cjs +1032 -0
  117. package/cap/bin/lib/template.cjs +231 -0
  118. package/cap/bin/lib/test-detector.cjs +62 -0
  119. package/cap/bin/lib/uat.cjs +283 -0
  120. package/cap/bin/lib/verify.cjs +889 -0
  121. package/cap/bin/lib/workspace-detector.cjs +371 -0
  122. package/cap/bin/lib/workstream.cjs +492 -0
  123. package/cap/commands/gsd/workstreams.md +63 -0
  124. package/cap/references/arc-standard.md +315 -0
  125. package/cap/references/cap-agent-architecture.md +101 -0
  126. package/cap/references/cap-gitignore-template +9 -0
  127. package/cap/references/cap-zero-deps.md +158 -0
  128. package/cap/references/checkpoints.md +778 -0
  129. package/cap/references/continuation-format.md +249 -0
  130. package/cap/references/contract-test-templates.md +312 -0
  131. package/cap/references/feature-map-template.md +25 -0
  132. package/cap/references/git-integration.md +295 -0
  133. package/cap/references/git-planning-commit.md +38 -0
  134. package/cap/references/model-profiles.md +174 -0
  135. package/cap/references/phase-numbering.md +126 -0
  136. package/cap/references/planning-config.md +202 -0
  137. package/cap/references/property-test-templates.md +316 -0
  138. package/cap/references/security-test-templates.md +347 -0
  139. package/cap/references/session-template.json +8 -0
  140. package/cap/references/tdd.md +263 -0
  141. package/cap/references/user-profiling.md +681 -0
  142. package/cap/references/verification-patterns.md +612 -0
  143. package/cap/templates/UAT.md +265 -0
  144. package/cap/templates/claude-md.md +175 -0
  145. package/cap/templates/codebase/architecture.md +255 -0
  146. package/cap/templates/codebase/concerns.md +310 -0
  147. package/cap/templates/codebase/conventions.md +307 -0
  148. package/cap/templates/codebase/integrations.md +280 -0
  149. package/cap/templates/codebase/stack.md +186 -0
  150. package/cap/templates/codebase/structure.md +285 -0
  151. package/cap/templates/codebase/testing.md +480 -0
  152. package/cap/templates/config.json +44 -0
  153. package/cap/templates/context.md +352 -0
  154. package/cap/templates/continue-here.md +78 -0
  155. package/cap/templates/copilot-instructions.md +7 -0
  156. package/cap/templates/debug-subagent-prompt.md +91 -0
  157. package/cap/templates/discussion-log.md +63 -0
  158. package/cap/templates/milestone-archive.md +123 -0
  159. package/cap/templates/milestone.md +115 -0
  160. package/cap/templates/phase-prompt.md +610 -0
  161. package/cap/templates/planner-subagent-prompt.md +117 -0
  162. package/cap/templates/project.md +186 -0
  163. package/cap/templates/requirements.md +231 -0
  164. package/cap/templates/research-project/ARCHITECTURE.md +204 -0
  165. package/cap/templates/research-project/FEATURES.md +147 -0
  166. package/cap/templates/research-project/PITFALLS.md +200 -0
  167. package/cap/templates/research-project/STACK.md +120 -0
  168. package/cap/templates/research-project/SUMMARY.md +170 -0
  169. package/cap/templates/research.md +552 -0
  170. package/cap/templates/roadmap.md +202 -0
  171. package/cap/templates/state.md +176 -0
  172. package/cap/templates/summary.md +364 -0
  173. package/cap/templates/user-preferences.md +498 -0
  174. package/cap/templates/verification-report.md +322 -0
  175. package/cap/workflows/add-phase.md +112 -0
  176. package/cap/workflows/add-tests.md +351 -0
  177. package/cap/workflows/add-todo.md +158 -0
  178. package/cap/workflows/audit-milestone.md +340 -0
  179. package/cap/workflows/audit-uat.md +109 -0
  180. package/cap/workflows/autonomous.md +891 -0
  181. package/cap/workflows/check-todos.md +177 -0
  182. package/cap/workflows/cleanup.md +152 -0
  183. package/cap/workflows/complete-milestone.md +767 -0
  184. package/cap/workflows/diagnose-issues.md +231 -0
  185. package/cap/workflows/discovery-phase.md +289 -0
  186. package/cap/workflows/discuss-phase-assumptions.md +653 -0
  187. package/cap/workflows/discuss-phase.md +1049 -0
  188. package/cap/workflows/do.md +104 -0
  189. package/cap/workflows/execute-phase.md +846 -0
  190. package/cap/workflows/execute-plan.md +514 -0
  191. package/cap/workflows/fast.md +105 -0
  192. package/cap/workflows/forensics.md +265 -0
  193. package/cap/workflows/health.md +181 -0
  194. package/cap/workflows/help.md +660 -0
  195. package/cap/workflows/insert-phase.md +130 -0
  196. package/cap/workflows/list-phase-assumptions.md +178 -0
  197. package/cap/workflows/list-workspaces.md +56 -0
  198. package/cap/workflows/manager.md +362 -0
  199. package/cap/workflows/map-codebase.md +377 -0
  200. package/cap/workflows/milestone-summary.md +223 -0
  201. package/cap/workflows/new-milestone.md +486 -0
  202. package/cap/workflows/new-project.md +1250 -0
  203. package/cap/workflows/new-workspace.md +237 -0
  204. package/cap/workflows/next.md +97 -0
  205. package/cap/workflows/node-repair.md +92 -0
  206. package/cap/workflows/note.md +156 -0
  207. package/cap/workflows/pause-work.md +176 -0
  208. package/cap/workflows/plan-milestone-gaps.md +273 -0
  209. package/cap/workflows/plan-phase.md +857 -0
  210. package/cap/workflows/plant-seed.md +169 -0
  211. package/cap/workflows/pr-branch.md +129 -0
  212. package/cap/workflows/profile-user.md +449 -0
  213. package/cap/workflows/progress.md +507 -0
  214. package/cap/workflows/quick.md +757 -0
  215. package/cap/workflows/remove-phase.md +155 -0
  216. package/cap/workflows/remove-workspace.md +90 -0
  217. package/cap/workflows/research-phase.md +82 -0
  218. package/cap/workflows/resume-project.md +326 -0
  219. package/cap/workflows/review.md +228 -0
  220. package/cap/workflows/session-report.md +146 -0
  221. package/cap/workflows/settings.md +283 -0
  222. package/cap/workflows/ship.md +228 -0
  223. package/cap/workflows/stats.md +60 -0
  224. package/cap/workflows/transition.md +671 -0
  225. package/cap/workflows/ui-phase.md +298 -0
  226. package/cap/workflows/ui-review.md +161 -0
  227. package/cap/workflows/update.md +323 -0
  228. package/cap/workflows/validate-phase.md +170 -0
  229. package/cap/workflows/verify-phase.md +254 -0
  230. package/cap/workflows/verify-work.md +637 -0
  231. package/commands/cap/annotate.md +165 -0
  232. package/commands/cap/brainstorm.md +393 -0
  233. package/commands/cap/checkpoint.md +106 -0
  234. package/commands/cap/completeness.md +94 -0
  235. package/commands/cap/continue.md +72 -0
  236. package/commands/cap/debug.md +588 -0
  237. package/commands/cap/deps.md +169 -0
  238. package/commands/cap/design.md +479 -0
  239. package/commands/cap/init.md +354 -0
  240. package/commands/cap/iterate.md +249 -0
  241. package/commands/cap/learn.md +459 -0
  242. package/commands/cap/memory.md +275 -0
  243. package/commands/cap/migrate-feature-map.md +91 -0
  244. package/commands/cap/migrate-memory.md +108 -0
  245. package/commands/cap/migrate-tags.md +91 -0
  246. package/commands/cap/migrate.md +131 -0
  247. package/commands/cap/prototype.md +510 -0
  248. package/commands/cap/reconcile.md +121 -0
  249. package/commands/cap/review.md +360 -0
  250. package/commands/cap/save.md +72 -0
  251. package/commands/cap/scan.md +404 -0
  252. package/commands/cap/start.md +356 -0
  253. package/commands/cap/status.md +118 -0
  254. package/commands/cap/test-audit.md +262 -0
  255. package/commands/cap/test.md +394 -0
  256. package/commands/cap/trace.md +133 -0
  257. package/commands/cap/ui.md +167 -0
  258. package/hooks/dist/cap-check-update.js +115 -0
  259. package/hooks/dist/cap-context-monitor.js +185 -0
  260. package/hooks/dist/cap-learn-review-hook.js +114 -0
  261. package/hooks/dist/cap-learning-hook.js +192 -0
  262. package/hooks/dist/cap-memory.js +299 -0
  263. package/hooks/dist/cap-prompt-guard.js +97 -0
  264. package/hooks/dist/cap-statusline.js +157 -0
  265. package/hooks/dist/cap-tag-observer.js +115 -0
  266. package/hooks/dist/cap-version-check.js +112 -0
  267. package/hooks/dist/cap-workflow-guard.js +175 -0
  268. package/hooks/hooks.json +55 -0
  269. package/package.json +58 -0
  270. package/scripts/base64-scan.sh +262 -0
  271. package/scripts/build-hooks.js +93 -0
  272. package/scripts/cap-removal-checklist.md +202 -0
  273. package/scripts/prompt-injection-scan.sh +199 -0
  274. package/scripts/run-tests.cjs +181 -0
  275. 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
+ <!-- @cap-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
+ <!-- @cap-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
+ <!-- @cap-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
+ <!-- @cap-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,393 @@
1
+ ---
2
+ name: cap:brainstorm
3
+ description: Interactive feature discovery — produces FEATURE-MAP.md entries (acceptance criteria, dependencies, feature grouping) from a structured conversation. TRIGGER when the user wants to plan a new feature, says "let's add X / build Y / we need a feature for Z", describes a problem without concrete ACs yet, references a Feature ID that doesn't exist in FEATURE-MAP.md, or asks "what should we build next". DO NOT trigger for refining an existing feature (use cap:iterate) or bug fixes (use cap:debug). 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
+ <!-- @cap-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
+ <!-- @cap-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
+ <!-- @cap-decision Command layer owns all file I/O -- agent is stateless. Proven pattern from GSD brainstorm.md. -->
19
+ <!-- @cap-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
+ <!-- @cap-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
+ // @cap-todo(ac:F-081/AC-4 iter:2) Migrated to {safe: true} opt-in to preserve CLI on duplicate-ID FEATURE-MAP.
58
+ // @cap-decision(F-081/iter2) Warn on parseError; continue with partial map for read-only display.
59
+ const featureMap = fm.readFeatureMap(process.cwd(), undefined, { safe: true });
60
+ if (featureMap && featureMap.parseError) {
61
+ console.warn('cap: brainstorm — duplicate feature ID detected, existing-features list uses partial map: ' + String(featureMap.parseError.message).trim());
62
+ }
63
+ console.log(JSON.stringify({
64
+ featureCount: featureMap.features.length,
65
+ existingIds: featureMap.features.map(f => f.id),
66
+ existingTitles: featureMap.features.map(f => f.title)
67
+ }));
68
+ "
69
+ ```
70
+
71
+ Store as `existing_features`.
72
+
73
+ If `resume_mode`:
74
+
75
+ ```bash
76
+ node -e "
77
+ const session = require('./cap/bin/lib/cap-session.cjs');
78
+ const s = session.loadSession(process.cwd());
79
+ console.log(JSON.stringify(s));
80
+ "
81
+ ```
82
+
83
+ Store as `session_context`.
84
+
85
+ ## Step 1b: Check for prior brainstorm threads
86
+
87
+ Check if the user's topic has been explored before. This gives the brainstormer context about prior discussions.
88
+
89
+ ```bash
90
+ node -e "
91
+ const tracker = require('./cap/bin/lib/cap-thread-tracker.cjs');
92
+ const threads = tracker.listThreads(process.cwd());
93
+ console.log(JSON.stringify({ threadCount: threads.length, threads: threads.slice(0, 10) }));
94
+ "
95
+ ```
96
+
97
+ Store as `prior_threads`.
98
+
99
+ If `resume_mode` and `session_context.activeThread`:
100
+
101
+ ```bash
102
+ node -e "
103
+ const tracker = require('./cap/bin/lib/cap-thread-tracker.cjs');
104
+ const thread = tracker.loadThread(process.cwd(), '{session_context.activeThread}');
105
+ console.log(JSON.stringify(thread));
106
+ "
107
+ ```
108
+
109
+ Store as `resume_thread`. This is the thread from the previous brainstorm session to continue.
110
+
111
+ If `prior_threads.threadCount > 0` and NOT `resume_mode`:
112
+ - Display prior threads briefly:
113
+ ```
114
+ Found {threadCount} prior brainstorm thread(s):
115
+ {For each thread:}
116
+ - {thread.name} ({thread.timestamp}) — features: {thread.featureIds.join(', ') || 'none'}
117
+ {End for}
118
+ ```
119
+ - The brainstormer agent will receive this context and can reference prior threads during conversation.
120
+
121
+ ## Step 1c: Passively check thread affinity before brainstorm
122
+
123
+ <!-- @cap-todo(ac:F-040/AC-5) /cap:brainstorm passively checks thread affinity at session start and presents relevant prior threads (notify band and above) before beginning discovery questions -->
124
+
125
+ If prior threads exist, check realtime affinity to surface relevant ones:
126
+
127
+ ```bash
128
+ node -e "
129
+ const realtimeAffinity = require('./cap/bin/lib/cap-realtime-affinity.cjs');
130
+ const clusterDisplay = require('./cap/bin/lib/cap-cluster-display.cjs');
131
+ const tracker = require('./cap/bin/lib/cap-thread-tracker.cjs');
132
+ const session = require('./cap/bin/lib/cap-session.cjs');
133
+
134
+ try {
135
+ const threads = tracker.listThreads(process.cwd());
136
+ if (threads.length > 0) {
137
+ const s = session.loadSession(process.cwd());
138
+ // Use the most recent thread as reference point for affinity detection
139
+ const latestThread = threads[0];
140
+ const fullThread = tracker.loadThread(process.cwd(), latestThread.id);
141
+ if (fullThread) {
142
+ const notifications = realtimeAffinity.onSessionStart(process.cwd(), fullThread);
143
+ const output = clusterDisplay.formatRealtimeNotifications(notifications);
144
+ if (output) console.log(output);
145
+ else console.log('');
146
+ } else {
147
+ console.log('');
148
+ }
149
+ } else {
150
+ console.log('');
151
+ }
152
+ } catch (e) {
153
+ console.log('');
154
+ }
155
+ "
156
+ ```
157
+
158
+ If output is non-empty, display it before spawning the brainstormer:
159
+
160
+ ```
161
+ {thread_affinity_output}
162
+ ```
163
+
164
+ This gives the user awareness of related prior discussions before beginning a new brainstorm.
165
+
166
+ ## Step 2: Spawn cap-brainstormer agent
167
+
168
+ <!-- @cap-todo(ref:AC-37) cap-brainstormer shall produce structured PRD output with numbered acceptance criteria. -->
169
+ <!-- @cap-todo(ref:AC-39) cap-brainstormer shall assign feature IDs in sequential format (F-001, F-002, ...). -->
170
+
171
+ Spawn `cap-brainstormer` via the Task tool with the following context:
172
+
173
+ ```
174
+ $ARGUMENTS
175
+
176
+ **Session context:**
177
+ Resume mode: {resume_mode}
178
+ Multi-feature hint: {multi_mode}
179
+ Existing features: {existing_features.featureCount} features already in FEATURE-MAP.md
180
+ Existing IDs: {existing_features.existingIds}
181
+ Next available ID: F-{padded next number}
182
+
183
+ {If resume_mode and resume_thread:}
184
+ **Resuming prior thread:**
185
+ Thread ID: {resume_thread.id}
186
+ Thread name: {resume_thread.name}
187
+ Problem statement: {resume_thread.problemStatement}
188
+ Solution shape: {resume_thread.solutionShape}
189
+ Boundary decisions: {resume_thread.boundaryDecisions}
190
+ Prior feature IDs: {resume_thread.featureIds}
191
+ {End if}
192
+
193
+ {If prior_threads.threadCount > 0 and NOT resume_mode:}
194
+ **Prior brainstorm threads (for reference):**
195
+ {For each thread in prior_threads.threads:}
196
+ - {thread.name} ({thread.timestamp}) — keywords: {thread.keywords.slice(0,8).join(', ')} — features: {thread.featureIds.join(', ') || 'none'}
197
+ {End for}
198
+ NOTE: If the user's topic overlaps with a prior thread, reference it. Ask if they want to continue that line of thinking or explore something new.
199
+ {End if}
200
+
201
+ {If resume_mode and session_context and NOT resume_thread:}
202
+ **Previous session context (no thread found):**
203
+ Active feature: {session_context.activeFeature}
204
+ Last step: {session_context.step}
205
+ Last command: {session_context.lastCommand}
206
+ {End if}
207
+
208
+ **Instructions:**
209
+ 1. Have a conversational exchange with the user to understand what needs to be built
210
+ 2. Ask targeted questions ONE AT A TIME -- do not present a list of questions
211
+ 3. After sufficient understanding, cluster features into logical groups
212
+ 4. Surface dependencies between feature groups
213
+ 5. For each feature, draft numbered acceptance criteria in imperative form
214
+ 6. Assign feature IDs:
215
+ - For single-app projects: sequential `F-NNN` starting from {next available ID}
216
+ - For monorepo projects (apps/* or workspace packages > 1): prefer descriptive `F-<App>-<Slug>` IDs (e.g., `F-Hub-Spotlight-Carousel`). Detect monorepo: presence of `apps/` directory or `package.json:workspaces`. Both formats may coexist.
217
+ 7. Return the feature entries in the exact structured format below
218
+
219
+ **Return format (delimited):**
220
+
221
+ === BRAINSTORM OUTPUT ===
222
+ FEATURE_COUNT: N
223
+
224
+ === FEATURE: F-NNN ===
225
+ TITLE: {verb+object title}
226
+ GROUP: {logical group name}
227
+ DEPENDS_ON: {comma-separated F-IDs or "none"}
228
+ AC-1: {imperative description}
229
+ AC-2: {imperative description}
230
+ ...
231
+ === END FEATURE ===
232
+
233
+ {Repeat for each feature}
234
+
235
+ === DECISIONS ===
236
+ - {decision 1}
237
+ - {decision 2}
238
+ === END DECISIONS ===
239
+
240
+ === END BRAINSTORM OUTPUT ===
241
+
242
+ Do NOT write any files -- return structured output only.
243
+ ```
244
+
245
+ Wait for `cap-brainstormer` to complete.
246
+
247
+ **Parse the agent output:**
248
+
249
+ 1. Extract between `=== BRAINSTORM OUTPUT ===` and `=== END BRAINSTORM OUTPUT ===`
250
+ 2. Parse `FEATURE_COUNT:` line
251
+ 3. For each `=== FEATURE: F-NNN ===` block, extract: TITLE, GROUP, DEPENDS_ON, and all AC-N lines
252
+ 4. Extract decisions from `=== DECISIONS ===` block
253
+ 5. Build Feature objects:
254
+
255
+ ```javascript
256
+ {
257
+ id: "F-NNN",
258
+ title: "extracted title",
259
+ state: "planned",
260
+ acs: [{ id: "AC-1", description: "...", status: "pending" }, ...],
261
+ files: [],
262
+ dependencies: ["F-NNN", ...],
263
+ metadata: { group: "group name" }
264
+ }
265
+ ```
266
+
267
+ ## Step 3: Present features for user approval
268
+
269
+ <!-- @cap-todo(ref:AC-38) cap-brainstormer shall write discovered features directly to FEATURE-MAP.md with state planned. -->
270
+ <!-- @cap-todo(ref:AC-40) cap-brainstormer output shall be directly consumable by /cap:prototype without manual translation. -->
271
+
272
+ Display the parsed features:
273
+
274
+ ```
275
+ Brainstorm complete. {feature_count} features discovered:
276
+
277
+ {For each feature:}
278
+ {feature.id}: {feature.title} [{feature.state}]
279
+ Group: {group}
280
+ Dependencies: {deps or "none"}
281
+ Acceptance criteria:
282
+ AC-1: {description}
283
+ AC-2: {description}
284
+ ...
285
+ {End for}
286
+
287
+ Decisions made:
288
+ {For each decision:}
289
+ - {decision}
290
+ {End for}
291
+ ```
292
+
293
+ Use AskUserQuestion:
294
+ > "Review the {feature_count} features above. Approve writing to FEATURE-MAP.md? [yes / provide corrections / restart]"
295
+
296
+ - If `yes`, `y`, or `approve`: proceed to Step 4
297
+ - If corrections: Re-spawn `cap-brainstormer` with original context + `**Corrections from user:** {user text}`. Re-parse and re-display. Loop back to approval gate.
298
+ - If `restart`: Clear all parsed data. Go back to Step 2 with fresh Task() call.
299
+
300
+ **IMPORTANT:** No code path reaches Step 4 without explicit user approval.
301
+
302
+ ## Step 4: Write approved features to FEATURE-MAP.md
303
+
304
+ ```bash
305
+ node -e "
306
+ const fm = require('./cap/bin/lib/cap-feature-map.cjs');
307
+ // @cap-todo(ac:F-081/AC-4 iter:2) Migrated to {safe: true} opt-in to preserve CLI on duplicate-ID FEATURE-MAP.
308
+ // @cap-decision(F-081/iter2) Bail on parseError — do not persist partial enrichment (write-back path).
309
+ const featureMap = fm.readFeatureMap(process.cwd(), undefined, { safe: true });
310
+ if (featureMap && featureMap.parseError) {
311
+ console.error('cap: brainstorm write aborted — duplicate feature ID detected: ' + String(featureMap.parseError.message).trim());
312
+ process.exit(2);
313
+ }
314
+ const newFeatures = {JSON.stringify(parsed_features)};
315
+ const updated = fm.addFeatures(featureMap, newFeatures);
316
+ fm.writeFeatureMap(process.cwd(), updated);
317
+ console.log('Written ' + newFeatures.length + ' features to FEATURE-MAP.md');
318
+ "
319
+ ```
320
+
321
+ ## Step 5: Persist brainstorm thread
322
+
323
+ Save this brainstorm session as a conversation thread. This enables future sessions to reference prior discussions.
324
+
325
+ Build the thread from the brainstorm results:
326
+ - `problemStatement`: The user's initial problem or topic (from the conversation)
327
+ - `solutionShape`: The high-level approach that emerged
328
+ - `boundaryDecisions`: Key scope decisions from the `=== DECISIONS ===` block
329
+ - `featureIds`: The IDs of features written to the Feature Map
330
+
331
+ ```bash
332
+ node -e "
333
+ const tracker = require('./cap/bin/lib/cap-thread-tracker.cjs');
334
+ const resumeThreadId = '{resume_thread?.id || null}';
335
+ const parentThread = resumeThreadId !== 'null' ? tracker.loadThread(process.cwd(), resumeThreadId) : null;
336
+
337
+ const threadParams = {
338
+ problemStatement: '{problem_statement from conversation}',
339
+ solutionShape: '{solution_shape from conversation}',
340
+ boundaryDecisions: {JSON.stringify(decisions_from_brainstorm)},
341
+ featureIds: {JSON.stringify(feature_ids_written)},
342
+ };
343
+
344
+ let thread;
345
+ if (parentThread) {
346
+ // Branching from resumed thread
347
+ thread = tracker.branchThread(parentThread, {
348
+ ...threadParams,
349
+ divergencePoint: 'Continued from prior session'
350
+ });
351
+ } else {
352
+ thread = tracker.createThread(threadParams);
353
+ }
354
+
355
+ tracker.persistThread(process.cwd(), thread);
356
+ console.log(JSON.stringify({ threadId: thread.id, threadName: thread.name }));
357
+ "
358
+ ```
359
+
360
+ Store as `persisted_thread`.
361
+
362
+ ## Step 5b: Update session state
363
+
364
+ ```bash
365
+ node -e "
366
+ const session = require('./cap/bin/lib/cap-session.cjs');
367
+ session.updateSession(process.cwd(), {
368
+ lastCommand: '/cap:brainstorm',
369
+ lastCommandTimestamp: new Date().toISOString(),
370
+ step: 'brainstorm-complete',
371
+ activeThread: '{persisted_thread.threadId}'
372
+ });
373
+ "
374
+ ```
375
+
376
+ ## Step 6: Final report
377
+
378
+ ```
379
+ cap:brainstorm complete.
380
+
381
+ Features written to FEATURE-MAP.md: {feature_count}
382
+ {For each feature: feature.id: feature.title}
383
+
384
+ Decisions recorded: {decision_count}
385
+ Thread saved: {persisted_thread.threadName} ({persisted_thread.threadId})
386
+
387
+ Next steps:
388
+ - Run /cap:start to select a feature to work on
389
+ - Run /cap:prototype --features {first_feature_id} to build initial code
390
+ - Run /cap:brainstorm --resume to continue this thread later
391
+ ```
392
+
393
+ </process>
@@ -0,0 +1,106 @@
1
+ ---
2
+ name: cap:checkpoint
3
+ description: Advisory checkpoint detection — nudges /compact at natural breakpoints, saves a labeled snapshot via cap-historian before the context fills up.
4
+ argument-hint: ""
5
+ allowed-tools:
6
+ - Task
7
+ - Bash
8
+ - Read
9
+ - Write
10
+ ---
11
+
12
+ <!-- @cap-feature(feature:F-057) Checkpoint Command for Strategic Compact -->
13
+ <!-- @cap-todo(ac:F-057/AC-1) /cap:checkpoint ist aufrufbar — this file registers the slash command. -->
14
+ <!-- @cap-todo(ac:F-057/AC-2) Command prueft SESSION.json (step-Transitions, AC-Status-Updates) und FEATURE-MAP-Diff seit letzter Checkpoint-Zeit auf logische Breakpoints. Delegated to cap-checkpoint.analyzeAndApply(). -->
15
+ <!-- @cap-todo(ac:F-057/AC-3) Bei erkanntem Breakpoint gibt Command Empfehlung aus: "Jetzt /compact, weil {konkreter Grund}". -->
16
+ <!-- @cap-todo(ac:F-057/AC-4) Bei erkanntem Breakpoint wird vor der Empfehlung implizit ein Snapshot mit Label `checkpoint-{feature_id}` angelegt. -->
17
+ <!-- @cap-decision Breakpoint-Heuristik bleibt in cap-checkpoint.cjs (analyzeAndApply). Die Save-Aktion wurde von "/cap:save chained" auf "Task() → cap-historian MODE: SAVE" umgestellt — gleiches Outcome (Snapshot in .cap/snapshots/), zusätzlich JSONL-Index-Eintrag. -->
18
+ <!-- @cap-todo(ac:F-057/AC-6) /cap:checkpoint bleibt advisory: KEIN Auto-/compact, KEIN --force-Flag. User entscheidet. -->
19
+ <!-- @cap-todo(ac:F-057/AC-5) Kein Breakpoint erkannt -> Message "Kein natürlicher Kontextbruch erkannt.", keine weitere Action. -->
20
+
21
+ <objective>
22
+ Detect natural breakpoints in the CAP workflow and nudge the user toward `/compact` before auto-compact degrades context quality. When a breakpoint is detected, the command first writes a `checkpoint-{feature_id}` snapshot via the cap-historian agent.
23
+
24
+ **Purely advisory.** Never runs `/compact` itself. No `--force` flag. The user decides.
25
+ </objective>
26
+
27
+ <process>
28
+
29
+ ## Step 1: Analyze and persist breakpoint state
30
+
31
+ `analyzeAndApply` reads SESSION.json and FEATURE-MAP.md, computes the plan, and — if a breakpoint was detected — persists `lastCheckpointAt` + `lastCheckpointSnapshot` in a single Node call (closes the TOCTOU window).
32
+
33
+ ```bash
34
+ node -e "
35
+ const capCheckpoint = require('./cap/bin/lib/cap-checkpoint.cjs');
36
+ const result = capCheckpoint.analyzeAndApply(process.cwd());
37
+ console.log(JSON.stringify(result, null, 2));
38
+ "
39
+ ```
40
+
41
+ Output shape:
42
+
43
+ ```
44
+ {
45
+ "breakpoint": { "kind": "...", "featureId": "F-057", "reason": "..." } | null,
46
+ "plan": {
47
+ "shouldSave": true | false,
48
+ "saveLabel": "checkpoint-F-057" | null,
49
+ "message": "Jetzt /compact, weil ..." | "Kein natürlicher Kontextbruch erkannt."
50
+ },
51
+ "currentSnapshot": { "featureStates": {...}, "acStatuses": {...} },
52
+ "persisted": true | false
53
+ }
54
+ ```
55
+
56
+ ## Step 2: Branch on breakpoint
57
+
58
+ **If `plan.breakpoint` is null:**
59
+
60
+ Print verbatim and stop:
61
+
62
+ ```
63
+ Kein natürlicher Kontextbruch erkannt.
64
+ ```
65
+
66
+ (AC-5)
67
+
68
+ **If `plan.breakpoint` is non-null:** continue. Checkpoint state is already persisted (AC-4).
69
+
70
+ ## Step 3: Save snapshot via cap-historian
71
+
72
+ Spawn `cap-historian` in SAVE mode with `plan.saveLabel` as the snapshot name:
73
+
74
+ ```
75
+ **MODE: SAVE**
76
+
77
+ {plan.saveLabel}
78
+
79
+ Save the current session as a checkpoint snapshot. Use the active feature for
80
+ linkage (default behavior — no --unassigned, no --platform). Reuse
81
+ cap-snapshot-linkage.cjs and cap-session-extract.cjs.
82
+
83
+ Return `=== HISTORIAN SAVE RESULTS ===` verbatim.
84
+ ```
85
+
86
+ Wait for cap-historian to complete.
87
+
88
+ ## Step 4: Print recommendation
89
+
90
+ Print `plan.message` verbatim:
91
+
92
+ ```
93
+ Jetzt /compact, weil {konkreter Grund}.
94
+ ```
95
+
96
+ ## Step 5: Advisory boundary
97
+
98
+ Do NOT invoke `/compact`. The only side effects of this command are:
99
+
100
+ 1. The checkpoint snapshot written by cap-historian (Step 3).
101
+ 2. `lastCheckpointAt` + `lastCheckpointSnapshot` updated in SESSION.json (Step 1).
102
+ 3. The recommendation printed to the user (Step 4).
103
+
104
+ If the user wants to compact, they run `/compact` themselves.
105
+
106
+ </process>