@opengsd/gsd-pi 1.8.1 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (339) hide show
  1. package/README.md +10 -8
  2. package/dist/cli.js +5 -1
  3. package/dist/headless-events.d.ts +2 -1
  4. package/dist/headless-events.js +11 -3
  5. package/dist/headless-milestone-readiness.d.ts +29 -0
  6. package/dist/headless-milestone-readiness.js +161 -0
  7. package/dist/headless.js +25 -2
  8. package/dist/print-mode-exit.d.ts +12 -0
  9. package/dist/print-mode-exit.js +14 -0
  10. package/dist/resources/.managed-resources-content-hash +1 -1
  11. package/dist/resources/GSD-WORKFLOW.md +16 -47
  12. package/dist/resources/extensions/browser-tools/capture.js +2 -77
  13. package/dist/resources/extensions/browser-tools/screenshot-constraints.js +83 -0
  14. package/dist/resources/extensions/claude-code-cli/stream-adapter.js +17 -2
  15. package/dist/resources/extensions/claude-code-cli/turn-assembler.js +30 -2
  16. package/dist/resources/extensions/gsd/auto-artifact-paths.js +2 -2
  17. package/dist/resources/extensions/gsd/auto-dispatch.js +74 -19
  18. package/dist/resources/extensions/gsd/auto-post-unit.js +4 -0
  19. package/dist/resources/extensions/gsd/auto-prompts.js +35 -1
  20. package/dist/resources/extensions/gsd/auto.js +5 -1
  21. package/dist/resources/extensions/gsd/bootstrap/db-tools.js +78 -4
  22. package/dist/resources/extensions/gsd/bootstrap/write-gate.js +84 -26
  23. package/dist/resources/extensions/gsd/command-feedback.js +16 -12
  24. package/dist/resources/extensions/gsd/compat/compat-marker.js +19 -2
  25. package/dist/resources/extensions/gsd/db/command-queue.js +7 -2
  26. package/dist/resources/extensions/gsd/db/engine.js +51 -16
  27. package/dist/resources/extensions/gsd/db/writers/cascades.js +5 -1
  28. package/dist/resources/extensions/gsd/db/writers/status.js +13 -3
  29. package/dist/resources/extensions/gsd/db-base-schema.js +28 -0
  30. package/dist/resources/extensions/gsd/db-migration-steps.js +30 -0
  31. package/dist/resources/extensions/gsd/db-schema-metadata.js +4 -1
  32. package/dist/resources/extensions/gsd/docs/preferences-reference.md +4 -4
  33. package/dist/resources/extensions/gsd/flat-phase-migration.js +156 -21
  34. package/dist/resources/extensions/gsd/gsd-db.js +187 -45
  35. package/dist/resources/extensions/gsd/guided-flow.js +29 -10
  36. package/dist/resources/extensions/gsd/markdown-renderer.js +16 -2
  37. package/dist/resources/extensions/gsd/md-importer.js +102 -14
  38. package/dist/resources/extensions/gsd/migrate/command.js +19 -162
  39. package/dist/resources/extensions/gsd/migrate/execution.js +98 -0
  40. package/dist/resources/extensions/gsd/migrate/plan.js +49 -0
  41. package/dist/resources/extensions/gsd/migrate/planning-writer.js +12 -17
  42. package/dist/resources/extensions/gsd/migrate/presentation.js +64 -0
  43. package/dist/resources/extensions/gsd/parallel-eligibility.js +5 -4
  44. package/dist/resources/extensions/gsd/parallel-monitor-overlay.js +28 -43
  45. package/dist/resources/extensions/gsd/paths.js +4 -1
  46. package/dist/resources/extensions/gsd/phase-anchor.js +7 -2
  47. package/dist/resources/extensions/gsd/post-execution-checks.js +4 -4
  48. package/dist/resources/extensions/gsd/prompts/refine-slice.md +2 -2
  49. package/dist/resources/extensions/gsd/safety/evidence-collector.js +26 -1
  50. package/dist/resources/extensions/gsd/safety/evidence-cross-ref.js +30 -5
  51. package/dist/resources/extensions/gsd/state-reconciliation/drift/external-markdown-edit.js +27 -13
  52. package/dist/resources/extensions/gsd/state-reconciliation/drift/external-planning-edit.js +13 -3
  53. package/dist/resources/extensions/gsd/stop-notice.js +15 -1
  54. package/dist/resources/extensions/gsd/sync-lock.js +13 -7
  55. package/dist/resources/extensions/gsd/tools/complete-task.js +82 -1
  56. package/dist/resources/extensions/gsd/tools/plan-task.js +13 -15
  57. package/dist/resources/extensions/gsd/tools/reassess-roadmap.js +18 -15
  58. package/dist/resources/extensions/gsd/tools/replan-task.js +128 -0
  59. package/dist/resources/extensions/gsd/tools/rework-brief.js +74 -0
  60. package/dist/resources/extensions/gsd/tools/workflow-tool-executors.js +81 -0
  61. package/dist/resources/extensions/gsd/unit-registry.js +4 -0
  62. package/dist/resources/extensions/gsd/uok/plan-v2.js +19 -3
  63. package/dist/resources/extensions/gsd/worktree-state-projection.js +6 -0
  64. package/dist/resources/extensions/mac-tools/index.js +31 -9
  65. package/dist/tsconfig.extensions.tsbuildinfo +1 -1
  66. package/dist/web/standalone/.next/BUILD_ID +1 -1
  67. package/dist/web/standalone/.next/app-path-routes-manifest.json +8 -8
  68. package/dist/web/standalone/.next/build-manifest.json +2 -2
  69. package/dist/web/standalone/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  70. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  71. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  72. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  73. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  74. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  75. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  76. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  77. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  78. package/dist/web/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  79. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  80. package/dist/web/standalone/.next/server/app/_not-found.rsc +2 -2
  81. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +2 -2
  82. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  83. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +2 -2
  84. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  85. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  86. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  87. package/dist/web/standalone/.next/server/app/index.html +1 -1
  88. package/dist/web/standalone/.next/server/app/index.rsc +2 -2
  89. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  90. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +2 -2
  91. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  92. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +2 -2
  93. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +2 -2
  94. package/dist/web/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
  95. package/dist/web/standalone/.next/server/app-paths-manifest.json +8 -8
  96. package/dist/web/standalone/.next/server/chunks/8357.js +1 -1
  97. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  98. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  99. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  100. package/dist/web/standalone/.next/static/css/3b1ceb7abfb9a230.css +1 -0
  101. package/dist/web/standalone/node_modules/@gsd/native/package.json +1 -1
  102. package/dist/web/standalone/node_modules/node-pty/build/Makefile +2 -2
  103. package/dist/web/standalone/node_modules/node-pty/build/Release/pty.node +0 -0
  104. package/dist/web/standalone/node_modules/node-pty/build/pty.target.mk +14 -14
  105. package/dist/web/standalone/package.json +0 -1
  106. package/dist/web-mode.js +31 -3
  107. package/integrations/hermes/open_gsd_hermes/gsd_client.py +1 -1
  108. package/integrations/hermes/pyproject.toml +1 -1
  109. package/package.json +12 -10
  110. package/packages/cloud-mcp-gateway/package.json +2 -2
  111. package/packages/contracts/dist/workflow.d.ts +14 -0
  112. package/packages/contracts/dist/workflow.d.ts.map +1 -1
  113. package/packages/contracts/dist/workflow.js +16 -0
  114. package/packages/contracts/dist/workflow.js.map +1 -1
  115. package/packages/contracts/package.json +1 -1
  116. package/packages/daemon/dist/cloud-config.d.ts +1 -1
  117. package/packages/daemon/dist/cloud-config.d.ts.map +1 -1
  118. package/packages/daemon/dist/cloud-config.js +5 -1
  119. package/packages/daemon/dist/cloud-config.js.map +1 -1
  120. package/packages/daemon/dist/cloud-config.test.js +51 -1
  121. package/packages/daemon/dist/cloud-config.test.js.map +1 -1
  122. package/packages/daemon/dist/local-tool-executor.d.ts.map +1 -1
  123. package/packages/daemon/dist/local-tool-executor.js +2 -0
  124. package/packages/daemon/dist/local-tool-executor.js.map +1 -1
  125. package/packages/daemon/package.json +6 -6
  126. package/packages/gsd-agent-core/package.json +5 -5
  127. package/packages/gsd-agent-modes/package.json +7 -7
  128. package/packages/gsd-cloud/dist/cli.d.ts +5 -0
  129. package/packages/gsd-cloud/dist/cli.d.ts.map +1 -0
  130. package/packages/gsd-cloud/dist/cli.js +160 -0
  131. package/packages/gsd-cloud/dist/cli.js.map +1 -0
  132. package/packages/gsd-cloud/dist/cloud-config.d.ts +19 -0
  133. package/packages/gsd-cloud/dist/cloud-config.d.ts.map +1 -0
  134. package/packages/gsd-cloud/dist/cloud-config.js +231 -0
  135. package/packages/gsd-cloud/dist/cloud-config.js.map +1 -0
  136. package/packages/gsd-cloud/dist/cloud-config.test.d.ts +2 -0
  137. package/packages/gsd-cloud/dist/cloud-config.test.d.ts.map +1 -0
  138. package/packages/gsd-cloud/dist/cloud-config.test.js +118 -0
  139. package/packages/gsd-cloud/dist/cloud-config.test.js.map +1 -0
  140. package/packages/gsd-cloud/dist/cloud-gateway-lookup.test.d.ts +2 -0
  141. package/packages/gsd-cloud/dist/cloud-gateway-lookup.test.d.ts.map +1 -0
  142. package/packages/gsd-cloud/dist/cloud-gateway-lookup.test.js +37 -0
  143. package/packages/gsd-cloud/dist/cloud-gateway-lookup.test.js.map +1 -0
  144. package/packages/gsd-cloud/dist/cloud-runtime.d.ts +35 -0
  145. package/packages/gsd-cloud/dist/cloud-runtime.d.ts.map +1 -0
  146. package/packages/gsd-cloud/dist/cloud-runtime.js +258 -0
  147. package/packages/gsd-cloud/dist/cloud-runtime.js.map +1 -0
  148. package/packages/gsd-cloud/dist/cloud-runtime.test.d.ts +2 -0
  149. package/packages/gsd-cloud/dist/cloud-runtime.test.d.ts.map +1 -0
  150. package/packages/gsd-cloud/dist/cloud-runtime.test.js +88 -0
  151. package/packages/gsd-cloud/dist/cloud-runtime.test.js.map +1 -0
  152. package/packages/gsd-cloud/dist/cloud-token.d.ts +3 -0
  153. package/packages/gsd-cloud/dist/cloud-token.d.ts.map +1 -0
  154. package/packages/gsd-cloud/dist/cloud-token.js +37 -0
  155. package/packages/gsd-cloud/dist/cloud-token.js.map +1 -0
  156. package/packages/gsd-cloud/dist/config.d.ts +17 -0
  157. package/packages/gsd-cloud/dist/config.d.ts.map +1 -0
  158. package/packages/gsd-cloud/dist/config.js +146 -0
  159. package/packages/gsd-cloud/dist/config.js.map +1 -0
  160. package/packages/gsd-cloud/dist/device-flow.d.ts +24 -0
  161. package/packages/gsd-cloud/dist/device-flow.d.ts.map +1 -0
  162. package/packages/gsd-cloud/dist/device-flow.js +128 -0
  163. package/packages/gsd-cloud/dist/device-flow.js.map +1 -0
  164. package/packages/gsd-cloud/dist/device-flow.test.d.ts +2 -0
  165. package/packages/gsd-cloud/dist/device-flow.test.d.ts.map +1 -0
  166. package/packages/gsd-cloud/dist/device-flow.test.js +155 -0
  167. package/packages/gsd-cloud/dist/device-flow.test.js.map +1 -0
  168. package/packages/gsd-cloud/dist/executors/claude-executor.d.ts +6 -0
  169. package/packages/gsd-cloud/dist/executors/claude-executor.d.ts.map +1 -0
  170. package/packages/gsd-cloud/dist/executors/claude-executor.js +15 -0
  171. package/packages/gsd-cloud/dist/executors/claude-executor.js.map +1 -0
  172. package/packages/gsd-cloud/dist/executors/codex-executor.d.ts +6 -0
  173. package/packages/gsd-cloud/dist/executors/codex-executor.d.ts.map +1 -0
  174. package/packages/gsd-cloud/dist/executors/codex-executor.js +15 -0
  175. package/packages/gsd-cloud/dist/executors/codex-executor.js.map +1 -0
  176. package/packages/gsd-cloud/dist/executors/executor.d.ts +28 -0
  177. package/packages/gsd-cloud/dist/executors/executor.d.ts.map +1 -0
  178. package/packages/gsd-cloud/dist/executors/executor.js +11 -0
  179. package/packages/gsd-cloud/dist/executors/executor.js.map +1 -0
  180. package/packages/gsd-cloud/dist/executors/gsd-pi-executor.d.ts +34 -0
  181. package/packages/gsd-cloud/dist/executors/gsd-pi-executor.d.ts.map +1 -0
  182. package/packages/gsd-cloud/dist/executors/gsd-pi-executor.js +179 -0
  183. package/packages/gsd-cloud/dist/executors/gsd-pi-executor.js.map +1 -0
  184. package/packages/gsd-cloud/dist/executors/gsd-pi-executor.test.d.ts +2 -0
  185. package/packages/gsd-cloud/dist/executors/gsd-pi-executor.test.d.ts.map +1 -0
  186. package/packages/gsd-cloud/dist/executors/gsd-pi-executor.test.js +44 -0
  187. package/packages/gsd-cloud/dist/executors/gsd-pi-executor.test.js.map +1 -0
  188. package/packages/gsd-cloud/dist/executors/index.d.ts +17 -0
  189. package/packages/gsd-cloud/dist/executors/index.d.ts.map +1 -0
  190. package/packages/gsd-cloud/dist/executors/index.js +29 -0
  191. package/packages/gsd-cloud/dist/executors/index.js.map +1 -0
  192. package/packages/gsd-cloud/dist/executors/mcp-stdio-client.d.ts +36 -0
  193. package/packages/gsd-cloud/dist/executors/mcp-stdio-client.d.ts.map +1 -0
  194. package/packages/gsd-cloud/dist/executors/mcp-stdio-client.js +176 -0
  195. package/packages/gsd-cloud/dist/executors/mcp-stdio-client.js.map +1 -0
  196. package/packages/gsd-cloud/dist/executors/mcp-stdio-client.test.d.ts +2 -0
  197. package/packages/gsd-cloud/dist/executors/mcp-stdio-client.test.d.ts.map +1 -0
  198. package/packages/gsd-cloud/dist/executors/mcp-stdio-client.test.js +34 -0
  199. package/packages/gsd-cloud/dist/executors/mcp-stdio-client.test.js.map +1 -0
  200. package/packages/gsd-cloud/dist/index.d.ts +7 -0
  201. package/packages/gsd-cloud/dist/index.d.ts.map +1 -0
  202. package/packages/gsd-cloud/dist/index.js +8 -0
  203. package/packages/gsd-cloud/dist/index.js.map +1 -0
  204. package/packages/gsd-cloud/dist/inject-gateway.d.ts +16 -0
  205. package/packages/gsd-cloud/dist/inject-gateway.d.ts.map +1 -0
  206. package/packages/gsd-cloud/dist/inject-gateway.js +29 -0
  207. package/packages/gsd-cloud/dist/inject-gateway.js.map +1 -0
  208. package/packages/gsd-cloud/dist/inject-gateway.test.d.ts +2 -0
  209. package/packages/gsd-cloud/dist/inject-gateway.test.d.ts.map +1 -0
  210. package/packages/gsd-cloud/dist/inject-gateway.test.js +41 -0
  211. package/packages/gsd-cloud/dist/inject-gateway.test.js.map +1 -0
  212. package/packages/gsd-cloud/dist/logger.d.ts +25 -0
  213. package/packages/gsd-cloud/dist/logger.d.ts.map +1 -0
  214. package/packages/gsd-cloud/dist/logger.js +72 -0
  215. package/packages/gsd-cloud/dist/logger.js.map +1 -0
  216. package/packages/gsd-cloud/dist/types.d.ts +51 -0
  217. package/packages/gsd-cloud/dist/types.d.ts.map +1 -0
  218. package/packages/gsd-cloud/dist/types.js +9 -0
  219. package/packages/gsd-cloud/dist/types.js.map +1 -0
  220. package/packages/gsd-cloud/package.json +3 -3
  221. package/packages/mcp-server/README.md +8 -0
  222. package/packages/mcp-server/dist/workflow-tools.d.ts.map +1 -1
  223. package/packages/mcp-server/dist/workflow-tools.js +64 -2
  224. package/packages/mcp-server/dist/workflow-tools.js.map +1 -1
  225. package/packages/mcp-server/package.json +4 -4
  226. package/packages/native/package.json +1 -1
  227. package/packages/pi-agent-core/package.json +1 -1
  228. package/packages/pi-ai/dist/models.generated.d.ts +60 -0
  229. package/packages/pi-ai/dist/models.generated.d.ts.map +1 -1
  230. package/packages/pi-ai/dist/models.generated.js +54 -0
  231. package/packages/pi-ai/dist/models.generated.js.map +1 -1
  232. package/packages/pi-ai/dist/providers/amazon-bedrock.js +1 -0
  233. package/packages/pi-ai/dist/providers/amazon-bedrock.js.map +1 -1
  234. package/packages/pi-ai/dist/providers/anthropic.js +19 -0
  235. package/packages/pi-ai/dist/providers/anthropic.js.map +1 -1
  236. package/packages/pi-ai/package.json +1 -1
  237. package/packages/pi-coding-agent/package.json +7 -7
  238. package/packages/pi-tui/package.json +2 -2
  239. package/packages/rpc-client/package.json +2 -2
  240. package/pkg/package.json +1 -1
  241. package/src/resources/GSD-WORKFLOW.md +16 -47
  242. package/src/resources/extensions/browser-tools/capture.ts +2 -86
  243. package/src/resources/extensions/browser-tools/screenshot-constraints.ts +94 -0
  244. package/src/resources/extensions/claude-code-cli/stream-adapter.ts +18 -1
  245. package/src/resources/extensions/claude-code-cli/tests/stream-adapter.test.ts +108 -0
  246. package/src/resources/extensions/claude-code-cli/turn-assembler.ts +30 -2
  247. package/src/resources/extensions/gsd/auto-artifact-paths.ts +2 -2
  248. package/src/resources/extensions/gsd/auto-dispatch.ts +86 -19
  249. package/src/resources/extensions/gsd/auto-post-unit.ts +4 -0
  250. package/src/resources/extensions/gsd/auto-prompts.ts +38 -1
  251. package/src/resources/extensions/gsd/auto.ts +5 -1
  252. package/src/resources/extensions/gsd/bootstrap/db-tools.ts +91 -4
  253. package/src/resources/extensions/gsd/bootstrap/write-gate.ts +80 -24
  254. package/src/resources/extensions/gsd/command-feedback.ts +19 -12
  255. package/src/resources/extensions/gsd/compat/compat-marker.ts +21 -4
  256. package/src/resources/extensions/gsd/db/command-queue.ts +7 -1
  257. package/src/resources/extensions/gsd/db/engine.ts +53 -17
  258. package/src/resources/extensions/gsd/db/writers/cascades.ts +5 -1
  259. package/src/resources/extensions/gsd/db/writers/status.ts +25 -8
  260. package/src/resources/extensions/gsd/db-base-schema.ts +30 -0
  261. package/src/resources/extensions/gsd/db-migration-steps.ts +32 -0
  262. package/src/resources/extensions/gsd/db-schema-metadata.ts +4 -1
  263. package/src/resources/extensions/gsd/docs/preferences-reference.md +4 -4
  264. package/src/resources/extensions/gsd/flat-phase-migration.ts +160 -19
  265. package/src/resources/extensions/gsd/gsd-db.ts +255 -52
  266. package/src/resources/extensions/gsd/guided-flow.ts +39 -10
  267. package/src/resources/extensions/gsd/markdown-renderer.ts +23 -7
  268. package/src/resources/extensions/gsd/md-importer.ts +109 -11
  269. package/src/resources/extensions/gsd/migrate/command.ts +21 -227
  270. package/src/resources/extensions/gsd/migrate/execution.ts +136 -0
  271. package/src/resources/extensions/gsd/migrate/plan.ts +101 -0
  272. package/src/resources/extensions/gsd/migrate/planning-writer.ts +12 -20
  273. package/src/resources/extensions/gsd/migrate/presentation.ts +83 -0
  274. package/src/resources/extensions/gsd/parallel-eligibility.ts +5 -4
  275. package/src/resources/extensions/gsd/parallel-monitor-overlay.ts +37 -40
  276. package/src/resources/extensions/gsd/paths.ts +4 -1
  277. package/src/resources/extensions/gsd/phase-anchor.ts +8 -2
  278. package/src/resources/extensions/gsd/post-execution-checks.ts +4 -4
  279. package/src/resources/extensions/gsd/prompts/refine-slice.md +2 -2
  280. package/src/resources/extensions/gsd/safety/evidence-collector.ts +28 -1
  281. package/src/resources/extensions/gsd/safety/evidence-cross-ref.ts +31 -5
  282. package/src/resources/extensions/gsd/state-reconciliation/drift/external-markdown-edit.ts +30 -13
  283. package/src/resources/extensions/gsd/state-reconciliation/drift/external-planning-edit.ts +16 -3
  284. package/src/resources/extensions/gsd/state-reconciliation/types.ts +2 -2
  285. package/src/resources/extensions/gsd/stop-notice.ts +18 -1
  286. package/src/resources/extensions/gsd/sync-lock.ts +14 -6
  287. package/src/resources/extensions/gsd/tests/closeout-git-deferral.test.ts +96 -1
  288. package/src/resources/extensions/gsd/tests/command-feedback.test.ts +12 -0
  289. package/src/resources/extensions/gsd/tests/compat-marker.test.ts +104 -0
  290. package/src/resources/extensions/gsd/tests/complete-task.test.ts +286 -0
  291. package/src/resources/extensions/gsd/tests/db-engine-migrate-guards.test.ts +186 -0
  292. package/src/resources/extensions/gsd/tests/derive-state-db.test.ts +29 -0
  293. package/src/resources/extensions/gsd/tests/discuss-routing-fixes.test.ts +123 -0
  294. package/src/resources/extensions/gsd/tests/dispatch-missing-task-plans.test.ts +50 -0
  295. package/src/resources/extensions/gsd/tests/dispatch-rule-coverage.test.ts +49 -0
  296. package/src/resources/extensions/gsd/tests/evidence-cross-ref.test.ts +81 -0
  297. package/src/resources/extensions/gsd/tests/evidence-xref-gsd-exec.test.ts +22 -0
  298. package/src/resources/extensions/gsd/tests/external-edit-scoped-import.test.ts +262 -0
  299. package/src/resources/extensions/gsd/tests/flat-phase-migration.test.ts +202 -0
  300. package/src/resources/extensions/gsd/tests/gate-storage.test.ts +29 -0
  301. package/src/resources/extensions/gsd/tests/gsd-db.test.ts +25 -0
  302. package/src/resources/extensions/gsd/tests/import-slice-milestone-completion-preserve.test.ts +116 -0
  303. package/src/resources/extensions/gsd/tests/migrate-plan.test.ts +68 -0
  304. package/src/resources/extensions/gsd/tests/migrate-presentation.test.ts +98 -0
  305. package/src/resources/extensions/gsd/tests/migrate-safety-audit.test.ts +1 -1
  306. package/src/resources/extensions/gsd/tests/milestone-leases.test.ts +55 -0
  307. package/src/resources/extensions/gsd/tests/parallel-eligibility-file-overlap.test.ts +146 -0
  308. package/src/resources/extensions/gsd/tests/parallel-monitor-overlay.test.ts +59 -0
  309. package/src/resources/extensions/gsd/tests/phase-anchor.test.ts +32 -4
  310. package/src/resources/extensions/gsd/tests/plan-task.test.ts +26 -23
  311. package/src/resources/extensions/gsd/tests/planning-writer.test.ts +29 -0
  312. package/src/resources/extensions/gsd/tests/post-execution-checks.test.ts +22 -0
  313. package/src/resources/extensions/gsd/tests/reassess-handler.test.ts +50 -0
  314. package/src/resources/extensions/gsd/tests/replan-task-handler.test.ts +103 -0
  315. package/src/resources/extensions/gsd/tests/rework-brief.test.ts +197 -0
  316. package/src/resources/extensions/gsd/tests/skip-slice-cascades-tasks.test.ts +21 -0
  317. package/src/resources/extensions/gsd/tests/stop-notice.test.ts +17 -0
  318. package/src/resources/extensions/gsd/tests/sync-lock.test.ts +19 -0
  319. package/src/resources/extensions/gsd/tests/unit-context-composer.test.ts +34 -0
  320. package/src/resources/extensions/gsd/tests/uok-plan-v2-wiring.test.ts +93 -1
  321. package/src/resources/extensions/gsd/tests/workflow-mcp.test.ts +2 -0
  322. package/src/resources/extensions/gsd/tests/workflow-migration-gates.test.ts +139 -0
  323. package/src/resources/extensions/gsd/tests/worktree-state-projection.test.ts +36 -0
  324. package/src/resources/extensions/gsd/tests/write-gate-seam.test.ts +52 -0
  325. package/src/resources/extensions/gsd/tools/complete-task.ts +120 -0
  326. package/src/resources/extensions/gsd/tools/plan-task.ts +14 -16
  327. package/src/resources/extensions/gsd/tools/reassess-roadmap.ts +18 -17
  328. package/src/resources/extensions/gsd/tools/replan-task.ts +160 -0
  329. package/src/resources/extensions/gsd/tools/rework-brief.ts +91 -0
  330. package/src/resources/extensions/gsd/tools/workflow-tool-executors.ts +92 -0
  331. package/src/resources/extensions/gsd/types.ts +11 -0
  332. package/src/resources/extensions/gsd/unit-registry.ts +4 -0
  333. package/src/resources/extensions/gsd/uok/plan-v2.ts +20 -3
  334. package/src/resources/extensions/gsd/worktree-state-projection.ts +12 -0
  335. package/src/resources/extensions/mac-tools/index.ts +52 -9
  336. package/src/resources/extensions/mac-tools/tests/mac-screenshot-payload.test.cjs +70 -0
  337. package/dist/web/standalone/.next/static/css/18c2fdf261bfc1b7.css +0 -1
  338. /package/dist/web/standalone/.next/static/{UaXRrOYxBpG9QBINKhZkg → BE5XoklToI6lZjRzpXih8}/_buildManifest.js +0 -0
  339. /package/dist/web/standalone/.next/static/{UaXRrOYxBpG9QBINKhZkg → BE5XoklToI6lZjRzpXih8}/_ssgManifest.js +0 -0
