gsd-pi 2.49.0-dev.de3d9f6 → 2.50.0-dev.9476db8

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 (249) hide show
  1. package/dist/headless-ui.js +12 -2
  2. package/dist/headless.js +29 -13
  3. package/dist/resources/extensions/gsd/auto/infra-errors.js +1 -0
  4. package/dist/resources/extensions/gsd/auto/phases.js +11 -11
  5. package/dist/resources/extensions/gsd/auto/resolve.js +2 -2
  6. package/dist/resources/extensions/gsd/auto/run-unit.js +2 -2
  7. package/dist/resources/extensions/gsd/auto/session.js +4 -0
  8. package/dist/resources/extensions/gsd/auto-artifact-paths.js +8 -10
  9. package/dist/resources/extensions/gsd/auto-dashboard.js +6 -3
  10. package/dist/resources/extensions/gsd/auto-dispatch.js +33 -21
  11. package/dist/resources/extensions/gsd/auto-post-unit.js +17 -24
  12. package/dist/resources/extensions/gsd/auto-prompts.js +102 -21
  13. package/dist/resources/extensions/gsd/auto-recovery.js +62 -184
  14. package/dist/resources/extensions/gsd/auto-start.js +4 -31
  15. package/dist/resources/extensions/gsd/auto-timers.js +2 -2
  16. package/dist/resources/extensions/gsd/auto-verification.js +4 -7
  17. package/dist/resources/extensions/gsd/auto-worktree.js +257 -113
  18. package/dist/resources/extensions/gsd/auto.js +7 -5
  19. package/dist/resources/extensions/gsd/bootstrap/db-tools.js +89 -0
  20. package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +8 -1
  21. package/dist/resources/extensions/gsd/branch-patterns.js +13 -0
  22. package/dist/resources/extensions/gsd/doctor-checks.js +5 -1234
  23. package/dist/resources/extensions/gsd/doctor-engine-checks.js +168 -0
  24. package/dist/resources/extensions/gsd/doctor-environment.js +28 -7
  25. package/dist/resources/extensions/gsd/doctor-git-checks.js +405 -0
  26. package/dist/resources/extensions/gsd/doctor-global-checks.js +74 -0
  27. package/dist/resources/extensions/gsd/doctor-runtime-checks.js +600 -0
  28. package/dist/resources/extensions/gsd/doctor.js +9 -1
  29. package/dist/resources/extensions/gsd/extension-manifest.json +1 -1
  30. package/dist/resources/extensions/gsd/git-service.js +9 -10
  31. package/dist/resources/extensions/gsd/gsd-db.js +124 -1
  32. package/dist/resources/extensions/gsd/guided-flow-queue.js +10 -11
  33. package/dist/resources/extensions/gsd/markdown-renderer.js +33 -5
  34. package/dist/resources/extensions/gsd/preferences-types.js +2 -1
  35. package/dist/resources/extensions/gsd/preferences-validation.js +39 -0
  36. package/dist/resources/extensions/gsd/prompts/complete-milestone.md +27 -8
  37. package/dist/resources/extensions/gsd/prompts/complete-slice.md +9 -8
  38. package/dist/resources/extensions/gsd/prompts/execute-task.md +16 -13
  39. package/dist/resources/extensions/gsd/prompts/forensics.md +12 -5
  40. package/dist/resources/extensions/gsd/prompts/gate-evaluate.md +32 -0
  41. package/dist/resources/extensions/gsd/prompts/guided-complete-slice.md +1 -1
  42. package/dist/resources/extensions/gsd/prompts/guided-execute-task.md +1 -1
  43. package/dist/resources/extensions/gsd/prompts/guided-plan-milestone.md +1 -1
  44. package/dist/resources/extensions/gsd/prompts/guided-plan-slice.md +1 -1
  45. package/dist/resources/extensions/gsd/prompts/plan-milestone.md +1 -1
  46. package/dist/resources/extensions/gsd/prompts/plan-slice.md +8 -3
  47. package/dist/resources/extensions/gsd/prompts/reassess-roadmap.md +3 -0
  48. package/dist/resources/extensions/gsd/prompts/replan-slice.md +1 -1
  49. package/dist/resources/extensions/gsd/repo-identity.js +29 -0
  50. package/dist/resources/extensions/gsd/roadmap-slices.js +2 -2
  51. package/dist/resources/extensions/gsd/session-forensics.js +6 -11
  52. package/dist/resources/extensions/gsd/session-lock.js +67 -56
  53. package/dist/resources/extensions/gsd/state.js +34 -7
  54. package/dist/resources/extensions/gsd/templates/milestone-summary.md +8 -0
  55. package/dist/resources/extensions/gsd/templates/plan.md +16 -0
  56. package/dist/resources/extensions/gsd/templates/roadmap.md +13 -0
  57. package/dist/resources/extensions/gsd/templates/slice-summary.md +9 -0
  58. package/dist/resources/extensions/gsd/templates/task-plan.md +24 -0
  59. package/dist/resources/extensions/gsd/tools/plan-slice.js +14 -1
  60. package/dist/resources/extensions/gsd/tools/validate-milestone.js +3 -3
  61. package/dist/resources/extensions/gsd/verdict-parser.js +84 -0
  62. package/dist/resources/extensions/gsd/worktree-resolver.js +24 -0
  63. package/dist/resources/extensions/gsd/worktree.js +3 -2
  64. package/dist/resources/extensions/remote-questions/config.js +3 -5
  65. package/dist/resources/extensions/search-the-web/native-search.js +8 -3
  66. package/dist/resources/extensions/search-the-web/tool-search.js +19 -2
  67. package/dist/resources/skills/github-workflows/references/gh/SKILL.md +22 -1
  68. package/dist/web/standalone/.next/BUILD_ID +1 -1
  69. package/dist/web/standalone/.next/app-path-routes-manifest.json +15 -15
  70. package/dist/web/standalone/.next/build-manifest.json +3 -3
  71. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  72. package/dist/web/standalone/.next/react-loadable-manifest.json +1 -1
  73. package/dist/web/standalone/.next/required-server-files.json +1 -1
  74. package/dist/web/standalone/.next/server/app/_global-error.html +2 -2
  75. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  76. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  77. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  78. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  79. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  80. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  81. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  82. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  83. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  84. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  85. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  86. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  87. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  88. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  89. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  90. package/dist/web/standalone/.next/server/app/index.html +1 -1
  91. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  92. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  93. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  94. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  95. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  96. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  97. package/dist/web/standalone/.next/server/app-paths-manifest.json +15 -15
  98. package/dist/web/standalone/.next/server/chunks/229.js +2 -2
  99. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  100. package/dist/web/standalone/.next/server/middleware-react-loadable-manifest.js +1 -1
  101. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  102. package/dist/web/standalone/.next/server/pages/500.html +2 -2
  103. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  104. package/dist/web/standalone/.next/static/chunks/4024.7c75ac378de0f2b5.js +9 -0
  105. package/dist/web/standalone/.next/static/chunks/{webpack-0a4cd455ec4197d2.js → webpack-2473ce2c3879fff4.js} +1 -1
  106. package/dist/web/standalone/server.js +1 -1
  107. package/package.json +1 -1
  108. package/packages/pi-agent-core/dist/agent-loop.d.ts.map +1 -1
  109. package/packages/pi-agent-core/dist/agent-loop.js +4 -1
  110. package/packages/pi-agent-core/dist/agent-loop.js.map +1 -1
  111. package/packages/pi-agent-core/src/agent-loop.ts +4 -1
  112. package/packages/pi-ai/dist/providers/openai-codex-responses.js +39 -10
  113. package/packages/pi-ai/dist/providers/openai-codex-responses.js.map +1 -1
  114. package/packages/pi-ai/src/providers/openai-codex-responses.ts +39 -8
  115. package/packages/pi-coding-agent/dist/core/blob-store.d.ts.map +1 -1
  116. package/packages/pi-coding-agent/dist/core/blob-store.js +8 -3
  117. package/packages/pi-coding-agent/dist/core/blob-store.js.map +1 -1
  118. package/packages/pi-coding-agent/dist/core/discovery-cache.d.ts.map +1 -1
  119. package/packages/pi-coding-agent/dist/core/discovery-cache.js +9 -2
  120. package/packages/pi-coding-agent/dist/core/discovery-cache.js.map +1 -1
  121. package/packages/pi-coding-agent/dist/core/retry-handler.js +1 -1
  122. package/packages/pi-coding-agent/dist/core/retry-handler.js.map +1 -1
  123. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  124. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js +7 -32
  125. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js.map +1 -1
  126. package/packages/pi-coding-agent/dist/modes/rpc/jsonl.d.ts.map +1 -1
  127. package/packages/pi-coding-agent/dist/modes/rpc/jsonl.js +5 -0
  128. package/packages/pi-coding-agent/dist/modes/rpc/jsonl.js.map +1 -1
  129. package/packages/pi-coding-agent/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  130. package/packages/pi-coding-agent/dist/modes/rpc/rpc-client.js +0 -1
  131. package/packages/pi-coding-agent/dist/modes/rpc/rpc-client.js.map +1 -1
  132. package/packages/pi-coding-agent/dist/modes/rpc/rpc-mode.js +1 -1
  133. package/packages/pi-coding-agent/dist/modes/rpc/rpc-mode.js.map +1 -1
  134. package/packages/pi-coding-agent/package.json +1 -1
  135. package/packages/pi-coding-agent/src/core/blob-store.ts +6 -3
  136. package/packages/pi-coding-agent/src/core/discovery-cache.ts +9 -2
  137. package/packages/pi-coding-agent/src/core/retry-handler.ts +1 -1
  138. package/packages/pi-coding-agent/src/modes/interactive/interactive-mode.ts +7 -32
  139. package/packages/pi-coding-agent/src/modes/rpc/jsonl.ts +6 -0
  140. package/packages/pi-coding-agent/src/modes/rpc/rpc-client.ts +0 -2
  141. package/packages/pi-coding-agent/src/modes/rpc/rpc-mode.ts +2 -2
  142. package/pkg/package.json +1 -1
  143. package/src/resources/extensions/gsd/auto/infra-errors.ts +1 -0
  144. package/src/resources/extensions/gsd/auto/phases.ts +10 -11
  145. package/src/resources/extensions/gsd/auto/resolve.ts +3 -3
  146. package/src/resources/extensions/gsd/auto/run-unit.ts +2 -2
  147. package/src/resources/extensions/gsd/auto/session.ts +5 -0
  148. package/src/resources/extensions/gsd/auto/types.ts +13 -0
  149. package/src/resources/extensions/gsd/auto-artifact-paths.ts +19 -21
  150. package/src/resources/extensions/gsd/auto-dashboard.ts +5 -2
  151. package/src/resources/extensions/gsd/auto-dispatch.ts +39 -21
  152. package/src/resources/extensions/gsd/auto-loop.ts +1 -1
  153. package/src/resources/extensions/gsd/auto-post-unit.ts +18 -28
  154. package/src/resources/extensions/gsd/auto-prompts.ts +113 -19
  155. package/src/resources/extensions/gsd/auto-recovery.ts +65 -199
  156. package/src/resources/extensions/gsd/auto-start.ts +7 -27
  157. package/src/resources/extensions/gsd/auto-timers.ts +2 -2
  158. package/src/resources/extensions/gsd/auto-verification.ts +4 -7
  159. package/src/resources/extensions/gsd/auto-worktree.ts +305 -108
  160. package/src/resources/extensions/gsd/auto.ts +11 -10
  161. package/src/resources/extensions/gsd/bootstrap/db-tools.ts +93 -0
  162. package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +8 -0
  163. package/src/resources/extensions/gsd/branch-patterns.ts +16 -0
  164. package/src/resources/extensions/gsd/doctor-checks.ts +5 -1291
  165. package/src/resources/extensions/gsd/doctor-engine-checks.ts +182 -0
  166. package/src/resources/extensions/gsd/doctor-environment.ts +30 -7
  167. package/src/resources/extensions/gsd/doctor-git-checks.ts +415 -0
  168. package/src/resources/extensions/gsd/doctor-global-checks.ts +84 -0
  169. package/src/resources/extensions/gsd/doctor-runtime-checks.ts +626 -0
  170. package/src/resources/extensions/gsd/doctor.ts +9 -1
  171. package/src/resources/extensions/gsd/extension-manifest.json +1 -1
  172. package/src/resources/extensions/gsd/git-service.ts +7 -15
  173. package/src/resources/extensions/gsd/gsd-db.ts +150 -2
  174. package/src/resources/extensions/gsd/guided-flow-queue.ts +11 -12
  175. package/src/resources/extensions/gsd/markdown-renderer.ts +37 -4
  176. package/src/resources/extensions/gsd/preferences-types.ts +5 -1
  177. package/src/resources/extensions/gsd/preferences-validation.ts +37 -0
  178. package/src/resources/extensions/gsd/prompts/complete-milestone.md +27 -8
  179. package/src/resources/extensions/gsd/prompts/complete-slice.md +9 -8
  180. package/src/resources/extensions/gsd/prompts/execute-task.md +16 -13
  181. package/src/resources/extensions/gsd/prompts/forensics.md +12 -5
  182. package/src/resources/extensions/gsd/prompts/gate-evaluate.md +32 -0
  183. package/src/resources/extensions/gsd/prompts/guided-complete-slice.md +1 -1
  184. package/src/resources/extensions/gsd/prompts/guided-execute-task.md +1 -1
  185. package/src/resources/extensions/gsd/prompts/guided-plan-milestone.md +1 -1
  186. package/src/resources/extensions/gsd/prompts/guided-plan-slice.md +1 -1
  187. package/src/resources/extensions/gsd/prompts/plan-milestone.md +1 -1
  188. package/src/resources/extensions/gsd/prompts/plan-slice.md +8 -3
  189. package/src/resources/extensions/gsd/prompts/reassess-roadmap.md +3 -0
  190. package/src/resources/extensions/gsd/prompts/replan-slice.md +1 -1
  191. package/src/resources/extensions/gsd/repo-identity.ts +28 -0
  192. package/src/resources/extensions/gsd/roadmap-slices.ts +2 -2
  193. package/src/resources/extensions/gsd/session-forensics.ts +6 -11
  194. package/src/resources/extensions/gsd/session-lock.ts +92 -64
  195. package/src/resources/extensions/gsd/state.ts +38 -5
  196. package/src/resources/extensions/gsd/templates/milestone-summary.md +8 -0
  197. package/src/resources/extensions/gsd/templates/plan.md +16 -0
  198. package/src/resources/extensions/gsd/templates/roadmap.md +13 -0
  199. package/src/resources/extensions/gsd/templates/slice-summary.md +9 -0
  200. package/src/resources/extensions/gsd/templates/task-plan.md +24 -0
  201. package/src/resources/extensions/gsd/tests/agent-end-retry.test.ts +2 -2
  202. package/src/resources/extensions/gsd/tests/auto-loop.test.ts +35 -0
  203. package/src/resources/extensions/gsd/tests/auto-recovery.test.ts +1 -81
  204. package/src/resources/extensions/gsd/tests/complete-slice.test.ts +2 -2
  205. package/src/resources/extensions/gsd/tests/complete-task.test.ts +2 -2
  206. package/src/resources/extensions/gsd/tests/completed-units-metrics-sync.test.ts +9 -12
  207. package/src/resources/extensions/gsd/tests/doctor-environment.test.ts +115 -1
  208. package/src/resources/extensions/gsd/tests/doctor-fixlevel.test.ts +65 -1
  209. package/src/resources/extensions/gsd/tests/doctor-git.test.ts +50 -0
  210. package/src/resources/extensions/gsd/tests/gate-dispatch.test.ts +189 -0
  211. package/src/resources/extensions/gsd/tests/gate-storage.test.ts +156 -0
  212. package/src/resources/extensions/gsd/tests/git-service.test.ts +49 -0
  213. package/src/resources/extensions/gsd/tests/gsd-db.test.ts +1 -1
  214. package/src/resources/extensions/gsd/tests/infra-error.test.ts +12 -2
  215. package/src/resources/extensions/gsd/tests/journal-integration.test.ts +39 -0
  216. package/src/resources/extensions/gsd/tests/md-importer.test.ts +1 -1
  217. package/src/resources/extensions/gsd/tests/memory-store.test.ts +2 -2
  218. package/src/resources/extensions/gsd/tests/quality-gates.test.ts +347 -0
  219. package/src/resources/extensions/gsd/tests/queue-completed-milestone-perf.test.ts +155 -0
  220. package/src/resources/extensions/gsd/tests/replan-slice.test.ts +2 -1
  221. package/src/resources/extensions/gsd/tests/repo-identity-worktree.test.ts +32 -0
  222. package/src/resources/extensions/gsd/tests/roadmap-slices.test.ts +26 -0
  223. package/src/resources/extensions/gsd/tests/run-uat.test.ts +20 -16
  224. package/src/resources/extensions/gsd/tests/session-lock-transient-read.test.ts +223 -0
  225. package/src/resources/extensions/gsd/tests/skill-activation.test.ts +44 -4
  226. package/src/resources/extensions/gsd/tests/tool-naming.test.ts +1 -1
  227. package/src/resources/extensions/gsd/tests/validate-milestone.test.ts +2 -1
  228. package/src/resources/extensions/gsd/tests/verification-gate.test.ts +0 -16
  229. package/src/resources/extensions/gsd/tests/worktree-resolver.test.ts +67 -0
  230. package/src/resources/extensions/gsd/tests/worktree-sync-milestones.test.ts +1 -1
  231. package/src/resources/extensions/gsd/tests/worktree-sync-overwrite-loop.test.ts +204 -0
  232. package/src/resources/extensions/gsd/tools/plan-slice.ts +16 -0
  233. package/src/resources/extensions/gsd/tools/validate-milestone.ts +3 -3
  234. package/src/resources/extensions/gsd/types.ts +30 -0
  235. package/src/resources/extensions/gsd/verdict-parser.ts +95 -0
  236. package/src/resources/extensions/gsd/verification-gate.ts +0 -2
  237. package/src/resources/extensions/gsd/worktree-resolver.ts +31 -0
  238. package/src/resources/extensions/gsd/worktree.ts +3 -2
  239. package/src/resources/extensions/remote-questions/config.ts +3 -5
  240. package/src/resources/extensions/search-the-web/native-search.ts +8 -3
  241. package/src/resources/extensions/search-the-web/tool-search.ts +22 -2
  242. package/src/resources/skills/github-workflows/references/gh/SKILL.md +22 -1
  243. package/dist/resources/extensions/gsd/auto-worktree-sync.js +0 -191
  244. package/dist/resources/extensions/gsd/resource-version.js +0 -97
  245. package/dist/web/standalone/.next/static/chunks/4024.11ca5c01938e5948.js +0 -9
  246. package/src/resources/extensions/gsd/auto-worktree-sync.ts +0 -234
  247. package/src/resources/extensions/gsd/resource-version.ts +0 -101
  248. /package/dist/web/standalone/.next/static/{ceckLbAMjhzHaQ3RPtJnT → MkE9kzqUGny3-cSE0GNnm}/_buildManifest.js +0 -0
  249. /package/dist/web/standalone/.next/static/{ceckLbAMjhzHaQ3RPtJnT → MkE9kzqUGny3-cSE0GNnm}/_ssgManifest.js +0 -0
