@opengsd/gsd-core 1.2.0-rc.1

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 (503) hide show
  1. package/LICENSE +21 -0
  2. package/README.ja-JP.md +870 -0
  3. package/README.ko-KR.md +861 -0
  4. package/README.md +301 -0
  5. package/README.pt-BR.md +492 -0
  6. package/README.zh-CN.md +842 -0
  7. package/agents/gsd-advisor-researcher.md +127 -0
  8. package/agents/gsd-ai-researcher.md +133 -0
  9. package/agents/gsd-assumptions-analyzer.md +105 -0
  10. package/agents/gsd-code-fixer.md +668 -0
  11. package/agents/gsd-code-reviewer.md +387 -0
  12. package/agents/gsd-codebase-mapper.md +853 -0
  13. package/agents/gsd-debug-session-manager.md +314 -0
  14. package/agents/gsd-debugger.md +1452 -0
  15. package/agents/gsd-doc-classifier.md +168 -0
  16. package/agents/gsd-doc-synthesizer.md +204 -0
  17. package/agents/gsd-doc-verifier.md +217 -0
  18. package/agents/gsd-doc-writer.md +615 -0
  19. package/agents/gsd-domain-researcher.md +153 -0
  20. package/agents/gsd-eval-auditor.md +191 -0
  21. package/agents/gsd-eval-planner.md +154 -0
  22. package/agents/gsd-executor.md +772 -0
  23. package/agents/gsd-framework-selector.md +160 -0
  24. package/agents/gsd-integration-checker.md +470 -0
  25. package/agents/gsd-intel-updater.md +342 -0
  26. package/agents/gsd-nyquist-auditor.md +203 -0
  27. package/agents/gsd-pattern-mapper.md +335 -0
  28. package/agents/gsd-phase-researcher.md +928 -0
  29. package/agents/gsd-plan-checker.md +978 -0
  30. package/agents/gsd-planner.md +1218 -0
  31. package/agents/gsd-project-researcher.md +677 -0
  32. package/agents/gsd-research-synthesizer.md +255 -0
  33. package/agents/gsd-roadmapper.md +688 -0
  34. package/agents/gsd-security-auditor.md +155 -0
  35. package/agents/gsd-ui-auditor.md +495 -0
  36. package/agents/gsd-ui-checker.md +309 -0
  37. package/agents/gsd-ui-researcher.md +380 -0
  38. package/agents/gsd-user-profiler.md +171 -0
  39. package/agents/gsd-verifier.md +917 -0
  40. package/bin/install.js +10936 -0
  41. package/bin/lib/ui-safety-gate.cjs +107 -0
  42. package/commands/gsd/add-tests.md +42 -0
  43. package/commands/gsd/ai-integration-phase.md +37 -0
  44. package/commands/gsd/audit-fix.md +34 -0
  45. package/commands/gsd/audit-milestone.md +37 -0
  46. package/commands/gsd/audit-uat.md +24 -0
  47. package/commands/gsd/autonomous.md +46 -0
  48. package/commands/gsd/capture.md +62 -0
  49. package/commands/gsd/cleanup.md +24 -0
  50. package/commands/gsd/code-review.md +59 -0
  51. package/commands/gsd/complete-milestone.md +143 -0
  52. package/commands/gsd/config.md +56 -0
  53. package/commands/gsd/debug.md +52 -0
  54. package/commands/gsd/discuss-phase.md +76 -0
  55. package/commands/gsd/docs-update.md +49 -0
  56. package/commands/gsd/eval-review.md +33 -0
  57. package/commands/gsd/execute-phase.md +64 -0
  58. package/commands/gsd/explore.md +27 -0
  59. package/commands/gsd/extract-learnings.md +23 -0
  60. package/commands/gsd/fast.md +31 -0
  61. package/commands/gsd/forensics.md +57 -0
  62. package/commands/gsd/graphify.md +199 -0
  63. package/commands/gsd/health.md +31 -0
  64. package/commands/gsd/help.md +28 -0
  65. package/commands/gsd/import.md +41 -0
  66. package/commands/gsd/inbox.md +39 -0
  67. package/commands/gsd/ingest-docs.md +42 -0
  68. package/commands/gsd/manager.md +45 -0
  69. package/commands/gsd/map-codebase.md +83 -0
  70. package/commands/gsd/milestone-summary.md +51 -0
  71. package/commands/gsd/mvp-phase.md +45 -0
  72. package/commands/gsd/new-milestone.md +45 -0
  73. package/commands/gsd/new-project.md +47 -0
  74. package/commands/gsd/ns-context.md +23 -0
  75. package/commands/gsd/ns-ideate.md +24 -0
  76. package/commands/gsd/ns-manage.md +29 -0
  77. package/commands/gsd/ns-project.md +22 -0
  78. package/commands/gsd/ns-review.md +26 -0
  79. package/commands/gsd/ns-workflow.md +28 -0
  80. package/commands/gsd/pause-work.md +43 -0
  81. package/commands/gsd/phase.md +56 -0
  82. package/commands/gsd/plan-phase.md +62 -0
  83. package/commands/gsd/plan-review-convergence.md +59 -0
  84. package/commands/gsd/pr-branch.md +26 -0
  85. package/commands/gsd/profile-user.md +46 -0
  86. package/commands/gsd/progress.md +47 -0
  87. package/commands/gsd/quick.md +174 -0
  88. package/commands/gsd/resume-work.md +30 -0
  89. package/commands/gsd/review-backlog.md +63 -0
  90. package/commands/gsd/review.md +41 -0
  91. package/commands/gsd/secure-phase.md +36 -0
  92. package/commands/gsd/settings.md +29 -0
  93. package/commands/gsd/ship.md +24 -0
  94. package/commands/gsd/sketch.md +60 -0
  95. package/commands/gsd/spec-phase.md +63 -0
  96. package/commands/gsd/spike.md +57 -0
  97. package/commands/gsd/stats.md +19 -0
  98. package/commands/gsd/surface.md +155 -0
  99. package/commands/gsd/thread.md +24 -0
  100. package/commands/gsd/ui-phase.md +35 -0
  101. package/commands/gsd/ui-review.md +33 -0
  102. package/commands/gsd/ultraplan-phase.md +34 -0
  103. package/commands/gsd/undo.md +35 -0
  104. package/commands/gsd/update.md +48 -0
  105. package/commands/gsd/validate-phase.md +36 -0
  106. package/commands/gsd/verify-work.md +39 -0
  107. package/commands/gsd/workspace.md +52 -0
  108. package/commands/gsd/workstreams.md +70 -0
  109. package/get-shit-done/bin/check-latest-version.cjs +106 -0
  110. package/get-shit-done/bin/gsd-tools.cjs +1676 -0
  111. package/get-shit-done/bin/lib/active-workstream-store.cjs +302 -0
  112. package/get-shit-done/bin/lib/adr-parser.cjs +394 -0
  113. package/get-shit-done/bin/lib/agent-command-router.cjs +65 -0
  114. package/get-shit-done/bin/lib/artifacts.cjs +53 -0
  115. package/get-shit-done/bin/lib/audit.cjs +755 -0
  116. package/get-shit-done/bin/lib/check-command-router.cjs +333 -0
  117. package/get-shit-done/bin/lib/cjs-command-router-adapter.cjs +118 -0
  118. package/get-shit-done/bin/lib/clock.cjs +96 -0
  119. package/get-shit-done/bin/lib/clusters.cjs +135 -0
  120. package/get-shit-done/bin/lib/code-review-flags.cjs +74 -0
  121. package/get-shit-done/bin/lib/command-aliases.cjs +815 -0
  122. package/get-shit-done/bin/lib/command-arg-projection.cjs +62 -0
  123. package/get-shit-done/bin/lib/command-routing-hub.cjs +388 -0
  124. package/get-shit-done/bin/lib/commands.cjs +1188 -0
  125. package/get-shit-done/bin/lib/config-schema.cjs +31 -0
  126. package/get-shit-done/bin/lib/config.cjs +728 -0
  127. package/get-shit-done/bin/lib/configuration.cjs +248 -0
  128. package/get-shit-done/bin/lib/context-utilization.cjs +47 -0
  129. package/get-shit-done/bin/lib/core.cjs +2121 -0
  130. package/get-shit-done/bin/lib/decisions.cjs +116 -0
  131. package/get-shit-done/bin/lib/docs.cjs +270 -0
  132. package/get-shit-done/bin/lib/drift.cjs +388 -0
  133. package/get-shit-done/bin/lib/fallow-runner.cjs +109 -0
  134. package/get-shit-done/bin/lib/frontmatter.cjs +389 -0
  135. package/get-shit-done/bin/lib/gap-checker.cjs +205 -0
  136. package/get-shit-done/bin/lib/graphify.cjs +592 -0
  137. package/get-shit-done/bin/lib/gsd2-import.cjs +514 -0
  138. package/get-shit-done/bin/lib/init-command-router.cjs +58 -0
  139. package/get-shit-done/bin/lib/init.cjs +2112 -0
  140. package/get-shit-done/bin/lib/install-profiles.cjs +603 -0
  141. package/get-shit-done/bin/lib/installer-migration-authoring.cjs +117 -0
  142. package/get-shit-done/bin/lib/installer-migration-report.cjs +354 -0
  143. package/get-shit-done/bin/lib/installer-migrations/000-first-time-baseline.cjs +220 -0
  144. package/get-shit-done/bin/lib/installer-migrations/001-legacy-orphan-files.cjs +41 -0
  145. package/get-shit-done/bin/lib/installer-migrations/002-codex-legacy-hooks-json.cjs +80 -0
  146. package/get-shit-done/bin/lib/installer-migrations.cjs +778 -0
  147. package/get-shit-done/bin/lib/intel.cjs +708 -0
  148. package/get-shit-done/bin/lib/learnings.cjs +421 -0
  149. package/get-shit-done/bin/lib/milestone.cjs +314 -0
  150. package/get-shit-done/bin/lib/model-catalog.cjs +212 -0
  151. package/get-shit-done/bin/lib/model-profiles.cjs +31 -0
  152. package/get-shit-done/bin/lib/observability/event.cjs +82 -0
  153. package/get-shit-done/bin/lib/observability/logger.cjs +174 -0
  154. package/get-shit-done/bin/lib/observability/redaction.cjs +50 -0
  155. package/get-shit-done/bin/lib/package-identity.cjs +31 -0
  156. package/get-shit-done/bin/lib/phase-command-router.cjs +191 -0
  157. package/get-shit-done/bin/lib/phase-lifecycle.cjs +80 -0
  158. package/get-shit-done/bin/lib/phase.cjs +1607 -0
  159. package/get-shit-done/bin/lib/phases-command-router.cjs +39 -0
  160. package/get-shit-done/bin/lib/plan-scan.cjs +97 -0
  161. package/get-shit-done/bin/lib/planning-workspace.cjs +238 -0
  162. package/get-shit-done/bin/lib/profile-output.cjs +1141 -0
  163. package/get-shit-done/bin/lib/profile-pipeline.cjs +539 -0
  164. package/get-shit-done/bin/lib/project-root.cjs +112 -0
  165. package/get-shit-done/bin/lib/prompt-budget.cjs +399 -0
  166. package/get-shit-done/bin/lib/review-reviewer-selection.cjs +125 -0
  167. package/get-shit-done/bin/lib/roadmap-command-router.cjs +28 -0
  168. package/get-shit-done/bin/lib/roadmap.cjs +650 -0
  169. package/get-shit-done/bin/lib/runtime-artifact-layout.cjs +301 -0
  170. package/get-shit-done/bin/lib/runtime-homes.cjs +222 -0
  171. package/get-shit-done/bin/lib/runtime-name-policy.cjs +83 -0
  172. package/get-shit-done/bin/lib/runtime-slash.cjs +112 -0
  173. package/get-shit-done/bin/lib/schema-detect.cjs +165 -0
  174. package/get-shit-done/bin/lib/secrets.cjs +32 -0
  175. package/get-shit-done/bin/lib/security.cjs +600 -0
  176. package/get-shit-done/bin/lib/semver-compare.cjs +35 -0
  177. package/get-shit-done/bin/lib/shell-command-projection.cjs +500 -0
  178. package/get-shit-done/bin/lib/state-command-router.cjs +252 -0
  179. package/get-shit-done/bin/lib/state-document.cjs +263 -0
  180. package/get-shit-done/bin/lib/state.cjs +2038 -0
  181. package/get-shit-done/bin/lib/surface.cjs +470 -0
  182. package/get-shit-done/bin/lib/task-command-router.cjs +81 -0
  183. package/get-shit-done/bin/lib/template.cjs +228 -0
  184. package/get-shit-done/bin/lib/uat.cjs +289 -0
  185. package/get-shit-done/bin/lib/update-context.cjs +209 -0
  186. package/get-shit-done/bin/lib/validate-command-router.cjs +83 -0
  187. package/get-shit-done/bin/lib/validate.cjs +92 -0
  188. package/get-shit-done/bin/lib/verify-command-router.cjs +40 -0
  189. package/get-shit-done/bin/lib/verify.cjs +1511 -0
  190. package/get-shit-done/bin/lib/workstream-inventory-builder.cjs +74 -0
  191. package/get-shit-done/bin/lib/workstream-inventory.cjs +146 -0
  192. package/get-shit-done/bin/lib/workstream-name-policy.cjs +94 -0
  193. package/get-shit-done/bin/lib/workstream.cjs +389 -0
  194. package/get-shit-done/bin/lib/worktree-safety.cjs +985 -0
  195. package/get-shit-done/bin/shared/config-defaults.manifest.json +97 -0
  196. package/get-shit-done/bin/shared/config-schema.manifest.json +175 -0
  197. package/get-shit-done/bin/shared/model-catalog.json +122 -0
  198. package/get-shit-done/bin/shared/runtime-aliases.manifest.json +75 -0
  199. package/get-shit-done/bin/verify-reapply-patches.cjs +352 -0
  200. package/get-shit-done/contexts/dev.md +21 -0
  201. package/get-shit-done/contexts/research.md +22 -0
  202. package/get-shit-done/contexts/review.md +23 -0
  203. package/get-shit-done/references/agent-contracts.md +79 -0
  204. package/get-shit-done/references/ai-evals.md +156 -0
  205. package/get-shit-done/references/ai-frameworks.md +186 -0
  206. package/get-shit-done/references/artifact-types.md +131 -0
  207. package/get-shit-done/references/autonomous-smart-discuss.md +277 -0
  208. package/get-shit-done/references/checkpoints.md +814 -0
  209. package/get-shit-done/references/common-bug-patterns.md +114 -0
  210. package/get-shit-done/references/context-budget.md +85 -0
  211. package/get-shit-done/references/continuation-format.md +253 -0
  212. package/get-shit-done/references/debugger-philosophy.md +76 -0
  213. package/get-shit-done/references/decimal-phase-calculation.md +64 -0
  214. package/get-shit-done/references/doc-conflict-engine.md +91 -0
  215. package/get-shit-done/references/domain-probes.md +125 -0
  216. package/get-shit-done/references/execute-mvp-tdd.md +81 -0
  217. package/get-shit-done/references/executor-examples.md +110 -0
  218. package/get-shit-done/references/few-shot-examples/plan-checker.md +73 -0
  219. package/get-shit-done/references/few-shot-examples/verifier.md +109 -0
  220. package/get-shit-done/references/gate-prompts.md +100 -0
  221. package/get-shit-done/references/gates.md +70 -0
  222. package/get-shit-done/references/git-integration.md +298 -0
  223. package/get-shit-done/references/git-planning-commit.md +40 -0
  224. package/get-shit-done/references/ios-scaffold.md +123 -0
  225. package/get-shit-done/references/mandatory-initial-read.md +2 -0
  226. package/get-shit-done/references/model-profile-resolution.md +38 -0
  227. package/get-shit-done/references/model-profiles.md +245 -0
  228. package/get-shit-done/references/mvp-concepts.md +49 -0
  229. package/get-shit-done/references/phase-argument-parsing.md +61 -0
  230. package/get-shit-done/references/planner-antipatterns.md +89 -0
  231. package/get-shit-done/references/planner-chunked.md +49 -0
  232. package/get-shit-done/references/planner-gap-closure.md +62 -0
  233. package/get-shit-done/references/planner-graphify-auto-update.md +67 -0
  234. package/get-shit-done/references/planner-human-verify-mode.md +57 -0
  235. package/get-shit-done/references/planner-interface-context.md +62 -0
  236. package/get-shit-done/references/planner-mvp-mode.md +53 -0
  237. package/get-shit-done/references/planner-reviews.md +39 -0
  238. package/get-shit-done/references/planner-revision.md +87 -0
  239. package/get-shit-done/references/planner-source-audit.md +73 -0
  240. package/get-shit-done/references/planning-config.md +471 -0
  241. package/get-shit-done/references/project-skills-discovery.md +19 -0
  242. package/get-shit-done/references/questioning.md +162 -0
  243. package/get-shit-done/references/revision-loop.md +97 -0
  244. package/get-shit-done/references/scout-codebase.md +51 -0
  245. package/get-shit-done/references/skeleton-template.md +48 -0
  246. package/get-shit-done/references/sketch-interactivity.md +41 -0
  247. package/get-shit-done/references/sketch-theme-system.md +94 -0
  248. package/get-shit-done/references/sketch-tooling.md +45 -0
  249. package/get-shit-done/references/sketch-variant-patterns.md +81 -0
  250. package/get-shit-done/references/spidr-splitting.md +69 -0
  251. package/get-shit-done/references/tdd.md +330 -0
  252. package/get-shit-done/references/thinking-models-debug.md +44 -0
  253. package/get-shit-done/references/thinking-models-execution.md +50 -0
  254. package/get-shit-done/references/thinking-models-planning.md +62 -0
  255. package/get-shit-done/references/thinking-models-research.md +50 -0
  256. package/get-shit-done/references/thinking-models-verification.md +55 -0
  257. package/get-shit-done/references/thinking-partner.md +96 -0
  258. package/get-shit-done/references/ui-brand.md +160 -0
  259. package/get-shit-done/references/universal-anti-patterns.md +63 -0
  260. package/get-shit-done/references/user-profiling.md +681 -0
  261. package/get-shit-done/references/user-story-template.md +58 -0
  262. package/get-shit-done/references/verification-overrides.md +227 -0
  263. package/get-shit-done/references/verification-patterns.md +612 -0
  264. package/get-shit-done/references/verify-mvp-mode.md +85 -0
  265. package/get-shit-done/references/workstream-flag.md +111 -0
  266. package/get-shit-done/references/worktree-path-safety.md +89 -0
  267. package/get-shit-done/templates/AI-SPEC.md +246 -0
  268. package/get-shit-done/templates/DEBUG.md +169 -0
  269. package/get-shit-done/templates/README.md +77 -0
  270. package/get-shit-done/templates/SECURITY.md +61 -0
  271. package/get-shit-done/templates/UAT.md +265 -0
  272. package/get-shit-done/templates/UI-SPEC.md +100 -0
  273. package/get-shit-done/templates/VALIDATION.md +76 -0
  274. package/get-shit-done/templates/claude-md.md +145 -0
  275. package/get-shit-done/templates/codebase/architecture.md +255 -0
  276. package/get-shit-done/templates/codebase/concerns.md +310 -0
  277. package/get-shit-done/templates/codebase/conventions.md +307 -0
  278. package/get-shit-done/templates/codebase/integrations.md +280 -0
  279. package/get-shit-done/templates/codebase/stack.md +186 -0
  280. package/get-shit-done/templates/codebase/structure.md +285 -0
  281. package/get-shit-done/templates/codebase/testing.md +480 -0
  282. package/get-shit-done/templates/config.json +62 -0
  283. package/get-shit-done/templates/context.md +352 -0
  284. package/get-shit-done/templates/continue-here.md +78 -0
  285. package/get-shit-done/templates/copilot-instructions.md +7 -0
  286. package/get-shit-done/templates/debug-subagent-prompt.md +91 -0
  287. package/get-shit-done/templates/dev-preferences.md +21 -0
  288. package/get-shit-done/templates/discovery.md +146 -0
  289. package/get-shit-done/templates/discussion-log.md +63 -0
  290. package/get-shit-done/templates/milestone-archive.md +123 -0
  291. package/get-shit-done/templates/milestone.md +115 -0
  292. package/get-shit-done/templates/phase-prompt.md +610 -0
  293. package/get-shit-done/templates/planner-subagent-prompt.md +117 -0
  294. package/get-shit-done/templates/project.md +186 -0
  295. package/get-shit-done/templates/requirements.md +231 -0
  296. package/get-shit-done/templates/research-project/ARCHITECTURE.md +204 -0
  297. package/get-shit-done/templates/research-project/FEATURES.md +147 -0
  298. package/get-shit-done/templates/research-project/PITFALLS.md +200 -0
  299. package/get-shit-done/templates/research-project/STACK.md +120 -0
  300. package/get-shit-done/templates/research-project/SUMMARY.md +170 -0
  301. package/get-shit-done/templates/research.md +592 -0
  302. package/get-shit-done/templates/retrospective.md +54 -0
  303. package/get-shit-done/templates/roadmap.md +202 -0
  304. package/get-shit-done/templates/spec.md +307 -0
  305. package/get-shit-done/templates/state.md +195 -0
  306. package/get-shit-done/templates/summary-complex.md +59 -0
  307. package/get-shit-done/templates/summary-minimal.md +41 -0
  308. package/get-shit-done/templates/summary-standard.md +48 -0
  309. package/get-shit-done/templates/summary.md +248 -0
  310. package/get-shit-done/templates/user-profile.md +146 -0
  311. package/get-shit-done/templates/user-setup.md +311 -0
  312. package/get-shit-done/templates/verification-report.md +322 -0
  313. package/get-shit-done/workflows/_runtime-launcher.snippet.sh +1 -0
  314. package/get-shit-done/workflows/add-backlog.md +91 -0
  315. package/get-shit-done/workflows/add-phase.md +113 -0
  316. package/get-shit-done/workflows/add-tests.md +355 -0
  317. package/get-shit-done/workflows/add-todo.md +161 -0
  318. package/get-shit-done/workflows/ai-integration-phase.md +295 -0
  319. package/get-shit-done/workflows/analyze-dependencies.md +96 -0
  320. package/get-shit-done/workflows/audit-fix.md +178 -0
  321. package/get-shit-done/workflows/audit-milestone.md +358 -0
  322. package/get-shit-done/workflows/audit-uat.md +110 -0
  323. package/get-shit-done/workflows/autonomous.md +795 -0
  324. package/get-shit-done/workflows/check-todos.md +180 -0
  325. package/get-shit-done/workflows/cleanup.md +155 -0
  326. package/get-shit-done/workflows/code-review-fix.md +502 -0
  327. package/get-shit-done/workflows/code-review.md +656 -0
  328. package/get-shit-done/workflows/complete-milestone.md +855 -0
  329. package/get-shit-done/workflows/debug.md +232 -0
  330. package/get-shit-done/workflows/diagnose-issues.md +241 -0
  331. package/get-shit-done/workflows/discovery-phase.md +291 -0
  332. package/get-shit-done/workflows/discuss-phase/modes/advisor.md +176 -0
  333. package/get-shit-done/workflows/discuss-phase/modes/all.md +28 -0
  334. package/get-shit-done/workflows/discuss-phase/modes/analyze.md +44 -0
  335. package/get-shit-done/workflows/discuss-phase/modes/auto.md +57 -0
  336. package/get-shit-done/workflows/discuss-phase/modes/batch.md +52 -0
  337. package/get-shit-done/workflows/discuss-phase/modes/chain.md +98 -0
  338. package/get-shit-done/workflows/discuss-phase/modes/default.md +141 -0
  339. package/get-shit-done/workflows/discuss-phase/modes/power.md +44 -0
  340. package/get-shit-done/workflows/discuss-phase/modes/text.md +55 -0
  341. package/get-shit-done/workflows/discuss-phase/templates/checkpoint.json +18 -0
  342. package/get-shit-done/workflows/discuss-phase/templates/context.md +136 -0
  343. package/get-shit-done/workflows/discuss-phase/templates/discussion-log.md +50 -0
  344. package/get-shit-done/workflows/discuss-phase-assumptions.md +675 -0
  345. package/get-shit-done/workflows/discuss-phase-power.md +291 -0
  346. package/get-shit-done/workflows/discuss-phase.md +499 -0
  347. package/get-shit-done/workflows/do.md +111 -0
  348. package/get-shit-done/workflows/docs-update.md +1162 -0
  349. package/get-shit-done/workflows/edit-phase.md +295 -0
  350. package/get-shit-done/workflows/eval-review.md +156 -0
  351. package/get-shit-done/workflows/execute-phase/steps/codebase-drift-gate.md +82 -0
  352. package/get-shit-done/workflows/execute-phase/steps/per-plan-worktree-gate.md +94 -0
  353. package/get-shit-done/workflows/execute-phase/steps/post-merge-gate.md +117 -0
  354. package/get-shit-done/workflows/execute-phase.md +1709 -0
  355. package/get-shit-done/workflows/execute-plan.md +526 -0
  356. package/get-shit-done/workflows/explore.md +144 -0
  357. package/get-shit-done/workflows/extract-learnings.md +243 -0
  358. package/get-shit-done/workflows/fast.md +124 -0
  359. package/get-shit-done/workflows/forensics.md +279 -0
  360. package/get-shit-done/workflows/graduation.md +196 -0
  361. package/get-shit-done/workflows/health.md +224 -0
  362. package/get-shit-done/workflows/help/modes/brief.md +22 -0
  363. package/get-shit-done/workflows/help/modes/default.md +50 -0
  364. package/get-shit-done/workflows/help/modes/full.md +784 -0
  365. package/get-shit-done/workflows/help/modes/topic.md +74 -0
  366. package/get-shit-done/workflows/help.md +24 -0
  367. package/get-shit-done/workflows/import.md +254 -0
  368. package/get-shit-done/workflows/inbox.md +387 -0
  369. package/get-shit-done/workflows/ingest-docs.md +339 -0
  370. package/get-shit-done/workflows/insert-phase.md +152 -0
  371. package/get-shit-done/workflows/list-phase-assumptions.md +178 -0
  372. package/get-shit-done/workflows/list-workspaces.md +57 -0
  373. package/get-shit-done/workflows/manager.md +393 -0
  374. package/get-shit-done/workflows/map-codebase.md +444 -0
  375. package/get-shit-done/workflows/milestone-summary.md +224 -0
  376. package/get-shit-done/workflows/mvp-phase.md +222 -0
  377. package/get-shit-done/workflows/new-milestone.md +635 -0
  378. package/get-shit-done/workflows/new-project.md +1555 -0
  379. package/get-shit-done/workflows/new-workspace.md +240 -0
  380. package/get-shit-done/workflows/next.md +299 -0
  381. package/get-shit-done/workflows/node-repair.md +92 -0
  382. package/get-shit-done/workflows/note.md +158 -0
  383. package/get-shit-done/workflows/pause-work.md +244 -0
  384. package/get-shit-done/workflows/plan-milestone-gaps.md +281 -0
  385. package/get-shit-done/workflows/plan-phase.md +1809 -0
  386. package/get-shit-done/workflows/plan-review-convergence.md +346 -0
  387. package/get-shit-done/workflows/plant-seed.md +230 -0
  388. package/get-shit-done/workflows/pr-branch.md +157 -0
  389. package/get-shit-done/workflows/profile-user.md +453 -0
  390. package/get-shit-done/workflows/progress.md +699 -0
  391. package/get-shit-done/workflows/quick.md +1039 -0
  392. package/get-shit-done/workflows/reapply-patches.md +426 -0
  393. package/get-shit-done/workflows/remove-phase.md +156 -0
  394. package/get-shit-done/workflows/remove-workspace.md +108 -0
  395. package/get-shit-done/workflows/resume-project.md +332 -0
  396. package/get-shit-done/workflows/review.md +623 -0
  397. package/get-shit-done/workflows/scan.md +105 -0
  398. package/get-shit-done/workflows/secure-phase.md +180 -0
  399. package/get-shit-done/workflows/session-report.md +146 -0
  400. package/get-shit-done/workflows/settings-advanced.md +620 -0
  401. package/get-shit-done/workflows/settings-integrations.md +312 -0
  402. package/get-shit-done/workflows/settings.md +552 -0
  403. package/get-shit-done/workflows/ship.md +356 -0
  404. package/get-shit-done/workflows/sketch-wrap-up.md +286 -0
  405. package/get-shit-done/workflows/sketch.md +361 -0
  406. package/get-shit-done/workflows/spec-phase.md +262 -0
  407. package/get-shit-done/workflows/spike-wrap-up.md +307 -0
  408. package/get-shit-done/workflows/spike.md +453 -0
  409. package/get-shit-done/workflows/stats.md +80 -0
  410. package/get-shit-done/workflows/sync-skills.md +182 -0
  411. package/get-shit-done/workflows/thread.md +222 -0
  412. package/get-shit-done/workflows/transition.md +694 -0
  413. package/get-shit-done/workflows/ui-phase.md +328 -0
  414. package/get-shit-done/workflows/ui-review.md +193 -0
  415. package/get-shit-done/workflows/ultraplan-phase.md +199 -0
  416. package/get-shit-done/workflows/undo.md +314 -0
  417. package/get-shit-done/workflows/update.md +443 -0
  418. package/get-shit-done/workflows/validate-phase.md +179 -0
  419. package/get-shit-done/workflows/verify-phase.md +544 -0
  420. package/get-shit-done/workflows/verify-work.md +781 -0
  421. package/hooks/dist/gsd-check-update-worker.js +95 -0
  422. package/hooks/dist/gsd-check-update.js +64 -0
  423. package/hooks/dist/gsd-context-monitor.js +195 -0
  424. package/hooks/dist/gsd-graphify-update.sh +158 -0
  425. package/hooks/dist/gsd-phase-boundary.sh +47 -0
  426. package/hooks/dist/gsd-prompt-guard.js +97 -0
  427. package/hooks/dist/gsd-read-guard.js +101 -0
  428. package/hooks/dist/gsd-read-injection-scanner.js +203 -0
  429. package/hooks/dist/gsd-session-state.sh +59 -0
  430. package/hooks/dist/gsd-statusline.js +548 -0
  431. package/hooks/dist/gsd-update-banner.js +134 -0
  432. package/hooks/dist/gsd-validate-commit.sh +57 -0
  433. package/hooks/dist/gsd-workflow-guard.js +166 -0
  434. package/hooks/dist/lib/git-cmd.js +150 -0
  435. package/hooks/dist/lib/gsd-graphify-rebuild.sh +65 -0
  436. package/hooks/gsd-check-update-worker.js +95 -0
  437. package/hooks/gsd-check-update.js +64 -0
  438. package/hooks/gsd-context-monitor.js +195 -0
  439. package/hooks/gsd-graphify-update.sh +158 -0
  440. package/hooks/gsd-phase-boundary.sh +47 -0
  441. package/hooks/gsd-prompt-guard.js +97 -0
  442. package/hooks/gsd-read-guard.js +101 -0
  443. package/hooks/gsd-read-injection-scanner.js +203 -0
  444. package/hooks/gsd-session-state.sh +59 -0
  445. package/hooks/gsd-statusline.js +548 -0
  446. package/hooks/gsd-update-banner.js +134 -0
  447. package/hooks/gsd-validate-commit.sh +57 -0
  448. package/hooks/gsd-workflow-guard.js +166 -0
  449. package/hooks/lib/git-cmd.js +150 -0
  450. package/hooks/lib/gsd-graphify-rebuild.sh +65 -0
  451. package/hooks/managed-hooks-registry.cjs +34 -0
  452. package/package.json +102 -0
  453. package/scripts/affected-tests-lib.cjs +541 -0
  454. package/scripts/audit-workflow-script-paths.cjs +73 -0
  455. package/scripts/base64-scan.sh +339 -0
  456. package/scripts/build-hooks.js +236 -0
  457. package/scripts/changeset/README.md +129 -0
  458. package/scripts/changeset/cli.cjs +392 -0
  459. package/scripts/changeset/github-release-notes.cjs +199 -0
  460. package/scripts/changeset/lint.cjs +110 -0
  461. package/scripts/changeset/new.cjs +137 -0
  462. package/scripts/changeset/parse.cjs +114 -0
  463. package/scripts/changeset/render.cjs +34 -0
  464. package/scripts/changeset/serialize.cjs +130 -0
  465. package/scripts/check-alias-drift.cjs +108 -0
  466. package/scripts/check-env.cjs +302 -0
  467. package/scripts/check-npm-integrity.cjs +209 -0
  468. package/scripts/ci-guard-runner.cjs +16 -0
  469. package/scripts/ci-prepare-test-scope.cjs +46 -0
  470. package/scripts/ci-rebase-check.cjs +85 -0
  471. package/scripts/ci-test-scope.cjs +302 -0
  472. package/scripts/command-contract-helpers.cjs +64 -0
  473. package/scripts/diff-touches-shipped-paths.cjs +147 -0
  474. package/scripts/fix-slash-commands.cjs +147 -0
  475. package/scripts/gen-inventory-manifest.cjs +109 -0
  476. package/scripts/generate-package-identity.cjs +104 -0
  477. package/scripts/lint-command-contract.cjs +108 -0
  478. package/scripts/lint-descriptions.cjs +83 -0
  479. package/scripts/lint-docs-required.cjs +222 -0
  480. package/scripts/lint-no-source-grep-extras.cjs +81 -0
  481. package/scripts/lint-no-source-grep.cjs +174 -0
  482. package/scripts/lint-package-identity-drift.cjs +141 -0
  483. package/scripts/lint-pr-check-project-dir.cjs +98 -0
  484. package/scripts/lint-shared-module-handsync.cjs +388 -0
  485. package/scripts/lint-shell-command-projection-drift.cjs +57 -0
  486. package/scripts/lint-skill-deps.cjs +180 -0
  487. package/scripts/lint-test-file-count.allowlist.json +36 -0
  488. package/scripts/lint-test-file-count.cjs +190 -0
  489. package/scripts/pr-template-policy.cjs +268 -0
  490. package/scripts/prompt-injection-scan.sh +203 -0
  491. package/scripts/release-tarball-smoke.cjs +627 -0
  492. package/scripts/run-affected-tests.cjs +6 -0
  493. package/scripts/run-cross-platform-tests.cjs +63 -0
  494. package/scripts/run-tests.cjs +282 -0
  495. package/scripts/secret-scan-lint.sh +231 -0
  496. package/scripts/secret-scan.sh +358 -0
  497. package/scripts/setup-branch-protection.sh +236 -0
  498. package/scripts/shared-module-handsync-allowlist.json +183 -0
  499. package/scripts/strip-prose-atrefs.cjs +106 -0
  500. package/scripts/sync-rulesets.sh +34 -0
  501. package/scripts/sync-runtime-launcher.cjs +402 -0
  502. package/scripts/test-failure-reasons.cjs +34 -0
  503. package/scripts/workflow-policy.cjs +450 -0
