@opengsd/gsd-pi 1.3.0-dev.eed73bea → 1.4.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 (505) hide show
  1. package/README.md +10 -10
  2. package/dist/cli.js +17 -4
  3. package/dist/headless-answers.js +1 -1
  4. package/dist/headless-ui.d.ts +1 -1
  5. package/dist/headless-ui.js +1 -1
  6. package/dist/headless.js +1 -1
  7. package/dist/resources/.managed-resources-content-hash +1 -1
  8. package/dist/resources/extensions/claude-code-cli/models.js +9 -0
  9. package/dist/resources/extensions/gsd/artifact-verification.js +427 -0
  10. package/dist/resources/extensions/gsd/auto/session.js +11 -0
  11. package/dist/resources/extensions/gsd/auto/verification-retry-policy.js +1 -1
  12. package/dist/resources/extensions/gsd/auto-artifact-paths.js +28 -1
  13. package/dist/resources/extensions/gsd/auto-budget.js +5 -1
  14. package/dist/resources/extensions/gsd/auto-dispatch.js +17 -6
  15. package/dist/resources/extensions/gsd/auto-post-unit.js +1 -1
  16. package/dist/resources/extensions/gsd/auto-prompts.js +8 -24
  17. package/dist/resources/extensions/gsd/auto-recovery.js +9 -517
  18. package/dist/resources/extensions/gsd/auto-runtime-state.js +4 -5
  19. package/dist/resources/extensions/gsd/auto-timeout-recovery.js +3 -3
  20. package/dist/resources/extensions/gsd/auto-verification.js +5 -2
  21. package/dist/resources/extensions/gsd/auto.js +19 -10
  22. package/dist/resources/extensions/gsd/bootstrap/core-session-tools.js +39 -0
  23. package/dist/resources/extensions/gsd/bootstrap/db-tools.js +5 -4
  24. package/dist/resources/extensions/gsd/bootstrap/register-extension.js +2 -0
  25. package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +33 -18
  26. package/dist/resources/extensions/gsd/bootstrap/tool-call-loop-guard.js +48 -36
  27. package/dist/resources/extensions/gsd/bootstrap/write-gate.js +15 -4
  28. package/dist/resources/extensions/gsd/closeout-consistency-gate.js +3 -1
  29. package/dist/resources/extensions/gsd/commands/handlers/auto.js +1 -1
  30. package/dist/resources/extensions/gsd/commands-prefs-wizard.js +1 -1
  31. package/dist/resources/extensions/gsd/commands-usage.js +1 -1
  32. package/dist/resources/extensions/gsd/db/engine.js +4 -1
  33. package/dist/resources/extensions/gsd/db-memory-fts-schema.js +34 -0
  34. package/dist/resources/extensions/gsd/db-workspace.js +55 -3
  35. package/dist/resources/extensions/gsd/delegation-policy.js +1 -1
  36. package/dist/resources/extensions/gsd/docs/preferences-reference.md +2 -2
  37. package/dist/resources/extensions/gsd/doctor-engine-checks.js +192 -4
  38. package/dist/resources/extensions/gsd/doctor-runtime-checks.js +3 -0
  39. package/dist/resources/extensions/gsd/exec-sandbox.js +8 -2
  40. package/dist/resources/extensions/gsd/flat-phase-migration.js +45 -0
  41. package/dist/resources/extensions/gsd/git-service.js +57 -0
  42. package/dist/resources/extensions/gsd/gitignore.js +4 -1
  43. package/dist/resources/extensions/gsd/guided-flow-queue.js +20 -13
  44. package/dist/resources/extensions/gsd/json-persistence.js +20 -0
  45. package/dist/resources/extensions/gsd/knowledge-backfill.js +18 -11
  46. package/dist/resources/extensions/gsd/layout-policy.js +3 -1
  47. package/dist/resources/extensions/gsd/markdown-renderer.js +2 -7
  48. package/dist/resources/extensions/gsd/memory-backfill.js +28 -21
  49. package/dist/resources/extensions/gsd/metrics.js +4 -4
  50. package/dist/resources/extensions/gsd/migrate-external.js +11 -2
  51. package/dist/resources/extensions/gsd/migration-auto-check.js +22 -0
  52. package/dist/resources/extensions/gsd/milestone-ids.js +32 -2
  53. package/dist/resources/extensions/gsd/orphan-stash-audit.js +92 -16
  54. package/dist/resources/extensions/gsd/prompts/code-review.md +6 -4
  55. package/dist/resources/extensions/gsd/prompts/plan-milestone.md +2 -2
  56. package/dist/resources/extensions/gsd/prompts/plan-slice.md +3 -3
  57. package/dist/resources/extensions/gsd/root-write-leak-guard.js +7 -1
  58. package/dist/resources/extensions/gsd/safety/destructive-guard.js +8 -1
  59. package/dist/resources/extensions/gsd/safety/evidence-collector.js +16 -1
  60. package/dist/resources/extensions/gsd/safety/file-change-validator.js +5 -2
  61. package/dist/resources/extensions/gsd/skills/gsd-headless/references/commands.md +1 -1
  62. package/dist/resources/extensions/gsd/state/derive/cache.js +28 -0
  63. package/dist/resources/extensions/gsd/state/derive/db-open.js +39 -0
  64. package/dist/resources/extensions/gsd/state/derive/from-db.js +452 -0
  65. package/dist/resources/extensions/gsd/state/derive/index.js +75 -0
  66. package/dist/resources/extensions/gsd/state/derive/interrupted-work.js +21 -0
  67. package/dist/resources/extensions/gsd/state-reconciliation/drift/stale-render.js +27 -33
  68. package/dist/resources/extensions/gsd/state-reconciliation/index.js +48 -23
  69. package/dist/resources/extensions/gsd/state-reconciliation/registry.js +32 -28
  70. package/dist/resources/extensions/gsd/state.js +12 -611
  71. package/dist/resources/extensions/gsd/tools/complete-milestone.js +4 -2
  72. package/dist/resources/extensions/gsd/tools/complete-slice.js +3 -34
  73. package/dist/resources/extensions/gsd/tools/complete-task.js +8 -41
  74. package/dist/resources/extensions/gsd/tools/plan-slice.js +59 -44
  75. package/dist/resources/extensions/gsd/tools/plan-task.js +28 -5
  76. package/dist/resources/extensions/gsd/undo.js +43 -6
  77. package/dist/resources/extensions/gsd/unit-registry.js +11 -3
  78. package/dist/resources/extensions/gsd/verification-gate.js +7 -0
  79. package/dist/resources/extensions/gsd/workflow-manifest.js +126 -13
  80. package/dist/resources/extensions/gsd/workflow-projections.js +19 -14
  81. package/dist/resources/extensions/gsd/worktree-manager.js +44 -2
  82. package/dist/tsconfig.extensions.tsbuildinfo +1 -1
  83. package/dist/web/standalone/.next/BUILD_ID +1 -1
  84. package/dist/web/standalone/.next/app-path-routes-manifest.json +10 -10
  85. package/dist/web/standalone/.next/build-manifest.json +4 -4
  86. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  87. package/dist/web/standalone/.next/react-loadable-manifest.json +9 -9
  88. package/dist/web/standalone/.next/required-server-files.json +3 -3
  89. package/dist/web/standalone/.next/server/app/_global-error/page.js +3 -3
  90. package/dist/web/standalone/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  91. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  92. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  93. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  94. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  95. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  96. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  97. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  98. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  99. package/dist/web/standalone/.next/server/app/_not-found/page.js +2 -2
  100. package/dist/web/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  101. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  102. package/dist/web/standalone/.next/server/app/_not-found.rsc +3 -3
  103. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +3 -3
  104. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  105. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +3 -3
  106. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  107. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  108. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  109. package/dist/web/standalone/.next/server/app/api/boot/route.js +1 -1
  110. package/dist/web/standalone/.next/server/app/api/boot/route_client-reference-manifest.js +1 -1
  111. package/dist/web/standalone/.next/server/app/api/bridge-terminal/input/route.js +1 -1
  112. package/dist/web/standalone/.next/server/app/api/bridge-terminal/input/route_client-reference-manifest.js +1 -1
  113. package/dist/web/standalone/.next/server/app/api/bridge-terminal/resize/route.js +1 -1
  114. package/dist/web/standalone/.next/server/app/api/bridge-terminal/resize/route_client-reference-manifest.js +1 -1
  115. package/dist/web/standalone/.next/server/app/api/bridge-terminal/stream/route.js +2 -2
  116. package/dist/web/standalone/.next/server/app/api/bridge-terminal/stream/route_client-reference-manifest.js +1 -1
  117. package/dist/web/standalone/.next/server/app/api/browse-directories/route.js +1 -1
  118. package/dist/web/standalone/.next/server/app/api/browse-directories/route_client-reference-manifest.js +1 -1
  119. package/dist/web/standalone/.next/server/app/api/captures/route.js +1 -1
  120. package/dist/web/standalone/.next/server/app/api/captures/route_client-reference-manifest.js +1 -1
  121. package/dist/web/standalone/.next/server/app/api/cleanup/route.js +1 -1
  122. package/dist/web/standalone/.next/server/app/api/cleanup/route_client-reference-manifest.js +1 -1
  123. package/dist/web/standalone/.next/server/app/api/dev-mode/route.js +1 -1
  124. package/dist/web/standalone/.next/server/app/api/dev-mode/route_client-reference-manifest.js +1 -1
  125. package/dist/web/standalone/.next/server/app/api/doctor/route.js +1 -1
  126. package/dist/web/standalone/.next/server/app/api/doctor/route_client-reference-manifest.js +1 -1
  127. package/dist/web/standalone/.next/server/app/api/experimental/route.js +2 -2
  128. package/dist/web/standalone/.next/server/app/api/experimental/route_client-reference-manifest.js +1 -1
  129. package/dist/web/standalone/.next/server/app/api/export-data/route.js +1 -1
  130. package/dist/web/standalone/.next/server/app/api/export-data/route_client-reference-manifest.js +1 -1
  131. package/dist/web/standalone/.next/server/app/api/files/route.js +1 -1
  132. package/dist/web/standalone/.next/server/app/api/files/route_client-reference-manifest.js +1 -1
  133. package/dist/web/standalone/.next/server/app/api/forensics/route.js +1 -1
  134. package/dist/web/standalone/.next/server/app/api/forensics/route_client-reference-manifest.js +1 -1
  135. package/dist/web/standalone/.next/server/app/api/git/route.js +1 -1
  136. package/dist/web/standalone/.next/server/app/api/git/route_client-reference-manifest.js +1 -1
  137. package/dist/web/standalone/.next/server/app/api/history/route.js +1 -1
  138. package/dist/web/standalone/.next/server/app/api/history/route_client-reference-manifest.js +1 -1
  139. package/dist/web/standalone/.next/server/app/api/hooks/route.js +1 -1
  140. package/dist/web/standalone/.next/server/app/api/hooks/route_client-reference-manifest.js +1 -1
  141. package/dist/web/standalone/.next/server/app/api/inspect/route.js +1 -1
  142. package/dist/web/standalone/.next/server/app/api/inspect/route_client-reference-manifest.js +1 -1
  143. package/dist/web/standalone/.next/server/app/api/knowledge/route.js +1 -1
  144. package/dist/web/standalone/.next/server/app/api/knowledge/route_client-reference-manifest.js +1 -1
  145. package/dist/web/standalone/.next/server/app/api/live-state/route.js +1 -1
  146. package/dist/web/standalone/.next/server/app/api/live-state/route_client-reference-manifest.js +1 -1
  147. package/dist/web/standalone/.next/server/app/api/mcp-connections/route.js +1 -1
  148. package/dist/web/standalone/.next/server/app/api/mcp-connections/route_client-reference-manifest.js +1 -1
  149. package/dist/web/standalone/.next/server/app/api/notifications/route.js +2 -2
  150. package/dist/web/standalone/.next/server/app/api/notifications/route_client-reference-manifest.js +1 -1
  151. package/dist/web/standalone/.next/server/app/api/onboarding/route.js +1 -1
  152. package/dist/web/standalone/.next/server/app/api/onboarding/route_client-reference-manifest.js +1 -1
  153. package/dist/web/standalone/.next/server/app/api/preferences/route.js +1 -1
  154. package/dist/web/standalone/.next/server/app/api/preferences/route_client-reference-manifest.js +1 -1
  155. package/dist/web/standalone/.next/server/app/api/projects/route.js +1 -1
  156. package/dist/web/standalone/.next/server/app/api/projects/route_client-reference-manifest.js +1 -1
  157. package/dist/web/standalone/.next/server/app/api/recovery/route.js +1 -1
  158. package/dist/web/standalone/.next/server/app/api/recovery/route_client-reference-manifest.js +1 -1
  159. package/dist/web/standalone/.next/server/app/api/remote-questions/route.js +2 -2
  160. package/dist/web/standalone/.next/server/app/api/remote-questions/route_client-reference-manifest.js +1 -1
  161. package/dist/web/standalone/.next/server/app/api/session/browser/route.js +1 -1
  162. package/dist/web/standalone/.next/server/app/api/session/browser/route_client-reference-manifest.js +1 -1
  163. package/dist/web/standalone/.next/server/app/api/session/command/route.js +1 -1
  164. package/dist/web/standalone/.next/server/app/api/session/command/route_client-reference-manifest.js +1 -1
  165. package/dist/web/standalone/.next/server/app/api/session/events/route.js +2 -2
  166. package/dist/web/standalone/.next/server/app/api/session/events/route_client-reference-manifest.js +1 -1
  167. package/dist/web/standalone/.next/server/app/api/session/manage/route.js +1 -1
  168. package/dist/web/standalone/.next/server/app/api/session/manage/route_client-reference-manifest.js +1 -1
  169. package/dist/web/standalone/.next/server/app/api/settings-data/route.js +1 -1
  170. package/dist/web/standalone/.next/server/app/api/settings-data/route_client-reference-manifest.js +1 -1
  171. package/dist/web/standalone/.next/server/app/api/shutdown/route.js +1 -1
  172. package/dist/web/standalone/.next/server/app/api/shutdown/route_client-reference-manifest.js +1 -1
  173. package/dist/web/standalone/.next/server/app/api/skill-health/route.js +1 -1
  174. package/dist/web/standalone/.next/server/app/api/skill-health/route_client-reference-manifest.js +1 -1
  175. package/dist/web/standalone/.next/server/app/api/steer/route.js +1 -1
  176. package/dist/web/standalone/.next/server/app/api/steer/route_client-reference-manifest.js +1 -1
  177. package/dist/web/standalone/.next/server/app/api/switch-root/route.js +1 -1
  178. package/dist/web/standalone/.next/server/app/api/switch-root/route_client-reference-manifest.js +1 -1
  179. package/dist/web/standalone/.next/server/app/api/terminal/input/route.js +1 -1
  180. package/dist/web/standalone/.next/server/app/api/terminal/input/route_client-reference-manifest.js +1 -1
  181. package/dist/web/standalone/.next/server/app/api/terminal/resize/route.js +2 -2
  182. package/dist/web/standalone/.next/server/app/api/terminal/resize/route_client-reference-manifest.js +1 -1
  183. package/dist/web/standalone/.next/server/app/api/terminal/sessions/route.js +1 -1
  184. package/dist/web/standalone/.next/server/app/api/terminal/sessions/route_client-reference-manifest.js +1 -1
  185. package/dist/web/standalone/.next/server/app/api/terminal/stream/route.js +4 -4
  186. package/dist/web/standalone/.next/server/app/api/terminal/stream/route_client-reference-manifest.js +1 -1
  187. package/dist/web/standalone/.next/server/app/api/terminal/upload/route.js +1 -1
  188. package/dist/web/standalone/.next/server/app/api/terminal/upload/route_client-reference-manifest.js +1 -1
  189. package/dist/web/standalone/.next/server/app/api/undo/route.js +1 -1
  190. package/dist/web/standalone/.next/server/app/api/undo/route_client-reference-manifest.js +1 -1
  191. package/dist/web/standalone/.next/server/app/api/update/route.js +1 -1
  192. package/dist/web/standalone/.next/server/app/api/update/route_client-reference-manifest.js +1 -1
  193. package/dist/web/standalone/.next/server/app/api/visualizer/route.js +1 -1
  194. package/dist/web/standalone/.next/server/app/api/visualizer/route_client-reference-manifest.js +1 -1
  195. package/dist/web/standalone/.next/server/app/index.html +1 -1
  196. package/dist/web/standalone/.next/server/app/index.rsc +4 -4
  197. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
  198. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +4 -4
  199. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  200. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +3 -3
  201. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  202. package/dist/web/standalone/.next/server/app/page.js +2 -2
  203. package/dist/web/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
  204. package/dist/web/standalone/.next/server/app-paths-manifest.json +10 -10
  205. package/dist/web/standalone/.next/server/chunks/2842.js +4 -4
  206. package/dist/web/standalone/.next/server/chunks/8357.js +3 -3
  207. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  208. package/dist/web/standalone/.next/server/middleware-react-loadable-manifest.js +1 -1
  209. package/dist/web/standalone/.next/server/middleware.js +3 -3
  210. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  211. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  212. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  213. package/dist/web/standalone/.next/static/chunks/{2659.b7b129ee6a769448.js → 2659.58e950899a9bb82f.js} +1 -1
  214. package/dist/web/standalone/.next/static/chunks/2772.a7c1fcc69a4685ef.js +1 -0
  215. package/dist/web/standalone/.next/static/chunks/{3616.3c60753b8ffcbd2e.js → 3616.61a2af74bb8833c8.js} +1 -1
  216. package/dist/web/standalone/.next/static/chunks/{4283.8e446784528ed9dc.js → 4283.d0d9e0a955e441cb.js} +1 -1
  217. package/dist/web/standalone/.next/static/chunks/{5826.a46ecdd1cfe8dabc.js → 5826.5421d66c72b9f34e.js} +1 -1
  218. package/dist/web/standalone/.next/static/chunks/{8785.481aa5869991b760.js → 8785.e29b3134cab1d153.js} +1 -1
  219. package/dist/web/standalone/.next/static/chunks/8937.640dc9c2aaa1dfad.js +10 -0
  220. package/dist/web/standalone/.next/static/chunks/app/_not-found/page-49f565245e1e4afe.js +1 -0
  221. package/dist/web/standalone/.next/static/chunks/app/{layout-4ae2d68984392bbf.js → layout-b35cbfff38aaf4cf.js} +1 -1
  222. package/dist/web/standalone/.next/static/chunks/app/page-bc4c723c6a19c6f0.js +1 -0
  223. package/dist/web/standalone/.next/static/chunks/{main-app-90d1d8d5e5d2dc6b.js → main-app-590a74400e35f685.js} +1 -1
  224. package/dist/web/standalone/.next/static/chunks/next/dist/client/components/builtin/global-error-ec3eaffc9785ba48.js +1 -0
  225. package/dist/web/standalone/.next/static/chunks/webpack-9c401904f87ded16.js +1 -0
  226. package/dist/web/standalone/node_modules/@gsd/native/package.json +1 -1
  227. package/dist/web/standalone/node_modules/node-pty/build/Makefile +2 -2
  228. package/dist/web/standalone/node_modules/node-pty/build/Release/pty.node +0 -0
  229. package/dist/web/standalone/node_modules/node-pty/build/pty.target.mk +14 -14
  230. package/dist/web/standalone/server.js +1 -1
  231. package/package.json +6 -6
  232. package/packages/cloud-mcp-gateway/package.json +2 -2
  233. package/packages/contracts/package.json +1 -1
  234. package/packages/daemon/package.json +4 -4
  235. package/packages/gsd-agent-core/dist/agent-session.d.ts +1 -0
  236. package/packages/gsd-agent-core/dist/agent-session.d.ts.map +1 -1
  237. package/packages/gsd-agent-core/dist/agent-session.js +3 -0
  238. package/packages/gsd-agent-core/dist/agent-session.js.map +1 -1
  239. package/packages/gsd-agent-core/dist/extension-ui-snapshot.d.ts +41 -0
  240. package/packages/gsd-agent-core/dist/extension-ui-snapshot.d.ts.map +1 -0
  241. package/packages/gsd-agent-core/dist/extension-ui-snapshot.js +62 -0
  242. package/packages/gsd-agent-core/dist/extension-ui-snapshot.js.map +1 -0
  243. package/packages/gsd-agent-core/dist/index.d.ts +2 -0
  244. package/packages/gsd-agent-core/dist/index.d.ts.map +1 -1
  245. package/packages/gsd-agent-core/dist/index.js +2 -0
  246. package/packages/gsd-agent-core/dist/index.js.map +1 -1
  247. package/packages/gsd-agent-core/dist/session/agent-session-events.js +1 -1
  248. package/packages/gsd-agent-core/dist/session/agent-session-events.js.map +1 -1
  249. package/packages/gsd-agent-core/dist/session/agent-session-host.d.ts +1 -0
  250. package/packages/gsd-agent-core/dist/session/agent-session-host.d.ts.map +1 -1
  251. package/packages/gsd-agent-core/dist/session/agent-session-host.js.map +1 -1
  252. package/packages/gsd-agent-core/dist/session/agent-session-prompt.d.ts +5 -0
  253. package/packages/gsd-agent-core/dist/session/agent-session-prompt.d.ts.map +1 -1
  254. package/packages/gsd-agent-core/dist/session/agent-session-prompt.js +60 -3
  255. package/packages/gsd-agent-core/dist/session/agent-session-prompt.js.map +1 -1
  256. package/packages/gsd-agent-core/dist/transcript-store.d.ts +58 -0
  257. package/packages/gsd-agent-core/dist/transcript-store.d.ts.map +1 -0
  258. package/packages/gsd-agent-core/dist/transcript-store.js +132 -0
  259. package/packages/gsd-agent-core/dist/transcript-store.js.map +1 -0
  260. package/packages/gsd-agent-core/package.json +5 -5
  261. package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.d.ts +2 -0
  262. package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  263. package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.js +25 -11
  264. package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.js.map +1 -1
  265. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller-latency.d.ts +4 -0
  266. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller-latency.d.ts.map +1 -0
  267. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller-latency.js +7 -0
  268. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller-latency.js.map +1 -0
  269. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.d.ts +3 -24
  270. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.d.ts.map +1 -1
  271. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.js +26 -841
  272. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.js.map +1 -1
  273. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-handoff-filter.d.ts +58 -0
  274. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-handoff-filter.d.ts.map +1 -0
  275. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-handoff-filter.js +312 -0
  276. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-handoff-filter.js.map +1 -0
  277. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-pinned-zone.d.ts +31 -0
  278. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-pinned-zone.d.ts.map +1 -0
  279. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-pinned-zone.js +130 -0
  280. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-pinned-zone.js.map +1 -0
  281. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-segment-walker.d.ts +15 -0
  282. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-segment-walker.d.ts.map +1 -0
  283. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-segment-walker.js +258 -0
  284. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-segment-walker.js.map +1 -0
  285. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-tool-rollup.d.ts +13 -0
  286. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-tool-rollup.d.ts.map +1 -0
  287. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-tool-rollup.js +118 -0
  288. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-tool-rollup.js.map +1 -0
  289. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-state.d.ts +9 -0
  290. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-state.d.ts.map +1 -1
  291. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-state.js +1 -1
  292. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-state.js.map +1 -1
  293. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-ui-state.d.ts +54 -0
  294. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-ui-state.d.ts.map +1 -0
  295. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-ui-state.js +20 -0
  296. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-ui-state.js.map +1 -0
  297. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode.d.ts +4 -1
  298. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  299. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode.js +9 -0
  300. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode.js.map +1 -1
  301. package/packages/gsd-agent-modes/dist/modes/interactive/streaming-render-state.d.ts +56 -0
  302. package/packages/gsd-agent-modes/dist/modes/interactive/streaming-render-state.d.ts.map +1 -0
  303. package/packages/gsd-agent-modes/dist/modes/interactive/streaming-render-state.js +44 -0
  304. package/packages/gsd-agent-modes/dist/modes/interactive/streaming-render-state.js.map +1 -0
  305. package/packages/gsd-agent-modes/dist/modes/interactive/tui-transcript-tracker.d.ts +5 -0
  306. package/packages/gsd-agent-modes/dist/modes/interactive/tui-transcript-tracker.d.ts.map +1 -0
  307. package/packages/gsd-agent-modes/dist/modes/interactive/tui-transcript-tracker.js +77 -0
  308. package/packages/gsd-agent-modes/dist/modes/interactive/tui-transcript-tracker.js.map +1 -0
  309. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-client.d.ts +2 -0
  310. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  311. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-client.js +23 -5
  312. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-client.js.map +1 -1
  313. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  314. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-mode.js +18 -0
  315. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-mode.js.map +1 -1
  316. package/packages/gsd-agent-modes/package.json +7 -7
  317. package/packages/mcp-server/dist/workflow-tools.js +1 -1
  318. package/packages/mcp-server/dist/workflow-tools.js.map +1 -1
  319. package/packages/mcp-server/package.json +4 -4
  320. package/packages/native/package.json +1 -1
  321. package/packages/pi-agent-core/dist/agent-loop.js +3 -2
  322. package/packages/pi-agent-core/dist/agent-loop.js.map +1 -1
  323. package/packages/pi-agent-core/package.json +1 -1
  324. package/packages/pi-ai/dist/models.generated.d.ts +46 -0
  325. package/packages/pi-ai/dist/models.generated.d.ts.map +1 -1
  326. package/packages/pi-ai/dist/models.generated.js +38 -0
  327. package/packages/pi-ai/dist/models.generated.js.map +1 -1
  328. package/packages/pi-ai/package.json +1 -1
  329. package/packages/pi-coding-agent/README.md +3 -2
  330. package/packages/pi-coding-agent/dist/core/session-manager-context.d.ts +9 -0
  331. package/packages/pi-coding-agent/dist/core/session-manager-context.d.ts.map +1 -0
  332. package/packages/pi-coding-agent/dist/core/session-manager-context.js +94 -0
  333. package/packages/pi-coding-agent/dist/core/session-manager-context.js.map +1 -0
  334. package/packages/pi-coding-agent/dist/core/session-manager-list.d.ts +8 -0
  335. package/packages/pi-coding-agent/dist/core/session-manager-list.d.ts.map +1 -0
  336. package/packages/pi-coding-agent/dist/core/session-manager-list.js +244 -0
  337. package/packages/pi-coding-agent/dist/core/session-manager-list.js.map +1 -0
  338. package/packages/pi-coding-agent/dist/core/session-manager-migration.d.ts +12 -0
  339. package/packages/pi-coding-agent/dist/core/session-manager-migration.d.ts.map +1 -0
  340. package/packages/pi-coding-agent/dist/core/session-manager-migration.js +84 -0
  341. package/packages/pi-coding-agent/dist/core/session-manager-migration.js.map +1 -0
  342. package/packages/pi-coding-agent/dist/core/session-manager-types.d.ts +135 -0
  343. package/packages/pi-coding-agent/dist/core/session-manager-types.d.ts.map +1 -0
  344. package/packages/pi-coding-agent/dist/core/session-manager-types.js +2 -0
  345. package/packages/pi-coding-agent/dist/core/session-manager-types.js.map +1 -0
  346. package/packages/pi-coding-agent/dist/core/session-manager.d.ts +6 -154
  347. package/packages/pi-coding-agent/dist/core/session-manager.d.ts.map +1 -1
  348. package/packages/pi-coding-agent/dist/core/session-manager.js +22 -459
  349. package/packages/pi-coding-agent/dist/core/session-manager.js.map +1 -1
  350. package/packages/pi-coding-agent/dist/theme/theme-schema.d.ts +75 -75
  351. package/packages/pi-coding-agent/dist/theme/theme-schema.d.ts.map +1 -1
  352. package/packages/pi-coding-agent/dist/theme/theme-schema.js +1 -1
  353. package/packages/pi-coding-agent/dist/theme/theme-schema.js.map +1 -1
  354. package/packages/pi-coding-agent/dist/theme/theme.d.ts.map +1 -1
  355. package/packages/pi-coding-agent/dist/theme/theme.js +11 -7
  356. package/packages/pi-coding-agent/dist/theme/theme.js.map +1 -1
  357. package/packages/pi-coding-agent/package.json +7 -7
  358. package/packages/pi-tui/package.json +2 -2
  359. package/packages/rpc-client/package.json +2 -2
  360. package/pkg/dist/theme/theme-schema.d.ts +75 -75
  361. package/pkg/dist/theme/theme-schema.d.ts.map +1 -1
  362. package/pkg/dist/theme/theme-schema.js +1 -1
  363. package/pkg/dist/theme/theme-schema.js.map +1 -1
  364. package/pkg/dist/theme/theme.d.ts.map +1 -1
  365. package/pkg/dist/theme/theme.js +11 -7
  366. package/pkg/dist/theme/theme.js.map +1 -1
  367. package/pkg/package.json +1 -1
  368. package/src/resources/extensions/claude-code-cli/models.ts +9 -0
  369. package/src/resources/extensions/claude-code-cli/tests/index.test.ts +14 -0
  370. package/src/resources/extensions/gsd/artifact-verification.ts +464 -0
  371. package/src/resources/extensions/gsd/auto/loop-deps.ts +1 -0
  372. package/src/resources/extensions/gsd/auto/session.ts +14 -0
  373. package/src/resources/extensions/gsd/auto/verification-retry-policy.ts +3 -1
  374. package/src/resources/extensions/gsd/auto-artifact-paths.ts +47 -1
  375. package/src/resources/extensions/gsd/auto-budget.ts +12 -1
  376. package/src/resources/extensions/gsd/auto-dispatch.ts +17 -7
  377. package/src/resources/extensions/gsd/auto-post-unit.ts +1 -1
  378. package/src/resources/extensions/gsd/auto-prompts.ts +7 -23
  379. package/src/resources/extensions/gsd/auto-recovery.ts +13 -518
  380. package/src/resources/extensions/gsd/auto-runtime-state.ts +4 -5
  381. package/src/resources/extensions/gsd/auto-timeout-recovery.ts +3 -2
  382. package/src/resources/extensions/gsd/auto-verification.ts +5 -1
  383. package/src/resources/extensions/gsd/auto.ts +23 -8
  384. package/src/resources/extensions/gsd/bootstrap/core-session-tools.ts +44 -0
  385. package/src/resources/extensions/gsd/bootstrap/db-tools.ts +5 -4
  386. package/src/resources/extensions/gsd/bootstrap/register-extension.ts +2 -0
  387. package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +43 -18
  388. package/src/resources/extensions/gsd/bootstrap/tests/write-gate-basepath.test.ts +49 -1
  389. package/src/resources/extensions/gsd/bootstrap/tool-call-loop-guard.ts +50 -37
  390. package/src/resources/extensions/gsd/bootstrap/write-gate.ts +16 -4
  391. package/src/resources/extensions/gsd/closeout-consistency-gate.ts +2 -1
  392. package/src/resources/extensions/gsd/commands/handlers/auto.ts +1 -1
  393. package/src/resources/extensions/gsd/commands-prefs-wizard.ts +1 -1
  394. package/src/resources/extensions/gsd/commands-usage.ts +1 -1
  395. package/src/resources/extensions/gsd/db/engine.ts +8 -1
  396. package/src/resources/extensions/gsd/db-memory-fts-schema.ts +45 -0
  397. package/src/resources/extensions/gsd/db-workspace.ts +61 -3
  398. package/src/resources/extensions/gsd/delegation-policy.ts +1 -1
  399. package/src/resources/extensions/gsd/docs/preferences-reference.md +2 -2
  400. package/src/resources/extensions/gsd/doctor-engine-checks.ts +233 -5
  401. package/src/resources/extensions/gsd/doctor-runtime-checks.ts +3 -0
  402. package/src/resources/extensions/gsd/doctor-types.ts +3 -0
  403. package/src/resources/extensions/gsd/exec-sandbox.ts +7 -2
  404. package/src/resources/extensions/gsd/flat-phase-migration.ts +44 -0
  405. package/src/resources/extensions/gsd/git-service.ts +64 -0
  406. package/src/resources/extensions/gsd/gitignore.ts +4 -1
  407. package/src/resources/extensions/gsd/guided-flow-queue.ts +20 -13
  408. package/src/resources/extensions/gsd/json-persistence.ts +20 -0
  409. package/src/resources/extensions/gsd/knowledge-backfill.ts +16 -10
  410. package/src/resources/extensions/gsd/layout-policy.ts +2 -1
  411. package/src/resources/extensions/gsd/markdown-renderer.ts +2 -10
  412. package/src/resources/extensions/gsd/memory-backfill.ts +26 -20
  413. package/src/resources/extensions/gsd/metrics.ts +4 -4
  414. package/src/resources/extensions/gsd/migrate-external.ts +8 -2
  415. package/src/resources/extensions/gsd/migration-auto-check.ts +23 -0
  416. package/src/resources/extensions/gsd/milestone-ids.ts +31 -2
  417. package/src/resources/extensions/gsd/orphan-stash-audit.ts +108 -20
  418. package/src/resources/extensions/gsd/prompts/code-review.md +6 -4
  419. package/src/resources/extensions/gsd/prompts/plan-milestone.md +2 -2
  420. package/src/resources/extensions/gsd/prompts/plan-slice.md +3 -3
  421. package/src/resources/extensions/gsd/root-write-leak-guard.ts +13 -1
  422. package/src/resources/extensions/gsd/safety/destructive-guard.ts +9 -1
  423. package/src/resources/extensions/gsd/safety/evidence-collector.ts +16 -1
  424. package/src/resources/extensions/gsd/safety/file-change-validator.ts +8 -2
  425. package/src/resources/extensions/gsd/skills/gsd-headless/references/commands.md +1 -1
  426. package/src/resources/extensions/gsd/state/derive/cache.ts +46 -0
  427. package/src/resources/extensions/gsd/state/derive/db-open.ts +45 -0
  428. package/src/resources/extensions/gsd/state/derive/from-db.ts +561 -0
  429. package/src/resources/extensions/gsd/state/derive/index.ts +104 -0
  430. package/src/resources/extensions/gsd/state/derive/interrupted-work.ts +31 -0
  431. package/src/resources/extensions/gsd/state-reconciliation/drift/stale-render.ts +36 -30
  432. package/src/resources/extensions/gsd/state-reconciliation/index.ts +50 -24
  433. package/src/resources/extensions/gsd/state-reconciliation/registry.ts +43 -28
  434. package/src/resources/extensions/gsd/state.ts +32 -732
  435. package/src/resources/extensions/gsd/tests/artifact-retry-cap.test.ts +4 -3
  436. package/src/resources/extensions/gsd/tests/auto-artifact-paths.test.ts +98 -1
  437. package/src/resources/extensions/gsd/tests/auto-budget-alerts.test.ts +14 -5
  438. package/src/resources/extensions/gsd/tests/auto-pause-double-entry-guard.test.ts +36 -0
  439. package/src/resources/extensions/gsd/tests/auto-paused-ui-cleanup.test.ts +182 -4
  440. package/src/resources/extensions/gsd/tests/auto-recovery.test.ts +35 -0
  441. package/src/resources/extensions/gsd/tests/auto-retry-mcp-churn-fixes.test.ts +30 -0
  442. package/src/resources/extensions/gsd/tests/commands-gsd-core.test.ts +1 -0
  443. package/src/resources/extensions/gsd/tests/complete-milestone.test.ts +28 -0
  444. package/src/resources/extensions/gsd/tests/complete-slice-reopen-handoff.test.ts +69 -0
  445. package/src/resources/extensions/gsd/tests/db-memory-fts-schema.test.ts +58 -3
  446. package/src/resources/extensions/gsd/tests/decisions-projection-from-memories.test.ts +51 -0
  447. package/src/resources/extensions/gsd/tests/destructive-guard.test.ts +44 -0
  448. package/src/resources/extensions/gsd/tests/dispatch-missing-task-plans.test.ts +143 -0
  449. package/src/resources/extensions/gsd/tests/doctor-scope-db-unavailable.test.ts +239 -2
  450. package/src/resources/extensions/gsd/tests/exec-sandbox.test.ts +16 -0
  451. package/src/resources/extensions/gsd/tests/file-change-validator.test.ts +40 -0
  452. package/src/resources/extensions/gsd/tests/flat-phase-migration.test.ts +37 -2
  453. package/src/resources/extensions/gsd/tests/gitignore-bg-shell-runtime.test.ts +4 -0
  454. package/src/resources/extensions/gsd/tests/integration/git-service.test.ts +11 -2
  455. package/src/resources/extensions/gsd/tests/json-persistence-atomic.test.ts +47 -0
  456. package/src/resources/extensions/gsd/tests/knowledge-backfill-projection.test.ts +35 -0
  457. package/src/resources/extensions/gsd/tests/memory-store.test.ts +48 -0
  458. package/src/resources/extensions/gsd/tests/merge-closeout-consistency-gate.test.ts +31 -1
  459. package/src/resources/extensions/gsd/tests/metrics-prune-cache-invalidation.test.ts +6 -0
  460. package/src/resources/extensions/gsd/tests/metrics.test.ts +1 -0
  461. package/src/resources/extensions/gsd/tests/migrate-external-worktree.test.ts +57 -0
  462. package/src/resources/extensions/gsd/tests/migration-auto-check.test.ts +70 -0
  463. package/src/resources/extensions/gsd/tests/orphan-stash-audit.test.ts +91 -7
  464. package/src/resources/extensions/gsd/tests/parsers-legacy-importers.test.ts +4 -1
  465. package/src/resources/extensions/gsd/tests/plan-slice-prompt.test.ts +10 -0
  466. package/src/resources/extensions/gsd/tests/plan-slice.test.ts +103 -4
  467. package/src/resources/extensions/gsd/tests/plan-task.test.ts +44 -1
  468. package/src/resources/extensions/gsd/tests/post-mutation-hook.test.ts +4 -2
  469. package/src/resources/extensions/gsd/tests/progressive-planning.test.ts +50 -14
  470. package/src/resources/extensions/gsd/tests/prompt-budget-enforcement.test.ts +58 -0
  471. package/src/resources/extensions/gsd/tests/prompt-contracts.test.ts +8 -6
  472. package/src/resources/extensions/gsd/tests/register-hooks-loop-guard-auto.test.ts +103 -0
  473. package/src/resources/extensions/gsd/tests/root-write-leak-guard.test.ts +20 -1
  474. package/src/resources/extensions/gsd/tests/runtime-invariant-modules.test.ts +15 -3
  475. package/src/resources/extensions/gsd/tests/stalled-tool-recovery.test.ts +56 -0
  476. package/src/resources/extensions/gsd/tests/state-reconciliation-drift.test.ts +115 -0
  477. package/src/resources/extensions/gsd/tests/tool-call-loop-guard.test.ts +140 -0
  478. package/src/resources/extensions/gsd/tests/tool-param-optionality.test.ts +6 -3
  479. package/src/resources/extensions/gsd/tests/undo.test.ts +74 -0
  480. package/src/resources/extensions/gsd/tests/uok-gitops-turn-action.test.ts +38 -0
  481. package/src/resources/extensions/gsd/tests/verification-retry-policy.test.ts +69 -4
  482. package/src/resources/extensions/gsd/tests/workflow-manifest.test.ts +96 -15
  483. package/src/resources/extensions/gsd/tests/workflow-mcp-preflight.test.ts +1 -0
  484. package/src/resources/extensions/gsd/tests/workflow-mcp.test.ts +8 -4
  485. package/src/resources/extensions/gsd/tests/workflow-tool-executors.test.ts +6 -5
  486. package/src/resources/extensions/gsd/tests/worktree-manager.test.ts +39 -0
  487. package/src/resources/extensions/gsd/tools/complete-milestone.ts +3 -2
  488. package/src/resources/extensions/gsd/tools/complete-slice.ts +3 -30
  489. package/src/resources/extensions/gsd/tools/complete-task.ts +7 -39
  490. package/src/resources/extensions/gsd/tools/plan-slice.ts +60 -47
  491. package/src/resources/extensions/gsd/tools/plan-task.ts +30 -5
  492. package/src/resources/extensions/gsd/undo.ts +47 -6
  493. package/src/resources/extensions/gsd/unit-registry.ts +11 -3
  494. package/src/resources/extensions/gsd/verification-gate.ts +8 -0
  495. package/src/resources/extensions/gsd/workflow-manifest.ts +141 -7
  496. package/src/resources/extensions/gsd/workflow-projections.ts +20 -14
  497. package/src/resources/extensions/gsd/worktree-manager.ts +41 -1
  498. package/dist/web/standalone/.next/static/chunks/2772.bfa657f49f955239.js +0 -1
  499. package/dist/web/standalone/.next/static/chunks/796.3976108148518f7d.js +0 -10
  500. package/dist/web/standalone/.next/static/chunks/app/_not-found/page-a6fb1847f67f167c.js +0 -1
  501. package/dist/web/standalone/.next/static/chunks/app/page-6644fc6ee8ca1247.js +0 -1
  502. package/dist/web/standalone/.next/static/chunks/next/dist/client/components/builtin/global-error-1115d46ac61b9823.js +0 -1
  503. package/dist/web/standalone/.next/static/chunks/webpack-7c1d97e39be2da11.js +0 -1
  504. /package/dist/web/standalone/.next/static/{SzEuqWX37DR9MEpEuQjP1 → zQLcXm0Za8lexoXtgDpMG}/_buildManifest.js +0 -0
  505. /package/dist/web/standalone/.next/static/{SzEuqWX37DR9MEpEuQjP1 → zQLcXm0Za8lexoXtgDpMG}/_ssgManifest.js +0 -0
