gsd-pi 2.63.0-dev.026d309 → 2.63.0-dev.786f0ff

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 (350) hide show
  1. package/README.md +46 -134
  2. package/dist/cli.js +48 -6
  3. package/dist/headless-query.js +11 -1
  4. package/dist/help-text.js +4 -1
  5. package/dist/onboarding.js +15 -8
  6. package/dist/resource-loader.js +18 -3
  7. package/dist/resources/extensions/cmux/index.js +21 -12
  8. package/dist/resources/extensions/gsd/auto/detect-stuck.js +27 -0
  9. package/dist/resources/extensions/gsd/auto/finalize-timeout.js +40 -0
  10. package/dist/resources/extensions/gsd/auto/loop.js +4 -0
  11. package/dist/resources/extensions/gsd/auto/phases.js +157 -22
  12. package/dist/resources/extensions/gsd/auto/session.js +12 -0
  13. package/dist/resources/extensions/gsd/auto-dashboard.js +9 -3
  14. package/dist/resources/extensions/gsd/auto-model-selection.js +32 -0
  15. package/dist/resources/extensions/gsd/auto-post-unit.js +124 -10
  16. package/dist/resources/extensions/gsd/auto-prompts.js +25 -0
  17. package/dist/resources/extensions/gsd/auto-recovery.js +15 -7
  18. package/dist/resources/extensions/gsd/auto-start.js +10 -21
  19. package/dist/resources/extensions/gsd/auto-timers.js +2 -1
  20. package/dist/resources/extensions/gsd/auto-tool-tracking.js +17 -0
  21. package/dist/resources/extensions/gsd/auto-worktree.js +13 -7
  22. package/dist/resources/extensions/gsd/auto.js +19 -2
  23. package/dist/resources/extensions/gsd/bootstrap/db-tools.js +147 -75
  24. package/dist/resources/extensions/gsd/bootstrap/dynamic-tools.js +13 -0
  25. package/dist/resources/extensions/gsd/bootstrap/query-tools.js +85 -0
  26. package/dist/resources/extensions/gsd/bootstrap/register-extension.js +3 -0
  27. package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +32 -1
  28. package/dist/resources/extensions/gsd/bootstrap/sanitize-complete-milestone.js +54 -0
  29. package/dist/resources/extensions/gsd/bootstrap/system-context.js +30 -2
  30. package/dist/resources/extensions/gsd/commands-handlers.js +9 -4
  31. package/dist/resources/extensions/gsd/constants.js +42 -0
  32. package/dist/resources/extensions/gsd/db-writer.js +72 -4
  33. package/dist/resources/extensions/gsd/forensics.js +20 -4
  34. package/dist/resources/extensions/gsd/gsd-db.js +64 -17
  35. package/dist/resources/extensions/gsd/guided-flow.js +19 -0
  36. package/dist/resources/extensions/gsd/metrics.js +27 -1
  37. package/dist/resources/extensions/gsd/native-git-bridge.js +5 -3
  38. package/dist/resources/extensions/gsd/preferences-types.js +2 -0
  39. package/dist/resources/extensions/gsd/preferences.js +7 -2
  40. package/dist/resources/extensions/gsd/prompt-loader.js +7 -0
  41. package/dist/resources/extensions/gsd/prompts/complete-milestone.md +2 -0
  42. package/dist/resources/extensions/gsd/prompts/complete-slice.md +2 -0
  43. package/dist/resources/extensions/gsd/prompts/doctor-heal.md +1 -0
  44. package/dist/resources/extensions/gsd/prompts/forensics.md +2 -0
  45. package/dist/resources/extensions/gsd/prompts/reassess-roadmap.md +2 -0
  46. package/dist/resources/extensions/gsd/prompts/system.md +4 -7
  47. package/dist/resources/extensions/gsd/prompts/validate-milestone.md +2 -0
  48. package/dist/resources/extensions/gsd/roadmap-mutations.js +1 -1
  49. package/dist/resources/extensions/gsd/roadmap-slices.js +9 -5
  50. package/dist/resources/extensions/gsd/safety/content-validator.js +73 -0
  51. package/dist/resources/extensions/gsd/safety/destructive-guard.js +34 -0
  52. package/dist/resources/extensions/gsd/safety/evidence-collector.js +109 -0
  53. package/dist/resources/extensions/gsd/safety/evidence-cross-ref.js +83 -0
  54. package/dist/resources/extensions/gsd/safety/file-change-validator.js +71 -0
  55. package/dist/resources/extensions/gsd/safety/git-checkpoint.js +91 -0
  56. package/dist/resources/extensions/gsd/safety/safety-harness.js +64 -0
  57. package/dist/resources/extensions/gsd/slice-parallel-conflict.js +67 -0
  58. package/dist/resources/extensions/gsd/slice-parallel-eligibility.js +51 -0
  59. package/dist/resources/extensions/gsd/slice-parallel-orchestrator.js +378 -0
  60. package/dist/resources/extensions/gsd/state.js +74 -14
  61. package/dist/resources/extensions/gsd/status-guards.js +11 -0
  62. package/dist/resources/extensions/gsd/tools/complete-milestone.js +17 -12
  63. package/dist/resources/extensions/gsd/tools/complete-slice.js +40 -26
  64. package/dist/resources/extensions/gsd/tools/complete-task.js +12 -12
  65. package/dist/resources/extensions/gsd/tools/plan-milestone.js +33 -25
  66. package/dist/resources/extensions/gsd/tools/plan-slice.js +5 -8
  67. package/dist/resources/extensions/gsd/workflow-projections.js +21 -5
  68. package/dist/resources/extensions/gsd/worktree-manager.js +82 -29
  69. package/dist/resources/extensions/gsd/worktree-resolver.js +4 -3
  70. package/dist/resources/extensions/mcp-client/auth.js +101 -0
  71. package/dist/resources/extensions/mcp-client/index.js +10 -1
  72. package/dist/resources/extensions/ollama/index.js +28 -22
  73. package/dist/resources/extensions/ollama/model-capabilities.js +37 -34
  74. package/dist/resources/extensions/ollama/ndjson-stream.js +54 -0
  75. package/dist/resources/extensions/ollama/ollama-chat-provider.js +380 -0
  76. package/dist/resources/extensions/ollama/ollama-client.js +23 -32
  77. package/dist/resources/extensions/ollama/ollama-discovery.js +2 -7
  78. package/dist/resources/extensions/ollama/ollama-tool.js +62 -0
  79. package/dist/resources/extensions/ollama/thinking-parser.js +104 -0
  80. package/dist/update-cmd.js +4 -2
  81. package/dist/web/standalone/.next/BUILD_ID +1 -1
  82. package/dist/web/standalone/.next/app-path-routes-manifest.json +20 -20
  83. package/dist/web/standalone/.next/build-manifest.json +2 -2
  84. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  85. package/dist/web/standalone/.next/server/app/_global-error.html +2 -2
  86. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  87. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  88. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  89. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  90. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  91. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  92. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  93. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  94. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  95. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  96. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  97. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  98. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  99. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  100. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  101. package/dist/web/standalone/.next/server/app/api/boot/route.js +1 -1
  102. package/dist/web/standalone/.next/server/app/api/boot/route.js.nft.json +1 -1
  103. package/dist/web/standalone/.next/server/app/api/bridge-terminal/input/route.js +1 -1
  104. package/dist/web/standalone/.next/server/app/api/bridge-terminal/input/route.js.nft.json +1 -1
  105. package/dist/web/standalone/.next/server/app/api/bridge-terminal/resize/route.js +1 -1
  106. package/dist/web/standalone/.next/server/app/api/bridge-terminal/resize/route.js.nft.json +1 -1
  107. package/dist/web/standalone/.next/server/app/api/bridge-terminal/stream/route.js +2 -2
  108. package/dist/web/standalone/.next/server/app/api/bridge-terminal/stream/route.js.nft.json +1 -1
  109. package/dist/web/standalone/.next/server/app/api/captures/route.js +1 -1
  110. package/dist/web/standalone/.next/server/app/api/captures/route.js.nft.json +1 -1
  111. package/dist/web/standalone/.next/server/app/api/cleanup/route.js +1 -1
  112. package/dist/web/standalone/.next/server/app/api/cleanup/route.js.nft.json +1 -1
  113. package/dist/web/standalone/.next/server/app/api/doctor/route.js +1 -1
  114. package/dist/web/standalone/.next/server/app/api/doctor/route.js.nft.json +1 -1
  115. package/dist/web/standalone/.next/server/app/api/export-data/route.js +1 -1
  116. package/dist/web/standalone/.next/server/app/api/export-data/route.js.nft.json +1 -1
  117. package/dist/web/standalone/.next/server/app/api/files/route.js +1 -1
  118. package/dist/web/standalone/.next/server/app/api/files/route.js.nft.json +1 -1
  119. package/dist/web/standalone/.next/server/app/api/forensics/route.js +1 -1
  120. package/dist/web/standalone/.next/server/app/api/forensics/route.js.nft.json +1 -1
  121. package/dist/web/standalone/.next/server/app/api/git/route.js +1 -1
  122. package/dist/web/standalone/.next/server/app/api/git/route.js.nft.json +1 -1
  123. package/dist/web/standalone/.next/server/app/api/history/route.js +1 -1
  124. package/dist/web/standalone/.next/server/app/api/history/route.js.nft.json +1 -1
  125. package/dist/web/standalone/.next/server/app/api/hooks/route.js +1 -1
  126. package/dist/web/standalone/.next/server/app/api/hooks/route.js.nft.json +1 -1
  127. package/dist/web/standalone/.next/server/app/api/inspect/route.js +1 -1
  128. package/dist/web/standalone/.next/server/app/api/inspect/route.js.nft.json +1 -1
  129. package/dist/web/standalone/.next/server/app/api/knowledge/route.js +1 -1
  130. package/dist/web/standalone/.next/server/app/api/knowledge/route.js.nft.json +1 -1
  131. package/dist/web/standalone/.next/server/app/api/live-state/route.js +1 -1
  132. package/dist/web/standalone/.next/server/app/api/live-state/route.js.nft.json +1 -1
  133. package/dist/web/standalone/.next/server/app/api/onboarding/route.js +1 -1
  134. package/dist/web/standalone/.next/server/app/api/onboarding/route.js.nft.json +1 -1
  135. package/dist/web/standalone/.next/server/app/api/projects/route.js +1 -1
  136. package/dist/web/standalone/.next/server/app/api/projects/route.js.nft.json +1 -1
  137. package/dist/web/standalone/.next/server/app/api/recovery/route.js +1 -1
  138. package/dist/web/standalone/.next/server/app/api/recovery/route.js.nft.json +1 -1
  139. package/dist/web/standalone/.next/server/app/api/session/browser/route.js +1 -1
  140. package/dist/web/standalone/.next/server/app/api/session/browser/route.js.nft.json +1 -1
  141. package/dist/web/standalone/.next/server/app/api/session/command/route.js +1 -1
  142. package/dist/web/standalone/.next/server/app/api/session/command/route.js.nft.json +1 -1
  143. package/dist/web/standalone/.next/server/app/api/session/events/route.js +2 -2
  144. package/dist/web/standalone/.next/server/app/api/session/events/route.js.nft.json +1 -1
  145. package/dist/web/standalone/.next/server/app/api/session/manage/route.js +1 -1
  146. package/dist/web/standalone/.next/server/app/api/session/manage/route.js.nft.json +1 -1
  147. package/dist/web/standalone/.next/server/app/api/settings-data/route.js +1 -1
  148. package/dist/web/standalone/.next/server/app/api/settings-data/route.js.nft.json +1 -1
  149. package/dist/web/standalone/.next/server/app/api/skill-health/route.js +1 -1
  150. package/dist/web/standalone/.next/server/app/api/skill-health/route.js.nft.json +1 -1
  151. package/dist/web/standalone/.next/server/app/api/steer/route.js +1 -1
  152. package/dist/web/standalone/.next/server/app/api/steer/route.js.nft.json +1 -1
  153. package/dist/web/standalone/.next/server/app/api/switch-root/route.js +1 -1
  154. package/dist/web/standalone/.next/server/app/api/switch-root/route.js.nft.json +1 -1
  155. package/dist/web/standalone/.next/server/app/api/terminal/sessions/route.js +2 -2
  156. package/dist/web/standalone/.next/server/app/api/terminal/sessions/route.js.nft.json +1 -1
  157. package/dist/web/standalone/.next/server/app/api/terminal/stream/route.js +2 -2
  158. package/dist/web/standalone/.next/server/app/api/terminal/stream/route.js.nft.json +1 -1
  159. package/dist/web/standalone/.next/server/app/api/undo/route.js +1 -1
  160. package/dist/web/standalone/.next/server/app/api/undo/route.js.nft.json +1 -1
  161. package/dist/web/standalone/.next/server/app/api/visualizer/route.js +1 -1
  162. package/dist/web/standalone/.next/server/app/api/visualizer/route.js.nft.json +1 -1
  163. package/dist/web/standalone/.next/server/app/index.html +1 -1
  164. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  165. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  166. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  167. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  168. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  169. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  170. package/dist/web/standalone/.next/server/app-paths-manifest.json +20 -20
  171. package/dist/web/standalone/.next/server/chunks/6897.js +12 -0
  172. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  173. package/dist/web/standalone/.next/server/pages/500.html +2 -2
  174. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  175. package/package.json +1 -1
  176. package/packages/pi-agent-core/dist/agent-loop.d.ts +8 -0
  177. package/packages/pi-agent-core/dist/agent-loop.d.ts.map +1 -1
  178. package/packages/pi-agent-core/dist/agent-loop.js +50 -0
  179. package/packages/pi-agent-core/dist/agent-loop.js.map +1 -1
  180. package/packages/pi-agent-core/src/agent-loop.test.ts +221 -5
  181. package/packages/pi-agent-core/src/agent-loop.ts +53 -0
  182. package/packages/pi-ai/dist/types.d.ts +16 -1
  183. package/packages/pi-ai/dist/types.d.ts.map +1 -1
  184. package/packages/pi-ai/dist/types.js.map +1 -1
  185. package/packages/pi-ai/src/types.ts +18 -1
  186. package/packages/pi-coding-agent/dist/core/auth-storage.d.ts +9 -0
  187. package/packages/pi-coding-agent/dist/core/auth-storage.d.ts.map +1 -1
  188. package/packages/pi-coding-agent/dist/core/auth-storage.js +50 -1
  189. package/packages/pi-coding-agent/dist/core/auth-storage.js.map +1 -1
  190. package/packages/pi-coding-agent/dist/core/auth-storage.test.js +41 -0
  191. package/packages/pi-coding-agent/dist/core/auth-storage.test.js.map +1 -1
  192. package/packages/pi-coding-agent/dist/core/extensions/loader.d.ts +7 -0
  193. package/packages/pi-coding-agent/dist/core/extensions/loader.d.ts.map +1 -1
  194. package/packages/pi-coding-agent/dist/core/extensions/loader.js +31 -4
  195. package/packages/pi-coding-agent/dist/core/extensions/loader.js.map +1 -1
  196. package/packages/pi-coding-agent/dist/core/extensions/loader.test.js +28 -1
  197. package/packages/pi-coding-agent/dist/core/extensions/loader.test.js.map +1 -1
  198. package/packages/pi-coding-agent/dist/core/extensions/provider-registration.test.d.ts +2 -0
  199. package/packages/pi-coding-agent/dist/core/extensions/provider-registration.test.d.ts.map +1 -0
  200. package/packages/pi-coding-agent/dist/core/extensions/provider-registration.test.js +46 -0
  201. package/packages/pi-coding-agent/dist/core/extensions/provider-registration.test.js.map +1 -0
  202. package/packages/pi-coding-agent/dist/core/extensions/types.d.ts +2 -0
  203. package/packages/pi-coding-agent/dist/core/extensions/types.d.ts.map +1 -1
  204. package/packages/pi-coding-agent/dist/core/extensions/types.js.map +1 -1
  205. package/packages/pi-coding-agent/dist/core/model-registry.d.ts +1 -0
  206. package/packages/pi-coding-agent/dist/core/model-registry.d.ts.map +1 -1
  207. package/packages/pi-coding-agent/dist/core/model-registry.js +12 -0
  208. package/packages/pi-coding-agent/dist/core/model-registry.js.map +1 -1
  209. package/packages/pi-coding-agent/dist/core/model-resolver.js +3 -3
  210. package/packages/pi-coding-agent/dist/core/model-resolver.js.map +1 -1
  211. package/packages/pi-coding-agent/dist/core/resource-loader.d.ts +23 -1
  212. package/packages/pi-coding-agent/dist/core/resource-loader.d.ts.map +1 -1
  213. package/packages/pi-coding-agent/dist/core/resource-loader.js +80 -56
  214. package/packages/pi-coding-agent/dist/core/resource-loader.js.map +1 -1
  215. package/packages/pi-coding-agent/dist/core/sdk.d.ts.map +1 -1
  216. package/packages/pi-coding-agent/dist/core/sdk.js +9 -0
  217. package/packages/pi-coding-agent/dist/core/sdk.js.map +1 -1
  218. package/packages/pi-coding-agent/src/core/auth-storage.test.ts +53 -0
  219. package/packages/pi-coding-agent/src/core/auth-storage.ts +66 -1
  220. package/packages/pi-coding-agent/src/core/extensions/loader.test.ts +39 -1
  221. package/packages/pi-coding-agent/src/core/extensions/loader.ts +34 -4
  222. package/packages/pi-coding-agent/src/core/extensions/provider-registration.test.ts +81 -0
  223. package/packages/pi-coding-agent/src/core/extensions/types.ts +2 -0
  224. package/packages/pi-coding-agent/src/core/model-registry.ts +14 -0
  225. package/packages/pi-coding-agent/src/core/model-resolver.ts +3 -3
  226. package/packages/pi-coding-agent/src/core/resource-loader.ts +89 -56
  227. package/packages/pi-coding-agent/src/core/sdk.ts +10 -0
  228. package/src/resources/extensions/cmux/index.ts +18 -12
  229. package/src/resources/extensions/gsd/auto/detect-stuck.ts +27 -0
  230. package/src/resources/extensions/gsd/auto/finalize-timeout.ts +46 -0
  231. package/src/resources/extensions/gsd/auto/loop.ts +5 -0
  232. package/src/resources/extensions/gsd/auto/phases.ts +194 -33
  233. package/src/resources/extensions/gsd/auto/session.ts +14 -0
  234. package/src/resources/extensions/gsd/auto-dashboard.ts +11 -3
  235. package/src/resources/extensions/gsd/auto-model-selection.ts +36 -0
  236. package/src/resources/extensions/gsd/auto-post-unit.ts +141 -12
  237. package/src/resources/extensions/gsd/auto-prompts.ts +21 -0
  238. package/src/resources/extensions/gsd/auto-recovery.ts +9 -8
  239. package/src/resources/extensions/gsd/auto-start.ts +11 -20
  240. package/src/resources/extensions/gsd/auto-timers.ts +2 -1
  241. package/src/resources/extensions/gsd/auto-tool-tracking.ts +19 -0
  242. package/src/resources/extensions/gsd/auto-worktree.ts +14 -6
  243. package/src/resources/extensions/gsd/auto.ts +22 -1
  244. package/src/resources/extensions/gsd/bootstrap/db-tools.ts +160 -88
  245. package/src/resources/extensions/gsd/bootstrap/dynamic-tools.ts +15 -0
  246. package/src/resources/extensions/gsd/bootstrap/query-tools.ts +98 -0
  247. package/src/resources/extensions/gsd/bootstrap/register-extension.ts +4 -0
  248. package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +36 -1
  249. package/src/resources/extensions/gsd/bootstrap/sanitize-complete-milestone.ts +57 -0
  250. package/src/resources/extensions/gsd/bootstrap/system-context.ts +31 -2
  251. package/src/resources/extensions/gsd/commands-handlers.ts +10 -4
  252. package/src/resources/extensions/gsd/constants.ts +44 -0
  253. package/src/resources/extensions/gsd/db-writer.ts +78 -4
  254. package/src/resources/extensions/gsd/forensics.ts +21 -5
  255. package/src/resources/extensions/gsd/gsd-db.ts +64 -17
  256. package/src/resources/extensions/gsd/guided-flow.ts +22 -0
  257. package/src/resources/extensions/gsd/metrics.ts +28 -1
  258. package/src/resources/extensions/gsd/native-git-bridge.ts +5 -3
  259. package/src/resources/extensions/gsd/preferences-types.ts +16 -0
  260. package/src/resources/extensions/gsd/preferences.ts +9 -2
  261. package/src/resources/extensions/gsd/prompt-loader.ts +8 -0
  262. package/src/resources/extensions/gsd/prompts/complete-milestone.md +2 -0
  263. package/src/resources/extensions/gsd/prompts/complete-slice.md +2 -0
  264. package/src/resources/extensions/gsd/prompts/doctor-heal.md +1 -0
  265. package/src/resources/extensions/gsd/prompts/forensics.md +2 -0
  266. package/src/resources/extensions/gsd/prompts/reassess-roadmap.md +2 -0
  267. package/src/resources/extensions/gsd/prompts/system.md +4 -7
  268. package/src/resources/extensions/gsd/prompts/validate-milestone.md +2 -0
  269. package/src/resources/extensions/gsd/roadmap-mutations.ts +1 -1
  270. package/src/resources/extensions/gsd/roadmap-slices.ts +10 -5
  271. package/src/resources/extensions/gsd/safety/content-validator.ts +98 -0
  272. package/src/resources/extensions/gsd/safety/destructive-guard.ts +49 -0
  273. package/src/resources/extensions/gsd/safety/evidence-collector.ts +151 -0
  274. package/src/resources/extensions/gsd/safety/evidence-cross-ref.ts +120 -0
  275. package/src/resources/extensions/gsd/safety/file-change-validator.ts +108 -0
  276. package/src/resources/extensions/gsd/safety/git-checkpoint.ts +106 -0
  277. package/src/resources/extensions/gsd/safety/safety-harness.ts +105 -0
  278. package/src/resources/extensions/gsd/slice-parallel-conflict.ts +86 -0
  279. package/src/resources/extensions/gsd/slice-parallel-eligibility.ts +73 -0
  280. package/src/resources/extensions/gsd/slice-parallel-orchestrator.ts +477 -0
  281. package/src/resources/extensions/gsd/state.ts +67 -12
  282. package/src/resources/extensions/gsd/status-guards.ts +13 -0
  283. package/src/resources/extensions/gsd/tests/artifact-corruption-2630.test.ts +288 -0
  284. package/src/resources/extensions/gsd/tests/auto-loop.test.ts +34 -13
  285. package/src/resources/extensions/gsd/tests/cmux.test.ts +58 -0
  286. package/src/resources/extensions/gsd/tests/cold-resume-db-reopen.test.ts +51 -0
  287. package/src/resources/extensions/gsd/tests/complete-milestone.test.ts +140 -0
  288. package/src/resources/extensions/gsd/tests/complete-slice-string-coercion.test.ts +211 -0
  289. package/src/resources/extensions/gsd/tests/complete-task.test.ts +39 -0
  290. package/src/resources/extensions/gsd/tests/dashboard-model-label-ordering.test.ts +107 -0
  291. package/src/resources/extensions/gsd/tests/db-access-guardrails.test.ts +109 -0
  292. package/src/resources/extensions/gsd/tests/db-path-worktree-symlink.test.ts +13 -9
  293. package/src/resources/extensions/gsd/tests/db-writer.test.ts +134 -0
  294. package/src/resources/extensions/gsd/tests/deferred-slice-dispatch.test.ts +203 -0
  295. package/src/resources/extensions/gsd/tests/discuss-tool-scoping.test.ts +130 -0
  296. package/src/resources/extensions/gsd/tests/doctor-fix-flag.test.ts +92 -0
  297. package/src/resources/extensions/gsd/tests/finalize-timeout-guard.test.ts +116 -0
  298. package/src/resources/extensions/gsd/tests/flat-rate-routing-guard.test.ts +50 -0
  299. package/src/resources/extensions/gsd/tests/forensics-stuck-loops.test.ts +103 -0
  300. package/src/resources/extensions/gsd/tests/git-checkpoint.test.ts +94 -0
  301. package/src/resources/extensions/gsd/tests/insert-slice-no-wipe.test.ts +88 -0
  302. package/src/resources/extensions/gsd/tests/integration/git-service.test.ts +27 -7
  303. package/src/resources/extensions/gsd/tests/integration/idle-recovery.test.ts +34 -0
  304. package/src/resources/extensions/gsd/tests/metrics.test.ts +116 -1
  305. package/src/resources/extensions/gsd/tests/milestone-status-tool.test.ts +201 -0
  306. package/src/resources/extensions/gsd/tests/plan-milestone-title.test.ts +2 -1
  307. package/src/resources/extensions/gsd/tests/plan-milestone.test.ts +82 -18
  308. package/src/resources/extensions/gsd/tests/preferences.test.ts +10 -0
  309. package/src/resources/extensions/gsd/tests/prompt-contracts.test.ts +25 -0
  310. package/src/resources/extensions/gsd/tests/roadmap-slices.test.ts +69 -0
  311. package/src/resources/extensions/gsd/tests/shared-wal.test.ts +30 -0
  312. package/src/resources/extensions/gsd/tests/slice-context-injection.test.ts +50 -0
  313. package/src/resources/extensions/gsd/tests/slice-parallel-conflict.test.ts +92 -0
  314. package/src/resources/extensions/gsd/tests/slice-parallel-eligibility.test.ts +95 -0
  315. package/src/resources/extensions/gsd/tests/slice-parallel-orchestrator.test.ts +83 -0
  316. package/src/resources/extensions/gsd/tests/stuck-detection-coverage.test.ts +42 -0
  317. package/src/resources/extensions/gsd/tests/tool-invocation-error-loop-break.test.ts +103 -0
  318. package/src/resources/extensions/gsd/tests/tool-param-optionality.test.ts +349 -0
  319. package/src/resources/extensions/gsd/tests/worktree-health-dispatch.test.ts +35 -2
  320. package/src/resources/extensions/gsd/tests/worktree-health-monorepo.test.ts +73 -0
  321. package/src/resources/extensions/gsd/tests/worktree-resolver.test.ts +34 -0
  322. package/src/resources/extensions/gsd/tests/worktree-submodule-safety.test.ts +1 -1
  323. package/src/resources/extensions/gsd/tests/worktree-teardown-safety.test.ts +148 -0
  324. package/src/resources/extensions/gsd/tools/complete-milestone.ts +34 -20
  325. package/src/resources/extensions/gsd/tools/complete-slice.ts +41 -26
  326. package/src/resources/extensions/gsd/tools/complete-task.ts +12 -12
  327. package/src/resources/extensions/gsd/tools/plan-milestone.ts +55 -30
  328. package/src/resources/extensions/gsd/tools/plan-slice.ts +13 -8
  329. package/src/resources/extensions/gsd/types.ts +44 -22
  330. package/src/resources/extensions/gsd/workflow-logger.ts +2 -1
  331. package/src/resources/extensions/gsd/workflow-projections.ts +23 -5
  332. package/src/resources/extensions/gsd/worktree-manager.ts +76 -28
  333. package/src/resources/extensions/gsd/worktree-resolver.ts +4 -3
  334. package/src/resources/extensions/mcp-client/auth.ts +149 -0
  335. package/src/resources/extensions/mcp-client/index.ts +16 -1
  336. package/src/resources/extensions/ollama/index.ts +26 -25
  337. package/src/resources/extensions/ollama/model-capabilities.ts +41 -34
  338. package/src/resources/extensions/ollama/ndjson-stream.ts +63 -0
  339. package/src/resources/extensions/ollama/ollama-auth-mode.test.ts +20 -0
  340. package/src/resources/extensions/ollama/ollama-chat-provider.ts +459 -0
  341. package/src/resources/extensions/ollama/ollama-client.ts +30 -30
  342. package/src/resources/extensions/ollama/ollama-discovery.ts +5 -8
  343. package/src/resources/extensions/ollama/ollama-tool.ts +69 -0
  344. package/src/resources/extensions/ollama/tests/ollama-chat-provider-stream.test.ts +82 -0
  345. package/src/resources/extensions/ollama/tests/ollama-discovery.test.ts +0 -27
  346. package/src/resources/extensions/ollama/thinking-parser.ts +116 -0
  347. package/src/resources/extensions/ollama/types.ts +23 -0
  348. package/dist/web/standalone/.next/server/chunks/2229.js +0 -12
  349. /package/dist/web/standalone/.next/static/{TTlAguZQ5vR9EOv6G8cel → SDB1T-4NqkMjYirjjqQhr}/_buildManifest.js +0 -0
  350. /package/dist/web/standalone/.next/static/{TTlAguZQ5vR9EOv6G8cel → SDB1T-4NqkMjYirjjqQhr}/_ssgManifest.js +0 -0
