gsd-pi 2.82.0-dev.2841a1e44 → 2.82.0-dev.3709f22a5

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 (305) hide show
  1. package/README.md +2 -2
  2. package/dist/resources/.managed-resources-content-hash +1 -1
  3. package/dist/resources/GSD-WORKFLOW.md +7 -0
  4. package/dist/resources/extensions/claude-code-cli/partial-builder.js +2 -1
  5. package/dist/resources/extensions/gsd/auto/infra-errors.js +9 -3
  6. package/dist/resources/extensions/gsd/auto/loop.js +5 -5
  7. package/dist/resources/extensions/gsd/auto/orchestrator.js +11 -0
  8. package/dist/resources/extensions/gsd/auto/phases.js +28 -2
  9. package/dist/resources/extensions/gsd/auto/workflow-memory-pressure.js +12 -0
  10. package/dist/resources/extensions/gsd/auto-dashboard.js +66 -1
  11. package/dist/resources/extensions/gsd/auto-dispatch.js +13 -6
  12. package/dist/resources/extensions/gsd/auto-model-selection.js +2 -0
  13. package/dist/resources/extensions/gsd/auto-post-unit.js +70 -9
  14. package/dist/resources/extensions/gsd/auto-recovery.js +31 -1
  15. package/dist/resources/extensions/gsd/auto-start.js +85 -12
  16. package/dist/resources/extensions/gsd/auto-worktree.js +111 -1
  17. package/dist/resources/extensions/gsd/auto.js +37 -4
  18. package/dist/resources/extensions/gsd/bootstrap/agent-end-recovery.js +25 -6
  19. package/dist/resources/extensions/gsd/bootstrap/db-tools.js +9 -8
  20. package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +4 -2
  21. package/dist/resources/extensions/gsd/bootstrap/subagent-input.js +5 -2
  22. package/dist/resources/extensions/gsd/bootstrap/write-gate.js +13 -1
  23. package/dist/resources/extensions/gsd/commands/handlers/core.js +17 -1
  24. package/dist/resources/extensions/gsd/crash-recovery.js +31 -5
  25. package/dist/resources/extensions/gsd/db/unit-dispatches.js +3 -2
  26. package/dist/resources/extensions/gsd/dispatch-guard.js +2 -2
  27. package/dist/resources/extensions/gsd/doctor-git-checks.js +46 -1
  28. package/dist/resources/extensions/gsd/doctor-runtime-checks.js +28 -11
  29. package/dist/resources/extensions/gsd/doctor.js +2 -28
  30. package/dist/resources/extensions/gsd/export-html.js +27 -425
  31. package/dist/resources/extensions/gsd/git-service.js +39 -1
  32. package/dist/resources/extensions/gsd/gsd-db.js +1 -0
  33. package/dist/resources/extensions/gsd/guided-flow.js +93 -111
  34. package/dist/resources/extensions/gsd/guided-unit-context.js +23 -0
  35. package/dist/resources/extensions/gsd/migrate/parsers.js +10 -0
  36. package/dist/resources/extensions/gsd/migration-auto-check.js +12 -17
  37. package/dist/resources/extensions/gsd/milestone-actions.js +11 -4
  38. package/dist/resources/extensions/gsd/native-git-bridge.js +48 -12
  39. package/dist/resources/extensions/gsd/pending-auto-start.js +52 -0
  40. package/dist/resources/extensions/gsd/post-execution-checks.js +73 -2
  41. package/dist/resources/extensions/gsd/pre-execution-checks.js +28 -1
  42. package/dist/resources/extensions/gsd/prompt-loader.js +1 -1
  43. package/dist/resources/extensions/gsd/prompts/complete-milestone.md +1 -1
  44. package/dist/resources/extensions/gsd/prompts/complete-slice.md +1 -1
  45. package/dist/resources/extensions/gsd/prompts/discuss-headless.md +8 -8
  46. package/dist/resources/extensions/gsd/prompts/discuss.md +9 -9
  47. package/dist/resources/extensions/gsd/prompts/guided-discuss-project.md +4 -4
  48. package/dist/resources/extensions/gsd/prompts/guided-discuss-requirements.md +3 -3
  49. package/dist/resources/extensions/gsd/prompts/plan-slice.md +4 -4
  50. package/dist/resources/extensions/gsd/prompts/queue.md +4 -4
  51. package/dist/resources/extensions/gsd/prompts/refine-slice.md +2 -2
  52. package/dist/resources/extensions/gsd/prompts/rewrite-docs.md +1 -1
  53. package/dist/resources/extensions/gsd/smart-entry-routing.js +36 -0
  54. package/dist/resources/extensions/gsd/state-reconciliation/drift/merge-state.js +6 -1
  55. package/dist/resources/extensions/gsd/state-reconciliation/drift/project-md.js +9 -14
  56. package/dist/resources/extensions/gsd/state-reconciliation/drift/roadmap.js +19 -24
  57. package/dist/resources/extensions/gsd/status-guards.js +4 -0
  58. package/dist/resources/extensions/gsd/templates/plan.md +8 -5
  59. package/dist/resources/extensions/gsd/templates/task-plan.md +4 -2
  60. package/dist/resources/extensions/gsd/tools/complete-milestone.js +6 -8
  61. package/dist/resources/extensions/gsd/tools/complete-slice.js +6 -8
  62. package/dist/resources/extensions/gsd/tools/plan-milestone.js +7 -1
  63. package/dist/resources/extensions/gsd/tools/plan-slice.js +89 -14
  64. package/dist/resources/extensions/gsd/unit-context-manifest.js +7 -8
  65. package/dist/resources/extensions/gsd/validation.js +23 -1
  66. package/dist/resources/extensions/gsd/verification-gate.js +68 -7
  67. package/dist/resources/extensions/gsd/workflow-projections.js +6 -8
  68. package/dist/resources/extensions/gsd/worktree-lifecycle.js +33 -8
  69. package/dist/resources/extensions/shared/html-shell.js +388 -0
  70. package/dist/resources/extensions/visual-brief/page-contract.js +2 -0
  71. package/dist/resources/extensions/visual-brief/prompts.js +29 -0
  72. package/dist/tsconfig.extensions.tsbuildinfo +1 -1
  73. package/dist/web/standalone/.next/BUILD_ID +1 -1
  74. package/dist/web/standalone/.next/app-path-routes-manifest.json +15 -15
  75. package/dist/web/standalone/.next/build-manifest.json +3 -3
  76. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  77. package/dist/web/standalone/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  78. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  79. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  80. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  81. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  82. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  83. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  84. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  85. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  86. package/dist/web/standalone/.next/server/app/_not-found/page.js +2 -2
  87. package/dist/web/standalone/.next/server/app/_not-found/page.js.nft.json +1 -1
  88. package/dist/web/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  89. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  90. package/dist/web/standalone/.next/server/app/_not-found.rsc +4 -7
  91. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +4 -7
  92. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  93. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +4 -5
  94. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  95. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  96. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -5
  97. package/dist/web/standalone/.next/server/app/api/git/route.js +1 -1
  98. package/dist/web/standalone/.next/server/app/index.html +1 -1
  99. package/dist/web/standalone/.next/server/app/index.rsc +4 -7
  100. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  101. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +4 -7
  102. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  103. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +4 -5
  104. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +2 -5
  105. package/dist/web/standalone/.next/server/app/page.js +2 -2
  106. package/dist/web/standalone/.next/server/app/page.js.nft.json +1 -1
  107. package/dist/web/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
  108. package/dist/web/standalone/.next/server/app-paths-manifest.json +15 -15
  109. package/dist/web/standalone/.next/server/chunks/4266.js +2 -0
  110. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  111. package/dist/web/standalone/.next/server/next-font-manifest.js +1 -1
  112. package/dist/web/standalone/.next/server/next-font-manifest.json +1 -1
  113. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  114. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  115. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  116. package/dist/web/standalone/.next/static/chunks/app/layout-8c10ec293ae0f1d5.js +1 -0
  117. package/dist/web/standalone/.next/static/chunks/{webpack-6a95bc41e0f7ec89.js → webpack-9a4db269f9ed63ad.js} +1 -1
  118. package/dist/web/standalone/.next/static/css/746ee28c929d1880.css +1 -0
  119. package/package.json +2 -2
  120. package/packages/mcp-server/src/workflow-tools.test.ts +1 -1
  121. package/packages/native/tsconfig.json +2 -1
  122. package/packages/native/tsconfig.tsbuildinfo +1 -1
  123. package/packages/pi-ai/dist/providers/openai-codex-responses.d.ts.map +1 -1
  124. package/packages/pi-ai/dist/providers/openai-codex-responses.js +82 -1
  125. package/packages/pi-ai/dist/providers/openai-codex-responses.js.map +1 -1
  126. package/packages/pi-ai/dist/providers/openai-codex-responses.test.d.ts +2 -0
  127. package/packages/pi-ai/dist/providers/openai-codex-responses.test.d.ts.map +1 -0
  128. package/packages/pi-ai/dist/providers/openai-codex-responses.test.js +52 -0
  129. package/packages/pi-ai/dist/providers/openai-codex-responses.test.js.map +1 -0
  130. package/packages/pi-ai/dist/providers/simple-options.d.ts +2 -4
  131. package/packages/pi-ai/dist/providers/simple-options.d.ts.map +1 -1
  132. package/packages/pi-ai/dist/providers/simple-options.js +5 -6
  133. package/packages/pi-ai/dist/providers/simple-options.js.map +1 -1
  134. package/packages/pi-ai/dist/providers/simple-options.test.d.ts +2 -0
  135. package/packages/pi-ai/dist/providers/simple-options.test.d.ts.map +1 -0
  136. package/packages/pi-ai/dist/providers/simple-options.test.js +50 -0
  137. package/packages/pi-ai/dist/providers/simple-options.test.js.map +1 -0
  138. package/packages/pi-ai/src/providers/openai-codex-responses.test.ts +63 -0
  139. package/packages/pi-ai/src/providers/openai-codex-responses.ts +91 -1
  140. package/packages/pi-ai/src/providers/simple-options.test.ts +60 -0
  141. package/packages/pi-ai/src/providers/simple-options.ts +5 -6
  142. package/packages/pi-ai/tsconfig.tsbuildinfo +1 -1
  143. package/packages/pi-coding-agent/dist/core/agent-session-thinking-level.test.d.ts +2 -0
  144. package/packages/pi-coding-agent/dist/core/agent-session-thinking-level.test.d.ts.map +1 -0
  145. package/packages/pi-coding-agent/dist/core/agent-session-thinking-level.test.js +66 -0
  146. package/packages/pi-coding-agent/dist/core/agent-session-thinking-level.test.js.map +1 -0
  147. package/packages/pi-coding-agent/dist/core/agent-session.js +1 -1
  148. package/packages/pi-coding-agent/dist/core/agent-session.js.map +1 -1
  149. package/packages/pi-coding-agent/dist/modes/interactive/components/footer.d.ts.map +1 -1
  150. package/packages/pi-coding-agent/dist/modes/interactive/components/footer.js +24 -6
  151. package/packages/pi-coding-agent/dist/modes/interactive/components/footer.js.map +1 -1
  152. package/packages/pi-coding-agent/src/core/agent-session-thinking-level.test.ts +79 -0
  153. package/packages/pi-coding-agent/src/core/agent-session.ts +1 -1
  154. package/packages/pi-coding-agent/src/modes/interactive/components/footer.ts +23 -7
  155. package/packages/pi-coding-agent/tsconfig.tsbuildinfo +1 -1
  156. package/src/resources/GSD-WORKFLOW.md +7 -0
  157. package/src/resources/extensions/claude-code-cli/partial-builder.ts +2 -1
  158. package/src/resources/extensions/claude-code-cli/tests/partial-builder.test.ts +19 -2
  159. package/src/resources/extensions/gsd/auto/contracts.ts +14 -6
  160. package/src/resources/extensions/gsd/auto/infra-errors.ts +9 -3
  161. package/src/resources/extensions/gsd/auto/loop.ts +8 -5
  162. package/src/resources/extensions/gsd/auto/orchestrator.ts +11 -0
  163. package/src/resources/extensions/gsd/auto/phases.ts +30 -2
  164. package/src/resources/extensions/gsd/auto/workflow-memory-pressure.ts +13 -0
  165. package/src/resources/extensions/gsd/auto-dashboard.ts +72 -1
  166. package/src/resources/extensions/gsd/auto-dispatch.ts +14 -6
  167. package/src/resources/extensions/gsd/auto-model-selection.ts +2 -1
  168. package/src/resources/extensions/gsd/auto-post-unit.ts +77 -7
  169. package/src/resources/extensions/gsd/auto-recovery.ts +29 -0
  170. package/src/resources/extensions/gsd/auto-start.ts +92 -9
  171. package/src/resources/extensions/gsd/auto-worktree.ts +119 -1
  172. package/src/resources/extensions/gsd/auto.ts +40 -4
  173. package/src/resources/extensions/gsd/bootstrap/agent-end-recovery.ts +33 -6
  174. package/src/resources/extensions/gsd/bootstrap/db-tools.ts +9 -8
  175. package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +4 -2
  176. package/src/resources/extensions/gsd/bootstrap/subagent-input.ts +3 -1
  177. package/src/resources/extensions/gsd/bootstrap/write-gate.ts +16 -1
  178. package/src/resources/extensions/gsd/commands/handlers/core.ts +17 -1
  179. package/src/resources/extensions/gsd/crash-recovery.ts +30 -4
  180. package/src/resources/extensions/gsd/db/unit-dispatches.ts +4 -3
  181. package/src/resources/extensions/gsd/dispatch-guard.ts +2 -2
  182. package/src/resources/extensions/gsd/doctor-git-checks.ts +45 -1
  183. package/src/resources/extensions/gsd/doctor-runtime-checks.ts +25 -13
  184. package/src/resources/extensions/gsd/doctor-types.ts +1 -0
  185. package/src/resources/extensions/gsd/doctor.ts +2 -27
  186. package/src/resources/extensions/gsd/export-html.ts +27 -427
  187. package/src/resources/extensions/gsd/git-service.ts +45 -1
  188. package/src/resources/extensions/gsd/gsd-db.ts +3 -0
  189. package/src/resources/extensions/gsd/guided-flow.ts +126 -128
  190. package/src/resources/extensions/gsd/guided-unit-context.ts +30 -0
  191. package/src/resources/extensions/gsd/migrate/parsers.ts +11 -0
  192. package/src/resources/extensions/gsd/migration-auto-check.ts +15 -23
  193. package/src/resources/extensions/gsd/milestone-actions.ts +10 -4
  194. package/src/resources/extensions/gsd/native-git-bridge.ts +54 -12
  195. package/src/resources/extensions/gsd/pending-auto-start.ts +79 -0
  196. package/src/resources/extensions/gsd/post-execution-checks.ts +87 -2
  197. package/src/resources/extensions/gsd/pre-execution-checks.ts +32 -1
  198. package/src/resources/extensions/gsd/prompt-loader.ts +1 -1
  199. package/src/resources/extensions/gsd/prompts/complete-milestone.md +1 -1
  200. package/src/resources/extensions/gsd/prompts/complete-slice.md +1 -1
  201. package/src/resources/extensions/gsd/prompts/discuss-headless.md +8 -8
  202. package/src/resources/extensions/gsd/prompts/discuss.md +9 -9
  203. package/src/resources/extensions/gsd/prompts/guided-discuss-project.md +4 -4
  204. package/src/resources/extensions/gsd/prompts/guided-discuss-requirements.md +3 -3
  205. package/src/resources/extensions/gsd/prompts/plan-slice.md +4 -4
  206. package/src/resources/extensions/gsd/prompts/queue.md +4 -4
  207. package/src/resources/extensions/gsd/prompts/refine-slice.md +2 -2
  208. package/src/resources/extensions/gsd/prompts/rewrite-docs.md +1 -1
  209. package/src/resources/extensions/gsd/smart-entry-routing.ts +77 -0
  210. package/src/resources/extensions/gsd/state-reconciliation/drift/merge-state.ts +8 -1
  211. package/src/resources/extensions/gsd/state-reconciliation/drift/project-md.ts +12 -15
  212. package/src/resources/extensions/gsd/state-reconciliation/drift/roadmap.ts +17 -25
  213. package/src/resources/extensions/gsd/status-guards.ts +5 -0
  214. package/src/resources/extensions/gsd/templates/plan.md +8 -5
  215. package/src/resources/extensions/gsd/templates/task-plan.md +4 -2
  216. package/src/resources/extensions/gsd/tests/auto-dashboard.test.ts +71 -0
  217. package/src/resources/extensions/gsd/tests/auto-deterministic-error-classification-4973.test.ts +116 -0
  218. package/src/resources/extensions/gsd/tests/auto-loop.test.ts +54 -0
  219. package/src/resources/extensions/gsd/tests/auto-orchestrator.test.ts +80 -1
  220. package/src/resources/extensions/gsd/tests/auto-paused-ui-cleanup.test.ts +6 -6
  221. package/src/resources/extensions/gsd/tests/auto-phases-lifecycle.test.ts +53 -2
  222. package/src/resources/extensions/gsd/tests/auto-post-unit-step-message.test.ts +12 -1
  223. package/src/resources/extensions/gsd/tests/auto-recovery.test.ts +15 -1
  224. package/src/resources/extensions/gsd/tests/auto-start-orphan-bootstrap.test.ts +1 -0
  225. package/src/resources/extensions/gsd/tests/auto-stop-notification.test.ts +20 -0
  226. package/src/resources/extensions/gsd/tests/auto-worktree-registry.test.ts +69 -1
  227. package/src/resources/extensions/gsd/tests/clear-stale-autostart.test.ts +11 -2
  228. package/src/resources/extensions/gsd/tests/complete-milestone.test.ts +4 -1
  229. package/src/resources/extensions/gsd/tests/complete-slice.test.ts +5 -9
  230. package/src/resources/extensions/gsd/tests/complete-task.test.ts +3 -1
  231. package/src/resources/extensions/gsd/tests/crash-recovery-via-db.test.ts +43 -2
  232. package/src/resources/extensions/gsd/tests/db-authority-regression.test.ts +208 -0
  233. package/src/resources/extensions/gsd/tests/deep-project-auto-loop.test.ts +59 -2
  234. package/src/resources/extensions/gsd/tests/dispatch-complete-milestone-guard.test.ts +39 -0
  235. package/src/resources/extensions/gsd/tests/dispatch-guard.test.ts +27 -0
  236. package/src/resources/extensions/gsd/tests/doctor-empty-worktree.test.ts +65 -0
  237. package/src/resources/extensions/gsd/tests/export-html-enhancements.test.ts +8 -0
  238. package/src/resources/extensions/gsd/tests/guided-discuss-project-prompt-rendering.test.ts +2 -0
  239. package/src/resources/extensions/gsd/tests/guided-dispatch-root.test.ts +106 -0
  240. package/src/resources/extensions/gsd/tests/guided-flow-session-isolation.test.ts +59 -11
  241. package/src/resources/extensions/gsd/tests/guided-flow.test.ts +21 -0
  242. package/src/resources/extensions/gsd/tests/guided-tool-contract.test.ts +65 -0
  243. package/src/resources/extensions/gsd/tests/headless-milestone-parity.test.ts +7 -7
  244. package/src/resources/extensions/gsd/tests/hook-model-resolution.test.ts +5 -0
  245. package/src/resources/extensions/gsd/tests/infra-error.test.ts +2 -2
  246. package/src/resources/extensions/gsd/tests/infra-errors-cooldown.test.ts +9 -0
  247. package/src/resources/extensions/gsd/tests/integration/doctor-runtime.test.ts +20 -0
  248. package/src/resources/extensions/gsd/tests/integration/git-service.test.ts +103 -1
  249. package/src/resources/extensions/gsd/tests/integration/state-machine-runtime-failures.test.ts +6 -1
  250. package/src/resources/extensions/gsd/tests/migrate-validator-parsers.test.ts +24 -1
  251. package/src/resources/extensions/gsd/tests/migration-auto-check.test.ts +26 -18
  252. package/src/resources/extensions/gsd/tests/native-git-bridge-exec-fallback.test.ts +63 -2
  253. package/src/resources/extensions/gsd/tests/orphaned-worktree-audit.test.ts +121 -1
  254. package/src/resources/extensions/gsd/tests/park-db-sync.test.ts +55 -1
  255. package/src/resources/extensions/gsd/tests/pending-autostart-scope.test.ts +29 -5
  256. package/src/resources/extensions/gsd/tests/plan-milestone.test.ts +26 -0
  257. package/src/resources/extensions/gsd/tests/plan-slice-prompt.test.ts +2 -0
  258. package/src/resources/extensions/gsd/tests/plan-slice.test.ts +225 -1
  259. package/src/resources/extensions/gsd/tests/plan-task.test.ts +17 -0
  260. package/src/resources/extensions/gsd/tests/post-execution-checks.test.ts +86 -0
  261. package/src/resources/extensions/gsd/tests/post-unit-git-failure.test.ts +1 -1
  262. package/src/resources/extensions/gsd/tests/pre-execution-checks.test.ts +53 -0
  263. package/src/resources/extensions/gsd/tests/prompt-loader.test.ts +23 -0
  264. package/src/resources/extensions/gsd/tests/provider-errors.test.ts +20 -1
  265. package/src/resources/extensions/gsd/tests/remediation-completion-guard.test.ts +46 -2
  266. package/src/resources/extensions/gsd/tests/session-switch-abort-misclassification.test.ts +10 -0
  267. package/src/resources/extensions/gsd/tests/smart-entry-routing.test.ts +113 -0
  268. package/src/resources/extensions/gsd/tests/start-auto-detached.test.ts +53 -2
  269. package/src/resources/extensions/gsd/tests/state-reconciliation-drift.test.ts +119 -23
  270. package/src/resources/extensions/gsd/tests/stuck-state-via-db.test.ts +64 -1
  271. package/src/resources/extensions/gsd/tests/summary-render-parity.test.ts +7 -3
  272. package/src/resources/extensions/gsd/tests/unit-context-manifest.test.ts +65 -7
  273. package/src/resources/extensions/gsd/tests/verification-gate.test.ts +110 -1
  274. package/src/resources/extensions/gsd/tests/workflow-mcp.test.ts +1 -1
  275. package/src/resources/extensions/gsd/tests/workflow-memory-pressure.test.ts +21 -1
  276. package/src/resources/extensions/gsd/tests/workflow-tool-executors.test.ts +1 -1
  277. package/src/resources/extensions/gsd/tests/worktree-git-pathspec.test.ts +39 -0
  278. package/src/resources/extensions/gsd/tests/worktree-journal-events.test.ts +64 -12
  279. package/src/resources/extensions/gsd/tests/write-gate-planning-unit.test.ts +38 -0
  280. package/src/resources/extensions/gsd/tools/complete-milestone.ts +8 -10
  281. package/src/resources/extensions/gsd/tools/complete-slice.ts +6 -8
  282. package/src/resources/extensions/gsd/tools/plan-milestone.ts +5 -1
  283. package/src/resources/extensions/gsd/tools/plan-slice.ts +98 -12
  284. package/src/resources/extensions/gsd/types.ts +1 -1
  285. package/src/resources/extensions/gsd/unit-context-manifest.ts +12 -9
  286. package/src/resources/extensions/gsd/validation.ts +23 -1
  287. package/src/resources/extensions/gsd/verification-gate.ts +78 -6
  288. package/src/resources/extensions/gsd/workflow-projections.ts +6 -8
  289. package/src/resources/extensions/gsd/worktree-lifecycle.ts +41 -8
  290. package/src/resources/extensions/shared/html-shell.ts +412 -0
  291. package/src/resources/extensions/visual-brief/page-contract.ts +2 -0
  292. package/src/resources/extensions/visual-brief/prompts.ts +37 -1
  293. package/src/resources/extensions/visual-brief/tests/visual-brief.test.ts +40 -0
  294. package/dist/web/standalone/.next/server/chunks/5822.js +0 -2
  295. package/dist/web/standalone/.next/static/chunks/app/layout-a16c7a7ecdf0c2cf.js +0 -1
  296. package/dist/web/standalone/.next/static/css/0262768ec1b89d34.css +0 -1
  297. package/dist/web/standalone/.next/static/css/de70bee13400563f.css +0 -1
  298. package/dist/web/standalone/.next/static/media/4cf2300e9c8272f7-s.p.woff2 +0 -0
  299. package/dist/web/standalone/.next/static/media/747892c23ea88013-s.woff2 +0 -0
  300. package/dist/web/standalone/.next/static/media/8d697b304b401681-s.woff2 +0 -0
  301. package/dist/web/standalone/.next/static/media/93f479601ee12b01-s.p.woff2 +0 -0
  302. package/dist/web/standalone/.next/static/media/9610d9e46709d722-s.woff2 +0 -0
  303. package/dist/web/standalone/.next/static/media/ba015fad6dcf6784-s.woff2 +0 -0
  304. /package/dist/web/standalone/.next/static/{Qgr2B_MRhPxC0z8fwv4vT → kkGf3_VaPFkiDNV_D7Dtl}/_buildManifest.js +0 -0
  305. /package/dist/web/standalone/.next/static/{Qgr2B_MRhPxC0z8fwv4vT → kkGf3_VaPFkiDNV_D7Dtl}/_ssgManifest.js +0 -0