@@ -40,8 +40,10 @@ export function dbPath(basePath) {
40
40
  * Used by the renderer to derive the phase number from the DB's milestone_id.
41
41
  */
42
42
  export function milestoneIdToPhaseNum(milestoneId) {
43
- // No $ anchor: accepts bare (M012) and team-suffixed (M012-abc123) IDs.
43
+ // No $ anchor: accepts bare (M012), team-suffixed (M012-abc123), and legacy numeric IDs.
44
44
  const m = milestoneId.match(/^M0*(\d+)/i);
45
+ if (!m && /^\d+$/.test(milestoneId))
46
+ return Number.parseInt(milestoneId, 10);
45
47
  return m ? Number.parseInt(m[1], 10) : 1;
46
48
  }
47
49
  /** Team-mode suffix from milestone ids like M001-abc123. */
@@ -518,13 +518,8 @@ export async function renderRoadmapFromDb(basePath, milestoneId) {
518
518
  * @returns true if the roadmap was written, false on skip/error
519
519
  */
520
520
  export async function renderRoadmapCheckboxes(basePath, milestoneId) {
521
- const slices = getMilestoneSlices(milestoneId);
522
- if (slices.length === 0) {
523
- process.stderr.write(`markdown-renderer: no slices found for milestone ${milestoneId}\n`);
524
- return false;
525
- }
526
- await renderRoadmapFromDb(basePath, milestoneId);
527
- return true;
521
+ const rendered = await renderRoadmapFromDb(basePath, milestoneId);
522
+ return !("skipped" in rendered);
528
523
  }
529
524
  /**
530
525
  * Project milestone-level artifacts (CONTEXT, RESEARCH, VALIDATION, etc.) from
@@ -33,8 +33,8 @@ import { logWarning } from "./workflow-logger.js";
33
33
  * decision is checked individually; only decisions whose id is already
34
34
  * present in the memory store are skipped. A user-authored memory with
35
35
  * their own `sourceDecisionId` does NOT abort the backfill.
36
- * - Best-effort: never throws. Logs and returns 0 on failure so a broken
37
- * backfill cannot block agent startup.
36
+ * - Best-effort: never throws. Failed memory inserts are logged and skipped;
37
+ * setup/read failures log and return 0 so backfill cannot block startup.
38
38
  * - Full migration (ADR-013 Stage 2a): both active and superseded rows are
39
39
  * migrated. `structured_fields.superseded_by` preserves the supersedes
40
40
  * chain so the DECISIONS.md projection regen can source from memories
@@ -117,25 +117,32 @@ export function backfillDecisionsToMemories() {
117
117
  continue;
118
118
  }
119
119
  const content = synthesizeDecisionMemoryContent(row);
120
- const id = createMemory({
121
- category: "architecture",
122
- content,
123
- scope: row.scope || "project",
124
- confidence: 0.85,
125
- structuredFields: {
126
- sourceDecisionId: row.id,
127
- when_context: row.when_context,
128
- scope: row.scope,
129
- decision: row.decision,
130
- choice: row.choice,
131
- rationale: row.rationale,
132
- made_by: row.made_by,
133
- revisable: row.revisable,
134
- superseded_by: row.superseded_by,
135
- },
136
- });
137
- if (id)
138
- written += 1;
120
+ try {
121
+ const id = createMemory({
122
+ category: "architecture",
123
+ content,
124
+ scope: row.scope || "project",
125
+ confidence: 0.85,
126
+ structuredFields: {
127
+ sourceDecisionId: row.id,
128
+ when_context: row.when_context,
129
+ scope: row.scope,
130
+ decision: row.decision,
131
+ choice: row.choice,
132
+ rationale: row.rationale,
133
+ made_by: row.made_by,
134
+ revisable: row.revisable,
135
+ superseded_by: row.superseded_by,
136
+ },
137
+ });
138
+ if (id)
139
+ written += 1;
140
+ }
141
+ catch (rowErr) {
142
+ const message = rowErr instanceof Error ? rowErr.message : String(rowErr);
143
+ logWarning("memory-backfill", `decisions->memories backfill skipped ${row.id}: ${message}`);
144
+ continue;
145
+ }
139
146
  }
140
147
  if (healed > 0) {
141
148
  logWarning("memory-backfill", `decisions->memories drift healed: ${healed} row${healed === 1 ? "" : "s"} updated superseded_by`);
@@ -17,7 +17,7 @@ import { join } from "node:path";
17
17
  import { openSync, closeSync, unlinkSync, statSync, writeFileSync } from "node:fs";
18
18
  import { gsdRoot } from "./paths.js";
19
19
  import { getAndClearSkills } from "./skill-telemetry.js";
20
- import { loadJsonFile, loadJsonFileOrNull, saveJsonFile } from "./json-persistence.js";
20
+ import { loadJsonFile, loadJsonFileOrNull, saveJsonFileCompact } from "./json-persistence.js";
21
21
  import { parseUnitId } from "./unit-id.js";
22
22
  import { buildAuditEnvelope, emitUokAuditEvent } from "./uok/audit.js";
23
23
  import { isUnifiedAuditEnabled } from "./uok/audit-toggle.js";
@@ -636,7 +636,7 @@ export function pruneMetricsLedger(base, keepCount) {
636
636
  return 0;
637
637
  const removed = disk.units.length - keepCount;
638
638
  disk.units = keepNewestUnits(disk.units, keepCount);
639
- saveJsonFile(metricsPath(base), disk);
639
+ saveJsonFileCompact(metricsPath(base), disk);
640
640
  // Keep the in-memory ledger in sync if it is loaded for this session.
641
641
  if (ledger) {
642
642
  ledger.units = keepNewestUnits(ledger.units, keepCount);
@@ -799,7 +799,7 @@ function saveLedger(base, data) {
799
799
  : dataUnits;
800
800
  merged.sort(compareUnitsByTime);
801
801
  data.units = keepNewestUnits(merged);
802
- saveJsonFile(path, data);
802
+ saveJsonFileCompact(path, data);
803
803
  }
804
804
  finally {
805
805
  releaseLock(lockPath);
@@ -813,6 +813,6 @@ function saveLedger(base, data) {
813
813
  // read-merge-write sequence without mutual exclusion.
814
814
  logWarning("fs", "saveLedger: lock not acquired — falling back to direct write (no merge)");
815
815
  data.units = keepNewestUnits(data.units);
816
- saveJsonFile(path, data);
816
+ saveJsonFileCompact(path, data);
817
817
  }
818
818
  }
@@ -110,6 +110,7 @@ export function migrateToExternalState(basePath) {
110
110
  }
111
111
  // Copy contents to external dir, skipping worktrees/
112
112
  const entries = readdirSync(migratingPath, { withFileTypes: true });
113
+ const copyFailures = [];
113
114
  for (const entry of entries) {
114
115
  if (entry.name === "worktrees")
115
116
  continue; // worktrees stay local
@@ -123,10 +124,18 @@ export function migrateToExternalState(basePath) {
123
124
  cpSync(src, dst, { force: true });
124
125
  }
125
126
  }
126
- catch {
127
- // Non-fatal: continue with other files
127
+ catch (copyErr) {
128
+ copyFailures.push(`${entry.name}: ${getErrorMessage(copyErr)}`);
128
129
  }
129
130
  }
131
+ if (copyFailures.length > 0) {
132
+ try {
133
+ rmSync(localGsd, { force: true });
134
+ }
135
+ catch { /* may not exist */ }
136
+ renameSync(migratingPath, localGsd);
137
+ return { migrated: false, error: `Migration copy failed: ${copyFailures.join("; ")}` };
138
+ }
130
139
  // Create symlink .gsd -> external path