@@ -0,0 +1,1709 @@
1
+ <purpose>
2
+ Execute all plans in a phase using wave-based parallel execution. Orchestrator stays lean — delegates plan execution to subagents.
3
+ </purpose>
4
+
5
+ <core_principle>
6
+ Orchestrator coordinates, not executes. Each subagent loads the full execute-plan context. Orchestrator: discover plans → analyze deps → group waves → spawn agents → handle checkpoints → collect results.
7
+ </core_principle>
8
+
9
+ <runtime_compatibility>
10
+ **Subagent spawning is runtime-specific:**
11
+ - **Claude Code:** Uses `Agent(subagent_type="gsd-executor", ...)` — blocks until complete, returns result
12
+ - **Copilot:** Subagent spawning does not reliably return completion signals. **Default to
13
+ sequential inline execution**: read and follow execute-plan.md directly for each plan
14
+ instead of spawning parallel agents. Only attempt parallel spawning if the user
15
+ explicitly requests it — and in that case, rely on the spot-check fallback in step 3
16
+ to detect completion.
17
+ - **Other runtimes:** If `Agent`/`agent` tool is unavailable, use sequential inline execution as the
18
+ fallback. Check for tool availability at runtime rather than assuming based on runtime name.
19
+
20
+ **Fallback rule:** If a spawned agent completes its work (commits visible, SUMMARY.md exists) but
21
+ the orchestrator never receives the completion signal, treat it as successful based on spot-checks
22
+ and continue to the next wave/plan. Never block indefinitely waiting for a signal — always verify
23
+ via filesystem and git state.
24
+ </runtime_compatibility>
25
+
26
+ <required_reading>
27
+ Read STATE.md before any operation to load project context.
28
+ @~/.claude/get-shit-done/references/agent-contracts.md
29
+ @~/.claude/get-shit-done/references/context-budget.md
30
+ @~/.claude/get-shit-done/references/gates.md
31
+ </required_reading>
32
+
33
+ <available_agent_types>
34
+ These are the valid GSD subagent types registered in .claude/agents/ (or equivalent for your runtime).
35
+ Always use the exact name from this list — do not fall back to 'general-purpose' or other built-in types:
36
+
37
+ - gsd-executor — Executes plan tasks, commits, creates SUMMARY.md
38
+ - gsd-verifier — Verifies phase completion, checks quality gates
39
+ - gsd-planner — Creates detailed plans from phase scope
40
+ - gsd-phase-researcher — Researches technical approaches for a phase
41
+ - gsd-plan-checker — Reviews plan quality before execution
42
+ - gsd-debugger — Diagnoses and fixes issues
43
+ - gsd-codebase-mapper — Maps project structure and dependencies
44
+ - gsd-integration-checker — Checks cross-phase integration
45
+ - gsd-nyquist-auditor — Validates verification coverage
46
+ - gsd-ui-researcher — Researches UI/UX approaches
47
+ - gsd-ui-checker — Reviews UI implementation quality
48
+ - gsd-ui-auditor — Audits UI against design requirements
49
+ </available_agent_types>
50
+
51
+ <process>
52
+
53
+ <step name="parse_args" priority="first">
54
+ Parse `$ARGUMENTS` before loading any context:
55
+
56
+ - First positional token → `PHASE_ARG`
57
+ - Optional `--wave N` → `WAVE_FILTER`
58
+ - Optional `--gaps-only` keeps its current meaning
59
+ - Optional `--cross-ai` → `CROSS_AI_FORCE=true` (force all plans through cross-AI execution)
60
+ - Optional `--no-cross-ai` → `CROSS_AI_DISABLED=true` (disable cross-AI for this run, overrides config and frontmatter)
61
+
62
+ If `--wave` is absent, preserve the current behavior of executing all incomplete waves in the phase.
63
+ </step>
64
+
65
+ <step name="initialize" priority="first">
66
+ Load all context in one call:
67
+
68
+ ```bash
69
+ _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}/get-shit-done/bin/${_GSD_SHIM_NAME}"; if [ -f "$GSD_TOOLS" ]; then gsd_run() { node "$GSD_TOOLS" "$@"; }; elif [ -f "${_GSD_RUNTIME_ROOT}/.claude/get-shit-done/bin/${_GSD_SHIM_NAME}" ]; then GSD_TOOLS="${_GSD_RUNTIME_ROOT}/.claude/get-shit-done/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/get-shit-done/bin/${_GSD_SHIM_NAME}" ]; then GSD_TOOLS="$HOME/.claude/get-shit-done/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 @opengsd/gsd-core@latest --claude --local" >&2; exit 1; fi
70
+ INIT=$(gsd_run query init.execute-phase "${PHASE_ARG}")
71
+ if [[ "$INIT" == @file:* ]]; then INIT=$(cat "${INIT#@file:}"); fi
72
+ AGENT_SKILLS=$(gsd_run query agent-skills gsd-executor)
73
+ ```
74
+
75
+ Parse JSON for: `executor_model`, `verifier_model`, `commit_docs`, `parallelization`, `branching_strategy`, `branch_name`, `phase_found`, `phase_dir`, `phase_number`, `phase_name`, `phase_slug`, `plans`, `incomplete_plans`, `plan_count`, `incomplete_count`, `state_exists`, `roadmap_exists`, `phase_req_ids`, `response_language`.
76
+
77
+ **Model resolution:** If `executor_model` is `"inherit"`, omit the `model=` parameter from all `Agent()` calls — do NOT pass `model="inherit"` to Agent. Omitting the `model=` parameter causes Claude Code to inherit the current orchestrator model automatically. Only set `model=` when `executor_model` is an explicit model name (e.g., `"claude-sonnet-4-6"`, `"claude-opus-4-7"`).
78
+
79
+ **If `response_language` is set:** Include `response_language: {value}` in all spawned subagent prompts so any user-facing output stays in the configured language.
80
+
81
+ Read runtime/worktree config and fail closed before any executor dispatch:
82
+
83
+ ```bash
84
+ RUNTIME=$(gsd_run query config-get runtime --default claude 2>/dev/null || echo "claude")
85
+ USE_WORKTREES=$(gsd_run query config-get workflow.use_worktrees 2>/dev/null || echo "true")
86
+ EXECUTOR_STALL_INTERVAL_MINUTES=$(gsd_run query config-get executor.stall_detect_interval_minutes 2>/dev/null || echo "5")
87
+ EXECUTOR_STALL_THRESHOLD_MINUTES=$(gsd_run query config-get executor.stall_threshold_minutes 2>/dev/null || echo "10")
88
+
89
+ if [ "$RUNTIME" = "codex" ] && [ "$USE_WORKTREES" != "false" ]; then
90
+ echo "FATAL: Codex execute-phase worktree isolation is unsupported. Set workflow.use_worktrees=false or use a runtime with Agent isolation=\"worktree\" support." >&2
91
+ exit 1
92
+ fi
93
+ # Sweep orphaned locked worktrees from prior crashed sessions before spawning executors (#3707).
94
+ [ "$USE_WORKTREES" != "false" ] && gsd_run query worktree.reap-orphans 2>/dev/null || true
95
+ ```
96
+ Codex maps subagents to `spawn_agent`, which has no direct Codex mapping for Claude Code's `isolation="worktree"` parameter. Failing closed prevents main-checkout edits while the workflow believes agents are isolated.
97
+
98
+ If the project uses git submodules, worktree isolation is unsafe **only when a plan touches a submodule path** — the executor commit protocol cannot correctly handle submodule commits inside isolated worktrees. The previous behavior unconditionally disabled worktree isolation whenever `.gitmodules` existed, which penalised every plan in a submodule project even when the plan was nowhere near a submodule. Compute submodule paths once and intersect them per-plan with the plan's declared `files_modified` frontmatter.
99
+
100
+ ```bash
101
+ # Parse submodule paths from .gitmodules once (empty if no .gitmodules).
102
+ # SUBMODULE_PATHS is a newline-separated list of repo-relative paths.
103
+ if [ -f .gitmodules ]; then
104
+ SUBMODULE_PATHS=$(git config --file .gitmodules --get-regexp '^submodule\..*\.path$' 2>/dev/null | awk '{print $2}')
105
+ else
106
+ SUBMODULE_PATHS=""
107
+ fi
108
+ ```
109
+
110
+ `SUBMODULE_PATHS` is exported to the `execute_waves` step, where the per-plan decision actually happens (see "Per-plan worktree decision" sub-step inside `execute_waves`). The decision is per-plan because different plans in the same wave can touch different files — only plans whose paths intersect a submodule must drop worktree isolation; plans nowhere near a submodule keep parallel isolation.
111
+
112
+ When `USE_WORKTREES` (project-level) is `false`, all executor agents run without `isolation="worktree"` — they execute sequentially on the main working tree instead of in parallel worktrees. The per-plan decision below has no effect when worktrees are project-disabled.
113
+
114
+ Read context window size for adaptive prompt enrichment:
115
+
116
+ ```bash
117
+ CONTEXT_WINDOW=$(gsd_run query config-get context_window 2>/dev/null || echo "200000")
118
+ ```
119
+
120
+ When `CONTEXT_WINDOW >= 500000` (1M-class models), subagent prompts include richer context:
121
+ - Executor agents receive prior wave SUMMARY.md files and the phase CONTEXT.md/RESEARCH.md
122
+ - Verifier agents receive all PLAN.md, SUMMARY.md, CONTEXT.md files plus REQUIREMENTS.md
123
+ - This enables cross-phase awareness and history-aware verification
124
+
125
+ When `CONTEXT_WINDOW < 200000` (sub-200K models), subagent prompts are thinned to reduce static overhead:
126
+ - Executor agents omit extended deviation rule examples and checkpoint examples from inline prompt — load on-demand via @~/.claude/get-shit-done/references/executor-examples.md
127
+ - Planner agents omit extended anti-pattern lists and specificity examples from inline prompt — load on-demand via @~/.claude/get-shit-done/references/planner-antipatterns.md
128
+ - Core rules and decision logic remain inline; only verbose examples and edge-case lists are extracted
129
+ - This reduces executor static overhead by ~40% while preserving behavioral correctness
130
+
131
+ **If `phase_found` is false:** Error — phase directory not found.
132
+ **If `plan_count` is 0:** Error — no plans found in phase.
133
+ **If `state_exists` is false but `.planning/` exists:** Offer reconstruct or continue.
134
+
135
+ When `parallelization` is false, plans within a wave execute sequentially.
136
+
137
+ **Runtime detection for Copilot:**
138
+ Check if the current runtime is Copilot by testing for the `@gsd-executor` agent pattern
139
+ or absence of the `Agent()` subagent API. If running under Copilot, force sequential inline
140
+ execution regardless of the `parallelization` setting — Copilot's subagent completion
141
+ signals are unreliable (see `<runtime_compatibility>`). Set `COPILOT_SEQUENTIAL=true`
142
+ internally and skip the `execute_waves` step in favor of `check_interactive_mode`'s
143
+ inline path for each plan.
144
+
145
+ **REQUIRED — Sync chain flag with intent.** If user invoked manually (no `--auto`), clear the ephemeral chain flag from any previous interrupted `--auto` chain. This prevents stale `_auto_chain_active: true` from causing unwanted auto-advance. This does NOT touch `workflow.auto_advance` (the user's persistent settings preference). You MUST execute this bash block before any config reads:
146
+ ```bash
147
+ # REQUIRED: prevents stale auto-chain from previous --auto runs
148
+ if [[ ! "$ARGUMENTS" =~ --auto ]]; then
149
+ gsd_run query config-set workflow._auto_chain_active false || true
150
+ fi
151
+ ```
152
+
153
+ Resolve `MVP_MODE` once via the centralized `phase.mvp-mode` query verb (precedence chain: CLI flag → ROADMAP `**Mode:** mvp` → `workflow.mvp_mode` config → false):
154
+ ```bash
155
+ MVP_FLAG_ARG=""
156
+ if [[ "$ARGUMENTS" =~ (^|[[:space:]])--mvp([[:space:]]|$) ]]; then MVP_FLAG_ARG="--cli-flag"; fi
157
+ MVP_MODE=$(gsd_run query phase.mvp-mode "${PHASE_NUMBER}" $MVP_FLAG_ARG --pick active)
158
+ TDD_MODE=$(gsd_run query config-get workflow.tdd_mode 2>/dev/null || echo "false")
159
+ ```
160
+
161
+ <step name="safe_resume_gate">
162
+ Before trusting `STATE.md` or dispatching any executor, derive `CURRENT_PLAN_ID`
163
+ from the active incomplete plan in `INIT`, then search recent history:
164
+ ```bash
165
+ CURRENT_PLAN_ID="{phase_number}-{plan_padded}"
166
+ SUMMARY_PATH="{phase_dir}/{plan_padded}-SUMMARY.md"
167
+ PLAN_COMMITS=$(git log --oneline --grep="${CURRENT_PLAN_ID}" -30)
168
+ ```
169
+ If production commits exist and `SUMMARY.md is missing`, stop before spawning a
170
+ new executor; continuing risks duplicate work and stale `STATE.md`/ROADMAP progress.
171
+ Offer these recovery options:
172
+ - `close out manually` — inspect commits, write SUMMARY.md, then update STATE/ROADMAP.
173
+ - `re-execute from scratch` — revert or supersede partial commits before dispatch.
174
+ - `mark-and-skip` — record the anomaly and move on only with explicit confirmation.
175
+ </step>
176
+
177
+ **MVP+TDD gate.** Task-scoped enforcement runs inside plan execution (immediately before each implementation step), where `TASK_FILE`, `PLAN_ID`, and `TASK_ID` are defined. Keep the same predicate and RED-commit contract:
178
+ ```bash
179
+ if [ "$MVP_MODE" = "true" ] && [ "$TDD_MODE" = "true" ]; then
180
+ IS_BEHAVIOR_ADDING=$(gsd_run query task.is-behavior-adding "$TASK_FILE" --pick is_behavior_adding)
181
+ if [ "$IS_BEHAVIOR_ADDING" = "true" ]; then
182
+ RED_COMMIT=$(git log --oneline --grep="^test(${PHASE_NUMBER}-${PLAN_ID}):" -- "**/*.test.*" "**/*.spec.*" "tests/" | head -1)
183
+ if [ -z "$RED_COMMIT" ]; then
184
+ gsd_run query state.update last_gate_trip "${PLAN_ID}/${TASK_ID}" || true
185
+ echo "MVP+TDD GATE TRIPPED: missing RED commit for ${PLAN_ID}/${TASK_ID}"
186
+ exit 1
187
+ fi
188
+ fi
189
+ fi
190
+ ```
191
+ Pure doc-only / config-only / test-only tasks return `is_behavior_adding=false` and are exempt. See `execute-mvp-tdd.md` for the halt report format.
192
+ </step>
193
+
194
+ <step name="check_blocking_antipatterns" priority="first">
195
+ **MANDATORY — Check for blocking anti-patterns before any other work.**
196
+
197
+ Look for a `.continue-here.md` in the current phase directory:
198
+
199
+ ```bash
200
+ ls ${phase_dir}/.continue-here.md 2>/dev/null || true
201
+ ```
202
+
203
+ If `.continue-here.md` exists, parse its "Critical Anti-Patterns" table for rows with `severity` = `blocking`.
204
+
205
+ **If one or more `blocking` anti-patterns are found:**
206
+
207
+ This step cannot be skipped. Before proceeding to `check_interactive_mode` or any other step, the agent must demonstrate understanding of each blocking anti-pattern by answering all three questions for each one:
208
+
209
+ 1. **What is this anti-pattern?** — Describe it in your own words, not by quoting the handoff.
210
+ 2. **How did it manifest?** — Explain the specific failure that caused it to be recorded.
211
+ 3. **What structural mechanism (not acknowledgment) prevents it?** — Name the concrete step, checklist item, or enforcement mechanism that stops recurrence.
212
+
213
+ Write these answers inline before continuing. If a blocking anti-pattern cannot be answered from the context in `.continue-here.md`, stop and ask the user for clarification.
214
+
215
+ **If no `.continue-here.md` exists, or no `blocking` rows are found:** Proceed directly to `check_interactive_mode`.
216
+ </step>
217
+
218
+ <step name="check_interactive_mode">
219
+ **Parse `--interactive` flag from $ARGUMENTS.**
220
+
221
+ **If `--interactive` flag present:** Switch to interactive execution mode.
222
+
223
+ Interactive mode executes plans sequentially **inline** (no subagent spawning) with user
224
+ checkpoints between tasks. The user can review, modify, or redirect work at any point.
225
+
226
+ **Interactive execution flow:**
227
+
228
+ 1. Load plan inventory as normal (discover_and_group_plans)
229
+ 2. For each plan (sequentially, ignoring wave grouping):
230
+
231
+ a. **Present the plan to the user:**
232
+ ```
233
+ ## Plan {plan_id}: {plan_name}
234
+
235
+ Objective: {from plan file}
236
+ Tasks: {task_count}
237
+
238
+ Options:
239
+ - Execute (proceed with all tasks)
240
+ - Review first (show task breakdown before starting)
241
+ - Skip (move to next plan)
242
+ - Stop (end execution, save progress)
243
+ ```
244
+
245
+ b. **If "Review first":** Read and display the full plan file. Ask again: Execute, Modify, Skip.
246
+
247
+ c. **If "Execute":** Read and follow `~/.claude/get-shit-done/workflows/execute-plan.md` **inline**
248
+ (do NOT spawn a subagent). Execute tasks one at a time.
249
+
250
+ d. **After each task:** Pause briefly. If the user intervenes (types anything), stop and address
251
+ their feedback before continuing. Otherwise proceed to next task.
252
+
253
+ e. **After plan complete:** Show results, commit, create SUMMARY.md, then present next plan.
254
+
255
+ 3. After all plans: proceed to verification (same as normal mode).
256
+
257
+ **Benefits of interactive mode:**
258
+ - No subagent overhead — dramatically lower token usage
259
+ - User catches mistakes early — saves costly verification cycles
260
+ - Maintains GSD's planning/tracking structure
261
+ - Best for: small phases, bug fixes, verification gaps, learning GSD
262
+
263
+ **Skip to handle_branching step** (interactive plans execute inline after grouping).
264
+ </step>
265
+
266
+ <step name="handle_branching">
267
+ Check `branching_strategy` from init:
268
+
269
+ **"none":** Skip, continue on current branch.
270
+
271
+ **"phase" or "milestone":** Use pre-computed `branch_name` from init.
272
+
273
+ Fork the new phase branch off `origin/HEAD` (the project's default branch), not the current HEAD — otherwise consecutive phases compound and stay unpushed (#2916). If `$BRANCH_NAME` already exists locally, reuse it as-is.
274
+
275
+ ```bash
276
+ DEFAULT_BRANCH=$(git symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null | sed 's|^origin/||')
277
+ DEFAULT_BRANCH=${DEFAULT_BRANCH:-main}
278
+
279
+ if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then
280
+ git switch "$BRANCH_NAME" || { echo "ERROR: Could not switch to existing branch '$BRANCH_NAME'." >&2; exit 1; }
281
+ else
282
+ if ! git fetch --quiet origin "$DEFAULT_BRANCH"; then # #2916
283
+ git show-ref --verify --quiet "refs/remotes/origin/$DEFAULT_BRANCH" \
284
+ || { echo "ERROR: fetch origin/$DEFAULT_BRANCH failed and no local copy exists. Refusing to create '$BRANCH_NAME' off current HEAD (#2916)." >&2; exit 1; }
285
+ echo "WARNING: fetch origin/$DEFAULT_BRANCH failed; using local copy as base." >&2
286
+ fi
287
+ if [ -n "$(git status --porcelain)" ]; then
288
+ echo "WARNING: Uncommitted changes will be carried onto '$BRANCH_NAME' (branched off origin/$DEFAULT_BRANCH, not previous HEAD)."
289
+ else
290
+ git switch --quiet "$DEFAULT_BRANCH" 2>/dev/null && git merge --ff-only --quiet "origin/$DEFAULT_BRANCH" 2>/dev/null || true
291
+ fi
292
+ # Pinned base + fail-fast: on success HEAD is exactly at origin/$DEFAULT_BRANCH,
293
+ # so a post-creation merge-base or "ahead-of" guard would be unreachable. The
294
+ # explicit base argument here is the single source of correctness for #2916.
295
+ git checkout -b "$BRANCH_NAME" "origin/$DEFAULT_BRANCH" \
296
+ || { echo "ERROR: Could not create '$BRANCH_NAME' from origin/$DEFAULT_BRANCH (#2916)." >&2; exit 1; }
297
+ fi
298
+ ```
299
+
300
+ All subsequent commits go to this branch. User handles merging.
301
+ </step>
302
+
303
+ <step name="validate_phase">
304
+ From init JSON: `phase_dir`, `plan_count`, `incomplete_count`.
305
+
306
+ Report: "Found {plan_count} plans in {phase_dir} ({incomplete_count} incomplete)"
307
+
308
+ **Update STATE.md for phase start:**
309
+ ```bash
310
+ gsd_run query state.begin-phase --phase "${PHASE_NUMBER}" --name "${PHASE_NAME}" --plans "${PLAN_COUNT}"
311
+ ```
312
+ This updates Status, Last Activity, Current focus, Current Position, and plan counts in STATE.md so frontmatter and body text reflect the active phase immediately.
313
+ </step>
314
+
315
+ <step name="discover_and_group_plans">
316
+ Load plan inventory with wave grouping in one call:
317
+
318
+ ```bash
319
+ PLAN_INDEX=$(gsd_run query phase-plan-index "${PHASE_NUMBER}")
320
+ ```
321
+
322
+ Parse JSON for: `phase`, `plans[]` (each with `id`, `wave`, `autonomous`, `objective`, `files_modified`, `task_count`, `has_summary`), `waves` (map of wave number → plan IDs), `incomplete`, `has_checkpoints`.
323
+
324
+ **Filtering:** Skip plans where `has_summary: true`. If `--gaps-only`: also skip non-gap_closure plans. If `WAVE_FILTER` is set: also skip plans whose `wave` does not equal `WAVE_FILTER`.
325
+
326
+ **Wave safety check:** If `WAVE_FILTER` is set and there are still incomplete plans in any lower wave that match the current execution mode, STOP and tell the user to finish earlier waves first. Do not let Wave 2+ execute while prerequisite earlier-wave plans remain incomplete.
327
+
328
+ If all filtered: "No matching incomplete plans" → exit.
329
+
330
+ Report:
331
+ ```
332
+ ## Execution Plan
333
+
334
+ **Phase {X}: {Name}** — {total_plans} matching plans across {wave_count} wave(s)
335
+
336
+ {If WAVE_FILTER is set: `Wave filter active: executing only Wave {WAVE_FILTER}`.}
337
+
338
+ | Wave | Plans | What it builds |
339
+ |------|-------|----------------|
340
+ | 1 | 01-01, 01-02 | {from plan objectives, 3-8 words} |
341
+ | 2 | 01-03 | ... |
342
+ ```
343
+ </step>
344
+
345
+ <step name="cross_ai_delegation">
346
+ **Optional step 2.5 — Delegate plans to an external AI runtime.**
347
+
348
+ This step runs after plan discovery and before normal wave execution. It identifies plans
349
+ that should be delegated to an external AI command and executes them via stdin-based prompt
350
+ delivery. Plans handled here are removed from the execute_waves plan list so the normal
351
+ executor skips them.
352
+
353
+ **Activation logic:**
354
+
355
+ 1. If `CROSS_AI_DISABLED` is true (`--no-cross-ai` flag): skip this step entirely.
356
+ 2. If `CROSS_AI_FORCE` is true (`--cross-ai` flag): mark ALL incomplete plans for cross-AI execution.
357
+ 3. Otherwise: check each plan's frontmatter for `cross_ai: true` AND verify config
358
+ `workflow.cross_ai_execution` is `true`. Plans matching both conditions are marked for cross-AI.
359
+
360
+ ```bash
361
+ CROSS_AI_ENABLED=$(gsd_run query config-get workflow.cross_ai_execution 2>/dev/null || echo "false")
362
+ CROSS_AI_CMD=$(gsd_run query config-get workflow.cross_ai_command 2>/dev/null || echo "")
363
+ CROSS_AI_TIMEOUT=$(gsd_run query config-get workflow.cross_ai_timeout 2>/dev/null || echo "300")
364
+ ```
365
+
366
+ **If no plans are marked for cross-AI:** Skip to execute_waves.
367
+
368
+ **If plans are marked but `cross_ai_command` is empty:** Error — tell user to set
369
+ `workflow.cross_ai_command` via `gsd-tools.cjs query config-set workflow.cross_ai_command "<command>"`.
370
+
371
+ **For each cross-AI plan (sequentially):**
372
+
373
+ 1. **Construct the task prompt** from the plan file:
374
+ - Extract `<objective>` and `<tasks>` sections from the PLAN.md
375
+ - Append PROJECT.md context (project name, description, tech stack)
376
+ - Format as a self-contained execution prompt
377
+
378
+ 2. **Check for dirty working tree before execution:**
379
+ ```bash
380
+ if ! git diff --quiet HEAD 2>/dev/null; then
381
+ echo "WARNING: dirty working tree detected — the external AI command may produce uncommitted changes that conflict with existing modifications"
382
+ fi
383
+ ```
384
+
385
+ 3. **Run the external command** from the project root, writing the prompt to stdin.
386
+ Never shell-interpolate the prompt — always pipe via stdin to prevent injection:
387
+ ```bash
388
+ echo "$TASK_PROMPT" | timeout "${CROSS_AI_TIMEOUT}s" ${CROSS_AI_CMD} > "$CANDIDATE_SUMMARY" 2>"$ERROR_LOG"
389
+ EXIT_CODE=$?
390
+ ```
391
+
392
+ 4. **Evaluate the result:**
393
+
394
+ **Success (exit 0 + valid summary):**
395
+ - Read `$CANDIDATE_SUMMARY` and validate it contains meaningful content
396
+ (not empty, has at least a heading and description — a valid SUMMARY.md structure)
397
+ - Write it as the plan's SUMMARY.md file
398
+ - Update STATE.md plan status to complete
399
+ - Update ROADMAP.md progress
400
+ - Mark plan as handled — skip it in execute_waves
401
+
402
+ **Failure (non-zero exit or invalid summary):**
403
+ - Display the error output and exit code
404
+ - Warn: "The external command may have left uncommitted changes or partial edits
405
+ in the working tree. Review `git status` and `git diff` before proceeding."
406
+ - Offer three choices:
407
+ - **retry** — run the same plan through cross-AI again
408
+ - **skip** — fall back to normal executor for this plan (re-add to execute_waves list)
409
+ - **abort** — stop execution entirely, preserve state for resume
410
+
411
+ 5. **After all cross-AI plans processed:** Remove successfully handled plans from the
412
+ incomplete plan list so execute_waves skips them. Any skipped-to-fallback plans remain
413
+ in the list for normal executor processing.
414
+ </step>
415
+
416
+ <step name="execute_waves">
417
+ Execute each selected wave in sequence. Within a wave: parallel if `PARALLELIZATION=true`, sequential if `false`.
418
+
419
+ **Stream-idle-timeout prevention — checkpoint heartbeats (#2410):**
420
+
421
+ Multi-plan phases can accumulate enough subagent context that the Claude API
422
+ SSE layer terminates with `Stream idle timeout - partial response received`
423
+ between a large tool_result and the next assistant turn (seen on Claude Code
424
+ + Opus 4.7 at ~200K+ cache_read). To keep the stream warm, emit short
425
+ assistant-text heartbeats — **no tool call, just a literal line** — at every
426
+ wave and plan boundary. Each heartbeat MUST start with `[checkpoint]` so
427
+ tooling and `/gsd:manager`'s background-completion handler can grep partial
428
+ transcripts. `{P}/{Q}` is the phase-wide completed/total plans counter and
429
+ increases monotonically across waves. `{status}` is `complete` (success),
430
+ `failed` (executor error), or `checkpoint` (human-gate returned).
431
+
432
+ ```
433
+ [checkpoint] phase {PHASE_NUMBER} wave {N}/{M} starting, {wave_plan_count} plan(s), {P}/{Q} plans done
434
+ [checkpoint] phase {PHASE_NUMBER} wave {N}/{M} plan {plan_id} starting ({P}/{Q} plans done)
435
+ [checkpoint] phase {PHASE_NUMBER} wave {N}/{M} plan {plan_id} {status} ({P}/{Q} plans done)
436
+ [checkpoint] phase {PHASE_NUMBER} wave {N}/{M} complete, {P}/{Q} plans done ({wave_success}/{wave_plan_count} ok)
437
+ ```
438
+
439
+ **For each wave:**
440
+
441
+ 1. **Intra-wave files_modified overlap check (BEFORE spawning):**
442
+
443
+ Before spawning any agents for this wave, inspect the `files_modified` list of all plans
444
+ in the wave. Check every pair of plans in the wave — if any two plans share even one file
445
+ in their `files_modified` lists, those plans have an implicit dependency and MUST NOT run
446
+ in parallel.
447
+
448
+ **Detection algorithm (pseudocode):**
449
+ ```
450
+ seen_files = {}
451
+ overlapping_plans = []
452
+ for each plan in wave_plans:
453
+ for each file in plan.files_modified:
454
+ if file in seen_files:
455
+ overlapping_plans.add(plan, seen_files[file]) # both plans overlap on this file
456
+ else:
457
+ seen_files[file] = plan
458
+ ```
459
+
460
+ **If overlap is detected:**
461
+ - Warn the user:
462
+ ```
463
+ ⚠ Intra-wave files_modified overlap detected in Wave {N}:
464
+ Plan {A} and Plan {B} both modify {file}
465
+ Running these plans sequentially to avoid parallel worktree conflicts.
466
+ ```
467
+ - Override `PARALLELIZATION` to `false` for this wave only — run all plans in the wave
468
+ sequentially regardless of the global parallelization setting.
469
+ - This is a safety net for plans that were incorrectly assigned to the same wave.
470
+ The planner should have caught this; flag it as a planning defect so the user can
471
+ replan the phase if desired.
472
+
473
+ **If no overlap:** proceed normally (parallel if `PARALLELIZATION=true`).
474
+
475
+ 2. **Describe what's being built (BEFORE spawning):**
476
+
477
+ **First, emit the wave-start checkpoint heartbeat as a literal assistant-text
478
+ line — no tool call (#2410). Do NOT skip this even for single-plan waves; it
479
+ is required before any further reasoning or spawning:**
480
+
481
+ ```
482
+ [checkpoint] phase {PHASE_NUMBER} wave {N}/{M} starting, {wave_plan_count} plan(s), {P}/{Q} plans done
483
+ ```
484
+
485
+ Then read each plan's `<objective>`. Extract what's being built and why.
486
+
487
+ ```
488
+ ---
489
+ ## Wave {N}
490
+
491
+ **{Plan ID}: {Plan Name}**
492
+ {2-3 sentences: what this builds, technical approach, why it matters}
493
+
494
+ Spawning {count} agent(s)...
495
+ ---
496
+ ```
497
+
498
+ - Bad: "Executing terrain generation plan"
499
+ - Good: "Procedural terrain generator using Perlin noise — creates height maps, biome zones, and collision meshes. Required before vehicle physics can interact with ground."
500
+
501
+ 2.5. **Per-plan worktree decision (run for each plan in this wave BEFORE its dispatch):**
502
+
503
+ Read and execute `get-shit-done/workflows/execute-phase/steps/per-plan-worktree-gate.md` for each plan. It extracts `PLAN_FILES` from the plan's JSON, intersects against `SUBMODULE_PATHS` (with normalization, bidirectional matching, and glob-prefix handling), and sets `USE_WORKTREES_FOR_PLAN` to `false` when the plan touches a submodule path. Append `plan_id` to a `WAVE_WORKTREE_PLANS` accumulator when `USE_WORKTREES_FOR_PLAN != false`.
504
+
505
+ The dispatch branches in step 3 below MUST gate on `USE_WORKTREES_FOR_PLAN` for the current plan, not on the project-level `USE_WORKTREES`.
506
+
507
+ 3. **Spawn executor agents:**
508
+
509
+ **Emit a plan-start heartbeat (literal line, no tool call) immediately before
510
+ each `Agent()` dispatch (#2410):**
511
+
512
+ `[checkpoint] phase {PHASE_NUMBER} wave {N}/{M} plan {plan_id} starting ({P}/{Q} plans done)`
513
+
514
+ Pass paths only — executors read files themselves with their fresh context window.
515
+ For 200k models, this keeps orchestrator context lean (~10-15%).
516
+ For 1M+ models (Opus 4.6, Sonnet 4.6), richer context can be passed directly.
517
+
518
+ **Worktree mode** (`USE_WORKTREES_FOR_PLAN` is not `false` — evaluated per-plan in step 2.5):
519
+
520
+ Before spawning, capture the current HEAD:
521
+ ```bash
522
+ EXPECTED_BASE=$(git rev-parse HEAD)
523
+ DISPATCH_TS=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
524
+ EXPECTED_BRANCH=$(git rev-parse --abbrev-ref HEAD)
525
+ if [ "${USE_WORKTREES_FOR_PLAN:-true}" != "false" ] && [ -z "${WAVE_WORKTREE_MANIFEST:-}" ]; then
526
+ WAVE_WORKTREE_MANIFEST=$(mktemp "${TMPDIR:-/tmp}/gsd-worktree-wave-XXXXXX.json")
527
+ printf '{"worktrees":[]}\n' > "$WAVE_WORKTREE_MANIFEST"
528
+ export WAVE_WORKTREE_MANIFEST
529
+ fi
530
+ ```
531
+
532
+ **Sequential dispatch for parallel execution (waves with 2+ agents):**
533
+ Dispatch each `Agent()` call **one at a time with `run_in_background: true`**. Do NOT
534
+ send all Agent calls in a single message: simultaneous `git worktree add` calls race
535
+ on `.git/config.lock`. Agents still run in parallel once their worktrees are created.
536
+
537
+ ```text
538
+ # CORRECT: one Agent() per message with run_in_background: true
539
+ # WRONG: multiple Agent() calls in one message -> .git/config.lock contention
540
+ ```
541
+
542
+ ```text
543
+ Agent(
544
+ subagent_type="gsd-executor",
545
+ description="Execute plan {plan_number} of phase {phase_number}",
546
+ # Only include model= when executor_model is an explicit model name.
547
+ # When executor_model is "inherit", omit this parameter entirely so
548
+ # Claude Code inherits the orchestrator model automatically.
549
+ model="{executor_model}", # omit this line when executor_model == "inherit"
550
+ isolation="worktree",
551
+ prompt="
552
+ <objective>
553
+ Execute plan {plan_number} of phase {phase_number}-{phase_name}.
554
+ Commit each task atomically. Create SUMMARY.md.
555
+ Do NOT update STATE.md or ROADMAP.md — the orchestrator owns those writes after all worktree agents in the wave complete.
556
+ </objective>
557
+
558
+ <worktree_branch_check>
559
+ FIRST ACTION: HEAD assertion MUST run before any reset/checkout. Worktrees
560
+ spawned by Claude Code's `isolation="worktree"` use the `worktree-agent-<id>`
561
+ namespace. If HEAD is on a protected ref (main/master/develop/trunk/release/*)
562
+ or detached, HALT — do NOT self-recover by force-rewinding via `git update-ref`,
563
+ that destroys concurrent commits in multi-active scenarios (#2924). Only after
564
+ Step 1 passes is `git reset --hard` safe (#2015 — affects all platforms).
565
+ ```bash
566
+ HEAD_REF=$(git symbolic-ref --quiet HEAD || echo "DETACHED")
567
+ ACTUAL_BRANCH=$(git rev-parse --abbrev-ref HEAD)
568
+ if [ "$HEAD_REF" = "DETACHED" ] || echo "$ACTUAL_BRANCH" | grep -Eq '^(main|master|develop|trunk|release/.*)$'; then
569
+ echo "FATAL: worktree HEAD on '$ACTUAL_BRANCH' (expected worktree-agent-*); refusing to self-recover via 'git update-ref' (#2924)." >&2
570
+ exit 1
571
+ fi
572
+ if ! echo "$ACTUAL_BRANCH" | grep -Eq '^worktree-agent-[A-Za-z0-9._/-]+$'; then
573
+ echo "FATAL: worktree HEAD '$ACTUAL_BRANCH' is not in the worktree-agent-* namespace; refusing to commit (#2924)." >&2
574
+ exit 1
575
+ fi
576
+ ACTUAL_BASE=$(git merge-base HEAD {EXPECTED_BASE})
577
+ if [ "$ACTUAL_BASE" != "{EXPECTED_BASE}" ]; then
578
+ git reset --hard {EXPECTED_BASE}
579
+ [ "$(git rev-parse HEAD)" != "{EXPECTED_BASE}" ] && { echo "ERROR: could not correct worktree base"; exit 1; }
580
+ fi
581
+ ```
582
+ Per-commit HEAD/cwd-drift/path-guard: `agents/gsd-executor.md` steps 0/0a/0b + `references/worktree-path-safety.md` (in <execution_context>).
583
+ </worktree_branch_check>
584
+
585
+ <parallel_execution>
586
+ You are running as a PARALLEL executor agent in a git worktree. Worktree path safety (cwd-drift, absolute-path guards) is in `worktree-path-safety.md` (loaded below).
587
+ Run `git commit` normally — hooks run by default. Do NOT pass `--no-verify`
588
+ unless the orchestrator surfaces `workflow.worktree_skip_hooks=true` in this
589
+ prompt; silent bypass violates project CLAUDE.md guidance (#2924).
590
+
591
+ IMPORTANT: Do NOT modify STATE.md or ROADMAP.md. execute-plan.md
592
+ auto-detects worktree mode (`.git` is a file, not a directory) and skips
593
+ shared file updates automatically. The orchestrator updates them centrally
594
+ after merge.
595
+
596
+ REQUIRED: SUMMARY.md MUST be committed before you return. In worktree mode the
597
+ git_commit_metadata step in execute-plan.md commits SUMMARY.md and REQUIREMENTS.md
598
+ only (STATE.md and ROADMAP.md are excluded automatically). Do NOT skip or defer
599
+ this commit — the orchestrator force-removes the worktree after you return, and
600
+ any uncommitted SUMMARY.md will be permanently lost (#2070).
601
+ REQUIRED ORDER: Write SUMMARY.md → commit → only then any narration. No text between Write and commit (truncation risk; #2070 rescue is not primary defense).
602
+ </parallel_execution>
603
+
604
+ <execution_context>
605
+ @~/.claude/get-shit-done/workflows/execute-plan.md
606
+ @~/.claude/get-shit-done/templates/summary.md
607
+ @~/.claude/get-shit-done/references/checkpoints.md
608
+ @~/.claude/get-shit-done/references/tdd.md
609
+ @~/.claude/get-shit-done/references/worktree-path-safety.md
610
+ ${CONTEXT_WINDOW < 200000 ? '' : '@~/.claude/get-shit-done/references/executor-examples.md'}
611
+ </execution_context>
612
+
613
+ <files_to_read>
614
+ Read these files at execution start using the Read tool.
615
+ First resolve repo root so every path is anchored:
616
+ \`PROJECT_ROOT=$(git rev-parse --show-toplevel 2>/dev/null)\`
617
+ - ${PROJECT_ROOT}/{phase_dir}/{plan_file} (Plan)
618
+ - ${PROJECT_ROOT}/.planning/PROJECT.md (Project context — core value, requirements, evolution rules)
619
+ - ${PROJECT_ROOT}/.planning/STATE.md (State)
620
+ - ${PROJECT_ROOT}/.planning/config.json (Config, if exists)
621
+ ${CONTEXT_WINDOW >= 500000 ? `
622
+ - ${PROJECT_ROOT}/${phase_dir}/*-CONTEXT.md (User decisions from discuss-phase — honors locked choices)
623
+ - ${PROJECT_ROOT}/${phase_dir}/*-RESEARCH.md (Technical research — pitfalls and patterns to follow)
624
+ - ${PROJECT_ROOT}/${prior_wave_summaries} (SUMMARY.md files from earlier waves in this phase — what was already built)
625
+ ` : ''}
626
+ - ${PROJECT_ROOT}/CLAUDE.md (Project instructions, if exists — follow project-specific guidelines and coding conventions)
627
+ - ${PROJECT_ROOT}/.claude/skills/ or ${PROJECT_ROOT}/.agents/skills/ (Project skills, if either exists — list skills, read SKILL.md for each, follow relevant rules during implementation)
628
+ </files_to_read>
629
+
630
+ ${AGENT_SKILLS}
631
+
632
+ <mcp_tools>
633
+ If CLAUDE.md or project instructions reference MCP tools (e.g. jCodeMunch, context7,
634
+ or other MCP servers), prefer those tools over Grep/Glob for code navigation when available.
635
+ MCP tools often save significant tokens by providing structured code indexes.
636
+ Check tool availability first — if MCP tools are not accessible, fall back to Grep/Glob.
637
+ </mcp_tools>
638
+
639
+ <success_criteria>
640
+ - [ ] All tasks executed
641
+ - [ ] Each task committed individually
642
+ - [ ] SUMMARY.md created in plan directory
643
+ - [ ] No modifications to shared orchestrator artifacts (the orchestrator handles all post-wave shared-file writes)
644
+ </success_criteria>
645
+ "
646
+ )
647
+ ```
648
+
649
+ Immediately after each worktree `Agent()` spawn returns metadata, atomically append `{agent_id, worktree_path, branch, expected_base}` to `WAVE_WORKTREE_MANIFEST`. If any field is missing, stop and ask for recovery instead of scanning all agent worktrees.
650
+
651
+ > **ORCHESTRATOR RULE — CODEX RUNTIME**: After calling Agent() above to spawn executor agent(s), 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.
652
+
653
+ **Sequential mode** (`USE_WORKTREES_FOR_PLAN` is `false` — either project-level `USE_WORKTREES=false`, or per-plan submodule intersection forced it false in step 2.5):
654
+
655
+ Omit `isolation="worktree"` from the Agent call. Replace the `<parallel_execution>` block with:
656
+
657
+ ```
658
+ <sequential_execution>
659
+ You are running as a SEQUENTIAL executor agent on the main working tree.
660
+ Use normal git commits (with hooks). Do NOT use --no-verify.
661
+ REQUIRED ORDER: Write SUMMARY.md → commit → only then any narration. No text between Write and commit (truncation risk; #2070 rescue is not primary defense).
662
+ </sequential_execution>
663
+ ```
664
+
665
+ The sequential mode Agent prompt uses the same structure as worktree mode but with these differences in success_criteria — since there is only one agent writing at a time, there are no shared-file conflicts:
666
+
667
+ ```
668
+ <success_criteria>
669
+ - [ ] All tasks executed
670
+ - [ ] Each task committed individually
671
+ - [ ] SUMMARY.md created in plan directory
672
+ - [ ] STATE.md updated with position and decisions
673
+ - [ ] ROADMAP.md updated with plan progress (via `roadmap update-plan-progress`)
674
+ </success_criteria>
675
+ ```
676
+
677
+ When worktrees are disabled for a plan (per-plan or project-level), that plan's executor runs on the main working tree. If **any** plan in the current wave dropped to sequential mode, execute the affected plan(s) **one at a time** to avoid concurrent writes to the main working tree — plans in the same wave that retained worktree isolation can still run in parallel alongside the sequential ones, but two non-worktree plans in the same wave must serialize. When the project-level `USE_WORKTREES=false`, all plans in the wave serialize regardless of the `PARALLELIZATION` setting.
678
+
679
+ 4. **Wait for all agents in wave to complete.**
680
+
681
+ **Plan-complete heartbeat (#2410):** as each executor returns (or is verified
682
+ via spot-check below), emit one line — `complete` advances `{P}`, `failed`
683
+ and `checkpoint` do not but still warm the stream:
684
+
685
+ ```
686
+ [checkpoint] phase {PHASE_NUMBER} wave {N}/{M} plan {plan_id} complete ({P}/{Q} plans done)
687
+ [checkpoint] phase {PHASE_NUMBER} wave {N}/{M} plan {plan_id} failed ({P}/{Q} plans done)
688
+ [checkpoint] phase {PHASE_NUMBER} wave {N}/{M} plan {plan_id} checkpoint ({P}/{Q} plans done)
689
+ ```
690
+
691
+ **Completion signal fallback (Copilot and runtimes where Agent() may not return):**
692
+
693
+ If a spawned agent does not return a completion signal but appears to have finished
694
+ its work, do NOT block indefinitely. Instead, verify completion via spot-checks:
695
+
696
+ ```bash
697
+ # For each plan in this wave, check if the executor finished:
698
+ SUMMARY_EXISTS=$(test -f "{phase_dir}/{plan_number}-{plan_padded}-SUMMARY.md" && echo "true" || echo "false")
699
+ COMMITS_FOUND=$(git log --oneline --all --grep="{phase_number}-{plan_padded}" --since="1 hour ago" | head -1)
700
+ COMMITS_SINCE_DISPATCH=$(git log "${EXPECTED_BRANCH}" --since="${DISPATCH_TS}" --oneline | head -1)
701
+ ```
702
+
703
+ **If SUMMARY.md exists AND commits are found:** The agent completed successfully —
704
+ treat as done and proceed to step 5. Log: `"✓ {Plan ID} completed (verified via spot-check — completion signal not received)"`
705
+
706
+ **If SUMMARY.md does NOT exist after a reasonable wait:** The agent may still be
707
+ running or may have failed silently. Check `git log --oneline -5` for recent
708
+ activity. If commits are still appearing, wait longer. If no activity, report
709
+ the plan as failed and route to the failure handler in step 6.
710
+
711
+ **Configurable stall surveillance (#3212):** Every `${EXECUTOR_STALL_INTERVAL_MINUTES}`
712
+ minutes while waiting, inspect `git log "${EXPECTED_BRANCH}" --since="${DISPATCH_TS}"`
713
+ for activity. If no completion signal, no SUMMARY.md, and no expected-branch
714
+ commits appear for `${EXECUTOR_STALL_THRESHOLD_MINUTES}` minutes, pause and
715
+ ask for one recovery path: `continue waiting`, `kill and retry`, or
716
+ `kill and switch to inline execution`.
717
+
718
+ **This fallback applies automatically to all runtimes.** Claude Code's Agent() normally
719
+ returns synchronously, but the fallback ensures resilience if it doesn't.
720
+
721
+ 5. **Post-wave hook validation (parallel mode only):** Hooks run on every executor commit by default (#2924); this post-wave run only fires when `workflow.worktree_skip_hooks=true` opted out of per-commit hooks:
722
+ ```bash
723
+ SKIP_HOOKS=$(gsd_run query config-get workflow.worktree_skip_hooks 2>/dev/null || echo "false")
724
+ if [ "$SKIP_HOOKS" = "true" ]; then
725
+ # Stash uncommitted changes under a named ref so we always pop (bare `git stash` strands them on hook/script failure). #3542: `refs/stash` is shared across worktrees, so this helper runs ONLY in the orchestrator's main checkout after all wave worktrees have been merged + removed; executors are forbidden from running any `git stash` subcommand (see `<destructive_git_prohibition>` in `agents/gsd-executor.md`).
726
+ STASHED=false
727
+ if (! git diff --quiet || ! git diff --cached --quiet) && git stash push -u -m "gsd-post-wave-hook-$$" >/dev/null 2>&1; then STASHED=true; fi
728
+ git hook run pre-commit 2>&1 || echo "⚠ Pre-commit hooks failed — review before continuing"
729
+ [ "$STASHED" = "true" ] && (git stash pop >/dev/null 2>&1 || echo "⚠ Could not pop gsd-post-wave-hook stash — recover manually")
730
+ fi
731
+ ```
732
+ If hooks fail: report the failure and ask "Fix hook issues now?" or "Continue to next wave?"
733
+
734
+ 5.5. **Worktree cleanup (when `isolation="worktree"` was used):**
735
+
736
+ **Standard wave contract:** Each wave's worktrees merge to main via the templated path below before the next wave's worktrees fork. The cleanup loop runs once per wave at the end of the wave lifecycle. Worktrees created in wave N must be fully removed before wave N+1 forks new ones.
737
+
738
+ **Cross-wave dependency deviation (supported execution mode):** When the orchestrator legitimately deviates from the standard wave model — for example, a phase with cross-wave plan dependencies that requires custom inter-worktree base-update merges (e.g., `merge: bring 09-01 + 09-02 into 09-03 base`) — the cleanup loop below is NOT automatically re-entered for those custom merges. The deviation path produces correct final history but bypasses this loop, leaving `worktree-agent-*` directories in place. Use the **cleanup-tail snippet** below to remove any residual worktrees after such a deviation.
739
+
740
+ When executor agents ran in worktree isolation, their commits land on temporary branches in separate working trees. After the wave completes, merge these changes back and clean up:
741
+
742
+ **Manifest source of truth (#3384):** Cleanup consumes the `WAVE_WORKTREE_MANIFEST` created and populated during executor dispatch in step 3. Do not recreate or truncate it here.
743
+
744
+ Prefer the bounded helper, which validates branch identity, expected base, deletion
745
+ diffs, merge result, and worktree removal before deleting the temporary branch.
746
+ If the helper reports a blocked cleanup, resolve the reported manifest entry and
747
+ rerun the same command. Do not fall back to broad worktree discovery.
748
+
749
+ ```bash
750
+ [ -n "${WAVE_WORKTREE_MANIFEST:-}" ] && [ -f "$WAVE_WORKTREE_MANIFEST" ] || {
751
+ echo "BLOCKED: missing WAVE_WORKTREE_MANIFEST; refusing broad worktree cleanup (#3384)." >&2
752
+ exit 1
753
+ }
754
+
755
+ # Guard: pin cleanup back to the primary worktree and fail on branch drift (#3174).
756
+ PRIMARY_WT=$(git worktree list --porcelain | awk '/^worktree /{print substr($0,10); exit}')
757
+ if [ -z "$PRIMARY_WT" ]; then
758
+ echo "FATAL: could not resolve primary worktree before cleanup" >&2
759
+ exit 1
760
+ fi
761
+ if [ -n "$PRIMARY_WT" ] && [ "$(pwd -P 2>/dev/null)" != "$(cd "$PRIMARY_WT" 2>/dev/null && pwd -P)" ]; then echo "⚠ Orchestrator CWD drifted to $(pwd) — pinning to $PRIMARY_WT before worktree cleanup (#3174)"; cd "$PRIMARY_WT" || { echo "FATAL: cannot cd to primary worktree $PRIMARY_WT" >&2; exit 1; }; fi
762
+ ORCH_BRANCH=$(git rev-parse --abbrev-ref HEAD)
763
+ [ -z "${EXPECTED_BRANCH:-}" ] || [ "$ORCH_BRANCH" = "$EXPECTED_BRANCH" ] || { echo "FATAL: orchestrator on '$ORCH_BRANCH' but expected '$EXPECTED_BRANCH' before worktree cleanup — refusing to merge (#3174-class drift)" >&2; exit 1; }
764
+
765
+ # Fail closed: SDK refusal (safety guard #3174/#3384) must surface — do not swallow exit 1.
766
+ gsd_run query worktree.cleanup-wave --manifest "$WAVE_WORKTREE_MANIFEST" || exit 1
767
+ ```
768
+
769
+ **Cleanup-tail snippet (use after any wave whose merges did not flow through the templated path above):**
770
+
771
+ If the orchestrator deviated from the standard wave merge path (e.g., custom inter-worktree base-update merges with `merge: bring …` style messages), run this snippet after the custom merges are complete. It reads only `WAVE_WORKTREE_MANIFEST`; do not discover unrelated `worktree-agent-*` worktrees.
772
+
773
+ ```bash
774
+ # Cleanup-tail: pin orchestrator CWD to primary worktree before cleanup-tail (#3174).
775
+ PRIMARY_WT=$(git worktree list --porcelain | awk '/^worktree /{print substr($0,10); exit}')
776
+ if [ -n "$PRIMARY_WT" ] && [ "$(pwd -P 2>/dev/null)" != "$(cd "$PRIMARY_WT" 2>/dev/null && pwd -P)" ]; then echo "⚠ Orchestrator CWD drifted to $(pwd) — pinning to $PRIMARY_WT before cleanup-tail (#3174)"; cd "$PRIMARY_WT" || { echo "FATAL: cannot cd to primary worktree $PRIMARY_WT" >&2; exit 1; }; fi
777
+ # Cleanup-tail: remove residual agent worktrees after a cross-wave-dependency deviation.
778
+ # Uses only the current wave manifest to avoid touching unrelated active agents (#3384).
779
+ WT_PATHS_FILE=$(mktemp "${TMPDIR:-/tmp}/gsd-worktree-paths-XXXXXX")
780
+ node -e 'const fs=require("fs");const p=process.env.WAVE_WORKTREE_MANIFEST;try{if(!p)throw new Error("WAVE_WORKTREE_MANIFEST is unset");if(!fs.existsSync(p))throw new Error("manifest does not exist");const s=fs.readFileSync(p,"utf8");if(!s.trim())throw new Error("manifest is empty");const j=JSON.parse(s);for(const w of j.worktrees||[])if(w.worktree_path)console.log(w.worktree_path)}catch(e){console.error(`ERROR: cannot read worktree manifest ${p||"(unset)"}: ${e.message}`);process.exit(1)}' > "$WT_PATHS_FILE" || { echo "BLOCKED: cannot read WAVE_WORKTREE_MANIFEST; refusing cleanup (#3384)." >&2; exit 1; }
781
+ while IFS= read -r WT; do
782
+ [ -z "$WT" ] && continue
783
+ WT_BRANCH=$(git -C "$WT" rev-parse --abbrev-ref HEAD 2>/dev/null)
784
+ [ -z "$WT_BRANCH" ] || [ "$WT_BRANCH" = "HEAD" ] && continue
785
+ echo "Cleaning up residual worktree: $WT (branch: $WT_BRANCH)"
786
+ git worktree unlock "$WT" 2>/dev/null || true
787
+ if ! git worktree remove "$WT" --force; then
788
+ WT_NAME=$(basename "$WT")
789
+ if [ -f ".git/worktrees/${WT_NAME}/locked" ]; then
790
+ echo "⚠ Worktree $WT is locked — unlock failed; manual cleanup required:"
791
+ echo " git worktree unlock \"$WT\" && git worktree remove \"$WT\" --force && git branch -D \"$WT_BRANCH\""
792
+ else
793
+ echo "⚠ Residual worktree at $WT — remove failed; manual cleanup required"
794
+ fi
795
+ else
796
+ git branch -D "$WT_BRANCH" 2>/dev/null || true
797
+ fi
798
+ done < "$WT_PATHS_FILE"
799
+ git worktree prune
800
+ ```
801
+
802
+ **When to skip step 5.5:**
803
+
804
+ **If no plan in this wave used worktree isolation** (project-level `USE_WORKTREES=false` OR every plan in the wave had `USE_WORKTREES_FOR_PLAN=false` — i.e. `WAVE_WORKTREE_PLANS` from step 2.5 is empty): all agents ran on the main working tree — skip this step entirely.
805
+
806
+ **If the orchestrator merged via custom messages (cross-wave-dependency deviation):** the templated cleanup loop above was not triggered for those merges. Run the cleanup-tail snippet above instead. After the snippet completes, proceed to step 5.6.
807
+
808
+ **If at least one plan used worktrees but others did not:** still run this cleanup — it iterates over actual `git worktree list` output and only merges back the worktrees that were created, leaving sequential plans' commits on the main tree untouched.
809
+
810
+ **If no worktrees found at runtime:** Skip silently — agents may have been spawned without worktree isolation, or the orchestrator already cleaned them up.
811
+
812
+ 5.6. **Post-merge build & test gate:**
813
+
814
+ After merging all worktrees in a wave (parallel mode), or after the last plan completes
815
+ (serial mode), run a build and then the project's test suite to catch cross-plan
816
+ integration issues that individual worktree self-checks cannot detect (e.g., conflicting
817
+ type definitions, removed exports, import changes, link errors).
818
+
819
+ This addresses the Generator self-evaluation blind spot identified in Anthropic's
820
+ harness engineering research: agents reliably report Self-Check: PASSED even when
821
+ merging their work creates failures.
822
+
823
+ Read and execute `get-shit-done/workflows/execute-phase/steps/post-merge-gate.md`.
824
+
825
+ 5.7. **Post-wave shared artifact update (when at least one plan used worktrees, skip if tests failed):**
826
+
827
+ When **any** executor agent in this wave ran with `isolation="worktree"`, that agent skipped STATE.md and ROADMAP.md updates to avoid last-merge-wins overwrites. The orchestrator is the single writer for these files. After worktrees are merged back, update shared artifacts once for every completed plan in the wave (worktree-mode plans **and** sequential plans that ran on the main tree but deferred to the orchestrator for tracking writes).
828
+
829
+ **Only update tracking when tests passed (TEST_EXIT=0).**
830
+ If tests failed or timed out, skip the tracking update — plans should
831
+ not be marked as complete when integration tests are failing or inconclusive.
832
+
833
+ ```bash
834
+ # Guard: only update tracking if post-merge tests passed
835
+ # Timeout (124) is treated as inconclusive — do NOT mark plans complete
836
+ if [ "${TEST_EXIT}" -eq 0 ]; then
837
+ # Update ROADMAP plan progress for each completed plan in this wave
838
+ for plan_id in {completed_plan_ids}; do
839
+ gsd_run query roadmap.update-plan-progress "${PHASE_NUMBER}" "${plan_id}" "complete"
840
+ done
841
+
842
+ # Only commit tracking files if they actually changed
843
+ if ! git diff --quiet .planning/ROADMAP.md .planning/STATE.md 2>/dev/null; then
844
+ gsd_run query commit "docs(phase-${PHASE_NUMBER}): update tracking after wave ${N}" --files .planning/ROADMAP.md .planning/STATE.md
845
+ fi
846
+ elif [ "${TEST_EXIT}" -eq 124 ]; then
847
+ echo "⚠ Skipping tracking update — test suite timed out. Plans remain in-progress. Run tests manually to confirm."
848
+ else
849
+ echo "⚠ Skipping tracking update — post-merge tests failed (exit ${TEST_EXIT}). Plans remain in-progress until tests pass."
850
+ fi
851
+ ```
852
+
853
+ Where `WAVE_PLAN_IDS` is the space-separated list of plan IDs that completed in this wave.
854
+
855
+ **If no plan in this wave used worktrees** (project-level `USE_WORKTREES=false` OR `WAVE_WORKTREE_PLANS` is empty): sequential agents already updated STATE.md and ROADMAP.md themselves — skip this step.
856
+
857
+ 5.8. **Handle test gate failures (when `WAVE_FAILURE_COUNT > 0`):**
858
+
859
+ ```
860
+ ## ⚠ Post-Merge Test Failure (cumulative failures: ${WAVE_FAILURE_COUNT})
861
+
862
+ Wave {N} worktrees merged successfully, but {M} tests fail after merge.
863
+ This typically indicates conflicting changes across parallel plans
864
+ (e.g., type definitions, shared imports, API contracts).
865
+
866
+ Failed tests:
867
+ {first 10 lines of failure output}
868
+
869
+ Options:
870
+ 1. Fix now (recommended) — resolve conflicts before next wave
871
+ 2. Continue — failures may compound in subsequent waves
872
+ ```
873
+
874
+ Note: If `WAVE_FAILURE_COUNT > 1`, strongly recommend "Fix now" — compounding
875
+ failures across multiple waves become exponentially harder to diagnose.
876
+
877
+ If "Fix now": diagnose failures (typically import conflicts, missing types,
878
+ or changed function signatures from parallel plans modifying the same module).
879
+ Fix, commit as `fix: resolve post-merge conflicts from wave {N}`, re-run tests.
880
+
881
+ **Why this matters:** Worktree isolation means each agent's Self-Check passes
882
+ in isolation. But when merged, add/add conflicts in shared files (models, registries,
883
+ CLI entry points) can silently drop code. The post-merge gate catches this before
884
+ the next wave builds on a broken foundation.
885
+
886
+ 6. **Report completion — spot-check claims first:**
887
+
888
+ **Wave-close heartbeat (#2410):** after spot-checks finish (pass or fail),
889
+ before the `## Wave {N} Complete` summary, emit as a literal line:
890
+
891
+ ```
892
+ [checkpoint] phase {PHASE_NUMBER} wave {N}/{M} complete, {P}/{Q} plans done ({wave_success}/{wave_plan_count} ok)
893
+ ```
894
+
895
+
896
+
897
+ For each SUMMARY.md:
898
+ - Verify first 2 files from `key-files.created` exist on disk
899
+ - Check `git log --oneline --all --grep="{phase}-{plan}"` returns ≥1 commit
900
+ - Check for `## Self-Check: FAILED` marker
901
+
902
+ If ANY spot-check fails: report which plan failed, route to failure handler — ask "Retry plan?" or "Continue with remaining waves?"
903
+
904
+ If pass:
905
+ ```
906
+ ---
907
+ ## Wave {N} Complete
908
+
909
+ **{Plan ID}: {Plan Name}**
910
+ {What was built — from SUMMARY.md}
911
+ {Notable deviations, if any}
912
+
913
+ {If more waves: what this enables for next wave}
914
+ ---
915
+ ```
916
+
917
+ 7. **Handle failures:**
918
+ **Step 7.0 — classify before branching (#3095):**
919
+ ```bash
920
+ CLASS_JSON=$(gsd_run query agent.classify-failure -- "$AGENT_RETURN_BODY")
921
+ CLASS=$(echo "$CLASS_JSON" | jq -r '.class')
922
+ SENTINEL=$(echo "$CLASS_JSON" | jq -r '.sentinel // empty')
923
+ RETRY_AFTER=$(echo "$CLASS_JSON" | jq -r '.retryAfterSeconds // empty')
924
+ if [ -n "$RETRY_AFTER" ]; then RETRY_HINT=" Provider hinted retry-after: ${RETRY_AFTER}s"; else RETRY_HINT=""; fi
925
+ ```
926
+ One classifier branch handles sentinels across Claude/Copilot/Codex/Gemini. Reference: `docs/research/provider-rate-limit-signals.md`.
927
+ **Step 7.1 — `class == "quota-exceeded"`:**
928
+ Do not offer "retry now". Run step-5 spot-check first; if SUMMARY.md is missing but commits exist, route to safe-resume (`state.verify-against-disk`) instead of immediate redispatch.
929
+ ```text
930
+ ⚠ Plan {plan_id} terminated by provider quota / rate limit
931
+ Runtime sentinel: {SENTINEL}
932
+ {RETRY_HINT}
933
+ Partial commits on worktree branch: {N}
934
+ SUMMARY.md present: {yes|no}
935
+ 1. Wait for quota reset, then resume (recommended)
936
+ 2. Switch to a different runtime / model and resume
937
+ 3. Abort phase and report partial state
938
+ ```
939
+ Re-run `/gsd:execute-phase` after quota reset for Option 1.
940
+ **Step 7.2 — `class == "classify-handoff-bug"`:**
941
+ If error contains `classifyHandoffIfNeeded is not defined`, treat as Claude runtime bug. Run the same step-5 spot-checks; PASS => treat as success, FAIL => fall through.
942
+ **Step 7.3 — `class == "unknown-failure"`:**
943
+ Report failed plan and ask Continue/Stop; continuing may cascade into dependent plan failures.
944
+
945
+ 7b. **Pre-wave dependency check (waves 2+ only):**
946
+ Before wave N+1, run `gsd-tools.cjs query verify.key-links {phase_dir}/{plan}-PLAN.md` for each upcoming plan.
947
+ If any PRIOR-wave artifact link fails, present:
948
+ - `## Cross-Plan Wiring Gap` with plan/link/from/pattern rows
949
+ - Options: investigate+fix before continue, or continue with cascade risk
950
+ Skip key-links that reference files in the CURRENT (upcoming) wave.
951
+ 8. **Execute checkpoint plans between waves** — see `<checkpoint_handling>`.
952
+ 9. **Proceed to next wave.**
953
+ </step>
954
+ <step name="checkpoint_handling">
955
+ Plans with `autonomous: false` require user interaction.
956
+ **Auto-mode checkpoint handling:**
957
+ Read auto-advance config (chain flag OR user preference — same boolean as `check.auto-mode`):
958
+ ```bash
959
+ AUTO_MODE=$(gsd_run query check auto-mode --pick active 2>/dev/null || echo "false")
960
+ ```
961
+
962
+ When executor returns a checkpoint AND `AUTO_MODE` is `true`:
963
+ - **human-verify** → Auto-spawn continuation agent with `{user_response}` = `"approved"`. Log `⚡ Auto-approved checkpoint`.
964
+ - **decision** → Auto-spawn continuation agent with `{user_response}` = first option from checkpoint details. Log `⚡ Auto-selected: [option]`.
965
+ - **human-action** → Present to user (existing behavior below). Auth gates cannot be automated.
966
+
967
+ **Standard flow (not auto-mode, or human-action type):**
968
+
969
+ 1. Spawn agent for checkpoint plan
970
+ 2. Agent runs until checkpoint task or auth gate → returns structured state
971
+ 3. Agent return includes: completed tasks table, current task + blocker, checkpoint type/details, what's awaited
972
+ 4. **Present to user:**
973
+ ```
974
+ ## Checkpoint: [Type]
975
+
976
+ **Plan:** 03-03 Dashboard Layout
977
+ **Progress:** 2/3 tasks complete
978
+
979
+ [Checkpoint Details from agent return]
980
+ [Awaiting section from agent return]
981
+ ```
982
+ 5. User responds: "approved"/"done" | issue description | decision selection
983
+ 6. **Spawn continuation agent (NOT resume)** using continuation-prompt.md template:
984
+ - `{completed_tasks_table}`: From checkpoint return
985
+ - `{resume_task_number}` + `{resume_task_name}`: Current task
986
+ - `{user_response}`: What user provided
987
+ - `{resume_instructions}`: Based on checkpoint type
988
+ 7. Continuation agent verifies previous commits, continues from resume point
989
+ 8. Repeat until plan completes or user stops
990
+
991
+ **Why fresh agent, not resume:** Resume relies on internal serialization that breaks with parallel tool calls. Fresh agents with explicit state are more reliable.
992
+
993
+ **Checkpoints in parallel waves:** Agent pauses and returns while other parallel agents may complete. Present checkpoint, spawn continuation, wait for all before next wave.
994
+ </step>
995
+
996
+ <step name="aggregate_results">
997
+ After all waves:
998
+
999
+ ```markdown
1000
+ ## Phase {X}: {Name} Execution Complete
1001
+
1002
+ **Waves:** {N} | **Plans:** {M}/{total} complete
1003
+
1004
+ | Wave | Plans | Status |
1005
+ |------|-------|--------|
1006
+ | 1 | plan-01, plan-02 | ✓ Complete |
1007
+ | CP | plan-03 | ✓ Verified |
1008
+ | 2 | plan-04 | ✓ Complete |
1009
+
1010
+ ### Plan Details
1011
+ 1. **03-01**: [one-liner from SUMMARY.md]
1012
+ 2. **03-02**: [one-liner from SUMMARY.md]
1013
+
1014
+ ### Issues Encountered
1015
+ [Aggregate from SUMMARYs, or "None"]
1016
+ ```
1017
+
1018
+ **Security gate check:**
1019
+ ```bash
1020
+ SECURITY_CFG=$(gsd_run query config-get workflow.security_enforcement --raw 2>/dev/null || echo "true")
1021
+ SECURITY_FILE=$(ls "${PHASE_DIR}"/*-SECURITY.md 2>/dev/null | head -1)
1022
+ ```
1023
+
1024
+ If `SECURITY_CFG` is `false`: skip.
1025
+
1026
+ If `SECURITY_CFG` is `true` AND `SECURITY_FILE` is empty (no SECURITY.md yet):
1027
+ Include in the next-steps routing output:
1028
+ ```
1029
+ ⚠ Security enforcement enabled — run before advancing:
1030
+ /gsd:secure-phase {PHASE} ${GSD_WS}
1031
+ ```
1032
+
1033
+ If `SECURITY_CFG` is `true` AND SECURITY.md exists: check frontmatter `threats_open`. If > 0:
1034
+ ```
1035
+ ⚠ Security gate: {threats_open} threats open
1036
+ /gsd:secure-phase {PHASE} — resolve before advancing
1037
+ ```
1038
+ </step>
1039
+
1040
+ <step name="tdd_review_checkpoint">
1041
+ **Optional step — TDD collaborative review.**
1042
+
1043
+ ```bash
1044
+ TDD_MODE=$(gsd_run query config-get workflow.tdd_mode 2>/dev/null || echo "false")
1045
+ ```
1046
+
1047
+ **Skip if `TDD_MODE` is `false`.**
1048
+
1049
+ When `TDD_MODE` is `true`, check whether any completed plans in this phase have `type: tdd` in their frontmatter:
1050
+
1051
+ ```bash
1052
+ TDD_PLANS=$(grep -rl "^type: tdd" "${PHASE_DIR}"/*-PLAN.md 2>/dev/null | wc -l | tr -d ' ')
1053
+ ```
1054
+
1055
+ **If `TDD_PLANS` > 0:** Insert end-of-phase collaborative review checkpoint.
1056
+
1057
+ 1. Collect all SUMMARY.md files for TDD plans
1058
+ 2. For each TDD plan summary, verify the RED/GREEN/REFACTOR gate sequence:
1059
+ - RED gate: A failing test commit exists (`test(...)` commit with MUST-fail evidence)
1060
+ - GREEN gate: An implementation commit exists (`feat(...)` commit making tests pass)
1061
+ - REFACTOR gate: Optional cleanup commit (`refactor(...)` commit, tests still pass)
1062
+ 3. If any TDD plan is missing the RED or GREEN gate commits, flag it:
1063
+ ```
1064
+ ⚠ TDD gate violation: Plan {plan_id} missing {RED|GREEN} phase commit.
1065
+ Expected commit pattern: test({phase}-{plan}): ... → feat({phase}-{plan}): ...
1066
+ ```
1067
+ 4. Present collaborative review summary:
1068
+ ```
1069
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1070
+ TDD REVIEW — Phase {X}
1071
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1072
+
1073
+ TDD Plans: {TDD_PLANS} | Gate violations: {count}
1074
+
1075
+ | Plan | RED | GREEN | REFACTOR | Status |
1076
+ |------|-----|-------|----------|--------|
1077
+ | {id} | ✓ | ✓ | ✓ | Pass |
1078
+ | {id} | ✓ | ✗ | — | FAIL |
1079
+ ```
1080
+
1081
+ **Escalation under MVP+TDD.** When `MVP_MODE=true` AND `TDD_MODE=true`, the review verdict escalates from advisory to **blocking**: missing RED or GREEN gate commits prevent marking the phase complete.
1082
+ ```text
1083
+ Phase blocked: {N} TDD plan(s) violate the RED→GREEN gate sequence under MVP+TDD.
1084
+ Resolve and re-run /gsd execute-phase, or override with
1085
+ /gsd execute-phase {phase} --force-mvp-gate to ship anyway.
1086
+ ```
1087
+ `--force-mvp-gate` is the escape hatch (documented, not yet implemented). Policy is:
1088
+ - `MVP_MODE=true` AND `TDD_MODE=true`: violations are **blocking** unless explicitly overridden.
1089
+ - otherwise: violations are advisory/non-blocking and are surfaced for review.
1090
+ The verifier agent (step `verify_phase_goal`) still checks TDD discipline in both cases.
1091
+ </step>
1092
+
1093
+ <step name="handle_partial_wave_execution">
1094
+ If `WAVE_FILTER` was used, re-run plan discovery after execution:
1095
+
1096
+ ```bash
1097
+ POST_PLAN_INDEX=$(gsd_run query phase-plan-index "${PHASE_NUMBER}")
1098
+ ```
1099
+
1100
+ Apply the same "incomplete" filtering rules as earlier:
1101
+ - ignore plans with `has_summary: true`
1102
+ - if `--gaps-only`, only consider `gap_closure: true` plans
1103
+
1104
+ **If incomplete plans still remain anywhere in the phase:**
1105
+ - STOP here
1106
+ - Do NOT run phase verification
1107
+ - Do NOT mark the phase complete in ROADMAP/STATE
1108
+ - Present:
1109
+
1110
+ ```markdown
1111
+ ## Wave {WAVE_FILTER} Complete
1112
+
1113
+ Selected wave finished successfully. This phase still has incomplete plans, so phase-level verification and completion were intentionally skipped.
1114
+
1115
+ /gsd:execute-phase {phase} ${GSD_WS} # Continue remaining waves
1116
+ /gsd:execute-phase {phase} --wave {next} ${GSD_WS} # Run the next wave explicitly
1117
+ ```
1118
+
1119
+ **If no incomplete plans remain after the selected wave finishes:**
1120
+ - continue with the normal phase-level verification and completion flow below
1121
+ - this means the selected wave happened to be the last remaining work in the phase
1122
+ </step>
1123
+
1124
+ <step name="code_review_gate" required="true">
1125
+ **This step is REQUIRED and must not be skipped.** Auto-invoke code review on the phase's source changes. Advisory only — never blocks execution flow.
1126
+
1127
+ **Config gate:**
1128
+ ```bash
1129
+ CODE_REVIEW_ENABLED=$(gsd_run query config-get workflow.code_review 2>/dev/null || echo "true")
1130
+ ```
1131
+
1132
+ If `CODE_REVIEW_ENABLED` is `"false"`: display "Code review skipped (workflow.code_review=false)" and proceed to next step.
1133
+
1134
+ **Invoke review:**
1135
+ ```
1136
+ Skill(skill="gsd-code-review", args="${PHASE_NUMBER}")
1137
+ ```
1138
+
1139
+ **Check results using deterministic path (not glob):**
1140
+ ```bash
1141
+ PADDED=$(printf "%02d" "${PHASE_NUMBER}")
1142
+ REVIEW_FILE="${PHASE_DIR}/${PADDED}-REVIEW.md"
1143
+ REVIEW_STATUS=$(sed -n '/^---$/,/^---$/p' "$REVIEW_FILE" | grep "^status:" | head -1 | cut -d: -f2 | tr -d ' ')
1144
+ ```
1145
+
1146
+ If REVIEW_STATUS is not "clean" and not "skipped" and not empty, display:
1147
+ ```
1148
+ Code review found issues. Consider running:
1149
+ /gsd:code-review ${PHASE_NUMBER} --fix
1150
+ ```
1151
+
1152
+ **Error handling:** If the Skill invocation fails or throws, catch the error, display "Code review encountered an error (non-blocking): {error}" and proceed to next step. Review failures must never block execution.
1153
+
1154
+ Regardless of review result, ALWAYS proceed to close_parent_artifacts → regression_gate → verify_phase_goal.
1155
+ </step>
1156
+
1157
+ <step name="close_parent_artifacts">
1158
+ **For decimal/polish phases only (X.Y pattern):** Close the feedback loop by resolving parent UAT and debug artifacts.
1159
+
1160
+ **Skip if** phase number has no decimal (e.g., `3`, `04`) — only applies to gap-closure phases like `4.1`, `03.1`.
1161
+
1162
+ **1. Detect decimal phase and derive parent:**
1163
+ ```bash
1164
+ # Check if phase_number contains a decimal
1165
+ if [[ "$PHASE_NUMBER" == *.* ]]; then
1166
+ PARENT_PHASE="${PHASE_NUMBER%%.*}"
1167
+ fi
1168
+ ```
1169
+
1170
+ **2. Find parent UAT file:**
1171
+ ```bash
1172
+ PARENT_INFO=$(gsd_run query find-phase "${PARENT_PHASE}" --raw)
1173
+ # Extract directory from PARENT_INFO JSON, then find UAT file in that directory
1174
+ ```
1175
+
1176
+ **If no parent UAT found:** Skip this step (gap-closure may have been triggered by VERIFICATION.md instead).
1177
+
1178
+ **3. Update UAT gap statuses:**
1179
+
1180
+ Read the parent UAT file's `## Gaps` section. For each gap entry with `status: failed`:
1181
+ - Update to `status: resolved`
1182
+
1183
+ **4. Update UAT frontmatter:**
1184
+
1185
+ If all gaps now have `status: resolved`:
1186
+ - Update frontmatter `status: diagnosed` → `status: resolved`
1187
+ - Update frontmatter `updated:` timestamp
1188
+
1189
+ **5. Resolve referenced debug sessions:**
1190
+
1191
+ For each gap that has a `debug_session:` field:
1192
+ - Read the debug session file
1193
+ - Update frontmatter `status:` → `resolved`
1194
+ - Update frontmatter `updated:` timestamp
1195
+ - Move to resolved directory:
1196
+ ```bash
1197
+ mkdir -p .planning/debug/resolved
1198
+ mv .planning/debug/{slug}.md .planning/debug/resolved/
1199
+ ```
1200
+
1201
+ **6. Commit updated artifacts:**
1202
+ ```bash
1203
+ gsd_run query commit "docs(phase-${PARENT_PHASE}): resolve UAT gaps and debug sessions after ${PHASE_NUMBER} gap closure" --files .planning/phases/*${PARENT_PHASE}*/*-UAT.md .planning/debug/resolved/*.md
1204
+ ```
1205
+ </step>
1206
+
1207
+ <step name="regression_gate">
1208
+ Run prior phases' test suites to catch cross-phase regressions BEFORE verification.
1209
+
1210
+ **Skip if:** This is the first phase (no prior phases), or no prior VERIFICATION.md files exist.
1211
+
1212
+ **Step 1: Discover prior phases' test files**
1213
+ ```bash
1214
+ # Find all VERIFICATION.md files from prior phases in current milestone
1215
+ PRIOR_VERIFICATIONS=$(find .planning/phases/ -name "*-VERIFICATION.md" ! -path "*${PHASE_NUMBER}*" 2>/dev/null)
1216
+ ```
1217
+
1218
+ **Step 2: Extract test file lists from prior verifications**
1219
+
1220
+ For each VERIFICATION.md found, look for test file references:
1221
+ - Lines containing `test`, `spec`, or `__tests__` paths
1222
+ - The "Test Suite" or "Automated Checks" section
1223
+ - File patterns from `key-files.created` in corresponding SUMMARY.md files that match `*.test.*` or `*.spec.*`
1224
+
1225
+ Collect all unique test file paths into `REGRESSION_FILES`.
1226
+
1227
+ **Step 3: Run regression tests (if any found)**
1228
+
1229
+ ```bash
1230
+ # Resolve test command: project config > Makefile > language sniff
1231
+ REG_TEST_CMD=$(gsd_run query config-get workflow.test_command --default "" 2>/dev/null || true)
1232
+ if [ -z "$REG_TEST_CMD" ]; then
1233
+ if [ -f "Makefile" ] && grep -q "^test:" Makefile; then
1234
+ REG_TEST_CMD="make test"
1235
+ elif [ -f "Justfile" ] || [ -f "justfile" ]; then
1236
+ REG_TEST_CMD="just test"
1237
+ elif [ -f "package.json" ]; then
1238
+ REG_TEST_CMD="npm test"
1239
+ elif [ -f "Cargo.toml" ]; then
1240
+ REG_TEST_CMD="cargo test"
1241
+ elif [ -f "go.mod" ]; then
1242
+ REG_TEST_CMD="go test ./..."
1243
+ elif [ -f "requirements.txt" ] || [ -f "pyproject.toml" ]; then
1244
+ REG_TEST_CMD="python -m pytest ${REGRESSION_FILES} -q --tb=short"
1245
+ else
1246
+ REG_TEST_CMD="true"
1247
+ fi
1248
+ fi
1249
+ # Detect test runner and run prior phase tests
1250
+ eval "$REG_TEST_CMD" 2>&1
1251
+ ```
1252
+
1253
+ **Step 4: Report results**
1254
+
1255
+ If all tests pass:
1256
+ ```
1257
+ ✓ Regression gate: {N} prior-phase test files passed — no regressions detected
1258
+ ```
1259
+ → Proceed to verify_phase_goal
1260
+
1261
+ If any tests fail:
1262
+ ```
1263
+ ## ⚠ Cross-Phase Regression Detected
1264
+
1265
+ Phase {X} execution may have broken functionality from prior phases.
1266
+
1267
+ | Test File | Phase | Status | Detail |
1268
+ |-----------|-------|--------|--------|
1269
+ | {file} | {origin_phase} | FAILED | {first_failure_line} |
1270
+
1271
+ Options:
1272
+ 1. Fix regressions before verification (recommended)
1273
+ 2. Continue to verification anyway (regressions will compound)
1274
+ 3. Abort phase — roll back and re-plan
1275
+ ```
1276
+
1277
+ Use AskUserQuestion to present the options.
1278
+ </step>
1279
+
1280
+ <step name="schema_drift_gate">
1281
+ Post-execution schema drift detection. Catches false-positive verification where
1282
+ build/types pass because TypeScript types come from config, not the live database.
1283
+
1284
+ **Run after execution completes but BEFORE verification marks success.**
1285
+
1286
+ ```bash
1287
+ SCHEMA_DRIFT=$(gsd_run query verify.schema-drift "${PHASE_NUMBER}" 2>/dev/null)
1288
+ ```
1289
+
1290
+ Parse JSON result for: `drift_detected`, `blocking`, `schema_files`, `orms`, `unpushed_orms`, `message`.
1291
+
1292
+ **If `drift_detected` is false:** Skip to verify_phase_goal.
1293
+
1294
+ **If `drift_detected` is true AND `blocking` is true:**
1295
+
1296
+ Check for override:
1297
+ ```bash
1298
+ SKIP_SCHEMA=$(echo "${GSD_SKIP_SCHEMA_CHECK:-false}")
1299
+ ```
1300
+
1301
+ **If `SKIP_SCHEMA` is `true`:**
1302
+
1303
+ Display:
1304
+ ```
1305
+ ⚠ Schema drift detected but GSD_SKIP_SCHEMA_CHECK=true — bypassing gate.
1306
+
1307
+ Schema files changed: {schema_files}
1308
+ ORMs requiring push: {unpushed_orms}
1309
+
1310
+ Proceeding to verification (database may be out of sync).
1311
+ ```
1312
+ → Continue to verify_phase_goal.
1313
+
1314
+ **If `SKIP_SCHEMA` is not `true`:**
1315
+
1316
+ BLOCK verification. Display:
1317
+
1318
+ ```
1319
+ ## BLOCKED: Schema Drift Detected
1320
+
1321
+ Schema-relevant files changed during this phase but no database push command
1322
+ was executed. Build and type checks pass because TypeScript types come from
1323
+ config, not the live database — verification would produce a false positive.
1324
+
1325
+ Schema files changed: {schema_files}
1326
+ ORMs requiring push: {unpushed_orms}
1327
+
1328
+ Required push commands:
1329
+ {For each unpushed ORM, show the push command from the message}
1330
+
1331
+ Options:
1332
+ 1. Run push command now (recommended) — execute the push, then re-verify
1333
+ 2. Skip schema check (GSD_SKIP_SCHEMA_CHECK=true) — bypass this gate
1334
+ 3. Abort — stop execution and investigate
1335
+ ```
1336
+
1337
+ If `TEXT_MODE` is true, present as a plain-text numbered list. Otherwise use AskUserQuestion.
1338
+
1339
+ **If user selects option 1:** Present the specific push command(s) to run. After user confirms execution, re-run the schema drift check. If it passes, continue to verify_phase_goal.
1340
+
1341
+ **If user selects option 2:** Set override and continue to verify_phase_goal.
1342
+
1343
+ **If user selects option 3:** Stop execution. Report partial completion.
1344
+ </step>
1345
+
1346
+ <step name="codebase_drift_gate">
1347
+ Post-execution structural drift detection (#2003). Non-blocking by contract:
1348
+ any internal error here MUST fall through to `verify_phase_goal`. The phase
1349
+ is never failed by this gate.
1350
+
1351
+ Load and follow the full step spec from
1352
+ `get-shit-done/workflows/execute-phase/steps/codebase-drift-gate.md` —
1353
+ covers the SDK call, JSON contract, `warn` vs `auto-remap` branches, mapper
1354
+ spawn template, and the two `workflow.drift_*` config keys.
1355
+ </step>
1356
+
1357
+ <step name="verify_phase_goal">
1358
+ Verify phase achieved its GOAL, not just completed tasks.
1359
+
1360
+ ```bash
1361
+ VERIFIER_SKILLS=$(gsd_run query agent-skills gsd-verifier)
1362
+ ```
1363
+
1364
+ ```
1365
+ Agent(
1366
+ description="Verify phase {phase_number} goal achievement",
1367
+ prompt="Verify phase {phase_number} goal achievement.
1368
+ Phase directory: {phase_dir}
1369
+ Phase goal: {goal from ROADMAP.md}
1370
+ Phase requirement IDs: {phase_req_ids}
1371
+ Check must_haves against actual codebase.
1372
+ Cross-reference requirement IDs from PLAN frontmatter against REQUIREMENTS.md — every ID MUST be accounted for.
1373
+ Create VERIFICATION.md.
1374
+
1375
+ <files_to_read>
1376
+ Read these files before verification:
1377
+ - {phase_dir}/*-PLAN.md (All plans — understand intent, check must_haves)
1378
+ - {phase_dir}/*-SUMMARY.md (All summaries — cross-reference claimed vs actual)
1379
+ - .planning/REQUIREMENTS.md (Requirement traceability)
1380
+ ${CONTEXT_WINDOW >= 500000 ? `- {phase_dir}/*-CONTEXT.md (User decisions — verify they were honored)
1381
+ - {phase_dir}/*-RESEARCH.md (Known pitfalls — check for traps)
1382
+ - Prior VERIFICATION.md files from earlier phases (regression check)
1383
+ ` : ''}
1384
+ </files_to_read>
1385
+
1386
+ ${VERIFIER_SKILLS}",
1387
+ subagent_type="gsd-verifier",
1388
+ model="{verifier_model}"
1389
+ )
1390
+ ```
1391
+
1392
+ > **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.
1393
+
1394
+ Read status:
1395
+ ```bash
1396
+ grep "^status:" "$PHASE_DIR"/*-VERIFICATION.md | cut -d: -f2 | tr -d ' '
1397
+ ```
1398
+
1399
+ | Status | Action |
1400
+ |--------|--------|
1401
+ | `passed` | → update_roadmap |
1402
+ | `human_needed` | Persist and present human testing items; keep phase pending until verification reruns as `passed` |
1403
+ | `gaps_found` | Present gap summary, offer `/gsd:plan-phase {phase} --gaps ${GSD_WS}` |
1404
+
1405
+ **If human_needed:**
1406
+
1407
+ **Step A: Persist human verification items as UAT file.**
1408
+
1409
+ Create `{phase_dir}/{phase_num}-HUMAN-UAT.md` using UAT template format:
1410
+
1411
+ ```markdown
1412
+ ---
1413
+ status: partial
1414
+ phase: {phase_num}-{phase_name}
1415
+ source: [{phase_num}-VERIFICATION.md]
1416
+ started: [now ISO]
1417
+ updated: [now ISO]
1418
+ ---
1419
+
1420
+ ## Current Test
1421
+
1422
+ [awaiting human testing]
1423
+
1424
+ ## Tests
1425
+
1426
+ {For each human_verification item from VERIFICATION.md:}
1427
+
1428
+ ### {N}. {item description}
1429
+ expected: {expected behavior from VERIFICATION.md}
1430
+ result: [pending]
1431
+
1432
+ ## Summary
1433
+
1434
+ total: {count}
1435
+ passed: 0
1436
+ issues: 0
1437
+ pending: {count}
1438
+ skipped: 0
1439
+ blocked: 0
1440
+
1441
+ ## Gaps
1442
+ ```
1443
+
1444
+ Commit the file:
1445
+ ```bash
1446
+ gsd_run query commit "test({phase_num}): persist human verification items as UAT" --files "{phase_dir}/{phase_num}-HUMAN-UAT.md"
1447
+ ```
1448
+
1449
+ **Step B: Present to user:**
1450
+
1451
+ ```
1452
+ ## ✓ Phase {X}: {Name} — Human Verification Required
1453
+
1454
+ All automated checks passed. {N} items need human testing:
1455
+
1456
+ {From VERIFICATION.md human_verification section}
1457
+
1458
+ Items saved to `{phase_num}-HUMAN-UAT.md` — they will appear in `/gsd:progress` and `/gsd:audit-uat`.
1459
+
1460
+ "approved" → continue | Report issues → gap closure
1461
+ ```
1462
+
1463
+ **If user says "approved":** Proceed to `update_roadmap`. The HUMAN-UAT.md file persists with `status: partial` and will surface in future progress checks until the user runs `/gsd:verify-work` on it.
1464
+
1465
+ **If user reports issues:** Proceed to gap closure as currently implemented.
1466
+
1467
+ **If gaps_found:**
1468
+ ```
1469
+ ## ⚠ Phase {X}: {Name} — Gaps Found
1470
+
1471
+ **Score:** {N}/{M} must-haves verified
1472
+ **Report:** {phase_dir}/{phase_num}-VERIFICATION.md
1473
+
1474
+ ### What's Missing
1475
+ {Gap summaries from VERIFICATION.md}
1476
+
1477
+ ---
1478
+ ## ▶ Next Up — [${PROJECT_CODE}] ${PROJECT_TITLE}
1479
+
1480
+ `/clear` then:
1481
+
1482
+ `/gsd:plan-phase {X} --gaps ${GSD_WS}`
1483
+
1484
+ Also: `cat {phase_dir}/{phase_num}-VERIFICATION.md` — full report
1485
+ Also: `/gsd:verify-work {X} ${GSD_WS}` — manual testing first
1486
+ ```
1487
+
1488
+ Gap closure cycle: `/gsd:plan-phase {X} --gaps ${GSD_WS}` reads VERIFICATION.md → creates gap plans with `gap_closure: true` → user runs `/gsd:execute-phase {X} --gaps-only ${GSD_WS}` → verifier re-runs.
1489
+ </step>
1490
+
1491
+ <step name="update_roadmap">
1492
+ **Mark phase complete and update all tracking files:**
1493
+
1494
+ ```bash
1495
+ COMPLETION=$(gsd_run query phase.complete "${PHASE_NUMBER}")
1496
+ ```
1497
+
1498
+ The CLI handles:
1499
+ - Marking phase checkbox `[x]` with completion date
1500
+ - Updating Progress table (Status → Complete, date)
1501
+ - Updating plan count to final
1502
+ - Advancing STATE.md to next phase
1503
+ - Updating REQUIREMENTS.md traceability
1504
+ - Scanning for verification debt (returns `warnings` array)
1505
+
1506
+ Extract from result: `next_phase`, `next_phase_name`, `is_last_phase`, `warnings`, `has_warnings`.
1507
+
1508
+ **If has_warnings is true:**
1509
+ ```
1510
+ ## Phase {X} marked complete with {N} warnings:
1511
+
1512
+ {list each warning}
1513
+
1514
+ These items are tracked and will appear in `/gsd:progress` and `/gsd:audit-uat`.
1515
+ ```
1516
+
1517
+ ```bash
1518
+ gsd_run query commit "docs(phase-{X}): complete phase execution" --files .planning/ROADMAP.md .planning/STATE.md .planning/REQUIREMENTS.md {phase_dir}/*-VERIFICATION.md
1519
+ ```
1520
+ </step>
1521
+
1522
+ <step name="auto_copy_learnings">
1523
+ **Auto-copy phase learnings to global store (when enabled).**
1524
+
1525
+ This step runs AFTER phase completion and SUMMARY.md is written. It copies any LEARNINGS.md
1526
+ entries from the completed phase to the global learnings store at `~/.gsd/knowledge/`.
1527
+
1528
+ **Check config gate:**
1529
+ ```bash
1530
+ GL_ENABLED=$(gsd_run query config-get features.global_learnings --raw 2>/dev/null || echo "false")
1531
+ ```
1532
+
1533
+ **If `GL_ENABLED` is not `true`:** Skip this step entirely (feature disabled by default).
1534
+
1535
+ **If enabled:**
1536
+
1537
+ 1. Check if LEARNINGS.md exists in the phase directory (use the `phase_dir` value from init context)
1538
+ 2. If found, copy to global store:
1539
+ ```bash
1540
+ gsd_run query learnings.copy 2>/dev/null || echo "⚠ Learnings copy failed — continuing"
1541
+ ```
1542
+ Copy failure must NOT block phase completion.
1543
+ </step>
1544
+
1545
+ <step name="close_phase_todos">
1546
+ **Auto-close pending todos tagged for this phase (#2433).**
1547
+
1548
+ This step runs AFTER `update_roadmap` marks the phase complete. It moves any pending todos that carry `resolves_phase: <current-phase-number>` to the completed directory.
1549
+
1550
+ ```bash
1551
+ PHASE_NUM="${PHASE_NUMBER}"
1552
+ PENDING_DIR=".planning/todos/pending"
1553
+ COMPLETED_DIR=".planning/todos/completed"
1554
+ mkdir -p "$COMPLETED_DIR"
1555
+
1556
+ CLOSED=()
1557
+ for TODO_FILE in "$PENDING_DIR"/*.md; do
1558
+ [ -f "$TODO_FILE" ] || continue
1559
+ # Extract resolves_phase from YAML frontmatter (first --- block only)
1560
+ RP=$(awk '/^---/{c++;next} c==1 && /^resolves_phase:/{print $2;exit} c==2{exit}' "$TODO_FILE" 2>/dev/null || true)
1561
+ if [ "$RP" = "$PHASE_NUM" ] || [ "$RP" = "\"$PHASE_NUM\"" ]; then
1562
+ mv "$TODO_FILE" "$COMPLETED_DIR/"
1563
+ CLOSED+=("$(basename "$TODO_FILE")")
1564
+ fi
1565
+ done
1566
+
1567
+ if [ ${#CLOSED[@]} -gt 0 ]; then
1568
+ gsd_run query commit "docs(phase-${PHASE_NUMBER}): auto-close ${#CLOSED[@]} todo(s) resolved by this phase" --files .planning/todos/completed/ .planning/STATE.md|| true
1569
+ echo "◆ Closed ${#CLOSED[@]} todo(s) resolved by Phase ${PHASE_NUMBER}:"
1570
+ for f in "${CLOSED[@]}"; do echo " ✓ $f"; done
1571
+ fi
1572
+ ```
1573
+
1574
+ **If no todos have `resolves_phase: <this-phase>`:** Skip silently — this step is always additive and never blocks phase completion.
1575
+ </step>
1576
+
1577
+ <step name="update_project_md">
1578
+ **Evolve PROJECT.md to reflect phase completion (prevents planning document drift — #956):**
1579
+
1580
+ PROJECT.md tracks validated requirements, decisions, and current state. Without this step,
1581
+ PROJECT.md falls behind silently over multiple phases.
1582
+
1583
+ 1. Read `.planning/PROJECT.md`
1584
+ 2. If the file exists and has a `## Validated Requirements` or `## Requirements` section:
1585
+ - Move any requirements validated by this phase from Active → Validated
1586
+ - Add a brief note: `Validated in Phase {X}: {Name}`
1587
+ 3. If the file has a `## Current State` or similar section:
1588
+ - Update it to reflect this phase's completion (e.g., "Phase {X} complete — {one-liner}")
1589
+ 4. Update the `Last updated:` footer to today's date
1590
+ 5. Commit the change:
1591
+
1592
+ ```bash
1593
+ gsd_run query commit "docs(phase-{X}): evolve PROJECT.md after phase completion" --files .planning/PROJECT.md
1594
+ ```
1595
+
1596
+ **Skip this step if** `.planning/PROJECT.md` does not exist.
1597
+ </step>
1598
+
1599
+ <step name="offer_next">
1600
+
1601
+ **Exception:** If `gaps_found`, the `verify_phase_goal` step already presents the gap-closure path (`/gsd:plan-phase {X} --gaps`). No additional routing needed — skip auto-advance.
1602
+
1603
+ **No-transition check (spawned by auto-advance chain):**
1604
+
1605
+ Parse `--no-transition` flag from $ARGUMENTS.
1606
+
1607
+ **If `--no-transition` flag present:**
1608
+
1609
+ Execute-phase was spawned by plan-phase's auto-advance. Do NOT run transition.md.
1610
+ After verification passes and roadmap is updated, return completion status to parent:
1611
+
1612
+ ```
1613
+ ## PHASE COMPLETE
1614
+
1615
+ Phase: ${PHASE_NUMBER} - ${PHASE_NAME}
1616
+ Plans: ${completed_count}/${total_count}
1617
+ Verification: {Passed | Gaps Found}
1618
+
1619
+ [Include aggregate_results output]
1620
+ ```
1621
+
1622
+ STOP. Do not proceed to auto-advance or transition.
1623
+
1624
+ **If `--no-transition` flag is NOT present:**
1625
+
1626
+ **Auto-advance detection:**
1627
+
1628
+ 1. Parse `--auto` flag from $ARGUMENTS
1629
+ 2. Read consolidated auto-mode (`active` = chain flag OR user preference; chain flag already synced in init step):
1630
+ ```bash
1631
+ AUTO_MODE=$(gsd_run query check auto-mode --pick active 2>/dev/null || echo "false")
1632
+ ```
1633
+
1634
+ **If `--auto` flag present OR `AUTO_MODE` is true (AND verification passed with no gaps):**
1635
+
1636
+ ```
1637
+ ╔══════════════════════════════════════════╗
1638
+ ║ AUTO-ADVANCING → TRANSITION ║
1639
+ ║ Phase {X} verified, continuing chain ║
1640
+ ╚══════════════════════════════════════════╝
1641
+ ```
1642
+
1643
+ Execute the transition workflow inline (do NOT use Agent — orchestrator context is ~10-15%, transition needs phase completion data already in context):
1644
+
1645
+ Read and follow `~/.claude/get-shit-done/workflows/transition.md`, passing through the `--auto` flag so it propagates to the next phase invocation.
1646
+
1647
+ **If neither `--auto` nor `AUTO_MODE` is true:**
1648
+
1649
+ **STOP. Do not auto-advance. Do not execute transition. Do not plan next phase. Present options to the user and wait.**
1650
+
1651
+ **IMPORTANT: There is NO `/gsd-transition` command. Never suggest it. The transition workflow is internal only.**
1652
+
1653
+ Check whether CONTEXT.md already exists for the next phase:
1654
+
1655
+ ```bash
1656
+ ls .planning/phases/*{next}*/{next}-CONTEXT.md 2>/dev/null || echo "no-context"
1657
+ ```
1658
+
1659
+ If CONTEXT.md does **not** exist for the next phase, present:
1660
+
1661
+ ```
1662
+ ## ✓ Phase {X}: {Name} Complete
1663
+
1664
+ /gsd:progress ${GSD_WS} — see updated roadmap
1665
+ /gsd:discuss-phase {next} ${GSD_WS} — start here: discuss next phase before planning ← recommended
1666
+ /gsd:plan-phase {next} ${GSD_WS} — plan next phase (skip discuss)
1667
+ /gsd:execute-phase {next} ${GSD_WS} — execute next phase (skip discuss and plan)
1668
+ ```
1669
+
1670
+ If CONTEXT.md **exists** for the next phase, present:
1671
+
1672
+ ```
1673
+ ## ✓ Phase {X}: {Name} Complete
1674
+
1675
+ /gsd:progress ${GSD_WS} — see updated roadmap
1676
+ /gsd:plan-phase {next} ${GSD_WS} — start here: plan next phase (CONTEXT.md already present) ← recommended
1677
+ /gsd:discuss-phase {next} ${GSD_WS} — re-discuss next phase
1678
+ /gsd:execute-phase {next} ${GSD_WS} — execute next phase (skip planning)
1679
+ ```
1680
+
1681
+ Only suggest the commands listed above. Do not invent or hallucinate command names.
1682
+ </step>
1683
+
1684
+ </process>
1685
+
1686
+ <context_efficiency>
1687
+ Orchestrator: ~10-15% context for 200k windows, can use more for 1M+ windows.
1688
+ Subagents: fresh context each (200k-1M depending on model). No polling (Agent blocks). No context bleed.
1689
+
1690
+ For 1M+ context models, consider:
1691
+ - Passing richer context (code snippets, dependency outputs) directly to executors instead of just file paths
1692
+ - Running small phases (≤3 plans, no dependencies) inline without subagent spawning overhead
1693
+ - Relaxing /clear recommendations — context rot onset is much further out with 5x window
1694
+ </context_efficiency>
1695
+
1696
+ <failure_handling>
1697
+ - **Quota / rate-limit (any runtime — #3095):** Agent return body contains a sentinel like `usage limit`, `rate limit`, `429`, `too many requests`, `RESOURCE_EXHAUSTED`, `usage_limit_reached`. Route via `gsd-tools.cjs query agent.classify-failure` → `class: "quota-exceeded"`. Do not offer retry-now; the right action is wait-for-reset and resume.
1698
+ - **classifyHandoffIfNeeded false failure:** Agent reports "failed" but error is `classifyHandoffIfNeeded is not defined` → Claude Code bug, not GSD. Spot-check (SUMMARY exists, commits present) → if pass, treat as success
1699
+ - **Agent fails mid-plan:** Missing SUMMARY.md → report, ask user how to proceed
1700
+ - **Dependency chain breaks:** Wave 1 fails → Wave 2 dependents likely fail → user chooses attempt or skip
1701
+ - **All agents in wave fail:** Systemic issue → stop, report for investigation
1702
+ - **Checkpoint unresolvable:** "Skip this plan?" or "Abort phase execution?" → record partial progress in STATE.md
1703
+ </failure_handling>
1704
+
1705
+ <resumption>
1706
+ Re-run `/gsd:execute-phase {phase}` → discover_plans finds completed SUMMARYs → skips them → resumes from first incomplete plan → continues wave execution.
1707
+
1708
+ STATE.md tracks: last completed plan, current wave, pending checkpoints.
1709
+ </resumption>