@@ -21,7 +21,7 @@ import { invalidateAllCaches } from "./cache.js";
21
21
  import { writeLock, clearLock } from "./crash-recovery.js";
22
22
  import { acquireSessionLock, releaseSessionLock, updateSessionLock, } from "./session-lock.js";
23
23
  import { ensureGitignore, untrackRuntimeFiles } from "./gitignore.js";
24
- import { nativeIsRepo, nativeInit, nativeAddAll, nativeCommit, nativeGetCurrentBranch, nativeDetectMainBranch, nativeCheckoutBranch, nativeBranchList, nativeBranchListMerged, nativeBranchDelete, nativeWorktreeRemove, nativeCommitCountBetween, } from "./native-git-bridge.js";
24
+ import { nativeIsRepo, nativeInit, nativeAddAll, nativeCommit, nativeGetCurrentBranch, nativeDetectMainBranch, nativeCheckoutBranch, nativeBranchList, nativeBranchExists, nativeBranchListMerged, nativeBranchDelete, nativeWorktreeRemove, nativeCommitCountBetween, } from "./native-git-bridge.js";
25
25
  import { GitServiceImpl } from "./git-service.js";
26
26
  import { captureIntegrationBranch, detectWorktreeName, setActiveMilestoneId, } from "./worktree.js";