@@ -0,0 +1,32 @@
1
+ # Quality Gate Evaluation — Parallel Dispatch
2
+
3
+ **Working directory:** `{{workingDirectory}}`
4
+ **Milestone:** {{milestoneId}} — {{milestoneTitle}}
5
+ **Slice:** {{sliceId}} — {{sliceTitle}}
6
+
7
+ ## Mission
8
+
9
+ You are evaluating **quality gates in parallel** for this slice. Each gate is an independent question that must be answered before task execution begins. Use the `subagent` tool to dispatch all gate evaluations simultaneously.
10
+
11
+ ## Slice Plan Context
12
+
13
+ {{slicePlanContent}}
14
+
15
+ ## Gates to Evaluate
16
+
17
+ {{gateCount}} gates require evaluation:
18
+
19
+ {{gateList}}
20
+
21
+ ## Execution Protocol
22
+
23
+ 1. **Dispatch all gates** using `subagent` in parallel mode. Each subagent prompt is provided below.
24
+ 2. **Wait for all subagents** to complete.
25
+ 3. **Verify each gate wrote its result** by checking that `gsd_save_gate_result` was called for each gate ID.
26
+ 4. **Report the batch outcome** — which gates passed, which flagged concerns, and which were omitted as not applicable.
27
+
28
+ Gate agents may return `verdict: "omitted"` if the gate question is not applicable to this slice (e.g., no auth surface for Q3, no existing requirements touched for Q4). This is expected for simple slices.
29
+
30
+ ## Subagent Prompts
31
+
32
+ {{subagentPrompts}}
@@ -1,3 +1,3 @@
1
- Complete slice {{sliceId}} ("{{sliceTitle}}") of milestone {{milestoneId}}. Your working directory is `{{workingDirectory}}` — all file operations must use this path. All tasks are done. Your slice summary is the primary record of what was built — downstream agents (reassess-roadmap, future slice researchers) read it to understand what this slice delivered and what to watch out for. Use the **Slice Summary** and **UAT** output templates below to understand the expected structure. {{skillActivation}} Call `gsd_slice_complete` to record completion — the tool writes `{{sliceId}}-SUMMARY.md`, `{{sliceId}}-UAT.md`, and toggles the roadmap checkbox atomically. Fill the `UAT Type` plus `Not Proven By This UAT` sections explicitly in `uatContent` so the artifact states what class of acceptance it covers and what still remains unproven. Review task summaries for `key_decisions` and ensure any significant ones are in `.gsd/DECISIONS.md`. Do not commit or merge manually — the system handles this after the unit completes.
1
+ Complete slice {{sliceId}} ("{{sliceTitle}}") of milestone {{milestoneId}}. Your working directory is `{{workingDirectory}}` — all file operations must use this path. All tasks are done. Your slice summary is the primary record of what was built — downstream agents (reassess-roadmap, future slice researchers) read it to understand what this slice delivered and what to watch out for. Use the **Slice Summary** and **UAT** output templates below to understand the expected structure. {{skillActivation}} Call `gsd_slice_complete` to record completion — the tool writes `{{sliceId}}-SUMMARY.md`, `{{sliceId}}-UAT.md`, and toggles the roadmap checkbox atomically. Fill the `UAT Type` plus `Not Proven By This UAT` sections explicitly in `uatContent` so the artifact states what class of acceptance it covers and what still remains unproven. Review task summaries for `key_decisions` and ensure any significant ones are in `.gsd/DECISIONS.md`. If the slice involved runtime behavior, fill the Operational Readiness section (Q8) in the summary: health signal, failure signal, recovery procedure, and monitoring gaps. Omit for simple slices. Do not commit or merge manually — the system handles this after the unit completes.
2
2
 