131
140
  symlinkSync(externalPath, localGsd, "junction");
132
141
  // Verify the symlink resolves correctly before removing the backup (#1377).
@@ -45,6 +45,27 @@ function scanHasExtraIdentities(a, b) {
45
45
  hasExtra(a.slices, b.slices) ||
46
46
  hasExtra(a.tasks, b.tasks));
47
47
  }
48
+ function paddedMilestoneId(id) {
49
+ return /^\d+$/.test(id) ? `M${id.padStart(3, "0")}` : null;
50
+ }
51
+ function replaceSetPrefix(values, from, to) {
52
+ for (const value of [...values]) {
53
+ if (value !== from && !value.startsWith(`${from}/`))
54
+ continue;
55
+ values.delete(value);
56
+ values.add(`${to}${value.slice(from.length)}`);
57
+ }
58
+ }
59
+ function alignNumericMarkdownIdsWithDb(markdownScan, dbScan) {
60
+ for (const dbId of dbScan.milestones) {
61
+ const paddedId = paddedMilestoneId(dbId);
62
+ if (!paddedId || dbScan.milestones.has(paddedId) || !markdownScan.milestones.has(paddedId))
63
+ continue;
64
+ replaceSetPrefix(markdownScan.milestones, paddedId, dbId);
65
+ replaceSetPrefix(markdownScan.slices, paddedId, dbId);
66
+ replaceSetPrefix(markdownScan.tasks, paddedId, dbId);
67
+ }
68
+ }
48
69
  /**
49
70
  * True when the DB holds any milestone/slice/task identity the markdown lacks —
50
71
  * i.e. a `/gsd recover --confirm` (markdown → DB) would DELETE authoritative DB
@@ -126,6 +147,7 @@ export async function checkMarkdownHierarchyAgainstDb(basePath) {
126
147
  refreshWorkflowDatabaseFromDisk();
127
148
  const dbScan = scanDbHierarchy();
128
149
  const beforeDb = dbScan.counts;
150
+ alignNumericMarkdownIdsWithDb(markdownScan, dbScan);
129
151
  // Discussion-phase scratch: a milestone dir with no ROADMAP and no DB row is
130
152
  // a pre-registration discussion artifact (CONTEXT/CONTEXT-DRAFT only — the
131
153
  // queued DB row is inserted only at discussion handoff). Treating it as
@@ -123,7 +123,8 @@ export function clearReservedMilestoneIds() {
123
123
  reservedMilestoneIds.clear();
124
124
  }
125
125
  // ─── Discovery ──────────────────────────────────────────────────────────────
126
- function scanMilestoneIdsFromDir(dir) {
126
+ function scanMilestoneIdsFromDir(basePath, dir) {
127
+ const legacyNumericIds = idsWithLegacyNumericDirs(basePath);
127
128
  return readdirSync(dir, { withFileTypes: true })
128
129
  .filter((d) => d.isDirectory())
129
130
  .map((d) => {
@@ -131,6 +132,12 @@ function scanMilestoneIdsFromDir(dir) {
131
132
  if (MILESTONE_ID_RE.test(d.name)) {
132
133
  return d.name;
133
134
  }
135
+ // Legacy recovery/imports may contain bare numeric milestone directories
136
+ // (for example `milestones/15/15-ROADMAP.md`). The DB can preserve that
137
+ // id, and rebuild renders it, so drift scans must see it too.
138
+ if (/^\d+$/.test(d.name)) {
139
+ return d.name;
140
+ }
134
141
  // Legacy layout: M001-abcdef-slug descriptor directories
135
142
  const legacyMatch = d.name.match(/^(M\d{3}(?:-[a-z0-9]{6})?)-/);
136
143
  if (legacyMatch) {
@@ -144,12 +151,35 @@ function scanMilestoneIdsFromDir(dir) {
144
151
  if (MILESTONE_ID_RE.test(fromSlug)) {
145
152
  return fromSlug;
146
153
  }
154
+ const numericId = String(phaseNum);
155
+ if (legacyNumericIds.has(numericId)) {
156
+ return numericId;
157
+ }
147
158
  return `M${String(phaseNum).padStart(3, "0")}`;
148
159
  }
149
160
  return null;
150
161
  })
151
162
  .filter((id) => id !== null);
152
163
  }
164
+ function idsWithLegacyNumericDirs(basePath) {
165
+ const legacyDir = join(gsdProjectionRoot(basePath), "milestones");
166
+ const ids = new Set();
167
+ try {
168
+ for (const entry of readdirSync(legacyDir, { withFileTypes: true })) {
169
+ if (entry.isDirectory() && /^\d+$/.test(entry.name))
170
+ ids.add(entry.name);
171
+ }
172
+ }
173
+ catch (err) {
174
+ // A missing legacy directory is the common, benign case (nothing to
175
+ // consult). Only surface a real failure when the directory exists but
176
+ // could not be read.
177
+ if (existsSync(legacyDir)) {
178
+ logWarning("engine", `idsWithLegacyNumericDirs: ${legacyDir} exists but readdirSync failed — ${getErrorMessage(err)}`);
179
+ }
180
+ }
181
+ return ids;
182
+ }
153
183
  /** Scan the milestones directory and return IDs sorted by queue order (or numeric fallback). */
