@bhargavvc/sdd-cc 1.30.1 → 1.35.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 (242) hide show
  1. package/README.ja-JP.md +144 -110
  2. package/README.ko-KR.md +143 -107
  3. package/README.md +183 -112
  4. package/README.pt-BR.md +90 -52
  5. package/README.zh-CN.md +141 -101
  6. package/agents/sdd-advisor-researcher.md +23 -0
  7. package/agents/sdd-ai-researcher.md +133 -0
  8. package/agents/sdd-code-fixer.md +516 -0
  9. package/agents/sdd-code-reviewer.md +355 -0
  10. package/agents/sdd-codebase-mapper.md +3 -3
  11. package/agents/sdd-debugger.md +17 -5
  12. package/agents/sdd-doc-verifier.md +201 -0
  13. package/agents/sdd-doc-writer.md +602 -0
  14. package/agents/sdd-domain-researcher.md +153 -0
  15. package/agents/sdd-eval-auditor.md +164 -0
  16. package/agents/sdd-eval-planner.md +154 -0
  17. package/agents/sdd-executor.md +87 -4
  18. package/agents/sdd-framework-selector.md +160 -0
  19. package/agents/sdd-intel-updater.md +314 -0
  20. package/agents/sdd-nyquist-auditor.md +1 -1
  21. package/agents/sdd-phase-researcher.md +71 -4
  22. package/agents/sdd-plan-checker.md +100 -6
  23. package/agents/sdd-planner.md +145 -206
  24. package/agents/sdd-project-researcher.md +25 -2
  25. package/agents/sdd-research-synthesizer.md +3 -3
  26. package/agents/sdd-roadmapper.md +6 -6
  27. package/agents/sdd-security-auditor.md +128 -0
  28. package/agents/sdd-ui-auditor.md +43 -3
  29. package/agents/sdd-ui-checker.md +5 -5
  30. package/agents/sdd-ui-researcher.md +27 -4
  31. package/agents/sdd-user-profiler.md +2 -2
  32. package/agents/sdd-verifier.md +142 -22
  33. package/bin/install.js +2145 -545
  34. package/commands/sdd/add-backlog.md +5 -5
  35. package/commands/sdd/add-tests.md +2 -2
  36. package/commands/sdd/ai-integration-phase.md +36 -0
  37. package/commands/sdd/analyze-dependencies.md +34 -0
  38. package/commands/sdd/audit-fix.md +33 -0
  39. package/commands/sdd/autonomous.md +7 -2
  40. package/commands/sdd/cleanup.md +5 -0
  41. package/commands/sdd/code-review-fix.md +52 -0
  42. package/commands/sdd/code-review.md +55 -0
  43. package/commands/sdd/complete-milestone.md +6 -6
  44. package/commands/sdd/debug.md +22 -9
  45. package/commands/sdd/discuss-phase.md +7 -2
  46. package/commands/sdd/do.md +1 -1
  47. package/commands/sdd/docs-update.md +48 -0
  48. package/commands/sdd/eval-review.md +32 -0
  49. package/commands/sdd/execute-phase.md +4 -0
  50. package/commands/sdd/explore.md +27 -0
  51. package/commands/sdd/fast.md +2 -2
  52. package/commands/sdd/from-sdd2.md +45 -0
  53. package/commands/sdd/help.md +2 -0
  54. package/commands/sdd/import.md +36 -0
  55. package/commands/sdd/intel.md +179 -0
  56. package/commands/sdd/join-discord.md +2 -1
  57. package/commands/sdd/manager.md +1 -0
  58. package/commands/sdd/map-codebase.md +3 -3
  59. package/commands/sdd/new-milestone.md +1 -1
  60. package/commands/sdd/new-project.md +5 -1
  61. package/commands/sdd/new-workspace.md +1 -1
  62. package/commands/sdd/next.md +2 -0
  63. package/commands/sdd/plan-milestone-gaps.md +2 -2
  64. package/commands/sdd/plan-phase.md +6 -1
  65. package/commands/sdd/plant-seed.md +1 -1
  66. package/commands/sdd/profile-user.md +1 -1
  67. package/commands/sdd/quick.md +5 -3
  68. package/commands/sdd/reapply-patches.md +230 -42
  69. package/commands/sdd/research-phase.md +3 -3
  70. package/commands/sdd/review-backlog.md +1 -0
  71. package/commands/sdd/review.md +6 -3
  72. package/commands/sdd/scan.md +26 -0
  73. package/commands/sdd/secure-phase.md +35 -0
  74. package/commands/sdd/ship.md +1 -1
  75. package/commands/sdd/thread.md +5 -5
  76. package/commands/sdd/undo.md +34 -0
  77. package/commands/sdd/verify-work.md +1 -1
  78. package/commands/sdd/workstreams.md +17 -11
  79. package/hooks/dist/sdd-check-update.js +33 -8
  80. package/hooks/dist/sdd-context-monitor.js +17 -8
  81. package/hooks/dist/sdd-phase-boundary.sh +27 -0
  82. package/hooks/dist/sdd-prompt-guard.js +1 -0
  83. package/hooks/dist/sdd-read-guard.js +82 -0
  84. package/hooks/dist/sdd-session-state.sh +33 -0
  85. package/hooks/dist/sdd-statusline.js +137 -15
  86. package/hooks/dist/sdd-validate-commit.sh +47 -0
  87. package/hooks/dist/sdd-workflow-guard.js +4 -4
  88. package/hooks/sdd-check-update.js +139 -0
  89. package/hooks/sdd-context-monitor.js +165 -0
  90. package/hooks/sdd-phase-boundary.sh +27 -0
  91. package/hooks/sdd-prompt-guard.js +97 -0
  92. package/hooks/sdd-read-guard.js +82 -0
  93. package/hooks/sdd-session-state.sh +33 -0
  94. package/hooks/sdd-statusline.js +241 -0
  95. package/hooks/sdd-validate-commit.sh +47 -0
  96. package/hooks/sdd-workflow-guard.js +94 -0
  97. package/package.json +3 -3
  98. package/scripts/build-hooks.js +18 -7
  99. package/scripts/prompt-injection-scan.sh +1 -0
  100. package/scripts/rebrand-gsd-to-sdd.sh +221 -220
  101. package/scripts/run-tests.cjs +5 -1
  102. package/scripts/sync-upstream.sh +1 -1
  103. package/sdd/bin/lib/commands.cjs +79 -17
  104. package/sdd/bin/lib/config.cjs +90 -48
  105. package/sdd/bin/lib/core.cjs +452 -87
  106. package/sdd/bin/lib/docs.cjs +267 -0
  107. package/sdd/bin/lib/frontmatter.cjs +381 -336
  108. package/sdd/bin/lib/init.cjs +110 -16
  109. package/sdd/bin/lib/intel.cjs +660 -0
  110. package/sdd/bin/lib/learnings.cjs +378 -0
  111. package/sdd/bin/lib/milestone.cjs +42 -11
  112. package/sdd/bin/lib/model-profiles.cjs +17 -15
  113. package/sdd/bin/lib/phase.cjs +367 -288
  114. package/sdd/bin/lib/profile-output.cjs +106 -10
  115. package/sdd/bin/lib/roadmap.cjs +146 -115
  116. package/sdd/bin/lib/schema-detect.cjs +238 -0
  117. package/sdd/bin/lib/sdd2-import.cjs +511 -0
  118. package/sdd/bin/lib/security.cjs +124 -3
  119. package/sdd/bin/lib/state.cjs +648 -264
  120. package/sdd/bin/lib/template.cjs +8 -4
  121. package/sdd/bin/lib/verify.cjs +209 -28
  122. package/sdd/bin/lib/workstream.cjs +7 -3
  123. package/sdd/bin/sdd-tools.cjs +184 -12
  124. package/sdd/contexts/dev.md +21 -0
  125. package/sdd/contexts/research.md +22 -0
  126. package/sdd/contexts/review.md +22 -0
  127. package/sdd/references/agent-contracts.md +79 -0
  128. package/sdd/references/ai-evals.md +156 -0
  129. package/sdd/references/ai-frameworks.md +186 -0
  130. package/sdd/references/artifact-types.md +113 -0
  131. package/sdd/references/common-bug-patterns.md +114 -0
  132. package/sdd/references/context-budget.md +49 -0
  133. package/sdd/references/continuation-format.md +25 -25
  134. package/sdd/references/domain-probes.md +125 -0
  135. package/sdd/references/few-shot-examples/plan-checker.md +73 -0
  136. package/sdd/references/few-shot-examples/verifier.md +109 -0
  137. package/sdd/references/gate-prompts.md +100 -0
  138. package/sdd/references/gates.md +70 -0
  139. package/sdd/references/git-integration.md +1 -1
  140. package/sdd/references/ios-scaffold.md +123 -0
  141. package/sdd/references/model-profile-resolution.md +2 -0
  142. package/sdd/references/model-profiles.md +24 -18
  143. package/sdd/references/planner-gap-closure.md +62 -0
  144. package/sdd/references/planner-reviews.md +39 -0
  145. package/sdd/references/planner-revision.md +87 -0
  146. package/sdd/references/planning-config.md +252 -0
  147. package/sdd/references/revision-loop.md +97 -0
  148. package/sdd/references/thinking-models-debug.md +44 -0
  149. package/sdd/references/thinking-models-execution.md +50 -0
  150. package/sdd/references/thinking-models-planning.md +62 -0
  151. package/sdd/references/thinking-models-research.md +50 -0
  152. package/sdd/references/thinking-models-verification.md +55 -0
  153. package/sdd/references/thinking-partner.md +96 -0
  154. package/sdd/references/ui-brand.md +4 -4
  155. package/sdd/references/universal-anti-patterns.md +63 -0
  156. package/sdd/references/verification-overrides.md +227 -0
  157. package/sdd/references/workstream-flag.md +56 -3
  158. package/sdd/templates/AI-SPEC.md +246 -0
  159. package/sdd/templates/DEBUG.md +1 -1
  160. package/sdd/templates/SECURITY.md +61 -0
  161. package/sdd/templates/UAT.md +4 -4
  162. package/sdd/templates/VALIDATION.md +4 -4
  163. package/sdd/templates/claude-md.md +32 -9
  164. package/sdd/templates/config.json +4 -0
  165. package/sdd/templates/debug-subagent-prompt.md +1 -1
  166. package/sdd/templates/dev-preferences.md +1 -1
  167. package/sdd/templates/discovery.md +2 -2
  168. package/sdd/templates/phase-prompt.md +1 -1
  169. package/sdd/templates/planner-subagent-prompt.md +3 -3
  170. package/sdd/templates/project.md +1 -1
  171. package/sdd/templates/research.md +1 -1
  172. package/sdd/templates/state.md +2 -2
  173. package/sdd/workflows/add-phase.md +8 -8
  174. package/sdd/workflows/add-tests.md +12 -9
  175. package/sdd/workflows/add-todo.md +5 -3
  176. package/sdd/workflows/ai-integration-phase.md +284 -0
  177. package/sdd/workflows/analyze-dependencies.md +96 -0
  178. package/sdd/workflows/audit-fix.md +157 -0
  179. package/sdd/workflows/audit-milestone.md +11 -11
  180. package/sdd/workflows/audit-uat.md +2 -2
  181. package/sdd/workflows/autonomous.md +195 -27
  182. package/sdd/workflows/check-todos.md +12 -10
  183. package/sdd/workflows/cleanup.md +2 -0
  184. package/sdd/workflows/code-review-fix.md +497 -0
  185. package/sdd/workflows/code-review.md +515 -0
  186. package/sdd/workflows/complete-milestone.md +56 -22
  187. package/sdd/workflows/diagnose-issues.md +10 -3
  188. package/sdd/workflows/discovery-phase.md +5 -3
  189. package/sdd/workflows/discuss-phase-assumptions.md +24 -6
  190. package/sdd/workflows/discuss-phase-power.md +291 -0
  191. package/sdd/workflows/discuss-phase.md +173 -21
  192. package/sdd/workflows/do.md +23 -21
  193. package/sdd/workflows/docs-update.md +1155 -0
  194. package/sdd/workflows/eval-review.md +155 -0
  195. package/sdd/workflows/execute-phase.md +594 -38
  196. package/sdd/workflows/execute-plan.md +67 -96
  197. package/sdd/workflows/explore.md +139 -0
  198. package/sdd/workflows/fast.md +5 -5
  199. package/sdd/workflows/forensics.md +2 -2
  200. package/sdd/workflows/health.md +4 -4
  201. package/sdd/workflows/help.md +122 -119
  202. package/sdd/workflows/import.md +276 -0
  203. package/sdd/workflows/inbox.md +387 -0
  204. package/sdd/workflows/insert-phase.md +7 -7
  205. package/sdd/workflows/list-phase-assumptions.md +4 -4
  206. package/sdd/workflows/list-workspaces.md +2 -2
  207. package/sdd/workflows/manager.md +35 -32
  208. package/sdd/workflows/map-codebase.md +7 -5
  209. package/sdd/workflows/milestone-summary.md +2 -2
  210. package/sdd/workflows/new-milestone.md +17 -9
  211. package/sdd/workflows/new-project.md +50 -25
  212. package/sdd/workflows/new-workspace.md +7 -5
  213. package/sdd/workflows/next.md +67 -11
  214. package/sdd/workflows/note.md +9 -7
  215. package/sdd/workflows/pause-work.md +75 -12
  216. package/sdd/workflows/plan-milestone-gaps.md +8 -8
  217. package/sdd/workflows/plan-phase.md +294 -42
  218. package/sdd/workflows/plant-seed.md +6 -3
  219. package/sdd/workflows/pr-branch.md +42 -14
  220. package/sdd/workflows/profile-user.md +9 -7
  221. package/sdd/workflows/progress.md +45 -45
  222. package/sdd/workflows/quick.md +195 -47
  223. package/sdd/workflows/remove-phase.md +6 -6
  224. package/sdd/workflows/remove-workspace.md +3 -1
  225. package/sdd/workflows/research-phase.md +2 -2
  226. package/sdd/workflows/resume-project.md +12 -12
  227. package/sdd/workflows/review.md +109 -9
  228. package/sdd/workflows/scan.md +102 -0
  229. package/sdd/workflows/secure-phase.md +166 -0
  230. package/sdd/workflows/session-report.md +2 -2
  231. package/sdd/workflows/settings.md +38 -12
  232. package/sdd/workflows/ship.md +21 -9
  233. package/sdd/workflows/stats.md +1 -1
  234. package/sdd/workflows/transition.md +23 -23
  235. package/sdd/workflows/ui-phase.md +15 -7
  236. package/sdd/workflows/ui-review.md +29 -4
  237. package/sdd/workflows/undo.md +314 -0
  238. package/sdd/workflows/update.md +171 -20
  239. package/sdd/workflows/validate-phase.md +6 -4
  240. package/sdd/workflows/verify-phase.md +210 -6
  241. package/sdd/workflows/verify-work.md +83 -9
  242. package/sdd/commands/sdd/workstreams.md +0 -63