3
3
  {{inlinedTemplates}}
@@ -1,3 +1,3 @@
1
- Execute the next task: {{taskId}} ("{{taskTitle}}") in slice {{sliceId}} of milestone {{milestoneId}}. Read the task plan (`{{taskId}}-PLAN.md`), load relevant summaries from prior tasks, and execute each step. Verify must-haves when done. If the task touches UI, browser flows, DOM behavior, or user-visible web state, exercise the real flow in the browser, prefer `browser_batch` for obvious sequences, prefer `browser_assert` for explicit pass/fail verification, use `browser_diff` when an action's effect is ambiguous, and use browser diagnostics when validating async or failure-prone UI. If you made an architectural, pattern, or library decision, append it to `.gsd/DECISIONS.md`. Use the **Task Summary** output template below. Call `gsd_task_complete` to record completion (it writes the summary, toggles the checkbox, and persists to DB atomically). {{skillActivation}} If running long and not all steps are finished, stop implementing and prioritize writing a clean partial summary over attempting one more step — a recoverable handoff is more valuable than a half-finished step with no documentation. If verification fails, debug methodically: form a hypothesis and test that specific theory before changing anything, change one variable at a time, read entire functions not just the suspect line, distinguish observable facts from assumptions, and if 3+ fixes fail without progress stop and reassess your mental model — list what you know for certain, what you've ruled out, and form fresh hypotheses. Don't fix symptoms — understand why something fails before changing code.
1
+ Execute the next task: {{taskId}} ("{{taskTitle}}") in slice {{sliceId}} of milestone {{milestoneId}}. Read the task plan (`{{taskId}}-PLAN.md`), load relevant summaries from prior tasks, and execute each step. Verify must-haves when done. If the task touches UI, browser flows, DOM behavior, or user-visible web state, exercise the real flow in the browser, prefer `browser_batch` for obvious sequences, prefer `browser_assert` for explicit pass/fail verification, use `browser_diff` when an action's effect is ambiguous, and use browser diagnostics when validating async or failure-prone UI. If you made an architectural, pattern, or library decision, append it to `.gsd/DECISIONS.md`. Use the **Task Summary** output template below. Call `gsd_task_complete` to record completion (it writes the summary, toggles the checkbox, and persists to DB atomically). {{skillActivation}} If running long and not all steps are finished, stop implementing and prioritize writing a clean partial summary over attempting one more step — a recoverable handoff is more valuable than a half-finished step with no documentation. If verification fails, debug methodically: form a hypothesis and test that specific theory before changing anything, change one variable at a time, read entire functions not just the suspect line, distinguish observable facts from assumptions, and if 3+ fixes fail without progress stop and reassess your mental model — list what you know for certain, what you've ruled out, and form fresh hypotheses. Don't fix symptoms — understand why something fails before changing code. If the task plan includes Failure Modes, Load Profile, or Negative Tests sections, implement and verify them: handle each dependency's error/timeout/malformed paths (Q5), protect against identified 10x breakpoints (Q6), and write specified negative test cases (Q7).
2
2
 