154
184
  export function findMilestoneIds(basePath) {
155
185
  const root = gsdProjectionRoot(basePath);
@@ -163,7 +193,7 @@ export function findMilestoneIds(basePath) {
163
193
  const ids = new Set();
164
194
  for (const dir of dirs) {
165
195
  try {
166
- for (const id of scanMilestoneIdsFromDir(dir))
196
+ for (const id of scanMilestoneIdsFromDir(basePath, dir))
167
197
  ids.add(id);
168
198
  }
169
199
  catch (err) {
@@ -26,16 +26,78 @@ function _isAlreadyRestoredApplyError(err) {
26
26
  return /already exists, no checkout/i.test(message);
27
27
  }
28
28
  export { _isAlreadyRestoredApplyError };
29
+ function gitOutput(basePath, args) {
30
+ return execFileSync("git", args, {
31
+ cwd: basePath,
32
+ stdio: ["ignore", "pipe", "pipe"],
33
+ encoding: "utf-8",
34
+ env: GIT_NO_PROMPT_ENV,
35
+ });
36
+ }
37
+ function listStashUntrackedPaths(basePath, stashRef) {
38
+ try {
39
+ return gitOutput(basePath, ["ls-tree", "-r", "-z", "--name-only", `${stashRef}^3`]).split("\0").filter(Boolean);
40
+ }
41
+ catch {
42
+ return null;
43
+ }
44
+ }
45
+ function listStashTrackedPaths(basePath, stashRef) {
46
+ try {
47
+ return gitOutput(basePath, ["diff", "--name-only", "-z", `${stashRef}^1`, stashRef]).split("\0").filter(Boolean);
48
+ }
49
+ catch {
50
+ return null;
51
+ }
52
+ }
53
+ function readWorkingTreeStatus(basePath) {
54
+ try {
55
+ return gitOutput(basePath, ["status", "--porcelain", "-z", "--untracked-files=all"])
56
+ .split("\0")
57
+ .filter(Boolean)
58
+ .map((entry) => ({ code: entry.slice(0, 2), path: entry.slice(3) }));
59
+ }
60
+ catch {
61
+ return null;
62
+ }
63
+ }
64
+ function isAlreadyRestoredUntrackedStatus(basePath, stashRef, statusEntries) {
65
+ if (statusEntries.length === 0 || statusEntries.some((entry) => entry.code !== "??"))
66
+ return false;
67
+ const stashTrackedPaths = listStashTrackedPaths(basePath, stashRef);
68
+ if (!stashTrackedPaths || stashTrackedPaths.length > 0)
69
+ return false;
70
+ const stashUntrackedPaths = listStashUntrackedPaths(basePath, stashRef);
71
+ if (!stashUntrackedPaths || stashUntrackedPaths.length === 0)
72
+ return false;
73
+ const stashUntrackedPathSet = new Set(stashUntrackedPaths);
74
+ const workingTreeUntrackedPathSet = new Set(statusEntries.map((entry) => entry.path));
75
+ // "Already restored" requires the working tree's untracked paths to match the
76
+ // stash's untracked paths exactly, in BOTH directions:
77
+ // 1. every current untracked path comes from the stash (no unexplained user
78
+ // work that an apply would clobber), AND
79
+ // 2. every stash untracked path is already present in the working tree.
80
+ // Without (2), a partial restore (where only some stash files were recovered)
81
+ // would be misread as fully restored: the audit would no-op without applying
82
+ // or warning, leaving the remaining pre-merge files missing.
83
+ return (statusEntries.every((entry) => stashUntrackedPathSet.has(entry.path)) &&
84
+ stashUntrackedPaths.every((path) => workingTreeUntrackedPathSet.has(path)));
85
+ }
86
+ function manualApplyWarning(stashRef, milestoneId, reason) {
87
+ return (`Pre-merge stash ${stashRef} for milestone ${milestoneId} not auto-applied: ${reason}; ` +
88
+ `run \`git stash apply ${stashRef}\` manually to restore your pre-merge changes.`);
89
+ }
29
90
  /**
30
91
  * Audit `git stash list` for orphaned `gsd-preflight-stash:M00x:*` entries.
31
92
  *
32
93
  * The matching merge code in `phases.ts` previously skipped the postflight
33
94
  * pop whenever `mergeAndExit` threw, leaking the user's pre-merge working
34
- * tree into the stash list. For every preflight-stash entry whose milestone
35
- * is now complete (per the supplied callback), `git stash apply` is invoked
95
+ * tree into the stash list. Completed-milestone stashes are only auto-applied
96
+ * when the working tree is clean and the stash does not modify tracked files.
97
+ * Dirty trees and tracked-file stashes are left untouched with a manual
98
+ * recovery warning. When auto-apply is safe, `git stash apply` is invoked —
36
99
  * NOT `pop`. The stash entry stays in the list so the user retains a backup
37
- * if the apply produces unexpected merge results. Idempotent across repeated
38
- * startup runs.
100
+ * if the apply produces unexpected merge results.
39
101
  *
40
102
  * Failures are best-effort: a list error (no repo, git unavailable) returns
41
103
  * an empty result. An apply error becomes a warning the user sees alongside
@@ -45,12 +107,7 @@ export function auditOrphanedPreflightStashes(basePath, isMilestoneComplete) {
45
107
  const result = { applied: [], warnings: [] };
46
108
  let listOutput;
47
109
  try {
48
- listOutput = execFileSync("git", ["stash", "list", "--format=%gd%x00%s"], {
49
- cwd: basePath,
50
- stdio: ["ignore", "pipe", "pipe"],
51
- encoding: "utf-8",
52
- env: GIT_NO_PROMPT_ENV,
53
- });
110
+ listOutput = gitOutput(basePath, ["stash", "list", "--format=%gd%x00%s"]);
54
111
  }
55
112
  catch {
56
113
  return result;
@@ -78,13 +135,32 @@ export function auditOrphanedPreflightStashes(basePath, isMilestoneComplete) {
78
135
  }
79
136
  if (!complete)
80
137
  continue;
138
+ const statusEntries = readWorkingTreeStatus(basePath);
139
+ if (!statusEntries) {
140
+ result.warnings.push(manualApplyWarning(ref, milestoneId, "could not verify working tree status"));
141
+ continue;
142
+ }
143
+ if (statusEntries.length > 0) {
144
+ if (isAlreadyRestoredUntrackedStatus(basePath, ref, statusEntries))
145
+ continue;
146
+ result.warnings.push(manualApplyWarning(ref, milestoneId, "working tree not clean"));
147
+ continue;
148
+ }
149
+ const trackedPaths = listStashTrackedPaths(basePath, ref);
150
+ if (trackedPaths === null) {
151
+ result.warnings.push(manualApplyWarning(ref, milestoneId, "could not inspect tracked paths in stash"));
152
+ continue;
153
+ }
154
+ if (trackedPaths.length > 0) {
155
+ // A retained tracked-file stash has no durable marker showing whether a
156
+ // clean tree needs first recovery or would be re-mutated by an old backup.
157
+ const preview = trackedPaths.slice(0, 5).join(", ");
158
+ const suffix = trackedPaths.length > 5 ? `, and ${trackedPaths.length - 5} more` : "";
159
+ result.warnings.push(manualApplyWarning(ref, milestoneId, `stash modifies tracked files (${preview}${suffix})`));
160
+ continue;
161
+ }
81
162
  try {
82
- execFileSync("git", ["stash", "apply", "--quiet", ref], {
83
- cwd: basePath,
84
- stdio: ["ignore", "pipe", "pipe"],
85
- encoding: "utf-8",
86
- env: GIT_NO_PROMPT_ENV,
87
- });
163
+ gitOutput(basePath, ["stash", "apply", "--quiet", ref]);
88
164
  result.applied.push({ milestoneId, stashRef: ref });
89
165
  }
90
166
  catch (err) {
@@ -16,18 +16,20 @@ You are running the GSD **code-review** workflow — review source files changed
16
16
 
17
17
  1. **Determine the file set.** Use the explicit `--files` list if provided. Otherwise derive the changed source files from the active slice's recent commits / SUMMARY, or fall back to the git diff against the base branch. Exclude `.gsd/`, lockfiles, generated/vendored code, and docs unless `--files` names them.
18
18
 
19
- 2. **Review each file** at the requested depth:
19
+ 2. **Gather diff-first context.** Run `git diff` for the file set (or the relevant commit range) and use that as the primary review evidence. Use `read` only when the diff is insufficient — new/untracked files, truncated hunks, or missing surrounding context needed for a finding. Do **not** read every changed file when the diff already covers the edits. If the Tool Call Loop Guard blocks a tool, stop calling tools for the rest of this turn and continue in text.
20
+
21
+ 3. **Review at the requested depth:**
20
22
  - **quick** — bugs, security, and correctness only.
21
23
  - **standard** (default) — quick + maintainability, error handling, edge cases.
22
24
  - **deep** — standard + performance, concurrency, API design, test coverage gaps.
23
25
 
24
26
  Ground every finding in the actual code with file path + line reference. Categorize each by severity (critical / warning / nit) and type (bug, security, quality, performance).
25
27
 
26
- 3. **Write the review.** Produce `.gsd/reviews/{{reviewId}}-REVIEW.md` with the findings table and per-finding detail (location, issue, suggested fix).
28
+ 4. **Write the review.** Produce `.gsd/reviews/{{reviewId}}-REVIEW.md` with the findings table and per-finding detail (location, issue, suggested fix).
27
29
 
28
- 4. **Present results.** Summarize counts by severity and list the critical findings first.
30
+ 5. **Present results.** Summarize counts by severity and list the critical findings first.
29
31
 
30
- 5. **Fix mode** (only when `--fix` is set): for each finding that is safely auto-fixable (deterministic, no behavior change beyond the fix), apply it. After each fix batch, run the project's tests. Commit atomically with the finding IDs referenced in the message. Do not auto-apply findings that are ambiguous or that change public behavior — surface those for a human decision instead.
32
+ 6. **Fix mode** (only when `--fix` is set): for each finding that is safely auto-fixable (deterministic, no behavior change beyond the fix), apply it. After each fix batch, run the project's tests. Commit atomically with the finding IDs referenced in the message. Do not auto-apply findings that are ambiguous or that change public behavior — surface those for a human decision instead.
31
33
 
32
34
  ## Success criteria
33
35
 
@@ -104,8 +104,8 @@ If the preference is off, ignore this section and plan every slice fully.
104
104
 
105
105
  If the roadmap has one slice, also plan S01 and its tasks inline:
106
106
 
107
- 1. After `gsd_plan_milestone` returns, call `gsd_plan_slice` for S01 with full task breakdown.
108
- 2. Use inlined **Slice Plan** and **Task Plan** templates for tool parameters.
107
+ 1. After `gsd_plan_milestone` returns, call `gsd_plan_slice` for S01 with slice metadata only; omit `tasks`.
108
+ 2. Then call `gsd_plan_task` once per S01 task. Use inlined **Slice Plan** and **Task Plan** templates for tool parameters.
109
109
  3. Keep simple slices lean. Omit Proof Level, Integration Closure, and Observability if all would be "none"; executable verification commands are enough.
110
110
 
111
111
  Do **not** write plan files manually; use DB-backed tools so state stays consistent.
@@ -45,8 +45,8 @@ If slice research is inlined, trust its architectural findings, but verify every
45
45
  6. Include Threat Surface (Q3), Requirement Impact (Q4), proof level, observability, integration closure, Failure Modes (Q5), Load Profile (Q6), and Negative Tests (Q7) only where applicable.
46
46
  7. Right-size tasks. Simple slices can be one task; split only when context, ownership, or verification boundaries justify it.
47
47
  8. Task `verify` commands must be safe, simple commands. Do not use shell pipes, redirects, semicolons, backticks, command substitution, output trimming, or grep regex alternation with `|`. If multiple checks are needed, create a small test file and run it with `node --test` or a package test script, or use separate simple commands joined only with `&&`. For absence checks, verify a pattern does not exist with `! grep -q 'pattern' file` or `! rg -q 'pattern' file`; do not use `grep -c` or `rg -c` to assert zero matches because count commands exit 1 when they find zero matches, and the verification gate treats that as failure.
48
- 9. Each task needs the exact `gsd_plan_slice.tasks[]` shape: `taskId`, `title`, `description`, `estimate`, `files`, `verify`, `inputs`, `expectedOutput`, and optional `observabilityImpact`. `description` should contain the Why / Do / Done-when narrative. `files`, `inputs`, and `expectedOutput` must be JSON arrays of strings, even when there is only one path (for example, `"inputs": ["src/index.ts"]`, never `"inputs": "src/index.ts"`). Use paths relative to `{{workingDirectory}}`; do not put absolute paths to the original checkout or any directory outside `{{workingDirectory}}` in `files`, `inputs`, `expectedOutput`, or verification commands. **`expectedOutput` must only list files the task actually creates or overwrites on disk.** Do NOT include files the task merely reads, verifies, tests, or describes — those belong in `inputs`, `verify`, `description`, or slice success criteria. If a task is a pure verification or test task that produces no new files, `expectedOutput` must be `[]`; if it writes a test-result log or assertion output file, list only that concrete file path. A file that does not yet exist on disk and is needed as an `input` must be produced by an earlier task's `expectedOutput` — if no prior task creates it, add a task before this one that does. Never list GSD planning artifacts — anything under `.gsd/`, `.planning/`, or `.audits/`, or artifact names like `M001-CONTEXT.md` / `S01-PLAN.md` — in `inputs`, `files`, or `expectedOutput`: their content is preloaded as context, and they are written by workflow tools, not by tasks.
49
- 10. Persist with `gsd_plan_slice` using `milestoneId`, `sliceId`, `goal`, optional `successCriteria`/`proofLevel`/`integrationClosure`/`observabilityImpact`, and `tasks`. `gsd_plan_slice` handles task persistence transactionally and renders `{{outputPath}}` plus task plans; do not call `gsd_plan_task`. The DB-backed tool is the canonical write path. Do **not** rely on direct `PLAN.md` writes as the source of truth.
48
+ 9. Each task persisted with `gsd_plan_task` needs the exact shape: `milestoneId`, `sliceId`, `taskId`, `title`, `description`, `estimate`, `files`, `verify`, `inputs`, `expectedOutput`, and optional `observabilityImpact`. `description` should contain the Why / Do / Done-when narrative. Any npm package name in a task description's install/add instructions (`npm install`, `yarn add`, `pnpm add`) or in `require('...')` or `import ... from '...'` code examples is subject to pre-execution registry validation; reference only packages that exist on the public npm registry, and remove or correct any package name that is not real. `files`, `inputs`, and `expectedOutput` must be JSON arrays of strings, even when there is only one path (for example, `"inputs": ["src/index.ts"]`, never `"inputs": "src/index.ts"`). Use paths relative to `{{workingDirectory}}`; do not put absolute paths to the original checkout or any directory outside `{{workingDirectory}}` in `files`, `inputs`, `expectedOutput`, or verification commands. **`expectedOutput` must only list files the task actually creates or overwrites on disk.** Do NOT include files the task merely reads, verifies, tests, or describes — those belong in `inputs`, `verify`, `description`, or slice success criteria. If a task is a pure verification or test task that produces no new files, `expectedOutput` must be `[]`; if it writes a test-result log or assertion output file, list only that concrete file path. A file that does not yet exist on disk and is needed as an `input` must be produced by an earlier task's `expectedOutput` — if no prior task creates it, add a task before this one that does. Never list GSD planning artifacts — anything under `.gsd/`, `.planning/`, or `.audits/`, or artifact names like `M001-CONTEXT.md` / `S01-PLAN.md` — in `inputs`, `files`, or `expectedOutput`: their content is preloaded as context, and they are written by workflow tools, not by tasks.
49
+ 10. Persist incrementally through DB-backed tools. First call `gsd_plan_slice` with `milestoneId`, `sliceId`, `goal`, and optional `successCriteria`/`proofLevel`/`integrationClosure`/`observabilityImpact`; omit `tasks` for this metadata call. Then call `gsd_plan_task` once per task, using the task shape above. Each successful tool call saves progress and re-renders `{{outputPath}}` from DB. The DB-backed tools are the canonical write path. Do **not** rely on direct `PLAN.md` writes as the source of truth.
50
50
  11. Self-audit before finishing: goal/demo closure, requirement coverage, deliverable coverage audit (cross-check every file listed in CONTEXT.md `## Scope` / `### In Scope` against task `files` or `expectedOutput`), locked decisions, concrete paths, dependency order, wiring, scope size, proof truthfulness, feature completeness, and quality gates. Quality gates: non-trivial slices/tasks include specific Q3-Q7 coverage where applicable.
51
51
  12. If planning creates structural decisions, call `gsd_decision_save` for each; the tool persists the decision and regenerates `.gsd/DECISIONS.md`.
52
52
  13. {{commitInstruction}}
@@ -55,6 +55,6 @@ The slice directory already exists. Do not mkdir.
55
55
 
56
56
  **Autonomous execution:** no human is available. Do not call `ask_user_questions` or `secure_env_collect`; make reasonable assumptions and document them.
57
57
 
58
- **You MUST call `gsd_plan_slice` to persist planning state before finishing, unless the stale-path safety rule above stops the unit before safe planning can occur.**
58
+ **You MUST call `gsd_plan_slice` and then `gsd_plan_task` once for each planned task before finishing, unless the stale-path safety rule above stops the unit before safe planning can occur.**
59
59
 
60
60
  When done, say: "Slice {{sliceId}} planned." Say this exactly once — if you already said it in a prior message, do not repeat it.
@@ -4,9 +4,15 @@ import { execFileSync } from "node:child_process";
4
4
  import { createHash } from "node:crypto";
5
5
  import { existsSync, readFileSync, statSync } from "node:fs";
6
6
  import { join } from "node:path";
7
+ import { GSD_RUNTIME_PATTERNS } from "./gitignore.js";
7
8
  const MAX_SYNC_FINGERPRINT_BYTES = 1_500_000_000;
9
+ const ROOT_RUNTIME_PATH_PREFIXES = Array.from(new Set(GSD_RUNTIME_PATTERNS.map((pattern) => {
10
+ const path = pattern.replace(/\/+$/, "");
11
+ const slash = path.indexOf("/");
12
+ return slash === -1 ? path : path.slice(0, slash);
13
+ })));
8
14
  function isRootRuntimePath(path) {
9
- return path === ".gsd" || path.startsWith(".gsd/");
15
+ return ROOT_RUNTIME_PATH_PREFIXES.some((prefix) => path === prefix || path.startsWith(`${prefix}/`));
10
16
  }
11
17
  function fileFingerprint(rootPath, relPath) {
12
18
  const absPath = join(rootPath, relPath);
@@ -20,14 +20,21 @@ const DESTRUCTIVE_PATTERNS = [
20
20
  { pattern: /\baws\s+\w+\s+(delete|create|put|remove|terminate)\b/i, label: "AWS mutation" },
21
21
  { pattern: /\bkubectl\s+(delete|apply)\b/i, label: "kubectl mutation" },
22
22
  ];
23
+ function stripQuotedAndComments(command) {
24
+ return command
25
+ .replace(/"(?:[^"\\]|\\.)*"/g, '""')
26
+ .replace(/'(?:[^'\\]|\\.)*'/g, "''")
27
+ .replace(/(^|\s)#.*$/g, "$1");
28
+ }
23
29
  /**
24
30
  * Classify a bash command for destructive operations.
25
31
  * Returns the list of matched destructive pattern labels.
26
32
  */
27
33
  export function classifyCommand(command) {
34
+ const commandToClassify = stripQuotedAndComments(command);
28
35
  const labels = [];
29
36
  for (const { pattern, label } of DESTRUCTIVE_PATTERNS) {
30
- if (pattern.test(command)) {
37
+ if (pattern.test(commandToClassify)) {
31
38
  // Deduplicate labels (e.g., two force-push patterns)
32
39
  if (!labels.includes(label))
33
40
  labels.push(label);
@@ -27,10 +27,14 @@ const EXECUTION_TOOL_NAMES = new Set([
27
27
  const MCP_EXECUTION_TOOL_RE = /^mcp__.+__gsd_(?:uat_)?exec(?:_search)?$/;
28
28
  // ─── Module State ───────────────────────────────────────────────────────────
29
29
  let unitEvidence = [];
30
+ let lastWritePath = null;
31
+ let lastWriteSig = null;
30
32
  // ─── Public API ─────────────────────────────────────────────────────────────
31
33
  /** Reset all evidence for a new unit. Call at unit start. */
32
34
  export function resetEvidence() {
33
35
  unitEvidence = [];
36
+ lastWritePath = null;
37
+ lastWriteSig = null;
34
38
  }
35
39
  /** Get a read-only view of all evidence collected for the current unit. */
36
40
  export function getEvidence() {
@@ -95,10 +99,15 @@ function isEvidenceArray(data) {
95
99
  export function saveEvidenceToDisk(basePath, milestoneId, sliceId, taskId) {
96
100
  try {
97
101
  const path = evidencePath(basePath, milestoneId, sliceId, taskId);
102
+ const body = JSON.stringify(unitEvidence, null, 2) + "\n";
103
+ if (path === lastWritePath && body === lastWriteSig)
104
+ return;
98
105
  mkdirSync(dirname(path), { recursive: true });
99
106
  const tmp = `${path}.tmp.${randomBytes(4).toString("hex")}`;
100
- writeFileSync(tmp, JSON.stringify(unitEvidence, null, 2) + "\n", "utf-8");
107
+ writeFileSync(tmp, body, "utf-8");
101
108
  renameSync(tmp, path);
109
+ lastWritePath = path;
110
+ lastWriteSig = body;
102
111
  }
103
112
  catch {
104
113
  // Non-fatal — don't let persistence failures break unit execution
@@ -112,6 +121,8 @@ export function saveEvidenceToDisk(basePath, milestoneId, sliceId, taskId) {
112
121
  */
113
122
  export function loadEvidenceFromDisk(basePath, milestoneId, sliceId, taskId) {
114
123
  try {
124
+ lastWritePath = null;
125
+ lastWriteSig = null;
115
126
  const path = evidencePath(basePath, milestoneId, sliceId, taskId);
116
127
  if (!existsSync(path))
117
128
  return;
@@ -136,6 +147,10 @@ export function clearEvidenceFromDisk(basePath, milestoneId, sliceId, taskId) {
136
147
  if (existsSync(path)) {
137
148
  unlinkSync(path);
138
149
  }
150
+ if (path === lastWritePath) {
151
+ lastWritePath = null;
152
+ lastWriteSig = null;
153
+ }
139
154
  }
140
155
  catch {
141
156
  // Non-fatal
@@ -44,8 +44,11 @@ export function validateFileChanges(basePath, expectedOutput, plannedFiles, file
44
44
  const actualFiles = getChangedFilesFromLastCommit(basePath);
45
45
  if (!actualFiles)
46
46
  return null;
47
- // Filter out .gsd/ internal files — only validate project source files
48
- const projectFiles = actualFiles.filter(f => !f.startsWith(".gsd/") && !f.startsWith(".gsd\\"));
47
+ // Filter out GSD-internal paths — only validate project source files.
48
+ const projectFiles = actualFiles.filter((f) => !f.startsWith(".gsd/") &&
49
+ !f.startsWith(".gsd\\") &&
50
+ !f.startsWith(".gsd-backups/") &&
51
+ !f.startsWith(".gsd-backups\\"));
49
52
  // Normalize expected paths (strip leading ./ or /)
50
53
  const normalizedExpected = new Set([...allExpected].map((f) => normalizePlannedFileReference(f).replace(/^\.\//, "").replace(/^\//, "")));
51
54
  // Build allowlist matchers once (dot: true so patterns like `**/.hidden` work).
@@ -66,7 +66,7 @@ These commands dispatch native GSD prompts adapted to the milestone, slice, and
66
66
  | `progress` | Summarize recent work; can route `--next` or `--do "..."` |
67
67
  | `health` | Check `.gsd/` integrity (`--repair`, `--context`) |
68
68
  | `surface` | Manage surfaced skills and extensions |
69
- | `code-review` | Review changed source for bugs, security, and quality |
69
+ | `code-review` | Review changed source diff-first for bugs, security, and quality |
70
70
  | `review` | Peer-review recent work across reviewer perspectives |
71
71
  | `audit-milestone` | Verify a milestone met its definition of done |
72
72
  | `audit-uat` | Audit outstanding UAT/verification items |
@@ -0,0 +1,28 @@
1
+ // Project/App: gsd-pi
2
+ // File Purpose: deriveState memoization cache and telemetry.
3
+ const CACHE_TTL_MS = 100;
4
+ let _stateCache = null;
5
+ let _telemetry = { dbDeriveCount: 0 };
6
+ export function getDeriveTelemetry() {
7
+ return { ..._telemetry };
8
+ }
9
+ export function resetDeriveTelemetry() {
10
+ _telemetry = { dbDeriveCount: 0 };
11
+ }
12
+ export function incrementDbDeriveCount() {
13
+ _telemetry.dbDeriveCount++;
14
+ }
15
+ export function invalidateStateCache() {
16
+ _stateCache = null;
17
+ }
18
+ export function readCachedDeriveState(cacheKey) {
19
+ if (_stateCache &&
20
+ _stateCache.basePath === cacheKey &&
21
+ Date.now() - _stateCache.timestamp < CACHE_TTL_MS) {
22
+ return _stateCache.result;
23
+ }
24
+ return null;
25
+ }
26
+ export function writeCachedDeriveState(cacheKey, result) {
27
+ _stateCache = { basePath: cacheKey, result, timestamp: Date.now() };
28
+ }