@bhargavvc/sdd-cc 1.30.0 → 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 +2151 -551
  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
@@ -0,0 +1,497 @@
1
+ <purpose>
2
+ Auto-fix issues from REVIEW.md. Validates phase, checks config gate, verifies REVIEW.md exists and has fixable issues, spawns sdd-code-fixer agent, handles --auto iteration loop (capped at 3), commits REVIEW-FIX.md once at the end, and presents results.
3
+ </purpose>
4
+
5
+ <required_reading>
6
+ Read all files referenced by the invoking prompt's execution_context before starting.
7
+ </required_reading>
8
+
9
+ <available_agent_types>
10
+ - sdd-code-fixer: Applies fixes to code review findings
11
+ - sdd-code-reviewer: Reviews source files for bugs and issues
12
+ </available_agent_types>
13
+
14
+ <process>
15
+
16
+ <step name="initialize">
17
+ Parse arguments and load project state:
18
+
19
+ ```bash
20
+ PHASE_ARG="${1}"
21
+ INIT=$(node "$HOME/.claude/sdd/bin/sdd-tools.cjs" init phase-op "${PHASE_ARG}")
22
+ if [[ "$INIT" == @file:* ]]; then INIT=$(cat "${INIT#@file:}"); fi
23
+ ```
24
+
25
+ Parse from init JSON: `phase_found`, `phase_dir`, `phase_number`, `phase_name`, `padded_phase`, `commit_docs`.
26
+
27
+ **Input sanitization (defense-in-depth):**
28
+ ```bash
29
+ # Validate PADDED_PHASE contains only digits and optional dot (e.g., "02", "03.1")
30
+ if ! [[ "$PADDED_PHASE" =~ ^[0-9]+(\.[0-9]+)?$ ]]; then
31
+ echo "Error: Invalid phase number format: '${PADDED_PHASE}'. Expected digits (e.g., 02, 03.1)."
32
+ # Exit workflow
33
+ fi
34
+ ```
35
+
36
+ **Phase validation (before config gate):**
37
+ If `phase_found` is false, report error and exit:
38
+ ```
39
+ Error: Phase ${PHASE_ARG} not found. Run /sdd-status to see available phases.
40
+ ```
41
+
42
+ This runs BEFORE config gate check so user errors are surfaced immediately regardless of config state.
43
+
44
+ Parse optional flags from $ARGUMENTS:
45
+
46
+ ```bash
47
+ FIX_ALL=false
48
+ AUTO_MODE=false
49
+ for arg in "$@"; do
50
+ if [[ "$arg" == "--all" ]]; then FIX_ALL=true; fi
51
+ if [[ "$arg" == "--auto" ]]; then AUTO_MODE=true; fi
52
+ done
53
+ ```
54
+
55
+ Compute scope variable:
56
+
57
+ ```bash
58
+ if [ "$FIX_ALL" = "true" ]; then
59
+ FIX_SCOPE="all"
60
+ else
61
+ FIX_SCOPE="critical_warning"
62
+ fi
63
+ ```
64
+
65
+ Compute review and fix report paths:
66
+
67
+ ```bash
68
+ REVIEW_PATH="${PHASE_DIR}/${PADDED_PHASE}-REVIEW.md"
69
+ FIX_REPORT_PATH="${PHASE_DIR}/${PADDED_PHASE}-REVIEW-FIX.md"
70
+ ```
71
+ </step>
72
+
73
+ <step name="check_config_gate">
74
+ Check if code review is enabled via config:
75
+
76
+ ```bash
77
+ CODE_REVIEW_ENABLED=$(node "$HOME/.claude/sdd/bin/sdd-tools.cjs" config-get workflow.code_review 2>/dev/null || echo "true")
78
+ ```
79
+
80
+ If CODE_REVIEW_ENABLED is "false":
81
+ ```
82
+ Code review fix skipped (workflow.code_review=false in config)
83
+ ```
84
+ Exit workflow.
85
+
86
+ Default is true — only skip on explicit false. This check runs AFTER phase validation so invalid phase errors are shown first.
87
+
88
+ Note: This reuses the `workflow.code_review` config key rather than introducing a separate `workflow.code_review_fix` key. Rationale: fixes are meaningless without review, so a single toggle makes sense. If independent control is needed later, a separate key can be added in v2.
89
+ </step>
90
+
91
+ <step name="check_review_exists">
92
+ Verify that REVIEW.md exists:
93
+
94
+ ```bash
95
+ if [ ! -f "${REVIEW_PATH}" ]; then
96
+ echo "Error: No REVIEW.md found for Phase ${PHASE_ARG}. Run /sdd-code-review ${PHASE_ARG} first."
97
+ exit 1
98
+ fi
99
+ ```
100
+
101
+ Do NOT auto-run code-review. Require explicit user action to ensure review intent is clear.
102
+ </step>
103
+
104
+ <step name="check_review_status">
105
+ Parse REVIEW.md frontmatter to check status and extract context for --auto loop:
106
+
107
+ ```bash
108
+ # Parse status field
109
+ REVIEW_STATUS=$(REVIEW_PATH="${REVIEW_PATH}" node -e "
110
+ const fs = require('fs');
111
+ const content = fs.readFileSync(process.env.REVIEW_PATH, 'utf-8');
112
+ const match = content.match(/^---\n([\s\S]*?)\n---/);
113
+ if (match && /status:\s*(\S+)/.test(match[1])) {
114
+ console.log(match[1].match(/status:\s*(\S+)/)[1]);
115
+ } else {
116
+ console.log('unknown');
117
+ }
118
+ " 2>/dev/null)
119
+ ```
120
+
121
+ If status is "clean" or "skipped":
122
+ ```
123
+ No issues to fix in Phase ${PHASE_ARG} REVIEW.md (status: ${REVIEW_STATUS}).
124
+ ```
125
+ Exit workflow.
126
+
127
+ If status is "unknown":
128
+ ```
129
+ Warning: Could not parse REVIEW.md status. Proceeding with fix attempt.
130
+ ```
131
+
132
+ Extract review depth for --auto re-review:
133
+
134
+ ```bash
135
+ REVIEW_DEPTH=$(REVIEW_PATH="${REVIEW_PATH}" node -e "
136
+ const fs = require('fs');
137
+ const content = fs.readFileSync(process.env.REVIEW_PATH, 'utf-8');
138
+ const match = content.match(/^---\n([\s\S]*?)\n---/);
139
+ if (match && /depth:\s*(\S+)/.test(match[1])) {
140
+ console.log(match[1].match(/depth:\s*(\S+)/)[1]);
141
+ } else {
142
+ console.log('standard');
143
+ }
144
+ " 2>/dev/null)
145
+ ```
146
+
147
+ Extract original review file list for --auto re-review scope persistence:
148
+
149
+ ```bash
150
+ # Extract review file list — portable bash 3.2+ (no mapfile, handles spaces in paths)
151
+ REVIEW_FILES_ARRAY=()
152
+ while IFS= read -r line; do
153
+ [ -n "$line" ] && REVIEW_FILES_ARRAY+=("$line")
154
+ done < <(REVIEW_PATH="${REVIEW_PATH}" node -e "
155
+ const fs = require('fs');
156
+ const content = fs.readFileSync(process.env.REVIEW_PATH, 'utf-8');
157
+ const match = content.match(/^---\n([\s\S]*?)\n---/);
158
+ if (match) {
159
+ const fm = match[1];
160
+ // Try YAML array format: files_reviewed_list: [file1, file2]
161
+ const bracketMatch = fm.match(/files_reviewed_list:\s*\[([^\]]+)\]/);
162
+ if (bracketMatch) {
163
+ bracketMatch[1].split(',').map(f => f.trim()).filter(Boolean).forEach(f => console.log(f));
164
+ } else {
165
+ // Try YAML list format: files_reviewed_list:\n - file1\n - file2
166
+ let inList = false;
167
+ for (const line of fm.split('\n')) {
168
+ if (/files_reviewed_list:/.test(line)) { inList = true; continue; }
169
+ if (inList && /^\s+-\s+(.+)/.test(line)) { console.log(line.match(/^\s+-\s+(.+)/)[1].trim()); }
170
+ else if (inList && /^\S/.test(line)) { break; }
171
+ }
172
+ }
173
+ }
174
+ " 2>/dev/null)
175
+ ```
176
+
177
+ If REVIEW.md contains a `files_reviewed_list` frontmatter field, use that as the re-review scope. If not present, fall back to re-reviewing the full phase (same behavior as initial code-review).
178
+ </step>
179
+
180
+ <step name="spawn_fixer">
181
+ Spawn the sdd-code-fixer agent with config:
182
+
183
+ ```bash
184
+ # Build config for agent
185
+ echo "Applying fixes from ${REVIEW_PATH}..."
186
+ echo "Fix scope: ${FIX_SCOPE}"
187
+ ```
188
+
189
+ Use Task() to spawn agent:
190
+
191
+ ```
192
+ Task(subagent_type="sdd-code-fixer", prompt="
193
+ <files_to_read>
194
+ ${REVIEW_PATH}
195
+ </files_to_read>
196
+
197
+ <config>
198
+ phase_dir: ${PHASE_DIR}
199
+ padded_phase: ${PADDED_PHASE}
200
+ review_path: ${REVIEW_PATH}
201
+ fix_scope: ${FIX_SCOPE}
202
+ fix_report_path: ${FIX_REPORT_PATH}
203
+ iteration: 1
204
+ </config>
205
+
206
+ Read REVIEW.md findings, apply fixes, commit each atomically, write REVIEW-FIX.md. Do NOT commit REVIEW-FIX.md (orchestrator handles that).
207
+ ")
208
+ ```
209
+
210
+ **Agent failure handling:**
211
+
212
+ If Task() fails:
213
+ ```
214
+ Error: Code fix agent failed: ${error_message}
215
+ ```
216
+
217
+ Check if FIX_REPORT_PATH exists:
218
+ - If yes: "Partial success — some fixes may have been committed."
219
+ - If no: "No fixes applied."
220
+
221
+ Either way:
222
+ ```
223
+ Some fix commits may already exist in git history — check git log for fix(${PADDED_PHASE}) commits.
224
+ You can retry with /sdd-code-review-fix ${PHASE_ARG}.
225
+ ```
226
+
227
+ Exit workflow (skip auto loop).
228
+ </step>
229
+
230
+ <step name="auto_iteration_loop">
231
+ Only runs if AUTO_MODE is true. If AUTO_MODE is false, skip this step entirely.
232
+
233
+ ```bash
234
+ if [ "$AUTO_MODE" = "true" ]; then
235
+ # Iteration semantics: the initial fix pass (step 5) is iteration 1.
236
+ # This loop runs iterations 2..MAX_ITERATIONS (re-review + re-fix cycles).
237
+ # Total fix passes = MAX_ITERATIONS. Loop uses -lt (not -le) intentionally.
238
+ ITERATION=1
239
+ MAX_ITERATIONS=3
240
+
241
+ while [ $ITERATION -lt $MAX_ITERATIONS ]; do
242
+ ITERATION=$((ITERATION + 1))
243
+
244
+ echo ""
245
+ echo "═══════════════════════════════════════════════════════"
246
+ echo " --auto: Starting iteration ${ITERATION}/${MAX_ITERATIONS}"
247
+ echo "═══════════════════════════════════════════════════════"
248
+ echo ""
249
+
250
+ # Re-review using same depth and file scope as original review
251
+ echo "Re-reviewing phase ${PHASE_ARG} at ${REVIEW_DEPTH} depth..."
252
+
253
+ # Backup previous REVIEW.md and REVIEW-FIX.md before overwriting
254
+ if [ -f "${REVIEW_PATH}" ]; then
255
+ cp "${REVIEW_PATH}" "${REVIEW_PATH%.md}.iter${ITERATION}.md" 2>/dev/null || true
256
+ fi
257
+ if [ -f "${FIX_REPORT_PATH}" ]; then
258
+ cp "${FIX_REPORT_PATH}" "${FIX_REPORT_PATH%.md}.iter${ITERATION}.md" 2>/dev/null || true
259
+ fi
260
+
261
+ # If original review had explicit file list, pass it safely to re-review agent
262
+ FILES_CONFIG=""
263
+ if [ ${#REVIEW_FILES_ARRAY[@]} -gt 0 ]; then
264
+ FILES_CONFIG="files:"
265
+ for f in "${REVIEW_FILES_ARRAY[@]}"; do
266
+ FILES_CONFIG="${FILES_CONFIG}
267
+ - ${f}"
268
+ done
269
+ fi
270
+
271
+ # Spawn sdd-code-reviewer agent to re-review
272
+ # (This overwrites REVIEW_PATH with latest review state)
273
+ Task(subagent_type="sdd-code-reviewer", prompt="
274
+ <config>
275
+ depth: ${REVIEW_DEPTH}
276
+ phase_dir: ${PHASE_DIR}
277
+ review_path: ${REVIEW_PATH}
278
+ ${FILES_CONFIG}
279
+ </config>
280
+
281
+ Re-review the phase at ${REVIEW_DEPTH} depth. Write findings to ${REVIEW_PATH}.
282
+ Do NOT commit the output — the orchestrator handles that.
283
+ ")
284
+
285
+ # Check new REVIEW.md status
286
+ NEW_STATUS=$(REVIEW_PATH="${REVIEW_PATH}" node -e "
287
+ const fs = require('fs');
288
+ const content = fs.readFileSync(process.env.REVIEW_PATH, 'utf-8');
289
+ const match = content.match(/^---\n([\s\S]*?)\n---/);
290
+ if (match && /status:\s*(\S+)/.test(match[1])) {
291
+ console.log(match[1].match(/status:\s*(\S+)/)[1]);
292
+ } else {
293
+ console.log('unknown');
294
+ }
295
+ " 2>/dev/null)
296
+
297
+ if [ "$NEW_STATUS" = "clean" ]; then
298
+ echo ""
299
+ echo "✓ All issues resolved after iteration ${ITERATION}."
300
+ break
301
+ fi
302
+
303
+ # Still has issues — spawn fixer again
304
+ echo "Issues remain. Applying fixes for iteration ${ITERATION}..."
305
+
306
+ Task(subagent_type="sdd-code-fixer", prompt="
307
+ <files_to_read>
308
+ ${REVIEW_PATH}
309
+ </files_to_read>
310
+
311
+ <config>
312
+ phase_dir: ${PHASE_DIR}
313
+ padded_phase: ${PADDED_PHASE}
314
+ review_path: ${REVIEW_PATH}
315
+ fix_scope: ${FIX_SCOPE}
316
+ fix_report_path: ${FIX_REPORT_PATH}
317
+ iteration: ${ITERATION}
318
+ </config>
319
+
320
+ Read REVIEW.md findings, apply fixes, commit each atomically, write REVIEW-FIX.md (overwrite previous). Do NOT commit REVIEW-FIX.md.
321
+ ")
322
+
323
+ # Check if fixer succeeded
324
+ if [ ! -f "${FIX_REPORT_PATH}" ]; then
325
+ echo "Warning: Iteration ${ITERATION} fixer failed to produce fix report. Stopping auto-loop."
326
+ break
327
+ fi
328
+ done
329
+
330
+ # After loop completes
331
+ if [ $ITERATION -ge $MAX_ITERATIONS ]; then
332
+ echo ""
333
+ echo "⚠ Reached maximum iterations (${MAX_ITERATIONS}). Remaining issues documented in REVIEW-FIX.md."
334
+ fi
335
+ fi
336
+ ```
337
+
338
+ Key design decisions for --auto (addresses ALL review HIGH concerns):
339
+ 1. **Re-review scope**: Uses REVIEW_FILES_ARRAY from original REVIEW.md frontmatter, falling back to full phase scope. Scope is NOT lost between iterations. Uses portable while-read loop (bash 3.2+ compatible, handles spaces in paths).
340
+ 2. **Artifact semantics**: REVIEW.md is overwritten by each re-review (latest review state). REVIEW-FIX.md is overwritten by each fixer iteration (latest fix state with iteration count). There is ONE final version of each artifact, not per-iteration copies.
341
+ Backup files (.iterN.md) preserve history for post-mortem analysis if iterations degrade.
342
+ 3. **Commit timing**: Fix commits happen per-finding inside the agent. REVIEW-FIX.md is NOT committed until step 7 (after ALL iterations complete). Only ONE docs commit for REVIEW-FIX.md, not one per iteration.
343
+ </step>
344
+
345
+ <step name="commit_fix_report">
346
+ After ALL iterations complete (or single pass in non-auto mode), validate and commit REVIEW-FIX.md:
347
+
348
+ ```bash
349
+ if [ -f "${FIX_REPORT_PATH}" ]; then
350
+ # Validate REVIEW-FIX.md has valid YAML frontmatter with status field
351
+ HAS_STATUS=$(REVIEW_PATH="${REVIEW_PATH}" node -e "
352
+ const fs = require('fs');
353
+ const content = fs.readFileSync(process.env.FIX_REPORT_PATH, 'utf-8');
354
+ const match = content.match(/^---\n([\s\S]*?)\n---/);
355
+ if (match && /status:/.test(match[1])) { console.log('valid'); } else { console.log('invalid'); }
356
+ " 2>/dev/null)
357
+
358
+ if [ "$HAS_STATUS" = "valid" ]; then
359
+ echo "REVIEW-FIX.md created at ${FIX_REPORT_PATH}"
360
+
361
+ if [ "$COMMIT_DOCS" = "true" ]; then
362
+ node "$HOME/.claude/sdd/bin/sdd-tools.cjs" commit \
363
+ "docs(${PADDED_PHASE}): add code review fix report" \
364
+ --files "${FIX_REPORT_PATH}"
365
+ fi
366
+ else
367
+ echo "Warning: REVIEW-FIX.md has invalid frontmatter (no status field). Not committing."
368
+ echo "Agent may have produced malformed output. Review manually: ${FIX_REPORT_PATH}"
369
+ fi
370
+ else
371
+ echo "Warning: REVIEW-FIX.md not found at ${FIX_REPORT_PATH}."
372
+ echo "Agent may have failed before writing report."
373
+ echo "Check git log for any fix(${PADDED_PHASE}) commits that were applied."
374
+ fi
375
+ ```
376
+
377
+ This commit happens ONCE at the end of the workflow, after all iterations (if --auto) complete. Not per-iteration.
378
+ </step>
379
+
380
+ <step name="present_results">
381
+ Parse REVIEW-FIX.md frontmatter and present formatted summary to user.
382
+
383
+ First check if fix report exists:
384
+
385
+ ```bash
386
+ if [ ! -f "${FIX_REPORT_PATH}" ]; then
387
+ echo ""
388
+ echo "═══════════════════════════════════════════════════════════════"
389
+ echo ""
390
+ echo " ⚠ No fix report generated"
391
+ echo ""
392
+ echo "───────────────────────────────────────────────────────────────"
393
+ echo ""
394
+ echo "The fixer agent may have failed before completing."
395
+ echo "Check git log for any fix(${PADDED_PHASE}) commits."
396
+ echo ""
397
+ echo "Retry: /sdd-code-review-fix ${PHASE_ARG}"
398
+ echo ""
399
+ echo "═══════════════════════════════════════════════════════════════"
400
+ exit 1
401
+ fi
402
+ ```
403
+
404
+ Extract frontmatter fields:
405
+
406
+ ```bash
407
+ # Extract only the YAML frontmatter block (between first two --- lines)
408
+ FIX_FRONTMATTER=$(REVIEW_PATH="${REVIEW_PATH}" node -e "
409
+ const fs = require('fs');
410
+ const content = fs.readFileSync(process.env.FIX_REPORT_PATH, 'utf-8');
411
+ const match = content.match(/^---\n([\s\S]*?)\n---/);
412
+ if (match) process.stdout.write(match[1]);
413
+ " 2>/dev/null)
414
+
415
+ # Parse fields from frontmatter only (not full file)
416
+ FIX_STATUS=$(echo "$FIX_FRONTMATTER" | grep "^status:" | cut -d: -f2 | xargs)
417
+ FINDINGS_IN_SCOPE=$(echo "$FIX_FRONTMATTER" | grep "^findings_in_scope:" | cut -d: -f2 | xargs)
418
+ FIXED_COUNT=$(echo "$FIX_FRONTMATTER" | grep "^fixed:" | cut -d: -f2 | xargs)
419
+ SKIPPED_COUNT=$(echo "$FIX_FRONTMATTER" | grep "^skipped:" | cut -d: -f2 | xargs)
420
+ ITERATION_COUNT=$(echo "$FIX_FRONTMATTER" | grep "^iteration:" | cut -d: -f2 | xargs)
421
+ ```
422
+
423
+ Display formatted inline summary:
424
+
425
+ ```bash
426
+ echo ""
427
+ echo "═══════════════════════════════════════════════════════════════"
428
+ echo ""
429
+ echo " Code Review Fix Complete: Phase ${PHASE_NUMBER} (${PHASE_NAME})"
430
+ echo ""
431
+ echo "───────────────────────────────────────────────────────────────"
432
+ echo ""
433
+ echo " Fix Scope: ${FIX_SCOPE}"
434
+ echo " Findings: ${FINDINGS_IN_SCOPE}"
435
+ echo " Fixed: ${FIXED_COUNT}"
436
+ echo " Skipped: ${SKIPPED_COUNT}"
437
+ if [ "$AUTO_MODE" = "true" ]; then
438
+ echo " Iterations: ${ITERATION_COUNT}"
439
+ fi
440
+ echo " Status: ${FIX_STATUS}"
441
+ echo ""
442
+ echo "───────────────────────────────────────────────────────────────"
443
+ echo ""
444
+ ```
445
+
446
+ If status is "all_fixed":
447
+ ```bash
448
+ if [ "$FIX_STATUS" = "all_fixed" ]; then
449
+ echo "✓ All issues resolved."
450
+ echo ""
451
+ echo "Full report: ${FIX_REPORT_PATH}"
452
+ echo ""
453
+ echo "Next step:"
454
+ echo " /sdd-verify-work — Verify phase completion"
455
+ echo ""
456
+ fi
457
+ ```
458
+
459
+ If status is "partial" or "none_fixed":
460
+ ```bash
461
+ if [ "$FIX_STATUS" = "partial" ] || [ "$FIX_STATUS" = "none_fixed" ]; then
462
+ echo "⚠ Some issues could not be fixed automatically."
463
+ echo ""
464
+ echo "Full report: ${FIX_REPORT_PATH}"
465
+ echo ""
466
+ echo "Next steps:"
467
+ echo " cat ${FIX_REPORT_PATH} — View fix report"
468
+ echo " /sdd-code-review ${PHASE_NUMBER} — Re-review code"
469
+ echo " /sdd-verify-work — Verify phase completion"
470
+ echo ""
471
+ fi
472
+ ```
473
+
474
+ ```bash
475
+ echo "═══════════════════════════════════════════════════════════════"
476
+ ```
477
+ </step>
478
+
479
+ </process>
480
+
481
+ <platform_notes>
482
+ **Windows:** This workflow uses bash features (arrays, variable expansion, while loops). On Windows, it requires Git Bash or WSL. Native PowerShell is not supported. The CI matrix (Ubuntu/macOS/Windows) runs under Git Bash on Windows runners, which provides bash compatibility.
483
+ </platform_notes>
484
+
485
+ <success_criteria>
486
+ - [ ] Phase validated before config gate check
487
+ - [ ] Config gate checked (workflow.code_review)
488
+ - [ ] REVIEW.md existence verified (error if missing)
489
+ - [ ] REVIEW.md status checked (skip if clean/skipped)
490
+ - [ ] Agent spawned with correct config (review_path, fix_scope, fix_report_path)
491
+ - [ ] Agent failure handled with partial-success awareness (some fix commits may exist)
492
+ - [ ] --auto iteration loop respects 3-iteration cap
493
+ - [ ] --auto re-review uses persisted file scope (not lost between iterations)
494
+ - [ ] REVIEW-FIX.md committed ONCE after all iterations (not per-iteration)
495
+ - [ ] Missing fix report handled with explicit error message in present_results
496
+ - [ ] Results presented inline with next step suggestion
497
+ </success_criteria>