@@ -26,6 +26,7 @@ import { tmpdir } from "node:os";
26
26
 
27
27
  import { registerHooks } from "../bootstrap/register-hooks.ts";
28
28
  import {
29
+ _setWriteGateInterleaveHookForTest,
29
30
  childWriteGateAdapter,
30
31
  clearDiscussionFlowState,
31
32
  getPendingGate,
@@ -36,6 +37,9 @@ import {
36
37
  setPendingGate,
37
38
  type WriteGateSnapshot,
38
39
  } from "../bootstrap/write-gate.ts";
40
+ import { acquireSyncLock, releaseSyncLock } from "../sync-lock.ts";
41
+
42
+ const WRITE_GATE_LOCK_NAME = "write-gate.lock";
39
43
 
40
44
  function makeTempDir(prefix: string): string {
41
45
  const dir = join(
@@ -356,3 +360,51 @@ test("seam: mutateWriteGateState reset path drops stale pendingGateId on a corru
356
360
  assert.equal(persisted.pendingGateId, null, "stale pending id must not be persisted after a corrupt-snapshot reconcile");
357
361
  assert.deepEqual(persisted.verifiedDepthMilestones, ["M099"]);
358
362
  });
363
+
364
+ // ── (f) cross-process lock closes the read-merge-write lost-update window ────
365
+
366
+ test("seam: read-merge-write holds the write-gate lock across the whole critical section", (t) => {
367
+ const dir = makeTempDir("lock-held");
368
+ t.after(() => {
369
+ _setWriteGateInterleaveHookForTest(null);
370
+ cleanup(dir);
371
+ });
372
+
373
+ // Fire inside the host's critical section, standing in for the OTHER process
374
+ // attempting to enter its own read-merge-write. The lock must lock it out.
375
+ let peerAcquiredMidSection: boolean | null = null;
376
+ _setWriteGateInterleaveHookForTest((lockRoot) => {
377
+ const res = acquireSyncLock(lockRoot, 0, WRITE_GATE_LOCK_NAME);
378
+ peerAcquiredMidSection = res.acquired;
379
+ if (res.acquired) releaseSyncLock(lockRoot, WRITE_GATE_LOCK_NAME);
380
+ });
381
+
382
+ markDepthVerified("M001", dir);
383
+
384
+ assert.equal(
385
+ peerAcquiredMidSection,
386
+ false,
387
+ "a concurrent process must be locked out of the read-merge-write section — this is what prevents the lost-update",
388
+ );
389
+ // The lock is released after the mutation, and the mutation still took effect.
390
+ assert.ok(loadWriteGateSnapshot(dir).verifiedDepthMilestones.includes("M001"));
391
+ assert.equal(acquireSyncLock(dir, 0, WRITE_GATE_LOCK_NAME).acquired, true, "lock released after mutation");
392
+ releaseSyncLock(dir, WRITE_GATE_LOCK_NAME);
393
+ });
394
+
395
+ test("seam: gate mutation fails OPEN when a live peer holds the lock (never blocks/refuses)", (t) => {
396
+ const dir = makeTempDir("lock-fail-open");
397
+ t.after(() => cleanup(dir));
398
+
399
+ // A live peer holds the lock (its own PID → never stolen as stale).
400
+ assert.equal(acquireSyncLock(dir, 0, WRITE_GATE_LOCK_NAME).acquired, true);
401
+ try {
402
+ // Host arms a gate while contended: fail-open means it proceeds anyway.
403
+ const armed = setPendingGate(GATE, dir);
404
+ assert.equal(armed, true, "arm must succeed (fail-open) even though the lock is held");
405
+ assert.equal(getPendingGate(dir), GATE);
406
+ assert.equal(readDiskRaw(dir).pendingGateId, GATE, "fail-open still persists the mutation");
407
+ } finally {
408
+ releaseSyncLock(dir, WRITE_GATE_LOCK_NAME);
409
+ }
410
+ });
@@ -29,6 +29,10 @@ import {
29
29
  deleteVerificationEvidence,
30
30
  saveGateResult,
31
31
  getPendingGatesForTurn,
32
+ getUnresolvedBlockingReworkFindingsForTask,
33
+ getBlockingReworkFindingsForTask,
34
+ applyReworkResolutions,
35
+ type ReworkFindingStatus,
32
36
  } from "../gsd-db.js";
33
37
  import { getWorkflowDatabasePath, ensureWorkflowDbAtPath } from "../db-workspace.js";
34
38
  import { getGatesForTurn } from "../gate-registry.js";
@@ -185,6 +189,70 @@ export function normalizeListParam(value: unknown): string[] {
185
189
  * Build a TaskRow-shaped object from CompleteTaskParams so the unified
186
190
  * renderSummaryContent() can be used at completion time (#2720).
187
191
  */
192
+
193
+ function normalizeReworkResolution(params: CompleteTaskParams): Array<{
194
+ milestoneId: string;
195
+ sliceId: string;
196
+ taskId: string;
197
+ findingId: string;
198
+ status: "resolved" | "deferred-with-override";
199
+ evidence: string;
200
+ decisionRef?: string;
201
+ }> {
202
+ return (params.reworkResolution ?? []).map((resolution) => ({
203
+ milestoneId: params.milestoneId,
204
+ sliceId: params.sliceId,
205
+ taskId: params.taskId,
206
+ findingId: resolution.findingId,
207
+ status: resolution.status,
208
+ evidence: resolution.evidence,
209
+ decisionRef: resolution.decisionRef,
210
+ }));
211
+ }
212
+
213
+ function unresolvedReworkError(missingFindingIds: string[]): string {
214
+ const plural = missingFindingIds.length === 1 ? "finding" : "findings";
215
+ return `unresolved blocking rework ${plural}: ${missingFindingIds.join(", ")} — provide reworkResolution entries with status resolved and evidence, or status deferred-with-override with evidence and decisionRef, before completing the task`;
216
+ }
217
+
218
+ function satisfiesBlockingReworkFinding(resolution: ReturnType<typeof normalizeReworkResolution>[number]): boolean {
219
+ if (resolution.evidence.trim().length === 0) return false;
220
+ if (resolution.status === "resolved") return true;
221
+ return (resolution.decisionRef ?? "").trim().length > 0;
222
+ }
223
+
224
+ /**
225
+ * Snapshot of a rework finding's status/evidence as it existed *before* this
226
+ * completion applied its reworkResolution. Captured inside the completion
227
+ * transaction so the compensating rollback paths can restore the exact prior
228
+ * state.
229
+ */
230
+ type ReworkFindingSnapshot = {
231
+ milestoneId: string;
232
+ sliceId: string;
233
+ taskId: string;
234
+ findingId: string;
235
+ status: ReworkFindingStatus;
236
+ evidence: string;
237
+ decisionRef?: string;
238
+ };
239
+
240
+ /**
241
+ * Restore rework findings to their pre-completion state.
242
+ *
243
+ * The completion transaction flips blocking findings to resolved/
244
+ * deferred-with-override via applyReworkResolutions. When a later projection
245
+ * or escalation write fails and we compensate by reverting the task to
246
+ * `pending`, we must also revert those findings. Otherwise a retry sees no
247
+ * unresolved blocking findings (getUnresolvedBlockingReworkFindingsForTask
248
+ * only returns `pending` rows) and completes the task with the blocking gate
249
+ * silently skipped.
250
+ */
251
+ function revertAppliedReworkResolutions(snapshot: ReworkFindingSnapshot[]): void {
252
+ if (snapshot.length === 0) return;
253
+ applyReworkResolutions(snapshot);
254
+ }
255
+
188
256
  function paramsToTaskRow(params: CompleteTaskParams, completedAt: string): TaskRow {
189
257
  return {
190
258
  milestone_id: params.milestoneId,
@@ -271,6 +339,7 @@ export async function handleCompleteTask(
271
339
  let guardError: string | null = null;
272
340
  let summaryMd = "";
273
341
  let repairTaskSummaryRow: TaskRow | null = null;
342
+ let appliedReworkSnapshot: ReworkFindingSnapshot[] = [];
274
343
  const rollbackDbPath = getWorkflowDatabasePath();
275
344
 
276
345
  // ── ADR-011 Phase 2: validate escalation payload BEFORE any side effects ─
@@ -282,6 +351,8 @@ export async function handleCompleteTask(
282
351
  // no escalation recorded, and the loop would silently advance past it.
283
352
  // The filesystem write happens later (after side effects) because that's
284
353
  // the cheapest ordering and validation is where 99% of failures live.
354
+ const reworkResolutions = normalizeReworkResolution(params);
355
+
285
356
  let validatedEscalationArtifact: ReturnType<typeof buildEscalationArtifact> | null = null;
286
357
  let escalationWriteEnabled = false;
287
358
  if (params.escalation) {
@@ -323,6 +394,20 @@ export async function handleCompleteTask(
323
394
  }
324
395
 
325
396
  const existingTask = getTask(params.milestoneId, params.sliceId, params.taskId);
397
+ const unresolvedRework = getUnresolvedBlockingReworkFindingsForTask(params.milestoneId, params.sliceId, params.taskId);
398
+ const resolvedFindingIds = new Set(
399
+ reworkResolutions
400
+ .filter(satisfiesBlockingReworkFinding)
401
+ .map((resolution) => resolution.findingId),
402
+ );
403
+ const missingFindingIds = unresolvedRework
404
+ .filter((finding) => !resolvedFindingIds.has(finding.finding_id))
405
+ .map((finding) => finding.finding_id);
406
+ if (missingFindingIds.length > 0) {
407
+ guardError = unresolvedReworkError(missingFindingIds);
408
+ return;
409
+ }
410
+
326
411
  if (existingTask && isClosedStatus(existingTask.status)) {
327
412
  // Stale-turn path: a timed-out turn that was superseded by recovery
328
413
  // can still reach this code when its LLM call eventually returns and
@@ -378,6 +463,38 @@ export async function handleCompleteTask(
378
463
  fullSummaryMd: summaryMd,
379
464
  });
380
465
 
466
+ // Only persist resolutions that actually satisfy the evidence
467
+ // requirement. The guard above admits a finding as long as ONE satisfying
468
+ // entry exists, but applyReworkResolutions writes by findingId and lets the
469
+ // last entry win. Persisting every entry would let a later non-satisfying
470
+ // duplicate (empty evidence, or deferred-with-override without decisionRef)
471
+ // overwrite a valid resolution and leave the finding non-pending without
472
+ // acceptable evidence. Filtering with the same predicate the guard uses
473
+ // keeps the applied set and the gate consistent.
474
+ const resolutionsToApply = reworkResolutions.filter(satisfiesBlockingReworkFinding);
475
+ if (resolutionsToApply.length > 0) {
476
+ // Snapshot the pre-resolution state of the findings we're about to
477
+ // change so a compensating rollback can restore them exactly (see
478
+ // revertAppliedReworkResolutions).
479
+ const resolvedFindingIdsForSnapshot = new Set(resolutionsToApply.map((r) => r.findingId));
480
+ appliedReworkSnapshot = getBlockingReworkFindingsForTask(
481
+ params.milestoneId,
482
+ params.sliceId,
483
+ params.taskId,
484
+ )
485
+ .filter((finding) => resolvedFindingIdsForSnapshot.has(finding.finding_id))
486
+ .map((finding) => ({
487
+ milestoneId: params.milestoneId,
488
+ sliceId: params.sliceId,
489
+ taskId: params.taskId,
490
+ findingId: finding.finding_id,
491
+ status: finding.status,
492
+ evidence: finding.evidence,
493
+ decisionRef: finding.decision_ref,
494
+ }));
495
+ applyReworkResolutions(resolutionsToApply);
496
+ }
497
+
381
498
  for (const evidence of (params.verificationEvidence ?? [])) {
382
499
  insertVerificationEvidence({
383
500
  taskId: params.taskId,
@@ -459,6 +576,7 @@ export async function handleCompleteTask(
459
576
  ensureWorkflowDbAtPath(rollbackDbPath);
460
577
  deleteVerificationEvidence(params.milestoneId, params.sliceId, params.taskId);
461
578
  updateTaskStatus(params.milestoneId, params.sliceId, params.taskId, "pending");
579
+ revertAppliedReworkResolutions(appliedReworkSnapshot);
462
580
  invalidateStateCache();
463
581
  rollbackSucceeded = true;
464
582
  } catch (rollbackErr) {
@@ -559,6 +677,7 @@ export async function handleCompleteTask(
559
677
  try {
560
678
  deleteVerificationEvidence(params.milestoneId, params.sliceId, params.taskId);
561
679
  updateTaskStatus(params.milestoneId, params.sliceId, params.taskId, 'pending');
680
+ revertAppliedReworkResolutions(appliedReworkSnapshot);
562
681
  invalidateStateCache();
563
682
  logWarning(
564
683
  "tool",
@@ -580,6 +699,7 @@ export async function handleCompleteTask(
580
699
  try {
581
700
  deleteVerificationEvidence(params.milestoneId, params.sliceId, params.taskId);
582
701
  updateTaskStatus(params.milestoneId, params.sliceId, params.taskId, 'pending');
702
+ revertAppliedReworkResolutions(appliedReworkSnapshot);
583
703
  invalidateStateCache();
584
704
  logWarning(
585
705
  "tool",
@@ -5,7 +5,7 @@ import { getGateIdsForTurn } from "../gate-registry.js";
5
5
  import { transaction, getSlice, getTask, insertTask, upsertTaskPlanning, insertGateRow, setSliceSketchFlag } from "../gsd-db.js";
6
6
  import { invalidateStateCache } from "../state.js";
7
7
  import { renderTaskPlanFromDb, renderPlanFromDb } from "../markdown-renderer.js";
8
- import { resolveTasksDir } from "../paths.js";
8
+ import { resolveMilestonePath, resolveSlicePath } from "../paths.js";
9
9
  import { flushWorkflowProjections } from "../projection-flush.js";
10
10
  import { writeManifest } from "../workflow-manifest.js";
11
11
  import { appendEvent } from "../workflow-events.js";
@@ -255,21 +255,19 @@ export async function handlePlanTask(
255
255
  }
256
256
 
257
257
  try {
258
- const renderResult = await renderTaskPlanFromDb(basePath, params.milestoneId, params.sliceId, params.taskId);
259
-
260
- // Flat-phase: tasks live as checkboxes in the slice plan's <tasks> block,
261
- // not as standalone TID-PLAN.md files. Re-render the slice plan so the
262
- // new/updated task appears in the plan file that gsd-core reads.
263
- // Guard: resolveTasksDir is null in flat-phase (no tasks/ subdir exists).
258
+ const milestonePath = resolveMilestonePath(basePath, params.milestoneId);
259
+ const slicePath = resolveSlicePath(basePath, params.milestoneId, params.sliceId);
260
+ const isLegacySliceLayout = Boolean(milestonePath && slicePath && slicePath !== milestonePath);
261
+ let renderedPath: string;
264
262
  let slicePlanSynced = false;
265
- try {
266
- const tDir = resolveTasksDir(basePath, params.milestoneId, params.sliceId);
267
- if (!tDir) {
268
- await renderPlanFromDb(basePath, params.milestoneId, params.sliceId);
269
- slicePlanSynced = true;
270
- }
271
- } catch (syncErr) {
272
- logWarning("tool", `plan-task: slice-plan sync failed: ${(syncErr as Error).message}`);
263
+
264
+ if (isLegacySliceLayout) {
265
+ const renderResult = await renderTaskPlanFromDb(basePath, params.milestoneId, params.sliceId, params.taskId);
266
+ renderedPath = renderResult.taskPlanPath;
267
+ } else {
268
+ const renderResult = await renderPlanFromDb(basePath, params.milestoneId, params.sliceId);
269
+ renderedPath = renderResult.planPath;
270
+ slicePlanSynced = true;
273
271
  }
274
272
 
275
273
  if (slicePlanSynced) {
@@ -299,7 +297,7 @@ export async function handlePlanTask(
299
297
  milestoneId: params.milestoneId,
300
298
  sliceId: params.sliceId,
301
299
  taskId: params.taskId,
302
- taskPlanPath: renderResult.taskPlanPath,
300
+ taskPlanPath: renderedPath,
303
301
  };
304
302
  } catch (err) {
305
303
  return { error: `render failed: ${(err as Error).message}` };
@@ -1,6 +1,6 @@
1
1
  import { existsSync, unlinkSync } from "node:fs";
2
- import { join } from "node:path";
3
- import { relSliceFile, resolveMilestoneFile, resolveMilestonePath, targetMilestoneFile } from "../paths.js";
2
+ import { join, relative } from "node:path";
3
+ import { gsdProjectionRoot, gsdRoot, resolveMilestoneFile, resolveMilestonePath, targetMilestoneFile } from "../paths.js";
4
4
  import { clearParseCache } from "../files.js";
5
5
  import { isClosedStatus } from "../status-guards.js";
6
6
  import { isNonEmptyString } from "../validation.js";
@@ -53,6 +53,14 @@ export interface ReassessRoadmapResult {
53
53
  roadmapPath: string;
54
54
  }
55
55
 
56
+ function assessmentDbPathForRenderedFile(basePath: string, absPath: string): string {
57
+ const projectionRoot = gsdProjectionRoot(basePath);
58
+ const projectionRel = relative(projectionRoot, absPath);
59
+ const root = projectionRel && !projectionRel.startsWith("..") && !projectionRel.startsWith("/")
60
+ ? projectionRoot
61
+ : gsdRoot(basePath);
62
+ return `.gsd/${relative(root, absPath).replace(/\\/g, "/")}`;
63
+ }
56
64
 
57
65
  function validateParams(params: ReassessRoadmapParams): ReassessRoadmapParams {
58
66
  if (!isNonEmptyString(params?.milestoneId)) throw new Error("milestoneId is required");
@@ -119,11 +127,6 @@ export async function handleReassessRoadmap(
119
127
  return { error: `validation failed: ${(err as Error).message}` };
120
128
  }
121
129
 
122
- // ── Compute assessment artifact path ──────────────────────────────
123
- // Assessment lives in the completed slice's directory.
124
- // Use relSliceFile so the path is layout-aware (flat-phase or legacy).
125
- const assessmentRelPath = relSliceFile(basePath, params.milestoneId, params.completedSliceId, "ASSESSMENT");
126
-
127
130
  // ── Guards + DB writes inside a single transaction (prevents TOCTOU) ───
128
131
  // Guards must be inside the transaction so the state they check cannot
129
132
  // change between the read and the write (#2723).
@@ -207,16 +210,6 @@ export async function handleReassessRoadmap(
207
210
  }
208
211
  }
209
212
 
210
- // Record assessment
211
- insertAssessment({
212
- path: assessmentRelPath,
213
- milestoneId: params.milestoneId,
214
- sliceId: params.completedSliceId,
215
- status: params.verdict,
216
- scope: "roadmap",
217
- fullContent: params.assessment,
218
- });
219
-
220
213
  // Apply slice modifications
221
214
  for (const mod of params.sliceChanges.modified) {
222
215
  updateSliceFields(params.milestoneId, mod.sliceId, {
@@ -282,6 +275,14 @@ export async function handleReassessRoadmap(
282
275
  assessment: params.assessment,
283
276
  completedSliceId: params.completedSliceId,
284
277
  });
278
+ insertAssessment({
279
+ path: assessmentDbPathForRenderedFile(basePath, assessmentResult.assessmentPath),
280
+ milestoneId: params.milestoneId,
281
+ sliceId: params.completedSliceId,
282
+ status: params.verdict,
283
+ scope: "roadmap",
284
+ fullContent: params.assessment,
285
+ });
285
286
 
286
287
  // ── Remove stale VALIDATION file from disk (#2957) ────────────
287
288
  const hasStructuralChanges =
@@ -0,0 +1,160 @@
1
+ import { clearParseCache } from "../files.js";
2
+ import {
3
+ getSlice,
4
+ getTask,
5
+ insertReplanHistory,
6
+ transaction,
7
+ upsertTaskPlanning,
8
+ } from "../gsd-db.js";
9
+ import { invalidateStateCache } from "../state.js";
10
+ import { isClosedStatus } from "../status-guards.js";
11
+ import { isNonEmptyString, validateStringArray } from "../validation.js";
12
+ import { renderPlanFromDb, renderTaskPlanFromDb } from "../markdown-renderer.js";
13
+ import { resolveMilestonePath, resolveSlicePath } from "../paths.js";
14
+ import { flushWorkflowProjections } from "../projection-flush.js";
15
+ import { writeManifest } from "../workflow-manifest.js";
16
+ import { appendEvent } from "../workflow-events.js";
17
+ import { logWarning } from "../workflow-logger.js";
18
+
19
+ export interface ReplanTaskParams {
20
+ milestoneId: string;
21
+ sliceId: string;
22
+ taskId: string;
23
+ title: string;
24
+ description: string;
25
+ estimate: string;
26
+ files: string[];
27
+ verify: string;
28
+ inputs: string[];
29
+ expectedOutput: string[];
30
+ reworkBriefRef?: string;
31
+ fullPlanMd?: string;
32
+ actorName?: string;
33
+ triggerReason?: string;
34
+ }
35
+
36
+ export interface ReplanTaskResult {
37
+ milestoneId: string;
38
+ sliceId: string;
39
+ taskId: string;
40
+ taskPlanPath: string;
41
+ }
42
+
43
+ function validateParams(params: ReplanTaskParams): ReplanTaskParams {
44
+ if (!isNonEmptyString(params?.milestoneId)) throw new Error("milestoneId is required");
45
+ if (!isNonEmptyString(params?.sliceId)) throw new Error("sliceId is required");
46
+ if (!isNonEmptyString(params?.taskId)) throw new Error("taskId is required");
47
+ if (!isNonEmptyString(params?.title)) throw new Error("title is required");
48
+ if (!isNonEmptyString(params?.description)) throw new Error("description is required");
49
+ if (!isNonEmptyString(params?.estimate)) throw new Error("estimate is required");
50
+ if (!isNonEmptyString(params?.verify)) throw new Error("verify is required");
51
+ return {
52
+ ...params,
53
+ files: validateStringArray(params.files, "files"),
54
+ inputs: validateStringArray(params.inputs, "inputs"),
55
+ expectedOutput: validateStringArray(params.expectedOutput, "expectedOutput"),
56
+ };
57
+ }
58
+
59
+ function replanSummary(params: ReplanTaskParams): string {
60
+ const ref = params.reworkBriefRef?.trim();
61
+ return ref
62
+ ? `Task ${params.taskId} replanned from rework brief ${ref}`
63
+ : `Task ${params.taskId} replanned`;
64
+ }
65
+
66
+ export async function handleReplanTask(
67
+ rawParams: ReplanTaskParams,
68
+ basePath: string,
69
+ ): Promise<ReplanTaskResult | { error: string }> {
70
+ let params: ReplanTaskParams;
71
+ try {
72
+ params = validateParams(rawParams);
73
+ } catch (err) {
74
+ return { error: `validation failed: ${(err as Error).message}` };
75
+ }
76
+
77
+ let guardError: string | null = null;
78
+ try {
79
+ transaction(() => {
80
+ const parentSlice = getSlice(params.milestoneId, params.sliceId);
81
+ if (!parentSlice) {
82
+ guardError = `missing parent slice: ${params.milestoneId}/${params.sliceId}`;
83
+ return;
84
+ }
85
+ if (isClosedStatus(parentSlice.status)) {
86
+ guardError = `cannot replan a task in a closed slice: ${params.sliceId} (status: ${parentSlice.status})`;
87
+ return;
88
+ }
89
+
90
+ const task = getTask(params.milestoneId, params.sliceId, params.taskId);
91
+ if (!task) {
92
+ guardError = `task not found: ${params.milestoneId}/${params.sliceId}/${params.taskId}`;
93
+ return;
94
+ }
95
+ if (isClosedStatus(task.status)) {
96
+ guardError = `cannot replan completed task ${params.taskId} — use gsd_task_reopen first`;
97
+ return;
98
+ }
99
+
100
+ upsertTaskPlanning(params.milestoneId, params.sliceId, params.taskId, {
101
+ title: params.title,
102
+ description: params.description,
103
+ estimate: params.estimate,
104
+ files: params.files,
105
+ verify: params.verify,
106
+ inputs: params.inputs,
107
+ expectedOutput: params.expectedOutput,
108
+ fullPlanMd: params.fullPlanMd,
109
+ });
110
+ insertReplanHistory({
111
+ milestoneId: params.milestoneId,
112
+ sliceId: params.sliceId,
113
+ taskId: params.taskId,
114
+ summary: replanSummary(params),
115
+ previousArtifactPath: params.reworkBriefRef ?? null,
116
+ });
117
+ });
118
+ } catch (err) {
119
+ return { error: `db write failed: ${(err as Error).message}` };
120
+ }
121
+
122
+ if (guardError) return { error: guardError };
123
+
124
+ try {
125
+ const milestonePath = resolveMilestonePath(basePath, params.milestoneId);
126
+ const slicePath = resolveSlicePath(basePath, params.milestoneId, params.sliceId);
127
+ const isLegacySliceLayout = Boolean(milestonePath && slicePath && slicePath !== milestonePath);
128
+ const renderResult = isLegacySliceLayout
129
+ ? await renderTaskPlanFromDb(basePath, params.milestoneId, params.sliceId, params.taskId)
130
+ : await renderPlanFromDb(basePath, params.milestoneId, params.sliceId);
131
+ const taskPlanPath = "taskPlanPath" in renderResult ? renderResult.taskPlanPath : renderResult.planPath;
132
+
133
+ invalidateStateCache();
134
+ clearParseCache();
135
+
136
+ try {
137
+ await flushWorkflowProjections(basePath, { milestoneId: params.milestoneId });
138
+ writeManifest(basePath);
139
+ appendEvent(basePath, {
140
+ cmd: "replan-task",
141
+ params: { milestoneId: params.milestoneId, sliceId: params.sliceId, taskId: params.taskId },
142
+ ts: new Date().toISOString(),
143
+ actor: "agent",
144
+ actor_name: params.actorName,
145
+ trigger_reason: params.triggerReason,
146
+ });
147
+ } catch (hookErr) {
148
+ logWarning("tool", `replan-task post-mutation hook warning: ${(hookErr as Error).message}`);
149
+ }
150
+
151
+ return {
152
+ milestoneId: params.milestoneId,
153
+ sliceId: params.sliceId,
154
+ taskId: params.taskId,
155
+ taskPlanPath,
156
+ };
157
+ } catch (err) {
158
+ return { error: `render failed: ${(err as Error).message}` };
159
+ }
160
+ }
@@ -0,0 +1,91 @@
1
+ import { saveReworkBrief, type ReworkBriefFindingInput } from "../gsd-db.js";
2
+ import { isNonEmptyString, validateStringArray } from "../validation.js";
3
+
4
+ export interface ReworkBriefSaveParams {
5
+ briefId?: string;
6
+ milestoneId: string;
7
+ sliceId: string;
8
+ taskId: string;
9
+ findings: ReworkBriefFindingInput[];
10
+ }
11
+
12
+ export interface ReworkBriefSaveResult {
13
+ briefId: string;
14
+ milestoneId: string;
15
+ sliceId: string;
16
+ taskId: string;
17
+ findingCount: number;
18
+ }
19
+
20
+ function validateFinding(finding: ReworkBriefFindingInput, index: number): ReworkBriefFindingInput {
21
+ if (!isNonEmptyString(finding?.findingId)) throw new Error(`findings[${index}].findingId is required`);
22
+ if (finding.severity !== "blocking" && finding.severity !== "advisory") {
23
+ throw new Error(`findings[${index}].severity must be blocking or advisory`);
24
+ }
25
+ if (!isNonEmptyString(finding.description)) throw new Error(`findings[${index}].description is required`);
26
+ if (!isNonEmptyString(finding.requiredFix)) throw new Error(`findings[${index}].requiredFix is required`);
27
+
28
+ const status = finding.status ?? "pending";
29
+ if (status !== "pending" && status !== "resolved" && status !== "deferred-with-override") {
30
+ throw new Error(`findings[${index}].status must be pending, resolved, or deferred-with-override`);
31
+ }
32
+
33
+ // A blocking finding is only enforced by gsd_task_complete while it is
34
+ // `pending` (getUnresolvedBlockingReworkFindingsForTask returns pending rows
35
+ // only). Persisting a blocking finding as resolved/deferred-with-override
36
+ // at save time therefore bypasses the completion gate entirely, so require
37
+ // the same justification a reworkResolution would (evidence for `resolved`,
38
+ // evidence + decisionRef for `deferred-with-override`). Advisory findings do
39
+ // not gate completion, so their status is left as-is.
40
+ if (finding.severity === "blocking" && status !== "pending") {
41
+ if (!isNonEmptyString(finding.evidence)) {
42
+ throw new Error(`findings[${index}].evidence is required when a blocking finding is saved as ${status}`);
43
+ }
44
+ if (status === "deferred-with-override" && !isNonEmptyString(finding.decisionRef)) {
45
+ throw new Error(`findings[${index}].decisionRef is required when a blocking finding is saved as deferred-with-override`);
46
+ }
47
+ }
48
+
49
+ return {
50
+ ...finding,
51
+ verificationCommands: validateStringArray(finding.verificationCommands, `findings[${index}].verificationCommands`),
52
+ status,
53
+ };
54
+ }
55
+
56
+ function validateParams(params: ReworkBriefSaveParams): ReworkBriefSaveParams {
57
+ if (!isNonEmptyString(params?.milestoneId)) throw new Error("milestoneId is required");
58
+ if (!isNonEmptyString(params?.sliceId)) throw new Error("sliceId is required");
59
+ if (!isNonEmptyString(params?.taskId)) throw new Error("taskId is required");
60
+ if (!Array.isArray(params.findings) || params.findings.length === 0) {
61
+ throw new Error("findings must be a non-empty array");
62
+ }
63
+ return {
64
+ ...params,
65
+ findings: params.findings.map(validateFinding),
66
+ };
67
+ }
68
+
69
+ export async function handleReworkBriefSave(
70
+ rawParams: ReworkBriefSaveParams,
71
+ ): Promise<ReworkBriefSaveResult | { error: string }> {
72
+ let params: ReworkBriefSaveParams;
73
+ try {
74
+ params = validateParams(rawParams);
75
+ } catch (err) {
76
+ return { error: `validation failed: ${(err as Error).message}` };
77
+ }
78
+
79
+ try {
80
+ const { briefId } = saveReworkBrief(params);
81
+ return {
82
+ briefId,
83
+ milestoneId: params.milestoneId,
84
+ sliceId: params.sliceId,
85
+ taskId: params.taskId,
86
+ findingCount: params.findings.length,
87
+ };
88
+ } catch (err) {
89
+ return { error: `db write failed: ${(err as Error).message}` };
90
+ }
91
+ }