3
3
  {{inlinedTemplates}}
@@ -1,4 +1,4 @@
1
- Plan milestone {{milestoneId}} ("{{milestoneTitle}}"). Read `.gsd/DECISIONS.md` if it exists — respect existing decisions. Read `.gsd/REQUIREMENTS.md` if it exists and treat Active requirements as the capability contract. If `REQUIREMENTS.md` is missing, continue in legacy compatibility mode but explicitly note missing requirement coverage. Use the **Roadmap** output template below to shape the milestone planning payload you send to `gsd_plan_milestone`. Call `gsd_plan_milestone` to persist the milestone planning fields and render `{{milestoneId}}-ROADMAP.md` from DB state. Do **not** write `{{milestoneId}}-ROADMAP.md`, `ROADMAP.md`, or other planning artifacts manually. If planning produces structural decisions, append them to `.gsd/DECISIONS.md`. {{skillActivation}}
1
+ Plan milestone {{milestoneId}} ("{{milestoneTitle}}"). Read `.gsd/DECISIONS.md` if it exists — respect existing decisions. Read `.gsd/REQUIREMENTS.md` if it exists and treat Active requirements as the capability contract. If `REQUIREMENTS.md` is missing, continue in legacy compatibility mode but explicitly note missing requirement coverage. Use the **Roadmap** output template below to shape the milestone planning payload you send to `gsd_plan_milestone`. Call `gsd_plan_milestone` to persist the milestone planning fields and render `{{milestoneId}}-ROADMAP.md` from DB state. Do **not** write `{{milestoneId}}-ROADMAP.md`, `ROADMAP.md`, or other planning artifacts manually. If planning produces structural decisions, append them to `.gsd/DECISIONS.md`. {{skillActivation}} Fill the Horizontal Checklist section with cross-cutting concerns considered during planning (requirements re-read, decisions re-evaluated, graceful shutdown, revenue paths, auth boundary, shared resources, reconnection). Omit for trivial milestones.
2
2
 
3
3
  ## Requirement Rules
4
4
 
@@ -1,3 +1,3 @@
1
- Plan slice {{sliceId}} ("{{sliceTitle}}") of milestone {{milestoneId}}. Read `.gsd/DECISIONS.md` if it exists — respect existing decisions. Read `.gsd/REQUIREMENTS.md` if it exists — identify which Active requirements the roadmap says this slice owns or supports, and ensure the plan delivers them. Read the roadmap boundary map, any existing context/research files, and dependency summaries. Use the **Slice Plan** and **Task Plan** output templates below. Decompose into tasks with must-haves. Fill the `Proof Level` and `Integration Closure` sections truthfully so the plan says what class of proof this slice really delivers and what end-to-end wiring still remains. Call `gsd_plan_slice` to persist the slice plan — the tool writes `{{sliceId}}-PLAN.md` and individual `T##-PLAN.md` files to disk and persists to DB. Do **not** write plan files manually — use the DB-backed tool so state stays consistent. If planning produces structural decisions, call `gsd_decision_save` for each — the tool auto-assigns IDs and regenerates `.gsd/DECISIONS.md` automatically. {{skillActivation}} Before finishing, self-audit the plan: every must-have maps to at least one task, every task has complete sections (steps, must-haves, verification, observability impact, inputs, and expected output), task ordering is consistent with no circular references, every pair of artifacts that must connect has an explicit wiring step, task scope targets 2–5 steps and 3–8 files (6–8 steps or 8–10 files — consider splitting; 10+ steps or 12+ files — must split), the plan honors locked decisions from context/research/decisions artifacts, the proof-level wording does not overclaim live integration if only fixture/contract proof is planned, every Active requirement this slice owns has at least one task with verification that proves it is met, and every task produces real user-facing progress — if the slice has a UI surface at least one task builds the real UI, if it has an API at least one task connects it to a real data source, and showing the completed result to a non-technical stakeholder would demonstrate real product progress rather than developer artifacts.
1
+ Plan slice {{sliceId}} ("{{sliceTitle}}") of milestone {{milestoneId}}. Read `.gsd/DECISIONS.md` if it exists — respect existing decisions. Read `.gsd/REQUIREMENTS.md` if it exists — identify which Active requirements the roadmap says this slice owns or supports, and ensure the plan delivers them. Read the roadmap boundary map, any existing context/research files, and dependency summaries. Use the **Slice Plan** and **Task Plan** output templates below. Decompose into tasks with must-haves. Fill the `Proof Level` and `Integration Closure` sections truthfully so the plan says what class of proof this slice really delivers and what end-to-end wiring still remains. Call `gsd_plan_slice` to persist the slice plan — the tool writes `{{sliceId}}-PLAN.md` and individual `T##-PLAN.md` files to disk and persists to DB. Do **not** write plan files manually — use the DB-backed tool so state stays consistent. If planning produces structural decisions, call `gsd_decision_save` for each — the tool auto-assigns IDs and regenerates `.gsd/DECISIONS.md` automatically. {{skillActivation}} Before finishing, self-audit the plan: every must-have maps to at least one task, every task has complete sections (steps, must-haves, verification, observability impact, inputs, and expected output), task ordering is consistent with no circular references, every pair of artifacts that must connect has an explicit wiring step, task scope targets 2–5 steps and 3–8 files (6–8 steps or 8–10 files — consider splitting; 10+ steps or 12+ files — must split), the plan honors locked decisions from context/research/decisions artifacts, the proof-level wording does not overclaim live integration if only fixture/contract proof is planned, every Active requirement this slice owns has at least one task with verification that proves it is met, and every task produces real user-facing progress — if the slice has a UI surface at least one task builds the real UI, if it has an API at least one task connects it to a real data source, and showing the completed result to a non-technical stakeholder would demonstrate real product progress rather than developer artifacts, and quality gate coverage — for non-trivial slices, Threat Surface (Q3: abuse, data exposure, input trust) and Requirement Impact (Q4: requirements touched, re-verify, decisions revisited) sections are present. For non-trivial tasks, Failure Modes (Q5), Load Profile (Q6), and Negative Tests (Q7) are filled in task plans.
2
2
 
3
3
  {{inlinedTemplates}}
@@ -47,7 +47,7 @@ Then:
47
47
  2. {{skillActivation}}
48
48
  3. Create the roadmap: decompose into demoable vertical slices — as many as the work genuinely needs, no more. A simple feature might be 1 slice. Don't decompose for decomposition's sake.
49
49
  4. Order by risk (high-risk first)
50
- 5. Call `gsd_plan_milestone` to persist the milestone planning fields and slice rows in the DB-backed planning path. Do **not** write `{{outputPath}}`, `ROADMAP.md`, or other planning artifacts manually — the planning tool owns roadmap rendering and persistence.
50
+ 5. Call `gsd_plan_milestone` to persist the milestone planning fields, slice rows, and **horizontal checklist** in the DB-backed planning path. Do **not** write `{{outputPath}}`, `ROADMAP.md`, or other planning artifacts manually — the planning tool owns roadmap rendering and persistence.
51
51
  6. If planning produced structural decisions (e.g. slice ordering rationale, technology choices, scope exclusions), call `gsd_decision_save` for each decision — the tool auto-assigns IDs and regenerates `.gsd/DECISIONS.md` automatically.
52
52
 
53
53
  ## Requirement Mapping Rules
@@ -57,14 +57,18 @@ Then:
57
57
  - Include `Observability / Diagnostics` for backend, integration, async, stateful, or UI slices where failure diagnosis matters.
