@therocketcode/gsd-core 1.4.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 (568) hide show
  1. package/.claude-plugin/plugin.json +23 -0
  2. package/GEMINI.md +53 -0
  3. package/LICENSE +21 -0
  4. package/README.ja-JP.md +125 -0
  5. package/README.ko-KR.md +125 -0
  6. package/README.md +144 -0
  7. package/README.pt-BR.md +125 -0
  8. package/README.zh-CN.md +125 -0
  9. package/agents/gsd-advisor-researcher.md +108 -0
  10. package/agents/gsd-ai-researcher.md +114 -0
  11. package/agents/gsd-assumptions-analyzer.md +105 -0
  12. package/agents/gsd-code-fixer.md +668 -0
  13. package/agents/gsd-code-reviewer.md +387 -0
  14. package/agents/gsd-codebase-mapper.md +853 -0
  15. package/agents/gsd-debug-session-manager.md +314 -0
  16. package/agents/gsd-debugger.md +1452 -0
  17. package/agents/gsd-doc-classifier.md +168 -0
  18. package/agents/gsd-doc-synthesizer.md +204 -0
  19. package/agents/gsd-doc-verifier.md +217 -0
  20. package/agents/gsd-doc-writer.md +616 -0
  21. package/agents/gsd-domain-researcher.md +147 -0
  22. package/agents/gsd-eval-auditor.md +191 -0
  23. package/agents/gsd-eval-planner.md +154 -0
  24. package/agents/gsd-executor.md +785 -0
  25. package/agents/gsd-framework-selector.md +160 -0
  26. package/agents/gsd-integration-checker.md +470 -0
  27. package/agents/gsd-intel-updater.md +342 -0
  28. package/agents/gsd-nyquist-auditor.md +203 -0
  29. package/agents/gsd-pattern-mapper.md +335 -0
  30. package/agents/gsd-phase-researcher.md +867 -0
  31. package/agents/gsd-plan-checker.md +978 -0
  32. package/agents/gsd-planner.md +1204 -0
  33. package/agents/gsd-project-researcher.md +611 -0
  34. package/agents/gsd-research-synthesizer.md +259 -0
  35. package/agents/gsd-roadmapper.md +688 -0
  36. package/agents/gsd-security-auditor.md +155 -0
  37. package/agents/gsd-ui-auditor.md +495 -0
  38. package/agents/gsd-ui-checker.md +309 -0
  39. package/agents/gsd-ui-researcher.md +374 -0
  40. package/agents/gsd-user-profiler.md +171 -0
  41. package/agents/gsd-verifier.md +923 -0
  42. package/assets/gsd-logo-2000-transparent.png +0 -0
  43. package/assets/gsd-logo-2000-transparent.svg +17 -0
  44. package/assets/gsd-logo-2000.png +0 -0
  45. package/assets/gsd-logo-2000.svg +21 -0
  46. package/assets/terminal.svg +68 -0
  47. package/bin/install.js +12726 -0
  48. package/bin/lib/ui-safety-gate.cjs +107 -0
  49. package/commands/gsd/add-tests.md +42 -0
  50. package/commands/gsd/ai-integration-phase.md +37 -0
  51. package/commands/gsd/audit-fix.md +34 -0
  52. package/commands/gsd/audit-milestone.md +37 -0
  53. package/commands/gsd/audit-uat.md +24 -0
  54. package/commands/gsd/autonomous.md +48 -0
  55. package/commands/gsd/capture.md +62 -0
  56. package/commands/gsd/cleanup.md +24 -0
  57. package/commands/gsd/code-review.md +59 -0
  58. package/commands/gsd/complete-milestone.md +143 -0
  59. package/commands/gsd/config.md +56 -0
  60. package/commands/gsd/debug.md +52 -0
  61. package/commands/gsd/discover-product.md +65 -0
  62. package/commands/gsd/discuss-phase.md +77 -0
  63. package/commands/gsd/docs-update.md +49 -0
  64. package/commands/gsd/eval-review.md +33 -0
  65. package/commands/gsd/execute-phase.md +66 -0
  66. package/commands/gsd/explore.md +27 -0
  67. package/commands/gsd/extract-learnings.md +23 -0
  68. package/commands/gsd/fast.md +31 -0
  69. package/commands/gsd/forensics.md +57 -0
  70. package/commands/gsd/graphify.md +204 -0
  71. package/commands/gsd/health.md +31 -0
  72. package/commands/gsd/help.md +28 -0
  73. package/commands/gsd/import.md +45 -0
  74. package/commands/gsd/inbox.md +39 -0
  75. package/commands/gsd/ingest-docs.md +42 -0
  76. package/commands/gsd/manager.md +45 -0
  77. package/commands/gsd/map-codebase.md +83 -0
  78. package/commands/gsd/milestone-summary.md +51 -0
  79. package/commands/gsd/model-domain.md +65 -0
  80. package/commands/gsd/mvp-phase.md +45 -0
  81. package/commands/gsd/new-milestone.md +45 -0
  82. package/commands/gsd/new-project.md +47 -0
  83. package/commands/gsd/ns-context.md +23 -0
  84. package/commands/gsd/ns-ideate.md +24 -0
  85. package/commands/gsd/ns-manage.md +29 -0
  86. package/commands/gsd/ns-project.md +22 -0
  87. package/commands/gsd/ns-review.md +26 -0
  88. package/commands/gsd/ns-workflow.md +28 -0
  89. package/commands/gsd/pause-work.md +43 -0
  90. package/commands/gsd/phase.md +56 -0
  91. package/commands/gsd/plan-phase.md +64 -0
  92. package/commands/gsd/plan-review-convergence.md +59 -0
  93. package/commands/gsd/pr-branch.md +26 -0
  94. package/commands/gsd/profile-user.md +46 -0
  95. package/commands/gsd/progress.md +48 -0
  96. package/commands/gsd/quick.md +174 -0
  97. package/commands/gsd/recommend-architecture.md +64 -0
  98. package/commands/gsd/resume-work.md +30 -0
  99. package/commands/gsd/review-backlog.md +63 -0
  100. package/commands/gsd/review.md +42 -0
  101. package/commands/gsd/secure-phase.md +36 -0
  102. package/commands/gsd/settings.md +29 -0
  103. package/commands/gsd/ship.md +24 -0
  104. package/commands/gsd/sketch.md +60 -0
  105. package/commands/gsd/spec-phase.md +63 -0
  106. package/commands/gsd/spike.md +57 -0
  107. package/commands/gsd/stats.md +20 -0
  108. package/commands/gsd/surface.md +155 -0
  109. package/commands/gsd/testing-strategy.md +65 -0
  110. package/commands/gsd/thread.md +24 -0
  111. package/commands/gsd/ui-phase.md +35 -0
  112. package/commands/gsd/ui-review.md +33 -0
  113. package/commands/gsd/ultraplan-phase.md +34 -0
  114. package/commands/gsd/undo.md +35 -0
  115. package/commands/gsd/update.md +49 -0
  116. package/commands/gsd/validate-phase.md +36 -0
  117. package/commands/gsd/verify-work.md +39 -0
  118. package/commands/gsd/workspace.md +52 -0
  119. package/commands/gsd/workstreams.md +70 -0
  120. package/gemini-extension.json +6 -0
  121. package/gsd-core/bin/check-latest-version.cjs +161 -0
  122. package/gsd-core/bin/gsd-tools.cjs +1928 -0
  123. package/gsd-core/bin/lib/active-workstream-store.cjs +291 -0
  124. package/gsd-core/bin/lib/adr-parser.cjs +399 -0
  125. package/gsd-core/bin/lib/agent-command-router.cjs +68 -0
  126. package/gsd-core/bin/lib/artifacts.cjs +51 -0
  127. package/gsd-core/bin/lib/audit.cjs +743 -0
  128. package/gsd-core/bin/lib/check-command-router.cjs +343 -0
  129. package/gsd-core/bin/lib/cjs-command-router-adapter.cjs +81 -0
  130. package/gsd-core/bin/lib/cli-exit.cjs +42 -0
  131. package/gsd-core/bin/lib/clock.cjs +95 -0
  132. package/gsd-core/bin/lib/clusters.cjs +132 -0
  133. package/gsd-core/bin/lib/code-review-flags.cjs +59 -0
  134. package/gsd-core/bin/lib/command-aliases.cjs +809 -0
  135. package/gsd-core/bin/lib/command-arg-projection.cjs +55 -0
  136. package/gsd-core/bin/lib/command-routing-hub.cjs +300 -0
  137. package/gsd-core/bin/lib/commands.cjs +1203 -0
  138. package/gsd-core/bin/lib/config-schema.cjs +29 -0
  139. package/gsd-core/bin/lib/config-types.cjs +19 -0
  140. package/gsd-core/bin/lib/config.cjs +738 -0
  141. package/gsd-core/bin/lib/configuration.cjs +239 -0
  142. package/gsd-core/bin/lib/context-utilization.cjs +48 -0
  143. package/gsd-core/bin/lib/core.cjs +2051 -0
  144. package/gsd-core/bin/lib/decisions.cjs +118 -0
  145. package/gsd-core/bin/lib/docs.cjs +252 -0
  146. package/gsd-core/bin/lib/drift.cjs +364 -0
  147. package/gsd-core/bin/lib/fallow-runner.cjs +115 -0
  148. package/gsd-core/bin/lib/frontmatter.cjs +442 -0
  149. package/gsd-core/bin/lib/gap-checker.cjs +257 -0
  150. package/gsd-core/bin/lib/graphify.cjs +496 -0
  151. package/gsd-core/bin/lib/gsd2-import.cjs +456 -0
  152. package/gsd-core/bin/lib/init-command-router.cjs +62 -0
  153. package/gsd-core/bin/lib/init.cjs +1815 -0
  154. package/gsd-core/bin/lib/install-profiles.cjs +584 -0
  155. package/gsd-core/bin/lib/installer-migration-authoring.cjs +122 -0
  156. package/gsd-core/bin/lib/installer-migration-report.cjs +350 -0
  157. package/gsd-core/bin/lib/installer-migrations/000-first-time-baseline.cjs +218 -0
  158. package/gsd-core/bin/lib/installer-migrations/001-legacy-orphan-files.cjs +48 -0
  159. package/gsd-core/bin/lib/installer-migrations/002-codex-legacy-hooks-json.cjs +94 -0
  160. package/gsd-core/bin/lib/installer-migrations/003-rename-get-shit-done-to-gsd-core.cjs +108 -0
  161. package/gsd-core/bin/lib/installer-migrations.cjs +823 -0
  162. package/gsd-core/bin/lib/intel.cjs +590 -0
  163. package/gsd-core/bin/lib/learnings.cjs +270 -0
  164. package/gsd-core/bin/lib/legacy-cleanup.cjs +253 -0
  165. package/gsd-core/bin/lib/milestone.cjs +373 -0
  166. package/gsd-core/bin/lib/model-catalog.cjs +154 -0
  167. package/gsd-core/bin/lib/model-profiles.cjs +24 -0
  168. package/gsd-core/bin/lib/observability/event.cjs +51 -0
  169. package/gsd-core/bin/lib/observability/logger.cjs +146 -0
  170. package/gsd-core/bin/lib/observability/redaction.cjs +48 -0
  171. package/gsd-core/bin/lib/package-identity.cjs +35 -0
  172. package/gsd-core/bin/lib/package-legitimacy.cjs +368 -0
  173. package/gsd-core/bin/lib/phase-command-router.cjs +189 -0
  174. package/gsd-core/bin/lib/phase-lifecycle.cjs +74 -0
  175. package/gsd-core/bin/lib/phase.cjs +1307 -0
  176. package/gsd-core/bin/lib/phases-command-router.cjs +43 -0
  177. package/gsd-core/bin/lib/plan-scan.cjs +91 -0
  178. package/gsd-core/bin/lib/planning-workspace.cjs +245 -0
  179. package/gsd-core/bin/lib/profile-output.cjs +1120 -0
  180. package/gsd-core/bin/lib/profile-pipeline.cjs +517 -0
  181. package/gsd-core/bin/lib/project-root.cjs +119 -0
  182. package/gsd-core/bin/lib/prompt-budget.cjs +305 -0
  183. package/gsd-core/bin/lib/research-provider.cjs +137 -0
  184. package/gsd-core/bin/lib/research-store.cjs +167 -0
  185. package/gsd-core/bin/lib/review-reviewer-selection.cjs +121 -0
  186. package/gsd-core/bin/lib/roadmap-command-router.cjs +166 -0
  187. package/gsd-core/bin/lib/roadmap-upgrade.cjs +476 -0
  188. package/gsd-core/bin/lib/roadmap.cjs +600 -0
  189. package/gsd-core/bin/lib/runtime-artifact-layout.cjs +312 -0
  190. package/gsd-core/bin/lib/runtime-config-adapter-registry.cjs +56 -0
  191. package/gsd-core/bin/lib/runtime-homes.cjs +190 -0
  192. package/gsd-core/bin/lib/runtime-name-policy.cjs +96 -0
  193. package/gsd-core/bin/lib/runtime-slash.cjs +119 -0
  194. package/gsd-core/bin/lib/schema-detect.cjs +159 -0
  195. package/gsd-core/bin/lib/secrets.cjs +34 -0
  196. package/gsd-core/bin/lib/security.cjs +480 -0
  197. package/gsd-core/bin/lib/semver-compare.cjs +42 -0
  198. package/gsd-core/bin/lib/shell-command-projection.cjs +533 -0
  199. package/gsd-core/bin/lib/state-command-router.cjs +160 -0
  200. package/gsd-core/bin/lib/state-document.cjs +259 -0
  201. package/gsd-core/bin/lib/state.cjs +2010 -0
  202. package/gsd-core/bin/lib/surface.cjs +449 -0
  203. package/gsd-core/bin/lib/task-command-router.cjs +85 -0
  204. package/gsd-core/bin/lib/template.cjs +237 -0
  205. package/gsd-core/bin/lib/uat.cjs +297 -0
  206. package/gsd-core/bin/lib/ui-safety-gate.cjs +98 -0
  207. package/gsd-core/bin/lib/update-context.cjs +218 -0
  208. package/gsd-core/bin/lib/validate-command-router.cjs +91 -0
  209. package/gsd-core/bin/lib/validate.cjs +112 -0
  210. package/gsd-core/bin/lib/verification-command-router.cjs +31 -0
  211. package/gsd-core/bin/lib/verification.cjs +193 -0
  212. package/gsd-core/bin/lib/verify-command-router.cjs +44 -0
  213. package/gsd-core/bin/lib/verify.cjs +1451 -0
  214. package/gsd-core/bin/lib/workstream-inventory-builder.cjs +81 -0
  215. package/gsd-core/bin/lib/workstream-inventory.cjs +147 -0
  216. package/gsd-core/bin/lib/workstream-name-policy.cjs +91 -0
  217. package/gsd-core/bin/lib/workstream.cjs +380 -0
  218. package/gsd-core/bin/lib/worktree-base-ref.cjs +325 -0
  219. package/gsd-core/bin/lib/worktree-safety.cjs +943 -0
  220. package/gsd-core/bin/shared/config-defaults.manifest.json +98 -0
  221. package/gsd-core/bin/shared/config-schema.manifest.json +192 -0
  222. package/gsd-core/bin/shared/model-catalog.json +149 -0
  223. package/gsd-core/bin/shared/runtime-aliases.manifest.json +75 -0
  224. package/gsd-core/bin/verify-reapply-patches.cjs +349 -0
  225. package/gsd-core/contexts/dev.md +21 -0
  226. package/gsd-core/contexts/research.md +22 -0
  227. package/gsd-core/contexts/review.md +23 -0
  228. package/gsd-core/references/agent-contracts.md +79 -0
  229. package/gsd-core/references/ai-evals.md +156 -0
  230. package/gsd-core/references/ai-frameworks.md +186 -0
  231. package/gsd-core/references/architecture-decision.md +74 -0
  232. package/gsd-core/references/artifact-types.md +131 -0
  233. package/gsd-core/references/auth-in-tests.md +91 -0
  234. package/gsd-core/references/autonomous-smart-discuss.md +277 -0
  235. package/gsd-core/references/checkpoints.md +814 -0
  236. package/gsd-core/references/common-bug-patterns.md +114 -0
  237. package/gsd-core/references/context-budget.md +85 -0
  238. package/gsd-core/references/continuation-format.md +253 -0
  239. package/gsd-core/references/db-test-isolation.md +54 -0
  240. package/gsd-core/references/debugger-philosophy.md +76 -0
  241. package/gsd-core/references/decimal-phase-calculation.md +64 -0
  242. package/gsd-core/references/doc-conflict-engine.md +91 -0
  243. package/gsd-core/references/domain-modeling.md +80 -0
  244. package/gsd-core/references/domain-probes.md +125 -0
  245. package/gsd-core/references/e2e-tiering.md +35 -0
  246. package/gsd-core/references/execute-mvp-tdd.md +81 -0
  247. package/gsd-core/references/executor-examples.md +110 -0
  248. package/gsd-core/references/few-shot-examples/plan-checker.md +73 -0
  249. package/gsd-core/references/few-shot-examples/verifier.md +109 -0
  250. package/gsd-core/references/flaky-test-checklist.md +22 -0
  251. package/gsd-core/references/gate-prompts.md +100 -0
  252. package/gsd-core/references/gates.md +70 -0
  253. package/gsd-core/references/git-integration.md +298 -0
  254. package/gsd-core/references/git-planning-commit.md +40 -0
  255. package/gsd-core/references/ios-scaffold.md +123 -0
  256. package/gsd-core/references/mandatory-initial-read.md +2 -0
  257. package/gsd-core/references/model-profile-resolution.md +38 -0
  258. package/gsd-core/references/model-profiles.md +245 -0
  259. package/gsd-core/references/mvp-concepts.md +49 -0
  260. package/gsd-core/references/phase-argument-parsing.md +61 -0
  261. package/gsd-core/references/planner-antipatterns.md +89 -0
  262. package/gsd-core/references/planner-chunked.md +49 -0
  263. package/gsd-core/references/planner-gap-closure.md +62 -0
  264. package/gsd-core/references/planner-graphify-auto-update.md +67 -0
  265. package/gsd-core/references/planner-human-verify-mode.md +57 -0
  266. package/gsd-core/references/planner-interface-context.md +62 -0
  267. package/gsd-core/references/planner-load-graph-context.md +36 -0
  268. package/gsd-core/references/planner-mvp-mode.md +53 -0
  269. package/gsd-core/references/planner-reviews.md +39 -0
  270. package/gsd-core/references/planner-revision.md +87 -0
  271. package/gsd-core/references/planner-source-audit.md +73 -0
  272. package/gsd-core/references/planning-config.md +473 -0
  273. package/gsd-core/references/product-discovery.md +49 -0
  274. package/gsd-core/references/project-skills-discovery.md +19 -0
  275. package/gsd-core/references/questioning.md +162 -0
  276. package/gsd-core/references/realistic-test-data.md +44 -0
  277. package/gsd-core/references/research-documentation-lookup.md +29 -0
  278. package/gsd-core/references/research-philosophy.md +29 -0
  279. package/gsd-core/references/research-verification-protocol.md +27 -0
  280. package/gsd-core/references/revision-loop.md +97 -0
  281. package/gsd-core/references/scout-codebase.md +51 -0
  282. package/gsd-core/references/skeleton-template.md +48 -0
  283. package/gsd-core/references/sketch-interactivity.md +41 -0
  284. package/gsd-core/references/sketch-theme-system.md +94 -0
  285. package/gsd-core/references/sketch-tooling.md +45 -0
  286. package/gsd-core/references/sketch-variant-patterns.md +81 -0
  287. package/gsd-core/references/spidr-splitting.md +69 -0
  288. package/gsd-core/references/tdd.md +330 -0
  289. package/gsd-core/references/test-containers.md +55 -0
  290. package/gsd-core/references/test-strategy.md +75 -0
  291. package/gsd-core/references/thinking-models-debug.md +44 -0
  292. package/gsd-core/references/thinking-models-execution.md +50 -0
  293. package/gsd-core/references/thinking-models-planning.md +62 -0
  294. package/gsd-core/references/thinking-models-research.md +50 -0
  295. package/gsd-core/references/thinking-models-verification.md +55 -0
  296. package/gsd-core/references/thinking-partner.md +96 -0
  297. package/gsd-core/references/ui-brand.md +162 -0
  298. package/gsd-core/references/universal-anti-patterns.md +63 -0
  299. package/gsd-core/references/user-profiling.md +681 -0
  300. package/gsd-core/references/user-story-template.md +58 -0
  301. package/gsd-core/references/verification-overrides.md +227 -0
  302. package/gsd-core/references/verification-patterns.md +612 -0
  303. package/gsd-core/references/verify-mvp-mode.md +85 -0
  304. package/gsd-core/references/workstream-flag.md +111 -0
  305. package/gsd-core/references/worktree-branch-check.md +38 -0
  306. package/gsd-core/references/worktree-path-safety.md +67 -0
  307. package/gsd-core/templates/AI-SPEC.md +246 -0
  308. package/gsd-core/templates/DEBUG.md +169 -0
  309. package/gsd-core/templates/README.md +77 -0
  310. package/gsd-core/templates/SECURITY.md +61 -0
  311. package/gsd-core/templates/UAT.md +265 -0
  312. package/gsd-core/templates/UI-SPEC.md +100 -0
  313. package/gsd-core/templates/VALIDATION.md +76 -0
  314. package/gsd-core/templates/adr.md +58 -0
  315. package/gsd-core/templates/claude-md.md +145 -0
  316. package/gsd-core/templates/codebase/architecture.md +255 -0
  317. package/gsd-core/templates/codebase/concerns.md +310 -0
  318. package/gsd-core/templates/codebase/conventions.md +307 -0
  319. package/gsd-core/templates/codebase/integrations.md +280 -0
  320. package/gsd-core/templates/codebase/stack.md +186 -0
  321. package/gsd-core/templates/codebase/structure.md +285 -0
  322. package/gsd-core/templates/codebase/testing.md +480 -0
  323. package/gsd-core/templates/config.json +62 -0
  324. package/gsd-core/templates/context.md +352 -0
  325. package/gsd-core/templates/continue-here.md +78 -0
  326. package/gsd-core/templates/copilot-instructions.md +7 -0
  327. package/gsd-core/templates/debug-subagent-prompt.md +91 -0
  328. package/gsd-core/templates/dev-preferences.md +21 -0
  329. package/gsd-core/templates/discovery.md +146 -0
  330. package/gsd-core/templates/discussion-log.md +63 -0
  331. package/gsd-core/templates/domain-model.md +54 -0
  332. package/gsd-core/templates/milestone-archive.md +123 -0
  333. package/gsd-core/templates/milestone.md +115 -0
  334. package/gsd-core/templates/phase-prompt.md +610 -0
  335. package/gsd-core/templates/planner-subagent-prompt.md +117 -0
  336. package/gsd-core/templates/product-brief.md +55 -0
  337. package/gsd-core/templates/project.md +186 -0
  338. package/gsd-core/templates/requirements.md +231 -0
  339. package/gsd-core/templates/research-project/ARCHITECTURE.md +204 -0
  340. package/gsd-core/templates/research-project/FEATURES.md +147 -0
  341. package/gsd-core/templates/research-project/PITFALLS.md +200 -0
  342. package/gsd-core/templates/research-project/STACK.md +120 -0
  343. package/gsd-core/templates/research-project/SUMMARY.md +170 -0
  344. package/gsd-core/templates/research.md +592 -0
  345. package/gsd-core/templates/retrospective.md +54 -0
  346. package/gsd-core/templates/roadmap.md +202 -0
  347. package/gsd-core/templates/spec.md +307 -0
  348. package/gsd-core/templates/state.md +195 -0
  349. package/gsd-core/templates/summary-complex.md +59 -0
  350. package/gsd-core/templates/summary-minimal.md +41 -0
  351. package/gsd-core/templates/summary-standard.md +48 -0
  352. package/gsd-core/templates/summary.md +248 -0
  353. package/gsd-core/templates/test-strategy.md +50 -0
  354. package/gsd-core/templates/user-profile.md +146 -0
  355. package/gsd-core/templates/user-setup.md +311 -0
  356. package/gsd-core/templates/verification-report.md +322 -0
  357. package/gsd-core/workflows/_runtime-launcher.snippet.sh +1 -0
  358. package/gsd-core/workflows/add-backlog.md +91 -0
  359. package/gsd-core/workflows/add-phase.md +113 -0
  360. package/gsd-core/workflows/add-tests.md +355 -0
  361. package/gsd-core/workflows/add-todo.md +161 -0
  362. package/gsd-core/workflows/ai-integration-phase.md +295 -0
  363. package/gsd-core/workflows/analyze-dependencies.md +96 -0
  364. package/gsd-core/workflows/audit-fix.md +178 -0
  365. package/gsd-core/workflows/audit-milestone.md +360 -0
  366. package/gsd-core/workflows/audit-uat.md +110 -0
  367. package/gsd-core/workflows/autonomous.md +797 -0
  368. package/gsd-core/workflows/check-todos.md +180 -0
  369. package/gsd-core/workflows/cleanup.md +195 -0
  370. package/gsd-core/workflows/code-review-fix.md +502 -0
  371. package/gsd-core/workflows/code-review.md +658 -0
  372. package/gsd-core/workflows/complete-milestone.md +855 -0
  373. package/gsd-core/workflows/debug.md +237 -0
  374. package/gsd-core/workflows/diagnose-issues.md +245 -0
  375. package/gsd-core/workflows/discover-product.md +112 -0
  376. package/gsd-core/workflows/discovery-phase.md +291 -0
  377. package/gsd-core/workflows/discuss-phase/modes/advisor.md +176 -0
  378. package/gsd-core/workflows/discuss-phase/modes/all.md +28 -0
  379. package/gsd-core/workflows/discuss-phase/modes/analyze.md +44 -0
  380. package/gsd-core/workflows/discuss-phase/modes/auto.md +57 -0
  381. package/gsd-core/workflows/discuss-phase/modes/batch.md +52 -0
  382. package/gsd-core/workflows/discuss-phase/modes/chain.md +98 -0
  383. package/gsd-core/workflows/discuss-phase/modes/default.md +141 -0
  384. package/gsd-core/workflows/discuss-phase/modes/power.md +44 -0
  385. package/gsd-core/workflows/discuss-phase/modes/text.md +55 -0
  386. package/gsd-core/workflows/discuss-phase/templates/checkpoint.json +18 -0
  387. package/gsd-core/workflows/discuss-phase/templates/context.md +136 -0
  388. package/gsd-core/workflows/discuss-phase/templates/discussion-log.md +50 -0
  389. package/gsd-core/workflows/discuss-phase-assumptions.md +675 -0
  390. package/gsd-core/workflows/discuss-phase-power.md +291 -0
  391. package/gsd-core/workflows/discuss-phase.md +499 -0
  392. package/gsd-core/workflows/do.md +111 -0
  393. package/gsd-core/workflows/docs-update.md +1176 -0
  394. package/gsd-core/workflows/edit-phase.md +295 -0
  395. package/gsd-core/workflows/eval-review.md +156 -0
  396. package/gsd-core/workflows/execute-phase/steps/codebase-drift-gate.md +95 -0
  397. package/gsd-core/workflows/execute-phase/steps/per-plan-worktree-gate.md +94 -0
  398. package/gsd-core/workflows/execute-phase/steps/post-merge-gate.md +117 -0
  399. package/gsd-core/workflows/execute-phase.md +1752 -0
  400. package/gsd-core/workflows/execute-plan.md +526 -0
  401. package/gsd-core/workflows/explore.md +146 -0
  402. package/gsd-core/workflows/extract-learnings.md +243 -0
  403. package/gsd-core/workflows/fast.md +124 -0
  404. package/gsd-core/workflows/forensics.md +279 -0
  405. package/gsd-core/workflows/graduation.md +196 -0
  406. package/gsd-core/workflows/health.md +224 -0
  407. package/gsd-core/workflows/help/modes/brief.md +22 -0
  408. package/gsd-core/workflows/help/modes/default.md +50 -0
  409. package/gsd-core/workflows/help/modes/full.md +789 -0
  410. package/gsd-core/workflows/help/modes/topic.md +74 -0
  411. package/gsd-core/workflows/help.md +24 -0
  412. package/gsd-core/workflows/import.md +256 -0
  413. package/gsd-core/workflows/inbox.md +387 -0
  414. package/gsd-core/workflows/ingest-docs.md +340 -0
  415. package/gsd-core/workflows/insert-phase.md +152 -0
  416. package/gsd-core/workflows/list-phase-assumptions.md +178 -0
  417. package/gsd-core/workflows/list-workspaces.md +57 -0
  418. package/gsd-core/workflows/manager.md +393 -0
  419. package/gsd-core/workflows/map-codebase.md +446 -0
  420. package/gsd-core/workflows/milestone-summary.md +224 -0
  421. package/gsd-core/workflows/model-domain.md +162 -0
  422. package/gsd-core/workflows/mvp-phase.md +222 -0
  423. package/gsd-core/workflows/new-milestone.md +635 -0
  424. package/gsd-core/workflows/new-project.md +1555 -0
  425. package/gsd-core/workflows/new-workspace.md +240 -0
  426. package/gsd-core/workflows/next.md +299 -0
  427. package/gsd-core/workflows/node-repair.md +92 -0
  428. package/gsd-core/workflows/note.md +158 -0
  429. package/gsd-core/workflows/pause-work.md +244 -0
  430. package/gsd-core/workflows/plan-milestone-gaps.md +281 -0
  431. package/gsd-core/workflows/plan-phase.md +1814 -0
  432. package/gsd-core/workflows/plan-review-convergence.md +346 -0
  433. package/gsd-core/workflows/plant-seed.md +230 -0
  434. package/gsd-core/workflows/pr-branch.md +157 -0
  435. package/gsd-core/workflows/profile-user.md +453 -0
  436. package/gsd-core/workflows/progress.md +699 -0
  437. package/gsd-core/workflows/quick.md +1017 -0
  438. package/gsd-core/workflows/reapply-patches.md +426 -0
  439. package/gsd-core/workflows/recommend-architecture.md +135 -0
  440. package/gsd-core/workflows/remove-phase.md +156 -0
  441. package/gsd-core/workflows/remove-workspace.md +108 -0
  442. package/gsd-core/workflows/resume-project.md +332 -0
  443. package/gsd-core/workflows/review.md +748 -0
  444. package/gsd-core/workflows/scan.md +107 -0
  445. package/gsd-core/workflows/secure-phase.md +182 -0
  446. package/gsd-core/workflows/session-report.md +146 -0
  447. package/gsd-core/workflows/settings-advanced.md +810 -0
  448. package/gsd-core/workflows/settings-integrations.md +312 -0
  449. package/gsd-core/workflows/settings.md +566 -0
  450. package/gsd-core/workflows/ship.md +405 -0
  451. package/gsd-core/workflows/sketch-wrap-up.md +286 -0
  452. package/gsd-core/workflows/sketch.md +361 -0
  453. package/gsd-core/workflows/spec-phase.md +263 -0
  454. package/gsd-core/workflows/spike-wrap-up.md +307 -0
  455. package/gsd-core/workflows/spike.md +453 -0
  456. package/gsd-core/workflows/stats.md +80 -0
  457. package/gsd-core/workflows/sync-skills.md +182 -0
  458. package/gsd-core/workflows/testing-strategy.md +122 -0
  459. package/gsd-core/workflows/thread.md +222 -0
  460. package/gsd-core/workflows/transition.md +694 -0
  461. package/gsd-core/workflows/ui-phase.md +328 -0
  462. package/gsd-core/workflows/ui-review.md +193 -0
  463. package/gsd-core/workflows/ultraplan-phase.md +199 -0
  464. package/gsd-core/workflows/undo.md +314 -0
  465. package/gsd-core/workflows/update.md +496 -0
  466. package/gsd-core/workflows/validate-phase.md +181 -0
  467. package/gsd-core/workflows/verify-phase.md +544 -0
  468. package/gsd-core/workflows/verify-work.md +781 -0
  469. package/hooks/dist/gsd-check-update-worker.js +108 -0
  470. package/hooks/dist/gsd-check-update.js +66 -0
  471. package/hooks/dist/gsd-config-reload.js +133 -0
  472. package/hooks/dist/gsd-context-monitor.js +195 -0
  473. package/hooks/dist/gsd-cursor-post-tool.js +75 -0
  474. package/hooks/dist/gsd-cursor-session-start.js +52 -0
  475. package/hooks/dist/gsd-graphify-update.sh +158 -0
  476. package/hooks/dist/gsd-phase-boundary.sh +47 -0
  477. package/hooks/dist/gsd-prompt-guard.js +97 -0
  478. package/hooks/dist/gsd-read-guard.js +101 -0
  479. package/hooks/dist/gsd-read-injection-scanner.js +203 -0
  480. package/hooks/dist/gsd-session-state.sh +59 -0
  481. package/hooks/dist/gsd-statusline.js +566 -0
  482. package/hooks/dist/gsd-update-banner.js +138 -0
  483. package/hooks/dist/gsd-validate-commit.sh +57 -0
  484. package/hooks/dist/gsd-workflow-guard.js +167 -0
  485. package/hooks/dist/gsd-worktree-path-guard.js +169 -0
  486. package/hooks/dist/lib/git-cmd.js +150 -0
  487. package/hooks/dist/lib/gsd-graphify-rebuild.sh +65 -0
  488. package/hooks/dist/managed-hooks-registry.cjs +38 -0
  489. package/hooks/gsd-check-update-worker.js +108 -0
  490. package/hooks/gsd-check-update.js +66 -0
  491. package/hooks/gsd-config-reload.js +133 -0
  492. package/hooks/gsd-context-monitor.js +195 -0
  493. package/hooks/gsd-cursor-post-tool.js +75 -0
  494. package/hooks/gsd-cursor-session-start.js +52 -0
  495. package/hooks/gsd-graphify-update.sh +158 -0
  496. package/hooks/gsd-phase-boundary.sh +47 -0
  497. package/hooks/gsd-prompt-guard.js +97 -0
  498. package/hooks/gsd-read-guard.js +101 -0
  499. package/hooks/gsd-read-injection-scanner.js +203 -0
  500. package/hooks/gsd-session-state.sh +59 -0
  501. package/hooks/gsd-statusline.js +566 -0
  502. package/hooks/gsd-update-banner.js +138 -0
  503. package/hooks/gsd-validate-commit.sh +57 -0
  504. package/hooks/gsd-workflow-guard.js +167 -0
  505. package/hooks/gsd-worktree-path-guard.js +169 -0
  506. package/hooks/hooks.json +69 -0
  507. package/hooks/lib/git-cmd.js +150 -0
  508. package/hooks/lib/gsd-graphify-rebuild.sh +65 -0
  509. package/hooks/managed-hooks-registry.cjs +38 -0
  510. package/package.json +115 -0
  511. package/scripts/affected-tests-lib.cjs +542 -0
  512. package/scripts/audit-workflow-script-paths.cjs +73 -0
  513. package/scripts/base64-scan.sh +351 -0
  514. package/scripts/build-hooks.js +247 -0
  515. package/scripts/changeset/README.md +129 -0
  516. package/scripts/changeset/cli.cjs +590 -0
  517. package/scripts/changeset/github-release-notes.cjs +199 -0
  518. package/scripts/changeset/lint.cjs +111 -0
  519. package/scripts/changeset/new.cjs +137 -0
  520. package/scripts/changeset/parse.cjs +114 -0
  521. package/scripts/changeset/render.cjs +34 -0
  522. package/scripts/changeset/serialize.cjs +130 -0
  523. package/scripts/check-alias-drift.cjs +114 -0
  524. package/scripts/check-env.cjs +312 -0
  525. package/scripts/check-npm-integrity.cjs +215 -0
  526. package/scripts/ci-guard-runner.cjs +22 -0
  527. package/scripts/ci-prepare-test-scope.cjs +51 -0
  528. package/scripts/ci-rebase-check.cjs +86 -0
  529. package/scripts/ci-test-scope.cjs +431 -0
  530. package/scripts/command-contract-helpers.cjs +64 -0
  531. package/scripts/diff-touches-shipped-paths.cjs +155 -0
  532. package/scripts/fix-slash-commands.cjs +147 -0
  533. package/scripts/gen-inventory-manifest.cjs +115 -0
  534. package/scripts/gen-research-agents.cjs +276 -0
  535. package/scripts/generate-package-identity.cjs +125 -0
  536. package/scripts/issue-dedupe.cjs +278 -0
  537. package/scripts/lib/allowlist-ratchet.cjs +136 -0
  538. package/scripts/lib/cli-exit.cjs +56 -0
  539. package/scripts/lint-command-contract.cjs +114 -0
  540. package/scripts/lint-descriptions.cjs +87 -0
  541. package/scripts/lint-docs-required.cjs +222 -0
  542. package/scripts/lint-legacy-dir-name.cjs +160 -0
  543. package/scripts/lint-package-identity-drift.cjs +141 -0
  544. package/scripts/lint-pr-check-project-dir.cjs +99 -0
  545. package/scripts/lint-shell-command-projection-drift.cjs +62 -0
  546. package/scripts/lint-skill-deps.cjs +185 -0
  547. package/scripts/lint-test-file-count.allowlist.json +135 -0
  548. package/scripts/lint-test-file-count.cjs +246 -0
  549. package/scripts/mutation-matrix.cjs +222 -0
  550. package/scripts/pr-template-policy.cjs +268 -0
  551. package/scripts/prompt-injection-scan.sh +207 -0
  552. package/scripts/release-notes/discord-release-summary.cjs +373 -0
  553. package/scripts/release-notes/format-github-release-notes.cjs +261 -0
  554. package/scripts/release-tarball-smoke.cjs +629 -0
  555. package/scripts/research-profiles.cjs +149 -0
  556. package/scripts/run-affected-tests.cjs +7 -0
  557. package/scripts/run-cross-platform-tests.cjs +67 -0
  558. package/scripts/run-tests.cjs +315 -0
  559. package/scripts/secret-scan-lint.sh +231 -0
  560. package/scripts/secret-scan.sh +358 -0
  561. package/scripts/setup-branch-protection.sh +236 -0
  562. package/scripts/strip-prose-atrefs.cjs +106 -0
  563. package/scripts/sync-manifest-versions.cjs +119 -0
  564. package/scripts/sync-rulesets.sh +34 -0
  565. package/scripts/sync-runtime-launcher.cjs +399 -0
  566. package/scripts/test-failure-reasons.cjs +34 -0
  567. package/scripts/verify-npm-publish.cjs +240 -0
  568. package/scripts/workflow-policy.cjs +450 -0