27
27
  import { getAutoWorktreePath } from "./auto-worktree.js";
@@ -33,7 +33,7 @@ import { initRoutingHistory } from "./routing-history.js";
33
33
  import { restoreHookState, resetHookState } from "./post-unit-hooks.js";
34
34
  import { resetProactiveHealing, setLevelChangeCallback } from "./doctor-proactive.js";
35
35
  import { snapshotSkills } from "./skill-discovery.js";
36
- import { isDbAvailable, getMilestone, openDatabase, getDbStatus } from "./gsd-db.js";
36
+ import { isDbAvailable, getMilestone, getAllMilestones, openDatabase, getDbStatus } from "./gsd-db.js";
37
37
  import { isClosedStatus } from "./status-guards.js";
38
38
  import { classifyMilestoneSummaryContent } from "./milestone-summary-classifier.js";
39
39
  import { auditOrphanedPreflightStashes } from "./orphan-stash-audit.js";
@@ -88,9 +88,11 @@ export function decideSurvivorAction(hasSurvivorBranch, phase) {
88
88
  return "finalize";
89
89
  return "none";
90
90
  }
91
- export function auditOrphanedMilestoneBranches(basePath, isolationMode) {
91
+ export function auditOrphanedMilestoneBranches(basePath, isolationMode, gitDeps = {}) {
92
92
  const recovered = [];
93
93
  const warnings = [];
94
+ const branchList = gitDeps.branchList ?? nativeBranchList;
95
+ const branchExists = gitDeps.branchExists ?? nativeBranchExists;
94
96
  // Skip in none mode — no milestone branches are created
95
97
  if (isolationMode === "none")
96
98
  return { recovered, warnings };
@@ -98,15 +100,16 @@ export function auditOrphanedMilestoneBranches(basePath, isolationMode) {
98
100
  if (!isDbAvailable())
99
101
  return { recovered, warnings };
100
102
  let milestoneBranches;
103
+ let milestoneBranchListAvailable = true;
101
104
  try {
102
- milestoneBranches = nativeBranchList(basePath, "milestone/*");
105
+ milestoneBranches = branchList(basePath, "milestone/*");
103
106
  }
104
107
  catch {
105
- // git branch list failed — skip audit
106
- return { recovered, warnings };
108
+ milestoneBranchListAvailable = false;
109
+ // git branch list failed — fall through with an empty branch set so the
110
+ // branch-less orphan pass can still run after per-milestone verification.
111
+ milestoneBranches = [];
107
112
  }
108
- if (milestoneBranches.length === 0)
109
- return { recovered, warnings };
110
113
  // Detect main branch for merge-check
111
114
  let mainBranch;
112
115
  try {
@@ -236,6 +239,71 @@ export function auditOrphanedMilestoneBranches(basePath, isolationMode) {
236
239
  }
237
240
  }
238
241
  }
242
+ // Second pass (#5879): catch worktree directories stranded by a previous
243
+ // audit that deleted the milestone/* branch but failed to remove the
244
+ // directory (or the dir was orphaned by a separate path entirely, e.g.
245
+ // postflight-stash-restore-failed during closeout). The branch-keyed loop
246
+ // above is invisible to these cases — `nativeBranchList` returns nothing
247
+ // for the milestone, so the dir-cleanup block at line ~310 is never
248
+ // reached.
249
+ //
250
+ // Keyed on milestones whose DB status is `complete`. We do not iterate
251
+ // over arbitrary directories under .gsd/worktrees/ to avoid touching
252
+ // dirs that belong to an in-progress milestone whose branch was deleted
253
+ // separately — those are handled by the in-progress orphan path above
254
+ // when the branch is present, and by `/gsd doctor` when it is not.
255
+ const seenMilestoneIds = new Set(milestoneBranches.map((branch) => branch.replace(/^milestone\//, "")));
256
+ let completedMilestones = [];
257
+ try {
258
+ completedMilestones = getAllMilestones();
259
+ }
260
+ catch {
261
+ // DB read failure — skip the second pass; the first pass is still useful.
262
+ completedMilestones = [];
263
+ }
264
+ for (const m of completedMilestones) {
265
+ if (m.status !== "complete")
266
+ continue;
267
+ if (seenMilestoneIds.has(m.id))
268
+ continue; // already processed in the branch loop
269
+ if (!milestoneBranchListAvailable) {
270
+ try {
271
+ if (branchExists(basePath, `milestone/${m.id}`))
272
+ continue;
273
+ }
274
+ catch (err) {
275
+ warnings.push(`Could not verify whether milestone/${m.id} still exists; skipping branch-less worktree cleanup for safety: ${err instanceof Error ? err.message : String(err)}`);
276
+ continue;
277
+ }
278
+ }
279
+ const wtDir = getWorktreeDir(basePath, m.id);
280
+ if (!existsSync(wtDir))
281
+ continue;
282
+ if (!isInsideWorktreesDir(basePath, wtDir)) {
283
+ warnings.push(`Orphaned worktree directory for ${m.id} is outside .gsd/worktrees/ — skipping removal for safety.`);
284
+ continue;
285
+ }
286
+ // Try `git worktree remove` first in case the dir is still registered
287
+ // (defensive — usually it is not when we reach this branch-less pass).
288
+ try {
289
+ nativeWorktreeRemove(basePath, wtDir, true);
290
+ }
291
+ catch (e) {
292
+ logWarning("engine", `worktree remove failed (expected for branch-less orphans): ${e instanceof Error ? e.message : String(e)}`);
293
+ }
294
+ if (existsSync(wtDir)) {
295
+ try {
296
+ rmSync(wtDir, { recursive: true, force: true });
297
+ recovered.push(`Removed orphaned worktree directory for ${m.id} (branch already deleted).`);
298
+ }
299
+ catch (err) {
300
+ warnings.push(`Failed to remove orphaned worktree directory for ${m.id}: ${err instanceof Error ? err.message : String(err)}`);
301
+ }
302
+ }
303
+ else {
304
+ recovered.push(`Removed orphaned worktree directory for ${m.id} (branch already deleted).`);
305
+ }
306
+ }
239
307
  return { recovered, warnings };
240
308
  }
241
309
  /**
@@ -368,7 +436,7 @@ export function _mergeOrphanCompletedMilestone(lifecycle, orphanId, ui) {
368
436
  return { merged: false, error: err };
369
437
  }
370
438
  export async function bootstrapAutoSession(s, ctx, pi, base, verboseMode, requestedStepMode, deps, interrupted) {
371
- const { shouldUseWorktreeIsolation, registerSigtermHandler, lockBase, buildLifecycle, } = deps;
439
+ const { shouldUseWorktreeIsolation, registerSigtermHandler, registerAutoWorkerForSession, lockBase, buildLifecycle, } = deps;
372
440
  const dirCheck = validateDirectory(base);
373
441
  if (dirCheck.severity === "blocked") {
374
442
  ctx.ui.notify(dirCheck.reason, "error");
@@ -523,6 +591,7 @@ export async function bootstrapAutoSession(s, ctx, pi, base, verboseMode, reques
523
591
  // consult DB status and avoid clearing runtime units for milestones that
524
592
  // only have a failure-path SUMMARY on disk (#4663).
525
593
  await openProjectDbIfPresent(base);
594
+ registerAutoWorkerForSession(base);
526
595
  // Clean stale runtime unit files for completed milestones (#887).
527
596
  // DB-authoritative: when DB is available, require DB status to be closed
528
597
  // before clearing runtime units. A SUMMARY file alone is no longer
@@ -606,12 +675,16 @@ export async function bootstrapAutoSession(s, ctx, pi, base, verboseMode, reques
606
675
  // worktree cleanup) was never run — the survivor branch must be merged.
607
676
  // Applies to both worktree and branch isolation modes.
608
677
  let hasSurvivorBranch = false;
609
- if (state.activeMilestone &&
678
+ let survivorMilestoneId = state.activeMilestone?.id ?? null;
679
+ if (!survivorMilestoneId && state.phase === "complete") {
680
+ survivorMilestoneId = findUnmergedCompletedMilestone(base, getIsolationMode(base));
681
+ }
682
+ if (survivorMilestoneId &&
610
683
  (state.phase === "pre-planning" || state.phase === "complete") &&
611
684
  getIsolationMode(base) !== "none" &&
612
685
  !detectWorktreeName(base) &&
613
686
  !base.includes(`${pathSep}.gsd${pathSep}worktrees${pathSep}`)) {
614
- const milestoneBranch = `milestone/${state.activeMilestone.id}`;
687
+ const milestoneBranch = `milestone/${survivorMilestoneId}`;
615
688
  const { nativeBranchExists } = await import("./native-git-bridge.js");
616
689
  hasSurvivorBranch = nativeBranchExists(base, milestoneBranch);
617
690
  if (hasSurvivorBranch) {
@@ -645,7 +718,7 @@ export async function bootstrapAutoSession(s, ctx, pi, base, verboseMode, reques
645
718
  // Re-evaluate via the helper — the discuss branch above may have cleared
646
719
  // hasSurvivorBranch after a successful promotion.
647
720
  if (decideSurvivorAction(hasSurvivorBranch, state.phase) === "finalize") {
648
- const mid = state.activeMilestone.id;
721
+ const mid = survivorMilestoneId;
649
722
  // Commit 68ef58a3c made `_mergeBranchMode` throw on wrong-branch
650
723
  // instead of returning false silently. Wrap the call so the throw is
651
724
  // converted into an error notify + clean bootstrap abort, not an
@@ -173,7 +173,18 @@ function gitPathspecForWorktreePath(basePath, targetPath) {
173
173
  let base = basePath;
174
174
  let target = targetPath;
175
175
  try {
176
- base = realpathSync.native(basePath);
176
+ base = execFileSync("git", ["rev-parse", "--show-toplevel"], {
177
+ cwd: basePath,
178
+ stdio: ["ignore", "pipe", "ignore"],
179
+ encoding: "utf-8",
180
+ }).trim() || basePath;
181
+ }
182
+ catch {
183
+ /* keep original */
184
+ void base;
185
+ }
186
+ try {
187
+ base = realpathSync.native(base);
177
188
  }
178
189
  catch {
179
190
  /* keep original */
@@ -191,6 +202,9 @@ function gitPathspecForWorktreePath(basePath, targetPath) {
191
202
  return null;
192
203
  return rel.replaceAll("\\", "/");
193
204
  }
205
+ export function _gitPathspecForWorktreePath(basePath, targetPath) {
206
+ return gitPathspecForWorktreePath(basePath, targetPath);
207
+ }
194
208
  function gitRemoteExists(basePath, remote) {
195
209
  try {
196
210
  execFileSync("git", ["remote", "get-url", remote], {
@@ -204,6 +218,52 @@ function gitRemoteExists(basePath, remote) {
204
218
  return false;
205
219
  }
206
220
  }
221
+ function findRegularMergeChangedPaths(basePath, milestoneBranch, mainBranch) {
222
+ const changedPaths = new Set();
223
+ let mergeLog = "";
224
+ try {
225
+ mergeLog = execFileSync("git", ["rev-list", "--merges", "--parents", mainBranch], {
226
+ cwd: basePath,
227
+ stdio: ["ignore", "pipe", "pipe"],
228
+ encoding: "utf-8",
229
+ }).trim();
230
+ }
231
+ catch (err) {
232
+ logWarning("worktree", `regular merge lookup failed: ${err instanceof Error ? err.message : String(err)}`);
233
+ return changedPaths;
234
+ }
235
+ for (const line of mergeLog.split("\n").filter(Boolean)) {
236
+ const [mergeCommit, firstParent, ...otherParents] = line.split(" ");
237
+ if (!mergeCommit || !firstParent || otherParents.length === 0)
238
+ continue;
239
+ const mergedMilestone = otherParents.some((parent) => {
240
+ try {
241
+ return nativeIsAncestor(basePath, milestoneBranch, parent);
242
+ }
243
+ catch {
244
+ return false;
245
+ }
246
+ });
247
+ if (!mergedMilestone)
248
+ continue;
249
+ try {
250
+ const output = execFileSync("git", ["diff", "--name-only", firstParent, mergeCommit], {
251
+ cwd: basePath,
252
+ stdio: ["ignore", "pipe", "pipe"],
253
+ encoding: "utf-8",
254
+ }).trim();
255
+ for (const path of output.split("\n").filter(Boolean)) {
256
+ if (!path.startsWith(".gsd/"))
257
+ changedPaths.add(path);
258
+ }
259
+ }
260
+ catch (err) {
261
+ logWarning("worktree", `regular merge diff lookup failed: ${err instanceof Error ? err.message : String(err)}`);
262
+ }
263
+ return changedPaths;
264
+ }
265
+ return changedPaths;
266
+ }
207
267
  function clearProjectRootStateFiles(basePath, milestoneId) {
208
268
  const gsdDir = gsdRoot(basePath);
209
269
  // Phase C pt 2: auto.lock removed from this list — the file is gone
@@ -1482,6 +1542,56 @@ export function mergeMilestoneToMain(originalBasePath_, milestoneId, roadmapCont
1482
1542
  });
1483
1543
  }
1484
1544
  }
1545
+ // Already regular-merged milestones can skip the squash path and proceed to cleanup (#5831).
1546
+ if (nativeIsAncestor(originalBasePath_, milestoneBranch, mainBranch)) {
1547
+ const codeChanges = nativeDiffNumstat(originalBasePath_, mainBranch, milestoneBranch).filter((entry) => !entry.path.startsWith(".gsd/"));
1548
+ if (codeChanges.length > 0) {
1549
+ const regularMergeChangedPaths = findRegularMergeChangedPaths(originalBasePath_, milestoneBranch, mainBranch);
1550
+ const unanchoredCodeChanges = codeChanges.filter((entry) => regularMergeChangedPaths.has(entry.path));
1551
+ if (unanchoredCodeChanges.length > 0) {
1552
+ process.chdir(previousCwd);
1553
+ throw new GSDError(GSD_GIT_ERROR, `Milestone branch "${milestoneBranch}" is reachable from "${mainBranch}" ` +
1554
+ `but has ${unanchoredCodeChanges.length} milestone-touched code file(s) not on current "${mainBranch}". ` +
1555
+ `Aborting worktree teardown to prevent data loss.`);
1556
+ }
1557
+ }
1558
+ debugLog("mergeMilestoneToMain", {
1559
+ action: "skip-squash-already-merged",
1560
+ milestoneId,
1561
+ milestoneBranch,
1562
+ mainBranch,
1563
+ });
1564
+ try {
1565
+ clearProjectRootStateFiles(originalBasePath_, milestoneId);
1566
+ }
1567
+ catch (err) {
1568
+ logWarning("worktree", `clearProjectRootStateFiles failed during already-merged cleanup: ${err instanceof Error ? err.message : String(err)}`);
1569
+ }
1570
+ try {
1571
+ removeWorktree(originalBasePath_, milestoneId, {
1572
+ branch: milestoneBranch,
1573
+ deleteBranch: false,
1574
+ });
1575
+ }
1576
+ catch (err) {
1577
+ logWarning("worktree", `worktree removal failed: ${err instanceof Error ? err.message : String(err)}`);
1578
+ }
1579
+ try {
1580
+ nativeBranchDelete(originalBasePath_, milestoneBranch);
1581
+ }
1582
+ catch (err) {
1583
+ logWarning("worktree", `git branch-delete failed: ${err instanceof Error ? err.message : String(err)}`);
1584
+ }
1585
+ setActiveWorkspace(null);
1586
+ nudgeGitBranchCache(previousCwd);
1587
+ try {
1588
+ process.chdir(originalBasePath_);
1589
+ }
1590
+ catch (err) {
1591
+ logWarning("worktree", `chdir to project root after already-merged cleanup failed: ${err instanceof Error ? err.message : String(err)}`);
1592
+ }
1593
+ return { commitMessage, pushed: false, prCreated: false, codeFilesChanged: true };
1594
+ }
1485
1595
  // 7. Shelter queued milestone directories before the squash merge (#2505).
1486
1596
  // The milestone branch may contain copies of queued milestone dirs (via
1487
1597
  // copyPlanningArtifacts), so `git merge --squash` rejects when those same
@@ -22,7 +22,7 @@ import { gsdRoot, resolveMilestoneFile, resolveMilestonePath, resolveDir, milest
22
22
  import { invalidateAllCaches } from "./cache.js";
23
23
  import { clearActivityLogState } from "./activity-log.js";
24
24
  import { synthesizeCrashRecovery, getDeepDiagnostic, readActiveMilestoneId, } from "./session-forensics.js";
25
- import { writeLock, clearLock, readCrashLock, isLockProcessAlive, formatCrashInfo, emitCrashRecoveredUnitEnd, emitOpenUnitEndForUnit, } from "./crash-recovery.js";
25
+ import { writeLock, clearLock, clearStaleWorkerLock, readCrashLock, isLockProcessAlive, formatCrashInfo, emitCrashRecoveredUnitEnd, emitOpenUnitEndForUnit, } from "./crash-recovery.js";
26
26
  import { acquireSessionLock, getSessionLockStatus, releaseSessionLock, updateSessionLock, } from "./session-lock.js";
27
27
  import { resolveAutoSupervisorConfig, loadEffectiveGSDPreferences, getIsolationMode, } from "./preferences.js";
28
28
  import { sendDesktopNotification } from "./notifications.js";
@@ -127,6 +127,12 @@ import { normalizeRealPath } from "./paths.js";
127
127
  // ─────────────────────────────────────────────────────────────────────────────
128
128
  /** Throttle STATE.md rebuilds — at most once per 30 seconds */
129
129
  const STATE_REBUILD_MIN_INTERVAL_MS = 30_000;
130
+ export function formatAutoStopNotification(prefix, totals, unitCount) {
131
+ return [
132
+ `${prefix}.`,
133
+ `Session: ${formatCost(totals.cost)} · ${formatTokenCount(totals.tokens.total)} tokens · ${unitCount} units`,
134
+ ].join("\n");
135
+ }
130
136
  /**
131
137
  * Phase B — register this auto-mode process in the workers table so other
132
138
  * workers and janitors can detect liveness via heartbeat. Best-effort: if
@@ -707,6 +713,7 @@ export async function cleanupAfterLoopExit(ctx) {
707
713
  // visible so the user still has a resumable auto-mode signal on screen.
708
714
  if (!s.paused) {
709
715
  ctx.ui.setStatus("gsd-auto", undefined);
716
+ ctx.ui.setWidget("gsd-progress", undefined);
710
717
  if (s.completionStopInProgress) {
711
718
  s.completionStopInProgress = false;
712
719
  }
@@ -1029,7 +1036,7 @@ export async function stopAuto(ctx, pi, reason, options = {}) {
1029
1036
  : `Auto-mode stopped${reasonSuffix}`;
1030
1037
  if (ledger && ledger.units.length > 0) {
1031
1038
  const totals = getProjectTotals(ledger.units);
1032
- ctx?.ui.notify(`${notificationPrefix}. Session: ${formatCost(totals.cost)} · ${formatTokenCount(totals.tokens.total)} tokens · ${ledger.units.length} units`, "info");
1039
+ ctx?.ui.notify(formatAutoStopNotification(notificationPrefix, totals, ledger.units.length), "info");
1033
1040
  }
1034
1041
  else {
1035
1042
  ctx?.ui.notify(`${notificationPrefix}.`, "info");
@@ -1420,6 +1427,13 @@ export function createWiredDispatchAdapter(ctx, pi, dispatchBasePath) {
1420
1427
  sessionProvider,
1421
1428
  modelRegistry,
1422
1429
  });
1430
+ if (action.action === "stop") {
1431
+ return {
1432
+ kind: "blocked",
1433
+ reason: action.reason,
1434
+ action: action.level === "warning" ? "pause" : "stop",
1435
+ };
1436
+ }
1423
1437
  if (action.action !== "dispatch")
1424
1438
  return null;
1425
1439
  return {
@@ -1640,6 +1654,17 @@ export function createWiredAutoOrchestrationModule(ctx, pi, dispatchBasePath, ru
1640
1654
  };
1641
1655
  return createAutoOrchestrator(deps);
1642
1656
  }
1657
+ function notifyResumeBlocked(ctx, result) {
1658
+ const resumeCmd = s.stepMode ? "/gsd next" : "/gsd auto";
1659
+ ctx.ui.notify(`Auto-mode blocked: ${result.reason}. Fix and run ${resumeCmd} to resume.`, "warning");
1660
+ setLifecycleOutcome(ctx, {
1661
+ status: "blocked",
1662
+ title: "Auto-mode blocked",
1663
+ detail: result.reason,
1664
+ nextAction: `Fix the blocker, then run ${resumeCmd} to resume.`,
1665
+ commands: ["/gsd status for overview", `${resumeCmd} to resume`, "/gsd doctor to diagnose"],
1666
+ });
1667
+ }
1643
1668
  function ensureOrchestrationModule(ctx, pi, basePath) {
1644
1669
  s.orchestration = createWiredAutoOrchestrationModule(ctx, pi, basePath, lockBase());
1645
1670
  }
@@ -1924,7 +1949,7 @@ export async function startAuto(ctx, pi, base, verboseMode, options) {
1924
1949
  // This closes the journal gap reported in #3348 where the worker wrote side
1925
1950
  // effects (SUMMARY.md, DB updates) but died before emitting unit-end.
1926
1951
  emitCrashRecoveredUnitEnd(base, freshStartAssessment.lock);
1927
- clearLock(base);
1952
+ clearStaleWorkerLock(base);
1928
1953
  }
1929
1954
  if (!s.paused) {
1930
1955
  s.pendingCrashRecovery =
@@ -1987,6 +2012,8 @@ export async function startAuto(ctx, pi, base, verboseMode, options) {
1987
2012
  initMetrics(base);
1988
2013
  if (s.currentMilestoneId)
1989
2014
  setActiveMilestoneId(base, s.currentMilestoneId);
2015
+ await openProjectDbIfPresent(base);
2016
+ registerAutoWorkerForSession(s, base);
1990
2017
  // Re-register health level notification callback lost across process restart
1991
2018
  setLevelChangeCallback((_from, to, summary) => {
1992
2019
  const level = to === "red" ? "error" : to === "yellow" ? "warning" : "info";
@@ -2062,7 +2089,12 @@ export async function startAuto(ctx, pi, base, verboseMode, options) {
2062
2089
  }
2063
2090
  pi.events.emit(CMUX_CHANNELS.LOG, { preferences: loadEffectiveGSDPreferences(s.basePath || undefined)?.preferences, message: s.stepMode ? "Step-mode resumed." : "Auto-mode resumed.", level: "progress" });
2064
2091
  try {
2065
- await s.orchestration?.resume();
2092
+ const resumeResult = await s.orchestration?.resume();
2093
+ if (resumeResult?.kind === "blocked") {
2094
+ notifyResumeBlocked(ctx, resumeResult);
2095
+ await cleanupAfterLoopExit(ctx);
2096
+ return;
2097
+ }
2066
2098
  }
2067
2099
  catch (err) {
2068
2100
  debugLog("resume-orchestration-resume", { error: err instanceof Error ? err.message : String(err) });
@@ -2083,6 +2115,7 @@ export async function startAuto(ctx, pi, base, verboseMode, options) {
2083
2115
  const bootstrapDeps = {
2084
2116
  shouldUseWorktreeIsolation,
2085
2117
  registerSigtermHandler,
2118
+ registerAutoWorkerForSession: (projectRoot) => registerAutoWorkerForSession(s, projectRoot),
2086
2119
  lockBase,
2087
2120
  buildLifecycle,
2088
2121
  };
@@ -10,6 +10,7 @@ import { shouldIgnoreAgentEndForActiveUnit } from "../auto/unit-runner-events.js
10
10
  import { resolveModelId } from "../auto-model-selection.js";
11
11
  import { resolveProjectRoot } from "../worktree.js";
12
12
  import { clearDiscussionFlowState } from "./write-gate.js";
13
+ import { clearGuidedUnitContext } from "../guided-unit-context.js";
13
14
  import { resumeAutoAfterProviderDelay } from "./provider-error-resume.js";
14
15
  import { classifyError, createRetryState, resetRetryState, isTransient, } from "../error-classifier.js";
15
16
  import { blockModel, isModelBlocked } from "../blocked-models.js";
@@ -18,6 +19,9 @@ const MAX_NETWORK_RETRIES = 2;
18
19
  function isObjectRecord(value) {
19
20
  return !!value && typeof value === "object";
20
21
  }
22
+ export function _hasEmptyAgentEndContent(content) {
23
+ return content == null || (Array.isArray(content) && content.length === 0);
24
+ }
21
25
  /**
22
26
  * Cap on auto-resume attempts for sustained transient-provider errors.
23
27
  *
@@ -150,6 +154,13 @@ export function resolveAgentEndErrorDisplay(rawErrorMsg, content) {
150
154
  }
151
155
  return rawErrorMsg;
152
156
  }
157
+ export function isTerminalDeletedWorktreeProviderError(message) {
158
+ if (!message)
159
+ return false;
160
+ if (!/\bdoes not exist\b/i.test(message))
161
+ return false;
162
+ return /[/\\]\.gsd[/\\](?:projects[/\\][^/\\]+[/\\])?worktrees[/\\][^/\\\s"']+/i.test(message);
163
+ }
153
164
  async function pauseTransientWithBackoff(cls, pi, ctx, errorDetail, isRateLimit) {
154
165
  retryState.consecutiveTransientCount += 1;
155
166
  const baseRetryAfterMs = "retryAfterMs" in cls ? cls.retryAfterMs : 15_000;
@@ -187,8 +198,10 @@ export async function handleAgentEnd(pi, event, ctx) {
187
198
  // falsely report files as missing — producing a spurious "ready signal
188
199
  // rejected" loop even though the files are on disk.
189
200
  clearPathCache();
201
+ const basePath = resolveAgentEndBasePath();
202
+ clearGuidedUnitContext(basePath);
190
203
  try {
191
- if (await checkDeepProjectSetupAfterTurn(event, ctx, resolveAgentEndBasePath())) {
204
+ if (await checkDeepProjectSetupAfterTurn(event, ctx, basePath)) {
192
205
  return;
193
206
  }
194
207
  }
@@ -196,22 +209,22 @@ export async function handleAgentEnd(pi, event, ctx) {
196
209
  const message = err instanceof Error ? err.message : String(err);
197
210
  logWarning("bootstrap", `checkDeepProjectSetupAfterTurn failed: ${message}`);
198
211
  }
199
- if (checkAutoStartAfterDiscuss()) {
200
- clearDiscussionFlowState(resolveAgentEndBasePath() ?? process.cwd());
212
+ if (checkAutoStartAfterDiscuss(basePath)) {
213
+ clearDiscussionFlowState(basePath ?? process.cwd());
201
214
  return;
202
215
  }
203
216
  // #4573 — When the LLM emits "Milestone X ready." but the required files
204
217
  // are missing, `checkAutoStartAfterDiscuss` returns false silently. Surface
205
218
  // that and nudge the LLM to complete the writes before the user hits the
206
219
  // downstream "All milestones complete" warning loop.
207
- if (maybeHandleReadyPhraseWithoutFiles(event))
220
+ if (maybeHandleReadyPhraseWithoutFiles(event, basePath))
208
221
  return;
209
222
  // #4573 — Empty-turn recovery: if the LLM announced intent in prose but
210
223
  // emitted no tool calls, nudge it to execute. Fires only when auto-mode is
211
224
  // active or a discussion autostart is pending (non-auto interactive discuss
212
225
  // is user-driven). Runs before `isAutoActive` early return so pending
213
226
  // discussions (where isAutoActive may be false) still get recovered.
214
- if (maybeHandleEmptyIntentTurn(event, isAutoActive()))
227
+ if (maybeHandleEmptyIntentTurn(event, isAutoActive(), basePath))
215
228
  return;
216
229
  if (!isAutoActive())
217
230
  return;
@@ -246,7 +259,7 @@ export async function handleAgentEnd(pi, event, ctx) {
246
259
  // that carry error context — e.g. errorMessage field or non-empty content
247
260
  // indicating a mid-stream failure. (#2695)
248
261
  const content = "content" in lastMsg ? lastMsg.content : undefined;
249
- const hasEmptyContent = Array.isArray(content) && content.length === 0;
262
+ const hasEmptyContent = _hasEmptyAgentEndContent(content);
250
263
  const hasErrorMessage = "errorMessage" in lastMsg && !!lastMsg.errorMessage;
251
264
  if (hasEmptyContent && !hasErrorMessage) {
252
265
  // Non-fatal: treat as a normal agent end so the loop can continue
@@ -292,6 +305,12 @@ export async function handleAgentEnd(pi, event, ctx) {
292
305
  // the assistant message text content for display purposes only.
293
306
  // Classification still uses rawErrorMsg to avoid false positives from prose.
294
307
  const displayMsg = resolveAgentEndErrorDisplay(rawErrorMsg, "content" in lastMsg ? lastMsg.content : undefined);
308
+ if (isAutoCompletionStopInProgress() &&
309
+ isTerminalDeletedWorktreeProviderError(`${rawErrorMsg}\n${displayMsg}`)) {
310
+ resetRetryState(retryState);
311
+ logWarning("bootstrap", `Ignoring stale deleted-worktree provider error during terminal completion reroot: ${displayMsg || rawErrorMsg}`);
312
+ return;
313
+ }
295
314
  const errorDetail = displayMsg ? `: ${displayMsg}` : "";
296
315
  const explicitRetryAfterMs = ("retryAfterMs" in lastMsg && typeof lastMsg.retryAfterMs === "number") ? lastMsg.retryAfterMs : undefined;
297
316
  // ── 1. Classify using rawErrorMsg to avoid prose false-positives ────
@@ -468,17 +468,18 @@ export function registerDbTools(pi) {
468
468
  promptGuidelines: [
469
469
  "Use gsd_plan_milestone for milestone planning instead of writing ROADMAP.md directly.",
470
470
  "Keep parameters flat and provide the full milestone planning payload, including slices.",
471
+ "Milestone and slice titles must not contain forward slash (/), en dash, or em dash characters.",
471
472
  "The tool validates input, writes milestone and slice planning data transactionally, renders ROADMAP.md from DB, and clears both state and parse caches after success.",
472
473
  "Use the canonical name gsd_plan_milestone; gsd_milestone_plan is only an alias.",
473
474
  ],
474
475
  parameters: Type.Object({
475
476
  // ── Core identification + content (required) ──────────────────────
476
477
  milestoneId: Type.String({ description: "Milestone ID (e.g. M001)" }),
477
- title: Type.String({ description: "Milestone title" }),
478
+ title: Type.String({ description: "Milestone title; must not contain forward slash (/), en dash, or em dash characters" }),
478
479
  vision: Type.String({ description: "Milestone vision" }),
479
480
  slices: Type.Array(Type.Object({
480
481
  sliceId: Type.String({ description: "Slice ID (e.g. S01)" }),
481
- title: Type.String({ description: "Slice title" }),
482
+ title: Type.String({ description: "Slice title; must not contain forward slash (/), en dash, or em dash characters" }),
482
483
  risk: Type.String({ description: "Slice risk" }),
483
484
  depends: Type.Array(Type.String(), { description: "Slice dependency IDs" }),
484
485
  demo: Type.String({ description: "Roadmap demo text / After this" }),
@@ -546,10 +547,10 @@ export function registerDbTools(pi) {
546
547
  title: Type.String({ description: "Task title" }),
547
548
  description: Type.String({ description: "Task description / steps block" }),
548
549
  estimate: Type.String({ description: "Task estimate string" }),
549
- files: Type.Array(Type.String(), { description: "Files likely touched" }),
550
+ files: Type.Array(Type.String(), { description: "Array<string> of files likely touched; pass [\"path\"] or [], never a single string" }),
550
551
  verify: Type.String({ description: "Verification command or block" }),
551
- inputs: Type.Array(Type.String(), { description: "Input files or references" }),
552
- expectedOutput: Type.Array(Type.String(), { description: "Expected output files or artifacts" }),
552
+ inputs: Type.Array(Type.String(), { description: "Array<string> of input files or references; pass [\"path\"] or [], never a single string" }),
553
+ expectedOutput: Type.Array(Type.String(), { description: "Array<string> of expected output files or artifacts; pass [\"path\"] or [], never a single string" }),
553
554
  observabilityImpact: Type.Optional(Type.String({ description: "Task observability impact" })),
554
555
  }), { description: "Planned tasks for the slice" }),
555
556
  // ── Enrichment metadata (optional — defaults to empty) ────────────
@@ -622,10 +623,10 @@ export function registerDbTools(pi) {
622
623
  title: Type.String({ description: "Task title" }),
623
624
  description: Type.String({ description: "Task description / steps block" }),
624
625
  estimate: Type.String({ description: "Task estimate string" }),
625
- files: Type.Array(Type.String(), { description: "Files likely touched" }),
626
+ files: Type.Array(Type.String(), { description: "Array<string> of files likely touched; pass [\"path\"] or [], never a single string" }),
626
627
  verify: Type.String({ description: "Verification command or block" }),
627
- inputs: Type.Array(Type.String(), { description: "Input files or references" }),
628
- expectedOutput: Type.Array(Type.String(), { description: "Expected output files or artifacts" }),
628
+ inputs: Type.Array(Type.String(), { description: "Array<string> of input files or references; pass [\"path\"] or [], never a single string" }),
629
+ expectedOutput: Type.Array(Type.String(), { description: "Array<string> of expected output files or artifacts; pass [\"path\"] or [], never a single string" }),
629
630
  observabilityImpact: Type.Optional(Type.String({ description: "Task observability impact" })),
630
631
  // Single-writer v3 audit trail (Stream 2): caller-provided actor identity + causation.
631
632
  actorName: Type.Optional(Type.String({ description: "Caller-provided actor identity for the audit trail (e.g. 'executor-01', 'gsd-orchestrator')" })),
@@ -24,6 +24,7 @@ import { resolveWorktreeProjectRoot } from "../worktree-root.js";
24
24
  import { extractSubagentAgentClasses } from "./subagent-input.js";
25
25
  import { approvalGateIdForUnit, isExplicitApprovalResponse, shouldPauseForUserApprovalQuestion } from "../user-input-boundary.js";
26
26
  import { resolveSkillManifest } from "../skill-manifest.js";
27
+ import { getGuidedUnitContext } from "../guided-unit-context.js";
27
28
  let approvalQuestionAbortInFlight = false;
28
29
  async function loadWelcomeScreenModule() {
29
30
  const candidates = [];
@@ -675,7 +676,8 @@ export function registerHooks(pi, ecosystemHandlers) {
675
676
  // subagent dispatch. Closes the b23 bug class where a discuss-milestone
676
677
  // turn used the host Edit tool to modify user source files.
677
678
  const dash = getAutoRuntimeSnapshot();
678
- const activeUnitType = dash.currentUnit?.type;
679
+ const guidedUnit = getGuidedUnitContext(discussionBasePath);
680
+ const activeUnitType = dash.currentUnit?.type ?? guidedUnit?.unitType;
679
681
  if (activeUnitType) {
680
682
  const manifest = resolveManifest(activeUnitType);
681
683
  if (manifest) {
@@ -694,7 +696,7 @@ export function registerHooks(pi, ecosystemHandlers) {
694
696
  // Subagent inputs use { agent }, { tasks: [{ agent }] }, or { chain: [{ agent }] }.
695
697
  agentClasses = extractSubagentAgentClasses(event.input);
696
698
  }
697
- const planningGuard = shouldBlockPlanningUnit(event.toolName, planningInput, dash.basePath || discussionBasePath, activeUnitType, manifest.tools, agentClasses);
699
+ const planningGuard = shouldBlockPlanningUnit(event.toolName, planningInput, dash.basePath || guidedUnit?.basePath || discussionBasePath, activeUnitType, manifest.tools, agentClasses);
698
700
  if (planningGuard.block)
699
701
  return planningGuard;
700
702
  }
@@ -4,8 +4,11 @@ export function extractSubagentAgentClasses(input) {
4
4
  const agentClasses = [];
5
5
  const visited = new WeakSet();
6
6
  const addAgentClass = (value) => {
7
- if (typeof value === "string" && value.trim().length > 0)
8
- agentClasses.push(value.trim());
7
+ if (typeof value !== "string")
8
+ return;
9
+ const normalized = value.trim().replace(/\.md$/i, "");
10
+ if (normalized.length > 0)
11
+ agentClasses.push(normalized);
9
12
  };
10
13
  const visitItems = (value) => {
11
14
  if (!Array.isArray(value))
@@ -59,6 +59,7 @@ const QUEUE_SAFE_TOOLS = new Set([
59
59
  * true / false — shell no-ops / test exit codes
60
60
  */
61
61
  const BASH_READ_ONLY_RE = /^\s*(cat|head|tail|less|more|wc|file|stat|du|df|which|type|echo|printf|ls|find|grep|rg|awk|sed\b(?!.*-i)|sort|uniq|diff|comm|tr|cut|tee\s+-a\s+\/dev\/null|git\s+(log|show|diff|status|branch|tag|remote|rev-parse|ls-files|blame|shortlog|describe|stash\s+list|config\s+--get|cat-file)|gh\s+(issue|pr|api|repo|release)\s+(view|list|diff|status|checks)|mkdir\s+-p\s+\.gsd|rtk\s|npm\s+run\s+(test|test:\w+|lint|lint:\w+|typecheck|type-check|type-check:\w+|check|verify|audit|outdated|format:check|ci|validate)\b|npm\s+(ls|list|info|view|show|outdated|audit|explain|doctor|ping|--version|-v)\b|npx\s|tsx\s|node\s+(--print|--version|-v\b)|python[23]?\s+(-c\s+'[^']*'|--version|-V\b|-m\s+(pip\s+show|pip\s+list|site))|pip[23]?\s+(show|list|freeze|check|index\s+versions)\b|jq\s|yq\s|curl\s+(-s\b|--silent\b)(?!\s+[^|>]*\s-[oO]\b)(?!\s+[^|>]*\s--output\b)[^|>]*$|openssl\s+(version|x509|s_client)|env\b|printenv\b|true\b|false\b)/;
62
+ const BASH_VERIFICATION_RE = /^\s*(npm\s+(run\s+(build|test|test:\w+|lint|lint:\w+|typecheck|type-check|verify|ci|validate)\b|test\b)|pnpm\s+(build|test|lint|typecheck|verify)\b|yarn\s+(build|test|lint|typecheck|verify)\b|vitest\b|jest\b|go\s+test\b)/;
62
63
  function createEmptyWriteGateState() {
63
64
  return {
64
65
  verifiedDepthMilestones: new Set(),
@@ -643,6 +644,9 @@ function blockReason(unitType, mode, what) {
643
644
  * and listed in the policy's allowedSubagents.
644
645
  * - "docs" → like "planning" but also allows writes to paths
645
646
  * matching `allowedPathGlobs` relative to basePath.
647
+ * - "verification"
648
+ * → allows Bash for project verification commands, but keeps
649
+ * writes restricted to .gsd/ and blocks subagent dispatch.
646
650
  *
647
651
  * `pathOrCommand` is the file path for write/edit-shaped tools and the
648
652
  * shell command for bash. Other tools ignore this argument.
@@ -674,7 +678,7 @@ export function shouldBlockPlanningUnit(toolName, pathOrCommand, basePath, unitT
674
678
  // Unknown tool in read-only mode — block by default.
675
679
  return { block: true, reason: blockReason(unitType, policy.mode, `tool "${tool}" is not on the read-only allowlist`) };
676
680
  }
677
- // planning / planning-dispatch / docs modes share the same surface for safe tools, bash, and subagent.
681
+ // planning / planning-dispatch / docs / verification modes share the same surface for safe tools, bash, and subagent.
678
682
  if (PLANNING_SAFE_TOOLS.has(tool))
679
683
  return { block: false };
680
684
  if (tool.startsWith("gsd_"))
@@ -720,6 +724,14 @@ export function shouldBlockPlanningUnit(toolName, pathOrCommand, basePath, unitT
720
724
  return { block: true, reason: blockReason(unitType, policy.mode, `subagent dispatch is not permitted in planning units`) };
721
725
  }
722
726
  if (tool === "bash") {
727
+ if (policy.mode === "verification") {
728
+ if (BASH_VERIFICATION_RE.test(pathOrCommand) || BASH_READ_ONLY_RE.test(pathOrCommand))
729
+ return { block: false };
730
+ return {
731
+ block: true,
732
+ reason: blockReason(unitType, policy.mode, `bash is restricted to build/test verification commands (npm run build, npm test, etc.); cannot run "${pathOrCommand.slice(0, 80)}${pathOrCommand.length > 80 ? "…" : ""}"`),
733
+ };
734
+ }
723
735
  if (BASH_READ_ONLY_RE.test(pathOrCommand))
724
736
  return { block: false };
725
737
  return {