gsd-opencode 1.33.3 → 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 (118) hide show
  1. package/agents/gsd-advisor-researcher.md +23 -0
  2. package/agents/gsd-ai-researcher.md +142 -0
  3. package/agents/gsd-code-fixer.md +523 -0
  4. package/agents/gsd-code-reviewer.md +361 -0
  5. package/agents/gsd-debugger.md +14 -1
  6. package/agents/gsd-domain-researcher.md +162 -0
  7. package/agents/gsd-eval-auditor.md +170 -0
  8. package/agents/gsd-eval-planner.md +161 -0
  9. package/agents/gsd-executor.md +70 -7
  10. package/agents/gsd-framework-selector.md +167 -0
  11. package/agents/gsd-intel-updater.md +320 -0
  12. package/agents/gsd-phase-researcher.md +26 -0
  13. package/agents/gsd-plan-checker.md +12 -0
  14. package/agents/gsd-planner.md +16 -6
  15. package/agents/gsd-project-researcher.md +23 -0
  16. package/agents/gsd-ui-researcher.md +23 -0
  17. package/agents/gsd-verifier.md +55 -1
  18. package/commands/gsd/gsd-ai-integration-phase.md +36 -0
  19. package/commands/gsd/gsd-audit-fix.md +33 -0
  20. package/commands/gsd/gsd-autonomous.md +1 -0
  21. package/commands/gsd/gsd-code-review-fix.md +52 -0
  22. package/commands/gsd/gsd-code-review.md +55 -0
  23. package/commands/gsd/gsd-eval-review.md +32 -0
  24. package/commands/gsd/gsd-explore.md +27 -0
  25. package/commands/gsd/gsd-from-gsd2.md +45 -0
  26. package/commands/gsd/gsd-import.md +36 -0
  27. package/commands/gsd/gsd-intel.md +183 -0
  28. package/commands/gsd/gsd-next.md +2 -0
  29. package/commands/gsd/gsd-reapply-patches.md +58 -3
  30. package/commands/gsd/gsd-review.md +4 -2
  31. package/commands/gsd/gsd-scan.md +26 -0
  32. package/commands/gsd/gsd-undo.md +34 -0
  33. package/commands/gsd/gsd-workstreams.md +6 -6
  34. package/get-shit-done/bin/gsd-tools.cjs +143 -5
  35. package/get-shit-done/bin/lib/commands.cjs +10 -2
  36. package/get-shit-done/bin/lib/config.cjs +71 -37
  37. package/get-shit-done/bin/lib/core.cjs +70 -8
  38. package/get-shit-done/bin/lib/gsd2-import.cjs +511 -0
  39. package/get-shit-done/bin/lib/init.cjs +20 -6
  40. package/get-shit-done/bin/lib/intel.cjs +660 -0
  41. package/get-shit-done/bin/lib/learnings.cjs +378 -0
  42. package/get-shit-done/bin/lib/milestone.cjs +25 -15
  43. package/get-shit-done/bin/lib/model-profiles.cjs +17 -17
  44. package/get-shit-done/bin/lib/phase.cjs +148 -112
  45. package/get-shit-done/bin/lib/roadmap.cjs +12 -5
  46. package/get-shit-done/bin/lib/security.cjs +119 -0
  47. package/get-shit-done/bin/lib/state.cjs +283 -221
  48. package/get-shit-done/bin/lib/template.cjs +8 -4
  49. package/get-shit-done/bin/lib/verify.cjs +42 -5
  50. package/get-shit-done/references/ai-evals.md +156 -0
  51. package/get-shit-done/references/ai-frameworks.md +186 -0
  52. package/get-shit-done/references/common-bug-patterns.md +114 -0
  53. package/get-shit-done/references/few-shot-examples/plan-checker.md +73 -0
  54. package/get-shit-done/references/few-shot-examples/verifier.md +109 -0
  55. package/get-shit-done/references/gates.md +70 -0
  56. package/get-shit-done/references/ios-scaffold.md +123 -0
  57. package/get-shit-done/references/model-profile-resolution.md +6 -7
  58. package/get-shit-done/references/model-profiles.md +20 -14
  59. package/get-shit-done/references/planning-config.md +237 -0
  60. package/get-shit-done/references/thinking-models-debug.md +44 -0
  61. package/get-shit-done/references/thinking-models-execution.md +50 -0
  62. package/get-shit-done/references/thinking-models-planning.md +62 -0
  63. package/get-shit-done/references/thinking-models-research.md +50 -0
  64. package/get-shit-done/references/thinking-models-verification.md +55 -0
  65. package/get-shit-done/references/thinking-partner.md +96 -0
  66. package/get-shit-done/references/universal-anti-patterns.md +6 -1
  67. package/get-shit-done/references/verification-overrides.md +227 -0
  68. package/get-shit-done/templates/AI-SPEC.md +246 -0
  69. package/get-shit-done/workflows/add-tests.md +3 -0
  70. package/get-shit-done/workflows/add-todo.md +2 -0
  71. package/get-shit-done/workflows/ai-integration-phase.md +284 -0
  72. package/get-shit-done/workflows/audit-fix.md +154 -0
  73. package/get-shit-done/workflows/autonomous.md +33 -2
  74. package/get-shit-done/workflows/check-todos.md +2 -0
  75. package/get-shit-done/workflows/cleanup.md +2 -0
  76. package/get-shit-done/workflows/code-review-fix.md +497 -0
  77. package/get-shit-done/workflows/code-review.md +515 -0
  78. package/get-shit-done/workflows/complete-milestone.md +40 -15
  79. package/get-shit-done/workflows/diagnose-issues.md +1 -1
  80. package/get-shit-done/workflows/discovery-phase.md +3 -1
  81. package/get-shit-done/workflows/discuss-phase-assumptions.md +1 -1
  82. package/get-shit-done/workflows/discuss-phase.md +21 -7
  83. package/get-shit-done/workflows/do.md +2 -0
  84. package/get-shit-done/workflows/docs-update.md +2 -0
  85. package/get-shit-done/workflows/eval-review.md +155 -0
  86. package/get-shit-done/workflows/execute-phase.md +307 -57
  87. package/get-shit-done/workflows/execute-plan.md +64 -93
  88. package/get-shit-done/workflows/explore.md +136 -0
  89. package/get-shit-done/workflows/help.md +1 -1
  90. package/get-shit-done/workflows/import.md +273 -0
  91. package/get-shit-done/workflows/inbox.md +387 -0
  92. package/get-shit-done/workflows/manager.md +4 -10
  93. package/get-shit-done/workflows/new-milestone.md +3 -1
  94. package/get-shit-done/workflows/new-project.md +2 -0
  95. package/get-shit-done/workflows/new-workspace.md +2 -0
  96. package/get-shit-done/workflows/next.md +56 -0
  97. package/get-shit-done/workflows/note.md +2 -0
  98. package/get-shit-done/workflows/plan-phase.md +97 -17
  99. package/get-shit-done/workflows/plant-seed.md +3 -0
  100. package/get-shit-done/workflows/pr-branch.md +41 -13
  101. package/get-shit-done/workflows/profile-user.md +4 -2
  102. package/get-shit-done/workflows/quick.md +99 -4
  103. package/get-shit-done/workflows/remove-workspace.md +2 -0
  104. package/get-shit-done/workflows/review.md +53 -6
  105. package/get-shit-done/workflows/scan.md +98 -0
  106. package/get-shit-done/workflows/secure-phase.md +2 -0
  107. package/get-shit-done/workflows/settings.md +18 -3
  108. package/get-shit-done/workflows/ship.md +3 -0
  109. package/get-shit-done/workflows/ui-phase.md +10 -2
  110. package/get-shit-done/workflows/ui-review.md +2 -0
  111. package/get-shit-done/workflows/undo.md +314 -0
  112. package/get-shit-done/workflows/update.md +2 -0
  113. package/get-shit-done/workflows/validate-phase.md +2 -0
  114. package/get-shit-done/workflows/verify-phase.md +83 -0
  115. package/get-shit-done/workflows/verify-work.md +12 -1
  116. package/package.json +1 -1
  117. package/skills/gsd-code-review/SKILL.md +48 -0
  118. package/skills/gsd-code-review-fix/SKILL.md +44 -0