58
58
  - Fill `Proof Level` and `Integration Closure` when the slice crosses runtime boundaries or has meaningful integration concerns.
59
59
  - **Omit these sections entirely for simple slices** where they would all be "none" or trivially obvious.
60
- 5. Decompose the slice into tasks, each fitting one context window. Each task needs:
60
+ 5. **Quality gates** for non-trivial slices, fill the Threat Surface (Q3) and Requirement Impact (Q4) sections in the slice plan:
61
+ - **Threat Surface:** Identify abuse scenarios, data exposure risks, and input trust boundaries. Required when the slice handles user input, authentication, authorization, or sensitive data. Omit entirely for internal refactoring or simple changes.
62
+ - **Requirement Impact:** List which existing requirements this slice touches, what must be re-verified after shipping, and which prior decisions should be reconsidered. Omit entirely if no existing requirements are affected.
63
+ - For each task in a non-trivial slice, fill Failure Modes (Q5), Load Profile (Q6), and Negative Tests (Q7) in the task plan when the task has external dependencies, shared resources, or non-trivial input handling. Omit for simple tasks.
64
+ 6. Decompose the slice into tasks, each fitting one context window. Each task needs:
61
65
  - a concrete, action-oriented title
62
66
  - the inline task entry fields defined in the plan.md template (Why / Files / Do / Verify / Done when)
63
67
  - a matching task plan file with description, steps, must-haves, verification, inputs, and expected output
64
68
  - **Inputs and Expected Output must list concrete backtick-wrapped file paths** (e.g. `` `src/types.ts` ``). These are machine-parsed to derive task dependencies — vague prose without paths breaks parallel execution. Every task must have at least one output file path.
65
69
  - Observability Impact section **only if the task touches runtime boundaries, async flows, or error paths** — omit it otherwise
66
- 6. **Persist planning state through `gsd_plan_slice`.** Call it with the full slice planning payload (goal, demo, must-haves, verification, tasks, and metadata). The tool inserts all tasks in the same transaction, writes to the DB, and renders `{{outputPath}}` and `{{slicePath}}/tasks/T##-PLAN.md` files automatically. Do **not** call `gsd_plan_task` separately — `gsd_plan_slice` handles task persistence. Do **not** rely on direct `PLAN.md` writes as the source of truth; the DB-backed tool is the canonical write path for slice and task planning state.
67
- 7. **Self-audit the plan.** Walk through each check — if any fail, fix the plan files before moving on:
70
+ 7. **Persist planning state through `gsd_plan_slice`.** Call it with the full slice planning payload (goal, demo, must-haves, verification, tasks, and metadata). The tool inserts all tasks in the same transaction, writes to the DB, and renders `{{outputPath}}` and `{{slicePath}}/tasks/T##-PLAN.md` files automatically. Do **not** call `gsd_plan_task` separately — `gsd_plan_slice` handles task persistence. Do **not** rely on direct `PLAN.md` writes as the source of truth; the DB-backed tool is the canonical write path for slice and task planning state.
71
+ 8. **Self-audit the plan.** Walk through each check — if any fail, fix the plan files before moving on:
68
72
  - **Completion semantics:** If every task were completed exactly as written, the slice goal/demo should actually be true.
69
73
  - **Requirement coverage:** Every must-have in the slice maps to at least one task. No must-have is orphaned. If `REQUIREMENTS.md` exists, every Active requirement this slice owns maps to at least one task.
70
74
  - **Task completeness:** Every task has steps, must-haves, verification, inputs, and expected output — none are blank or vague. Inputs and Expected Output list backtick-wrapped file paths, not prose descriptions.
@@ -72,6 +76,7 @@ Then:
72
76
  - **Key links planned:** For every pair of artifacts that must connect, there is an explicit step that wires them.
73
77
  - **Scope sanity:** Target 2–5 steps and 3–8 files per task. 10+ steps or 12+ files — must split. Each task must be completable in a single fresh context window.
74
78
  - **Feature completeness:** Every task produces real, user-facing progress — not just internal scaffolding.
79
+ - **Quality gate coverage:** For non-trivial slices, Threat Surface and Requirement Impact sections are present and specific (not placeholder text). For non-trivial tasks, Failure Modes, Load Profile, and Negative Tests are addressed in the task plan.
75
80
  10. If planning produced structural decisions, append them to `.gsd/DECISIONS.md`
76
81
  11. {{commitInstruction}}
77
82
 
@@ -36,6 +36,9 @@ Ask yourself:
36
36
  - Did assumptions in remaining slice descriptions turn out wrong?
37
37
  - If `.gsd/REQUIREMENTS.md` exists: did this slice validate, invalidate, defer, block, or newly surface requirements?
38
38
  - If `.gsd/REQUIREMENTS.md` exists: does the remaining roadmap still provide credible coverage for Active requirements, including launchability, primary user loop, continuity, and failure visibility where relevant?
39
+ - Are the Threat Surface and Requirement Impact sections in completed slice plans still accurate for remaining slices?
40
+ - Did this slice's Operational Readiness reveal monitoring gaps that remaining slices should address?
41
+ - Should any Horizontal Checklist items be updated based on what was actually built?
39
42
 
40
43
  ### Success-Criterion Coverage Check
41
44
 
@@ -32,7 +32,7 @@ Consider these captures when rewriting the remaining tasks — they represent th
32
32
 
33
33
  1. Read the blocker task summary carefully. Understand exactly what was discovered and why it blocks the current plan.
34
34
  2. Analyze the remaining `[ ]` tasks in the slice plan. Determine which are still valid, which need modification, and which should be replaced.
35
- 3. **Persist replan state through `gsd_replan_slice`.** Call it with: `milestoneId`, `sliceId`, `blockerTaskId`, `blockerDescription`, `whatChanged`, `updatedTasks` (array of task objects with taskId, title, description, estimate, files, verify, inputs, expectedOutput), `removedTaskIds` (array of task ID strings). The tool structurally enforces preservation of completed tasks, writes replan history to the DB, re-renders `{{planPath}}`, and renders `{{replanPath}}`.
35
+ 3. **Persist replan state through `gsd_replan_slice`.** Call it with: `milestoneId`, `sliceId`, `blockerTaskId`, `blockerDescription`, `whatChanged`, `updatedTasks` (array of task objects with taskId, title, description, estimate, files, verify, inputs, expectedOutput), `removedTaskIds` (array of task ID strings). The tool structurally enforces preservation of completed tasks, writes replan history to the DB, re-renders `{{planPath}}`, and renders `{{replanPath}}`. Preserve or update the Threat Surface and Requirement Impact sections if the replan changes the slice's security posture or requirement coverage.
36
36
  4. If any incomplete task had a `T0x-PLAN.md`, remove or rewrite it to match the new task description.
37
37
  5. Do not commit manually — the system auto-commits your changes after this unit completes.
38
38
 
