gsd-pi 2.78.1-dev.b0759e59b → 2.78.1-dev.d8826a445

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 (300) hide show
  1. package/README.md +8 -5
  2. package/dist/headless-recover.d.ts +23 -0
  3. package/dist/headless-recover.js +93 -0
  4. package/dist/headless.js +9 -0
  5. package/dist/help-text.js +1 -0
  6. package/dist/resources/.managed-resources-content-hash +1 -1
  7. package/dist/resources/extensions/browser-tools/tools/intent.js +8 -1
  8. package/dist/resources/extensions/gsd/auto/phases.js +7 -2
  9. package/dist/resources/extensions/gsd/auto/session.js +3 -0
  10. package/dist/resources/extensions/gsd/auto-dispatch.js +7 -58
  11. package/dist/resources/extensions/gsd/auto-post-unit.js +14 -28
  12. package/dist/resources/extensions/gsd/auto-start.js +1 -8
  13. package/dist/resources/extensions/gsd/auto-worktree.js +244 -216
  14. package/dist/resources/extensions/gsd/auto.js +86 -7
  15. package/dist/resources/extensions/gsd/bootstrap/agent-end-recovery.js +1 -1
  16. package/dist/resources/extensions/gsd/bootstrap/dynamic-tools.js +9 -77
  17. package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +17 -16
  18. package/dist/resources/extensions/gsd/bootstrap/write-gate.js +67 -55
  19. package/dist/resources/extensions/gsd/commands-codebase.js +2 -2
  20. package/dist/resources/extensions/gsd/commands-handlers.js +5 -5
  21. package/dist/resources/extensions/gsd/commands-logs.js +2 -2
  22. package/dist/resources/extensions/gsd/commands-scan.js +2 -2
  23. package/dist/resources/extensions/gsd/commands-ship.js +2 -2
  24. package/dist/resources/extensions/gsd/commands-workflow-templates.js +5 -5
  25. package/dist/resources/extensions/gsd/db-writer.js +106 -95
  26. package/dist/resources/extensions/gsd/delegation-policy.js +155 -0
  27. package/dist/resources/extensions/gsd/dispatch-guard.js +6 -10
  28. package/dist/resources/extensions/gsd/doctor-engine-checks.js +2 -2
  29. package/dist/resources/extensions/gsd/gsd-db.js +268 -8
  30. package/dist/resources/extensions/gsd/guided-flow-queue.js +1 -1
  31. package/dist/resources/extensions/gsd/guided-flow.js +141 -32
  32. package/dist/resources/extensions/gsd/markdown-renderer.js +14 -51
  33. package/dist/resources/extensions/gsd/metrics.js +287 -1
  34. package/dist/resources/extensions/gsd/parallel-merge.js +14 -13
  35. package/dist/resources/extensions/gsd/parallel-monitor-overlay.js +5 -2
  36. package/dist/resources/extensions/gsd/paths.js +114 -9
  37. package/dist/resources/extensions/gsd/prompts/complete-slice.md +4 -4
  38. package/dist/resources/extensions/gsd/prompts/execute-task.md +3 -3
  39. package/dist/resources/extensions/gsd/prompts/guided-discuss-milestone.md +8 -1
  40. package/dist/resources/extensions/gsd/prompts/guided-discuss-project.md +22 -7
  41. package/dist/resources/extensions/gsd/prompts/guided-discuss-requirements.md +6 -2
  42. package/dist/resources/extensions/gsd/prompts/guided-discuss-slice.md +8 -1
  43. package/dist/resources/extensions/gsd/prompts/plan-milestone.md +6 -0
  44. package/dist/resources/extensions/gsd/queue-order.js +6 -1
  45. package/dist/resources/extensions/gsd/rethink.js +2 -2
  46. package/dist/resources/extensions/gsd/state.js +91 -372
  47. package/dist/resources/extensions/gsd/templates/project.md +10 -0
  48. package/dist/resources/extensions/gsd/tools/complete-milestone.js +6 -5
  49. package/dist/resources/extensions/gsd/tools/complete-slice.js +7 -12
  50. package/dist/resources/extensions/gsd/tools/complete-task.js +19 -31
  51. package/dist/resources/extensions/gsd/tools/validate-milestone.js +7 -5
  52. package/dist/resources/extensions/gsd/workflow-manifest.js +2 -1
  53. package/dist/resources/extensions/gsd/workflow-mcp-auto-prep.js +3 -21
  54. package/dist/resources/extensions/gsd/workflow-mcp.js +2 -2
  55. package/dist/resources/extensions/gsd/workflow-reconcile.js +3 -3
  56. package/dist/resources/extensions/gsd/workspace.js +59 -0
  57. package/dist/resources/extensions/gsd/worktree-command.js +4 -3
  58. package/dist/resources/extensions/gsd/worktree-resolver.js +15 -2
  59. package/dist/resources/extensions/gsd/write-intercept.js +3 -3
  60. package/dist/tsconfig.extensions.tsbuildinfo +1 -1
  61. package/dist/web/standalone/.next/BUILD_ID +1 -1
  62. package/dist/web/standalone/.next/app-path-routes-manifest.json +12 -12
  63. package/dist/web/standalone/.next/build-manifest.json +2 -2
  64. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  65. package/dist/web/standalone/.next/required-server-files.json +1 -1
  66. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  67. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  68. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  69. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  70. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  71. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  72. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  73. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  74. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  75. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  76. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  77. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  78. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  79. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  80. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  81. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  82. package/dist/web/standalone/.next/server/app/api/boot/route.js.nft.json +1 -1
  83. package/dist/web/standalone/.next/server/app/api/bridge-terminal/input/route.js.nft.json +1 -1
  84. package/dist/web/standalone/.next/server/app/api/bridge-terminal/resize/route.js.nft.json +1 -1
  85. package/dist/web/standalone/.next/server/app/api/bridge-terminal/stream/route.js.nft.json +1 -1
  86. package/dist/web/standalone/.next/server/app/api/captures/route.js.nft.json +1 -1
  87. package/dist/web/standalone/.next/server/app/api/cleanup/route.js.nft.json +1 -1
  88. package/dist/web/standalone/.next/server/app/api/doctor/route.js.nft.json +1 -1
  89. package/dist/web/standalone/.next/server/app/api/export-data/route.js.nft.json +1 -1
  90. package/dist/web/standalone/.next/server/app/api/files/route.js.nft.json +1 -1
  91. package/dist/web/standalone/.next/server/app/api/forensics/route.js.nft.json +1 -1
  92. package/dist/web/standalone/.next/server/app/api/git/route.js.nft.json +1 -1
  93. package/dist/web/standalone/.next/server/app/api/history/route.js.nft.json +1 -1
  94. package/dist/web/standalone/.next/server/app/api/hooks/route.js.nft.json +1 -1
  95. package/dist/web/standalone/.next/server/app/api/inspect/route.js.nft.json +1 -1
  96. package/dist/web/standalone/.next/server/app/api/knowledge/route.js.nft.json +1 -1
  97. package/dist/web/standalone/.next/server/app/api/live-state/route.js.nft.json +1 -1
  98. package/dist/web/standalone/.next/server/app/api/notifications/route.js.nft.json +1 -1
  99. package/dist/web/standalone/.next/server/app/api/onboarding/route.js.nft.json +1 -1
  100. package/dist/web/standalone/.next/server/app/api/projects/route.js.nft.json +1 -1
  101. package/dist/web/standalone/.next/server/app/api/recovery/route.js.nft.json +1 -1
  102. package/dist/web/standalone/.next/server/app/api/session/browser/route.js.nft.json +1 -1
  103. package/dist/web/standalone/.next/server/app/api/session/command/route.js.nft.json +1 -1
  104. package/dist/web/standalone/.next/server/app/api/session/events/route.js.nft.json +1 -1
  105. package/dist/web/standalone/.next/server/app/api/session/manage/route.js.nft.json +1 -1
  106. package/dist/web/standalone/.next/server/app/api/settings-data/route.js.nft.json +1 -1
  107. package/dist/web/standalone/.next/server/app/api/skill-health/route.js.nft.json +1 -1
  108. package/dist/web/standalone/.next/server/app/api/steer/route.js.nft.json +1 -1
  109. package/dist/web/standalone/.next/server/app/api/switch-root/route.js.nft.json +1 -1
  110. package/dist/web/standalone/.next/server/app/api/terminal/sessions/route.js.nft.json +1 -1
  111. package/dist/web/standalone/.next/server/app/api/terminal/stream/route.js.nft.json +1 -1
  112. package/dist/web/standalone/.next/server/app/api/undo/route.js.nft.json +1 -1
  113. package/dist/web/standalone/.next/server/app/api/visualizer/route.js.nft.json +1 -1
  114. package/dist/web/standalone/.next/server/app/index.html +1 -1
  115. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  116. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  117. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  118. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  119. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  120. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  121. package/dist/web/standalone/.next/server/app-paths-manifest.json +12 -12
  122. package/dist/web/standalone/.next/server/chunks/6336.js +1 -0
  123. package/dist/web/standalone/.next/server/chunks/6897.js +1 -1
  124. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  125. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  126. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  127. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  128. package/dist/web/standalone/server.js +1 -1
  129. package/package.json +1 -1
  130. package/packages/mcp-server/README.md +2 -11
  131. package/packages/mcp-server/dist/remote-questions.d.ts +27 -0
  132. package/packages/mcp-server/dist/remote-questions.d.ts.map +1 -1
  133. package/packages/mcp-server/dist/remote-questions.js +28 -0
  134. package/packages/mcp-server/dist/remote-questions.js.map +1 -1
  135. package/packages/mcp-server/dist/server.d.ts +28 -0
  136. package/packages/mcp-server/dist/server.d.ts.map +1 -1
  137. package/packages/mcp-server/dist/server.js +94 -4
  138. package/packages/mcp-server/dist/server.js.map +1 -1
  139. package/packages/mcp-server/dist/workflow-tools.d.ts +6 -0
  140. package/packages/mcp-server/dist/workflow-tools.d.ts.map +1 -1
  141. package/packages/mcp-server/dist/workflow-tools.js +56 -2
  142. package/packages/mcp-server/dist/workflow-tools.js.map +1 -1
  143. package/packages/mcp-server/src/mcp-server.test.ts +226 -0
  144. package/packages/mcp-server/src/parse-workflow-args.test.ts +80 -0
  145. package/packages/mcp-server/src/remote-questions.test.ts +103 -0
  146. package/packages/mcp-server/src/remote-questions.ts +35 -0
  147. package/packages/mcp-server/src/server.ts +129 -6
  148. package/packages/mcp-server/src/workflow-tools.ts +62 -3
  149. package/packages/mcp-server/tsconfig.tsbuildinfo +1 -1
  150. package/src/resources/extensions/browser-tools/tools/intent.ts +13 -2
  151. package/src/resources/extensions/gsd/auto/phases.ts +8 -2
  152. package/src/resources/extensions/gsd/auto/session.ts +4 -0
  153. package/src/resources/extensions/gsd/auto-dispatch.ts +14 -62
  154. package/src/resources/extensions/gsd/auto-post-unit.ts +15 -27
  155. package/src/resources/extensions/gsd/auto-start.ts +1 -8
  156. package/src/resources/extensions/gsd/auto-worktree.ts +286 -251
  157. package/src/resources/extensions/gsd/auto.ts +102 -7
  158. package/src/resources/extensions/gsd/bootstrap/agent-end-recovery.ts +1 -1
  159. package/src/resources/extensions/gsd/bootstrap/dynamic-tools.ts +9 -84
  160. package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +17 -17
  161. package/src/resources/extensions/gsd/bootstrap/tests/write-gate-basepath.test.ts +103 -0
  162. package/src/resources/extensions/gsd/bootstrap/write-gate.ts +80 -55
  163. package/src/resources/extensions/gsd/commands-codebase.ts +2 -2
  164. package/src/resources/extensions/gsd/commands-handlers.ts +5 -5
  165. package/src/resources/extensions/gsd/commands-logs.ts +2 -2
  166. package/src/resources/extensions/gsd/commands-scan.ts +2 -2
  167. package/src/resources/extensions/gsd/commands-ship.ts +2 -2
  168. package/src/resources/extensions/gsd/commands-workflow-templates.ts +5 -5
  169. package/src/resources/extensions/gsd/db-writer.ts +123 -94
  170. package/src/resources/extensions/gsd/delegation-policy.ts +197 -0
  171. package/src/resources/extensions/gsd/dispatch-guard.ts +6 -11
  172. package/src/resources/extensions/gsd/doctor-engine-checks.ts +2 -2
  173. package/src/resources/extensions/gsd/gsd-db.ts +269 -8
  174. package/src/resources/extensions/gsd/guided-flow-queue.ts +1 -1
  175. package/src/resources/extensions/gsd/guided-flow.ts +181 -32
  176. package/src/resources/extensions/gsd/markdown-renderer.ts +13 -64
  177. package/src/resources/extensions/gsd/metrics.ts +321 -1
  178. package/src/resources/extensions/gsd/parallel-merge.ts +14 -13
  179. package/src/resources/extensions/gsd/parallel-monitor-overlay.ts +5 -2
  180. package/src/resources/extensions/gsd/paths.ts +122 -9
  181. package/src/resources/extensions/gsd/prompts/complete-slice.md +4 -4
  182. package/src/resources/extensions/gsd/prompts/execute-task.md +3 -3
  183. package/src/resources/extensions/gsd/prompts/guided-discuss-milestone.md +8 -1
  184. package/src/resources/extensions/gsd/prompts/guided-discuss-project.md +22 -7
  185. package/src/resources/extensions/gsd/prompts/guided-discuss-requirements.md +6 -2
  186. package/src/resources/extensions/gsd/prompts/guided-discuss-slice.md +8 -1
  187. package/src/resources/extensions/gsd/prompts/plan-milestone.md +6 -0
  188. package/src/resources/extensions/gsd/queue-order.ts +6 -1
  189. package/src/resources/extensions/gsd/rethink.ts +2 -2
  190. package/src/resources/extensions/gsd/state.ts +91 -389
  191. package/src/resources/extensions/gsd/templates/project.md +10 -0
  192. package/src/resources/extensions/gsd/tests/artifact-corruption-2630.test.ts +1 -0
  193. package/src/resources/extensions/gsd/tests/auto-discuss-milestone-deadlock-4973.test.ts +14 -14
  194. package/src/resources/extensions/gsd/tests/auto-paused-session-validation.test.ts +6 -0
  195. package/src/resources/extensions/gsd/tests/auto-remediate-slice-status.test.ts +21 -34
  196. package/src/resources/extensions/gsd/tests/auto-session-scope.test.ts +331 -0
  197. package/src/resources/extensions/gsd/tests/auto-worktree-registry.test.ts +176 -0
  198. package/src/resources/extensions/gsd/tests/complete-task-rollback-evidence.test.ts +6 -7
  199. package/src/resources/extensions/gsd/tests/complete-task.test.ts +8 -6
  200. package/src/resources/extensions/gsd/tests/completed-at-reconcile.test.ts +12 -27
  201. package/src/resources/extensions/gsd/tests/completed-units-metrics-sync.test.ts +18 -5
  202. package/src/resources/extensions/gsd/tests/db-path-worktree-symlink.test.ts +4 -4
  203. package/src/resources/extensions/gsd/tests/db-writer-path-containment.test.ts +152 -0
  204. package/src/resources/extensions/gsd/tests/db-writer-root-artifact.test.ts +221 -0
  205. package/src/resources/extensions/gsd/tests/db-writer-scope.test.ts +230 -0
  206. package/src/resources/extensions/gsd/tests/db-writer.test.ts +14 -16
  207. package/src/resources/extensions/gsd/tests/delegation-policy.test.ts +151 -0
  208. package/src/resources/extensions/gsd/tests/derive-state-crossval.test.ts +6 -5
  209. package/src/resources/extensions/gsd/tests/derive-state-db-disk-reconcile.test.ts +10 -38
  210. package/src/resources/extensions/gsd/tests/derive-state-db.test.ts +136 -56
  211. package/src/resources/extensions/gsd/tests/derive-state-draft.test.ts +3 -0
  212. package/src/resources/extensions/gsd/tests/derive-state-helpers.test.ts +119 -61
  213. package/src/resources/extensions/gsd/tests/derive-state.test.ts +4 -0
  214. package/src/resources/extensions/gsd/tests/dispatch-backgroundable-annotation.test.ts +55 -0
  215. package/src/resources/extensions/gsd/tests/dispatch-complete-milestone-guard.test.ts +6 -20
  216. package/src/resources/extensions/gsd/tests/dispatch-guard.test.ts +4 -5
  217. package/src/resources/extensions/gsd/tests/dispatcher-stuck-planning.test.ts +14 -15
  218. package/src/resources/extensions/gsd/tests/draft-promotion.test.ts +3 -23
  219. package/src/resources/extensions/gsd/tests/ensure-db-open.test.ts +11 -16
  220. package/src/resources/extensions/gsd/tests/escalation.test.ts +2 -1
  221. package/src/resources/extensions/gsd/tests/gate-1b-orphan-discrimination.test.ts +193 -0
  222. package/src/resources/extensions/gsd/tests/gate-1b-recovery-bound-corrections.test.ts +246 -0
  223. package/src/resources/extensions/gsd/tests/gate-1b-recovery-bound.test.ts +218 -0
  224. package/src/resources/extensions/gsd/tests/gsd-db-failed-open-restore.test.ts +117 -0
  225. package/src/resources/extensions/gsd/tests/gsd-db-workspace-scope.test.ts +226 -0
  226. package/src/resources/extensions/gsd/tests/gsd-db.test.ts +2 -1
  227. package/src/resources/extensions/gsd/tests/gsd-root-canonical.test.ts +66 -0
  228. package/src/resources/extensions/gsd/tests/gsd-root-home-guard.test.ts +68 -5
  229. package/src/resources/extensions/gsd/tests/gsdroot-worktree-detection.test.ts +15 -36
  230. package/src/resources/extensions/gsd/tests/guided-flow-prompt-consolidation.test.ts +4 -4
  231. package/src/resources/extensions/gsd/tests/handler-worktree-write-isolation.test.ts +57 -0
  232. package/src/resources/extensions/gsd/tests/integration/parallel-merge.test.ts +15 -15
  233. package/src/resources/extensions/gsd/tests/integration/state-machine-edge-cases.test.ts +15 -5
  234. package/src/resources/extensions/gsd/tests/integration/workspace-collapse-integration.test.ts +371 -0
  235. package/src/resources/extensions/gsd/tests/markdown-renderer.test.ts +14 -8
  236. package/src/resources/extensions/gsd/tests/md-importer.test.ts +2 -1
  237. package/src/resources/extensions/gsd/tests/memory-store.test.ts +3 -2
  238. package/src/resources/extensions/gsd/tests/metrics-atomic-merge.test.ts +222 -0
  239. package/src/resources/extensions/gsd/tests/metrics-lock-hardening.test.ts +400 -0
  240. package/src/resources/extensions/gsd/tests/metrics-lock-not-acquired.test.ts +141 -0
  241. package/src/resources/extensions/gsd/tests/metrics-lock-retry-sleep.test.ts +287 -0
  242. package/src/resources/extensions/gsd/tests/metrics-prune-cache-invalidation.test.ts +149 -0
  243. package/src/resources/extensions/gsd/tests/metrics-scope.test.ts +378 -0
  244. package/src/resources/extensions/gsd/tests/originalbase-path-comparison.test.ts +329 -0
  245. package/src/resources/extensions/gsd/tests/park-milestone.test.ts +2 -0
  246. package/src/resources/extensions/gsd/tests/path-cache-decoupled.test.ts +209 -0
  247. package/src/resources/extensions/gsd/tests/path-normalization-unified.test.ts +175 -0
  248. package/src/resources/extensions/gsd/tests/paths-cache.test.ts +170 -0
  249. package/src/resources/extensions/gsd/tests/pending-autostart-scope.test.ts +120 -0
  250. package/src/resources/extensions/gsd/tests/progressive-planning.test.ts +25 -16
  251. package/src/resources/extensions/gsd/tests/projection-regression.test.ts +1 -0
  252. package/src/resources/extensions/gsd/tests/prompt-contracts.test.ts +150 -7
  253. package/src/resources/extensions/gsd/tests/ready-phrase-no-files-4573.test.ts +184 -0
  254. package/src/resources/extensions/gsd/tests/register-hooks-compaction-checkpoint.test.ts +6 -1
  255. package/src/resources/extensions/gsd/tests/register-hooks-depth-verification.test.ts +28 -16
  256. package/src/resources/extensions/gsd/tests/replan-slice.test.ts +3 -0
  257. package/src/resources/extensions/gsd/tests/resolve-ts.mjs +4 -0
  258. package/src/resources/extensions/gsd/tests/resume-missing-worktree-warning.test.ts +209 -0
  259. package/src/resources/extensions/gsd/tests/rogue-file-detection.test.ts +3 -4
  260. package/src/resources/extensions/gsd/tests/slice-disk-reconcile.test.ts +10 -56
  261. package/src/resources/extensions/gsd/tests/stale-slice-rows.test.ts +15 -16
  262. package/src/resources/extensions/gsd/tests/state-corruption-2945.test.ts +1 -0
  263. package/src/resources/extensions/gsd/tests/state-machine-full-walkthrough.test.ts +23 -27
  264. package/src/resources/extensions/gsd/tests/steer-worktree-path.test.ts +13 -14
  265. package/src/resources/extensions/gsd/tests/stop-auto-remote.test.ts +4 -3
  266. package/src/resources/extensions/gsd/tests/sync-layer-scope.test.ts +453 -0
  267. package/src/resources/extensions/gsd/tests/sync-worktree-skip-current.test.ts +10 -33
  268. package/src/resources/extensions/gsd/tests/teardown-chdir-failure-clears-registry.test.ts +162 -0
  269. package/src/resources/extensions/gsd/tests/teardown-cleanup-parity.test.ts +102 -0
  270. package/src/resources/extensions/gsd/tests/teardown-failure-clears-registry.test.ts +186 -0
  271. package/src/resources/extensions/gsd/tests/tool-invocation-error-loop-break.test.ts +1 -1
  272. package/src/resources/extensions/gsd/tests/validate-milestone-write-order.test.ts +7 -8
  273. package/src/resources/extensions/gsd/tests/validate-milestone.test.ts +9 -15
  274. package/src/resources/extensions/gsd/tests/validator-scope-parity.test.ts +239 -0
  275. package/src/resources/extensions/gsd/tests/workflow-logger-wiring.test.ts +12 -7
  276. package/src/resources/extensions/gsd/tests/workflow-mcp-auto-prep.test.ts +4 -4
  277. package/src/resources/extensions/gsd/tests/workflow-mcp.test.ts +26 -3
  278. package/src/resources/extensions/gsd/tests/workflow-tool-executors.test.ts +9 -15
  279. package/src/resources/extensions/gsd/tests/workspace.test.ts +190 -0
  280. package/src/resources/extensions/gsd/tests/worktree-db-same-file.test.ts +13 -0
  281. package/src/resources/extensions/gsd/tests/worktree-sync-milestones.test.ts +65 -71
  282. package/src/resources/extensions/gsd/tests/worktree-sync-tasks.test.ts +26 -151
  283. package/src/resources/extensions/gsd/tests/write-gate-predicates.test.ts +35 -35
  284. package/src/resources/extensions/gsd/tests/write-gate.test.ts +67 -52
  285. package/src/resources/extensions/gsd/tests/write-intercept.test.ts +1 -1
  286. package/src/resources/extensions/gsd/tools/complete-milestone.ts +7 -5
  287. package/src/resources/extensions/gsd/tools/complete-slice.ts +7 -14
  288. package/src/resources/extensions/gsd/tools/complete-task.ts +19 -34
  289. package/src/resources/extensions/gsd/tools/validate-milestone.ts +7 -5
  290. package/src/resources/extensions/gsd/workflow-manifest.ts +4 -1
  291. package/src/resources/extensions/gsd/workflow-mcp-auto-prep.ts +2 -18
  292. package/src/resources/extensions/gsd/workflow-mcp.ts +2 -2
  293. package/src/resources/extensions/gsd/workflow-reconcile.ts +3 -3
  294. package/src/resources/extensions/gsd/workspace.ts +95 -0
  295. package/src/resources/extensions/gsd/worktree-command.ts +4 -3
  296. package/src/resources/extensions/gsd/worktree-resolver.ts +16 -2
  297. package/src/resources/extensions/gsd/write-intercept.ts +3 -3
  298. package/dist/web/standalone/.next/server/chunks/8527.js +0 -1
  299. /package/dist/web/standalone/.next/static/{rk1EN3FQTE6Z1yalkW_GE → AT5qi39nKXkdmQIOIoh0f}/_buildManifest.js +0 -0
  300. /package/dist/web/standalone/.next/static/{rk1EN3FQTE6Z1yalkW_GE → AT5qi39nKXkdmQIOIoh0f}/_ssgManifest.js +0 -0