@@ -55,6 +55,12 @@ gaps = [
55
55
  </step>
56
56
 
57
57
  <step name="report_plan">
58
+ **Read worktree config:**
59
+
60
+ ```bash
61
+ USE_WORKTREES=$(node "$HOME/.claude/sdd/bin/sdd-tools.cjs" config-get workflow.use_worktrees 2>/dev/null || echo "true")
62
+ ```
63
+
58
64
  **Report diagnosis plan to user:**
59
65
 
60
66
  ```
@@ -82,6 +88,7 @@ This runs in parallel - all gaps investigated simultaneously.
82
88
 
83
89
  ```bash
84
90
  AGENT_SKILLS_DEBUGGER=$(node "$HOME/.claude/sdd/bin/sdd-tools.cjs" agent-skills sdd-debugger 2>/dev/null)
91
+ EXPECTED_BASE=$(git rev-parse HEAD)
85
92
  ```
86
93
 
87
94
  **Spawn debug agents in parallel:**
@@ -90,9 +97,9 @@ For each gap, fill the debug-subagent-prompt template and spawn:
90
97
 
91
98
  ```
92
99
  Task(
93
- prompt=filled_debug_subagent_prompt + "\n\n<files_to_read>\n- {phase_dir}/{phase_num}-UAT.md\n- .planning/STATE.md\n</files_to_read>\n${AGENT_SKILLS_DEBUGGER}",
100
+ prompt=filled_debug_subagent_prompt + "\n\n<worktree_branch_check>\nFIRST ACTION: run git merge-base HEAD {EXPECTED_BASE} — if result differs from {EXPECTED_BASE}, run git reset --hard {EXPECTED_BASE} to correct the branch base (safe — runs before any agent work). Then verify: if [ \"$(git rev-parse HEAD)\" != \"{EXPECTED_BASE}\" ]; then echo \"ERROR: Could not correct worktree base\"; exit 1; fi. Fixes EnterWorktree creating branches from main on all platforms.\n</worktree_branch_check>\n\n<files_to_read>\n- {phase_dir}/{phase_num}-UAT.md\n- .planning/STATE.md\n</files_to_read>\n${AGENT_SKILLS_DEBUGGER}",
94
101
  subagent_type="sdd-debugger",
95
- isolation="worktree",
102
+ ${USE_WORKTREES !== "false" ? 'isolation="worktree",' : ''}
96
103
  description="Debug: {truth_short}"
97
104
  )
98
105
  ```
@@ -213,7 +220,7 @@ Agents only diagnose—plan-phase --gaps handles fixes (no fix application).
213
220
 
214
221
  **Agent times out:**
215
222
  - Check DEBUG-{slug}.md for partial progress
216
- - Can resume with /sdd:debug
223
+ - Can resume with /sdd-debug
217
224
 
218
225
  **All agents fail:**
219
226
  - Something systemic (permissions, git, etc.)
@@ -4,7 +4,7 @@ Produces DISCOVERY.md (for Level 2-3) that informs PLAN.md creation.
4
4
 
5
5
  Called from plan-phase.md's mandatory_discovery step with a depth parameter.
6
6
 
7
- NOTE: For comprehensive ecosystem research ("how do experts build this"), use /sdd:research-phase instead, which produces RESEARCH.md.
7
+ NOTE: For comprehensive ecosystem research ("how do experts build this"), use /sdd-research-phase instead, which produces RESEARCH.md.
8
8
  </purpose>
9
9
 
10
10
  <depth_levels>
@@ -214,6 +214,8 @@ Write `.planning/phases/XX-name/DISCOVERY.md`:
214
214
  After creating DISCOVERY.md, check confidence level.
215
215
 
216
216
  If confidence is LOW:
217
+
218
+ **Text mode (`workflow.text_mode: true` in config or `--text` flag):** Set `TEXT_MODE=true` if `--text` is present in `$ARGUMENTS` OR `text_mode` from init JSON is `true`. When TEXT_MODE is active, replace every `AskUserQuestion` call with a plain-text numbered list and ask the user to type their choice number. This is required for non-Claude runtimes (OpenAI Codex, Gemini CLI, etc.) where `AskUserQuestion` is not available.
217
219
  Use AskUserQuestion:
218
220
 
219
221
  - header: "Low Conf."
@@ -252,8 +254,8 @@ Confidence: [level]
252
254
 
253
255
  What's next?
254
256
 
255
- 1. Discuss phase context (/sdd:discuss-phase [current-phase])
256
- 2. Create phase plan (/sdd:plan-phase [current-phase])
257
+ 1. Discuss phase context (/sdd-discuss-phase [current-phase])
258
+ 2. Create phase plan (/sdd-plan-phase [current-phase])
257
259
  3. Refine discovery (dig deeper)
258
260
  4. Review discovery
259
261
 
@@ -77,7 +77,7 @@ Parse JSON for: `commit_docs`, `phase_found`, `phase_dir`, `phase_number`, `phas
77
77
  ```
78
78
  Phase [X] not found in roadmap.
79
79
 
80
- Use /sdd:progress to see available phases.
80
+ Use /sdd-progress to see available phases.
81
81
  ```
82
82
  Exit workflow.
83
83
 
@@ -186,6 +186,24 @@ Parse JSON for: `todo_count`, `matches[]`.
186
186
  **Auto mode (`--auto`):** Fold all todos with score >= 0.4 automatically. Log the selection.
187
187
  </step>
188
188
 
189
+ <step name="load_methodology">
190
+ Read the project-level methodology file if it exists. This must happen before assumption analysis
191
+ so that active lenses shape how assumptions are generated and evaluated.
192
+
193
+ ```bash
194
+ cat .planning/METHODOLOGY.md 2>/dev/null || true
195
+ ```
196
+
197
+ **If METHODOLOGY.md exists:**
198
+ - Parse each named lens: its diagnoses, recommendations, and triggering conditions
199
+ - Store as internal `<active_lenses>` for use in deep_codebase_analysis and present_assumptions
200
+ - When spawning the sdd-assumptions-analyzer, pass the lens list so it can flag which lenses apply
201
+ - When presenting assumptions, append a "Methodology" section showing which lenses were applied
202
+ and what they flagged (if anything)
203
+
204
+ **If METHODOLOGY.md does not exist:** Skip silently. This artifact is optional.
205
+ </step>
206
+
189
207
  <step name="scout_codebase">
190
208
  Lightweight scan of existing code to inform assumption generation.
191
209
 
@@ -579,15 +597,15 @@ Created: .planning/phases/${PADDED_PHASE}-${SLUG}/${PADDED_PHASE}-CONTEXT.md
579
597
 
580
598
  **Phase ${PHASE}: {phase_name}** — {Goal from ROADMAP.md}
581
599
 
582
- `/sdd:plan-phase ${PHASE}`
600
+ `/clear` then:
583
601
 
584
- <sub>`/clear` first → fresh context window</sub>
602
+ `/sdd-plan-phase ${PHASE}`
585
603
 
586
604
  ---
587
605
 
588
606
  **Also available:**
589
- - `/sdd:plan-phase ${PHASE} --skip-research` — plan without research
590
- - `/sdd:ui-phase ${PHASE}` — generate UI design contract (if frontend work)
607
+ - `/sdd-plan-phase ${PHASE} --skip-research` — plan without research
608
+ - `/sdd-ui-phase ${PHASE}` — generate UI design contract (if frontend work)
591
609
  - Review/edit CONTEXT.md before continuing
592
610
 
593
611
  ---
@@ -626,7 +644,7 @@ Display banner:
626
644
  Context captured (assumptions mode). Launching plan-phase...
627
645
  ```
628
646
 
629
- Launch: `Skill(skill="sdd:plan-phase", args="${PHASE} --auto")`
647
+ Launch: `Skill(skill="sdd-plan-phase", args="${PHASE} --auto")`
630
648
 
631
649
  Handle return: PHASE COMPLETE / PLANNING COMPLETE / INCONCLUSIVE / GAPS FOUND
632
650
  (identical handling to discuss-phase.md auto_advance step)
@@ -0,0 +1,291 @@
1
+ <purpose>
2
+ Power user mode for discuss-phase. Generates ALL questions upfront into a JSON state file and an HTML companion UI, then waits for the user to answer at their own pace. When the user signals readiness, processes all answers in one pass and generates CONTEXT.md.
3
+
4
+ **When to use:** Large phases with many gray areas, or when users prefer to answer questions offline / asynchronously rather than interactively in the chat session.
5
+ </purpose>
6
+
7
+ <trigger>
8
+ This workflow executes when `--power` flag is present in ARGUMENTS to `/sdd-discuss-phase`.
9
+
10
+ The caller (discuss-phase.md) has already:
11
+ - Validated the phase exists
12
+ - Provided init context: `phase_dir`, `padded_phase`, `phase_number`, `phase_name`, `phase_slug`
13
+
14
+ Begin at **Step 1** immediately.
15
+ </trigger>
16
+
17
+ <step name="analyze">
18
+ Run the same gray area identification as standard discuss-phase mode.
19
+
20
+ 1. Load prior context (PROJECT.md, REQUIREMENTS.md, STATE.md, prior CONTEXT.md files)
21
+ 2. Scout codebase for reusable assets and patterns relevant to this phase
22
+ 3. Read the phase goal from ROADMAP.md
23
+ 4. Identify ALL gray areas — specific implementation decisions the user should weigh in on
24
+ 5. For each gray area, generate 2–4 concrete options with tradeoff descriptions
25
+
26
+ Group questions by topic into sections (e.g., "Visual Style", "Data Model", "Interactions", "Error Handling"). Each section should have 2–6 questions.
27
+
28
+ Do NOT ask the user anything at this stage. Capture everything internally, then proceed to generate.
29
+ </step>
30
+
31
+ <step name="generate_json">
32
+ Write all questions to:
33
+
34
+ ```
35
+ {phase_dir}/{padded_phase}-QUESTIONS.json
36
+ ```
37
+
38
+ **JSON structure:**
39
+
40
+ ```json
41
+ {
42
+ "phase": "{padded_phase}-{phase_slug}",
43
+ "generated_at": "ISO-8601 timestamp",
44
+ "stats": {
45
+ "total": 0,
46
+ "answered": 0,
47
+ "chat_more": 0,
48
+ "remaining": 0
49
+ },
50
+ "sections": [
51
+ {
52
+ "id": "section-slug",
53
+ "title": "Section Title",
54
+ "questions": [
55
+ {
56
+ "id": "Q-01",
57
+ "title": "Short question title",
58
+ "context": "Codebase info, prior decisions, or constraints relevant to this question",
59
+ "options": [
60
+ {
61
+ "id": "a",
62
+ "label": "Option label",
63
+ "description": "Tradeoff or elaboration for this option"
64
+ },
65
+ {
66
+ "id": "b",
67
+ "label": "Another option",
68
+ "description": "Tradeoff or elaboration"
69
+ },
70
+ {
71
+ "id": "c",
72
+ "label": "Custom",
73
+ "description": ""
74
+ }
75
+ ],
76
+ "answer": null,
77
+ "chat_more": "",
78
+ "status": "unanswered"
79
+ }
80
+ ]
81
+ }
82
+ ]
83
+ }
84
+ ```
85
+
86
+ **Field rules:**
87
+ - `stats.total`: count of all questions across all sections
88
+ - `stats.answered`: count where `answer` is not null and not empty string
89
+ - `stats.chat_more`: count where `chat_more` has content
90
+ - `stats.remaining`: `total - answered`
91
+ - `question.id`: sequential across all sections — Q-01, Q-02, Q-03, ...
92
+ - `question.context`: concrete codebase or prior-decision annotation (not generic)
93
+ - `question.answer`: null until user sets it; once answered, the selected option id or free-text
94
+ - `question.status`: "unanswered" | "answered" | "chat-more" (has chat_more but no answer yet)
95
+ </step>
96
+
97
+ <step name="generate_html">
98
+ Write a self-contained HTML companion file to:
99
+
100
+ ```
101
+ {phase_dir}/{padded_phase}-QUESTIONS.html
102
+ ```
103
+
104
+ The file must be a single self-contained HTML file with inline CSS and JavaScript. No external dependencies.
105
+
106
+ **Layout:**
107
+
108
+ ```
109
+ ┌─────────────────────────────────────────────────────┐
110
+ │ Phase {N}: {phase_name} — Discussion Questions │
111
+ │ ┌──────────────────────────────────────────────┐ │
112
+ │ │ 12 total | 3 answered | 9 remaining │ │
113
+ │ └──────────────────────────────────────────────┘ │
114
+ ├─────────────────────────────────────────────────────┤
115
+ │ ▼ Visual Style (3 questions) │
116
+ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
117
+ │ │ Q-01 │ │ Q-02 │ │ Q-03 │ │
118
+ │ │ Layout │ │ Density │ │ Colors │ │
119
+ │ │ ... │ │ ... │ │ ... │ │
120
+ │ └──────────┘ └──────────┘ └──────────┘ │
121
+ │ ▼ Data Model (2 questions) │
122
+ │ ... │
123
+ └─────────────────────────────────────────────────────┘
124
+ ```
125
+
126
+ **Stats bar:**
127
+ - Total questions, answered count, remaining count
128
+ - A simple CSS progress bar (green fill = answered / total)
129
+
130
+ **Section headers:**
131
+ - Collapsible via click — show/hide questions in the section
132
+ - Show answered count for the section (e.g., "2/4 answered")
133
+
134
+ **Question cards (3-column grid):**
135
+ Each card contains:
136
+ - Question ID badge (e.g., "Q-01") and title
137
+ - Context annotation (gray italic text)
138
+ - Option list: radio buttons with bold label + description text
139
+ - Chat more textarea (orange border when content present)
140
+ - Card highlighted green when answered
141
+
142
+ **JavaScript behavior:**
143
+ - On radio button select: mark question as answered in page state; update stats bar
144
+ - On textarea input: update chat_more content in page state; show orange border if content present
145
+ - "Save answers" button at top and bottom: serializes page state back to the JSON file path
146
+
147
+ **Save mechanism:**
148
+ The Save button writes the updated JSON back using the File System Access API if available, otherwise generates a downloadable JSON file the user can save over the original. Include clear instructions in the UI:
149
+
150
+ ```
151
+ After answering, click "Save answers" — or download the JSON and replace the original file.
152
+ Then return to Claude and say "refresh" to process your answers.
153
+ ```
154
+
155
+ **Answered question styling:**
156
+ - Card border: `2px solid #22c55e` (green)
157
+ - Card background: `#f0fdf4` (light green tint)
158
+
159
+ **Unanswered question styling:**
160
+ - Card border: `1px solid #e2e8f0` (gray)
161
+ - Card background: `white`
162
+
163
+ **Chat more textarea:**
164
+ - Placeholder: "Add context, nuance, or clarification for this question..."
165
+ - Normal border: `1px solid #e2e8f0`
166
+ - Active (has content) border: `2px solid #f97316` (orange)
167
+ </step>
168
+
169
+ <step name="notify_user">
170
+ After writing both files, print this message to the user:
171
+
172
+ ```
173
+ Questions ready for Phase {N}: {phase_name}
174
+
175
+ HTML (open in browser/IDE): {phase_dir}/{padded_phase}-QUESTIONS.html
176
+ JSON (state file): {phase_dir}/{padded_phase}-QUESTIONS.json
177
+
178
+ {total} questions across {section_count} topics.
179
+
180
+ Open the HTML file, answer the questions at your own pace, then save.
181
+
182
+ When ready, tell me:
183
+ "refresh" — process your answers and update the file
184
+ "finalize" — generate CONTEXT.md from all answered questions
185
+ "explain Q-05" — elaborate on a specific question
186
+ "exit power mode" — return to standard one-by-one discussion (answers carry over)
187
+ ```
188
+ </step>
189
+
190
+ <step name="wait_loop">
191
+ Enter wait mode. Claude listens for user commands and handles each:
192
+
193
+ ---
194
+
195
+ **"refresh"** (or "process answers", "update", "re-read"):
196
+
197
+ 1. Read `{phase_dir}/{padded_phase}-QUESTIONS.json`
198
+ 2. Recalculate stats: count answered, chat_more, remaining
199
+ 3. Write updated stats back to the JSON
200
+ 4. Re-generate the HTML file with the updated state (answered cards highlighted green, progress bar updated)
201
+ 5. Report to user:
202
+
203
+ ```
204
+ Refreshed. Updated state:
205
+ Answered: {answered} / {total}
206
+ Remaining: {remaining}
207
+ Chat-more: {chat_more}
208
+
209
+ {phase_dir}/{padded_phase}-QUESTIONS.html updated.
210
+
211
+ Answer more questions, then say "refresh" again, or say "finalize" when done.
212
+ ```
213
+
214
+ ---
215
+
216
+ **"finalize"** (or "done", "generate context", "write context"):
217
+
218
+ Proceed to the **finalize** step.
219
+
220
+ ---
221
+
222
+ **"explain Q-{N}"** (or "more info on Q-{N}", "elaborate Q-{N}"):
223
+
224
+ 1. Find the question by ID in the JSON
225
+ 2. Provide a detailed explanation: why this decision matters, how it affects the downstream plan, what additional context from the codebase is relevant
226
+ 3. Return to wait mode
227
+
228
+ ---
229
+
230
+ **"exit power mode"** (or "switch to interactive"):
231
+
232
+ 1. Read all currently answered questions from JSON
233
+ 2. Load answers into the internal accumulator as if they were answered interactively
234
+ 3. Continue with standard `discuss_areas` step from discuss-phase.md for any unanswered questions
235
+ 4. Generate CONTEXT.md as normal
236
+
237
+ ---
238
+
239
+ **Any other message:**
240
+ Respond helpfully, then remind the user of available commands:
241
+ ```
242
+ (Power mode active — say "refresh", "finalize", "explain Q-N", or "exit power mode")
243
+ ```
244
+ </step>
245
+
246
+ <step name="finalize">
247
+ Process all answered questions from the JSON file and generate CONTEXT.md.
248
+
249
+ 1. Read `{phase_dir}/{padded_phase}-QUESTIONS.json`
250
+ 2. Filter to questions where `answer` is not null/empty
251
+ 3. Group decisions by section
252
+ 4. For each answered question, format as a decision entry:
253
+ - Decision: the selected option label (or custom text if free-form answer)
254
+ - Rationale: the option description, plus `chat_more` content if present
255
+ - Status: "Decided" if fully answered, "Needs clarification" if only chat_more with no option selected
256
+
257
+ 5. Write CONTEXT.md using the standard context template format:
258
+ - `<decisions>` section with all answered questions grouped by section
259
+ - `<deferred_ideas>` section for unanswered questions (carry forward for future discussion)
260
+ - `<specifics>` section for any chat_more content that adds nuance
261
+ - `<code_context>` section with reusable assets found during analysis
262
+ - `<canonical_refs>` section (MANDATORY — paths to relevant specs/docs)
263
+
264
+ 6. If fewer than 50% of questions were answered, warn the user:
265
+ ```
266
+ Warning: Only {answered}/{total} questions answered ({pct}%).
267
+ CONTEXT.md generated with available decisions. Unanswered questions listed as deferred.
268
+ Consider running /sdd-discuss-phase {N} again to refine before planning.
269
+ ```
270
+
271
+ 7. Print completion message:
272
+ ```
273
+ CONTEXT.md written: {phase_dir}/{padded_phase}-CONTEXT.md
274
+
275
+ Decisions captured: {answered}
276
+ Deferred: {remaining}
277
+
278
+ Next step: /sdd-plan-phase {N}
279
+ ```
280
+ </step>
281
+
282
+ <success_criteria>
283
+ - Questions generated into well-structured JSON covering all identified gray areas
284
+ - HTML companion file is self-contained and usable without a server
285
+ - Stats bar accurately reflects answered/remaining counts after each refresh
286
+ - Answered questions highlighted green in HTML
287
+ - CONTEXT.md generated in the same format as standard discuss-phase output
288
+ - Unanswered questions preserved as deferred items (not silently dropped)
289
+ - `canonical_refs` section always present in CONTEXT.md (MANDATORY)
290
+ - User knows how to refresh, finalize, explain, or exit power mode
291
+ </success_criteria>