@@ -0,0 +1,477 @@
1
+ /**
2
+ * GSD Slice Parallel Orchestrator — Engine for parallel slice execution
3
+ * within a single milestone.
4
+ *
5
+ * Mirrors the existing parallel-orchestrator.ts pattern at slice scope
6
+ * instead of milestone scope. Workers are separate processes spawned via
7
+ * child_process, each running in its own git worktree with GSD_SLICE_LOCK
8
+ * + GSD_MILESTONE_LOCK env vars set.
9
+ *
10
+ * Key differences from milestone-level parallelism:
11
+ * - Scope: slices within one milestone, not milestones within a project
12
+ * - Lock env: GSD_SLICE_LOCK (in addition to GSD_MILESTONE_LOCK)
13
+ * - Conflict check: file overlap between slice plans (slice-parallel-conflict.ts)
14
+ */
15
+
16
+ import { spawn, type ChildProcess } from "node:child_process";
17
+ import {
18
+ appendFileSync,
19
+ existsSync,
20
+ writeFileSync,
21
+ readFileSync,
22
+ mkdirSync,
23
+ } from "node:fs";
24
+ import { join, dirname } from "node:path";
25
+ import { fileURLToPath } from "node:url";
26
+ import { gsdRoot } from "./paths.js";
27
+ import { createWorktree, worktreePath, removeWorktree } from "./worktree-manager.js";
28
+ import { autoWorktreeBranch, runWorktreePostCreateHook } from "./auto-worktree.js";
29
+ import {
30
+ writeSessionStatus,
31
+ removeSessionStatus,
32
+ } from "./session-status-io.js";
33
+ import { hasFileConflict } from "./slice-parallel-conflict.js";
34
+ import { getErrorMessage } from "./error-utils.js";
35
+
36
+ // ─── Types ─────────────────────────────────────────────────────────────────
37
+
38
+ export interface SliceWorkerInfo {
39
+ milestoneId: string;
40
+ sliceId: string;
41
+ pid: number;
42
+ process: ChildProcess | null;
43
+ worktreePath: string;
44
+ startedAt: number;
45
+ state: "running" | "stopped" | "error";
46
+ completedUnits: number;
47
+ cost: number;
48
+ cleanup?: () => void;
49
+ }
50
+
51
+ export interface SliceOrchestratorState {
52
+ active: boolean;
53
+ workers: Map<string, SliceWorkerInfo>;
54
+ totalCost: number;
55
+ budgetCeiling?: number;
56
+ maxWorkers: number;
57
+ startedAt: number;
58
+ basePath: string;
59
+ }
60
+
61
+ export interface StartSliceParallelOpts {
62
+ maxWorkers?: number;
63
+ budgetCeiling?: number;
64
+ }
65
+
66
+ // ─── Module State ──────────────────────────────────────────────────────────
67
+
68
+ let sliceState: SliceOrchestratorState | null = null;
69
+
70
+ // ─── Public API ────────────────────────────────────────────────────────────
71
+
72
+ /**
73
+ * Check whether slice-level parallel is currently active.
74
+ */
75
+ export function isSliceParallelActive(): boolean {
76
+ return sliceState?.active === true;
77
+ }
78
+
79
+ /**
80
+ * Get current slice orchestrator state (read-only snapshot).
81
+ */
82
+ export function getSliceOrchestratorState(): SliceOrchestratorState | null {
83
+ return sliceState;
84
+ }
85
+
86
+ /**
87
+ * Start parallel execution for eligible slices within a milestone.
88
+ *
89
+ * For each eligible slice: create a worktree, spawn `gsd --mode json --print "/gsd auto"`
90
+ * with env GSD_SLICE_LOCK=<SID> + GSD_MILESTONE_LOCK=<MID> + GSD_PARALLEL_WORKER=1.
91
+ */
92
+ export async function startSliceParallel(
93
+ basePath: string,
94
+ milestoneId: string,
95
+ eligibleSlices: Array<{ id: string }>,
96
+ opts: StartSliceParallelOpts = {},
97
+ ): Promise<{ started: string[]; errors: Array<{ sid: string; error: string }> }> {
98
+ // Prevent nesting: if already a parallel worker, refuse
99
+ if (process.env.GSD_PARALLEL_WORKER) {
100
+ return { started: [], errors: [{ sid: "all", error: "Cannot start slice-parallel from within a parallel worker" }] };
101
+ }
102
+
103
+ const maxWorkers = opts.maxWorkers ?? 2;
104
+ const budgetCeiling = opts.budgetCeiling;
105
+
106
+ // Initialize orchestrator state
107
+ sliceState = {
108
+ active: true,
109
+ workers: new Map(),
110
+ totalCost: 0,
111
+ budgetCeiling,
112
+ maxWorkers,
113
+ startedAt: Date.now(),
114
+ basePath,
115
+ };
116
+
117
+ const started: string[] = [];
118
+ const errors: Array<{ sid: string; error: string }> = [];
119
+
120
+ // Filter out conflicting slices (conservative: check all pairs)
121
+ const safeSlices = filterConflictingSlices(basePath, milestoneId, eligibleSlices);
122
+
123
+ // Limit to maxWorkers
124
+ const toSpawn = safeSlices.slice(0, maxWorkers);
125
+
126
+ for (const slice of toSpawn) {
127
+ try {
128
+ // Create worktree for this slice
129
+ const wtBranch = `slice/${milestoneId}/${slice.id}`;
130
+ const wtName = `${milestoneId}-${slice.id}`;
131
+ const wtPath = worktreePath(basePath, wtName);
132
+
133
+ if (!existsSync(wtPath)) {
134
+ createWorktree(basePath, wtName, { branch: wtBranch });
135
+ }
136
+
137
+ // Create worker info
138
+ const worker: SliceWorkerInfo = {
139
+ milestoneId,
140
+ sliceId: slice.id,
141
+ pid: 0,
142
+ process: null,
143
+ worktreePath: wtPath,
144
+ startedAt: Date.now(),
145
+ state: "running",
146
+ completedUnits: 0,
147
+ cost: 0,
148
+ };
149
+
150
+ sliceState.workers.set(slice.id, worker);
151
+
152
+ // Spawn worker
153
+ const spawned = spawnSliceWorker(basePath, milestoneId, slice.id);
154
+ if (spawned) {
155
+ started.push(slice.id);
156
+ } else {
157
+ errors.push({ sid: slice.id, error: "Failed to spawn worker process" });
158
+ worker.state = "error";
159
+ }
160
+ } catch (err) {
161
+ errors.push({ sid: slice.id, error: getErrorMessage(err) });
162
+ // Best-effort cleanup of partially created worktree
163
+ const wtName = `${milestoneId}-${slice.id}`;
164
+ try {
165
+ removeWorktree(basePath, wtName, { deleteBranch: true, force: true });
166
+ } catch { /* ignore cleanup failures */ }
167
+ }
168
+ }
169
+
170
+ // If nothing started, deactivate
171
+ if (started.length === 0) {
172
+ sliceState.active = false;
173
+ }
174
+
175
+ return { started, errors };
176
+ }
177
+
178
+ /**
179
+ * Stop all slice-parallel workers and deactivate.
180
+ */
181
+ export function stopSliceParallel(): void {
182
+ if (!sliceState) return;
183
+
184
+ for (const worker of sliceState.workers.values()) {
185
+ if (worker.process) {
186
+ try {
187
+ worker.process.kill("SIGTERM");
188
+ } catch { /* already dead */ }
189
+ }
190
+ worker.cleanup?.();
191
+ worker.cleanup = undefined;
192
+ worker.process = null;
193
+ worker.state = "stopped";
194
+
195
+ // Clean up worktree created for this worker
196
+ const wtName = `${worker.milestoneId}-${worker.sliceId}`;
197
+ try {
198
+ removeWorktree(sliceState.basePath, wtName, { deleteBranch: true, force: true });
199
+ } catch { /* best-effort cleanup */ }
200
+ }
201
+
202
+ sliceState.active = false;
203
+ }
204
+
205
+ /**
206
+ * Get aggregate cost across all slice workers.
207
+ */
208
+ export function getSliceAggregateCost(): number {
209
+ if (!sliceState) return 0;
210
+ let total = 0;
211
+ for (const w of sliceState.workers.values()) {
212
+ total += w.cost;
213
+ }
214
+ return total;
215
+ }
216
+
217
+ /**
218
+ * Check if budget ceiling has been exceeded.
219
+ */
220
+ export function isSliceBudgetExceeded(): boolean {
221
+ if (!sliceState?.budgetCeiling) return false;
222
+ return getSliceAggregateCost() >= sliceState.budgetCeiling;
223
+ }
224
+
225
+ /**
226
+ * Reset module state (for testing).
227
+ */
228
+ export function resetSliceOrchestrator(): void {
229
+ if (sliceState) {
230
+ for (const w of sliceState.workers.values()) {
231
+ w.cleanup?.();
232
+ }
233
+ }
234
+ sliceState = null;
235
+ }
236
+
237
+ // ─── Internal: Conflict Filtering ──────────────────────────────────────────
238
+
239
+ /**
240
+ * Remove slices that have file conflicts with each other.
241
+ * Greedy: add slices to the safe set in order; skip any that conflict
242
+ * with an already-included slice.
243
+ */
244
+ function filterConflictingSlices(
245
+ basePath: string,
246
+ milestoneId: string,
247
+ slices: Array<{ id: string }>,
248
+ ): Array<{ id: string }> {
249
+ const safe: Array<{ id: string }> = [];
250
+
251
+ for (const candidate of slices) {
252
+ let conflictsWithSafe = false;
253
+ for (const existing of safe) {
254
+ if (hasFileConflict(basePath, milestoneId, candidate.id, existing.id)) {
255
+ conflictsWithSafe = true;
256
+ break;
257
+ }
258
+ }
259
+ if (!conflictsWithSafe) {
260
+ safe.push(candidate);
261
+ }
262
+ }
263
+
264
+ return safe;
265
+ }
266
+
267
+ // ─── Internal: Worker Spawning ─────────────────────────────────────────────
268
+
269
+ /**
270
+ * Resolve the GSD CLI binary path.
271
+ * Same logic as parallel-orchestrator.ts resolveGsdBin().
272
+ */
273
+ function resolveGsdBin(): string | null {
274
+ if (process.env.GSD_BIN_PATH && existsSync(process.env.GSD_BIN_PATH)) {
275
+ return process.env.GSD_BIN_PATH;
276
+ }
277
+
278
+ let thisDir: string;
279
+ try {
280
+ thisDir = dirname(fileURLToPath(import.meta.url));
281
+ } catch {
282
+ thisDir = process.cwd();
283
+ }
284
+ const candidates = [
285
+ join(thisDir, "..", "..", "..", "loader.js"),
286
+ join(thisDir, "..", "..", "..", "..", "dist", "loader.js"),
287
+ ];
288
+ for (const candidate of candidates) {
289
+ if (existsSync(candidate)) return candidate;
290
+ }
291
+
292
+ return null;
293
+ }
294
+
295
+ /**
296
+ * Spawn a worker process for a slice.
297
+ * The worker runs `gsd --mode json --print "/gsd auto"` in the slice's worktree
298
+ * with GSD_SLICE_LOCK, GSD_MILESTONE_LOCK, and GSD_PARALLEL_WORKER set.
299
+ */
300
+ function spawnSliceWorker(
301
+ basePath: string,
302
+ milestoneId: string,
303
+ sliceId: string,
304
+ ): boolean {
305
+ if (!sliceState) return false;
306
+ const worker = sliceState.workers.get(sliceId);
307
+ if (!worker) return false;
308
+ if (worker.process) return true;
309
+
310
+ const binPath = resolveGsdBin();
311
+ if (!binPath) return false;
312
+
313
+ let child: ChildProcess;
314
+ try {
315
+ child = spawn(process.execPath, [binPath, "--mode", "json", "--print", "/gsd auto"], {
316
+ cwd: worker.worktreePath,
317
+ env: {
318
+ ...process.env,
319
+ GSD_SLICE_LOCK: sliceId,
320
+ GSD_MILESTONE_LOCK: milestoneId,
321
+ GSD_PROJECT_ROOT: basePath,
322
+ GSD_PARALLEL_WORKER: "1",
323
+ },
324
+ stdio: ["ignore", "pipe", "pipe"],
325
+ detached: false,
326
+ });
327
+ } catch {
328
+ return false;
329
+ }
330
+
331
+ child.on("error", () => {
332
+ if (!sliceState) return;
333
+ const w = sliceState.workers.get(sliceId);
334
+ if (w) {
335
+ w.process = null;
336
+ }
337
+ });
338
+
339
+ worker.process = child;
340
+ worker.pid = child.pid ?? 0;
341
+
342
+ if (!child.pid) {
343
+ worker.process = null;
344
+ return false;
345
+ }
346
+
347
+ // ── NDJSON stdout monitoring ────────────────────────────────────────
348
+ if (child.stdout) {
349
+ let stdoutBuffer = "";
350
+ child.stdout.on("data", (data: Buffer) => {
351
+ stdoutBuffer += data.toString();
352
+ const lines = stdoutBuffer.split("\n");
353
+ stdoutBuffer = lines.pop() || "";
354
+ for (const line of lines) {
355
+ processSliceWorkerLine(basePath, milestoneId, sliceId, line);
356
+ }
357
+ });
358
+ child.stdout.on("close", () => {
359
+ if (stdoutBuffer.trim()) {
360
+ processSliceWorkerLine(basePath, milestoneId, sliceId, stdoutBuffer);
361
+ }
362
+ });
363
+ }
364
+
365
+ if (child.stderr) {
366
+ child.stderr.on("data", (data: Buffer) => {
367
+ appendSliceWorkerLog(basePath, milestoneId, sliceId, data.toString());
368
+ });
369
+ }
370
+
371
+ // Update session status
372
+ writeSessionStatus(basePath, {
373
+ milestoneId: `${milestoneId}/${sliceId}`,
374
+ pid: worker.pid,
375
+ state: "running",
376
+ currentUnit: null,
377
+ completedUnits: worker.completedUnits,
378
+ cost: worker.cost,
379
+ lastHeartbeat: Date.now(),
380
+ startedAt: worker.startedAt,
381
+ worktreePath: worker.worktreePath,
382
+ });
383
+
384
+ // Store cleanup function
385
+ worker.cleanup = () => {
386
+ child.stdout?.removeAllListeners();
387
+ child.stderr?.removeAllListeners();
388
+ child.removeAllListeners();
389
+ };
390
+
391
+ // Handle worker exit
392
+ child.on("exit", (code) => {
393
+ if (!sliceState) return;
394
+ const w = sliceState.workers.get(sliceId);
395
+ if (!w) return;
396
+
397
+ w.cleanup?.();
398
+ w.cleanup = undefined;
399
+ w.process = null;
400
+
401
+ if (w.state === "stopped") return;
402
+
403
+ if (code === 0) {
404
+ w.state = "stopped";
405
+ } else {
406
+ w.state = "error";
407
+ appendSliceWorkerLog(basePath, milestoneId, sliceId,
408
+ `\n[slice-orchestrator] worker exited with code ${code ?? "null"}\n`);
409
+ }
410
+
411
+ writeSessionStatus(basePath, {
412
+ milestoneId: `${milestoneId}/${sliceId}`,
413
+ pid: w.pid,
414
+ state: w.state,
415
+ currentUnit: null,
416
+ completedUnits: w.completedUnits,
417
+ cost: w.cost,
418
+ lastHeartbeat: Date.now(),
419
+ startedAt: w.startedAt,
420
+ worktreePath: w.worktreePath,
421
+ });
422
+ });
423
+
424
+ return true;
425
+ }
426
+
427
+ // ─── NDJSON Processing ──────────────────────────────────────────────────────
428
+
429
+ /**
430
+ * Process a single NDJSON line from a slice worker's stdout.
431
+ * Extracts cost from message_end events.
432
+ */
433
+ function processSliceWorkerLine(
434
+ _basePath: string,
435
+ _milestoneId: string,
436
+ sliceId: string,
437
+ line: string,
438
+ ): void {
439
+ if (!line.trim() || !sliceState) return;
440
+
441
+ let event: Record<string, unknown>;
442
+ try {
443
+ event = JSON.parse(line);
444
+ } catch {
445
+ return;
446
+ }
447
+
448
+ const type = String(event.type ?? "");
449
+ if (type === "message_end") {
450
+ const worker = sliceState.workers.get(sliceId);
451
+ if (worker) {
452
+ const usage = event.usage as Record<string, unknown> | undefined;
453
+ if (usage?.cost && typeof usage.cost === "number") {
454
+ worker.cost += usage.cost;
455
+ sliceState.totalCost += usage.cost;
456
+ }
457
+ worker.completedUnits++;
458
+ }
459
+ }
460
+ }
461
+
462
+ // ─── Logging ────────────────────────────────────────────────────────────────
463
+
464
+ function sliceLogDir(basePath: string): string {
465
+ return join(gsdRoot(basePath), "parallel", "slice-logs");
466
+ }
467
+
468
+ function appendSliceWorkerLog(
469
+ basePath: string,
470
+ milestoneId: string,
471
+ sliceId: string,
472
+ text: string,
473
+ ): void {
474
+ const dir = sliceLogDir(basePath);
475
+ mkdirSync(dir, { recursive: true });
476
+ appendFileSync(join(dir, `${milestoneId}-${sliceId}.log`), text);
477
+ }
@@ -36,13 +36,14 @@ import {
36
36
 
37
37
  import { findMilestoneIds } from './milestone-ids.js';
38
38
  import { loadQueueOrder, sortByQueueOrder } from './queue-order.js';
39
+ import { isClosedStatus, isDeferredStatus } from './status-guards.js';
39
40
  import { nativeBatchParseGsdFiles, type BatchParsedFile } from './native-parser-bridge.js';
40
41
 
41
42
  import { join, resolve } from 'path';
42
43
  import { existsSync, readdirSync, readFileSync } from 'node:fs';
43
44
  import { debugCount, debugTime } from './debug-logger.js';
44
- import { extractVerdict } from './verdict-parser.js';
45
45
  import { logWarning, logError } from './workflow-logger.js';
46
+ import { extractVerdict } from './verdict-parser.js';
46
47
 
47
48
  import {
48
49
  isDbAvailable,
@@ -674,12 +675,39 @@ export async function deriveStateFromDb(basePath: string): Promise<GSDState> {
674
675
  let activeSlice: ActiveRef | null = null;
675
676
  let activeSliceRow: SliceRow | null = null;
676
677
 
677
- for (const s of activeMilestoneSlices) {
678
- if (isStatusDone(s.status)) continue;
679
- if (s.depends.every(dep => doneSliceIds.has(dep))) {
680
- activeSlice = { id: s.id, title: s.title };
681
- activeSliceRow = s;
682
- break;
678
+ // ── Slice-level parallel worker isolation ─────────────────────────────
679
+ // When GSD_SLICE_LOCK is set, this process is a parallel worker scoped
680
+ // to a single slice. Override activeSlice to only the locked slice ID.
681
+ const sliceLock = process.env.GSD_SLICE_LOCK;
682
+ if (sliceLock) {
683
+ const lockedSlice = activeMilestoneSlices.find(s => s.id === sliceLock);
684
+ if (lockedSlice) {
685
+ activeSlice = { id: lockedSlice.id, title: lockedSlice.title };
686
+ activeSliceRow = lockedSlice;
687
+ } else {
688
+ logWarning("state", `GSD_SLICE_LOCK=${sliceLock} not found in active slices — worker has no assigned work`);
689
+ // Don't silently continue — this is a dispatch error
690
+ return {
691
+ activeMilestone, activeSlice: null, activeTask: null,
692
+ phase: 'blocked',
693
+ recentDecisions: [], blockers: [`GSD_SLICE_LOCK=${sliceLock} not found in active milestone slices`],
694
+ nextAction: 'Slice lock references a non-existent slice — check orchestrator dispatch.',
695
+ registry, requirements,
696
+ progress: { milestones: milestoneProgress, slices: sliceProgress },
697
+ };
698
+ }
699
+ } else {
700
+ for (const s of activeMilestoneSlices) {
701
+ if (isStatusDone(s.status)) continue;
702
+ // #2661: Skip deferred slices — a decision explicitly deferred this work.
703
+ // Without this guard the dispatcher would keep dispatching deferred slices
704
+ // because DECISIONS.md is only contextual, not authoritative for dispatch.
705
+ if (isDeferredStatus(s.status)) continue;
706
+ if (s.depends.every(dep => doneSliceIds.has(dep))) {
707
+ activeSlice = { id: s.id, title: s.title };
708
+ activeSliceRow = s;
709
+ break;
710
+ }
683
711
  }
684
712
  }
685
713
 
@@ -1320,11 +1348,38 @@ export async function _deriveStateImpl(basePath: string): Promise<GSDState> {
1320
1348
  const doneSliceIds = new Set(activeRoadmap.slices.filter(s => s.done).map(s => s.id));
1321
1349
  let activeSlice: ActiveRef | null = null;
1322
1350
 
1323
- for (const s of activeRoadmap.slices) {
1324
- if (s.done) continue;
1325
- if (s.depends.every(dep => doneSliceIds.has(dep))) {
1326
- activeSlice = { id: s.id, title: s.title };
1327
- break;
1351
+ // ── Slice-level parallel worker isolation ─────────────────────────────
1352
+ // When GSD_SLICE_LOCK is set, override activeSlice to only the locked slice.
1353
+ const sliceLockLegacy = process.env.GSD_SLICE_LOCK;
1354
+ if (sliceLockLegacy) {
1355
+ const lockedSlice = activeRoadmap.slices.find(s => s.id === sliceLockLegacy);
1356
+ if (lockedSlice) {
1357
+ activeSlice = { id: lockedSlice.id, title: lockedSlice.title };
1358
+ } else {
1359
+ logWarning("state", `GSD_SLICE_LOCK=${sliceLockLegacy} not found in active slices — worker has no assigned work`);
1360
+ return {
1361
+ activeMilestone,
1362
+ activeSlice: null,
1363
+ activeTask: null,
1364
+ phase: 'blocked',
1365
+ recentDecisions: [],
1366
+ blockers: [`GSD_SLICE_LOCK=${sliceLockLegacy} not found in active milestone slices`],
1367
+ nextAction: 'Slice lock references a non-existent slice — check orchestrator dispatch.',
1368
+ registry,
1369
+ requirements,
1370
+ progress: {
1371
+ milestones: milestoneProgress,
1372
+ slices: sliceProgress,
1373
+ },
1374
+ };
1375
+ }
1376
+ } else {
1377
+ for (const s of activeRoadmap.slices) {
1378
+ if (s.done) continue;
1379
+ if (s.depends.every(dep => doneSliceIds.has(dep))) {
1380
+ activeSlice = { id: s.id, title: s.title };
1381
+ break;
1382
+ }
1328
1383
  }
1329
1384
  }
1330
1385
 
@@ -12,3 +12,16 @@
12
12
  export function isClosedStatus(status: string): boolean {
13
13
  return status === "complete" || status === "done" || status === "skipped";
14
14
  }
15
+
16
+ /** Returns true when a slice status indicates it was deferred by a decision. */
17
+ export function isDeferredStatus(status: string): boolean {
18
+ return status === "deferred";
19
+ }
20
+
21
+ /**
22
+ * Returns true when a slice should be skipped during active-slice selection.
23
+ * This includes both closed (complete/done) and deferred slices.
24
+ */
25
+ export function isInactiveStatus(status: string): boolean {
26
+ return isClosedStatus(status) || isDeferredStatus(status);
27
+ }