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,588 @@
1
+ ---
2
+ name: cap:debug
3
+ description: Systematic debugging with persistent state across context resets. Spawns cap-debugger agent using scientific method. Deploy-aware workflow minimizes deploy cycles.
4
+ argument-hint: "[issue description] [--research]"
5
+ allowed-tools:
6
+ - Read
7
+ - Write
8
+ - Bash
9
+ - Task
10
+ - AskUserQuestion
11
+ ---
12
+
13
+ <!-- @cap-context CAP v2.0 debug command -- orchestrates scientific debugging. Gathers symptoms, spawns cap-debugger agent, handles checkpoints and continuations. Debug state persists in .cap/debug/. -->
14
+ <!-- @cap-decision Debug state in .cap/debug/ (not .planning/debug/) -- CAP centralizes all runtime state under .cap/ -->
15
+ <!-- @cap-pattern Orchestrator gathers symptoms and spawns agent. Fresh context per investigation to avoid context exhaustion. -->
16
+ <!-- @cap-feature(feature:F-022) Deploy-Aware Debug Workflow -->
17
+
18
+ <objective>
19
+ <!-- @cap-todo(ref:AC-63) /cap:debug shall invoke the cap-debugger agent using a scientific method approach. -->
20
+
21
+ Debug issues using scientific method with subagent isolation and deploy-aware workflow.
22
+
23
+ **Orchestrator role:** Gather symptoms, spawn cap-debugger agent, manage deploy-verify cycles, handle checkpoints.
24
+
25
+ **Deploy-aware:** For issues requiring deployment to verify (staging/production bugs, cross-service issues), the workflow enforces:
26
+ 1. Hypothesis with expected outcome BEFORE code changes
27
+ 2. Local verification gate BEFORE deploy
28
+ 3. Deploy logbook tracking every deploy cycle
29
+ 4. User provides actual results after each deploy
30
+ 5. Agent reads logbook to avoid repeating failed approaches
31
+
32
+ **Why subagent:** Investigation burns context fast. Fresh context per investigation. Main context stays lean for user interaction.
33
+ </objective>
34
+
35
+ <context>
36
+ User's issue: $ARGUMENTS
37
+
38
+ Check for active sessions:
39
+ ```bash
40
+ ls .cap/debug/*.md 2>/dev/null | head -5
41
+ ```
42
+ </context>
43
+
44
+ <process>
45
+
46
+ ## Step 0: Load session and project context
47
+
48
+ <!-- @cap-todo(ref:AC-64) cap-debugger shall maintain persistent debug state across the debug session. -->
49
+
50
+ ```bash
51
+ node -e "
52
+ const session = require('./cap/bin/lib/cap-session.cjs');
53
+ const fs = require('node:fs');
54
+ const path = require('node:path');
55
+ const s = session.loadSession(process.cwd());
56
+ const debugDir = path.join(process.cwd(), '.cap', 'debug');
57
+ let activeSessions = [];
58
+ if (fs.existsSync(debugDir)) {
59
+ activeSessions = fs.readdirSync(debugDir)
60
+ .filter(f => f.startsWith('SESSION-') && f.endsWith('.md'))
61
+ .map(f => {
62
+ const content = fs.readFileSync(path.join(debugDir, f), 'utf8');
63
+ const statusMatch = content.match(/^## Status: (.+)$/m);
64
+ return { file: f, status: statusMatch ? statusMatch[1] : 'unknown' };
65
+ });
66
+ }
67
+ console.log(JSON.stringify({
68
+ activeFeature: s.activeFeature,
69
+ activeDebugSession: s.activeDebugSession,
70
+ existingSessions: activeSessions
71
+ }));
72
+ "
73
+ ```
74
+
75
+ Store as `debug_context`.
76
+
77
+ ## Step 1: Check for active or resumable debug sessions
78
+
79
+ If `debug_context.activeDebugSession` is set:
80
+
81
+ ```bash
82
+ node -e "
83
+ const fs = require('node:fs');
84
+ const path = require('node:path');
85
+ const sessionFile = path.join(process.cwd(), '.cap', 'debug', 'SESSION-{debug_context.activeDebugSession}.md');
86
+ if (fs.existsSync(sessionFile)) {
87
+ console.log(fs.readFileSync(sessionFile, 'utf8'));
88
+ } else {
89
+ console.log('NOT_FOUND');
90
+ }
91
+ "
92
+ ```
93
+
94
+ Also check for deploy logbook:
95
+
96
+ ```bash
97
+ node -e "
98
+ const fs = require('node:fs');
99
+ const path = require('node:path');
100
+ const logFile = path.join(process.cwd(), '.cap', 'debug', 'DEPLOY-LOG-{debug_context.activeDebugSession}.md');
101
+ if (fs.existsSync(logFile)) {
102
+ console.log(fs.readFileSync(logFile, 'utf8'));
103
+ } else {
104
+ console.log('NO_DEPLOY_LOG');
105
+ }
106
+ "
107
+ ```
108
+
109
+ If active session found, display:
110
+
111
+ ```
112
+ Active debug session found: SESSION-{id}
113
+ Status: {status}
114
+ {If deploy log exists:} Deploy log: {N} deploys recorded
115
+ ```
116
+
117
+ Use AskUserQuestion:
118
+ > "Resume existing debug session SESSION-{id}, or start a new investigation? [resume / new]"
119
+
120
+ - If `resume`: load existing session + deploy log, proceed to Step 3 with session context
121
+ - If `new`: generate new session ID, proceed to Step 2
122
+
123
+ If no active session: proceed to Step 2.
124
+
125
+ ## Step 2: Gather symptoms and classify issue type
126
+
127
+ If `$ARGUMENTS` contains an issue description, use it as initial symptoms.
128
+
129
+ If `$ARGUMENTS` is empty, use AskUserQuestion:
130
+ > "Describe the issue you are investigating. Include: what you expected, what actually happened, any error messages, and when this started."
131
+
132
+ Store as `symptoms`.
133
+
134
+ <!-- @cap-todo(ac:F-022/AC-7) Determine if this is a deploy-dependent issue -->
135
+ Use AskUserQuestion:
136
+ > "Does this issue require deploying to test (staging/production), or can it be fully reproduced locally?"
137
+ > Options: "Deploy required (staging/prod)" / "Local reproduction possible" / "Not sure yet"
138
+
139
+ Store as `issue_type`. If "Deploy required" or "Not sure": enable deploy-aware workflow.
140
+
141
+ Generate a new debug session ID:
142
+
143
+ ```bash
144
+ node -e "
145
+ const crypto = require('node:crypto');
146
+ const id = crypto.randomBytes(4).toString('hex');
147
+ console.log(id);
148
+ "
149
+ ```
150
+
151
+ Store as `session_id`.
152
+
153
+ Create the debug session file:
154
+
155
+ Write `.cap/debug/SESSION-{session_id}.md` using the Write tool:
156
+
157
+ ```markdown
158
+ # Debug Session: {session_id}
159
+
160
+ ## Status: investigating
161
+
162
+ ## Issue Type
163
+ {issue_type — "deploy-required" or "local"}
164
+
165
+ ## Symptoms
166
+ {symptoms}
167
+
168
+ ## Context
169
+ - Active feature: {debug_context.activeFeature or 'none'}
170
+ - Timestamp: {ISO timestamp}
171
+
172
+ ## Hypotheses
173
+ <!-- Cap-debugger will populate this section -->
174
+
175
+ ## Tests Performed
176
+ <!-- Cap-debugger will populate this section -->
177
+
178
+ ## Debug Logs Inserted
179
+ <!-- @cap-todo(ac:F-022/AC-6) Track debug logs for cleanup -->
180
+ <!-- Cap-debugger tracks all console.log/debug statements added to code here -->
181
+
182
+ ## Findings
183
+ <!-- Cap-debugger will populate this section -->
184
+
185
+ ## Resolution
186
+ <!-- Populated when root cause is found and fix is applied -->
187
+ ```
188
+
189
+ <!-- @cap-todo(ac:F-022/AC-3) Create deploy logbook for deploy-dependent issues -->
190
+ If deploy-aware workflow is enabled, also write `.cap/debug/DEPLOY-LOG-{session_id}.md`:
191
+
192
+ ```markdown
193
+ # Deploy Log: {session_id}
194
+
195
+ > Every deploy is documented here. The debugger reads this before each cycle
196
+ > to avoid repeating failed approaches.
197
+
198
+ ## Disproven Hypotheses
199
+ <!-- Hypotheses that were tested via deploy and shown to be wrong -->
200
+
201
+ ## Deploy Cycles
202
+
203
+ <!-- Each deploy cycle is recorded below -->
204
+ ```
205
+
206
+ Update session:
207
+
208
+ ```bash
209
+ node -e "
210
+ const session = require('./cap/bin/lib/cap-session.cjs');
211
+ session.updateSession(process.cwd(), {
212
+ activeDebugSession: '{session_id}',
213
+ lastCommand: '/cap:debug',
214
+ lastCommandTimestamp: new Date().toISOString(),
215
+ step: 'debug-investigating'
216
+ });
217
+ "
218
+ ```
219
+
220
+ ## Step 2c: Pitfall Research for Debug Context (only when --research is set)
221
+
222
+ <!-- @cap-feature(feature:F-024) Pre-Work Pitfall Research -->
223
+ <!-- @cap-feature(feature:F-044) Audit and Right-Size Agent Behaviors for Opus 4.7 -->
224
+ <!-- @cap-todo(ac:F-024/AC-8) /cap:debug triggers pitfall research for technologies involved in the bug -->
225
+ <!-- @cap-todo(ac:F-024/AC-1) Detect technologies from symptoms, package.json, and code context -->
226
+ <!-- @cap-todo(ac:F-024/AC-2) Research known pitfalls via Context7 -->
227
+ <!-- @cap-todo(ac:F-044/AC-2) Pitfall research is now opt-in via --research instead of always-on -->
228
+ <!-- @cap-decision(F-044/AC-2) /cap:debug pitfall research is opt-in via --research as of F-044. -->
229
+ <!-- When debugging a known-pitfall stack (Supabase RLS, OAuth callbacks, etc.) the user opts in. -->
230
+ <!-- Otherwise the debugger relies on Opus 4.7's training knowledge of common libraries. -->
231
+
232
+ **Skip this step if `--research` is NOT in `$ARGUMENTS` (research is opt-in as of F-044).**
233
+
234
+ **Detect technologies from symptoms and project:**
235
+
236
+ Scan the `symptoms` text for technology keywords (Supabase, Firebase, OAuth, SSO, Redis, Docker, etc.).
237
+ Also check `package.json` for relevant dependencies.
238
+
239
+ ```bash
240
+ node -e "
241
+ const fs = require('node:fs');
242
+ const path = require('node:path');
243
+ const cwd = process.cwd();
244
+ const techs = new Set();
245
+ const symptoms = process.argv[1] || '';
246
+
247
+ // Technology keywords to detect in symptoms
248
+ const keywords = ['supabase','firebase','prisma','drizzle','next','nuxt','react','vue','svelte','express','fastify','stripe','auth0','clerk','passport','redis','postgres','mongodb','docker','kubernetes','vercel','netlify','aws','oauth','sso','jwt','cookie','session','cors','webhook','websocket','graphql','trpc'];
249
+ const sympLower = symptoms.toLowerCase();
250
+ for (const kw of keywords) {
251
+ if (sympLower.includes(kw)) techs.add(kw);
252
+ }
253
+
254
+ // From package.json
255
+ const pkgPath = path.join(cwd, 'package.json');
256
+ if (fs.existsSync(pkgPath)) {
257
+ try {
258
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
259
+ const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
260
+ for (const dep of Object.keys(allDeps)) {
261
+ const known = ['supabase','firebase','prisma','drizzle','next','nuxt','stripe','auth0','clerk','passport','redis','socket.io','trpc','graphql','apollo'];
262
+ if (known.some(k => dep.includes(k))) techs.add(dep);
263
+ }
264
+ } catch(_) {}
265
+ }
266
+ console.log(JSON.stringify([...techs]));
267
+ " '{symptoms}'
268
+ ```
269
+
270
+ Store as `detected_techs`.
271
+
272
+ **If detected_techs is not empty:**
273
+
274
+ <!-- @cap-todo(ac:F-024/AC-3) Present pitfall briefing -->
275
+ <!-- @cap-todo(ac:F-024/AC-4) Critical pitfalls at top -->
276
+
277
+ For each detected technology, fetch known pitfalls via Context7:
278
+
279
+ ```bash
280
+ npx ctx7@latest docs {library_id} "common pitfalls problems debugging issues" 2>/dev/null | head -200
281
+ ```
282
+
283
+ Also check for cached pitfalls from previous sessions:
284
+
285
+ ```bash
286
+ ls .cap/pitfalls/*.md 2>/dev/null | head -5
287
+ ```
288
+
289
+ **Compile and display the Pitfall Briefing:**
290
+
291
+ ```
292
+ 🔍 Pitfall Research for Debug: {tech names}
293
+
294
+ ⚠️ KNOWN ISSUES (check these first — they cause the most debugging time):
295
+ {N}. {pitfall + typical symptom + fix}
296
+
297
+ 📋 COMMON CAUSES for "{symptom keywords}":
298
+ {N}. {cause + how to verify}
299
+ ```
300
+
301
+ <!-- @cap-todo(ac:F-024/AC-6) Persist briefing -->
302
+
303
+ Save briefing to `.cap/pitfalls/debug-{session_id}.md`.
304
+
305
+ <!-- @cap-todo(ac:F-024/AC-5) Agent receives briefing as context -->
306
+
307
+ Store as `pitfall_briefing` — passed to the cap-debugger agent in Step 3.
308
+
309
+ **If detected_techs is empty:**
310
+
311
+ Log: "No known-pitfall technologies detected in symptoms. Skipping research."
312
+
313
+ ## Step 3: Spawn cap-debugger agent
314
+
315
+ <!-- @cap-todo(ref:AC-65) cap-debugger shall follow a hypothesis -> test -> verify loop, documenting each step. -->
316
+ <!-- @cap-todo(ref:AC-66) cap-debugger shall not modify production code without explicit developer approval. -->
317
+
318
+ Identify relevant files from the active feature:
319
+
320
+ ```bash
321
+ node -e "
322
+ const fm = require('./cap/bin/lib/cap-feature-map.cjs');
323
+ const session = require('./cap/bin/lib/cap-session.cjs');
324
+ const s = session.loadSession(process.cwd());
325
+ // @cap-todo(ac:F-081/AC-4 iter:2) Migrated to {safe: true} opt-in to preserve CLI on duplicate-ID FEATURE-MAP.
326
+ // @cap-decision(F-081/iter2) Warn on parseError; continue with partial map for read-only display.
327
+ const featureMap = fm.readFeatureMap(process.cwd(), undefined, { safe: true });
328
+ if (featureMap && featureMap.parseError) {
329
+ console.warn('cap: debug — duplicate feature ID detected, file list uses partial map: ' + String(featureMap.parseError.message).trim());
330
+ }
331
+ const feature = s.activeFeature ? featureMap.features.find(f => f.id === s.activeFeature) : null;
332
+ console.log(JSON.stringify({
333
+ files: feature ? feature.files : [],
334
+ title: feature ? feature.title : 'unknown'
335
+ }));
336
+ "
337
+ ```
338
+
339
+ Spawn `cap-debugger` via Task tool:
340
+
341
+ ```
342
+ **DEBUG SESSION: {session_id}**
343
+ **ISSUE TYPE: {issue_type}**
344
+
345
+ **Symptoms:**
346
+ {symptoms}
347
+
348
+ {If resuming:}
349
+ **Previous session state:**
350
+ {existing session file content}
351
+
352
+ **Previous deploy log:**
353
+ {existing deploy log content}
354
+ {End if}
355
+
356
+ **Active feature:** {feature.title or 'none'}
357
+
358
+ <files_to_read>
359
+ {For each file in feature.files: - file}
360
+ - .cap/debug/SESSION-{session_id}.md
361
+ {If deploy-aware:} - .cap/debug/DEPLOY-LOG-{session_id}.md {End if}
362
+ </files_to_read>
363
+
364
+ {If pitfall_briefing:}
365
+ **⚠️ PITFALL BRIEFING — Check these known issues FIRST before forming hypotheses:**
366
+ {pitfall_briefing}
367
+ Start your investigation by checking whether any of these known pitfalls match the symptoms.
368
+ If a known pitfall matches, prioritize it as H1 in your hypothesis list.
369
+ {End if}
370
+
371
+ **Instructions:**
372
+ 1. Read all files listed above
373
+ {If pitfall_briefing:}
374
+ 2. Check known pitfalls from the briefing against the symptoms FIRST
375
+ 3. Form ranked hypotheses (pitfall matches first, then original hypotheses)
376
+ {Else:}
377
+ 2. Analyze symptoms and form ranked hypotheses
378
+ {End if}
379
+ 3. Test each hypothesis through code reading and execution
380
+ 4. Document each step in the debug session file
381
+ {If deploy-aware:}
382
+ 5. DEPLOY-AWARE MODE: Follow the deploy-aware protocol:
383
+ a. Define hypothesis with expected outcome BEFORE changing code
384
+ b. Identify local verification steps (unit test, grep, curl, log check)
385
+ c. Only return DEPLOY_READY when local verification passes
386
+ d. Read DEPLOY-LOG to avoid repeating disproven hypotheses
387
+ e. Batch multiple fixes per deploy when possible
388
+ f. Track all debug logs you insert for later cleanup
389
+ {End if}
390
+ 6. DO NOT modify production code -- only observe and test
391
+ 7. When root cause is found, propose a fix and wait for approval
392
+
393
+ **Return format:**
394
+ === DEBUG RESULT ===
395
+ STATUS: ROOT_CAUSE_FOUND | DEPLOY_READY | CHECKPOINT_REACHED | DEBUG_COMPLETE
396
+ SESSION_ID: {session_id}
397
+ {If ROOT_CAUSE_FOUND:}
398
+ ROOT_CAUSE: {description}
399
+ PROPOSED_FIX: {description}
400
+ FILES_TO_MODIFY: [list]
401
+ {End if}
402
+ {If DEPLOY_READY:}
403
+ HYPOTHESIS: {what we think is wrong}
404
+ EXPECTED_RESULT: {what should happen after deploy if hypothesis is correct}
405
+ LOCAL_VERIFICATION: {what was checked locally and passed}
406
+ CHANGES_MADE: [list of file:change pairs]
407
+ DEBUG_LOGS_ADDED: [list of file:line pairs for temporary debug logging]
408
+ DEPLOY_BATCH: {number of fixes batched in this deploy}
409
+ {End if}
410
+ {If CHECKPOINT_REACHED:}
411
+ CHECKPOINT_REASON: {what user input is needed}
412
+ NEXT_STEPS: {what to investigate next}
413
+ {End if}
414
+ === END DEBUG RESULT ===
415
+ ```
416
+
417
+ Wait for cap-debugger to complete. Parse the result.
418
+
419
+ ## Step 4: Handle agent result
420
+
421
+ **If STATUS == ROOT_CAUSE_FOUND:**
422
+
423
+ Display:
424
+ ```
425
+ Root cause found:
426
+ {root_cause}
427
+
428
+ Proposed fix:
429
+ {proposed_fix}
430
+
431
+ Files to modify:
432
+ {files_to_modify}
433
+ ```
434
+
435
+ Use AskUserQuestion:
436
+ > "Apply the proposed fix? [yes / no / modify: instructions]"
437
+
438
+ - If `yes`: Spawn cap-debugger again with `**MODE: APPLY_FIX**` and the proposed fix details. The agent applies the fix and runs verification.
439
+ - If `no`: Update session file status to `root_cause_found_pending`, end debug session.
440
+ - If `modify: <instructions>`: Spawn cap-debugger again with modified fix instructions.
441
+
442
+ <!-- @cap-todo(ac:F-022/AC-1) Hypothesis with expected outcome before code changes -->
443
+ <!-- @cap-todo(ac:F-022/AC-2) Verify-before-deploy gate -->
444
+ <!-- @cap-todo(ac:F-022/AC-4) Batch hypotheses into single deploy -->
445
+ **If STATUS == DEPLOY_READY:**
446
+
447
+ Display:
448
+ ```
449
+ Ready to deploy. {DEPLOY_BATCH} fix(es) batched.
450
+
451
+ Hypothesis: {hypothesis}
452
+ Expected result: {expected_result}
453
+ Local verification: {local_verification} ✓
454
+
455
+ Changes:
456
+ {For each change: - file: change}
457
+
458
+ {If debug logs added:}
459
+ Debug logs added (will be cleaned up):
460
+ {For each log: - file:line}
461
+ {End if}
462
+ ```
463
+
464
+ Use AskUserQuestion:
465
+ > "Deploy now? Review the changes above, then deploy and report the result. [deploy / abort / modify]"
466
+
467
+ - If `deploy`: Proceed to Step 4a (Deploy-Verify Cycle)
468
+ - If `abort`: Revert changes, update session file
469
+ - If `modify`: Re-spawn agent with modifications
470
+
471
+ ## Step 4a: Deploy-Verify Cycle
472
+
473
+ <!-- @cap-todo(ac:F-022/AC-3) Log every deploy in the deploy logbook -->
474
+ <!-- @cap-todo(ac:F-022/AC-7) User provides actual result after deploy -->
475
+
476
+ Increment deploy counter.
477
+
478
+ ```
479
+ Deploy #{deploy_number} in progress.
480
+
481
+ Waiting for your deploy to complete...
482
+ ```
483
+
484
+ Use AskUserQuestion:
485
+ > "Deploy #{deploy_number} complete. What happened? [pass: it works / fail: describe what went wrong]"
486
+
487
+ Store user response as `deploy_result`.
488
+
489
+ **Update deploy logbook** (`.cap/debug/DEPLOY-LOG-{session_id}.md`):
490
+
491
+ Append to the logbook using Edit tool:
492
+
493
+ ```markdown
494
+ ### Deploy #{deploy_number} — {timestamp}
495
+
496
+ **Hypothesis:** {hypothesis}
497
+ **Expected:** {expected_result}
498
+ **Actual:** {deploy_result}
499
+ **Verdict:** {PASS or FAIL}
500
+ **Changes:** {list of changes}
501
+ ```
502
+
503
+ <!-- @cap-todo(ac:F-022/AC-5) After failed deploy, read logbook and don't repeat disproven hypotheses -->
504
+ **If deploy_result is PASS:**
505
+ - Update session status to `resolved`
506
+ - Proceed to Step 5 (cleanup)
507
+
508
+ **If deploy_result is FAIL:**
509
+ - Add the hypothesis to the **Disproven Hypotheses** section of deploy logbook
510
+ - Display:
511
+
512
+ ```
513
+ Deploy #{deploy_number} failed.
514
+ Recorded in deploy log. {total_deploys} deploy(s) so far, {disproven_count} hypothesis(es) disproven.
515
+
516
+ Re-spawning debugger with updated context...
517
+ ```
518
+
519
+ - Re-spawn cap-debugger (Step 3) with:
520
+ - The updated deploy log (so it reads what was already tried)
521
+ - The user's failure description
522
+ - Explicit instruction: "The following hypotheses have been DISPROVEN — do NOT re-pursue them: {list}"
523
+
524
+ Loop back to Step 3.
525
+
526
+ **If STATUS == CHECKPOINT_REACHED:**
527
+
528
+ Display checkpoint reason and next steps.
529
+
530
+ Use AskUserQuestion:
531
+ > "{checkpoint_reason}. Provide the requested information, or type 'stop' to pause the session."
532
+
533
+ - If user provides info: Re-spawn cap-debugger with the new information added to context.
534
+ - If `stop`: Update session file, end session. User can resume later with `/cap:debug`.
535
+
536
+ **If STATUS == DEBUG_COMPLETE:**
537
+
538
+ Log: "Debug session {session_id} complete."
539
+ Proceed to Step 5.
540
+
541
+ ## Step 5: Cleanup and report
542
+
543
+ <!-- @cap-todo(ac:F-022/AC-6) Clean up debug logs inserted during session -->
544
+
545
+ If the session had debug logs inserted, spawn cap-debugger with `**MODE: CLEANUP_DEBUG_LOGS**`:
546
+
547
+ ```
548
+ Remove all temporary debug logs tracked in the session file under "## Debug Logs Inserted".
549
+ Read the session file, find each file:line entry, and remove the debug statement.
550
+ Verify the code still works after removal.
551
+ ```
552
+
553
+ Update debug session file with resolution (via Write tool).
554
+
555
+ ```bash
556
+ node -e "
557
+ const session = require('./cap/bin/lib/cap-session.cjs');
558
+ session.updateSession(process.cwd(), {
559
+ activeDebugSession: null,
560
+ lastCommand: '/cap:debug',
561
+ lastCommandTimestamp: new Date().toISOString(),
562
+ step: 'debug-complete'
563
+ });
564
+ "
565
+ ```
566
+
567
+ ```
568
+ cap:debug complete.
569
+
570
+ Session: {session_id}
571
+ Status: {final_status}
572
+ Debug log: .cap/debug/SESSION-{session_id}.md
573
+ {If deploy-aware:}
574
+ Deploy log: .cap/debug/DEPLOY-LOG-{session_id}.md
575
+ Total deploys: {deploy_count}
576
+ Hypotheses tested: {hypothesis_count}
577
+ Hypotheses disproven: {disproven_count}
578
+ {End if}
579
+
580
+ {If fix applied:}
581
+ Fix applied and verified. Run /cap:test to confirm no regressions.
582
+ {End if}
583
+ {If debug logs cleaned:}
584
+ Temporary debug logs removed.
585
+ {End if}
586
+ ```
587
+
588
+ </process>