@@ -349,6 +349,35 @@ export function ensureGsdSymlink(projectPath) {
349
349
  if (localGsdNormalized === gsdHomePath) {
350
350
  return localGsd;
351
351
  }
352
+ // Guard: If projectPath is a plain subdirectory (not a worktree) of a git
353
+ // repo that already has a .gsd at the git root, do not create a duplicate
354
+ // symlink in the subdirectory — that causes `.gsd 2` collision variants on
355
+ // macOS (#2380). Worktrees are excluded because they legitimately need their
356
+ // own .gsd symlink pointing at the shared external state dir.
357
+ if (!inWorktree) {
358
+ try {
359
+ const gitRoot = resolveGitRoot(projectPath);
360
+ const normalizedProject = canonicalizeExistingPath(projectPath);
361
+ const normalizedRoot = canonicalizeExistingPath(gitRoot);
362
+ if (normalizedProject !== normalizedRoot) {
363
+ const rootGsd = join(gitRoot, ".gsd");
364
+ if (existsSync(rootGsd)) {
365
+ try {
366
+ const rootStat = lstatSync(rootGsd);
367
+ if (rootStat.isSymbolicLink() || rootStat.isDirectory()) {
368
+ return rootStat.isSymbolicLink() ? realpathSync(rootGsd) : rootGsd;
369
+ }
370
+ }
371
+ catch {
372
+ // Fall through to normal logic if we can't stat root .gsd
373
+ }
374
+ }
375
+ }
376
+ }
377
+ catch {
378
+ // If git root detection fails, fall through to normal logic
379
+ }
380
+ }
352
381
  // Clean up macOS numbered collision variants (.gsd 2, .gsd 3, etc.) before
353
382
  // any existence checks — otherwise they accumulate and confuse state (#2205).
354
383
  cleanNumberedGsdVariants(projectPath);
@@ -36,8 +36,8 @@ export function expandDependencies(deps) {
36
36
  return result;
37
37
  }
38
38
  function extractSlicesSection(content) {
39
- // Match "## Slices", "## Slice Overview", "## Slice Table", etc.
40
- const headingMatch = /^## Slice(?:s| Overview| Table| Summary| Status)\b.*$/m.exec(content);
39
+ // Match "## Slices", "## Slice Overview", "## Slice Table", "## Slice Roadmap", etc.
40
+ const headingMatch = /^## Slice(?:s| Overview| Table| Summary| Status| Roadmap)\b.*$/m.exec(content);
41
41
  if (!headingMatch || headingMatch.index == null)
42
42
  return "";
43
43
  const start = headingMatch.index + headingMatch[0].length;
@@ -24,7 +24,6 @@ import { truncateWithEllipsis } from "../shared/format-utils.js";
24
24
  import { nativeParseJsonlTail } from "./native-parser-bridge.js";
25
25
  import { MAX_JSONL_BYTES, parseJSONL } from "./jsonl-utils.js";
26
26
  import { nativeWorkingTreeStatus, nativeDiffStat } from "./native-git-bridge.js";
27
- import { getAutoWorktreePath } from "./auto-worktree.js";
28
27
  // ─── JSONL Parsing ────────────────────────────────────────────────────────────
29
28
  // MAX_JSONL_BYTES and parseJSONL are imported from ./jsonl-utils.js
30
29
  /**
@@ -235,17 +234,13 @@ export function synthesizeCrashRecovery(basePath, unitType, unitId, sessionFile,
235
234
  * Deep diagnostic from any JSONL source (activity log or session file).
236
235
  * Replaces the old shallow getLastActivityDiagnostic().
237
236
  */
238
- export function getDeepDiagnostic(basePath) {
239
- // Try worktree activity logs first if an auto-worktree is active
237
+ export function getDeepDiagnostic(basePath, worktreePath) {
238
+ // Try worktree activity logs first if a worktree path is provided
240
239
  let trace = null;
241
240
  try {
242
- const mid = readActiveMilestoneId(basePath);
243
- if (mid) {
244
- const wtPath = getAutoWorktreePath(basePath, mid);
245
- if (wtPath) {
246
- const wtActivityDir = join(gsdRoot(wtPath), "activity");
247
- trace = readLastActivityLog(wtActivityDir);
248
- }
241
+ if (worktreePath) {
242
+ const wtActivityDir = join(gsdRoot(worktreePath), "activity");
243
+ trace = readLastActivityLog(wtActivityDir);
249
244
  }
250
245
  }
251
246
  catch { /* non-fatal — fall through to root */ }
@@ -262,7 +257,7 @@ export function getDeepDiagnostic(basePath) {
262
257
  * Read the active milestone ID directly from STATE.md without async deriveState().
263
258
  * Looks for `**Active Milestone:** M001` pattern.
264
259
  */
265
- function readActiveMilestoneId(basePath) {
260
+ export function readActiveMilestoneId(basePath) {
266
261
  try {
267
262
  const statePath = join(gsdRoot(basePath), "STATE.md");
268
263
  if (!existsSync(statePath))
@@ -134,6 +134,49 @@ function ensureExitHandler(_gsdDir) {
134
134
  }
135
135
  });
136
136
  }
137
+ // ─── Lock Acquisition Helpers ───────────────────────────────────────────────
138
+ /**
139
+ * Create the onCompromised callback for proper-lockfile.
140
+ *
141
+ * proper-lockfile fires onCompromised when it detects mtime drift (system sleep,
142
+ * event loop stall, etc.). The default handler throws inside setTimeout — an
143
+ * uncaught exception that crashes or corrupts process state.
144
+ *
145
+ * False-positive suppression (#1362): If we're still within the stale window
146
+ * (30 min since acquisition), the mtime mismatch is from an event loop stall
147
+ * during a long LLM call — not a real takeover. Log and continue.
148
+ *
149
+ * PID ownership check (#1578): Past the stale window, check if the lock file
150
+ * still contains our PID before declaring compromise. Retry reads tolerate
151
+ * transient filesystem hiccups (NFS/CIFS latency, APFS snapshots, etc.) (#2324).
152
+ */
153
+ function createLockCompromisedHandler(lockFilePath) {
154
+ return () => {
155
+ const elapsed = Date.now() - _lockAcquiredAt;
156
+ if (elapsed < 1_800_000) {
157
+ process.stderr.write(`[gsd] Lock heartbeat caught up after ${Math.round(elapsed / 1000)}s — long LLM call, no action needed.\n`);
158
+ return;
159
+ }
160
+ const existing = readExistingLockDataWithRetry(lockFilePath);
161
+ if (existing && existing.pid === process.pid) {
162
+ process.stderr.write(`[gsd] Lock heartbeat mismatch after ${Math.round(elapsed / 1000)}s — lock file still owned by PID ${process.pid}, treating as false positive.\n`);
163
+ return;
164
+ }
165
+ _lockCompromised = true;
166
+ _releaseFunction = null;
167
+ };
168
+ }
169
+ /**
170
+ * Assign module-level lock state after a successful lock acquisition.
171
+ */
172
+ function assignLockState(basePath, release, lockFilePath) {
173
+ _releaseFunction = release;
174
+ _lockedPath = basePath;
175
+ _lockPid = process.pid;
176
+ _lockCompromised = false;
177
+ _lockAcquiredAt = Date.now();
178
+ _snapshotLockPath = lockFilePath;
179
+ }
137
180
  // ─── Public API ─────────────────────────────────────────────────────────────
138
181
  /**
139
182
  * Attempt to acquire an exclusive session lock for the given project.
@@ -188,38 +231,9 @@ export function acquireSessionLock(basePath) {
188
231
  realpath: false,
189
232
  stale: 1_800_000, // 30 minutes — safe for laptop sleep / long event loop stalls
190
233
  update: 10_000, // Update lock mtime every 10s to prove liveness
191
- onCompromised: () => {
192
- // proper-lockfile detected mtime drift (system sleep, event loop stall, etc.).
193
- // Default handler throws inside setTimeout — an uncaught exception that crashes
194
- // or corrupts process state.
195
- //
196
- // False-positive suppression (#1362): If we're still within the stale window
197
- // (30 min since acquisition), the mtime mismatch is from an event loop stall
198
- // during a long LLM call — not a real takeover. Log and continue.
199
- const elapsed = Date.now() - _lockAcquiredAt;
200
- if (elapsed < 1_800_000) {
201
- process.stderr.write(`[gsd] Lock heartbeat caught up after ${Math.round(elapsed / 1000)}s — long LLM call, no action needed.\n`);
202
- return; // Suppress false positive
203
- }
204
- // Past the stale window — check if the lock file still belongs to us before
205
- // declaring compromise (#1578). If our PID still owns the metadata, this is
206
- // a false positive from a very long event loop stall (e.g. subagent execution).
207
- const existing = readExistingLockData(lp);
208
- if (existing && existing.pid === process.pid) {
209
- process.stderr.write(`[gsd] Lock heartbeat mismatch after ${Math.round(elapsed / 1000)}s — lock file still owned by PID ${process.pid}, treating as false positive.\n`);
210
- return; // Our PID still owns the lock file — no real takeover
211
- }
212
- // Lock file is gone or owned by another PID — real compromise
213
- _lockCompromised = true;
214
- _releaseFunction = null;
215
- },
234
+ onCompromised: createLockCompromisedHandler(lp),
216
235
  });
217
- _releaseFunction = release;
218
- _lockedPath = basePath;
219
- _lockPid = process.pid;
220
- _lockCompromised = false;
221
- _lockAcquiredAt = Date.now();
222
- _snapshotLockPath = lp; // Snapshot the resolved path for consistent access (#1363)
236
+ assignLockState(basePath, release, lp);
223
237
  // Safety net: clean up lock dir on process exit if _releaseFunction
224
238
  // wasn't called (e.g., normal exit after clean completion) (#1245).
225
239
  ensureExitHandler(gsdDir);
@@ -245,31 +259,9 @@ export function acquireSessionLock(basePath) {
245
259
  realpath: false,
246
260
  stale: 1_800_000, // 30 minutes — match primary lock settings
247
261
  update: 10_000,
248
- onCompromised: () => {
249
- // Same false-positive suppression as the primary lock (#1512).
250
- // Without this, the retry path fires _lockCompromised unconditionally
251
- // on benign mtime drift (laptop sleep, heavy LLM event loop stalls).
252
- const elapsed = Date.now() - _lockAcquiredAt;
253
- if (elapsed < 1_800_000) {
254
- process.stderr.write(`[gsd] Lock heartbeat caught up after ${Math.round(elapsed / 1000)}s — long LLM call, no action needed.\n`);
255
- return;
256
- }
257
- // Check PID ownership before declaring compromise (#1578)
258
- const existing = readExistingLockData(lp);
259
- if (existing && existing.pid === process.pid) {
260
- process.stderr.write(`[gsd] Lock heartbeat mismatch after ${Math.round(elapsed / 1000)}s — lock file still owned by PID ${process.pid}, treating as false positive.\n`);
261
- return;
262
- }
263
- _lockCompromised = true;
264
- _releaseFunction = null;
265
- },
262
+ onCompromised: createLockCompromisedHandler(lp),
266
263
  });
267
- _releaseFunction = release;
268
- _lockedPath = basePath;
269
- _lockPid = process.pid;
270
- _lockCompromised = false;
271
- _lockAcquiredAt = Date.now();
272
- _snapshotLockPath = lp; // Snapshot for retry path too (#1363)
264
+ assignLockState(basePath, release, lp);
273
265
  // Safety net — uses centralized handler to avoid double-registration
274
266
  ensureExitHandler(gsdDir);
275
267
  atomicWriteSync(lp, JSON.stringify(lockData, null, 2));
@@ -348,7 +340,8 @@ export function getSessionLockStatus(basePath) {
348
340
  // onCompromised fired from benign mtime drift (laptop sleep, event loop stall
349
341
  // beyond the stale window). Attempt re-acquisition instead of giving up.
350
342
  const lp = lockPath(basePath);
351
- const existing = readExistingLockData(lp);
343
+ // Retry reads to tolerate transient filesystem hiccups (#2324).
344
+ const existing = readExistingLockDataWithRetry(lp);
352
345
  if (existing && existing.pid === process.pid) {
353
346
  // Lock file still ours — try to re-acquire the OS lock
354
347
  try {
@@ -492,6 +485,24 @@ function readExistingLockData(lp) {
492
485
  return null;
493
486
  }
494
487
  }
488
+ export function readExistingLockDataWithRetry(lp, options) {
489
+ const maxAttempts = options?.maxAttempts ?? 3;
490
+ const delayMs = options?.delayMs ?? 200;
491
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
492
+ const data = readExistingLockData(lp);
493
+ if (data !== null)
494
+ return data;
495
+ if (attempt < maxAttempts) {
496
+ // Synchronous busy-wait — onCompromised runs in a sync callback context
497
+ // and the delays are short (200ms default).
498
+ const start = Date.now();
499
+ while (Date.now() - start < delayMs) {
500
+ // busy-wait
501
+ }
502
+ }
503
+ }
504
+ return null;
505
+ }
495
506
  function isPidAlive(pid) {
496
507
  if (!Number.isInteger(pid) || pid <= 0)
497
508
  return false;
@@ -9,7 +9,8 @@ import { nativeBatchParseGsdFiles } from './native-parser-bridge.js';
9
9
  import { join, resolve } from 'path';
10
10
  import { existsSync, readdirSync } from 'node:fs';
11
11
  import { debugCount, debugTime } from './debug-logger.js';
12
- import { isDbAvailable, getAllMilestones, getMilestoneSlices, getSliceTasks, getReplanHistory, getSlice, insertMilestone, updateTaskStatus, } from './gsd-db.js';
12
+ import { extractVerdict } from './verdict-parser.js';
13
+ import { isDbAvailable, getAllMilestones, getMilestoneSlices, getSliceTasks, getReplanHistory, getSlice, insertMilestone, updateTaskStatus, getPendingSliceGateCount, } from './gsd-db.js';
13
14
  /**
14
15
  * A "ghost" milestone directory contains only META.json (and no substantive
15
16
  * files like CONTEXT, CONTEXT-DRAFT, ROADMAP, or SUMMARY). These appear when
@@ -42,13 +43,9 @@ export function isMilestoneComplete(roadmap) {
42
43
  * after remediation slices are executed.
43
44
  */
44
45
  export function isValidationTerminal(validationContent) {
45
- const match = validationContent.match(/^---\n([\s\S]*?)\n---/);
46
- if (!match)
46
+ const v = extractVerdict(validationContent);
47
+ if (!v)
47
48
  return false;
48
- const verdict = match[1].match(/verdict:\s*(\S+)/);
49
- if (!verdict)
50
- return false;
51
- const v = verdict[1] === 'passed' ? 'pass' : verdict[1];
52
49
  // 'pass' and 'needs-attention' are always terminal.
53
50
  // 'needs-remediation' is treated as terminal to prevent infinite loops
54
51
  // when no remediation slices exist in the roadmap (#832). The validation
@@ -595,6 +592,21 @@ export async function deriveStateFromDb(basePath) {
595
592
  };
596
593
  }
597
594
  }
595
+ // ── Quality gate evaluation check ──────────────────────────────────
596
+ // If slice-scoped gates (Q3/Q4) are still pending, pause before execution
597
+ // so the gate-evaluate dispatch rule can run parallel sub-agents.
598
+ // Slices with zero gate rows (pre-feature or simple) skip straight through.
599
+ const pendingGateCount = getPendingSliceGateCount(activeMilestone.id, activeSlice.id);
600
+ if (pendingGateCount > 0) {
601
+ return {
602
+ activeMilestone, activeSlice, activeTask: null,
603
+ phase: 'evaluating-gates',
604
+ recentDecisions: [], blockers: [],
605
+ nextAction: `Evaluate ${pendingGateCount} quality gate(s) for ${activeSlice.id} before execution.`,
606
+ registry, requirements,
607
+ progress: { milestones: milestoneProgress, slices: sliceProgress, tasks: taskProgress },
608
+ };
609
+ }
598
610
  // ── Blocker detection: check completed tasks for blocker_discovered ──
599
611
  const completedTasks = tasks.filter(t => isStatusDone(t.status));
600
612
  let blockerTaskId = null;
@@ -1143,6 +1155,21 @@ export async function _deriveStateImpl(basePath) {
1143
1155
  };
1144
1156
  }
1145
1157
  const slicePlan = parsePlan(slicePlanContent);
1158
+ // ── Reconcile stale task status for filesystem-based projects (#2514) ──
1159
+ // Heading-style tasks (### T01:) are always parsed as done=false by
1160
+ // parsePlan because the heading syntax has no checkbox. When the agent
1161
+ // writes a SUMMARY file but the plan's heading isn't converted to a
1162
+ // checkbox, the task appears incomplete forever — causing infinite
1163
+ // re-dispatch. Reconcile by checking SUMMARY files on disk.
1164
+ for (const t of slicePlan.tasks) {
1165
+ if (t.done)
1166
+ continue;
1167
+ const summaryPath = resolveTaskFile(basePath, activeMilestone.id, activeSlice.id, t.id, "SUMMARY");
1168
+ if (summaryPath && existsSync(summaryPath)) {
1169
+ t.done = true;
1170
+ process.stderr.write(`gsd-reconcile: task ${activeMilestone.id}/${activeSlice.id}/${t.id} has SUMMARY on disk but plan shows incomplete — marking done (#2514)\n`);
1171
+ }
1172
+ }
1146
1173
  const taskProgress = {
1147
1174
  done: slicePlan.tasks.filter(t => t.done).length,
1148
1175
  total: slicePlan.tasks.length,
@@ -49,6 +49,14 @@ completed_at: {{date}}
49
49
 
50
50
  - {{requirementId}}: {{fromStatus}} → {{toStatus}} — {{evidence}}
51
51
 
52
+ ## Decision Re-evaluation
53
+
54
+ <!-- Review decisions from this milestone. OMIT if no decisions need re-evaluation. -->
55
+
56
+ | Decision | Original Rationale | Still Valid? | Action |
57
+ |----------|-------------------|-------------|--------|
58
+ | {{decisionId}} | {{originalRationale}} | {{yes/no/partially}} | {{keep/revise/supersede}} |
59
+
52
60
  ## Forward Intelligence
53
61
 
54
62
  <!-- Write what you wish you'd known at the start of this milestone.
@@ -8,6 +8,22 @@
8
8
  - {{mustHave}}
9
9
  - {{mustHave}}
10
10
 
11
+ ## Threat Surface
12
+
13
+ <!-- Q3: How can this be exploited? OMIT ENTIRELY for simple slices with no auth, user input, or data exposure. -->
14
+
15
+ - **Abuse**: {{abuseScenarios — parameter tampering, replay, privilege escalation, or N/A}}
16
+ - **Data exposure**: {{sensitiveDataAccessible — PII, tokens, secrets, or none}}
17
+ - **Input trust**: {{untrustedInput — user input reaching DB/API/filesystem, or none}}
18
+
19
+ ## Requirement Impact
20
+
21
+ <!-- Q4: What existing promises does this break? OMIT ENTIRELY if no existing requirements are affected. -->
22
+
23
+ - **Requirements touched**: {{requirementIds — e.g. R001, R003, or none}}
24
+ - **Re-verify**: {{whatMustBeRetested — e.g. login flow, API contract, or N/A}}
25
+ - **Decisions revisited**: {{decisionIds — e.g. D002, or none}}
26
+
11
27
  ## Proof Level
12
28
 
13
29
  <!-- Omit this section entirely for simple slices where the answer is trivially obvious. -->
@@ -92,6 +92,19 @@ This milestone is complete only when all are true:
92
92
  - Each "After this" line must be truthful about proof level: if only fixtures or tests prove it, say so; do not imply the user can already perform the live end-to-end behavior unless that has actually been exercised
93
93
  -->
94
94
 
95
+ ## Horizontal Checklist
96
+
97
+ <!-- Cross-cutting concerns across all slices. Check each that was considered.
98
+ OMIT ENTIRELY for trivial milestones. -->
99
+
100
+ - [ ] Every active R### re-read against new code — still fully satisfied?
101
+ - [ ] Every D### from prior milestones re-evaluated — still valid at new scope?
102
+ - [ ] Graceful shutdown / cleanup on termination verified
103
+ - [ ] Revenue / billing path impact assessed (or N/A)
104
+ - [ ] Auth boundary documented — what's protected vs public
105
+ - [ ] Shared resource budget confirmed — connection pools, caches, rate limits hold under peak
106
+ - [ ] Reconnection / retry strategy verified for every external dependency
107
+
95
108
  ## Boundary Map
96
109
 
97
110
  <!-- Be specific. Name concrete outputs: API endpoints, event payloads, shared types/interfaces,
@@ -57,6 +57,15 @@ completed_at: {{date}}
57
57
 
58
58
  - {{requirementIdOr_none}} — {{what changed}}
59
59
 
60
+ ## Operational Readiness
61
+
62
+ <!-- Q8: How will ops know it's healthy/broken? OMIT ENTIRELY for simple slices with no runtime concerns. -->
63
+
64
+ - **Health signal**: {{howToConfirmHealthy — health endpoint, heartbeat log, metric, or N/A}}
65
+ - **Failure signal**: {{howToDetectBroken — error rate spike, alert, log pattern, or N/A}}
66
+ - **Recovery**: {{selfRecoverOrRestart — auto-reconnect, circuit breaker, manual restart, or N/A}}
67
+ - **Monitoring gaps**: {{silentFailureModes — background jobs, cache eviction, memory pressure, or none}}
68
+
60
69
  ## Deviations
61
70
 
62
71
  <!-- Deviations are unplanned changes to the written plan, not ordinary debugging inside the plan's intended scope. -->
@@ -17,6 +17,30 @@ skills_used:
17
17
 
18
18
  {{description}}
19
19
 
20
+ ## Failure Modes
21
+
22
+ <!-- Q5: What breaks when dependencies fail? OMIT ENTIRELY for tasks with no external dependencies. -->
23
+
24
+ | Dependency | On error | On timeout | On malformed response |
25
+ |------------|----------|-----------|----------------------|
26
+ | {{dependency}} | {{errorStrategy}} | {{timeoutStrategy}} | {{malformedStrategy}} |
27
+
28
+ ## Load Profile
29
+
30
+ <!-- Q6: What breaks at 10x load? OMIT ENTIRELY for tasks with no shared resources or scaling concerns. -->
31
+
32
+ - **Shared resources**: {{sharedResources — DB connections, caches, rate limiters, or none}}
33
+ - **Per-operation cost**: {{perOpCost — N API calls, M DB queries, K bytes, or trivial}}
34
+ - **10x breakpoint**: {{whatBreaksFirst — pool exhaustion, rate limit, memory, or N/A}}
35
+
36
+ ## Negative Tests
37
+
38
+ <!-- Q7: What negative tests prove robustness? OMIT ENTIRELY for trivial tasks. -->
39
+
40
+ - **Malformed inputs**: {{malformedInputTests — empty string, null, oversized, wrong type}}
41
+ - **Error paths**: {{errorPathTests — network timeout, auth failure, 5xx, invalid JSON}}
42
+ - **Boundary conditions**: {{boundaryTests — empty list, max length, zero, off-by-one}}
43
+
20
44
  ## Steps
21
45
 
22
46
  1. {{step}}
@@ -1,5 +1,5 @@
1
1
  import { clearParseCache } from "../files.js";
2
- import { transaction, getMilestone, getSlice, insertTask, upsertSlicePlanning, upsertTaskPlanning, } from "../gsd-db.js";
2
+ import { transaction, getMilestone, getSlice, insertTask, upsertSlicePlanning, upsertTaskPlanning, insertGateRow, } from "../gsd-db.js";
3
3
  import { invalidateStateCache } from "../state.js";
4
4
  import { renderPlanFromDb } from "../markdown-renderer.js";
5
5
  import { renderAllProjections } from "../workflow-projections.js";
@@ -145,6 +145,19 @@ export async function handlePlanSlice(rawParams, basePath) {
145
145
  fullPlanMd: task.fullPlanMd,
146
146
  });
147
147
  }
148
+ // Seed quality gate rows inside the transaction — all-or-nothing with
149
+ // the plan data so a crash can't leave orphaned gates without tasks.
150
+ const sliceGates = ["Q3", "Q4"];
151
+ for (const gid of sliceGates) {
152
+ insertGateRow({ milestoneId: params.milestoneId, sliceId: params.sliceId, gateId: gid, scope: "slice" });
153
+ }
154
+ const taskGates = ["Q5", "Q6", "Q7"];
155
+ for (const task of params.tasks) {
156
+ for (const gid of taskGates) {
157
+ insertGateRow({ milestoneId: params.milestoneId, sliceId: params.sliceId, gateId: gid, scope: "task", taskId: task.taskId });
158
+ }
159
+ }
160
+ insertGateRow({ milestoneId: params.milestoneId, sliceId: params.sliceId, gateId: "Q8", scope: "slice" });
148
161
  });
149
162
  }