@@ -0,0 +1,515 @@
1
+ <objective>
2
+ Review source files changed during a phase for bugs, security issues, and code quality problems. Computes file scope (--files override > SUMMARY.md > git diff fallback), checks config gate, spawns gsd-code-reviewer agent, commits REVIEW.md, and presents results to user.
3
+ </objective>
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
+ - gsd-code-reviewer: Reviews source files for bugs and quality issues
11
+ </available_agent_types>
12
+
13
+ <process>
14
+
15
+ <step name="initialize">
16
+ Parse arguments and load project state:
17
+
18
+ ```bash
19
+ PHASE_ARG="${1}"
20
+ INIT=$(node "$HOME/.config/opencode/get-shit-done/bin/gsd-tools.cjs" init phase-op "${PHASE_ARG}")
21
+ if [[ "$INIT" == @file:* ]]; then INIT=$(cat "${INIT#@file:}"); fi
22
+ ```
23
+
24
+ Parse from init JSON: `phase_found`, `phase_dir`, `phase_number`, `phase_name`, `padded_phase`, `commit_docs`.
25
+
26
+ **Input sanitization (defense-in-depth):**
27
+ ```bash
28
+ # Validate PADDED_PHASE contains only digits and optional dot (e.g., "02", "03.1")
29
+ if ! [[ "$PADDED_PHASE" =~ ^[0-9]+(\.[0-9]+)?$ ]]; then
30
+ echo "Error: Invalid phase number format: '${PADDED_PHASE}'. Expected digits (e.g., 02, 03.1)."
31
+ # Exit workflow
32
+ fi
33
+ ```
34
+
35
+ **Phase validation (before config gate):**
36
+ If `phase_found` is false, report error and exit:
37
+ ```
38
+ Error: Phase ${PHASE_ARG} not found. Run /gsd-status to see available phases.
39
+ ```
40
+
41
+ This runs BEFORE config gate check so user errors are surfaced immediately regardless of config state.
42
+
43
+ Parse optional flags from $ARGUMENTS:
44
+
45
+ **--depth flag:**
46
+ ```bash
47
+ DEPTH_OVERRIDE=""
48
+ for arg in "$@"; do
49
+ if [[ "$arg" == --depth=* ]]; then
50
+ DEPTH_OVERRIDE="${arg#--depth=}"
51
+ fi
52
+ done
53
+ ```
54
+
55
+ **--files flag:**
56
+ ```bash
57
+ FILES_OVERRIDE=""
58
+ for arg in "$@"; do
59
+ if [[ "$arg" == --files=* ]]; then
60
+ FILES_OVERRIDE="${arg#--files=}"
61
+ fi
62
+ done
63
+ ```
64
+
65
+ If FILES_OVERRIDE is set, split by comma into array:
66
+ ```bash
67
+ if [ -n "$FILES_OVERRIDE" ]; then
68
+ IFS=',' read -ra FILES_ARRAY <<< "$FILES_OVERRIDE"
69
+ fi
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/.config/opencode/get-shit-done/bin/gsd-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 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
+ </step>
88
+
89
+ <step name="resolve_depth">
90
+ Determine review depth with priority order:
91
+
92
+ 1. DEPTH_OVERRIDE from --depth flag (highest priority)
93
+ 2. Config value: `node "$HOME/.config/opencode/get-shit-done/bin/gsd-tools.cjs" config-get workflow.code_review_depth 2>/dev/null`
94
+ 3. Default: "standard"
95
+
96
+ ```bash
97
+ if [ -n "$DEPTH_OVERRIDE" ]; then
98
+ REVIEW_DEPTH="$DEPTH_OVERRIDE"
99
+ else
100
+ CONFIG_DEPTH=$(node "$HOME/.config/opencode/get-shit-done/bin/gsd-tools.cjs" config-get workflow.code_review_depth 2>/dev/null || echo "")
101
+ REVIEW_DEPTH="${CONFIG_DEPTH:-standard}"
102
+ fi
103
+ ```
104
+
105
+ **Validate depth value:**
106
+ ```bash
107
+ case "$REVIEW_DEPTH" in
108
+ quick|standard|deep)
109
+ # Valid
110
+ ;;
111
+ *)
112
+ echo "Warning: Invalid depth '${REVIEW_DEPTH}'. Valid values: quick, standard, deep. Using 'standard'."
113
+ REVIEW_DEPTH="standard"
114
+ ;;
115
+ esac
116
+ ```
117
+ </step>
118
+
119
+ <step name="compute_file_scope">
120
+ Three-tier scoping with explicit precedence:
121
+
122
+ **Tier 1 — --files override (highest precedence per D-08):**
123
+
124
+ If FILES_OVERRIDE is set (from --files flag):
125
+ ```bash
126
+ if [ -n "$FILES_OVERRIDE" ]; then
127
+ REVIEW_FILES=()
128
+ REPO_ROOT=$(git rev-parse --show-toplevel 2>/dev/null)
129
+
130
+ for file_path in "${FILES_ARRAY[@]}"; do
131
+ # Security: validate path is within repository (prevent path traversal)
132
+ ABS_PATH=$(realpath -m "${file_path}" 2>/dev/null || echo "${file_path}")
133
+ if [[ "$ABS_PATH" != "$REPO_ROOT"* ]]; then
134
+ echo "Error: File path outside repository, skipping: ${file_path}"
135
+ continue
136
+ fi
137
+
138
+ # Validate path exists (relative to repo root)
139
+ if [ -f "${REPO_ROOT}/${file_path}" ] || [ -f "${file_path}" ]; then
140
+ REVIEW_FILES+=("$file_path")
141
+ else
142
+ echo "Warning: File not found, skipping: ${file_path}"
143
+ fi
144
+ done
145
+
146
+ echo "File scope: ${#REVIEW_FILES[@]} files from --files override"
147
+ fi
148
+ ```
149
+
150
+ Skip SUMMARY/git scoping entirely when --files is provided.
151
+
152
+ **Tier 2 — SUMMARY.md extraction (primary per D-01):**
153
+
154
+ If --files NOT provided:
155
+ ```bash
156
+ if [ -z "$FILES_OVERRIDE" ]; then
157
+ SUMMARIES=$(ls "${PHASE_DIR}"/*-SUMMARY.md 2>/dev/null)
158
+ REVIEW_FILES=()
159
+
160
+ if [ -n "$SUMMARIES" ]; then
161
+ for summary in $SUMMARIES; do
162
+ # Extract key_files.created and key_files.modified using node for reliable YAML parsing
163
+ # This avoids fragile awk parsing that breaks on indentation differences
164
+ EXTRACTED=$(node -e "
165
+ const fs = require('fs');
166
+ const content = fs.readFileSync('$summary', 'utf-8');
167
+ const match = content.match(/^---\n([\s\S]*?)\n---/);
168
+ if (!match) { process.exit(0); }
169
+ const yaml = match[1];
170
+ const files = [];
171
+ let inSection = null;
172
+ for (const line of yaml.split('\n')) {
173
+ if (/^\s+created:/.test(line)) { inSection = 'created'; continue; }
174
+ if (/^\s+modified:/.test(line)) { inSection = 'modified'; continue; }
175
+ if (/^\s+\w+:/.test(line) && !/^\s+-/.test(line)) { inSection = null; continue; }
176
+ if (inSection && /^\s+-\s+(.+)/.test(line)) {
177
+ files.push(line.match(/^\s+-\s+(.+)/)[1].trim());
178
+ }
179
+ }
180
+ if (files.length) console.log(files.join('\n'));
181
+ " 2>/dev/null)
182
+
183
+ # Add extracted files to REVIEW_FILES array
184
+ if [ -n "$EXTRACTED" ]; then
185
+ while IFS= read -r file; do
186
+ if [ -n "$file" ]; then
187
+ REVIEW_FILES+=("$file")
188
+ fi
189
+ done <<< "$EXTRACTED"
190
+ fi
191
+ done
192
+
193
+ if [ ${#REVIEW_FILES[@]} -eq 0 ]; then
194
+ echo "Warning: SUMMARY artifacts found but contained no file paths. Falling back to git diff."
195
+ fi
196
+ fi
197
+ fi
198
+ ```
199
+
200
+ **Tier 3 — Git diff fallback (per D-02):**
201
+
202
+ If no SUMMARY.md files found OR no files extracted from them:
203
+ ```bash
204
+ if [ ${#REVIEW_FILES[@]} -eq 0 ]; then
205
+ # Compute diff base from phase commits — fail closed if no reliable base found
206
+ PHASE_COMMITS=$(git log --oneline --all --grep="${PADDED_PHASE}" --format="%H" 2>/dev/null)
207
+
208
+ if [ -n "$PHASE_COMMITS" ]; then
209
+ DIFF_BASE=$(echo "$PHASE_COMMITS" | tail -1)^
210
+
211
+ # Verify the parent commit exists (first commit in repo has no parent)
212
+ if ! git rev-parse "${DIFF_BASE}" >/dev/null 2>&1; then
213
+ DIFF_BASE=$(echo "$PHASE_COMMITS" | tail -1)
214
+ fi
215
+
216
+ # Run git diff with specific exclusions (per D-03)
217
+ DIFF_FILES=$(git diff --name-only "${DIFF_BASE}..HEAD" -- . \
218
+ ':!.planning/' ':!ROADMAP.md' ':!STATE.md' \
219
+ ':!*-SUMMARY.md' ':!*-VERIFICATION.md' ':!*-PLAN.md' \
220
+ ':!package-lock.json' ':!yarn.lock' ':!Gemfile.lock' ':!poetry.lock' 2>/dev/null)
221
+
222
+ while IFS= read -r file; do
223
+ [ -n "$file" ] && REVIEW_FILES+=("$file")
224
+ done <<< "$DIFF_FILES"
225
+
226
+ echo "File scope: ${#REVIEW_FILES[@]} files from git diff (base: ${DIFF_BASE})"
227
+ else
228
+ # Fail closed — no reliable diff base found. Do not use arbitrary HEAD~N.
229
+ echo "Warning: No phase commits found for '${PADDED_PHASE}'. Cannot determine reliable diff scope."
230
+ echo "Use --files flag to specify files explicitly: /gsd-code-review ${PHASE_ARG} --files=file1,file2,..."
231
+ fi
232
+ fi
233
+ ```
234
+
235
+ **Post-processing (all tiers):**
236
+
237
+ 1. **Apply exclusions (per D-03):** Remove paths matching planning artifacts
238
+ ```bash
239
+ FILTERED_FILES=()
240
+ for file in "${REVIEW_FILES[@]}"; do
241
+ # Skip planning directory and specific artifacts
242
+ if [[ "$file" == .planning/* ]] || \
243
+ [[ "$file" == ROADMAP.md ]] || \
244
+ [[ "$file" == STATE.md ]] || \
245
+ [[ "$file" == *-SUMMARY.md ]] || \
246
+ [[ "$file" == *-VERIFICATION.md ]] || \
247
+ [[ "$file" == *-PLAN.md ]]; then
248
+ continue
249
+ fi
250
+ FILTERED_FILES+=("$file")
251
+ done
252
+ REVIEW_FILES=("${FILTERED_FILES[@]}")
253
+ ```
254
+
255
+ 2. **Filter deleted files:** Remove paths that don't exist on disk
256
+ ```bash
257
+ EXISTING_FILES=()
258
+ DELETED_COUNT=0
259
+ for file in "${REVIEW_FILES[@]}"; do
260
+ if [ -f "$file" ]; then
261
+ EXISTING_FILES+=("$file")
262
+ else
263
+ DELETED_COUNT=$((DELETED_COUNT + 1))
264
+ fi
265
+ done
266
+ REVIEW_FILES=("${EXISTING_FILES[@]}")
267
+
268
+ if [ $DELETED_COUNT -gt 0 ]; then
269
+ echo "Filtered $DELETED_COUNT deleted files from review scope"
270
+ fi
271
+ ```
272
+
273
+ 3. **Deduplicate:** Remove duplicate paths (portable — bash 3.2+ compatible, handles spaces in paths)
274
+ ```bash
275
+ DEDUPED=()
276
+ while IFS= read -r line; do
277
+ [ -n "$line" ] && DEDUPED+=("$line")
278
+ done < <(printf '%s\n' "${REVIEW_FILES[@]}" | sort -u)
279
+ REVIEW_FILES=("${DEDUPED[@]}")
280
+ ```
281
+
282
+ 4. **Sort:** Alphabetical sort for reproducible agent input (already sorted by sort -u above)
283
+
284
+ **Log final scope and warn if large:**
285
+ ```bash
286
+ if [ -n "$FILES_OVERRIDE" ]; then
287
+ TIER="--files override"
288
+ elif [ -n "$SUMMARIES" ] && [ ${#REVIEW_FILES[@]} -gt 0 ]; then
289
+ TIER="SUMMARY.md"
290
+ else
291
+ TIER="git diff"
292
+ fi
293
+ echo "File scope: ${#REVIEW_FILES[@]} files from ${TIER}"
294
+
295
+ # Warn if file count is very large — may exceed agent context or produce superficial review
296
+ if [ ${#REVIEW_FILES[@]} -gt 50 ]; then
297
+ echo "Warning: ${#REVIEW_FILES[@]} files is a large review scope."
298
+ echo "Consider using --files to narrow scope, or --depth=quick for a faster pass."
299
+ if [ "$REVIEW_DEPTH" = "deep" ]; then
300
+ echo "Switching from deep to standard depth for large file count."
301
+ REVIEW_DEPTH="standard"
302
+ fi
303
+ fi
304
+ ```
305
+ </step>
306
+
307
+ <step name="check_empty_scope">
308
+ If REVIEW_FILES is empty:
309
+ ```
310
+ No source files changed in phase ${PHASE_ARG}. Skipping review.
311
+ ```
312
+ Exit workflow. Do NOT spawn agent or create REVIEW.md.
313
+ </step>
314
+
315
+ <step name="spawn_reviewer">
316
+ Compute the review output path:
317
+ ```bash
318
+ REVIEW_PATH="${PHASE_DIR}/${PADDED_PHASE}-REVIEW.md"
319
+ ```
320
+
321
+ Compute DIFF_BASE for agent context (in case agent needs it):
322
+ ```bash
323
+ PHASE_COMMITS=$(git log --oneline --all --grep="${PADDED_PHASE}" --format="%H" 2>/dev/null)
324
+ if [ -n "$PHASE_COMMITS" ]; then
325
+ DIFF_BASE=$(echo "$PHASE_COMMITS" | tail -1)^
326
+ else
327
+ DIFF_BASE=""
328
+ fi
329
+ ```
330
+
331
+ Build files_to_read block for agent:
332
+ ```bash
333
+ FILES_TO_READ=""
334
+ for file in "${REVIEW_FILES[@]}"; do
335
+ FILES_TO_READ+="- ${file}\n"
336
+ done
337
+ ```
338
+
339
+ Build config block for agent:
340
+ ```bash
341
+ CONFIG_FILES=""
342
+ for file in "${REVIEW_FILES[@]}"; do
343
+ CONFIG_FILES+=" - ${file}\n"
344
+ done
345
+ ```
346
+
347
+ Spawn the gsd-code-reviewer agent:
348
+
349
+ ```
350
+ @gsd-code-reviewer "
351
+ <files_to_read>
352
+ ${FILES_TO_READ}
353
+ </files_to_read>
354
+
355
+ <config>
356
+ depth: ${REVIEW_DEPTH}
357
+ phase_dir: ${PHASE_DIR}
358
+ review_path: ${REVIEW_PATH}
359
+ ${DIFF_BASE:+diff_base: ${DIFF_BASE}}
360
+ files:
361
+ ${CONFIG_FILES}
362
+ </config>
363
+
364
+ Review the listed source files at ${REVIEW_DEPTH} depth. write findings to ${REVIEW_PATH}.
365
+ Do NOT commit the output — the orchestrator handles that.
366
+ "
367
+ ```
368
+
369
+ **Agent failure handling:**
370
+
371
+ If the task() call fails (agent error, timeout, or exception):
372
+ ```
373
+ Error: Code review agent failed: ${error_message}
374
+
375
+ No REVIEW.md created. You can retry with /gsd-code-review ${PHASE_ARG} or check agent logs.
376
+ ```
377
+
378
+ Do NOT proceed to commit_review step. Do NOT create a partial or empty REVIEW.md. Exit workflow.
379
+ </step>
380
+
381
+ <step name="commit_review">
382
+ After agent completes successfully, verify REVIEW.md was created and has valid structure:
383
+
384
+ ```bash
385
+ if [ -f "${REVIEW_PATH}" ]; then
386
+ # Validate REVIEW.md has valid YAML frontmatter with status field
387
+ HAS_STATUS=$(REVIEW_PATH="${REVIEW_PATH}" node -e "
388
+ const fs = require('fs');
389
+ const content = fs.readFileSync(process.env.REVIEW_PATH, 'utf-8');
390
+ const match = content.match(/^---\n([\s\S]*?)\n---/);
391
+ if (match && /status:/.test(match[1])) { console.log('valid'); } else { console.log('invalid'); }
392
+ " 2>/dev/null)
393
+
394
+ if [ "$HAS_STATUS" = "valid" ]; then
395
+ echo "REVIEW.md created at ${REVIEW_PATH}"
396
+
397
+ if [ "$COMMIT_DOCS" = "true" ]; then
398
+ node "$HOME/.config/opencode/get-shit-done/bin/gsd-tools.cjs" commit \
399
+ "docs(${PADDED_PHASE}): add code review report" \
400
+ --files "${REVIEW_PATH}"
401
+ fi
402
+ else
403
+ echo "Warning: REVIEW.md exists but has invalid or missing frontmatter (no status field)."
404
+ echo "Agent may have produced malformed output. Not committing. Review manually: ${REVIEW_PATH}"
405
+ fi
406
+ else
407
+ echo "Warning: Agent completed but REVIEW.md not found at ${REVIEW_PATH}. This may indicate an agent issue."
408
+ echo "No REVIEW.md to commit. Please retry with /gsd-code-review ${PHASE_ARG}"
409
+ fi
410
+ ```
411
+ </step>
412
+
413
+ <step name="present_results">
414
+ read the REVIEW.md YAML frontmatter to extract finding counts.
415
+
416
+ Extract frontmatter between `---` delimiters first to avoid matching values in the review body:
417
+
418
+ ```bash
419
+ # Extract only the YAML frontmatter block (between first two --- lines)
420
+ FRONTMATTER=$(REVIEW_PATH="${REVIEW_PATH}" node -e "
421
+ const fs = require('fs');
422
+ const content = fs.readFileSync(process.env.REVIEW_PATH, 'utf-8');
423
+ const match = content.match(/^---\n([\s\S]*?)\n---/);
424
+ if (match) process.stdout.write(match[1]);
425
+ " 2>/dev/null)
426
+
427
+ # Parse fields from frontmatter only (not full file)
428
+ STATUS=$(echo "$FRONTMATTER" | grep "^status:" | cut -d: -f2 | xargs)
429
+ FILES_REVIEWED=$(echo "$FRONTMATTER" | grep "^files_reviewed:" | cut -d: -f2 | xargs)
430
+ CRITICAL=$(echo "$FRONTMATTER" | grep "critical:" | head -1 | cut -d: -f2 | xargs)
431
+ WARNING=$(echo "$FRONTMATTER" | grep "warning:" | head -1 | cut -d: -f2 | xargs)
432
+ INFO=$(echo "$FRONTMATTER" | grep "info:" | head -1 | cut -d: -f2 | xargs)
433
+ TOTAL=$(echo "$FRONTMATTER" | grep "total:" | head -1 | cut -d: -f2 | xargs)
434
+ ```
435
+
436
+ Display inline summary to user:
437
+
438
+ ```
439
+ ═══════════════════════════════════════════════════════════════
440
+
441
+ Code Review Complete: Phase ${PHASE_NUMBER} (${PHASE_NAME})
442
+
443
+ ───────────────────────────────────────────────────────────────
444
+
445
+ Depth: ${REVIEW_DEPTH}
446
+ Files Reviewed: ${FILES_REVIEWED}
447
+
448
+ Findings:
449
+ Critical: ${CRITICAL}
450
+ Warning: ${WARNING}
451
+ Info: ${INFO}
452
+ ──────────
453
+ Total: ${TOTAL}
454
+
455
+ ───────────────────────────────────────────────────────────────
456
+ ```
457
+
458
+ If status is "clean":
459
+ ```
460
+ ✓ No issues found. All ${FILES_REVIEWED} files pass review at ${REVIEW_DEPTH} depth.
461
+
462
+ Full report: ${REVIEW_PATH}
463
+ ```
464
+
465
+ If total findings > 0:
466
+ ```
467
+ ⚠ Issues found. Review the report for details.
468
+
469
+ Full report: ${REVIEW_PATH}
470
+
471
+ Next steps:
472
+ /gsd-code-review-fix ${PHASE_NUMBER} — Auto-fix issues
473
+ cat ${REVIEW_PATH} — View full report
474
+ ```
475
+
476
+ If critical > 0 or warning > 0, list top 3 issues inline:
477
+ ```bash
478
+ echo "Top issues:"
479
+ grep -A 3 "^### CR-\|^### WR-" "${REVIEW_PATH}" | head -n 12
480
+ ```
481
+
482
+ **Note on tests:** Automated tests for this command and workflow are planned for Phase 4 (Pipeline Integration & Testing, requirement INFR-03). Phase 2 focuses on correct implementation; Phase 4 adds regression coverage across platforms.
483
+
484
+ ═══════════════════════════════════════════════════════════════
485
+ </step>
486
+
487
+ </process>
488
+
489
+ <platform_notes>
490
+ **Windows:** This workflow uses bash features (arrays, process substitution). On Windows, it requires
491
+ Git bash or WSL. Native PowerShell is not supported. The CI matrix (Ubuntu/macOS/Windows)
492
+ runs under Git bash on Windows runners, which provides bash compatibility.
493
+
494
+ **macOS:** macOS ships with bash 3.2 (GPL licensing). This workflow does NOT use `mapfile` (bash 4+
495
+ only) — all array construction uses portable `while IFS= read -r` loops compatible with bash 3.2.
496
+ The `--files` path validation uses `realpath -m` which requires GNU coreutils (install via
497
+ `brew install coreutils`). Without coreutils, the path guard falls back to fail-closed behavior
498
+ (rejects paths it cannot verify), so security is maintained but valid relative paths may be rejected.
499
+ If `--files` validation fails unexpectedly on macOS, install coreutils or use absolute paths.
500
+ </platform_notes>
501
+
502
+ <success_criteria>
503
+ - [ ] Phase validated before config gate check
504
+ - [ ] Config gate checked (workflow.code_review)
505
+ - [ ] Depth resolved with validation (quick|standard|deep)
506
+ - [ ] File scope computed with 3 tiers: --files > SUMMARY.md > git diff
507
+ - [ ] Malformed/missing SUMMARY.md handled gracefully with fallback
508
+ - [ ] Deleted files filtered from scope
509
+ - [ ] Files deduplicated and sorted
510
+ - [ ] Empty scope results in skip (no agent spawn)
511
+ - [ ] Agent spawned with explicit file list, depth, review_path, diff_base
512
+ - [ ] Agent failure handled without partial commits
513
+ - [ ] REVIEW.md committed if created
514
+ - [ ] Results presented inline with next step suggestion
515
+ </success_criteria>
@@ -20,8 +20,8 @@ When a milestone completes:
20
20
 
21
21
  1. Extract full milestone details to `.planning/milestones/v[X.Y]-ROADMAP.md`
22
22
  2. Archive requirements to `.planning/milestones/v[X.Y]-REQUIREMENTS.md`
23
- 3. Update ROADMAP.md — replace milestone details with one-line summary
24
- 4. Delete REQUIREMENTS.md (fresh one for next milestone)
23
+ 3. Update ROADMAP.md — overwrite in place with milestone grouping (preserve Backlog section)
24
+ 4. Safety commit archive files + updated ROADMAP.md, then `git rm REQUIREMENTS.md` (fresh for next milestone)
25
25
  5. Perform full PROJECT.md evolution review
26
26
  6. Offer to create next milestone inline
27
27
  7. Archive UI artifacts (`*-UI-SPEC.md`, `*-UI-REVIEW.md`) alongside other phase documents
@@ -387,6 +387,8 @@ Verify: `✅ Milestone archived to .planning/milestones/`
387
387
 
388
388
  **Phase archival (optional):** After archival completes, ask the user:
389
389
 
390
+
391
+ **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 `question` call with a plain-text numbered list and ask the user to type their choice number. This is required for non-OpenCode runtimes (OpenAI Codex, Gemini CLI, etc.) where `question` is not available.
390
392
  question(header="Archive Phases", question="Archive phase directories to milestones/?", options: "Yes — move to milestones/v[X.Y]-phases/" | "Skip — keep phases in place")
391
393
 
392
394
  If "Yes": move phase directories to the milestone archive:
@@ -400,18 +402,29 @@ Verify: `✅ Phase directories archived to .planning/milestones/v[X.Y]-phases/`
400
402
  If "Skip": Phase directories remain in `.planning/phases/` as raw execution history. Use `/gsd-cleanup` later to archive retroactively.
401
403
 
402
404
  After archival, the AI still handles:
403
- - Reorganizing ROADMAP.md with milestone grouping (requires judgment)
405
+ - Reorganizing ROADMAP.md with milestone grouping (requires judgment) — overwrite in place after extracting Backlog section
404
406
  - Full PROJECT.md evolution review (requires understanding)
405
- - Deleting original ROADMAP.md and REQUIREMENTS.md
407
+ - Safety commit of archive files + updated ROADMAP.md, then `git rm .planning/REQUIREMENTS.md`
406
408
  - These are NOT fully delegated because they require AI interpretation of content
407
409
 
408
410
  </step>
409
411
 
410
412
  <step name="reorganize_roadmap_and_delete_originals">
411
413
 
412
- After `milestone complete` has archived, reorganize ROADMAP.md with milestone groupings, then delete originals:
414
+ After `milestone complete` has archived, reorganize ROADMAP.md with milestone groupings, then commit archives as a safety checkpoint before removing originals.
415
+
416
+ **Backlog preservation — do this FIRST before rewriting ROADMAP.md:**
417
+
418
+ Extract the Backlog section from the current ROADMAP.md before making any changes:
419
+
420
+ ```bash
421
+ # Extract lines under ## Backlog through end of file (or next ## section)
422
+ BACKLOG_SECTION=$(awk '/^## Backlog/{found=1} found{print}' .planning/ROADMAP.md)
423
+ ```
413
424
 
414
- **Reorganize ROADMAP.md** group completed milestone phases:
425
+ If `$BACKLOG_SECTION` is empty, there is no Backlog section — skip silently.
426
+
427
+ **Reorganize ROADMAP.md** — overwrite in place (do NOT delete first) with milestone groupings:
415
428
 
416
429
  ```markdown
417
430
  # Roadmap: [Project Name]
@@ -432,11 +445,22 @@ After `milestone complete` has archived, reorganize ROADMAP.md with milestone gr
432
445
  </details>
433
446
  ```
434
447
 
435
- **Then delete originals:**
448
+ **Re-append Backlog section after the rewrite** (only if `$BACKLOG_SECTION` was non-empty):
449
+
450
+ Append the extracted Backlog content verbatim to the end of the newly written ROADMAP.md. This ensures 999.x backlog items are never silently dropped during milestone reorganization.
451
+
452
+ **Safety commit — commit archive files BEFORE deleting any originals:**
436
453
 
437
454
  ```bash
438
- rm .planning/ROADMAP.md
439
- rm .planning/REQUIREMENTS.md
455
+ node "$HOME/.config/opencode/get-shit-done/bin/gsd-tools.cjs" commit "chore: archive v[X.Y] milestone files" --files .planning/milestones/v[X.Y]-ROADMAP.md .planning/milestones/v[X.Y]-REQUIREMENTS.md .planning/milestones/v[X.Y]-MILESTONE-AUDIT.md .planning/MILESTONES.md .planning/PROJECT.md .planning/STATE.md .planning/ROADMAP.md
456
+ ```
457
+
458
+ This creates a durable checkpoint in git history. If anything fails after this point, the working tree can be reconstructed from git.
459
+
460
+ **Remove REQUIREMENTS.md via git rm** (preserves history, stages deletion atomically):
461
+
462
+ ```bash
463
+ git rm .planning/REQUIREMENTS.md
440
464
  ```
441
465
 
442
466
  </step>
@@ -686,14 +710,13 @@ git push origin v[X.Y]
686
710
 
687
711
  <step name="git_commit_milestone">
688
712
 
689
- Commit milestone completion.
713
+ Commit the REQUIREMENTS.md deletion (archive files and ROADMAP.md were already committed in the safety commit in `reorganize_roadmap_and_delete_originals`).
690
714
 
691
715
  ```bash
692
- node "$HOME/.config/opencode/get-shit-done/bin/gsd-tools.cjs" commit "chore: complete v[X.Y] milestone" --files .planning/milestones/v[X.Y]-ROADMAP.md .planning/milestones/v[X.Y]-REQUIREMENTS.md .planning/milestones/v[X.Y]-MILESTONE-AUDIT.md .planning/MILESTONES.md .planning/PROJECT.md .planning/STATE.md
693
- ```
716
+ git commit -m "chore: remove REQUIREMENTS.md for v[X.Y] milestone"
694
717
  ```
695
718
 
696
- Confirm: "Committed: chore: complete v[X.Y] milestone"
719
+ Confirm: "Committed: chore: remove REQUIREMENTS.md for v[X.Y] milestone"
697
720
 
698
721
  </step>
699
722
 
@@ -759,10 +782,12 @@ Milestone completion is successful when:
759
782
  - [ ] PROJECT.md full evolution review completed
760
783
  - [ ] All shipped requirements moved to Validated in PROJECT.md
761
784
  - [ ] Key Decisions updated with outcomes
762
- - [ ] ROADMAP.md reorganized with milestone grouping
785
+ - [ ] ROADMAP.md Backlog section extracted before rewrite, re-appended after (skipped if absent)
786
+ - [ ] ROADMAP.md reorganized with milestone grouping (overwritten in place, not deleted)
763
787
  - [ ] Roadmap archive created (milestones/v[X.Y]-ROADMAP.md)
764
788
  - [ ] Requirements archive created (milestones/v[X.Y]-REQUIREMENTS.md)
765
- - [ ] REQUIREMENTS.md deleted (fresh for next milestone)
789
+ - [ ] Safety commit made (archive files + updated ROADMAP.md) BEFORE deleting REQUIREMENTS.md
790
+ - [ ] REQUIREMENTS.md removed via `git rm` (fresh for next milestone, history preserved)
766
791
  - [ ] STATE.md updated with fresh project reference
767
792
  - [ ] Git tag created (v[X.Y])
768
793
  - [ ] Milestone commit made (includes archive files and deletion)
@@ -96,7 +96,7 @@ EXPECTED_BASE=$(git rev-parse HEAD)
96
96
  For each gap, fill the debug-subagent-prompt template and spawn:
97
97
 
98
98
  ```
99
- @gsd-debugger 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 --soft {EXPECTED_BASE} to correct the branch base (fixes Windows EnterWorktree creating branches from main).\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}"
99
+ @gsd-debugger 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}"
100
100
  ```
101
101
 
102
102
  **All agents spawn in single message** (parallel execution).
@@ -93,7 +93,7 @@ For: Choosing between options, new external integration.
93
93
 
94
94
  ```
95
95
  For each library/framework:
96
- - mcp__context7__resolve-library-id
96
+ - mcp__context7__resolve-library-id
97
97
  - mcp__context7__get-library-docs (mode: "code" for API, "info" for concepts)
98
98
  ```
99
99
 
@@ -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 `question` call with a plain-text numbered list and ask the user to type their choice number. This is required for non-OpenCode runtimes (OpenAI Codex, Gemini CLI, etc.) where `question` is not available.
217
219
  Use question:
218
220
 
219
221
  - header: "Low Conf."
@@ -310,7 +310,7 @@ Parse the subagent's response. Extract:
310
310
  If research topics were flagged, spawn a general research agent:
311
311
 
312
312
  ```
313
- @general """
313
+ @gsd-assumptions-analyzer """
314
314
  Research the following topics for Phase {PHASE}: {phase_name}.
315
315
 
316
316
  Topics needing research: