@opengsd/gsd-pi 1.2.0-dev.4c756166 → 1.2.0-dev.5457a158

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 (338) hide show
  1. package/dist/cli-style.d.ts +17 -0
  2. package/dist/cli-style.js +28 -0
  3. package/dist/cli.js +1 -1
  4. package/dist/headless-events.d.ts +4 -2
  5. package/dist/headless-events.js +7 -29
  6. package/dist/models-resolver.d.ts +3 -13
  7. package/dist/models-resolver.js +3 -22
  8. package/dist/resource-loader.js +2 -14
  9. package/dist/resources/.managed-resources-content-hash +1 -1
  10. package/dist/resources/extensions/bg-shell/utilities.js +5 -2
  11. package/dist/resources/extensions/claude-code-cli/models.js +9 -0
  12. package/dist/resources/extensions/claude-code-cli/stream-adapter.js +35 -4
  13. package/dist/resources/extensions/gsd/auto/orchestrator.js +33 -4
  14. package/dist/resources/extensions/gsd/auto/phases.js +6 -1
  15. package/dist/resources/extensions/gsd/auto-post-unit.js +19 -8
  16. package/dist/resources/extensions/gsd/auto-prompts.js +3 -0
  17. package/dist/resources/extensions/gsd/auto-start.js +12 -14
  18. package/dist/resources/extensions/gsd/auto-tool-tracking.js +18 -0
  19. package/dist/resources/extensions/gsd/auto-unit-tool-scope.js +7 -16
  20. package/dist/resources/extensions/gsd/auto-worktree-repair.js +10 -2
  21. package/dist/resources/extensions/gsd/auto-worktree.js +35 -352
  22. package/dist/resources/extensions/gsd/auto.js +8 -20
  23. package/dist/resources/extensions/gsd/bootstrap/agent-end-recovery.js +3 -2
  24. package/dist/resources/extensions/gsd/bootstrap/dynamic-tools.js +9 -6
  25. package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +86 -6
  26. package/dist/resources/extensions/gsd/bootstrap/write-gate.js +30 -4
  27. package/dist/resources/extensions/gsd/branch-patterns.js +2 -0
  28. package/dist/resources/extensions/gsd/captures.js +5 -15
  29. package/dist/resources/extensions/gsd/closeout-recovery.js +3 -2
  30. package/dist/resources/extensions/gsd/commands/catalog.js +6 -62
  31. package/dist/resources/extensions/gsd/crash-recovery.js +4 -12
  32. package/dist/resources/extensions/gsd/db/engine.js +755 -0
  33. package/dist/resources/extensions/gsd/db/queries.js +372 -0
  34. package/dist/resources/extensions/gsd/db/sql-constants.js +11 -0
  35. package/dist/resources/extensions/gsd/db/writers/cascades.js +194 -0
  36. package/dist/resources/extensions/gsd/db/writers/import-restore.js +182 -0
  37. package/dist/resources/extensions/gsd/db/writers/memory.js +149 -0
  38. package/dist/resources/extensions/gsd/db/writers/reconcile.js +458 -0
  39. package/dist/resources/extensions/gsd/db/writers/status.js +70 -0
  40. package/dist/resources/extensions/gsd/doctor-environment.js +5 -11
  41. package/dist/resources/extensions/gsd/doctor-format.js +9 -6
  42. package/dist/resources/extensions/gsd/doctor-git-checks.js +4 -3
  43. package/dist/resources/extensions/gsd/doctor-runtime-checks.js +21 -16
  44. package/dist/resources/extensions/gsd/error-classifier.js +9 -0
  45. package/dist/resources/extensions/gsd/git-service.js +1 -0
  46. package/dist/resources/extensions/gsd/gitignore.js +3 -0
  47. package/dist/resources/extensions/gsd/gsd-db.js +171 -2048
  48. package/dist/resources/extensions/gsd/guidance.js +98 -0
  49. package/dist/resources/extensions/gsd/guided-flow.js +51 -5
  50. package/dist/resources/extensions/gsd/mcp-tool-name.js +5 -13
  51. package/dist/resources/extensions/gsd/memory-consolidation-scanner.js +1 -1
  52. package/dist/resources/extensions/gsd/migrate/safety.js +20 -9
  53. package/dist/resources/extensions/gsd/migration-auto-check.js +24 -3
  54. package/dist/resources/extensions/gsd/model-cost-table.js +1 -0
  55. package/dist/resources/extensions/gsd/model-router.js +3 -0
  56. package/dist/resources/extensions/gsd/notification-store.js +11 -4
  57. package/dist/resources/extensions/gsd/parallel-merge.js +14 -11
  58. package/dist/resources/extensions/gsd/parallel-monitor-overlay.js +11 -7
  59. package/dist/resources/extensions/gsd/paths.js +37 -24
  60. package/dist/resources/extensions/gsd/pre-execution-checks.js +91 -3
  61. package/dist/resources/extensions/gsd/preferences-models.js +12 -46
  62. package/dist/resources/extensions/gsd/preferences.js +14 -0
  63. package/dist/resources/extensions/gsd/prompts/plan-slice.md +1 -1
  64. package/dist/resources/extensions/gsd/prompts/refine-slice.md +1 -1
  65. package/dist/resources/extensions/gsd/prompts/replan-slice.md +1 -1
  66. package/dist/resources/extensions/gsd/provider-error-guidance.js +1 -5
  67. package/dist/resources/extensions/gsd/provider-switch-observer.js +1 -1
  68. package/dist/resources/extensions/gsd/publication.js +87 -0
  69. package/dist/resources/extensions/gsd/recovery-classification.js +41 -87
  70. package/dist/resources/extensions/gsd/safety/evidence-collector.js +37 -4
  71. package/dist/resources/extensions/gsd/safety/evidence-cross-ref.js +7 -2
  72. package/dist/resources/extensions/gsd/safety/file-change-validator.js +10 -0
  73. package/dist/resources/extensions/gsd/state-transition-matrix.js +38 -0
  74. package/dist/resources/extensions/gsd/state.js +1 -20
  75. package/dist/resources/extensions/gsd/status-guards.js +56 -8
  76. package/dist/resources/extensions/gsd/stop-notice.js +57 -0
  77. package/dist/resources/extensions/gsd/tool-surface-readiness.js +56 -0
  78. package/dist/resources/extensions/gsd/tools/complete-slice.js +24 -43
  79. package/dist/resources/extensions/gsd/tools/exec-tool.js +5 -8
  80. package/dist/resources/extensions/gsd/tools/plan-slice.js +12 -6
  81. package/dist/resources/extensions/gsd/tools/reopen-milestone.js +11 -29
  82. package/dist/resources/extensions/gsd/tools/reopen-slice.js +14 -33
  83. package/dist/resources/extensions/gsd/tools/skip-slice.js +18 -36
  84. package/dist/resources/extensions/gsd/undo.js +8 -7
  85. package/dist/resources/extensions/gsd/unit-closeout.js +138 -0
  86. package/dist/resources/extensions/gsd/unit-context-composer.js +9 -1
  87. package/dist/resources/extensions/gsd/unit-context-manifest.js +4 -27
  88. package/dist/resources/extensions/gsd/unit-registry.js +350 -0
  89. package/dist/resources/extensions/gsd/unit-tool-contracts.js +9 -182
  90. package/dist/resources/extensions/gsd/workflow-tool-surface.js +1 -1
  91. package/dist/resources/extensions/gsd/worktree-git-recovery.js +293 -0
  92. package/dist/resources/extensions/gsd/worktree-lifecycle.js +9 -1
  93. package/dist/resources/extensions/gsd/worktree-manager.js +45 -28
  94. package/dist/resources/extensions/gsd/worktree-placement.js +59 -0
  95. package/dist/resources/extensions/gsd/worktree-reentry.js +12 -8
  96. package/dist/resources/extensions/gsd/worktree-root.js +28 -6
  97. package/dist/resources/extensions/gsd/worktree-safety.js +8 -5
  98. package/dist/resources/extensions/gsd/worktree-session-state.js +12 -11
  99. package/dist/resources/skills/gsd-browser/SKILL.md +1 -1
  100. package/dist/tsconfig.extensions.tsbuildinfo +1 -1
  101. package/dist/web/standalone/.next/BUILD_ID +1 -1
  102. package/dist/web/standalone/.next/app-path-routes-manifest.json +9 -9
  103. package/dist/web/standalone/.next/build-manifest.json +2 -2
  104. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  105. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  106. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  107. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  108. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  109. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  110. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  111. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  112. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  113. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  114. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  115. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  116. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  117. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  118. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  119. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  120. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  121. package/dist/web/standalone/.next/server/app/api/boot/route.js.nft.json +1 -1
  122. package/dist/web/standalone/.next/server/app/api/bridge-terminal/input/route.js.nft.json +1 -1
  123. package/dist/web/standalone/.next/server/app/api/bridge-terminal/resize/route.js.nft.json +1 -1
  124. package/dist/web/standalone/.next/server/app/api/bridge-terminal/stream/route.js.nft.json +1 -1
  125. package/dist/web/standalone/.next/server/app/api/captures/route.js.nft.json +1 -1
  126. package/dist/web/standalone/.next/server/app/api/cleanup/route.js.nft.json +1 -1
  127. package/dist/web/standalone/.next/server/app/api/doctor/route.js.nft.json +1 -1
  128. package/dist/web/standalone/.next/server/app/api/export-data/route.js.nft.json +1 -1
  129. package/dist/web/standalone/.next/server/app/api/files/route.js.nft.json +1 -1
  130. package/dist/web/standalone/.next/server/app/api/forensics/route.js.nft.json +1 -1
  131. package/dist/web/standalone/.next/server/app/api/git/route.js.nft.json +1 -1
  132. package/dist/web/standalone/.next/server/app/api/history/route.js.nft.json +1 -1
  133. package/dist/web/standalone/.next/server/app/api/hooks/route.js.nft.json +1 -1
  134. package/dist/web/standalone/.next/server/app/api/inspect/route.js.nft.json +1 -1
  135. package/dist/web/standalone/.next/server/app/api/knowledge/route.js.nft.json +1 -1
  136. package/dist/web/standalone/.next/server/app/api/live-state/route.js.nft.json +1 -1
  137. package/dist/web/standalone/.next/server/app/api/mcp-connections/route.js.nft.json +1 -1
  138. package/dist/web/standalone/.next/server/app/api/notifications/route.js.nft.json +1 -1
  139. package/dist/web/standalone/.next/server/app/api/onboarding/route.js.nft.json +1 -1
  140. package/dist/web/standalone/.next/server/app/api/projects/route.js.nft.json +1 -1
  141. package/dist/web/standalone/.next/server/app/api/recovery/route.js.nft.json +1 -1
  142. package/dist/web/standalone/.next/server/app/api/session/browser/route.js.nft.json +1 -1
  143. package/dist/web/standalone/.next/server/app/api/session/command/route.js.nft.json +1 -1
  144. package/dist/web/standalone/.next/server/app/api/session/events/route.js.nft.json +1 -1
  145. package/dist/web/standalone/.next/server/app/api/session/manage/route.js.nft.json +1 -1
  146. package/dist/web/standalone/.next/server/app/api/settings-data/route.js.nft.json +1 -1
  147. package/dist/web/standalone/.next/server/app/api/shutdown/route.js.nft.json +1 -1
  148. package/dist/web/standalone/.next/server/app/api/skill-health/route.js.nft.json +1 -1
  149. package/dist/web/standalone/.next/server/app/api/steer/route.js.nft.json +1 -1
  150. package/dist/web/standalone/.next/server/app/api/switch-root/route.js.nft.json +1 -1
  151. package/dist/web/standalone/.next/server/app/api/terminal/sessions/route.js.nft.json +1 -1
  152. package/dist/web/standalone/.next/server/app/api/terminal/stream/route.js.nft.json +1 -1
  153. package/dist/web/standalone/.next/server/app/api/undo/route.js.nft.json +1 -1
  154. package/dist/web/standalone/.next/server/app/api/visualizer/route.js.nft.json +1 -1
  155. package/dist/web/standalone/.next/server/app/index.html +1 -1
  156. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  157. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  158. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  159. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  160. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  161. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  162. package/dist/web/standalone/.next/server/app-paths-manifest.json +9 -9
  163. package/dist/web/standalone/.next/server/chunks/5124.js +1 -1
  164. package/dist/web/standalone/.next/server/chunks/{5047.js → 5942.js} +2 -2
  165. package/dist/web/standalone/.next/server/chunks/8357.js +1 -1
  166. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  167. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  168. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  169. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  170. package/dist/worktree-cli.js +3 -6
  171. package/dist/worktree-status-banner.js +7 -11
  172. package/package.json +1 -1
  173. package/packages/cloud-mcp-gateway/package.json +2 -2
  174. package/packages/contracts/dist/workflow.d.ts +4 -0
  175. package/packages/contracts/dist/workflow.d.ts.map +1 -1
  176. package/packages/contracts/dist/workflow.js.map +1 -1
  177. package/packages/contracts/package.json +1 -1
  178. package/packages/daemon/package.json +4 -4
  179. package/packages/gsd-agent-core/package.json +5 -5
  180. package/packages/gsd-agent-modes/package.json +7 -7
  181. package/packages/mcp-server/dist/cli.js +6 -3
  182. package/packages/mcp-server/dist/cli.js.map +1 -1
  183. package/packages/mcp-server/dist/workflow-tools.d.ts +8 -0
  184. package/packages/mcp-server/dist/workflow-tools.d.ts.map +1 -1
  185. package/packages/mcp-server/dist/workflow-tools.js +46 -21
  186. package/packages/mcp-server/dist/workflow-tools.js.map +1 -1
  187. package/packages/mcp-server/package.json +3 -3
  188. package/packages/native/package.json +1 -1
  189. package/packages/pi-agent-core/package.json +1 -1
  190. package/packages/pi-ai/dist/models.generated.d.ts +294 -239
  191. package/packages/pi-ai/dist/models.generated.d.ts.map +1 -1
  192. package/packages/pi-ai/dist/models.generated.js +260 -256
  193. package/packages/pi-ai/dist/models.generated.js.map +1 -1
  194. package/packages/pi-ai/package.json +1 -1
  195. package/packages/pi-coding-agent/dist/core/capability-patches.d.ts.map +1 -1
  196. package/packages/pi-coding-agent/dist/core/capability-patches.js +3 -1
  197. package/packages/pi-coding-agent/dist/core/capability-patches.js.map +1 -1
  198. package/packages/pi-coding-agent/package.json +7 -7
  199. package/packages/pi-tui/package.json +2 -2
  200. package/packages/rpc-client/package.json +2 -2
  201. package/pkg/package.json +1 -1
  202. package/src/resources/extensions/bg-shell/utilities.ts +5 -2
  203. package/src/resources/extensions/claude-code-cli/models.ts +9 -0
  204. package/src/resources/extensions/claude-code-cli/stream-adapter.ts +37 -2
  205. package/src/resources/extensions/claude-code-cli/tests/stream-adapter.test.ts +28 -0
  206. package/src/resources/extensions/gsd/auto/loop-deps.ts +1 -1
  207. package/src/resources/extensions/gsd/auto/orchestrator.ts +39 -5
  208. package/src/resources/extensions/gsd/auto/phases.ts +10 -1
  209. package/src/resources/extensions/gsd/auto-post-unit.ts +25 -7
  210. package/src/resources/extensions/gsd/auto-prompts.ts +3 -0
  211. package/src/resources/extensions/gsd/auto-start.ts +12 -15
  212. package/src/resources/extensions/gsd/auto-tool-tracking.ts +19 -0
  213. package/src/resources/extensions/gsd/auto-unit-tool-scope.ts +10 -17
  214. package/src/resources/extensions/gsd/auto-worktree-repair.ts +13 -2
  215. package/src/resources/extensions/gsd/auto-worktree.ts +41 -364
  216. package/src/resources/extensions/gsd/auto.ts +20 -24
  217. package/src/resources/extensions/gsd/bootstrap/agent-end-recovery.ts +3 -5
  218. package/src/resources/extensions/gsd/bootstrap/dynamic-tools.ts +10 -6
  219. package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +87 -6
  220. package/src/resources/extensions/gsd/bootstrap/write-gate.ts +29 -3
  221. package/src/resources/extensions/gsd/branch-patterns.ts +3 -0
  222. package/src/resources/extensions/gsd/captures.ts +5 -16
  223. package/src/resources/extensions/gsd/closeout-recovery.ts +2 -1
  224. package/src/resources/extensions/gsd/commands/catalog.ts +6 -68
  225. package/src/resources/extensions/gsd/crash-recovery.ts +3 -9
  226. package/src/resources/extensions/gsd/db/engine.ts +809 -0
  227. package/src/resources/extensions/gsd/db/queries.ts +453 -0
  228. package/src/resources/extensions/gsd/db/sql-constants.ts +12 -0
  229. package/src/resources/extensions/gsd/db/writers/cascades.ts +237 -0
  230. package/src/resources/extensions/gsd/db/writers/import-restore.ts +310 -0
  231. package/src/resources/extensions/gsd/db/writers/memory.ts +220 -0
  232. package/src/resources/extensions/gsd/db/writers/reconcile.ts +500 -0
  233. package/src/resources/extensions/gsd/db/writers/status.ts +88 -0
  234. package/src/resources/extensions/gsd/doctor-environment.ts +5 -13
  235. package/src/resources/extensions/gsd/doctor-format.ts +12 -7
  236. package/src/resources/extensions/gsd/doctor-git-checks.ts +3 -3
  237. package/src/resources/extensions/gsd/doctor-runtime-checks.ts +22 -17
  238. package/src/resources/extensions/gsd/error-classifier.ts +11 -0
  239. package/src/resources/extensions/gsd/git-service.ts +1 -0
  240. package/src/resources/extensions/gsd/gitignore.ts +3 -0
  241. package/src/resources/extensions/gsd/gsd-db.ts +173 -2373
  242. package/src/resources/extensions/gsd/guidance.ts +139 -0
  243. package/src/resources/extensions/gsd/guided-flow.ts +50 -5
  244. package/src/resources/extensions/gsd/mcp-tool-name.ts +6 -11
  245. package/src/resources/extensions/gsd/memory-consolidation-scanner.ts +1 -1
  246. package/src/resources/extensions/gsd/migrate/safety.ts +18 -7
  247. package/src/resources/extensions/gsd/migration-auto-check.ts +28 -3
  248. package/src/resources/extensions/gsd/model-cost-table.ts +1 -0
  249. package/src/resources/extensions/gsd/model-router.ts +3 -0
  250. package/src/resources/extensions/gsd/notification-store.ts +26 -3
  251. package/src/resources/extensions/gsd/parallel-merge.ts +12 -9
  252. package/src/resources/extensions/gsd/parallel-monitor-overlay.ts +10 -7
  253. package/src/resources/extensions/gsd/paths.ts +42 -22
  254. package/src/resources/extensions/gsd/pre-execution-checks.ts +109 -3
  255. package/src/resources/extensions/gsd/preferences-models.ts +10 -46
  256. package/src/resources/extensions/gsd/preferences.ts +18 -0
  257. package/src/resources/extensions/gsd/prompts/plan-slice.md +1 -1
  258. package/src/resources/extensions/gsd/prompts/refine-slice.md +1 -1
  259. package/src/resources/extensions/gsd/prompts/replan-slice.md +1 -1
  260. package/src/resources/extensions/gsd/provider-error-guidance.ts +4 -9
  261. package/src/resources/extensions/gsd/provider-switch-observer.ts +1 -1
  262. package/src/resources/extensions/gsd/publication.ts +122 -0
  263. package/src/resources/extensions/gsd/recovery-classification.ts +47 -88
  264. package/src/resources/extensions/gsd/safety/evidence-collector.ts +36 -4
  265. package/src/resources/extensions/gsd/safety/evidence-cross-ref.ts +7 -2
  266. package/src/resources/extensions/gsd/safety/file-change-validator.ts +14 -0
  267. package/src/resources/extensions/gsd/state-transition-matrix.ts +42 -0
  268. package/src/resources/extensions/gsd/state.ts +4 -21
  269. package/src/resources/extensions/gsd/status-guards.ts +59 -8
  270. package/src/resources/extensions/gsd/stop-notice.ts +75 -0
  271. package/src/resources/extensions/gsd/tests/auto-loop.test.ts +123 -0
  272. package/src/resources/extensions/gsd/tests/auto-paused-ui-cleanup.test.ts +3 -1
  273. package/src/resources/extensions/gsd/tests/auto-post-unit-evidence-crossref-4909.test.ts +46 -0
  274. package/src/resources/extensions/gsd/tests/auto-worktree-registry.test.ts +2 -2
  275. package/src/resources/extensions/gsd/tests/auto-worktree-repair.test.ts +4 -2
  276. package/src/resources/extensions/gsd/tests/checkout-branch-stash-guard.test.ts +66 -1
  277. package/src/resources/extensions/gsd/tests/clear-stale-autostart.test.ts +44 -0
  278. package/src/resources/extensions/gsd/tests/commands-verdict.test.ts +8 -7
  279. package/src/resources/extensions/gsd/tests/evidence-xref-gsd-exec.test.ts +157 -0
  280. package/src/resources/extensions/gsd/tests/file-change-validator.test.ts +33 -1
  281. package/src/resources/extensions/gsd/tests/guidance.test.ts +125 -0
  282. package/src/resources/extensions/gsd/tests/integration/auto-worktree-milestone-merge.test.ts +51 -4
  283. package/src/resources/extensions/gsd/tests/integration/auto-worktree.test.ts +54 -1
  284. package/src/resources/extensions/gsd/tests/integration/git-service.test.ts +3 -2
  285. package/src/resources/extensions/gsd/tests/migration-auto-check.test.ts +85 -1
  286. package/src/resources/extensions/gsd/tests/notification-store.test.ts +32 -0
  287. package/src/resources/extensions/gsd/tests/pre-execution-checks.test.ts +193 -1
  288. package/src/resources/extensions/gsd/tests/provider-error-guidance.test.ts +3 -3
  289. package/src/resources/extensions/gsd/tests/publication.test.ts +120 -0
  290. package/src/resources/extensions/gsd/tests/recovery-classification-illegal-transition.test.ts +30 -0
  291. package/src/resources/extensions/gsd/tests/register-hooks-depth-verification.test.ts +248 -1
  292. package/src/resources/extensions/gsd/tests/runtime-invariant-modules.test.ts +1 -0
  293. package/src/resources/extensions/gsd/tests/safety-harness-false-positives.test.ts +38 -0
  294. package/src/resources/extensions/gsd/tests/session-switch-clears-pending-autostart.test.ts +108 -0
  295. package/src/resources/extensions/gsd/tests/single-writer-invariant.test.ts +43 -6
  296. package/src/resources/extensions/gsd/tests/state-transition-matrix.test.ts +36 -0
  297. package/src/resources/extensions/gsd/tests/status-guards.test.ts +38 -0
  298. package/src/resources/extensions/gsd/tests/stop-notice.test.ts +70 -0
  299. package/src/resources/extensions/gsd/tests/tool-invocation-error-loop-break.test.ts +8 -0
  300. package/src/resources/extensions/gsd/tests/tool-surface-readiness.test.ts +155 -0
  301. package/src/resources/extensions/gsd/tests/unit-closeout.test.ts +209 -0
  302. package/src/resources/extensions/gsd/tests/unit-context-composer.test.ts +23 -2
  303. package/src/resources/extensions/gsd/tests/unit-registry.test.ts +163 -0
  304. package/src/resources/extensions/gsd/tests/workflow-mcp.test.ts +2 -2
  305. package/src/resources/extensions/gsd/tests/workflow-tool-executors.test.ts +2 -2
  306. package/src/resources/extensions/gsd/tests/worktree-lifecycle.test.ts +41 -4
  307. package/src/resources/extensions/gsd/tests/worktree-manager.test.ts +22 -1
  308. package/src/resources/extensions/gsd/tests/worktree-placement.test.ts +113 -0
  309. package/src/resources/extensions/gsd/tests/worktree-reentry.test.ts +1 -1
  310. package/src/resources/extensions/gsd/tests/worktree-safety.test.ts +3 -1
  311. package/src/resources/extensions/gsd/tests/worktree-symlink-removal.test.ts +12 -6
  312. package/src/resources/extensions/gsd/tests/worktree-teardown-safety.test.ts +2 -2
  313. package/src/resources/extensions/gsd/tests/write-gate.test.ts +42 -0
  314. package/src/resources/extensions/gsd/tool-surface-readiness.ts +76 -0
  315. package/src/resources/extensions/gsd/tools/complete-slice.ts +23 -58
  316. package/src/resources/extensions/gsd/tools/exec-tool.ts +5 -8
  317. package/src/resources/extensions/gsd/tools/plan-slice.ts +12 -6
  318. package/src/resources/extensions/gsd/tools/reopen-milestone.ts +11 -38
  319. package/src/resources/extensions/gsd/tools/reopen-slice.ts +14 -42
  320. package/src/resources/extensions/gsd/tools/skip-slice.ts +18 -44
  321. package/src/resources/extensions/gsd/undo.ts +9 -8
  322. package/src/resources/extensions/gsd/unit-closeout.ts +201 -0
  323. package/src/resources/extensions/gsd/unit-context-composer.ts +12 -1
  324. package/src/resources/extensions/gsd/unit-context-manifest.ts +4 -28
  325. package/src/resources/extensions/gsd/unit-registry.ts +425 -0
  326. package/src/resources/extensions/gsd/unit-tool-contracts.ts +27 -192
  327. package/src/resources/extensions/gsd/workflow-tool-surface.ts +4 -1
  328. package/src/resources/extensions/gsd/worktree-git-recovery.ts +314 -0
  329. package/src/resources/extensions/gsd/worktree-lifecycle.ts +10 -1
  330. package/src/resources/extensions/gsd/worktree-manager.ts +47 -28
  331. package/src/resources/extensions/gsd/worktree-placement.ts +63 -0
  332. package/src/resources/extensions/gsd/worktree-reentry.ts +10 -7
  333. package/src/resources/extensions/gsd/worktree-root.ts +29 -6
  334. package/src/resources/extensions/gsd/worktree-safety.ts +8 -5
  335. package/src/resources/extensions/gsd/worktree-session-state.ts +11 -11
  336. package/src/resources/skills/gsd-browser/SKILL.md +1 -1
  337. /package/dist/web/standalone/.next/static/{DUFWcMFRH3iXh7d2fbrOF → 2p9Rv9pQflAxCBbGVI2vb}/_buildManifest.js +0 -0
  338. /package/dist/web/standalone/.next/static/{DUFWcMFRH3iXh7d2fbrOF → 2p9Rv9pQflAxCBbGVI2vb}/_ssgManifest.js +0 -0