150
163
  catch (err) {
@@ -9,6 +9,7 @@ import { transaction, _getAdapter, } from "../gsd-db.js";
9
9
  import { resolveMilestonePath, clearPathCache } from "../paths.js";
10
10
  import { saveFile, clearParseCache } from "../files.js";
11
11
  import { invalidateStateCache } from "../state.js";
12
+ import { VALIDATION_VERDICTS, isValidMilestoneVerdict } from "../verdict-parser.js";
12
13
  function renderValidationMarkdown(params) {
13
14
  let md = `---
14
15
  verdict: ${params.verdict}
@@ -41,9 +42,8 @@ export async function handleValidateMilestone(params, basePath) {
41
42
  if (!params.milestoneId || typeof params.milestoneId !== "string" || params.milestoneId.trim() === "") {
42
43
  return { error: "milestoneId is required and must be a non-empty string" };
43
44
  }
44
- const validVerdicts = ["pass", "needs-attention", "needs-remediation"];
45
- if (!validVerdicts.includes(params.verdict)) {
46
- return { error: `verdict must be one of: ${validVerdicts.join(", ")}` };
45
+ if (!isValidMilestoneVerdict(params.verdict)) {
46
+ return { error: `verdict must be one of: ${VALIDATION_VERDICTS.join(", ")}` };
47
47
  }
48
48
  // ── Filesystem render ──────────────────────────────────────────────────
49
49
  const validationMd = renderValidationMarkdown(params);