@@ -24,38 +24,38 @@ import {
24
24
  // ─── shouldBlockQueueExecution ────────────────────────────────────────────
25
25
 
26
26
  test('shouldBlockQueueExecution: queue inactive → allow write to user source', (t) => {
27
- t.after(() => clearDiscussionFlowState());
28
- setQueuePhaseActive(false);
27
+ t.after(() => clearDiscussionFlowState(process.cwd()));
28
+ setQueuePhaseActive(false, process.cwd());
29
29
  const r = shouldBlockQueueExecution('write', 'src/main.ts', false);
30
30
  assert.strictEqual(r.block, false);
31
31
  });
32
32
 
33
33
  test('shouldBlockQueueExecution: queue active → block write to user source', (t) => {
34
- t.after(() => clearDiscussionFlowState());
35
- setQueuePhaseActive(true);
34
+ t.after(() => clearDiscussionFlowState(process.cwd()));
35
+ setQueuePhaseActive(true, process.cwd());
36
36
  const r = shouldBlockQueueExecution('write', 'src/main.ts', true);
37
37
  assert.strictEqual(r.block, true);
38
38
  assert.ok(r.reason);
39
39
  });
40
40
 
41
41
  test('shouldBlockQueueExecution: queue active → allow write to .gsd/ path', (t) => {
42
- t.after(() => clearDiscussionFlowState());
43
- setQueuePhaseActive(true);
42
+ t.after(() => clearDiscussionFlowState(process.cwd()));
43
+ setQueuePhaseActive(true, process.cwd());
44
44
  const r = shouldBlockQueueExecution('write', '.gsd/milestones/M001/M001-CONTEXT.md', true);
45
45
  assert.strictEqual(r.block, false);
46
46
  });
47
47
 
48
48
  test('shouldBlockQueueExecution: queue active → block mutating bash', (t) => {
49
- t.after(() => clearDiscussionFlowState());
50
- setQueuePhaseActive(true);
49
+ t.after(() => clearDiscussionFlowState(process.cwd()));
50
+ setQueuePhaseActive(true, process.cwd());
51
51
  const r = shouldBlockQueueExecution('bash', 'npm run build', true);
52
52
  assert.strictEqual(r.block, true);
53
53
  assert.ok(r.reason);
54
54
  });
55
55
 
56
56
  test('shouldBlockQueueExecution: queue active → allow read-only bash', (t) => {
57
- t.after(() => clearDiscussionFlowState());
58
- setQueuePhaseActive(true);
57
+ t.after(() => clearDiscussionFlowState(process.cwd()));
58
+ setQueuePhaseActive(true, process.cwd());
59
59
  const r = shouldBlockQueueExecution('bash', 'git log --oneline -5', true);
60
60
  assert.strictEqual(r.block, false);
61
61
  });
@@ -63,30 +63,30 @@ test('shouldBlockQueueExecution: queue active → allow read-only bash', (t) =>
63
63
  // ─── shouldBlockPendingGate ───────────────────────────────────────────────
64
64
 
65
65
  test('shouldBlockPendingGate: no pending gate → allow any tool', (t) => {
66
- t.after(() => clearDiscussionFlowState());
67
- clearPendingGate();
66
+ t.after(() => clearDiscussionFlowState(process.cwd()));
67
+ clearPendingGate(process.cwd());
68
68
  const r = shouldBlockPendingGate('write', 'M001');
69
69
  assert.strictEqual(r.block, false);
70
70
  });
71
71
 
72
72
  test('shouldBlockPendingGate: pending gate → block write', (t) => {
73
- t.after(() => clearDiscussionFlowState());
74
- setPendingGate('depth_verification_M001');
73
+ t.after(() => clearDiscussionFlowState(process.cwd()));
74
+ setPendingGate('depth_verification_M001', process.cwd());
75
75
  const r = shouldBlockPendingGate('write', 'M001');
76
76
  assert.strictEqual(r.block, true);
77
77
  assert.ok(r.reason?.includes('depth_verification_M001'));
78
78
  });
79
79
 
80
80
  test('shouldBlockPendingGate: pending gate → allow ask_user_questions', (t) => {
81
- t.after(() => clearDiscussionFlowState());
82
- setPendingGate('depth_verification_M001');
81
+ t.after(() => clearDiscussionFlowState(process.cwd()));
82
+ setPendingGate('depth_verification_M001', process.cwd());
83
83
  const r = shouldBlockPendingGate('ask_user_questions', 'M001');
84
84
  assert.strictEqual(r.block, false);
85
85
  });
86
86
 
87
87
  test('shouldBlockPendingGate: pending gate → block read so approval question stays visible', (t) => {
88
- t.after(() => clearDiscussionFlowState());
89
- setPendingGate('depth_verification_M001');
88
+ t.after(() => clearDiscussionFlowState(process.cwd()));
89
+ setPendingGate('depth_verification_M001', process.cwd());
90
90
  const r = shouldBlockPendingGate('read', 'M001');
91
91
  assert.strictEqual(r.block, true);
92
92
  assert.ok(r.reason?.includes('already asked for user confirmation'));
@@ -95,31 +95,31 @@ test('shouldBlockPendingGate: pending gate → block read so approval question s
95
95
  // ─── shouldBlockPendingGateBash ───────────────────────────────────────────
96
96
 
97
97
  test('shouldBlockPendingGateBash: no pending gate → allow mutating bash', (t) => {
98
- t.after(() => clearDiscussionFlowState());
99
- clearPendingGate();
98
+ t.after(() => clearDiscussionFlowState(process.cwd()));
99
+ clearPendingGate(process.cwd());
100
100
  const r = shouldBlockPendingGateBash('npm run build', 'M001');
101
101
  assert.strictEqual(r.block, false);
102
102
  });
103
103
 
104
104
  test('shouldBlockPendingGateBash: pending gate → block mutating bash', (t) => {
105
- t.after(() => clearDiscussionFlowState());
106
- setPendingGate('depth_verification_M001');
105
+ t.after(() => clearDiscussionFlowState(process.cwd()));
106
+ setPendingGate('depth_verification_M001', process.cwd());
107
107
  const r = shouldBlockPendingGateBash('npm run build', 'M001');
108
108
  assert.strictEqual(r.block, true);
109
109
  assert.ok(r.reason?.includes('depth_verification_M001'));
110
110
  });
111
111
 
112
112
  test('shouldBlockPendingGateBash: pending gate → block read-only bash (cat)', (t) => {
113
- t.after(() => clearDiscussionFlowState());
114
- setPendingGate('depth_verification_M001');
113
+ t.after(() => clearDiscussionFlowState(process.cwd()));
114
+ setPendingGate('depth_verification_M001', process.cwd());
115
115
  const r = shouldBlockPendingGateBash('cat README.md', 'M001');
116
116
  assert.strictEqual(r.block, true);
117
117
  assert.ok(r.reason?.includes('already asked for user confirmation'));
118
118
  });
119
119
 
120
120
  test('shouldBlockPendingGateBash: pending gate → block read-only bash (git log)', (t) => {
121
- t.after(() => clearDiscussionFlowState());
122
- setPendingGate('depth_verification_M001');
121
+ t.after(() => clearDiscussionFlowState(process.cwd()));
122
+ setPendingGate('depth_verification_M001', process.cwd());
123
123
  const r = shouldBlockPendingGateBash('git log --oneline -10', 'M001');
124
124
  assert.strictEqual(r.block, true);
125
125
  });
@@ -127,26 +127,26 @@ test('shouldBlockPendingGateBash: pending gate → block read-only bash (git log
127
127
  // ─── shouldBlockContextWrite ──────────────────────────────────────────────
128
128
 
129
129
  test('shouldBlockContextWrite: non-write tool → allow', (t) => {
130
- t.after(() => clearDiscussionFlowState());
130
+ t.after(() => clearDiscussionFlowState(process.cwd()));
131
131
  const r = shouldBlockContextWrite('read', '.gsd/milestones/M001/M001-CONTEXT.md', 'M001');
132
132
  assert.strictEqual(r.block, false);
133
133
  });
134
134
 
135
135
  test('shouldBlockContextWrite: write to non-CONTEXT file → allow', (t) => {
136
- t.after(() => clearDiscussionFlowState());
136
+ t.after(() => clearDiscussionFlowState(process.cwd()));
137
137
  const r = shouldBlockContextWrite('write', 'src/index.ts', 'M001');
138
138
  assert.strictEqual(r.block, false);
139
139
  });
140
140
 
141
141
  test('shouldBlockContextWrite: write to CONTEXT.md without verification → block', (t) => {
142
- t.after(() => clearDiscussionFlowState());
142
+ t.after(() => clearDiscussionFlowState(process.cwd()));
143
143
  const r = shouldBlockContextWrite('write', '.gsd/milestones/M007/M007-CONTEXT.md', 'M007');
144
144
  assert.strictEqual(r.block, true);
145
145
  assert.ok(r.reason);
146
146
  });
147
147
 
148
148
  test('shouldBlockContextWrite: write to CONTEXT.md after verification → allow', (t) => {
149
- t.after(() => clearDiscussionFlowState());
149
+ t.after(() => clearDiscussionFlowState(process.cwd()));
150
150
  markDepthVerified('M008');
151
151
  const r = shouldBlockContextWrite('write', '.gsd/milestones/M008/M008-CONTEXT.md', 'M008');
152
152
  assert.strictEqual(r.block, false);
@@ -155,33 +155,33 @@ test('shouldBlockContextWrite: write to CONTEXT.md after verification → allow'
155
155
  // ─── shouldBlockContextArtifactSave ───────────────────────────────────────
156
156
 
157
157
  test('shouldBlockContextArtifactSave: non-CONTEXT artifact type → allow', (t) => {
158
- t.after(() => clearDiscussionFlowState());
158
+ t.after(() => clearDiscussionFlowState(process.cwd()));
159
159
  const r = shouldBlockContextArtifactSave('CONTEXT-DRAFT', 'M001');
160
160
  assert.strictEqual(r.block, false);
161
161
  });
162
162
 
163
163
  test('shouldBlockContextArtifactSave: slice-level CONTEXT → allow', (t) => {
164
- t.after(() => clearDiscussionFlowState());
164
+ t.after(() => clearDiscussionFlowState(process.cwd()));
165
165
  const r = shouldBlockContextArtifactSave('CONTEXT', 'M001', 'S01');
166
166
  assert.strictEqual(r.block, false);
167
167
  });
168
168
 
169
169
  test('shouldBlockContextArtifactSave: milestone CONTEXT without verification → block', (t) => {
170
- t.after(() => clearDiscussionFlowState());
170
+ t.after(() => clearDiscussionFlowState(process.cwd()));
171
171
  const r = shouldBlockContextArtifactSave('CONTEXT', 'M009');
172
172
  assert.strictEqual(r.block, true);
173
173
  assert.ok(r.reason?.includes('M009'));
174
174
  });
175
175
 
176
176
  test('shouldBlockContextArtifactSave: milestone CONTEXT after verification → allow', (t) => {
177
- t.after(() => clearDiscussionFlowState());
177
+ t.after(() => clearDiscussionFlowState(process.cwd()));
178
178
  markDepthVerified('M010');
179
179
  const r = shouldBlockContextArtifactSave('CONTEXT', 'M010');
180
180
  assert.strictEqual(r.block, false);
181
181
  });
182
182
 
183
183
  test('shouldBlockContextArtifactSave: CONTEXT with no milestoneId → block', (t) => {
184
- t.after(() => clearDiscussionFlowState());
184
+ t.after(() => clearDiscussionFlowState(process.cwd()));
185
185
  const r = shouldBlockContextArtifactSave('CONTEXT', null);
186
186
  assert.strictEqual(r.block, true);
187
187
  assert.ok(r.reason);
@@ -9,14 +9,16 @@
9
9
  * (e) else → block with actionable reason
10
10
  */
11
11
 
12
- import test from 'node:test';
12
+ import test, { afterEach } from 'node:test';
13
13
  import assert from 'node:assert/strict';
14
14
  import { mkdirSync, writeFileSync, unlinkSync, existsSync, rmSync } from 'node:fs';
15
15
  import { join } from 'node:path';
16
16
  import { tmpdir } from 'node:os';
17
17
  import { randomUUID } from 'node:crypto';
18
18
  import {
19
+ isDepthVerified,
19
20
  isDepthConfirmationAnswer,
21
+ isQueuePhaseActive,
20
22
  shouldBlockContextWrite,
21
23
  setQueuePhaseActive,
22
24
  } from '../index.ts';
@@ -32,6 +34,10 @@ import {
32
34
  loadWriteGateSnapshot,
33
35
  } from '../bootstrap/write-gate.ts';
34
36
 
37
+ afterEach(() => {
38
+ clearDiscussionFlowState(process.cwd());
39
+ });
40
+
35
41
  // ─── Scenario 1: Blocks CONTEXT.md write during discussion without depth verification (absolute path) ──
36
42
 
37
43
  test('write-gate: blocks CONTEXT.md write during discussion without depth verification (absolute path)', () => {
@@ -61,7 +67,7 @@ test('write-gate: blocks CONTEXT.md write during discussion without depth verifi
61
67
  // ─── Scenario 3: Allows CONTEXT.md write after depth verification ──
62
68
 
63
69
  test('write-gate: allows CONTEXT.md write after depth verification', () => {
64
- clearDiscussionFlowState();
70
+ clearDiscussionFlowState(process.cwd());
65
71
  markDepthVerified('M001');
66
72
  const result = shouldBlockContextWrite(
67
73
  'write',
@@ -70,7 +76,6 @@ test('write-gate: allows CONTEXT.md write after depth verification', () => {
70
76
  );
71
77
  assert.strictEqual(result.block, false, 'should not block after depth verification');
72
78
  assert.strictEqual(result.reason, undefined, 'should have no reason');
73
- clearDiscussionFlowState();
74
79
  });
75
80
 
76
81
  // ─── Scenario 4: Ambiguous session context no longer bypasses the gate ──
@@ -154,7 +159,7 @@ test('write-gate: blocks CONTEXT.md write in queue mode without depth verificati
154
159
  // ─── Scenario 9: Queue mode allows CONTEXT.md write after depth verification ──
155
160
 
156
161
  test('write-gate: allows CONTEXT.md write in queue mode after depth verification', () => {
157
- clearDiscussionFlowState();
162
+ clearDiscussionFlowState(process.cwd());
158
163
  markDepthVerified('M001');
159
164
  const result = shouldBlockContextWrite(
160
165
  'write',
@@ -163,13 +168,12 @@ test('write-gate: allows CONTEXT.md write in queue mode after depth verification
163
168
  true, // queue phase active
164
169
  );
165
170
  assert.strictEqual(result.block, false, 'should not block in queue mode after depth verification');
166
- clearDiscussionFlowState();
167
171
  });
168
172
 
169
173
  // ─── Scenario 10: depth verification is scoped per milestone, not global ──
170
174
 
171
175
  test('write-gate: markDepthVerified unlocks only the matching milestone', () => {
172
- clearDiscussionFlowState();
176
+ clearDiscussionFlowState(process.cwd());
173
177
  markDepthVerified('M001');
174
178
 
175
179
  const allowed = shouldBlockContextWrite(
@@ -187,14 +191,12 @@ test('write-gate: markDepthVerified unlocks only the matching milestone', () =>
187
191
  assert.strictEqual(blockedOther.block, true, 'other milestones should remain blocked');
188
192
  assert.strictEqual(isMilestoneDepthVerified('M001'), true);
189
193
  assert.strictEqual(isMilestoneDepthVerified('M002'), false);
190
-
191
- clearDiscussionFlowState();
192
194
  });
193
195
 
194
196
  // ─── Scenario 11: gsd_summary_save CONTEXT contract is milestone-scoped ──
195
197
 
196
198
  test('write-gate: gsd_summary_save only blocks final milestone CONTEXT writes', () => {
197
- clearDiscussionFlowState();
199
+ clearDiscussionFlowState(process.cwd());
198
200
 
199
201
  assert.strictEqual(
200
202
  shouldBlockContextArtifactSave('CONTEXT-DRAFT', 'M001').block,
@@ -218,8 +220,6 @@ test('write-gate: gsd_summary_save only blocks final milestone CONTEXT writes',
218
220
  false,
219
221
  'final milestone CONTEXT should pass after verification',
220
222
  );
221
-
222
- clearDiscussionFlowState();
223
223
  });
224
224
 
225
225
  test('write-gate: root PROJECT/REQUIREMENTS final saves block behind pending approval gate', () => {
@@ -299,12 +299,12 @@ test('write-gate: deep root PROJECT/REQUIREMENTS final saves require verified ap
299
299
  });
300
300
 
301
301
  test('write-gate: reopening a gate revokes its previous verified approval', () => {
302
- clearDiscussionFlowState();
302
+ clearDiscussionFlowState(process.cwd());
303
303
 
304
304
  markApprovalGateVerified('depth_verification_project_confirm');
305
305
  assert.strictEqual(
306
306
  shouldBlockRootArtifactSaveInSnapshot(
307
- loadWriteGateSnapshot(),
307
+ loadWriteGateSnapshot(process.cwd()),
308
308
  'PROJECT',
309
309
  { requireVerifiedApproval: true },
310
310
  ).block,
@@ -312,20 +312,18 @@ test('write-gate: reopening a gate revokes its previous verified approval', () =
312
312
  'precondition: verified approval unlocks the final project artifact',
313
313
  );
314
314
 
315
- setPendingGate('depth_verification_project_confirm');
316
- clearPendingGate();
315
+ setPendingGate('depth_verification_project_confirm', process.cwd());
316
+ clearPendingGate(process.cwd());
317
317
 
318
318
  assert.strictEqual(
319
319
  shouldBlockRootArtifactSaveInSnapshot(
320
- loadWriteGateSnapshot(),
320
+ loadWriteGateSnapshot(process.cwd()),
321
321
  'PROJECT',
322
322
  { requireVerifiedApproval: true },
323
323
  ).block,
324
324
  true,
325
325
  'a re-asked gate must require a fresh approval',
326
326
  );
327
-
328
- clearDiscussionFlowState();
329
327
  });
330
328
 
331
329
  // ═══════════════════════════════════════════════════════════════════════
@@ -357,26 +355,26 @@ test('write-gate: isGateQuestionId recognizes all gate patterns', () => {
357
355
  // ─── Scenario 20: setPendingGate / getPendingGate / clearPendingGate lifecycle ──
358
356
 
359
357
  test('write-gate: pending gate lifecycle (set, get, clear)', () => {
360
- clearDiscussionFlowState();
358
+ clearDiscussionFlowState(process.cwd());
361
359
  assert.strictEqual(getPendingGate(), null, 'starts null');
362
360
 
363
- setPendingGate('depth_verification');
361
+ setPendingGate('depth_verification', process.cwd());
364
362
  assert.strictEqual(getPendingGate(), 'depth_verification', 'set correctly');
365
363
 
366
- clearPendingGate();
364
+ clearPendingGate(process.cwd());
367
365
  assert.strictEqual(getPendingGate(), null, 'cleared correctly');
368
366
 
369
367
  // clearDiscussionFlowState also clears pending gate
370
- setPendingGate('depth_verification_M002');
371
- clearDiscussionFlowState();
368
+ setPendingGate('depth_verification_M002', process.cwd());
369
+ clearDiscussionFlowState(process.cwd());
372
370
  assert.strictEqual(getPendingGate(), null, 'clearDiscussionFlowState clears pending gate');
373
371
  });
374
372
 
375
373
  // ─── Scenario 21: shouldBlockPendingGate blocks non-safe tools when gate is pending ──
376
374
 
377
375
  test('write-gate: shouldBlockPendingGate blocks write/edit during pending gate', () => {
378
- clearDiscussionFlowState();
379
- setPendingGate('depth_verification');
376
+ clearDiscussionFlowState(process.cwd());
377
+ setPendingGate('depth_verification', process.cwd());
380
378
 
381
379
  // write should be blocked during discussion
382
380
  const writeResult = shouldBlockPendingGate('write', 'M001', false);
@@ -390,15 +388,13 @@ test('write-gate: shouldBlockPendingGate blocks write/edit during pending gate',
390
388
  // gsd tools should be blocked
391
389
  const gsdResult = shouldBlockPendingGate('gsd_plan_milestone', 'M001', false);
392
390
  assert.strictEqual(gsdResult.block, true, 'gsd tools should be blocked');
393
-
394
- clearDiscussionFlowState();
395
391
  });
396
392
 
397
393
  // ─── Scenario 22: shouldBlockPendingGate allows only re-asking when gate is pending ──
398
394
 
399
395
  test('write-gate: shouldBlockPendingGate blocks read-only tools and allows ask_user_questions during pending gate', () => {
400
- clearDiscussionFlowState();
401
- setPendingGate('depth_verification');
396
+ clearDiscussionFlowState(process.cwd());
397
+ setPendingGate('depth_verification', process.cwd());
402
398
 
403
399
  // ask_user_questions is always safe (model needs to re-ask)
404
400
  assert.strictEqual(shouldBlockPendingGate('ask_user_questions', 'M001').block, false);
@@ -407,67 +403,57 @@ test('write-gate: shouldBlockPendingGate blocks read-only tools and allows ask_u
407
403
  assert.strictEqual(shouldBlockPendingGate('grep', 'M001').block, true);
408
404
  assert.strictEqual(shouldBlockPendingGate('glob', 'M001').block, true);
409
405
  assert.strictEqual(shouldBlockPendingGate('ls', 'M001').block, true);
410
-
411
- clearDiscussionFlowState();
412
406
  });
413
407
 
414
408
  // ─── Scenario 23: shouldBlockPendingGate still blocks when the session is ambiguous ──
415
409
 
416
410
  test('write-gate: shouldBlockPendingGate blocks outside discussion when a gate is pending', () => {
417
- clearDiscussionFlowState();
418
- setPendingGate('depth_verification');
411
+ clearDiscussionFlowState(process.cwd());
412
+ setPendingGate('depth_verification', process.cwd());
419
413
 
420
414
  // No milestoneId and no queue phase — still block because the gate is pending
421
415
  const result = shouldBlockPendingGate('write', null, false);
422
416
  assert.strictEqual(result.block, true, 'should block even when milestoneId is null');
423
-
424
- clearDiscussionFlowState();
425
417
  });
426
418
 
427
419
  // ─── Scenario 24: shouldBlockPendingGate blocks in queue mode ──
428
420
 
429
421
  test('write-gate: shouldBlockPendingGate blocks in queue mode when gate is pending', () => {
430
- clearDiscussionFlowState();
431
- setQueuePhaseActive(true);
432
- setPendingGate('depth_verification');
422
+ clearDiscussionFlowState(process.cwd());
423
+ setQueuePhaseActive(true, process.cwd());
424
+ setPendingGate('depth_verification', process.cwd());
433
425
 
434
426
  const result = shouldBlockPendingGate('write', null, true);
435
427
  assert.strictEqual(result.block, true, 'should block in queue mode');
436
-
437
- clearDiscussionFlowState();
438
428
  });
439
429
 
440
430
  // ─── Scenario 25: shouldBlockPendingGateBash blocks read-only commands ──
441
431
 
442
432
  test('write-gate: shouldBlockPendingGateBash blocks read-only commands during pending gate', () => {
443
- clearDiscussionFlowState();
444
- setPendingGate('depth_verification');
433
+ clearDiscussionFlowState(process.cwd());
434
+ setPendingGate('depth_verification', process.cwd());
445
435
 
446
436
  assert.strictEqual(shouldBlockPendingGateBash('cat file.txt', 'M001').block, true);
447
437
  assert.strictEqual(shouldBlockPendingGateBash('git log --oneline', 'M001').block, true);
448
438
  assert.strictEqual(shouldBlockPendingGateBash('grep -r pattern .', 'M001').block, true);
449
439
  assert.strictEqual(shouldBlockPendingGateBash('ls -la', 'M001').block, true);
450
-
451
- clearDiscussionFlowState();
452
440
  });
453
441
 
454
442
  // ─── Scenario 26: shouldBlockPendingGateBash blocks mutating commands ──
455
443
 
456
444
  test('write-gate: shouldBlockPendingGateBash blocks mutating commands during pending gate', () => {
457
- clearDiscussionFlowState();
458
- setPendingGate('depth_verification');
445
+ clearDiscussionFlowState(process.cwd());
446
+ setPendingGate('depth_verification', process.cwd());
459
447
 
460
448
  const result = shouldBlockPendingGateBash('npm run build', 'M001');
461
449
  assert.strictEqual(result.block, true, 'mutating bash should be blocked');
462
450
  assert.ok(result.reason!.includes('depth_verification'));
463
-
464
- clearDiscussionFlowState();
465
451
  });
466
452
 
467
453
  // ─── Scenario 27: no pending gate means no blocking ──
468
454
 
469
455
  test('write-gate: no pending gate means no blocking', () => {
470
- clearDiscussionFlowState();
456
+ clearDiscussionFlowState(process.cwd());
471
457
 
472
458
  assert.strictEqual(shouldBlockPendingGate('write', 'M001').block, false);
473
459
  assert.strictEqual(shouldBlockPendingGateBash('npm run build', 'M001').block, false);
@@ -476,11 +462,40 @@ test('write-gate: no pending gate means no blocking', () => {
476
462
  // ─── Scenario 28: resetWriteGateState clears pending gate ──
477
463
 
478
464
  test('write-gate: resetWriteGateState clears pending gate', () => {
479
- setPendingGate('depth_verification');
480
- resetWriteGateState();
465
+ setPendingGate('depth_verification', process.cwd());
466
+ resetWriteGateState(process.cwd());
481
467
  assert.strictEqual(getPendingGate(), null);
482
468
  });
483
469
 
470
+ test('write-gate: in-memory state is scoped by basePath', () => {
471
+ const workspaceA = join(tmpdir(), `gsd-write-gate-isolation-a-${randomUUID()}`);
472
+ const workspaceB = join(tmpdir(), `gsd-write-gate-isolation-b-${randomUUID()}`);
473
+
474
+ try {
475
+ clearDiscussionFlowState(workspaceA);
476
+ clearDiscussionFlowState(workspaceB);
477
+
478
+ setPendingGate('depth_verification_M777', workspaceA);
479
+ assert.strictEqual(getPendingGate(workspaceA), 'depth_verification_M777', 'workspace A should see its pending gate');
480
+ assert.strictEqual(getPendingGate(workspaceB), null, 'workspace B should not see workspace A pending gate');
481
+
482
+ clearPendingGate(workspaceA);
483
+ setQueuePhaseActive(true, workspaceA);
484
+ assert.strictEqual(isQueuePhaseActive(workspaceA), true, 'workspace A should see queue mode active');
485
+ assert.strictEqual(isQueuePhaseActive(workspaceB), false, 'workspace B should not see workspace A queue mode');
486
+
487
+ markDepthVerified('M777', workspaceA);
488
+ assert.strictEqual(isMilestoneDepthVerified('M777', workspaceA), true, 'workspace A should see its verified milestone');
489
+ assert.strictEqual(isMilestoneDepthVerified('M777', workspaceB), false, 'workspace B should not see workspace A milestone verification');
490
+ assert.strictEqual(isDepthVerified(workspaceB), false, 'workspace B should have no verified depth state');
491
+ } finally {
492
+ clearDiscussionFlowState(workspaceA);
493
+ clearDiscussionFlowState(workspaceB);
494
+ rmSync(workspaceA, { recursive: true, force: true });
495
+ rmSync(workspaceB, { recursive: true, force: true });
496
+ }
497
+ });
498
+
484
499
  // ─── Standard options fixture used across depth confirmation tests ──
485
500
 
486
501
  const STANDARD_OPTIONS = [
@@ -656,7 +671,7 @@ test('write-gate: loadWriteGateSnapshot returns empty default when persist file
656
671
  } else {
657
672
  process.env.GSD_PERSIST_WRITE_GATE_STATE = originalEnv;
658
673
  }
659
- clearDiscussionFlowState();
674
+ clearDiscussionFlowState(base);
660
675
  try {
661
676
  rmSync(base, { recursive: true, force: true });
662
677
  } catch { /* swallow */ }
@@ -71,6 +71,6 @@ test('write-intercept: BLOCKED_WRITE_ERROR is a non-empty string', () => {
71
71
  });
72
72
 
73
73
  test('write-intercept: BLOCKED_WRITE_ERROR mentions engine tool calls', () => {
74
- assert.ok(BLOCKED_WRITE_ERROR.includes('gsd_complete_task'), 'should mention gsd_complete_task');
74
+ assert.ok(BLOCKED_WRITE_ERROR.includes('gsd_task_complete'), 'should mention gsd_task_complete');
75
75
  assert.ok(BLOCKED_WRITE_ERROR.includes('engine tool calls'), 'should mention engine tool calls');
76
76
  });
@@ -56,6 +56,7 @@ export interface CompleteMilestoneParams {
56
56
  export interface CompleteMilestoneResult {
57
57
  milestoneId: string;
58
58
  summaryPath: string;
59
+ stale?: boolean;
59
60
  }
60
61
 
61
62
  function renderMilestoneSummaryMarkdown(params: CompleteMilestoneParams): string {
@@ -206,15 +207,15 @@ export async function handleCompleteMilestone(
206
207
  // This handles re-dispatch scenarios (DB/disk state divergence) where a prior
207
208
  // completion already wrote the file. Overwriting would silently destroy the
208
209
  // richer content the agent produced during the original completion run.
210
+ let projectionStale = false;
209
211
  if (!existsSync(summaryPath)) {
210
212
  try {
211
213
  await saveFile(summaryPath, summaryMd);
212
214
  } catch (renderErr) {
213
- // Disk render failed — roll back DB status so state stays consistent
214
- logWarning("tool", `complete_milestone disk render failed, rolling back DB status: ${(renderErr as Error).message}`);
215
- updateMilestoneStatus(params.milestoneId, 'active', null);
216
- invalidateStateCache();
217
- return { error: `disk render failed: ${(renderErr as Error).message}` };
215
+ projectionStale = true;
216
+ logWarning("projection", `complete_milestone projection write failed for ${params.milestoneId}; DB completion remains committed`, {
217
+ error: (renderErr as Error).message,
218
+ });
218
219
  }
219
220
  }
220
221
 
@@ -252,5 +253,6 @@ export async function handleCompleteMilestone(
252
253
  return {
253
254
  milestoneId: params.milestoneId,
254
255
  summaryPath,
256
+ ...(projectionStale ? { stale: true } : {}),
255
257
  };
256
258
  }
@@ -4,7 +4,8 @@
4
4
  * Validates inputs, checks all tasks are complete, writes slice row to DB in
5
5
  * a transaction, then (outside the transaction) renders SUMMARY.md + UAT.md
6
6
  * to disk, toggles the roadmap checkbox, stores rendered markdown in DB for
7
- * D004 recovery, and invalidates caches.
7
+ * D004 recovery, and invalidates caches. Projection write failures are stale
8
+ * projection diagnostics and do not roll back committed DB state.
8
9
  */
9
10
 
10
11
  import { join } from "node:path";
@@ -277,7 +278,6 @@ export async function handleCompleteSlice(
277
278
 
278
279
  // ── Guards + DB writes inside a single transaction (prevents TOCTOU) ───
279
280
  const completedAt = new Date().toISOString();
280
- const originalSliceStatus = getSlice(params.milestoneId, params.sliceId)?.status ?? "pending";
281
281
  let guardError: string | null = null;
282
282
 
283
283
  transaction(() => {
@@ -349,10 +349,6 @@ export async function handleCompleteSlice(
349
349
  return { error: guardError };
350
350
  }
351
351
 
352
- // ── Filesystem operations (outside transaction) ─────────────────────────
353
- // If disk render fails, roll back the DB status so deriveState() and
354
- // verifyExpectedArtifact() stay consistent (both say "not done").
355
-
356
352
  // Render summary markdown
357
353
  const summaryMd = renderSliceSummaryMarkdown(params);
358
354
 
@@ -371,6 +367,8 @@ export async function handleCompleteSlice(
371
367
 
372
368
  const uatMd = renderUatMarkdown(params);
373
369
  const uatPath = summaryPath.replace(/-SUMMARY\.md$/, "-UAT.md");
370
+ setSliceSummaryMd(params.milestoneId, params.sliceId, summaryMd, uatMd);
371
+ let projectionStale = false;
374
372
 
375
373
  try {
376
374
  await saveFile(summaryPath, summaryMd);
@@ -382,16 +380,10 @@ export async function handleCompleteSlice(
382
380
  logWarning("tool", `complete_slice — could not find roadmap for ${params.milestoneId}, skipping checkbox toggle`);
383
381
  }
384
382
  } catch (renderErr) {
385
- // Disk render failed — roll back DB status so state stays consistent
386
- logWarning("tool", `complete_slice disk render failed for ${params.milestoneId}/${params.sliceId}, rolling back DB status`, { error: (renderErr as Error).message });
387
- updateSliceStatus(params.milestoneId, params.sliceId, originalSliceStatus);
388
- invalidateStateCache();
389
- return { error: `disk render failed: ${(renderErr as Error).message}` };
383
+ projectionStale = true;
384
+ logWarning("projection", `complete_slice projection write failed for ${params.milestoneId}/${params.sliceId}; DB completion remains committed`, { error: (renderErr as Error).message });
390
385
  }
391
386
 
392
- // Store rendered markdown in DB for D004 recovery
393
- setSliceSummaryMd(params.milestoneId, params.sliceId, summaryMd, uatMd);
394
-
395
387
  // ── Close gates owned by complete-slice (Q8) ───────────────────────────
396
388
  // Each owned gate maps to a specific summary section via the registry.
397
389
  // If the caller populated the corresponding field, record `pass`; if the
@@ -493,5 +485,6 @@ export async function handleCompleteSlice(
493
485
  milestoneId: params.milestoneId,
494
486
  summaryPath,
495
487
  uatPath,
488
+ ...(projectionStale ? { stale: true } : {}),
496
489
  };
497
490
  }