@@ -1,6 +1,6 @@
1
1
  import test from "node:test";
2
2
  import assert from "node:assert/strict";
3
- import { existsSync, mkdirSync, readFileSync, rmSync } from "node:fs";
3
+ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
4
4
  import { join } from "node:path";
5
5
  import { tmpdir } from "node:os";
6
6
 
@@ -13,7 +13,11 @@ import { closeDatabase, getMilestone } from "../gsd-db.ts";
13
13
  import { deriveState, invalidateStateCache } from "../state.ts";
14
14
  import {
15
15
  getPendingGate,
16
+ loadWriteGateSnapshot,
17
+ markApprovalGateVerified,
18
+ markDepthVerified,
16
19
  resetWriteGateState,
20
+ setPendingGate,
17
21
  shouldBlockContextArtifactSave,
18
22
  } from "../bootstrap/write-gate.ts";
19
23
  import { classifyCommand } from "../safety/destructive-guard.ts";
@@ -802,3 +806,246 @@ test("register-hooks message_update does NOT pause while an interactive elicitat
802
806
  "prose-only approval with no elicitation in flight must still arm the pause notice",
803
807
  );
804
808
  });
809
+
810
+ test("register-hooks agent_end does not re-arm deferred gate after workflow MCP verified write-gate on disk", async (t) => {
811
+ const dir = makeTempDir("mcp-disk-sync");
812
+ const originalCwd = process.cwd();
813
+ const originalEnv = process.env.GSD_PERSIST_WRITE_GATE_STATE;
814
+ process.chdir(dir);
815
+ resetWriteGateState(dir);
816
+ clearPendingAutoStart(dir);
817
+ process.env.GSD_PERSIST_WRITE_GATE_STATE = "1";
818
+
819
+ const gateId = "depth_verification_M005_confirm";
820
+ const statePath = join(dir, ".gsd", "runtime", "write-gate-state.json");
821
+
822
+ t.after(() => {
823
+ try {
824
+ resetWriteGateState(dir);
825
+ clearPendingAutoStart(dir);
826
+ } finally {
827
+ if (originalEnv === undefined) {
828
+ delete process.env.GSD_PERSIST_WRITE_GATE_STATE;
829
+ } else {
830
+ process.env.GSD_PERSIST_WRITE_GATE_STATE = originalEnv;
831
+ }
832
+ process.chdir(originalCwd);
833
+ rmSync(dir, { recursive: true, force: true });
834
+ }
835
+ });
836
+
837
+ const handlers = new Map<string, Array<(event: any, ctx?: any) => Promise<any> | any>>();
838
+ const pi = {
839
+ on(event: string, handler: (event: any, ctx?: any) => Promise<any> | any) {
840
+ const existing = handlers.get(event) ?? [];
841
+ existing.push(handler);
842
+ handlers.set(event, existing);
843
+ },
844
+ } as any;
845
+
846
+ const ctx = {
847
+ cwd: dir,
848
+ ui: { notify: () => undefined },
849
+ } as any;
850
+
851
+ registerHooks(pi, []);
852
+
853
+ setPendingAutoStart(dir, {
854
+ basePath: dir,
855
+ milestoneId: "M005",
856
+ ctx,
857
+ pi: { sendMessage: () => undefined } as any,
858
+ });
859
+
860
+ const approvalMessage = {
861
+ role: "assistant",
862
+ content: [
863
+ { type: "text", text: "Did I capture the depth right?" },
864
+ ],
865
+ };
866
+
867
+ for (const handler of handlers.get("message_update") ?? []) {
868
+ await handler({ message: approvalMessage }, ctx);
869
+ }
870
+
871
+ setPendingGate(gateId, dir);
872
+ mkdirSync(join(dir, ".gsd", "runtime"), { recursive: true });
873
+ writeFileSync(statePath, JSON.stringify({
874
+ verifiedDepthMilestones: ["M005"],
875
+ verifiedApprovalGates: [gateId],
876
+ activeQueuePhase: false,
877
+ pendingGateId: null,
878
+ }, null, 2), "utf-8");
879
+
880
+ for (const handler of handlers.get("agent_end") ?? []) {
881
+ await handler({ messages: [] }, ctx);
882
+ }
883
+
884
+ assert.equal(getPendingGate(dir), null, "agent_end must not re-arm a gate the MCP subprocess already verified");
885
+ assert.equal(
886
+ shouldBlockContextArtifactSave("CONTEXT", "M005", null, dir).block,
887
+ false,
888
+ "verified milestone context writes must stay unlocked after agent_end",
889
+ );
890
+ assert.deepEqual(loadWriteGateSnapshot(dir), {
891
+ verifiedDepthMilestones: ["M005"],
892
+ verifiedApprovalGates: [gateId],
893
+ activeQueuePhase: false,
894
+ pendingGateId: null,
895
+ });
896
+ });
897
+
898
+ // ── External-engine post-hoc gate replay (write-gate two-process sync) ──────
899
+ // On claude-code-cli, pi ingests the SDK turn's tool blocks after the workflow
900
+ // MCP child already executed them. The depth gate can therefore arrive at
901
+ // tool_execution_start AFTER the child verified it and allowed the CONTEXT
902
+ // save; re-arming then wipes the verification and permanently blocks the
903
+ // discuss→auto handoff.
904
+
905
+ function makeHookHarness(): {
906
+ handlers: Map<string, Array<(event: any, ctx?: any) => Promise<any> | any>>;
907
+ pi: any;
908
+ } {
909
+ const handlers = new Map<string, Array<(event: any, ctx?: any) => Promise<any> | any>>();
910
+ const pi = {
911
+ on(event: string, handler: (event: any, ctx?: any) => Promise<any> | any) {
912
+ const existing = handlers.get(event) ?? [];
913
+ existing.push(handler);
914
+ handlers.set(event, existing);
915
+ },
916
+ } as any;
917
+ return { handlers, pi };
918
+ }
919
+
920
+ test("tool_execution_start does not re-arm a depth gate the MCP child already verified", async (t) => {
921
+ const dir = makeTempDir("posthoc-no-rearm");
922
+ resetWriteGateState(dir);
923
+ t.after(() => {
924
+ resetWriteGateState(dir);
925
+ rmSync(dir, { recursive: true, force: true });
926
+ });
927
+
928
+ const { handlers, pi } = makeHookHarness();
929
+ registerHooks(pi, []);
930
+ const ctx = { cwd: dir, ui: { notify: () => undefined } } as any;
931
+
932
+ // The child verified the gate and allowed the CONTEXT save before the host
933
+ // ever saw the tool block.
934
+ markApprovalGateVerified("depth_verification_M002_confirm", dir);
935
+ markDepthVerified("M002", dir);
936
+
937
+ for (const handler of handlers.get("tool_execution_start") ?? []) {
938
+ await handler({
939
+ toolCallId: "t-depth",
940
+ toolName: "mcp__gsd-workflow__ask_user_questions",
941
+ args: { questions: [{ id: "depth_verification_M002_confirm" }] },
942
+ }, ctx);
943
+ }
944
+
945
+ assert.equal(getPendingGate(dir), null, "post-hoc replay must not re-arm a verified gate");
946
+ const snapshot = loadWriteGateSnapshot(dir);
947
+ assert.ok(
948
+ snapshot.verifiedDepthMilestones.includes("M002"),
949
+ "re-arm wipes verifiedDepthMilestones — the verification must survive the replay",
950
+ );
951
+ assert.equal(
952
+ shouldBlockContextArtifactSave("CONTEXT", "M002", null, dir).block,
953
+ false,
954
+ "context saves must stay unlocked after the replayed tool_execution_start",
955
+ );
956
+ });
957
+
958
+ test("tool_execution_start still arms an unverified depth gate", async (t) => {
959
+ const dir = makeTempDir("live-arm");
960
+ resetWriteGateState(dir);
961
+ t.after(() => {
962
+ resetWriteGateState(dir);
963
+ rmSync(dir, { recursive: true, force: true });
964
+ });
965
+
966
+ const { handlers, pi } = makeHookHarness();
967
+ registerHooks(pi, []);
968
+ const ctx = { cwd: dir, ui: { notify: () => undefined } } as any;
969
+
970
+ for (const handler of handlers.get("tool_execution_start") ?? []) {
971
+ await handler({
972
+ toolCallId: "t-depth",
973
+ toolName: "ask_user_questions",
974
+ args: { questions: [{ id: "depth_verification_M002_confirm" }] },
975
+ }, ctx);
976
+ }
977
+
978
+ assert.equal(getPendingGate(dir), "depth_verification_M002_confirm");
979
+ });
980
+
981
+ test("tool_result verifies the gate from result.structuredContent when event.details is missing", async (t) => {
982
+ const dir = makeTempDir("structured-fallback");
983
+ resetWriteGateState(dir);
984
+ t.after(() => {
985
+ resetWriteGateState(dir);
986
+ rmSync(dir, { recursive: true, force: true });
987
+ });
988
+
989
+ const { handlers, pi } = makeHookHarness();
990
+ registerHooks(pi, []);
991
+ const ctx = { cwd: dir, ui: { notify: () => undefined } } as any;
992
+
993
+ setPendingGate("depth_verification_M002_confirm", dir);
994
+
995
+ const questions = [{
996
+ id: "depth_verification_M002_confirm",
997
+ options: [
998
+ { label: "Yes, you got it (Recommended)" },
999
+ { label: "Not quite — let me clarify" },
1000
+ ],
1001
+ }];
1002
+ for (const handler of handlers.get("tool_result") ?? []) {
1003
+ await handler({
1004
+ toolCallId: "t-depth",
1005
+ toolName: "mcp__gsd-workflow__ask_user_questions",
1006
+ input: { questions },
1007
+ // External MCP relay: no pi-native details, structured payload on result.
1008
+ result: {
1009
+ content: [{ type: "text", text: "answered" }],
1010
+ structuredContent: {
1011
+ questions,
1012
+ response: {
1013
+ answers: {
1014
+ depth_verification_M002_confirm: { selected: "Yes, you got it (Recommended)", notes: "" },
1015
+ },
1016
+ },
1017
+ cancelled: false,
1018
+ },
1019
+ },
1020
+ }, ctx);
1021
+ }
1022
+
1023
+ assert.equal(getPendingGate(dir), null, "structured fallback must clear the pending gate");
1024
+ assert.ok(loadWriteGateSnapshot(dir).verifiedDepthMilestones.includes("M002"));
1025
+ });
1026
+
1027
+ test("tool_result without details or structured content leaves the gate pending without crashing", async (t) => {
1028
+ const dir = makeTempDir("no-details");
1029
+ resetWriteGateState(dir);
1030
+ t.after(() => {
1031
+ resetWriteGateState(dir);
1032
+ rmSync(dir, { recursive: true, force: true });
1033
+ });
1034
+
1035
+ const { handlers, pi } = makeHookHarness();
1036
+ registerHooks(pi, []);
1037
+ const ctx = { cwd: dir, ui: { notify: () => undefined } } as any;
1038
+
1039
+ setPendingGate("depth_verification_M002_confirm", dir);
1040
+
1041
+ for (const handler of handlers.get("tool_result") ?? []) {
1042
+ await handler({
1043
+ toolCallId: "t-depth",
1044
+ toolName: "ask_user_questions",
1045
+ input: { questions: [{ id: "depth_verification_M002_confirm" }] },
1046
+ result: { content: [{ type: "text", text: "answered" }] },
1047
+ }, ctx);
1048
+ }
1049
+
1050
+ assert.equal(getPendingGate(dir), "depth_verification_M002_confirm");
1051
+ });
@@ -164,6 +164,7 @@ test("Recovery Classification covers ADR-015 failure families", () => {
164
164
  const cases = [
165
165
  ["invalid tool schema enum", "tool-schema", "stop"],
166
166
  ["Tool Contract failure: complete-slice cannot use gsd_uat_result_save", "tool-contract", "stop"],
167
+ ["No such tool available: mcp__gsd-workflow__gsd_uat_exec", "tool-unavailable", "retry"],
167
168
  ["deterministic policy rejection", "deterministic-policy", "stop"],
168
169
  ["cannot legally advance because required UAT Assessment artifact is missing", "lifecycle-progression", "stop"],
169
170
  ["stale worker lease", "stale-worker", "stop"],
@@ -266,3 +266,41 @@ test("safety-harness: planned changed file avoids unexpected-file warning", (t)
266
266
  assert.deepEqual(audit!.unexpectedFiles, [], "planned index.html must not be unexpected");
267
267
  assert.deepEqual(audit!.missingFiles, [], "planned index.html must not be missing");
268
268
  });
269
+
270
+ // ─── External engine evidence (claude-code-cli pre-executed tools) ──────────
271
+ // External engines skip beforeToolCall/tool_call, so register-hooks.ts records
272
+ // evidence at tool_execution_start instead. These tests lock the collector
273
+ // semantics that wiring relies on: idempotent recording by toolCallId, and
274
+ // capitalized external tool names (Bash/Write/Edit) being recognized.
275
+
276
+ test("safety-harness: recordToolCall is idempotent by toolCallId", () => {
277
+ resetEvidence();
278
+
279
+ // Native tools fire tool_execution_start AND tool_call — both record.
280
+ recordToolCall("tc-dup-1", "bash", { command: "npm test" });
281
+ recordToolCall("tc-dup-1", "bash", { command: "npm test" });
282
+
283
+ assert.equal(getEvidence().length, 1, "same toolCallId must not duplicate");
284
+ });
285
+
286
+ test("safety-harness: external capitalized Bash call records and resolves evidence", () => {
287
+ resetEvidence();
288
+
289
+ // tool_execution_start with Claude Code's native tool name
290
+ recordToolCall("ext-bash-1", "Bash", { command: "node /tmp/t01-verify.mjs" });
291
+ const entries = getEvidence().filter((e): e is BashEvidence => e.kind === "bash");
292
+ assert.equal(entries.length, 1, "capitalized Bash must be recognized as execution tool");
293
+ assert.equal(entries[0]!.command, "node /tmp/t01-verify.mjs");
294
+
295
+ // tool_execution_end fills the result
296
+ recordToolResult("ext-bash-1", "Bash", { content: [{ type: "text", text: "13 checks passed" }] }, false);
297
+ assert.equal(entries[0]!.exitCode, 0, "non-error external result resolves to exitCode 0");
298
+ });
299
+
300
+ test("safety-harness: external Write call records file evidence", () => {
301
+ resetEvidence();
302
+
303
+ recordToolCall("ext-write-1", "Write", { file_path: "/tmp/app/index.html" });
304
+ const writes = getEvidence().filter((e) => e.kind === "write");
305
+ assert.equal(writes.length, 1, "capitalized Write must record file evidence");
306
+ });
@@ -0,0 +1,108 @@
1
+ // gsd-pi — A fresh conversation (/clear, /new) must clear pending auto-start.
2
+ //
3
+ // The discuss→auto handoff entry lives in-memory and is consumed on agent_end
4
+ // of the live interview. Once the milestone CONTEXT artifact is saved, the
5
+ // guided-flow staleness heuristic (which requires the CONTEXT file to be
6
+ // absent) can never fire — so a discussion interrupted by /clear left an
7
+ // immortal entry and every subsequent /gsd dead-ended on "Discussion already
8
+ // in progress — answer the question above" with no question above.
9
+ //
10
+ // session_switch with reason "new" means the conversation that contained the
11
+ // interview is gone; the entry must go with it. Reason "resume" restores the
12
+ // interview transcript, so the entry must survive.
13
+
14
+ import { describe, it, beforeEach, afterEach } from "node:test";
15
+ import assert from "node:assert/strict";
16
+ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
17
+ import { join } from "node:path";
18
+ import { tmpdir } from "node:os";
19
+
20
+ import { registerHooks } from "../bootstrap/register-hooks.ts";
21
+ import {
22
+ setPendingAutoStart,
23
+ clearPendingAutoStart,
24
+ _getPendingAutoStart,
25
+ } from "../pending-auto-start.ts";
26
+
27
+ function makeProjectDir(): string {
28
+ const dir = mkdtempSync(join(tmpdir(), "gsd-session-switch-pas-"));
29
+ const milestoneDir = join(dir, ".gsd", "milestones", "M001");
30
+ mkdirSync(milestoneDir, { recursive: true });
31
+ // The post-CONTEXT state that made the entry immortal before the fix.
32
+ writeFileSync(join(milestoneDir, "M001-CONTEXT.md"), "# M001 Context\n");
33
+ return dir;
34
+ }
35
+
36
+ function fakeCtx(base: string): any {
37
+ return {
38
+ cwd: base,
39
+ ui: {
40
+ notify: () => undefined,
41
+ setWidget: () => undefined,
42
+ setStatus: () => undefined,
43
+ },
44
+ };
45
+ }
46
+
47
+ function armPendingAutoStart(base: string): void {
48
+ setPendingAutoStart(base, {
49
+ basePath: base,
50
+ milestoneId: "M001",
51
+ ctx: { ui: { notify: () => undefined } } as any,
52
+ pi: { sendMessage: () => undefined } as any,
53
+ });
54
+ }
55
+
56
+ describe("session_switch clears pending auto-start on conversation reset", () => {
57
+ let base: string;
58
+ const handlers = new Map<string, Function>();
59
+
60
+ beforeEach(() => {
61
+ clearPendingAutoStart();
62
+ base = makeProjectDir();
63
+ handlers.clear();
64
+ registerHooks({ on(event: string, handler: Function) { handlers.set(event, handler); } } as any, []);
65
+ });
66
+
67
+ afterEach(() => {
68
+ clearPendingAutoStart();
69
+ rmSync(base, { recursive: true, force: true });
70
+ });
71
+
72
+ async function fireSessionSwitch(reason: "new" | "resume"): Promise<void> {
73
+ const handler = handlers.get("session_switch");
74
+ assert.ok(handler, "session_switch handler should be registered");
75
+ try {
76
+ await handler({ type: "session_switch", reason, previousSessionFile: undefined }, fakeCtx(base));
77
+ } catch {
78
+ // The handler also performs session plumbing (MCP prep, service tier
79
+ // sync) that may throw against the minimal fake ctx. Pending auto-start
80
+ // is cleared before that plumbing runs, so the assertions below remain
81
+ // valid either way.
82
+ }
83
+ }
84
+
85
+ it('reason "new" (/clear, /new) drops the entry even after CONTEXT was saved', async () => {
86
+ armPendingAutoStart(base);
87
+ assert.ok(_getPendingAutoStart(base), "entry should be armed");
88
+
89
+ await fireSessionSwitch("new");
90
+
91
+ assert.equal(
92
+ _getPendingAutoStart(base),
93
+ null,
94
+ "a fresh conversation destroyed the interview — the handoff entry must not outlive it",
95
+ );
96
+ });
97
+
98
+ it('reason "resume" keeps the entry (the interview transcript is restored)', async () => {
99
+ armPendingAutoStart(base);
100
+
101
+ await fireSessionSwitch("resume");
102
+
103
+ assert.ok(
104
+ _getPendingAutoStart(base),
105
+ "resuming restores the interview — the in-flight handoff must survive",
106
+ );
107
+ });
108
+ });
@@ -24,10 +24,24 @@ import { join, relative } from "node:path";
24
24
 
25
25
  const gsdDir = join(process.cwd(), "src/resources/extensions/gsd");
26
26
 
27
- const ALLOWLIST = new Set([
28
- "gsd-db.ts",
29
- "unit-ownership.ts",
30
- ]);
27
+ // The single-writer invariant is enforced on a directory layer, not a single
28
+ // filename. Write SQL may live only in:
29
+ // - db/engine.ts — connection lifecycle, schema/migrations (DDL), and the
30
+ // BEGIN/COMMIT transaction primitives. The shared handle every writer reads.
31
+ // - db/writers/**.ts — the Single Writer Layer: one cohesive write subsystem
32
+ // per file (hierarchy, memory, gates, escalation, reconcile, manifest,
33
+ // legacy-import, cascades).
34
+ // - gsd-db.ts — the barrel that re-exports the layer (still holds wrappers
35
+ // mid-migration).
36
+ // - unit-ownership.ts — a separate .gsd/unit-claims.db, intentionally outside.
37
+ // db/queries.ts is explicitly NOT allowed write SQL (asserted separately below).
38
+ function isSingleWriterFile(rel: string): boolean {
39
+ const norm = rel.split("\\").join("/");
40
+ if (norm === "gsd-db.ts" || norm === "unit-ownership.ts") return true;
41
+ if (norm === "db/engine.ts") return true;
42
+ if (norm.startsWith("db/writers/") && norm.endsWith(".ts")) return true;
43
+ return false;
44
+ }
31
45
 
32
46
  /** Walk the gsd extension dir and return all .ts files outside tests/. */
33
47
  function walkTsFiles(root: string): string[] {
@@ -106,8 +120,7 @@ test("no module outside gsd-db.ts issues raw write SQL against the engine DB", (
106
120
 
107
121
  for (const abs of files) {
108
122
  const rel = relative(gsdDir, abs);
109
- const base = rel.split("/").pop()!;
110
- if (ALLOWLIST.has(base)) continue;
123
+ if (isSingleWriterFile(rel)) continue;
111
124
 
112
125
  let content: string;
113
126
  try {
@@ -154,6 +167,30 @@ test("no module outside gsd-db.ts issues raw write SQL against the engine DB", (
154
167
  }
155
168
  });
156
169
 
170
+ test("db/queries.ts (the Query Module) is read-only — contains no write SQL", () => {
171
+ // The read seam is separate from the single-writer layer. queries.ts holds
172
+ // SELECT-only wrappers so read-only callers depend on a read seam, not the
173
+ // write surface. (test 1 above also forbids this, since queries.ts is not in
174
+ // db/writers/ — this is the explicit, positive statement of intent.)
175
+ const queriesPath = join(gsdDir, "db", "queries.ts");
176
+ const content = readFileSync(queriesPath, "utf-8");
177
+ const lines = content.split("\n");
178
+ const violations: Violation[] = [];
179
+ for (let i = 0; i < lines.length; i++) {
180
+ const line = lines[i];
181
+ const m = PREPARE_WRITE_RE.exec(line) ?? EXEC_WRITE_RE.exec(line);
182
+ if (m) {
183
+ violations.push({ file: "db/queries.ts", line: i + 1, snippet: line.trim(), kind: m[1].toUpperCase() });
184
+ }
185
+ }
186
+ assert.equal(
187
+ violations.length,
188
+ 0,
189
+ `db/queries.ts must contain no write SQL — move write wrappers to db/writers/:\n` +
190
+ violations.map((v) => ` db/queries.ts:${v.line} [${v.kind}] — ${v.snippet}`).join("\n"),
191
+ );
192
+ });
193
+
157
194
  test("gsd-db.ts exports the expected single-writer wrappers", async () => {
158
195
  // Positive assertion — fail loudly if the module layout changes so this
159
196
  // structural test can't silently become a no-op.
@@ -5,6 +5,8 @@ import {
5
5
  STATE_TRANSITION_MATRIX,
6
6
  findTransition,
7
7
  validateTransitionMatrix,
8
+ isLegalEdge,
9
+ IllegalPhaseTransitionError,
8
10
  } from "../state-transition-matrix.ts";
9
11
 
10
12
  test("state transition matrix covers required swarm hardening events", () => {
@@ -42,3 +44,37 @@ test("state transition matrix entries all have guard and reason codes", () => {
42
44
  assert.ok(entry.reasonCode.length > 0, `${entry.event} must include reason code`);
43
45
  }
44
46
  });
47
+
48
+ // ─── ADR-030: Phase Transition Invariant ───────────────────────────────────
49
+
50
+ test("isLegalEdge treats a self-edge as trivially legal", () => {
51
+ assert.equal(isLegalEdge("executing", "executing"), true);
52
+ assert.equal(isLegalEdge("planning", "planning"), true);
53
+ });
54
+
55
+ test("isLegalEdge accepts edges enumerated in the matrix", () => {
56
+ assert.equal(isLegalEdge("planning", "executing"), true);
57
+ assert.equal(isLegalEdge("executing", "summarizing"), true);
58
+ assert.equal(isLegalEdge("summarizing", "validating-milestone"), true);
59
+ assert.equal(isLegalEdge("completing-milestone", "complete"), true);
60
+ });
61
+
62
+ test("isLegalEdge honors the * wildcard rows (any -> blocked, any -> executing)", () => {
63
+ assert.equal(isLegalEdge("planning", "blocked"), true);
64
+ assert.equal(isLegalEdge("summarizing", "executing"), true);
65
+ });
66
+
67
+ test("isLegalEdge rejects an edge no matrix entry permits", () => {
68
+ // executing -> complete skips validation — exactly the illegal jump the
69
+ // invariant exists to catch.
70
+ assert.equal(isLegalEdge("executing", "complete"), false);
71
+ assert.equal(isLegalEdge("planning", "summarizing"), false);
72
+ });
73
+
74
+ test("IllegalPhaseTransitionError carries both endpoints and a descriptive message", () => {
75
+ const err = new IllegalPhaseTransitionError("executing", "complete");
76
+ assert.equal(err.from, "executing");
77
+ assert.equal(err.to, "complete");
78
+ assert.equal(err.name, "IllegalPhaseTransitionError");
79
+ assert.match(err.message, /executing -> complete/);
80
+ });
@@ -9,7 +9,10 @@ import {
9
9
  isDeferredStatus,
10
10
  isInactiveStatus,
11
11
  isSkippedForDispatch,
12
+ toStatus,
13
+ RAW_CLOSED_STATUSES,
12
14
  } from '../status-guards.ts';
15
+ import { TERMINAL_STATUS_SQL } from '../db/sql-constants.ts';
13
16
 
14
17
  test('isClosedStatus: "complete" returns true', () => {
15
18
  assert.equal(isClosedStatus('complete'), true);
@@ -95,3 +98,38 @@ test('isSkippedForDispatch does NOT skip pending/active/planned', () => {
95
98
  assert.equal(isSkippedForDispatch(s), false, `${s} should block dispatch ordering`);
96
99
  }
97
100
  });
101
+
102
+ // ─── ADR-030: canonical Status vocabulary + normalization ──────────────────
103
+
104
+ test('toStatus passes canonical values through unchanged', () => {
105
+ for (const s of ['pending', 'queued', 'active', 'parked', 'in_progress', 'blocked', 'complete', 'skipped', 'deferred']) {
106
+ assert.equal(toStatus(s), s, `${s} is canonical and should be returned verbatim`);
107
+ }
108
+ });
109
+
110
+ test('toStatus maps known aliases to canonical', () => {
111
+ assert.equal(toStatus('done'), 'complete');
112
+ assert.equal(toStatus('closed'), 'complete');
113
+ assert.equal(toStatus('planned'), 'pending');
114
+ assert.equal(toStatus('in-progress'), 'in_progress');
115
+ });
116
+
117
+ test('toStatus trims surrounding whitespace before matching', () => {
118
+ assert.equal(toStatus(' complete '), 'complete');
119
+ assert.equal(toStatus(' done '), 'complete');
120
+ });
121
+
122
+ test('toStatus quarantines unknown values verbatim (tolerant read, no throw)', () => {
123
+ assert.equal(toStatus('weird-legacy-value'), 'weird-legacy-value');
124
+ });
125
+
126
+ test('RAW_CLOSED_STATUSES is the single source: every member is closed', () => {
127
+ for (const s of RAW_CLOSED_STATUSES) {
128
+ assert.equal(isClosedStatus(s), true, `${s} is in RAW_CLOSED_STATUSES so must be closed`);
129
+ }
130
+ });
131
+
132
+ test('TERMINAL_STATUS_SQL is derived from RAW_CLOSED_STATUSES and renders identically', () => {
133
+ assert.equal(TERMINAL_STATUS_SQL, "'complete', 'done', 'skipped', 'closed'");
134
+ assert.equal(TERMINAL_STATUS_SQL, RAW_CLOSED_STATUSES.map((s) => `'${s}'`).join(', '));
135
+ });
@@ -0,0 +1,70 @@
1
+ // GSD Extension — Stop Notice module tests
2
+ // Locks the emitter↔detector round-trip: every notice the formatters produce
3
+ // must be recognized by the classifiers the headless host uses for exit codes.
4
+
5
+ import { describe, test } from "node:test";
6
+ import assert from "node:assert/strict";
7
+
8
+ import {
9
+ formatStopNoticePrefix,
10
+ isBlockedStopReason,
11
+ stopNoticeDisplayReason,
12
+ stopNoticeKind,
13
+ isTerminalNotice,
14
+ isPauseNotice,
15
+ isBlockedNoticeMessage,
16
+ isManualResolutionNotice,
17
+ PAUSED_NOTICE_PREFIXES,
18
+ TERMINAL_NOTICE_PREFIXES,
19
+ } from "../stop-notice.js";
20
+
21
+ describe("stop notice formatting", () => {
22
+ test("plain stop has no reason suffix", () => {
23
+ assert.equal(formatStopNoticePrefix(), "Auto-mode stopped");
24
+ assert.equal(formatStopNoticePrefix(null), "Auto-mode stopped");
25
+ });
26
+
27
+ test("reason is appended after an em-dash", () => {
28
+ assert.equal(formatStopNoticePrefix("user request"), "Auto-mode stopped — user request");
29
+ });
30
+
31
+ test("Blocked: marker switches the prefix and is stripped from display", () => {
32
+ assert.equal(formatStopNoticePrefix("Blocked: validation gate"), "Auto-mode blocked — validation gate");
33
+ assert.equal(stopNoticeKind("Blocked: x"), "blocked");
34
+ assert.equal(stopNoticeKind("stop"), "stopped");
35
+ assert.ok(isBlockedStopReason("blocked: lowercase too"));
36
+ assert.equal(stopNoticeDisplayReason("Blocked: spaced "), "spaced");
37
+ });
38
+ });
39
+
40
+ describe("emitter↔detector round-trip", () => {
41
+ test("formatted stop notices classify as terminal", () => {
42
+ for (const reason of [undefined, "user request"]) {
43
+ const message = formatStopNoticePrefix(reason).toLowerCase();
44
+ assert.ok(isTerminalNotice(message), `not terminal: ${message}`);
45
+ }
46
+ });
47
+
48
+ test("pause prefixes classify as pause and as blocked (operator intervention)", () => {
49
+ for (const prefix of PAUSED_NOTICE_PREFIXES) {
50
+ assert.ok(isPauseNotice(`${prefix}: provider error`));
51
+ assert.ok(isBlockedNoticeMessage(`${prefix}: provider error`));
52
+ }
53
+ });
54
+
55
+ test("idempotent-advance pauses are non-blocking", () => {
56
+ assert.equal(isBlockedNoticeMessage("auto-mode paused (idempotent advance: unit already active)"), false);
57
+ });
58
+
59
+ test("manual-resolution notices classify as blocked", () => {
60
+ const message = "merge conflict — resolve manually and re-run /gsd auto";
61
+ assert.ok(isManualResolutionNotice(message));
62
+ assert.ok(isBlockedNoticeMessage(message));
63
+ });
64
+
65
+ test("terminal prefixes cover the known stop vocabulary", () => {
66
+ for (const message of ["auto-mode stopped.", "auto-mode complete", "auto-mode idle", "no active milestone"]) {
67
+ assert.ok(TERMINAL_NOTICE_PREFIXES.some((prefix) => message.startsWith(prefix)), message);
68
+ }
69
+ });
70
+ });