@@ -0,0 +1,1814 @@
1
+ <purpose>
2
+ Create executable phase prompts (PLAN.md files) for a roadmap phase with integrated research and verification. Default flow: Research (if needed) -> Plan -> Verify -> Done. Orchestrates gsd-phase-researcher, gsd-planner, and gsd-plan-checker agents with a revision loop (max 3 iterations).
3
+ </purpose>
4
+
5
+ <required_reading>
6
+ Read all files referenced by the invoking prompt's execution_context before starting.
7
+
8
+ @~/.claude/gsd-core/references/ui-brand.md
9
+ @~/.claude/gsd-core/references/revision-loop.md
10
+ @~/.claude/gsd-core/references/gate-prompts.md
11
+ @~/.claude/gsd-core/references/agent-contracts.md
12
+ @~/.claude/gsd-core/references/gates.md
13
+ </required_reading>
14
+
15
+ <available_agent_types>
16
+ Valid GSD subagent types (use exact names — do not fall back to 'general-purpose'):
17
+ - gsd-phase-researcher — Researches technical approaches for a phase
18
+ - gsd-pattern-mapper — Analyzes codebase for existing patterns, produces PATTERNS.md
19
+ - gsd-planner — Creates detailed plans from phase scope
20
+ - gsd-plan-checker — Reviews plan quality before execution
21
+ </available_agent_types>
22
+
23
+ <process>
24
+
25
+ ## 0. Git Branch Invariant
26
+
27
+ **Do not create, rename, or switch git branches during plan-phase.** Branch identity is established at discuss-phase and is owned by the user's git workflow. A phase rename in ROADMAP.md is a plan-level change only — it does not mutate git branch names. If `phase_slug` in the init JSON differs from the current branch name, that is expected and correct; leave the branch unchanged.
28
+
29
+ ## 1. Initialize
30
+
31
+ Load all context in one call (paths only to minimize orchestrator context):
32
+
33
+ ```bash
34
+ _GSD_SHIM_NAME="gsd-tools.cjs"; _GSD_RUNTIME_ROOT="${RUNTIME_DIR:-$(git rev-parse --show-toplevel 2>/dev/null || pwd)}"; GSD_TOOLS="${_GSD_RUNTIME_ROOT}/gsd-core/bin/${_GSD_SHIM_NAME}"; if [ -f "$GSD_TOOLS" ]; then gsd_run() { node "$GSD_TOOLS" "$@"; }; elif [ -f "${_GSD_RUNTIME_ROOT}/.claude/gsd-core/bin/${_GSD_SHIM_NAME}" ]; then GSD_TOOLS="${_GSD_RUNTIME_ROOT}/.claude/gsd-core/bin/${_GSD_SHIM_NAME}"; gsd_run() { node "$GSD_TOOLS" "$@"; }; elif command -v gsd-tools >/dev/null 2>&1; then GSD_TOOLS="$(command -v gsd-tools)"; gsd_run() { "$GSD_TOOLS" "$@"; }; elif [ -f "$HOME/.claude/gsd-core/bin/${_GSD_SHIM_NAME}" ]; then GSD_TOOLS="$HOME/.claude/gsd-core/bin/${_GSD_SHIM_NAME}"; gsd_run() { node "$GSD_TOOLS" "$@"; }; else echo "ERROR: gsd-tools.cjs not found at $GSD_TOOLS and gsd-tools is not on PATH. Run: npx -y @therocketcode/gsd-core@latest --claude --local" >&2; exit 1; fi
35
+ GRAN_PARAM=""; if [[ "$ARGUMENTS" =~ (^|[[:space:]])--granularity[[:space:]]+([^[:space:]-][^[:space:]]*) ]]; then GRAN_PARAM="--granularity ${BASH_REMATCH[2]}"; fi
36
+ INIT=$(gsd_run query init.plan-phase "$PHASE" $GRAN_PARAM)
37
+ if [[ "$INIT" == @file:* ]]; then INIT=$(cat "${INIT#@file:}"); fi
38
+ AGENT_SKILLS_RESEARCHER=$(gsd_run query agent-skills gsd-phase-researcher)
39
+ AGENT_SKILLS_PLANNER=$(gsd_run query agent-skills gsd-planner)
40
+ AGENT_SKILLS_CHECKER=$(gsd_run query agent-skills gsd-plan-checker)
41
+ CONTEXT_WINDOW=$(gsd_run query config-get context_window 2>/dev/null || echo "200000")
42
+ TDD_MODE=$(gsd_run query config-get workflow.tdd_mode 2>/dev/null || echo "false")
43
+ MVP_MODE_CFG=$(gsd_run query config-get workflow.mvp_mode 2>/dev/null || echo "false")
44
+ ```
45
+
46
+ When `TDD_MODE` is `true`, the planner agent is instructed to apply `type: tdd` to eligible tasks using heuristics from `references/tdd.md`. The planner's `<required_reading>` is extended to include `@~/.claude/gsd-core/references/tdd.md` so gate enforcement rules are available during planning.
47
+
48
+ When `CONTEXT_WINDOW >= 500000`, the planner prompt includes the 3 most recent prior phase CONTEXT.md and SUMMARY.md files PLUS any phases explicitly listed in the current phase's `Depends on:` field in ROADMAP.md. Explicit dependencies always load regardless of recency (e.g., Phase 7 declaring `Depends on: Phase 2` always sees Phase 2's context). Bounded recency keeps the planner's context budget focused on recent work.
49
+
50
+ Parse JSON for: `researcher_model`, `planner_model`, `checker_model`, `research_enabled`, `plan_checker_enabled`, `nyquist_validation_enabled`, `commit_docs`, `text_mode`, `phase_found`, `phase_dir`, `phase_number`, `phase_name`, `phase_slug`, `padded_phase`, `has_research`, `has_context`, `has_reviews`, `has_plans`, `plan_count`, `phase_status` (#3569), `planning_exists`, `roadmap_exists`, `phase_req_ids`, `response_language`, `granularity`.
51
+
52
+ **If `response_language` is set:** Include `response_language: {value}` in all spawned subagent prompts so any user-facing output stays in the configured language.
53
+
54
+ **File paths (for <files_to_read> blocks):** `state_path`, `roadmap_path`, `requirements_path`, `context_path`, `research_path`, `verification_path`, `uat_path`, `reviews_path`. These are null if files don't exist.
55
+
56
+ **If `planning_exists` is false:** Error — run `/gsd:new-project` first.
57
+
58
+ ## 1.5. Closed-Phase Gate (#3569)
59
+
60
+ The init JSON includes `phase_status` — one of `Pending | Planned | In Progress | Executed | Complete | Needs Review`. `Complete` means the phase has all summaries AND a `VERIFICATION.md` with `status: passed`. Replanning a closed phase silently rewrites plan docs that no longer match the shipped code, so the workflow must hard-stop here unless the operator explicitly overrides.
61
+
62
+ Parse `phase_status` from the init JSON, then:
63
+
64
+ ```bash
65
+ FORCE_REPLAN=false
66
+ if [[ "$ARGUMENTS" =~ (^|[[:space:]])--force([[:space:]]|$) ]]; then
67
+ FORCE_REPLAN=true
68
+ fi
69
+
70
+ if [ "${phase_status}" = "Complete" ]; then
71
+ if [[ "$ARGUMENTS" =~ (^|[[:space:]])--reviews([[:space:]]|$) ]]; then
72
+ # --reviews on a closed phase is never legitimate — concerns belong in a
73
+ # new phase or issue against the closed phase's commits.
74
+ cat <<EOF >&2
75
+ Phase ${phase_number} (${phase_name}) is already CLOSED (VERIFICATION status: passed).
76
+ /gsd:plan-phase --reviews cannot replan a closed phase. If the review surfaced
77
+ real concerns, open a follow-up phase or file an issue against the closed
78
+ phase's commits. There is no --force override for --reviews on a closed phase.
79
+ EOF
80
+ exit 1
81
+ fi
82
+ if [ "$FORCE_REPLAN" != "true" ]; then
83
+ cat <<EOF >&2
84
+ Phase ${phase_number} (${phase_name}) is already CLOSED (VERIFICATION status: passed).
85
+ Replanning a closed phase will overwrite plan docs that no longer match the
86
+ shipped code. If you intentionally want to replan over closed work, re-run
87
+ with: /gsd:plan-phase ${phase_number} --force
88
+
89
+ Otherwise, to view what shipped, see: ${verification_path}
90
+ EOF
91
+ exit 1
92
+ fi
93
+ # FORCE_REPLAN=true: continue, but emit a banner so the operator sees the
94
+ # decision in the transcript and in any committed plan docs.
95
+ echo "WARNING: Replanning CLOSED phase ${phase_number} under --force. Verify the closeout was wrong before committing new plan docs." >&2
96
+ fi
97
+ ```
98
+
99
+ The gate fires only on `Complete`. `Executed` and `Needs Review` are not gated — those states mean planning was finished but verification did not pass, and replanning is a legitimate next step.
100
+
101
+ ## 2. Parse and Normalize Arguments
102
+
103
+ Extract from $ARGUMENTS: phase number (integer or decimal like `2.1`), flags (`--research`, `--skip-research`, `--research-phase <N>`, `--gaps`, `--skip-verify`, `--skip-ui`, `--prd <filepath>`, `--ingest <path-or-glob>`, `--ingest-format <auto|nygard|madr|narrative>`, `--reviews`, `--text`, `--bounce`, `--skip-bounce`, `--chunked`, `--mvp`, `--tdd`, `--granularity <coarse|standard|fine>`, `--force` (override closed-phase gate, see §1.5)).
104
+
105
+ **`--research-phase <N>` — research-only mode (#3042 + #3044).** When this flag is present, parse `<N>` as the phase number (overrides any positional phase argument), set `RESEARCH_ONLY=true`, and treat the rest of this workflow as a research-dispatch only — the planner spawn (step 8), plan-checker, verification, gaps, bounce, and post-planning-gaps blocks all skip on `RESEARCH_ONLY`. Use this for cross-phase research, doc review before committing to a planning approach, and correction-without-replanning loops. Replaces the deleted `/gsd-research-phase` command.
106
+
107
+ In research-only mode, two modifiers control behavior when `RESEARCH.md` already exists:
108
+
109
+ - **`--research`** — force-refresh re-research without prompting. Re-spawns the researcher unconditionally and overwrites the existing RESEARCH.md. (This is the existing `--research` flag's standard "force re-research" semantics, reused here.)
110
+ - **`--view`** — view-only: print existing `RESEARCH.md` to stdout, do **not** spawn the researcher. Sets `VIEW_ONLY=true`. Cheapest mode for the correction-without-replanning loop. If `RESEARCH.md` does not exist, error with a hint to drop `--view`.
111
+
112
+ ```bash
113
+ RESEARCH_ONLY=false
114
+ VIEW_ONLY=false
115
+ if [[ "$ARGUMENTS" =~ --research-phase[[:space:]]+([0-9]+(\.[0-9]+)?) ]]; then
116
+ RESEARCH_ONLY=true
117
+ PHASE="${BASH_REMATCH[1]}"
118
+ fi
119
+ if $RESEARCH_ONLY && [[ "$ARGUMENTS" =~ (^|[[:space:]])--view([[:space:]]|$) ]]; then
120
+ VIEW_ONLY=true
121
+ fi
122
+ ```
123
+
124
+ **`--granularity <coarse|standard|fine>` — CLI override (#703).** When present, this value is the resolved granularity passed to the planner — it wins over any per-phase `granularities.<type>` config, top-level `granularity` config, or project defaults. The init JSON always includes a `granularity` field reflecting the resolved value; read it from there. Invalid values (anything other than `coarse`, `standard`, `fine`) cause an error at the CLI boundary.
125
+
126
+ 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 Claude Code remote sessions (`/rc` mode) where TUI menus don't work through the Claude App.
127
+
128
+ **MVP_MODE resolution.** Resolve `MVP_MODE` once via the centralized `phase.mvp-mode` query verb. Precedence (first hit wins): CLI flag → ROADMAP.md `**Mode:** mvp` → `workflow.mvp_mode` config → false. The verb is the single source of truth — do not re-implement the chain.
129
+
130
+ ```bash
131
+ MVP_FLAG_ARG=""
132
+ if [[ "$ARGUMENTS" =~ (^|[[:space:]])--mvp([[:space:]]|$) ]]; then MVP_FLAG_ARG="--cli-flag"; fi
133
+ if [[ "$ARGUMENTS" =~ (^|[[:space:]])--tdd([[:space:]]|$) ]]; then TDD_MODE=true; fi
134
+ ```
135
+
136
+ Defer the `phase.mvp-mode` query until `PHASE` is finalized (after explicit argument parsing/fallback phase detection + validation). The verb returns `true|false`; full result also exposes `source` (`cli_flag` | `roadmap` | `config` | `none`) for diagnostics. Mode is **all-or-nothing per phase** (PRD decision Q1).
137
+
138
+ **Walking Skeleton gate.** When `MVP_MODE=true` AND `phase_number == "01"` AND there are zero prior phase summaries (new project), the planner runs in **Walking Skeleton mode** (per PRD decision Q2 — new projects only). Detect with:
139
+
140
+ ```bash
141
+ WALKING_SKELETON=false
142
+ if [ "$MVP_MODE" = "true" ] && [ "$padded_phase" = "01" ]; then
143
+ PRIOR_SUMMARIES=$(gsd_run query phases.list --pick summaries_total 2>/dev/null || echo "0")
144
+ if [ "$PRIOR_SUMMARIES" = "0" ]; then WALKING_SKELETON=true; fi
145
+ fi
146
+ ```
147
+
148
+ When `WALKING_SKELETON=true`:
149
+ - Planner is instructed to produce `SKELETON.md` in the phase directory alongside `PLAN.md`. The template lives at `~/.claude/gsd-core/references/skeleton-template.md` — the planner reads it when producing SKELETON.md (lazy; not loaded on non-skeleton runs).
150
+ - The plan must scaffold project + routing + one real DB read/write + one real UI interaction + dev deployment — the thinnest possible end-to-end working slice.
151
+
152
+ **Interaction with `--prd <filepath>`.** `--mvp` and `--prd` compose. The PRD express path (Step 3.5) creates `CONTEXT.md` from the PRD file and continues to research; the Walking Skeleton gate fires independently from the conditions above. When both are active on Phase 1 of a new project, the planner receives `WALKING_SKELETON=true` and PRD-derived context simultaneously — the PRD informs *what the skeleton should prove*. No precedence is needed; the two signals are orthogonal. See [`references/mvp-concepts.md`](../references/mvp-concepts.md) for the broader interaction map.
153
+
154
+ Extract express-path args from $ARGUMENTS: `PRD_FILE` (`--prd <filepath>`), `INGEST_PATH` (`--ingest <path-or-glob>`), and optional `INGEST_FORMAT` (`--ingest-format <auto|nygard|madr|narrative>`, default `auto`).
155
+
156
+ `--prd` and `--ingest` are mutually exclusive. If both are present, error and exit:
157
+ `Invalid arguments: cannot combine \`--prd\` with \`--ingest\`.`
158
+
159
+ **If no phase number:** Detect next unplanned phase from roadmap.
160
+
161
+ **If `phase_found` is false:** Validate phase exists in ROADMAP.md. If valid, create the directory using `expected_phase_dir` from init (includes `project_code` prefix when set):
162
+ ```bash
163
+ mkdir -p "${expected_phase_dir}"
164
+ ```
165
+
166
+ Set `phase_dir="${expected_phase_dir}"` after creation.
167
+
168
+ **Existing artifacts from init:** `has_research`, `has_plans`, `plan_count`.
169
+
170
+ Set `CHUNKED_MODE` from flag or config:
171
+ ```bash
172
+ CHUNKED_CFG=$(gsd_run query config-get workflow.plan_chunked 2>/dev/null || echo "false")
173
+ CHUNKED_MODE=false
174
+ if [[ "$ARGUMENTS" =~ --chunked ]] || [[ "$CHUNKED_CFG" == "true" ]]; then
175
+ CHUNKED_MODE=true
176
+ fi
177
+ ```
178
+
179
+ ## 2.5. Validate `--reviews` Prerequisite
180
+
181
+ **Skip if:** No `--reviews` flag.
182
+
183
+ **If `--reviews` AND `--gaps`:** Error — cannot combine `--reviews` with `--gaps`. These are conflicting modes.
184
+
185
+ **If `--reviews` AND `has_reviews` is false (no REVIEWS.md in phase dir):**
186
+
187
+ Error:
188
+ ```
189
+ No REVIEWS.md found for Phase {N}. Run reviews first:
190
+
191
+ /gsd:review --phase {N}
192
+
193
+ Then re-run /gsd:plan-phase {N} --reviews
194
+ ```
195
+ Exit workflow.
196
+
197
+ ## 3. Validate Phase
198
+
199
+ ```bash
200
+ PHASE_INFO=$(gsd_run query roadmap.get-phase "${PHASE}")
201
+ ```
202
+
203
+ **If `found` is false:** Error with available phases. **If `found` is true:** Extract `phase_number`, `phase_name`, `goal` from JSON.
204
+
205
+ Now that `PHASE` is finalized, resolve MVP mode:
206
+ ```bash
207
+ MVP_MODE=$(gsd_run query phase.mvp-mode "${PHASE}" $MVP_FLAG_ARG --pick active)
208
+ ```
209
+
210
+ ## 3.5. Handle PRD Express Path
211
+
212
+ **Skip if:** No `--prd` flag in arguments.
213
+
214
+ **If `--prd <filepath>` provided:**
215
+
216
+ 1. Read the PRD file:
217
+ ```bash
218
+ PRD_CONTENT=$(cat "$PRD_FILE" 2>/dev/null)
219
+ if [ -z "$PRD_CONTENT" ]; then
220
+ echo "Error: PRD file not found: $PRD_FILE"
221
+ exit 1
222
+ fi
223
+ ```
224
+
225
+ 2. Display banner:
226
+ ```
227
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
228
+ GSD ► PRD EXPRESS PATH
229
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
230
+
231
+ Using PRD: {PRD_FILE}
232
+ Generating CONTEXT.md from requirements...
233
+ ```
234
+
235
+ 3. Parse the PRD content and generate CONTEXT.md. The orchestrator should:
236
+ - Extract all requirements, user stories, acceptance criteria, and constraints from the PRD
237
+ - Map each to a locked decision (everything in the PRD is treated as a locked decision)
238
+ - Identify any areas the PRD doesn't cover and mark as "Claude's Discretion"
239
+ - **Extract canonical refs** from ROADMAP.md for this phase, plus any specs/ADRs referenced in the PRD — expand to full file paths (MANDATORY)
240
+ - Create CONTEXT.md in the phase directory
241
+
242
+ 4. Write CONTEXT.md:
243
+ ```markdown
244
+ # Phase [X]: [Name] - Context
245
+
246
+ **Gathered:** [date]
247
+ **Status:** Ready for planning
248
+ **Source:** PRD Express Path ({PRD_FILE})
249
+
250
+ <domain>
251
+ ## Phase Boundary
252
+
253
+ [Extracted from PRD — what this phase delivers]
254
+
255
+ </domain>
256
+
257
+ <decisions>
258
+ ## Implementation Decisions
259
+
260
+ {For each requirement/story/criterion in the PRD:}
261
+ ### [Category derived from content]
262
+ - [Requirement as locked decision]
263
+
264
+ ### Claude's Discretion
265
+ [Areas not covered by PRD — implementation details, technical choices]
266
+
267
+ </decisions>
268
+
269
+ <canonical_refs>
270
+ ## Canonical References
271
+
272
+ **Downstream agents MUST read these before planning or implementing.**
273
+
274
+ [MANDATORY. Extract from ROADMAP.md and any docs referenced in the PRD.
275
+ Use full relative paths. Group by topic area.]
276
+
277
+ ### [Topic area]
278
+ - `path/to/spec-or-adr.md` — [What it decides/defines]
279
+
280
+ [If no external specs: "No external specs — requirements fully captured in decisions above"]
281
+
282
+ </canonical_refs>
283
+
284
+ <specifics>
285
+ ## Specific Ideas
286
+
287
+ [Any specific references, examples, or concrete requirements from PRD]
288
+
289
+ </specifics>
290
+
291
+ <deferred>
292
+ ## Deferred Ideas
293
+
294
+ [Items in PRD explicitly marked as future/v2/out-of-scope]
295
+ [If none: "None — PRD covers phase scope"]
296
+
297
+ </deferred>
298
+
299
+ ---
300
+
301
+ *Phase: XX-name*
302
+ *Context gathered: [date] via PRD Express Path*
303
+ ```
304
+
305
+ 5. Commit:
306
+ ```bash
307
+ gsd_run query commit "docs(${padded_phase}): generate context from PRD" --files "${phase_dir}/${padded_phase}-CONTEXT.md"
308
+ ```
309
+
310
+ 6. Set `context_content` to the generated CONTEXT.md content and continue to step 5 (Handle Research).
311
+
312
+ **Effect:** This completely bypasses step 4 (Load CONTEXT.md) since we just created it. The rest of the workflow (research, planning, verification) proceeds normally with the PRD-derived context.
313
+
314
+ ## 3.6. Handle ADR Ingest Express Path
315
+
316
+ **Skip if:** No `--ingest` flag in arguments.
317
+
318
+ **If `--ingest <path-or-glob>` provided:**
319
+
320
+ 1. Display banner: `GSD ► ADR Ingest Express Path` with `{INGEST_PATH}` and `{INGEST_FORMAT}`.
321
+ 2. Parse each resolved ADR through `gsd-core/bin/lib/adr-parser.cjs` (`--input`, `--format`) and collect normalized records.
322
+ 3. Status gate: reject `superseded`/`rejected`/`deprecated`; warn on `proposed`; missing status defaults to `accepted`.
323
+ 4. Empty-decisions fallback: if all parsed ADRs have zero `decisions[]`, emit `ADR ingest produced no locked decisions; fall back to discuss-phase for this phase.` and exit with `/gsd:discuss-phase {N}` guidance.
324
+ 5. Generate CONTEXT.md using `<domain>`, `<decisions>`, `<canonical_refs>`, `<specifics>`, `<deferred>`, `<scope_fence>`, map `consequences_positive[]` to Success Criteria and `consequences_negative[]` to Risk Summary, and include `**Source:** ADR Ingest Express Path ({INGEST_PATH})`.
325
+ 6. Commit with `gsd-tools.cjs query commit "docs(${padded_phase}): generate context from ADR ingest" --files "${phase_dir}/${padded_phase}-CONTEXT.md"` and set `context_content`; continue to step 5.
326
+
327
+ **Effect:** This bypasses step 4 (Load CONTEXT.md) since CONTEXT.md was synthesized from ADR input.
328
+
329
+ ## 4. Load CONTEXT.md
330
+
331
+ **Skip if:** PRD express path or ADR ingest express path was used (CONTEXT.md already created in step 3.5/3.6).
332
+
333
+ Check `context_path` from init JSON.
334
+
335
+ If `context_path` is not null, display: `Using phase context from: ${context_path}`
336
+
337
+ **If `context_path` is null (no CONTEXT.md exists):**
338
+
339
+ Read discuss mode for context gate label:
340
+ ```bash
341
+ DISCUSS_MODE=$(gsd_run query config-get workflow.discuss_mode 2>/dev/null || echo "discuss")
342
+ ```
343
+
344
+ If `TEXT_MODE` is true, present as a plain-text numbered list:
345
+ ```
346
+ No CONTEXT.md found for Phase {X}. Plans will use research and requirements only — your design preferences won't be included.
347
+
348
+ 1. Continue without context — Plan using research + requirements only
349
+ [If DISCUSS_MODE is "assumptions":]
350
+ 2. Gather context (assumptions mode) — Analyze codebase and surface assumptions before planning
351
+ [If DISCUSS_MODE is "discuss" or unset:]
352
+ 2. Run discuss-phase first — Capture design decisions before planning
353
+
354
+ Enter number:
355
+ ```
356
+
357
+ Otherwise use AskUserQuestion:
358
+ - header: "No context"
359
+ - question: "No CONTEXT.md found for Phase {X}. Plans will use research and requirements only — your design preferences won't be included. Continue or capture context first?"
360
+ - options:
361
+ - "Continue without context" — Plan using research + requirements only
362
+ If `DISCUSS_MODE` is `"assumptions"`:
363
+ - "Gather context (assumptions mode)" — Analyze codebase and surface assumptions before planning
364
+ If `DISCUSS_MODE` is `"discuss"` (or unset):
365
+ - "Run discuss-phase first" — Capture design decisions before planning
366
+
367
+ If "Continue without context": Proceed to step 5.
368
+ If "Run discuss-phase first":
369
+ **IMPORTANT:** Do NOT invoke discuss-phase as a nested Skill/Task call — AskUserQuestion
370
+ does not work correctly in nested subcontexts (#1009). Instead, display the command
371
+ and exit so the user runs it as a top-level command:
372
+ ```
373
+ Run this command first, then re-run /gsd:plan-phase {X} ${GSD_WS}:
374
+
375
+ /gsd:discuss-phase {X} ${GSD_WS}
376
+ ```
377
+ **Exit the plan-phase workflow. Do not continue.**
378
+
379
+ ## 4.5. Check AI-SPEC
380
+
381
+ **Skip if:** `ai_integration_phase_enabled` from config is false, or `--skip-ai-spec` flag provided.
382
+
383
+ ```bash
384
+ AI_SPEC_FILE=$(ls "${PHASE_DIR}"/*-AI-SPEC.md 2>/dev/null | head -1)
385
+ AI_PHASE_CFG=$(gsd_run query config-get workflow.ai_integration_phase 2>/dev/null || echo "true")
386
+ ```
387
+
388
+ **Skip if `AI_PHASE_CFG` is `false`.**
389
+
390
+ **If `AI_SPEC_FILE` is empty:** Check phase goal for AI keywords:
391
+ ```bash
392
+ echo "${phase_goal}" | grep -qi "agent\|llm\|rag\|chatbot\|embedding\|langchain\|llamaindex\|crewai\|langgraph\|openai\|anthropic\|vector\|eval\|ai system"
393
+ ```
394
+
395
+ **If AI keywords detected AND no AI-SPEC.md:**
396
+ ```
397
+ ◆ Note: This phase appears to involve AI system development.
398
+ Consider running /gsd:ai-integration-phase {N} before planning to:
399
+ - Select the right framework for your use case
400
+ - Research its docs and best practices
401
+ - Design an evaluation strategy
402
+
403
+ Continue planning without AI-SPEC? (non-blocking — /gsd:ai-integration-phase can be run after)
404
+ ```
405
+
406
+ Use AskUserQuestion with options:
407
+ - "Continue — plan without AI-SPEC"
408
+ - "Stop — I'll run /gsd:ai-integration-phase {N} first"
409
+
410
+ If "Stop": Exit with `/gsd:ai-integration-phase {N}` reminder.
411
+ If "Continue": Proceed. (Non-blocking — planner will note AI-SPEC is absent.)
412
+
413
+ **If `AI_SPEC_FILE` is non-empty:** Extract framework for planner context:
414
+ ```bash
415
+ FRAMEWORK_LINE=$(grep "Selected Framework:" "${AI_SPEC_FILE}" | head -1)
416
+ ```
417
+ Pass `ai_spec_path` and `framework_line` to planner in step 7 so it can reference the AI design contract.
418
+
419
+ ## 5. Handle Research
420
+
421
+ **Skip if:** `--gaps` flag or `--skip-research` flag or `--reviews` flag.
422
+
423
+ ### 5.0. Research-Only Modifiers (`--view`, `--research`)
424
+
425
+ **Skip if:** `RESEARCH_ONLY` is `false`.
426
+
427
+ Three branches in research-only mode (`--research-phase <N>`):
428
+
429
+ 1. **`--view`**: print `RESEARCH.md` to stdout, no spawn, exit. If `RESEARCH.md` is missing, error with: `--view requires an existing RESEARCH.md; drop --view to spawn the researcher.`
430
+ 2. **`--research`** (force-refresh): re-spawn researcher unconditionally — fall through to "Spawn gsd-phase-researcher" below.
431
+ 3. **Neither flag AND `has_research=true`:** auto-use the existing research and exit cleanly — do not prompt, do not re-spawn. Emit `RESEARCH.md already exists for Phase ${PHASE}, using it. To force-refresh, re-invoke with --research; to print, re-invoke with --view. Path: ${research_path}` then exit. The explicit-flag escape hatches cover any deviation; this matches §5.1's promptless auto-use of existing research, removing the §5.0/§5.1 inconsistency (#159).
432
+
433
+ ```bash
434
+ if [[ "$VIEW_ONLY" == "true" ]]; then
435
+ [[ -f "$research_path" ]] || { echo "Error: --view requires an existing RESEARCH.md (Phase ${PHASE}). Drop --view to spawn the researcher."; exit 1; }
436
+ cat "$research_path"; exit 0
437
+ fi
438
+ ```
439
+
440
+ ### 5.1. Standard Research Decision
441
+
442
+ **Skip if** `RESEARCH_ONLY=true` (the research-only mode in 5.0 already determined the path: spawn or exit). Without this guard, an LLM following the workflow could fall through into "use existing, skip to step 6" → planner spawn, violating the research-only contract. **CR #3045 finding: this gate makes the early-exit unreachable from any non-research-only branch.**
443
+
444
+ **If `has_research` is true (from init) AND no `--research` flag:** Use existing, skip to step 6.
445
+
446
+ **If RESEARCH.md missing OR `--research` flag:**
447
+
448
+ **If no explicit flag (`--research` or `--skip-research`) and not `--auto`:**
449
+ Ask the user whether to research, with a contextual recommendation based on the phase:
450
+
451
+ If `TEXT_MODE` is true, present as a plain-text numbered list:
452
+ ```
453
+ Research before planning Phase {X}: {phase_name}?
454
+
455
+ 1. Research first (Recommended) — Investigate domain, patterns, and dependencies before planning. Best for new features, unfamiliar integrations, or architectural changes.
456
+ 2. Skip research — Plan directly from context and requirements. Best for bug fixes, simple refactors, or well-understood tasks.
457
+
458
+ Enter number:
459
+ ```
460
+
461
+ Otherwise use AskUserQuestion:
462
+ ```
463
+ AskUserQuestion([
464
+ {
465
+ question: "Research before planning Phase {X}: {phase_name}?",
466
+ header: "Research",
467
+ multiSelect: false,
468
+ options: [
469
+ { label: "Research first (Recommended)", description: "Investigate domain, patterns, and dependencies before planning. Best for new features, unfamiliar integrations, or architectural changes." },
470
+ { label: "Skip research", description: "Plan directly from context and requirements. Best for bug fixes, simple refactors, or well-understood tasks." }
471
+ ]
472
+ }
473
+ ])
474
+ ```
475
+
476
+ If user selects "Skip research": skip to step 6.
477
+
478
+ **If `--auto` and `research_enabled` is false:** Skip research silently (preserves automated behavior).
479
+
480
+ Display banner:
481
+ ```
482
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
483
+ GSD ► RESEARCHING PHASE {X}
484
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
485
+
486
+ ◆ Spawning researcher... (runs in a subagent — no output until it returns, ~1–5 min; expected, not a freeze)
487
+ ```
488
+
489
+ ### Spawn gsd-phase-researcher
490
+
491
+ ```bash
492
+ PHASE_DESC=$(gsd_run query roadmap.get-phase "${PHASE}" --pick section)
493
+ ```
494
+
495
+ Research prompt:
496
+
497
+ ```markdown
498
+ <objective>
499
+ Research how to implement Phase {phase_number}: {phase_name}
500
+ Answer: "What do I need to know to PLAN this phase well?"
501
+ </objective>
502
+
503
+ <files_to_read>
504
+ - {context_path} (USER DECISIONS from /gsd:discuss-phase)
505
+ - {requirements_path} (Project requirements)
506
+ - {state_path} (Project decisions and history)
507
+ </files_to_read>
508
+
509
+ ${AGENT_SKILLS_RESEARCHER}
510
+
511
+ <additional_context>
512
+ **Phase description:** {phase_description}
513
+ **Phase requirement IDs (MUST address):** {phase_req_ids}
514
+
515
+ **Project instructions:** Read ./CLAUDE.md if exists — follow project-specific guidelines
516
+ **Project skills:** Check .claude/skills/ or .agents/skills/ directory (if either exists) — read SKILL.md files, research should account for project skill patterns
517
+ </additional_context>
518
+
519
+ <output>
520
+ Write to: {phase_dir}/{phase_num}-RESEARCH.md
521
+ </output>
522
+ ```
523
+
524
+ ```
525
+ Agent(
526
+ prompt=research_prompt,
527
+ subagent_type="gsd-phase-researcher",
528
+ model="{researcher_model}",
529
+ description="Research Phase {phase}"
530
+ )
531
+ ```
532
+
533
+ > **ORCHESTRATOR RULE — CODEX RUNTIME**: After calling Agent() above, stop working on this task immediately. Do not read more files, edit code, or run tests related to this task while the subagent is active. Wait for the subagent to return its result. This prevents duplicate work, conflicting edits, and wasted context. Only resume when the subagent result is available.
534
+
535
+ ### Handle Researcher Return
536
+
537
+ - **`## RESEARCH COMPLETE`:** Display confirmation, continue to step 6
538
+ - **`## RESEARCH BLOCKED`:** Display blocker, offer: 1) Provide context, 2) Skip research, 3) Abort
539
+
540
+ ### Research-Only Early Exit (`--research-phase`)
541
+
542
+ **Skip if:** `RESEARCH_ONLY` is `false` (the default).
543
+
544
+ **If `RESEARCH_ONLY=true`:** the user invoked `/gsd:plan-phase --research-phase <N>` for research-only mode. Do **not** continue to Section 5.5+ (validation strategy, planner, plan-checker, verification, gaps, bounce, post-planning-gaps). Print the research-complete summary and exit cleanly:
545
+
546
+ ```text
547
+ ✓ Research-only mode complete (#3042)
548
+
549
+ Phase: ${PHASE}
550
+ RESEARCH.md: ${research_path}
551
+
552
+ Re-run /gsd:plan-phase ${PHASE} to plan the phase using this research,
553
+ or /gsd:plan-phase ${PHASE} --research to refresh research and plan.
554
+ ```
555
+
556
+ This exits the workflow. The planner / plan-checker / verifier blocks below are skipped.
557
+
558
+ ## 5.5. Create Validation Strategy
559
+
560
+ Skip if `nyquist_validation_enabled` is false OR `research_enabled` is false.
561
+
562
+ If `research_enabled` is false and `nyquist_validation_enabled` is true: warn "Nyquist validation enabled but research disabled — VALIDATION.md cannot be created without RESEARCH.md. Plans will lack validation requirements (Dimension 8)." Continue to step 6.
563
+
564
+ **But Nyquist is not applicable for this run** when all of the following are true:
565
+ - `research_enabled` is false
566
+ - `has_research` is false
567
+ - no `--research` flag was provided
568
+
569
+ In that case: **skip validation-strategy creation entirely**. Do **not** expect `RESEARCH.md` or `VALIDATION.md` for this run, and continue to Step 6.
570
+
571
+ ```bash
572
+ grep -l "## Validation Architecture" "${PHASE_DIR}"/*-RESEARCH.md 2>/dev/null || true
573
+ ```
574
+
575
+ **If found:**
576
+ 1. Read template: `~/.claude/gsd-core/templates/VALIDATION.md`
577
+ 2. Write to `${PHASE_DIR}/${PADDED_PHASE}-VALIDATION.md` (use Write tool)
578
+ 3. Fill frontmatter: `{N}` → phase number, `{phase-slug}` → slug, `{date}` → current date
579
+ 4. Verify:
580
+ ```bash
581
+ test -f "${PHASE_DIR}/${PADDED_PHASE}-VALIDATION.md" && echo "VALIDATION_CREATED=true" || echo "VALIDATION_CREATED=false"
582
+ ```
583
+ 5. If `VALIDATION_CREATED=false`: STOP — do not proceed to Step 6
584
+ 6. If `commit_docs`: `commit "docs(phase-${PHASE}): add validation strategy"`
585
+
586
+ **If not found:** Warn and continue — plans may fail Dimension 8.
587
+
588
+ ## 5.55. Security Threat Model Gate
589
+
590
+ > Skip if `workflow.security_enforcement` is explicitly `false`. Absent = enabled.
591
+
592
+ ```bash
593
+ SECURITY_CFG=$(gsd_run query config-get workflow.security_enforcement --raw 2>/dev/null || echo "true")
594
+ SECURITY_ASVS=$(gsd_run query config-get workflow.security_asvs_level --raw 2>/dev/null || echo "1")
595
+ SECURITY_BLOCK=$(gsd_run query config-get workflow.security_block_on --raw 2>/dev/null || echo "high")
596
+ ```
597
+
598
+ **If `SECURITY_CFG` is `false`:** Skip to step 5.6.
599
+
600
+ **If `SECURITY_CFG` is `true`:** Display banner:
601
+
602
+ ```
603
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
604
+ GSD ► SECURITY THREAT MODEL REQUIRED (ASVS L{SECURITY_ASVS})
605
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
606
+
607
+ Each PLAN.md must include a <threat_model> block.
608
+ Block on: {SECURITY_BLOCK} severity threats.
609
+ Opt out: set security_enforcement: false in .planning/config.json
610
+ ```
611
+
612
+ Continue to step 5.6. Security config is passed to the planner in step 8.
613
+
614
+ ## 5.6. UI Design Contract Gate
615
+
616
+ > Skip if `workflow.ui_phase` is explicitly `false` AND `workflow.ui_safety_gate` is explicitly `false` in `.planning/config.json`. If keys are absent, treat as enabled.
617
+
618
+ ```bash
619
+ UI_PHASE_CFG=$(gsd_run query config-get workflow.ui_phase 2>/dev/null || echo "true")
620
+ UI_GATE_CFG=$(gsd_run query config-get workflow.ui_safety_gate 2>/dev/null || echo "true")
621
+ ```
622
+
623
+ **If both are `false`:** Skip to step 6.
624
+
625
+ Check if phase has frontend indicators:
626
+
627
+ ```bash
628
+ PHASE_SECTION=$(gsd_run query roadmap.get-phase "${PHASE}" 2>/dev/null)
629
+ # Shell-free word-boundary gate (#3718): Node.js helper — no locale env-var dependency.
630
+ # Reads via stdin to avoid OS ARG_MAX limits on large phase text.
631
+ # Resolve the helper against the GSD install dir via RUNTIME_DIR (#448) — NOT the consuming
632
+ # project's git root — falling back to git toplevel / $HOME/.claude. Exit codes mirror grep (0=UI,1=none).
633
+ _GSD_RT="${RUNTIME_DIR:-$(git rev-parse --show-toplevel 2>/dev/null || pwd)}"
634
+ UI_GATE_JS=$(for _c in "$_GSD_RT/gsd-core/bin/lib/ui-safety-gate.cjs" "$_GSD_RT/bin/lib/ui-safety-gate.cjs" "$_GSD_RT/.claude/bin/lib/ui-safety-gate.cjs" "$HOME/.claude/gsd-core/bin/lib/ui-safety-gate.cjs" "$HOME/.claude/bin/lib/ui-safety-gate.cjs"; do [ -f "$_c" ] && { echo "$_c"; break; }; done)
635
+ if [ -n "$UI_GATE_JS" ]; then printf '%s' "$PHASE_SECTION" | node "$UI_GATE_JS" >/dev/null 2>&1; HAS_UI=$?; else echo "WARN: ui-safety-gate.cjs not found via RUNTIME_DIR/\$HOME (#448) — assuming UI present" >&2; HAS_UI=0; fi
636
+ ```
637
+
638
+ **If `HAS_UI` is 0 (frontend indicators found):**
639
+
640
+ Check for existing UI-SPEC:
641
+ ```bash
642
+ UI_SPEC_FILE=$(ls "${PHASE_DIR}"/*-UI-SPEC.md 2>/dev/null | head -1)
643
+ ```
644
+
645
+ **If UI-SPEC.md found:** Set `UI_SPEC_PATH=$UI_SPEC_FILE`. Display: `Using UI design contract: ${UI_SPEC_PATH}`
646
+
647
+ **If UI-SPEC.md missing AND `--skip-ui` flag is present in $ARGUMENTS:** Skip silently to step 6.
648
+
649
+ **If UI-SPEC.md missing AND `UI_GATE_CFG` is `true`:**
650
+
651
+ Read ephemeral chain flag (same field as `check.auto-mode` → `auto_chain_active`):
652
+ ```bash
653
+ AUTO_CHAIN=$(gsd_run query check auto-mode --pick auto_chain_active 2>/dev/null || echo "false")
654
+ ```
655
+
656
+ **If `AUTO_CHAIN` is `true` (running inside a `--chain` or `--auto` pipeline):**
657
+
658
+ Auto-generate UI-SPEC without prompting:
659
+ ```
660
+ Skill(skill="gsd-ui-phase", args="${PHASE} --auto ${GSD_WS}")
661
+ ```
662
+ After `gsd-ui-phase` returns, re-read:
663
+ ```bash
664
+ UI_SPEC_FILE=$(ls "${PHASE_DIR}"/*-UI-SPEC.md 2>/dev/null | head -1)
665
+ UI_SPEC_PATH="${UI_SPEC_FILE}"
666
+ ```
667
+ Continue to step 6.
668
+
669
+ **If `AUTO_CHAIN` is `false` (manual invocation):**
670
+
671
+ Output this markdown directly (not as a code block):
672
+
673
+ ```
674
+ ## ⚠ UI-SPEC.md missing for Phase {N}
675
+ ▶ Recommended next step:
676
+ `/gsd:ui-phase {N} ${GSD_WS}` — generate UI design contract before planning
677
+ ───────────────────────────────────────────────
678
+ Also available:
679
+ - `/gsd:plan-phase {N} --skip-ui ${GSD_WS}` — plan without UI-SPEC (not recommended for frontend phases)
680
+ ```
681
+
682
+ **Exit the plan-phase workflow. Do not continue.**
683
+
684
+ **If `HAS_UI` is 1 (no frontend indicators):** Skip silently to step 5.7.
685
+
686
+ ## 5.7. Schema Push Detection Gate
687
+
688
+ > Detects schema-relevant files in the phase scope and injects a mandatory `[BLOCKING]` schema push task into the plan. Prevents false-positive verification where build/types pass because TypeScript types come from config, not the live database.
689
+
690
+ Check if any files in the phase scope match schema patterns:
691
+
692
+ ```bash
693
+ PHASE_SECTION=$(gsd_run query roadmap.get-phase "${PHASE}" --pick section 2>/dev/null)
694
+ ```
695
+
696
+ Scan `PHASE_SECTION`, `CONTEXT.md` (if loaded), and `RESEARCH.md` (if exists) for file paths matching these ORM patterns:
697
+
698
+ | ORM | File Patterns |
699
+ |-----|--------------|
700
+ | Payload CMS | `src/collections/**/*.ts`, `src/globals/**/*.ts` |
701
+ | Prisma | `prisma/schema.prisma`, `prisma/schema/*.prisma` |
702
+ | Drizzle | `drizzle/schema.ts`, `src/db/schema.ts`, `drizzle/*.ts` |
703
+ | Supabase | `supabase/migrations/*.sql` |
704
+ | TypeORM | `src/entities/**/*.ts`, `src/migrations/**/*.ts` |
705
+
706
+ Also check if any existing PLAN.md files for this phase already reference these file patterns in `files_modified`.
707
+
708
+ **If schema-relevant files detected:**
709
+
710
+ Set `SCHEMA_PUSH_REQUIRED=true` and `SCHEMA_ORM={detected_orm}`.
711
+
712
+ Determine the push command for the detected ORM:
713
+
714
+ | ORM | Push Command | Non-TTY Workaround |
715
+ |-----|-------------|-------------------|
716
+ | Payload CMS | `npx payload migrate` | `CI=true PAYLOAD_MIGRATING=true npx payload migrate` |
717
+ | Prisma | `npx prisma db push` | `npx prisma db push --accept-data-loss` (if destructive) |
718
+ | Drizzle | `npx drizzle-kit push` | `npx drizzle-kit push` |
719
+ | Supabase | `supabase db push` | Set `SUPABASE_ACCESS_TOKEN` env var |
720
+ | TypeORM | `npx typeorm migration:run` | `npx typeorm migration:run -d src/data-source.ts` |
721
+
722
+ Inject the following into the planner prompt (step 8) as an additional constraint:
723
+
724
+ ```markdown
725
+ <schema_push_requirement>
726
+ **[BLOCKING] Schema Push Required**
727
+
728
+ This phase modifies schema-relevant files ({detected_files}). The planner MUST include
729
+ a `[BLOCKING]` task that runs the database schema push command AFTER all schema file
730
+ modifications are complete but BEFORE verification.
731
+
732
+ - ORM detected: {SCHEMA_ORM}
733
+ - Push command: {push_command}
734
+ - Non-TTY workaround: {env_hint}
735
+ - If push requires interactive prompts that cannot be suppressed, flag the task for
736
+ manual intervention with `autonomous: false`
737
+
738
+ This task is mandatory — the phase CANNOT pass verification without it. Build and
739
+ type checks will pass without the push (types come from config, not the live database),
740
+ creating a false-positive verification state.
741
+ </schema_push_requirement>
742
+ ```
743
+
744
+ Display: `Schema files detected ({SCHEMA_ORM}) — [BLOCKING] push task will be injected into plans`
745
+
746
+ **If no schema-relevant files detected:** Skip silently to step 6.
747
+
748
+ ## 6. Check Existing Plans
749
+
750
+ ```bash
751
+ ls "${PHASE_DIR}"/*-PLAN.md 2>/dev/null || true
752
+ ```
753
+
754
+ **If exists AND `--reviews` flag:** Skip prompt — go straight to replanning (the purpose of `--reviews` is to replan with review feedback).
755
+
756
+ **If exists AND no `--reviews` flag:** Offer: 1) Add more plans, 2) View existing, 3) Replan from scratch.
757
+
758
+ ## 7. Use Context Paths from INIT
759
+
760
+ Extract from INIT JSON:
761
+
762
+ ```bash
763
+ _gsd_field() { node -e "const o=JSON.parse(process.argv[1]); const v=o[process.argv[2]]; process.stdout.write(v==null?'':String(v))" "$1" "$2"; }
764
+ STATE_PATH=$(_gsd_field "$INIT" state_path)
765
+ ROADMAP_PATH=$(_gsd_field "$INIT" roadmap_path)
766
+ REQUIREMENTS_PATH=$(_gsd_field "$INIT" requirements_path)
767
+ RESEARCH_PATH=$(_gsd_field "$INIT" research_path)
768
+ VERIFICATION_PATH=$(_gsd_field "$INIT" verification_path)
769
+ UAT_PATH=$(_gsd_field "$INIT" uat_path)
770
+ CONTEXT_PATH=$(_gsd_field "$INIT" context_path)
771
+ REVIEWS_PATH=$(_gsd_field "$INIT" reviews_path)
772
+ PATTERNS_PATH=$(_gsd_field "$INIT" patterns_path)
773
+
774
+ # Detect spike/sketch findings skills (project-local)
775
+ SPIKE_FINDINGS_PATH=$(ls ./.claude/skills/spike-findings-*/SKILL.md 2>/dev/null | head -1 || true)
776
+ SKETCH_FINDINGS_PATH=$(ls ./.claude/skills/sketch-findings-*/SKILL.md 2>/dev/null | head -1 || true)
777
+ ```
778
+
779
+ ## 7.5. Verify Nyquist Artifacts
780
+
781
+ Skip if `nyquist_validation_enabled` is false OR `research_enabled` is false.
782
+
783
+ Also skip if all of the following are true:
784
+ - `research_enabled` is false
785
+ - `has_research` is false
786
+ - no `--research` flag was provided
787
+
788
+ In that no-research path, Nyquist artifacts are **not required** for this run.
789
+
790
+ ```bash
791
+ VALIDATION_EXISTS=$(ls "${PHASE_DIR}"/*-VALIDATION.md 2>/dev/null | head -1)
792
+ ```
793
+
794
+ If missing and Nyquist is still enabled/applicable — ask user:
795
+ 1. Re-run: `/gsd:plan-phase {PHASE} --research ${GSD_WS}`
796
+ 2. Disable Nyquist with the exact command:
797
+ `gsd-tools.cjs query config-set workflow.nyquist_validation false`
798
+ 3. Continue anyway (plans fail Dimension 8)
799
+
800
+ Proceed to Step 7.8 (or Step 8 if pattern mapper is disabled) only if user selects 2 or 3.
801
+
802
+ ## 7.8. Spawn gsd-pattern-mapper Agent (Optional)
803
+
804
+ **Skip if** `workflow.pattern_mapper` is explicitly set to `false` in config.json (absent key = enabled). Also skip if no CONTEXT.md and no RESEARCH.md exist for this phase (nothing to extract file lists from).
805
+
806
+ Check config:
807
+ ```bash
808
+ PATTERN_MAPPER_CFG=$(gsd_run query config-get workflow.pattern_mapper 2>/dev/null || echo "true")
809
+ ```
810
+
811
+ **If `PATTERN_MAPPER_CFG` is `false`:** Skip to step 8.
812
+
813
+ **If PATTERNS.md already exists** (`PATTERNS_PATH` is non-empty from step 7): Skip to step 8 (use existing).
814
+
815
+ Display banner:
816
+ ```
817
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
818
+ GSD ► PATTERN MAPPING PHASE {X}
819
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
820
+
821
+ ◆ Spawning pattern mapper... (runs in a subagent — no output until it returns, ~1–5 min; expected, not a freeze)
822
+ ```
823
+
824
+ Pattern mapper prompt:
825
+
826
+ ```markdown
827
+ <pattern_mapping_context>
828
+ **Phase:** {phase_number} - {phase_name}
829
+ **Phase directory:** {phase_dir}
830
+ **Padded phase:** {padded_phase}
831
+
832
+ <files_to_read>
833
+ - {context_path} (USER DECISIONS from /gsd:discuss-phase)
834
+ - {research_path} (Technical Research)
835
+ </files_to_read>
836
+
837
+ **Output file:** {phase_dir}/{padded_phase}-PATTERNS.md
838
+
839
+ Extract the list of files to be created/modified from CONTEXT.md and RESEARCH.md. For each file, classify by role and data flow, find the closest existing analog in the codebase, extract concrete code excerpts, and produce PATTERNS.md.
840
+ </pattern_mapping_context>
841
+ ```
842
+
843
+ Spawn with:
844
+ ```
845
+ Agent(
846
+ prompt="{above}",
847
+ subagent_type="gsd-pattern-mapper",
848
+ model="{researcher_model}",
849
+ )
850
+ ```
851
+
852
+ > **ORCHESTRATOR RULE — CODEX RUNTIME**: After calling Agent() above, stop working on this task immediately. Do not read more files, edit code, or run tests related to this task while the subagent is active. Wait for the subagent to return its result. This prevents duplicate work, conflicting edits, and wasted context. Only resume when the subagent result is available.
853
+
854
+ **Handle return:**
855
+ - **`## PATTERN MAPPING COMPLETE`:** Update `PATTERNS_PATH` to the created file path, continue to step 8.
856
+ - **Any error or empty return:** Log warning, continue to step 8 without patterns (non-blocking).
857
+
858
+ After pattern mapper completes, update the path variable:
859
+ ```bash
860
+ PATTERNS_PATH="${PHASE_DIR}/${PADDED_PHASE}-PATTERNS.md"
861
+ ```
862
+
863
+ ## 7.9. Regenerate API-SURFACE.md (intel gate)
864
+
865
+ ```bash
866
+ INTEL_CFG=$(gsd_run query config-get intel.enabled 2>/dev/null || echo "false")
867
+ # false (absent = false) → API_SURFACE_PATH stays empty; step-8 planner entry omitted
868
+ if [ "$INTEL_CFG" = "true" ]; then
869
+ gsd_run intel api-surface
870
+ API_SURFACE_PATH=".planning/intel/API-SURFACE.md"
871
+ echo "✓ API surface regenerated: ${API_SURFACE_PATH}" # injected into step 8 as HINT
872
+ fi
873
+ ```
874
+
875
+ ## 8. Spawn gsd-planner Agent
876
+
877
+ Display banner:
878
+ ```
879
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
880
+ GSD ► PLANNING PHASE {X}
881
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
882
+
883
+ ◆ Spawning planner... (runs in a subagent — no output until it returns, ~1–5 min; expected, not a freeze)
884
+ ```
885
+
886
+ Planner prompt:
887
+
888
+ ```markdown
889
+ <planning_context>
890
+ **Phase:** {phase_number}
891
+ **Mode:** {standard | gap_closure | reviews}
892
+
893
+ <files_to_read>
894
+ - {state_path} (Project State)
895
+ - {roadmap_path} (Roadmap)
896
+ - {requirements_path} (Requirements)
897
+ - {context_path} (USER DECISIONS from /gsd:discuss-phase)
898
+ - {research_path} (Technical Research)
899
+ - {PATTERNS_PATH} (Pattern Map — analog files and code excerpts, if exists)
900
+ - {verification_path} (Verification Gaps - if --gaps)
901
+ - {uat_path} (UAT Gaps - if --gaps)
902
+ - {reviews_path} (Cross-AI Review Feedback - if --reviews)
903
+ - {UI_SPEC_PATH} (UI Design Contract — visual/interaction specs, if exists)
904
+ - {SPIKE_FINDINGS_PATH} (Spike Findings — validated patterns, constraints, landmines from experiments, if exists)
905
+ - {SKETCH_FINDINGS_PATH} (Sketch Findings — validated design decisions, CSS patterns, visual direction, if exists)
906
+ - {API_SURFACE_PATH} (API Surface — HINT ONLY, if intel.enabled; see <intel_surface_hint> below)
907
+ ${CONTEXT_WINDOW >= 500000 ? `
908
+ **Cross-phase context (1M model enrichment):**
909
+ - CONTEXT.md files from the 3 most recent completed phases (locked decisions — maintain consistency)
910
+ - SUMMARY.md files from the 3 most recent completed phases (what was built — reuse patterns, avoid duplication)
911
+ - LEARNINGS.md files from the 3 most recent completed phases (structured decisions, patterns, lessons, surprises — skip silently if a phase has no LEARNINGS.md; prefix each block with \`[from Phase N LEARNINGS]\` for source attribution; if total size exceeds 15% of context budget, drop oldest first)
912
+ - CONTEXT.md, SUMMARY.md, and LEARNINGS.md from any phases listed in the current phase's "Depends on:" field in ROADMAP.md (regardless of recency — explicit dependencies always load, deduplicated against the 3 most recent)
913
+ - Skip all other prior phases to stay within context budget
914
+ ` : ''}
915
+ </files_to_read>
916
+ ${API_SURFACE_PATH ? `
917
+ <intel_surface_hint>
918
+ **API Surface (HINT — may be incomplete):** When \`intel.enabled\` is true, \`.planning/intel/API-SURFACE.md\` lists symbols extracted from the codebase by regex/JS analysis. Prefer symbols listed there when referencing existing code. This surface is regex/JS-derived and MAY BE INCOMPLETE — a symbol's absence means *unknown*, not *nonexistent*. Never treat the surface as exhaustive. If you reference a symbol that is not in the surface and this phase creates it, list it under "Artifacts this phase produces".
919
+ </intel_surface_hint>
920
+ ` : ''}
921
+ ${AGENT_SKILLS_PLANNER}
922
+
923
+ **Phase requirement IDs (every ID MUST appear in a plan's `requirements` field):** {phase_req_ids}
924
+
925
+ **Project instructions:** Read ./CLAUDE.md if exists — follow project-specific guidelines
926
+ **Project skills:** Check .claude/skills/ or .agents/skills/ directory (if either exists) — read SKILL.md files, plans should account for project skill rules
927
+
928
+ ${TDD_MODE === 'true' ? `
929
+ <tdd_mode_active>
930
+ **TDD Mode is ENABLED.** Apply TDD heuristics from @~/.claude/gsd-core/references/tdd.md to all eligible tasks:
931
+ - Business logic with defined I/O → type: tdd
932
+ - API endpoints with request/response contracts → type: tdd
933
+ - Data transformations, validation, algorithms → type: tdd
934
+ - UI, config, glue code, CRUD → standard plan (type: execute)
935
+ Each TDD plan gets one feature with RED/GREEN/REFACTOR gate sequence.
936
+ </tdd_mode_active>
937
+ ` : ''}
938
+
939
+ **MVP_MODE:** ${MVP_MODE} (when true, follow vertical-slice rules from `~/.claude/gsd-core/references/planner-mvp-mode.md`; when false, ignore MVP guidance entirely.)
940
+ **WALKING_SKELETON:** ${WALKING_SKELETON} (when true, the first deliverable must be a Walking Skeleton — Read the template at `~/.claude/gsd-core/references/skeleton-template.md` and produce SKELETON.md alongside PLAN.md.)
941
+ **Granularity:** {granularity}
942
+
943
+ ${MVP_MODE === 'true' ? `
944
+ <mvp_mode_active>
945
+ **MVP Mode is ENABLED.** Read `~/.claude/gsd-core/references/planner-mvp-mode.md` now and follow its vertical-slice planning rules. Each plan must deliver a complete vertical slice — thin end-to-end functionality rather than horizontal layers.
946
+ </mvp_mode_active>
947
+ ` : ''}
948
+ </planning_context>
949
+
950
+ <downstream_consumer>
951
+ Output consumed by /gsd:execute-phase. Plans need:
952
+ - Frontmatter (wave, depends_on, files_modified, autonomous)
953
+ - Tasks in XML format with read_first and acceptance_criteria fields (MANDATORY on every task)
954
+ - Verification criteria
955
+ - must_haves for goal-backward verification
956
+ - **"Artifacts this phase produces" section (MANDATORY)** — list every symbol this phase creates: decorators, classes, functions, CLI flags, struct/dataclass fields, new file paths. The plan-review-convergence source-grounding pass reads this section to exclude newly-created symbols from drift verification; omitting it causes new symbols to be flagged for acknowledgement.
957
+ </downstream_consumer>
958
+
959
+ <deep_work_rules>
960
+ ## Anti-Shallow Execution Rules (MANDATORY)
961
+
962
+ Every task MUST include these fields — they are NOT optional:
963
+
964
+ 1. **`<read_first>`** — Files the executor MUST read before touching anything. Always include:
965
+ - The file being modified (so executor sees current state, not assumptions)
966
+ - Any "source of truth" file referenced in CONTEXT.md (reference implementations, existing patterns, config files, schemas)
967
+ - Any file whose patterns, signatures, types, or conventions must be replicated or respected
968
+
969
+ 2. **`<acceptance_criteria>`** — Verifiable conditions that prove the task was done correctly. Rules:
970
+ - Every criterion must be checkable as a source assertion, behavior assertion, test command, or CLI output
971
+ - NEVER use subjective language ("looks correct", "properly configured", "consistent with")
972
+ - Include exact strings, patterns, values, command outputs, or observable behavior where that is the right proof
973
+ - Examples:
974
+ - Code: `auth.py contains def verify_token(` / `test_auth.py exits 0`
975
+ - Behavior: `POST /api/auth/login returns 200 + httpOnly JWT cookie for valid credentials`
976
+ - Config: `.env.example contains DATABASE_URL=` / `Dockerfile contains HEALTHCHECK`
977
+ - Docs: `README.md contains '## Installation'` / `API.md lists all endpoints`
978
+ - Infra: `deploy.yml has rollback step` / `docker-compose.yml has healthcheck for db`
979
+
980
+ 3. **`<action>`** — Must include CONCRETE values, not references. Rules:
981
+ - NEVER say "align X with Y", "match X to Y", "update to be consistent" without specifying the exact target state
982
+ - Include concrete identifiers and reference values: config keys, function signatures, SQL table names, class names, import paths, env vars, endpoint paths, etc.
983
+ - If CONTEXT.md has a comparison table or expected values, copy only the target identifiers/values needed to remove ambiguity
984
+ - Do not include full file contents, fenced code blocks, or complete implementations in `<action>`
985
+ - The executor should understand the intended target state from `<action>` and use `<read_first>` files for current implementation details, patterns, and source-of-truth context
986
+
987
+ **Why this matters:** Executor agents work from the plan text. Vague instructions like "update the config to match production" produce shallow one-line changes. Concrete instructions like "add DATABASE_URL, set POOL_SIZE=20, add REDIS_URL, and read config/runtime.ts before editing" produce complete work without turning the planner into the executor.
988
+ </deep_work_rules>
989
+
990
+ <quality_gate>
991
+ - [ ] PLAN.md files created in phase directory
992
+ - [ ] Each plan has valid frontmatter
993
+ - [ ] Tasks are specific and actionable
994
+ - [ ] Every task has `<read_first>` with at least the file being modified
995
+ - [ ] Every task has `<acceptance_criteria>` with behavior, test-command, CLI, or source assertions
996
+ - [ ] Every `<action>` contains concrete identifiers without fenced code blocks or full implementations
997
+ - [ ] Dependencies correctly identified
998
+ - [ ] Waves assigned for parallel execution
999
+ - [ ] must_haves derived from phase goal
1000
+ - [ ] Every PLAN.md includes an "Artifacts this phase produces" section listing symbols created by this phase (decorators, classes, functions, CLI flags, struct/dataclass fields, new file paths)
1001
+ </quality_gate>
1002
+ ```
1003
+
1004
+ **If `CHUNKED_MODE` is `false` (default):** Spawn the planner as a single long-lived Agent:
1005
+
1006
+ ```text
1007
+ Agent(
1008
+ prompt=filled_prompt,
1009
+ subagent_type="gsd-planner",
1010
+ model="{planner_model}",
1011
+ description="Plan Phase {phase}"
1012
+ )
1013
+ ```
1014
+
1015
+ > **ORCHESTRATOR RULE — CODEX RUNTIME**: After calling Agent() above, stop working on this task immediately. Do not read more files, edit code, or run tests related to this task while the subagent is active. Wait for the subagent to return its result. This prevents duplicate work, conflicting edits, and wasted context. Only resume when the subagent result is available.
1016
+
1017
+ **If `CHUNKED_MODE` is `true`:** Skip the Agent() call above — proceed to step 8.5 instead.
1018
+
1019
+ ## 8.5. Chunked Planning Mode
1020
+
1021
+ **Skip if `CHUNKED_MODE` is `false`.**
1022
+
1023
+ Chunked mode splits the single long-lived planner Agent run into a short outline Agent run followed by
1024
+ N short per-plan Agent runs. Each run is bounded to ~3–5 min; each plan is committed individually
1025
+ for crash resilience. If any run hangs and the terminal is force-killed, rerunning
1026
+ `/gsd:plan-phase {N} --chunked` resumes from the last successfully committed plan.
1027
+
1028
+ **Intended for new or in-progress chunked runs.** To recover plans already written by a prior
1029
+ *non-chunked* run, use step 6's "Add more plans" or proceed directly to `/gsd:execute-phase`
1030
+ — don't start a fresh chunked run over existing non-chunked plans.
1031
+
1032
+ ### 8.5.1 Outline Phase (outline-only mode, ~2 min)
1033
+
1034
+ **Resume detection:** If `${PHASE_DIR}/${PADDED_PHASE}-PLAN-OUTLINE.md` already exists **and
1035
+ is valid** (contains the `## OUTLINE COMPLETE` marker), skip this sub-step — the outline
1036
+ already exists from a previous run. Proceed directly to 8.5.2.
1037
+
1038
+ ```bash
1039
+ OUTLINE_FILE="${PHASE_DIR}/${PADDED_PHASE}-PLAN-OUTLINE.md"
1040
+ if [[ -f "$OUTLINE_FILE" ]] && grep -q "^## OUTLINE COMPLETE" "$OUTLINE_FILE"; then
1041
+ # reuse existing outline — skip to 8.5.2
1042
+ fi
1043
+ ```
1044
+
1045
+ Display:
1046
+ ```text
1047
+ ◆ Chunked mode: spawning outline planner... (runs in a subagent — no output until it returns, ~1–5 min; expected, not a freeze)
1048
+ ```
1049
+
1050
+ Spawn the planner in **outline-only** mode — it must write only the outline manifest, not any
1051
+ PLAN.md files:
1052
+
1053
+ ```javascript
1054
+ Agent(
1055
+ prompt="{same planning_context as step 8, plus:}
1056
+
1057
+ **Chunked mode: outline-only.**
1058
+ Do NOT write any PLAN.md files in this Task.
1059
+ Write only: {PHASE_DIR}/{PADDED_PHASE}-PLAN-OUTLINE.md
1060
+
1061
+ The outline must be a markdown table with columns:
1062
+ Plan ID | Objective | Wave | Depends On | Requirements
1063
+
1064
+ Return: ## OUTLINE COMPLETE with plan count.",
1065
+ subagent_type="gsd-planner",
1066
+ model="{planner_model}",
1067
+ description="Outline Phase {phase} (chunked)"
1068
+ )
1069
+ ```
1070
+
1071
+ > **ORCHESTRATOR RULE — CODEX RUNTIME**: After calling Agent() above, stop working on this task immediately. Do not read more files, edit code, or run tests related to this task while the subagent is active. Wait for the subagent to return its result. This prevents duplicate work, conflicting edits, and wasted context. Only resume when the subagent result is available.
1072
+
1073
+ Handle return:
1074
+ - **`## OUTLINE COMPLETE`:** Read `PLAN-OUTLINE.md`, extract plan list. Continue to 8.5.2.
1075
+ - **Any other return or empty:** Display error. Offer: 1) Retry outline, 2) Stop.
1076
+
1077
+ ### 8.5.2 Per-Plan Tasks (single-plan mode, ~3-5 min each)
1078
+
1079
+ For each plan entry extracted from `PLAN-OUTLINE.md`:
1080
+
1081
+ 1. **Resume check:** If `${PHASE_DIR}/{plan_id}-PLAN.md` already exists on disk **and has
1082
+ valid YAML frontmatter** (opening `---` delimiter present), skip this plan (do not
1083
+ overwrite completed work — resume safety).
1084
+
1085
+ ```bash
1086
+ PLAN_FILE="${PHASE_DIR}/${plan_id}-PLAN.md"
1087
+ if [[ -f "$PLAN_FILE" ]] && head -1 "$PLAN_FILE" | grep -q '^---'; then
1088
+ continue # plan already written, skip
1089
+ fi
1090
+ ```
1091
+
1092
+ 2. Display:
1093
+ ```text
1094
+ ◆ Chunked mode: planning {plan_id} ({k}/{N})... (runs in a subagent — no output until it returns, ~1–5 min; expected, not a freeze)
1095
+ ```
1096
+
1097
+ 3. Spawn the planner in **single-plan** mode — it must write exactly one PLAN.md file:
1098
+ ```javascript
1099
+ Agent(
1100
+ prompt="{same planning_context as step 8, plus:}
1101
+
1102
+ **Chunked mode: single-plan.**
1103
+ Write exactly ONE plan file: {PHASE_DIR}/{plan_id}-PLAN.md
1104
+ Plan to write: {plan_id} — {objective}
1105
+ Wave: {wave} | Depends on: {depends_on}
1106
+ Phase requirement IDs to cover in this plan: {plan_requirements}
1107
+
1108
+ Return: ## PLAN COMPLETE with the plan ID.",
1109
+ subagent_type="gsd-planner",
1110
+ model="{planner_model}",
1111
+ description="Plan {plan_id} (chunked {k}/{N})"
1112
+ )
1113
+ ```
1114
+
1115
+ > **ORCHESTRATOR RULE — CODEX RUNTIME**: After calling Agent() above, stop working on this task immediately. Do not read more files, edit code, or run tests related to this task while the subagent is active. Wait for the subagent to return its result. This prevents duplicate work, conflicting edits, and wasted context. Only resume when the subagent result is available.
1116
+
1117
+ 4. **Verify disk:** Check `${PHASE_DIR}/{plan_id}-PLAN.md` exists. If missing: offer 1) Retry, 2) Stop.
1118
+
1119
+ 5. **Commit per-plan:**
1120
+ ```bash
1121
+ gsd_run query commit "docs(${PADDED_PHASE}): plan ${plan_id} (chunked)" --files "${PHASE_DIR}/${plan_id}-PLAN.md"
1122
+ ```
1123
+
1124
+ After all N plans are written and committed, treat this as `## PLANNING COMPLETE` and continue
1125
+ to step 9.
1126
+
1127
+ ## 9. Handle Planner Return
1128
+
1129
+ - **`## PLANNING COMPLETE`:** Display plan count. If `--skip-verify` or `plan_checker_enabled` is false (from init): skip to step 13. Otherwise: step 10.
1130
+ - **`## PHASE SPLIT RECOMMENDED`:** The planner determined the phase exceeds the context budget for full-fidelity implementation of all source items. Handle in step 9b.
1131
+ - **`## ⚠ Source Audit: Unplanned Items Found`:** The planner's multi-source coverage audit found items from REQUIREMENTS.md, RESEARCH.md, ROADMAP goal, or CONTEXT.md decisions that are not covered by any plan. Handle in step 9c.
1132
+ - **`## CHECKPOINT REACHED`:** Present to user, get response, spawn continuation (step 12)
1133
+ - **`## PLANNING INCONCLUSIVE`:** Show attempts, offer: Add context / Retry / Manual
1134
+ - **Empty / truncated / no recognized marker:** → Filesystem fallback (step 9a).
1135
+
1136
+ ## 9a. Filesystem Fallback (Planner)
1137
+
1138
+ **Triggered when:** Agent() returns but the return contains no recognized marker (`## PLANNING COMPLETE`, `## PHASE SPLIT RECOMMENDED`, `## ⚠ Source Audit`, `## CHECKPOINT REACHED`, `## PLANNING INCONCLUSIVE`).
1139
+
1140
+ ```bash
1141
+ DISK_PLANS=$(ls "${PHASE_DIR}"/*-PLAN.md 2>/dev/null | wc -l | tr -d ' ')
1142
+ ```
1143
+
1144
+ **If `DISK_PLANS` > 0:** The planner wrote plans to disk but the Agent() return was empty or
1145
+ truncated (the Windows stdio hang pattern — the subagent finished but the return never
1146
+ arrived). Display:
1147
+
1148
+ ```text
1149
+ ◆ Planner wrote {DISK_PLANS} plan(s) to disk but did not emit a PLANNING COMPLETE marker.
1150
+ This is a known Windows stdio hang pattern — work is likely recoverable.
1151
+
1152
+ Plans found on disk:
1153
+ {ls output of *-PLAN.md}
1154
+ ```
1155
+
1156
+ Offer 3 options:
1157
+ 1. **Accept plans** — treat as `## PLANNING COMPLETE` and continue through step 9 `## PLANNING COMPLETE` handling (so `--skip-verify` / `plan_checker_enabled=false` are honored — may skip to step 13 rather than step 10)
1158
+ 2. **Retry planner** — re-spawn the planner with the same prompt (return to step 8)
1159
+ 3. **Stop** — exit; user can re-run `/gsd:plan-phase {N}` to resume
1160
+
1161
+ **If `DISK_PLANS` is 0 and no marker:** The planner produced no output. Treat as
1162
+ `## PLANNING INCONCLUSIVE` and handle accordingly.
1163
+
1164
+ ## 9b. Handle Phase Split Recommendation
1165
+
1166
+ When the planner returns `## PHASE SPLIT RECOMMENDED`, it means the phase's source items exceed the context budget for full-fidelity implementation. The planner proposes groupings.
1167
+
1168
+ **Extract from planner return:**
1169
+ - Proposed sub-phases (e.g., "17a: processing core (D-01 to D-19)", "17b: billing + config UX (D-20 to D-27)")
1170
+ - Which source items (REQ-IDs, D-XX decisions, RESEARCH items) go in each sub-phase
1171
+ - Why the split is necessary (context cost estimate, file count)
1172
+
1173
+ **Present to user:**
1174
+ ```
1175
+ ## Phase {X} exceeds context budget for full-fidelity implementation
1176
+
1177
+ The planner found {N} source items that exceed the context budget when
1178
+ planned at full fidelity. Instead of reducing scope, we recommend splitting:
1179
+
1180
+ **Option 1: Split into sub-phases**
1181
+ - Phase {X}a: {name} — {items} ({N} source items, ~{P}% context)
1182
+ - Phase {X}b: {name} — {items} ({M} source items, ~{Q}% context)
1183
+
1184
+ **Option 2: Proceed anyway** (planner will attempt all, quality may degrade past 50% context)
1185
+
1186
+ **Option 3: Prioritize** — you choose which items to implement now,
1187
+ rest become a follow-up phase
1188
+ ```
1189
+
1190
+ Use AskUserQuestion with these 3 options.
1191
+
1192
+ **If "Split":** Use `/gsd:phase --insert` to create the sub-phases, then replan each.
1193
+ **If "Proceed":** Return to planner with instruction to attempt all items at full fidelity, accepting more plans/tasks.
1194
+ **If "Prioritize":** Use AskUserQuestion (multiSelect) to let user pick which items are "now" vs "later". Create CONTEXT.md for each sub-phase with the selected items.
1195
+
1196
+ ## 9c. Handle Source Audit Gaps
1197
+
1198
+ When the planner returns `## ⚠ Source Audit: Unplanned Items Found`, it means items from REQUIREMENTS.md, RESEARCH.md, ROADMAP goal, or CONTEXT.md decisions have no corresponding plan.
1199
+
1200
+ **Extract from planner return:**
1201
+ - Each unplanned item with its source artifact and section
1202
+ - The planner's suggested options (A: add plan, B: split phase, C: defer with confirmation)
1203
+
1204
+ **Present each gap to user.** For each unplanned item:
1205
+
1206
+ ```
1207
+ ## ⚠ Unplanned: {item description}
1208
+
1209
+ Source: {RESEARCH.md / REQUIREMENTS.md / ROADMAP goal / CONTEXT.md}
1210
+ Details: {why the planner flagged this}
1211
+
1212
+ Options:
1213
+ 1. Add a plan to cover this item (recommended)
1214
+ 2. Split phase — move to a sub-phase with related items
1215
+ 3. Defer — add to backlog (developer confirms this is intentional)
1216
+ ```
1217
+
1218
+ Use AskUserQuestion for each gap (or batch if multiple gaps).
1219
+
1220
+ **If "Add plan":** Return to planner (step 8) with instruction to add plans covering the missing items, preserving existing plans.
1221
+ **If "Split":** Use `/gsd:phase --insert` for overflow items, then replan.
1222
+ **If "Defer":** Record in CONTEXT.md `## Deferred Ideas` with developer's confirmation. Proceed to step 10.
1223
+
1224
+ ## 10. Spawn gsd-plan-checker Agent
1225
+
1226
+ Display banner:
1227
+ ```
1228
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1229
+ GSD ► VERIFYING PLANS
1230
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1231
+
1232
+ ◆ Spawning plan checker... (runs in a subagent — no output until it returns, ~1–5 min; expected, not a freeze)
1233
+ ```
1234
+
1235
+ Checker prompt:
1236
+
1237
+ ```markdown
1238
+ <verification_context>
1239
+ **Phase:** {phase_number}
1240
+ **Phase Goal:** {goal from ROADMAP}
1241
+
1242
+ <files_to_read>
1243
+ - {PHASE_DIR}/*-PLAN.md (Plans to verify)
1244
+ - {roadmap_path} (Roadmap)
1245
+ - {requirements_path} (Requirements)
1246
+ - {context_path} (USER DECISIONS from /gsd:discuss-phase)
1247
+ - {research_path} (Technical Research — includes Validation Architecture)
1248
+ </files_to_read>
1249
+
1250
+ ${AGENT_SKILLS_CHECKER}
1251
+
1252
+ **Phase requirement IDs (MUST ALL be covered):** {phase_req_ids}
1253
+
1254
+ **Project instructions:** Read ./CLAUDE.md if exists — verify plans honor project guidelines
1255
+ **Project skills:** Check .claude/skills/ or .agents/skills/ directory (if either exists) — verify plans account for project skill rules
1256
+ </verification_context>
1257
+
1258
+ <expected_output>
1259
+ - ## VERIFICATION PASSED — all checks pass
1260
+ - ## ISSUES FOUND — structured issue list
1261
+ </expected_output>
1262
+ ```
1263
+
1264
+ ```
1265
+ Agent(
1266
+ prompt=checker_prompt,
1267
+ subagent_type="gsd-plan-checker",
1268
+ model="{checker_model}",
1269
+ description="Verify Phase {phase} plans"
1270
+ )
1271
+ ```
1272
+
1273
+ > **ORCHESTRATOR RULE — CODEX RUNTIME**: After calling Agent() above, stop working on this task immediately. Do not read more files, edit code, or run tests related to this task while the subagent is active. Wait for the subagent to return its result. This prevents duplicate work, conflicting edits, and wasted context. Only resume when the subagent result is available.
1274
+
1275
+ ## 11. Handle Checker Return
1276
+
1277
+ - **`## VERIFICATION PASSED`:** Display confirmation, proceed to step 13.
1278
+ - **`## ISSUES FOUND`:** Display issues, check iteration count, proceed to step 12.
1279
+ - **Empty / truncated / no recognized marker:** → Filesystem fallback (step 11a).
1280
+
1281
+ **Thinking partner for architectural tradeoffs (conditional):**
1282
+ If `features.thinking_partner` is enabled, scan the checker's issues for architectural tradeoff keywords
1283
+ ("architecture", "approach", "strategy", "pattern", "vs", "alternative"). If found:
1284
+
1285
+ ```
1286
+ The plan-checker flagged an architectural decision point:
1287
+ {issue description}
1288
+
1289
+ Brief analysis:
1290
+ - Option A: {approach_from_plan} — {pros/cons}
1291
+ - Option B: {alternative_approach} — {pros/cons}
1292
+ - Recommendation: {choice} aligned with {phase_goal}
1293
+
1294
+ Apply this to the revision? [Yes] / [No, I'll decide]
1295
+ ```
1296
+
1297
+ If yes: include the recommendation in the revision prompt. If no: proceed to revision loop as normal.
1298
+ If thinking_partner disabled: skip this block entirely.
1299
+
1300
+ ## 11a. Filesystem Fallback (Checker)
1301
+
1302
+ **Triggered when:** Checker Agent() returns but the return contains neither `## VERIFICATION PASSED` nor `## ISSUES FOUND`.
1303
+
1304
+ ```bash
1305
+ DISK_PLANS=$(ls "${PHASE_DIR}"/*-PLAN.md 2>/dev/null | wc -l | tr -d ' ')
1306
+ ```
1307
+
1308
+ **If `DISK_PLANS` > 0:** Plans exist on disk; the checker return was empty or truncated (the
1309
+ Windows stdio hang pattern — the subagent finished but the return never arrived). Display:
1310
+
1311
+ ```text
1312
+ ◆ Checker return was empty or truncated. {DISK_PLANS} plan(s) exist on disk.
1313
+ This is a known Windows stdio hang pattern — checker may have completed without returning.
1314
+ ```
1315
+
1316
+ Offer 3 options:
1317
+ 1. **Accept verification** — treat as `## VERIFICATION PASSED` and continue to step 13
1318
+ 2. **Retry checker** — re-spawn the checker with the same prompt (return to step 10)
1319
+ 3. **Stop** — exit; user can re-run `/gsd:plan-phase {N}` to resume
1320
+
1321
+ **If `DISK_PLANS` is 0:** No plans on disk — something is seriously wrong. Display error and stop.
1322
+
1323
+ ## 12. Revision Loop (Max 3 Iterations)
1324
+
1325
+ Track `iteration_count` (starts at 1 after initial plan + check).
1326
+ Track `prev_issue_count` (initialized to `Infinity` before the loop begins).
1327
+ Track `stall_reentry_count` (starts at 0; incremented each time "Adjust approach" re-enters step 8).
1328
+
1329
+ **If iteration_count < 3:**
1330
+
1331
+ Parse issue count from checker return: count BLOCKER + WARNING entries in the YAML issues block (structured output from gsd-plan-checker). If the checker's return contains no YAML issues block (i.e., the plan was approved with no issues), treat `issue_count` as 0 and skip the stall check — the plan passed. Proceed to step 13.
1332
+
1333
+ Display: `Revision iteration {N}/3 -- {blocker_count} blockers, {warning_count} warnings`
1334
+
1335
+ **Stall detection:** If `issue_count >= prev_issue_count`:
1336
+ Display: `Revision loop stalled — issue count not decreasing ({issue_count} issues remain after {N} iterations)`
1337
+
1338
+ **If `stall_reentry_count < 2`:**
1339
+ Ask user:
1340
+ Question: "Issues remain after {N} revision attempts with no progress. Proceed with current output?"
1341
+ Options: "Proceed anyway" | "Adjust approach"
1342
+ If "Proceed anyway": accept current plans and continue to step 13.
1343
+ If "Adjust approach": increment `stall_reentry_count`, open freeform discussion, then re-enter step 8 (full replanning). Note: re-entry resets `iteration_count` and `prev_issue_count` but `stall_reentry_count` persists across re-entries and is capped at 2.
1344
+
1345
+ **If `stall_reentry_count >= 2`:**
1346
+ Display: `Stall persists after 2 re-planning attempts. The following issues could not be resolved automatically:`
1347
+ List the remaining issues from the checker.
1348
+ Suggest: "Consider resolving these issues manually or running `/gsd:debug` to investigate root causes."
1349
+ Options: "Proceed anyway" | "Abandon"
1350
+ If "Proceed anyway": accept current plans and continue to step 13.
1351
+ If "Abandon": stop workflow.
1352
+
1353
+ Set `prev_issue_count = issue_count`.
1354
+
1355
+ Revision prompt:
1356
+
1357
+ ```markdown
1358
+ <revision_context>
1359
+ **Phase:** {phase_number}
1360
+ **Mode:** revision
1361
+
1362
+ <files_to_read>
1363
+ - {PHASE_DIR}/*-PLAN.md (Existing plans)
1364
+ - {context_path} (USER DECISIONS from /gsd:discuss-phase)
1365
+ </files_to_read>
1366
+
1367
+ ${AGENT_SKILLS_PLANNER}
1368
+
1369
+ **Checker issues:** {structured_issues_from_checker}
1370
+ </revision_context>
1371
+
1372
+ <instructions>
1373
+ Make targeted updates to address checker issues.
1374
+ Do NOT replan from scratch unless issues are fundamental.
1375
+ Return what changed.
1376
+ </instructions>
1377
+ ```
1378
+
1379
+ ```
1380
+ Agent(
1381
+ prompt=revision_prompt,
1382
+ subagent_type="gsd-planner",
1383
+ model="{planner_model}",
1384
+ description="Revise Phase {phase} plans"
1385
+ )
1386
+ ```
1387
+
1388
+ > **ORCHESTRATOR RULE — CODEX RUNTIME**: After calling Agent() above, stop working on this task immediately. Do not read more files, edit code, or run tests related to this task while the subagent is active. Wait for the subagent to return its result. This prevents duplicate work, conflicting edits, and wasted context. Only resume when the subagent result is available.
1389
+
1390
+ After planner returns -> spawn checker again (step 10), increment iteration_count.
1391
+
1392
+ **If iteration_count >= 3:**
1393
+
1394
+ Display: `Max iterations reached. {N} issues remain:` + issue list
1395
+
1396
+ Offer: 1) Force proceed, 2) Provide guidance and retry, 3) Abandon
1397
+
1398
+ ## 12.5. Plan Bounce (Optional External Refinement)
1399
+
1400
+ **Skip if:** `--skip-bounce` flag, `--gaps` flag, or bounce is not activated.
1401
+
1402
+ **Activation:** Bounce runs when `--bounce` flag is present OR `workflow.plan_bounce` config is `true`. The `--skip-bounce` flag always wins (disables bounce even if config enables it). The `--gaps` flag also disables bounce (gap-closure mode should not modify plans externally).
1403
+
1404
+ **Prerequisites:** `workflow.plan_bounce_script` must be set to a valid script path. If bounce is activated but no script is configured, display warning and skip:
1405
+ ```
1406
+ ⚠ Plan bounce activated but no script configured.
1407
+ Set workflow.plan_bounce_script to the path of your refinement script.
1408
+ Skipping bounce step.
1409
+ ```
1410
+
1411
+ **Read pass count:**
1412
+ ```bash
1413
+ BOUNCE_PASSES=$(gsd_run query config-get workflow.plan_bounce_passes 2>/dev/null || echo "2")
1414
+ BOUNCE_SCRIPT=$(gsd_run query config-get workflow.plan_bounce_script 2>/dev/null | jq -r '.' 2>/dev/null || true)
1415
+ ```
1416
+
1417
+ Display banner:
1418
+ ```
1419
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1420
+ GSD ► BOUNCING PLANS (External Refinement)
1421
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1422
+
1423
+ Script: ${BOUNCE_SCRIPT}
1424
+ Max passes: ${BOUNCE_PASSES}
1425
+ ```
1426
+
1427
+ **For each PLAN.md file in the phase directory:**
1428
+
1429
+ 1. **Backup:** Copy `*-PLAN.md` to `*-PLAN.pre-bounce.md`
1430
+ ```bash
1431
+ cp "${PLAN_FILE}" "${PLAN_FILE%.md}.pre-bounce.md"
1432
+ ```
1433
+
1434
+ 2. **Invoke bounce script:**
1435
+ ```bash
1436
+ "${BOUNCE_SCRIPT}" "${PLAN_FILE}" "${BOUNCE_PASSES}"
1437
+ ```
1438
+
1439
+ 3. **Validate bounced plan — YAML frontmatter integrity:**
1440
+ After the script returns, check that the bounced file still has valid YAML frontmatter (opening and closing `---` delimiters with parseable content between them). If the bounced plan breaks YAML frontmatter validation, restore the original from the pre-bounce.md backup and continue to the next plan:
1441
+ ```
1442
+ ⚠ Bounced plan ${PLAN_FILE} has broken YAML frontmatter — restoring original from pre-bounce backup.
1443
+ ```
1444
+
1445
+ 4. **Handle script failure:** If the bounce script exits non-zero, restore the original plan from the pre-bounce.md backup and continue to the next plan:
1446
+ ```
1447
+ ⚠ Bounce script failed for ${PLAN_FILE} (exit code ${EXIT_CODE}) — restoring original from pre-bounce backup.
1448
+ ```
1449
+
1450
+ **After all plans are bounced:**
1451
+
1452
+ 5. **Re-run plan checker on bounced plans:** Spawn gsd-plan-checker (same as step 10) on all modified plans. If a bounced plan fails the checker, restore original from its pre-bounce.md backup:
1453
+ ```
1454
+ ⚠ Bounced plan ${PLAN_FILE} failed checker validation — restoring original from pre-bounce backup.
1455
+ ```
1456
+
1457
+ 6. **Commit surviving bounced plans:** If at least one plan survived both the frontmatter validation and the checker re-run, commit the changes:
1458
+ ```bash
1459
+ gsd_run query commit "refactor(${padded_phase}): bounce plans through external refinement" --files "${PHASE_DIR}/*-PLAN.md"
1460
+ ```
1461
+
1462
+ Display summary:
1463
+ ```
1464
+ Plan bounce complete: {survived}/{total} plans refined
1465
+ ```
1466
+
1467
+ **Clean up:** Remove all `*-PLAN.pre-bounce.md` backup files after the bounce step completes (whether plans survived or were restored).
1468
+
1469
+ ## 13. Requirements Coverage Gate
1470
+
1471
+ After plans pass the checker (or checker is skipped), verify that all phase requirements are covered by at least one plan.
1472
+
1473
+ **Skip if:** `phase_req_ids` is null or TBD (no requirements mapped to this phase).
1474
+
1475
+ **Step 1: Extract requirement IDs claimed by plans**
1476
+ ```bash
1477
+ # Collect all requirement IDs from plan frontmatter
1478
+ PLAN_REQS=$(grep -h "requirements_addressed\|requirements:" ${PHASE_DIR}/*-PLAN.md 2>/dev/null | tr -d '[]' | tr ',' '\n' | sed 's/^[[:space:]]*//' | sort -u)
1479
+ ```
1480
+
1481
+ **Step 2: Compare against phase requirements from ROADMAP**
1482
+
1483
+ For each REQ-ID in `phase_req_ids`:
1484
+ - If REQ-ID appears in `PLAN_REQS` → covered ✓
1485
+ - If REQ-ID does NOT appear in any plan → uncovered ✗
1486
+
1487
+ **Step 3: Check CONTEXT.md features against plan objectives**
1488
+
1489
+ Read CONTEXT.md `<decisions>` section. Extract feature/capability names. Check each against plan `<objective>` blocks. Features not mentioned in any plan objective → potentially dropped.
1490
+
1491
+ **Step 4: Report**
1492
+
1493
+ If all requirements covered and no dropped features:
1494
+ ```
1495
+ ✓ Requirements coverage: {N}/{N} REQ-IDs covered by plans
1496
+ ```
1497
+ → Proceed to step 14.
1498
+
1499
+ If gaps found:
1500
+ ```
1501
+ ## ⚠ Requirements Coverage Gap
1502
+
1503
+ {M} of {N} phase requirements are not assigned to any plan:
1504
+
1505
+ | REQ-ID | Description | Plans |
1506
+ |--------|-------------|-------|
1507
+ | {id} | {from REQUIREMENTS.md} | None |
1508
+
1509
+ {K} CONTEXT.md features not found in plan objectives:
1510
+ - {feature_name} — described in CONTEXT.md but no plan covers it
1511
+
1512
+ Options:
1513
+ 1. Re-plan to include missing requirements (recommended)
1514
+ 2. Move uncovered requirements to next phase
1515
+ 3. Proceed anyway — accept coverage gaps
1516
+ ```
1517
+
1518
+ If `TEXT_MODE` is true, present as a plain-text numbered list (options already shown in the block above). Otherwise use AskUserQuestion to present the options.
1519
+
1520
+ ## 13a. Decision Coverage Gate
1521
+
1522
+ After the requirements coverage gate passes, verify that every trackable
1523
+ decision captured by discuss-phase in CONTEXT.md `<decisions>` is referenced
1524
+ by at least one plan. This is the **translation gate** from issue #2492 —
1525
+ its job is to refuse to mark a phase planned when a discuss-phase decision
1526
+ silently dropped on the way into the plans.
1527
+
1528
+ **Skip if** `workflow.context_coverage_gate` is explicitly set to `false`
1529
+ (absent key = enabled). Also skip if no CONTEXT.md exists for this phase
1530
+ (nothing to translate) or if its `<decisions>` block is empty.
1531
+
1532
+ ```bash
1533
+ GATE_CFG=$(gsd_run query config-get workflow.context_coverage_gate 2>/dev/null || echo "true")
1534
+ if [ "$GATE_CFG" != "false" ]; then
1535
+ GATE_RESULT=$(gsd_run query check.decision-coverage-plan "${PHASE_DIR}" "${CONTEXT_PATH}")
1536
+ # BLOCKING: refuse to mark phase planned when a trackable decision is uncovered.
1537
+ # `passed: true` covers both real-pass and skipped cases (gate disabled / no CONTEXT.md /
1538
+ # no trackable decisions). Verify-phase counterpart deliberately omits this exit-1 — that
1539
+ # gate is non-blocking by design (review finding F15).
1540
+ echo "$GATE_RESULT" | jq -e '(.passed // .data.passed) == true' >/dev/null || {
1541
+ echo "$GATE_RESULT" | jq -r '(.message // .data.message // "Decision coverage gate failed.")'
1542
+ exit 1
1543
+ }
1544
+ fi
1545
+ ```
1546
+
1547
+ The handler returns JSON:
1548
+ ```json
1549
+ {
1550
+ "passed": true,
1551
+ "skipped": false,
1552
+ "total": 2,
1553
+ "covered": 2,
1554
+ "uncovered": [ { "id": "D-01", "text": "...", "category": "..." } ],
1555
+ "message": "..."
1556
+ }
1557
+ ```
1558
+
1559
+ **If `passed` is true (or `skipped` is true):** Display
1560
+ `✓ Decision coverage: {M}/{N} CONTEXT.md decisions covered by plans` (or
1561
+ `(skipped — gate disabled)` / `(skipped — no decisions)`) and proceed to
1562
+ step 13b.
1563
+
1564
+ **If `passed` is false:** Display the handler's `message` block. It already
1565
+ names each uncovered decision (`D-NN | category | text`) and tells the user
1566
+ what to do — cite the id in a relevant plan's `must_haves` / `truths`, or
1567
+ move the decision under `### Claude's Discretion` / tag it `[informational]`
1568
+ if it should not be tracked. Then offer:
1569
+
1570
+ ```text
1571
+ Options:
1572
+ 1. Re-plan to cover missing decisions (recommended)
1573
+ 2. Edit CONTEXT.md to mark dropped decisions as [informational] / Discretion
1574
+ 3. Proceed anyway — accept the coverage gap
1575
+ ```
1576
+
1577
+ If `TEXT_MODE` is true, present as a plain-text numbered list. Otherwise use
1578
+ AskUserQuestion. Selecting "Proceed anyway" continues to step 13b but
1579
+ records the override in STATE.md so verify-phase can re-surface it.
1580
+
1581
+ **Why this gate blocks:** failing here is cheap. The plans are the contract
1582
+ between discuss-phase and execute-phase; if a decision isn't visible in any
1583
+ plan, no executor will implement it. Catching that now beats discovering it
1584
+ after thousands of dollars of execution.
1585
+
1586
+ ## 13b. Record Planning Completion in STATE.md
1587
+
1588
+ After plans pass all gates, record that planning is complete so STATE.md reflects the new phase status:
1589
+
1590
+ ```bash
1591
+ gsd_run query state.planned-phase --phase "${PHASE_NUMBER}" --name "${PHASE_NAME}" --plans "${PLAN_COUNT}"
1592
+ ```
1593
+
1594
+ This updates STATUS to "Ready to execute", sets the correct plan count, and timestamps Last Activity.
1595
+
1596
+ ## 13c. Annotate ROADMAP with Wave Dependencies and Cross-cutting Constraints
1597
+
1598
+ After plans are finalized, annotate the ROADMAP.md plan list for this phase with:
1599
+ - **Wave dependency notes** — a bold header before each wave group ("Wave 2 *(blocked on Wave 1 completion)*")
1600
+ - **Cross-cutting constraints** — a "Cross-cutting constraints:" subsection listing `must_haves.truths` entries that appear in 2 or more plans
1601
+
1602
+ This step is derived entirely from existing PLAN frontmatter — no extra LLM pass is required.
1603
+
1604
+ ```bash
1605
+ gsd_run query roadmap.annotate-dependencies "${PHASE_NUMBER}"
1606
+ ```
1607
+
1608
+ This operation is idempotent: if wave headers or cross-cutting constraints already exist in the ROADMAP phase section, the command returns without modifying the file. Skip this step if `plan_count` is 0.
1609
+
1610
+ ## 13d. Commit Plans if commit_docs is true
1611
+
1612
+ If `commit_docs` is true (from the init JSON parsed in step 1), commit the generated plan artifacts (including any ROADMAP.md annotations from step 13c):
1613
+
1614
+ ```bash
1615
+ gsd_run query commit "docs(${PADDED_PHASE}): create phase plan" --files "${PHASE_DIR}"/*-PLAN.md .planning/STATE.md .planning/ROADMAP.md
1616
+ ```
1617
+
1618
+ This commits all PLAN.md files for the phase plus the updated STATE.md and ROADMAP.md to version-control the planning artifacts. Skip this step if `commit_docs` is false.
1619
+
1620
+ ## 13e. Post-Planning Gap Analysis
1621
+
1622
+ After all plans are generated, committed, and the Requirements Coverage Gate (§13)
1623
+ has run, emit a single unified gap report covering both REQUIREMENTS.md and the
1624
+ CONTEXT.md `<decisions>` section. This is a **proactive, post-hoc report** — it
1625
+ does not block phase advancement and does not re-plan. It exists so that any
1626
+ requirement or decision that slipped through the per-plan checks is surfaced in
1627
+ one place before execution begins.
1628
+
1629
+ **Skip if:** `workflow.post_planning_gaps` is `false`. Default is `true`.
1630
+
1631
+ ```bash
1632
+ POST_PLANNING_GAPS=$(gsd_run query config-get workflow.post_planning_gaps --default true 2>/dev/null || echo true)
1633
+ if [ "$POST_PLANNING_GAPS" = "true" ]; then
1634
+ # Scope to this phase's mapped REQ-IDs (#447); null/TBD skips the requirements comparison (CONTEXT.md decisions still reported), mirroring §13.
1635
+ gsd_run gap-analysis --phase-dir "${PHASE_DIR}" --phase-req-ids "$(gsd_run query init.plan-phase "$PHASE" --pick phase_req_ids 2>/dev/null || echo TBD)"
1636
+ fi
1637
+ ```
1638
+
1639
+ (`gsd-tools.cjs gap-analysis` reads `.planning/REQUIREMENTS.md`, `${PHASE_DIR}/CONTEXT.md`,
1640
+ and `${PHASE_DIR}/*-PLAN.md`, then prints a markdown table with one row per
1641
+ REQ-ID and D-ID. Word-boundary matching prevents `REQ-1` from being mistaken for
1642
+ `REQ-10`.)
1643
+
1644
+ **Output format (deterministic; sorted REQUIREMENTS.md → CONTEXT.md, then natural
1645
+ sort within source):**
1646
+
1647
+ ```
1648
+ ## Post-Planning Gap Analysis
1649
+
1650
+ | Source | Item | Status |
1651
+ |--------|------|--------|
1652
+ | REQUIREMENTS.md | REQ-01 | ✓ Covered |
1653
+ | REQUIREMENTS.md | REQ-02 | ✗ Not covered |
1654
+ | CONTEXT.md | D-01 | ✓ Covered |
1655
+ | CONTEXT.md | D-02 | ✗ Not covered |
1656
+
1657
+ ⚠ N items not covered by any plan
1658
+ ```
1659
+
1660
+ **Skip-gracefully behavior:**
1661
+ - REQUIREMENTS.md missing → CONTEXT-only report.
1662
+ - CONTEXT.md missing → REQUIREMENTS-only report.
1663
+ - Both missing or `<decisions>` block missing → "No requirements or decisions to check" line, no error.
1664
+
1665
+ This step is non-blocking. If items are reported as not covered, the user may
1666
+ re-run `/gsd:plan-phase --gaps` to add plans, or proceed to execute-phase as-is.
1667
+
1668
+ ## 14. Present Final Status
1669
+
1670
+ Route to `<offer_next>` OR `auto_advance` depending on flags/config.
1671
+
1672
+ ## 15. Auto-Advance Check
1673
+
1674
+ Check for auto-advance trigger using values already loaded in step 1:
1675
+
1676
+ 1. Parse `--auto` and `--chain` flags from $ARGUMENTS
1677
+ 2. Use `auto_chain_active` and `auto_advance` from the INIT JSON parsed in step 1 — **do not issue additional `config-get` calls for these values** (they are already present in the init output). Issuing redundant `config-get` calls for values already in INIT can cause infinite read loops on some runtimes.
1678
+ 3. **Sync chain flag with intent** — if user invoked manually (no `--auto` and no `--chain`), clear the ephemeral chain flag from any previous interrupted `--auto` chain. This does NOT touch `workflow.auto_advance` (the user's persistent settings preference):
1679
+ ```bash
1680
+ if [[ ! "$ARGUMENTS" =~ --auto ]] && [[ ! "$ARGUMENTS" =~ --chain ]]; then
1681
+ gsd_run query config-set workflow._auto_chain_active false || true
1682
+ fi
1683
+ ```
1684
+
1685
+ Set local variables from INIT (parsed once in step 1):
1686
+ - `AUTO_CHAIN` = `auto_chain_active` from INIT JSON (boolean, default false)
1687
+ - `AUTO_CFG` = `auto_advance` from INIT JSON (boolean, default false)
1688
+
1689
+ **If `--auto` or `--chain` flag present AND `AUTO_CHAIN` is not true:** Persist chain flag to config (handles direct invocation without prior discuss-phase):
1690
+ ```bash
1691
+ if ([[ "$ARGUMENTS" =~ --auto ]] || [[ "$ARGUMENTS" =~ --chain ]]) && [[ "$AUTO_CHAIN" != "true" ]]; then
1692
+ gsd_run query config-set workflow._auto_chain_active true
1693
+ fi
1694
+ ```
1695
+
1696
+ **If `--auto` or `--chain` flag present OR `AUTO_CHAIN` is true OR `AUTO_CFG` is true:**
1697
+
1698
+ Display banner:
1699
+ ```
1700
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1701
+ GSD ► AUTO-ADVANCING TO EXECUTE
1702
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1703
+
1704
+ Plans ready. Launching execute-phase...
1705
+ ```
1706
+
1707
+ Launch execute-phase using the Skill tool to avoid nested Task sessions (which cause runtime freezes due to deep agent nesting):
1708
+ ```
1709
+ Skill(skill="gsd-execute-phase", args="${PHASE} --auto --no-transition ${GSD_WS}")
1710
+ ```
1711
+
1712
+ The `--no-transition` flag tells execute-phase to return status after verification instead of chaining further. This keeps the auto-advance chain flat — each phase runs at the same nesting level rather than spawning deeper Task agents.
1713
+
1714
+ **Handle execute-phase return:**
1715
+ - **PHASE COMPLETE** → Display final summary:
1716
+ ```
1717
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1718
+ GSD ► PHASE ${PHASE} COMPLETE ✓
1719
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1720
+
1721
+ Auto-advance pipeline finished.
1722
+
1723
+ Next: /gsd:discuss-phase ${NEXT_PHASE} --auto ${GSD_WS}
1724
+ ```
1725
+ - **GAPS FOUND / VERIFICATION FAILED** → Display result, stop chain:
1726
+ ```
1727
+ Auto-advance stopped: Execution needs review.
1728
+
1729
+ Review the output above and continue manually:
1730
+ /gsd:execute-phase ${PHASE} ${GSD_WS}
1731
+ ```
1732
+
1733
+ **If neither `--auto` nor config enabled:**
1734
+ Route to `<offer_next>` (existing behavior).
1735
+
1736
+ </process>
1737
+
1738
+ <offer_next>
1739
+ Output this markdown directly (not as a code block):
1740
+
1741
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1742
+ GSD ► PHASE {X} PLANNED ✓
1743
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1744
+
1745
+ **Phase {X}: {Name}** — {N} plan(s) in {M} wave(s)
1746
+
1747
+ | Wave | Plans | What it builds |
1748
+ |------|-------|----------------|
1749
+ | 1 | 01, 02 | [objectives] |
1750
+ | 2 | 03 | [objective] |
1751
+
1752
+ Research: {Completed | Used existing | Skipped}
1753
+ Verification: {Passed | Passed with override | Skipped}
1754
+
1755
+ ───────────────────────────────────────────────────────────────
1756
+
1757
+ ## ▶ Next Up — [${PROJECT_CODE}] ${PROJECT_TITLE}
1758
+
1759
+ **Execute Phase {X}** — run all {N} plans
1760
+
1761
+ /clear then:
1762
+
1763
+ /gsd:execute-phase {X} ${GSD_WS}
1764
+
1765
+ ───────────────────────────────────────────────────────────────
1766
+
1767
+ **Also available:**
1768
+ - cat .planning/phases/{phase-dir}/*-PLAN.md — review plans
1769
+ - /gsd:plan-phase {X} --research — re-research first
1770
+ - /gsd:review --phase {X} --all — peer review plans with external AIs
1771
+ - /gsd:plan-phase {X} --reviews — replan incorporating review feedback
1772
+
1773
+ ───────────────────────────────────────────────────────────────
1774
+ </offer_next>
1775
+
1776
+ <windows_troubleshooting>
1777
+ **Windows users:** If plan-phase freezes during agent spawning (common on Windows due to
1778
+ stdio deadlocks with MCP servers — see Claude Code issue anthropics/claude-code#28126):
1779
+
1780
+ 1. **Force-kill:** Close the terminal (Ctrl+C may not work)
1781
+ 2. **Clean up orphaned processes:**
1782
+ ```powershell
1783
+ # Kill orphaned node processes from stale MCP servers
1784
+ Get-Process node -ErrorAction SilentlyContinue | Where-Object {$_.StartTime -lt (Get-Date).AddHours(-1)} | Stop-Process -Force
1785
+ ```
1786
+ 3. **Clean up stale task directories:**
1787
+ ```powershell
1788
+ # Remove stale subagent task dirs (Claude Code never cleans these on crash)
1789
+ Remove-Item -Recurse -Force "$env:USERPROFILE\.claude\tasks\*" -ErrorAction SilentlyContinue
1790
+ ```
1791
+ 4. **Reduce MCP server count:** Temporarily disable non-essential MCP servers in settings.json
1792
+ 5. **Retry:** Restart Claude Code and run `/gsd:plan-phase` again
1793
+
1794
+ If freezes persist, try `--skip-research` to reduce the agent chain from 3 to 2 agents:
1795
+ ```
1796
+ /gsd:plan-phase N --skip-research
1797
+ ```
1798
+ </windows_troubleshooting>
1799
+
1800
+ <success_criteria>
1801
+ - [ ] .planning/ directory validated
1802
+ - [ ] Phase validated against roadmap
1803
+ - [ ] Phase directory created if needed
1804
+ - [ ] CONTEXT.md loaded early (step 4) and passed to ALL agents
1805
+ - [ ] Research completed (unless --skip-research or --gaps or exists)
1806
+ - [ ] gsd-phase-researcher spawned with CONTEXT.md
1807
+ - [ ] Existing plans checked
1808
+ - [ ] gsd-planner spawned with CONTEXT.md + RESEARCH.md
1809
+ - [ ] Plans created (PLANNING COMPLETE or CHECKPOINT handled)
1810
+ - [ ] gsd-plan-checker spawned with CONTEXT.md
1811
+ - [ ] Verification passed OR user override OR max iterations with user decision
1812
+ - [ ] User sees status between agent spawns
1813
+ - [ ] User knows next steps
1814
+ </success_criteria>