gsd-pi 2.33.1 → 2.34.0-dev.bbb5216

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 (828) hide show
  1. package/dist/bundled-resource-path.d.ts +8 -0
  2. package/dist/bundled-resource-path.js +14 -0
  3. package/dist/cli.js +16 -0
  4. package/dist/headless-query.js +6 -6
  5. package/dist/resource-loader.d.ts +2 -0
  6. package/dist/resource-loader.js +39 -4
  7. package/dist/resources/extensions/ask-user-questions.js +217 -0
  8. package/dist/resources/extensions/async-jobs/async-bash-tool.js +180 -0
  9. package/dist/resources/extensions/async-jobs/await-tool.js +90 -0
  10. package/dist/resources/extensions/async-jobs/cancel-job-tool.js +28 -0
  11. package/dist/resources/extensions/async-jobs/index.js +119 -0
  12. package/dist/resources/extensions/async-jobs/job-manager.js +159 -0
  13. package/dist/resources/extensions/aws-auth/index.js +138 -0
  14. package/dist/resources/extensions/bg-shell/bg-shell-command.js +182 -0
  15. package/dist/resources/extensions/bg-shell/bg-shell-lifecycle.js +343 -0
  16. package/dist/resources/extensions/bg-shell/bg-shell-tool.js +831 -0
  17. package/dist/resources/extensions/bg-shell/index.js +41 -0
  18. package/dist/resources/extensions/bg-shell/interaction.js +160 -0
  19. package/dist/resources/extensions/bg-shell/output-formatter.js +245 -0
  20. package/dist/resources/extensions/bg-shell/overlay.js +378 -0
  21. package/dist/resources/extensions/bg-shell/process-manager.js +413 -0
  22. package/dist/resources/extensions/bg-shell/readiness-detector.js +109 -0
  23. package/dist/resources/extensions/bg-shell/types.js +96 -0
  24. package/dist/resources/extensions/bg-shell/utilities.js +50 -0
  25. package/dist/resources/extensions/browser-tools/capture.js +179 -0
  26. package/dist/resources/extensions/browser-tools/core.js +899 -0
  27. package/dist/resources/extensions/browser-tools/{evaluate-helpers.ts → evaluate-helpers.js} +0 -1
  28. package/dist/resources/extensions/browser-tools/index.js +123 -0
  29. package/dist/resources/extensions/browser-tools/lifecycle.js +222 -0
  30. package/dist/resources/extensions/browser-tools/refs.js +254 -0
  31. package/dist/resources/extensions/browser-tools/settle.js +173 -0
  32. package/dist/resources/extensions/browser-tools/state.js +126 -0
  33. package/dist/resources/extensions/browser-tools/tools/action-cache.js +179 -0
  34. package/dist/resources/extensions/browser-tools/tools/assertions.js +320 -0
  35. package/dist/resources/extensions/browser-tools/tools/codegen.js +242 -0
  36. package/dist/resources/extensions/browser-tools/tools/device.js +162 -0
  37. package/dist/resources/extensions/browser-tools/tools/extract.js +191 -0
  38. package/dist/resources/extensions/browser-tools/tools/forms.js +710 -0
  39. package/dist/resources/extensions/browser-tools/tools/injection-detect.js +178 -0
  40. package/dist/resources/extensions/browser-tools/tools/inspection.js +426 -0
  41. package/dist/resources/extensions/browser-tools/tools/intent.js +556 -0
  42. package/dist/resources/extensions/browser-tools/tools/interaction.js +776 -0
  43. package/dist/resources/extensions/browser-tools/tools/navigation.js +208 -0
  44. package/dist/resources/extensions/browser-tools/tools/network-mock.js +194 -0
  45. package/dist/resources/extensions/browser-tools/tools/pages.js +280 -0
  46. package/dist/resources/extensions/browser-tools/tools/pdf.js +74 -0
  47. package/dist/resources/extensions/browser-tools/tools/refs.js +485 -0
  48. package/dist/resources/extensions/browser-tools/tools/screenshot.js +87 -0
  49. package/dist/resources/extensions/browser-tools/tools/session.js +375 -0
  50. package/dist/resources/extensions/browser-tools/tools/state-persistence.js +180 -0
  51. package/dist/resources/extensions/browser-tools/tools/visual-diff.js +174 -0
  52. package/dist/resources/extensions/browser-tools/tools/wait.js +201 -0
  53. package/dist/resources/extensions/browser-tools/tools/zoom.js +90 -0
  54. package/dist/resources/extensions/browser-tools/utils.js +490 -0
  55. package/dist/resources/extensions/context7/index.js +337 -0
  56. package/dist/resources/extensions/get-secrets-from-user.js +492 -0
  57. package/dist/resources/extensions/google-search/index.js +373 -0
  58. package/dist/resources/extensions/gsd/activity-log.js +146 -0
  59. package/dist/resources/extensions/gsd/atomic-write.js +38 -0
  60. package/dist/resources/extensions/gsd/auto/session.js +182 -0
  61. package/dist/resources/extensions/gsd/auto-budget.js +30 -0
  62. package/dist/resources/extensions/gsd/auto-dashboard.js +429 -0
  63. package/dist/resources/extensions/gsd/auto-direct-dispatch.js +185 -0
  64. package/dist/resources/extensions/gsd/auto-dispatch.js +353 -0
  65. package/dist/resources/extensions/gsd/auto-loop.js +956 -0
  66. package/dist/resources/extensions/gsd/auto-model-selection.js +133 -0
  67. package/dist/resources/extensions/gsd/auto-observability.js +56 -0
  68. package/dist/resources/extensions/gsd/auto-post-unit.js +385 -0
  69. package/dist/resources/extensions/gsd/auto-prompts.js +1153 -0
  70. package/dist/resources/extensions/gsd/auto-recovery.js +512 -0
  71. package/dist/resources/extensions/gsd/auto-start.js +414 -0
  72. package/dist/resources/extensions/gsd/auto-supervisor.js +47 -0
  73. package/dist/resources/extensions/gsd/auto-timeout-recovery.js +183 -0
  74. package/dist/resources/extensions/gsd/auto-timers.js +180 -0
  75. package/dist/resources/extensions/gsd/auto-tool-tracking.js +50 -0
  76. package/dist/resources/extensions/gsd/auto-unit-closeout.js +30 -0
  77. package/dist/resources/extensions/gsd/auto-verification.js +171 -0
  78. package/dist/resources/extensions/gsd/auto-worktree-sync.js +167 -0
  79. package/dist/resources/extensions/gsd/auto-worktree.js +830 -0
  80. package/dist/resources/extensions/gsd/auto.js +765 -0
  81. package/dist/resources/extensions/gsd/{cache.ts → cache.js} +5 -7
  82. package/dist/resources/extensions/gsd/captures.js +354 -0
  83. package/dist/resources/extensions/gsd/claude-import.js +540 -0
  84. package/dist/resources/extensions/gsd/collision-diagnostics.js +226 -0
  85. package/dist/resources/extensions/gsd/commands-bootstrap.js +223 -0
  86. package/dist/resources/extensions/gsd/commands-config.js +89 -0
  87. package/dist/resources/extensions/gsd/commands-extensions.js +259 -0
  88. package/dist/resources/extensions/gsd/commands-handlers.js +310 -0
  89. package/dist/resources/extensions/gsd/commands-inspect.js +70 -0
  90. package/dist/resources/extensions/gsd/commands-logs.js +468 -0
  91. package/dist/resources/extensions/gsd/commands-maintenance.js +185 -0
  92. package/dist/resources/extensions/gsd/commands-prefs-wizard.js +660 -0
  93. package/dist/resources/extensions/gsd/commands-workflow-templates.js +408 -0
  94. package/dist/resources/extensions/gsd/commands.js +1024 -0
  95. package/dist/resources/extensions/gsd/complexity-classifier.js +257 -0
  96. package/dist/resources/extensions/gsd/{constants.ts → constants.js} +0 -6
  97. package/dist/resources/extensions/gsd/context-budget.js +187 -0
  98. package/dist/resources/extensions/gsd/context-store.js +165 -0
  99. package/dist/resources/extensions/gsd/crash-recovery.js +110 -0
  100. package/dist/resources/extensions/gsd/dashboard-overlay.js +562 -0
  101. package/dist/resources/extensions/gsd/db-writer.js +298 -0
  102. package/dist/resources/extensions/gsd/debug-logger.js +161 -0
  103. package/dist/resources/extensions/gsd/detection.js +373 -0
  104. package/dist/resources/extensions/gsd/diff-context.js +168 -0
  105. package/dist/resources/extensions/gsd/dispatch-guard.js +75 -0
  106. package/dist/resources/extensions/gsd/docs/preferences-reference.md +25 -18
  107. package/dist/resources/extensions/gsd/doctor-checks.js +562 -0
  108. package/dist/resources/extensions/gsd/doctor-environment.js +429 -0
  109. package/dist/resources/extensions/gsd/doctor-format.js +71 -0
  110. package/dist/resources/extensions/gsd/doctor-proactive.js +239 -0
  111. package/dist/resources/extensions/gsd/doctor-providers.js +292 -0
  112. package/dist/resources/extensions/gsd/doctor-types.js +12 -0
  113. package/dist/resources/extensions/gsd/doctor.js +672 -0
  114. package/dist/resources/extensions/gsd/error-utils.js +6 -0
  115. package/dist/resources/extensions/gsd/{errors.ts → errors.js} +6 -11
  116. package/dist/resources/extensions/gsd/exit-command.js +11 -0
  117. package/dist/resources/extensions/gsd/{export-html.ts → export-html.js} +482 -614
  118. package/dist/resources/extensions/gsd/export.js +268 -0
  119. package/dist/resources/extensions/gsd/file-watcher.js +76 -0
  120. package/dist/resources/extensions/gsd/files.js +937 -0
  121. package/dist/resources/extensions/gsd/forensics.js +511 -0
  122. package/dist/resources/extensions/gsd/{git-constants.ts → git-constants.js} +4 -5
  123. package/dist/resources/extensions/gsd/git-self-heal.js +113 -0
  124. package/dist/resources/extensions/gsd/git-service.js +460 -0
  125. package/dist/resources/extensions/gsd/{gitignore.ts → gitignore.js} +98 -125
  126. package/dist/resources/extensions/gsd/gsd-db.js +735 -0
  127. package/dist/resources/extensions/gsd/guided-flow-queue.js +366 -0
  128. package/dist/resources/extensions/gsd/guided-flow.js +1158 -0
  129. package/dist/resources/extensions/gsd/health-widget.js +141 -0
  130. package/dist/resources/extensions/gsd/history.js +118 -0
  131. package/dist/resources/extensions/gsd/index.js +1114 -0
  132. package/dist/resources/extensions/gsd/init-wizard.js +479 -0
  133. package/dist/resources/extensions/gsd/json-persistence.js +62 -0
  134. package/dist/resources/extensions/gsd/{jsonl-utils.ts → jsonl-utils.js} +10 -7
  135. package/dist/resources/extensions/gsd/key-manager.js +829 -0
  136. package/dist/resources/extensions/gsd/marketplace-discovery.js +356 -0
  137. package/dist/resources/extensions/gsd/md-importer.js +440 -0
  138. package/dist/resources/extensions/gsd/memory-extractor.js +295 -0
  139. package/dist/resources/extensions/gsd/memory-store.js +351 -0
  140. package/dist/resources/extensions/gsd/metrics.js +377 -0
  141. package/dist/resources/extensions/gsd/migrate/command.js +157 -0
  142. package/dist/resources/extensions/gsd/migrate/index.js +7 -0
  143. package/dist/resources/extensions/gsd/migrate/parser.js +268 -0
  144. package/dist/resources/extensions/gsd/migrate/parsers.js +477 -0
  145. package/dist/resources/extensions/gsd/migrate/preview.js +47 -0
  146. package/dist/resources/extensions/gsd/migrate/transformer.js +278 -0
  147. package/dist/resources/extensions/gsd/migrate/types.js +4 -0
  148. package/dist/resources/extensions/gsd/migrate/validator.js +41 -0
  149. package/dist/resources/extensions/gsd/migrate/writer.js +477 -0
  150. package/dist/resources/extensions/gsd/migrate-external.js +130 -0
  151. package/dist/resources/extensions/gsd/milestone-actions.js +111 -0
  152. package/dist/resources/extensions/gsd/{milestone-ids.ts → milestone-ids.js} +50 -63
  153. package/dist/resources/extensions/gsd/model-cost-table.js +48 -0
  154. package/dist/resources/extensions/gsd/model-router.js +187 -0
  155. package/dist/resources/extensions/gsd/namespaced-registry.js +322 -0
  156. package/dist/resources/extensions/gsd/namespaced-resolver.js +176 -0
  157. package/dist/resources/extensions/gsd/native-git-bridge.js +842 -0
  158. package/dist/resources/extensions/gsd/native-parser-bridge.js +156 -0
  159. package/dist/resources/extensions/gsd/notifications.js +58 -0
  160. package/dist/resources/extensions/gsd/observability-validator.js +398 -0
  161. package/dist/resources/extensions/gsd/parallel-eligibility.js +182 -0
  162. package/dist/resources/extensions/gsd/parallel-merge.js +121 -0
  163. package/dist/resources/extensions/gsd/parallel-orchestrator.js +687 -0
  164. package/dist/resources/extensions/gsd/paths.js +414 -0
  165. package/dist/resources/extensions/gsd/plugin-importer.js +254 -0
  166. package/dist/resources/extensions/gsd/post-unit-hooks.js +433 -0
  167. package/dist/resources/extensions/gsd/preferences-models.js +294 -0
  168. package/dist/resources/extensions/gsd/preferences-skills.js +154 -0
  169. package/dist/resources/extensions/gsd/preferences-types.js +73 -0
  170. package/dist/resources/extensions/gsd/preferences-validation.js +607 -0
  171. package/dist/resources/extensions/gsd/preferences.js +325 -0
  172. package/dist/resources/extensions/gsd/progress-score.js +102 -0
  173. package/dist/resources/extensions/gsd/prompt-cache-optimizer.js +150 -0
  174. package/dist/resources/extensions/gsd/prompt-compressor.js +393 -0
  175. package/dist/resources/extensions/gsd/prompt-loader.js +119 -0
  176. package/dist/resources/extensions/gsd/prompt-ordering.js +170 -0
  177. package/dist/resources/extensions/gsd/provider-error-pause.js +60 -0
  178. package/dist/resources/extensions/gsd/queue-order.js +178 -0
  179. package/dist/resources/extensions/gsd/queue-reorder-ui.js +234 -0
  180. package/dist/resources/extensions/gsd/quick.js +206 -0
  181. package/dist/resources/extensions/gsd/repo-identity.js +187 -0
  182. package/dist/resources/extensions/gsd/{reports.ts → reports.js} +146 -241
  183. package/dist/resources/extensions/gsd/{resource-version.ts → resource-version.js} +50 -53
  184. package/dist/resources/extensions/gsd/roadmap-slices.js +130 -0
  185. package/dist/resources/extensions/gsd/routing-history.js +210 -0
  186. package/dist/resources/extensions/gsd/safe-fs.js +52 -0
  187. package/dist/resources/extensions/gsd/semantic-chunker.js +254 -0
  188. package/dist/resources/extensions/gsd/session-forensics.js +427 -0
  189. package/dist/resources/extensions/gsd/session-lock.js +397 -0
  190. package/dist/resources/extensions/gsd/session-status-io.js +134 -0
  191. package/dist/resources/extensions/gsd/skill-discovery.js +121 -0
  192. package/dist/resources/extensions/gsd/skill-health.js +324 -0
  193. package/dist/resources/extensions/gsd/{skill-telemetry.ts → skill-telemetry.js} +58 -74
  194. package/dist/resources/extensions/gsd/state.js +653 -0
  195. package/dist/resources/extensions/gsd/structured-data-formatter.js +97 -0
  196. package/dist/resources/extensions/gsd/summary-distiller.js +212 -0
  197. package/dist/resources/extensions/gsd/templates/preferences.md +1 -0
  198. package/dist/resources/extensions/gsd/token-counter.js +54 -0
  199. package/dist/resources/extensions/gsd/triage-resolution.js +217 -0
  200. package/dist/resources/extensions/gsd/triage-ui.js +125 -0
  201. package/dist/resources/extensions/gsd/types.js +4 -0
  202. package/dist/resources/extensions/gsd/undo.js +205 -0
  203. package/dist/resources/extensions/gsd/unit-id.js +7 -0
  204. package/dist/resources/extensions/gsd/unit-runtime.js +131 -0
  205. package/dist/resources/extensions/gsd/validate-directory.js +143 -0
  206. package/dist/resources/extensions/gsd/verification-evidence.js +122 -0
  207. package/dist/resources/extensions/gsd/verification-gate.js +514 -0
  208. package/dist/resources/extensions/gsd/visualizer-data.js +612 -0
  209. package/dist/resources/extensions/gsd/visualizer-overlay.js +501 -0
  210. package/dist/resources/extensions/gsd/visualizer-views.js +893 -0
  211. package/dist/resources/extensions/gsd/workflow-templates.js +188 -0
  212. package/dist/resources/extensions/gsd/workspace-index.js +139 -0
  213. package/dist/resources/extensions/gsd/worktree-command-bootstrap.js +40 -0
  214. package/dist/resources/extensions/gsd/worktree-command.js +682 -0
  215. package/dist/resources/extensions/gsd/worktree-manager.js +358 -0
  216. package/dist/resources/extensions/gsd/worktree-resolver.js +344 -0
  217. package/dist/resources/extensions/gsd/worktree.js +199 -0
  218. package/dist/resources/extensions/mac-tools/index.js +768 -0
  219. package/dist/resources/extensions/mcp-client/index.js +363 -0
  220. package/dist/resources/extensions/package.json +3 -0
  221. package/dist/resources/extensions/remote-questions/config.js +70 -0
  222. package/dist/resources/extensions/remote-questions/discord-adapter.js +134 -0
  223. package/dist/resources/extensions/remote-questions/format.js +234 -0
  224. package/dist/resources/extensions/remote-questions/http-client.js +43 -0
  225. package/dist/resources/extensions/remote-questions/manager.js +156 -0
  226. package/dist/resources/extensions/remote-questions/{mod.ts → mod.js} +1 -10
  227. package/dist/resources/extensions/remote-questions/notify.js +89 -0
  228. package/dist/resources/extensions/remote-questions/remote-command.js +453 -0
  229. package/dist/resources/extensions/remote-questions/slack-adapter.js +123 -0
  230. package/dist/resources/extensions/remote-questions/status.js +25 -0
  231. package/dist/resources/extensions/remote-questions/store.js +70 -0
  232. package/dist/resources/extensions/remote-questions/telegram-adapter.js +123 -0
  233. package/dist/resources/extensions/remote-questions/types.js +5 -0
  234. package/dist/resources/extensions/search-the-web/cache.js +74 -0
  235. package/dist/resources/extensions/search-the-web/command-search-provider.js +79 -0
  236. package/dist/resources/extensions/search-the-web/format.js +161 -0
  237. package/dist/resources/extensions/search-the-web/http.js +178 -0
  238. package/dist/resources/extensions/search-the-web/index.js +41 -0
  239. package/dist/resources/extensions/search-the-web/native-search.js +166 -0
  240. package/dist/resources/extensions/search-the-web/provider.js +143 -0
  241. package/dist/resources/extensions/search-the-web/tavily.js +82 -0
  242. package/dist/resources/extensions/search-the-web/tool-fetch-page.js +452 -0
  243. package/dist/resources/extensions/search-the-web/tool-llm-context.js +455 -0
  244. package/dist/resources/extensions/search-the-web/tool-search.js +482 -0
  245. package/dist/resources/extensions/search-the-web/url-utils.js +121 -0
  246. package/dist/resources/extensions/shared/confirm-ui.js +96 -0
  247. package/dist/resources/extensions/shared/{format-utils.ts → format-utils.js} +85 -91
  248. package/dist/resources/extensions/shared/frontmatter.js +109 -0
  249. package/dist/resources/extensions/shared/interview-ui.js +569 -0
  250. package/dist/resources/extensions/shared/{mod.ts → mod.js} +2 -24
  251. package/dist/resources/extensions/shared/next-action-ui.js +168 -0
  252. package/dist/resources/extensions/shared/{path-display.ts → path-display.js} +2 -3
  253. package/dist/resources/extensions/shared/sanitize.js +17 -0
  254. package/dist/resources/extensions/shared/terminal.js +21 -0
  255. package/dist/resources/extensions/shared/ui.js +245 -0
  256. package/dist/resources/extensions/shared/wizard-ui.js +478 -0
  257. package/dist/resources/extensions/slash-commands/audit.js +72 -0
  258. package/dist/resources/extensions/slash-commands/clear.js +8 -0
  259. package/dist/resources/extensions/slash-commands/create-extension.js +264 -0
  260. package/dist/resources/extensions/slash-commands/create-slash-command.js +208 -0
  261. package/dist/resources/extensions/slash-commands/index.js +10 -0
  262. package/dist/resources/extensions/subagent/agents.js +103 -0
  263. package/dist/resources/extensions/subagent/index.js +905 -0
  264. package/dist/resources/extensions/subagent/isolation.js +384 -0
  265. package/dist/resources/extensions/subagent/worker-registry.js +73 -0
  266. package/dist/resources/extensions/ttsr/index.js +144 -0
  267. package/dist/resources/extensions/ttsr/rule-loader.js +70 -0
  268. package/dist/resources/extensions/ttsr/ttsr-manager.js +380 -0
  269. package/dist/resources/extensions/universal-config/discovery.js +94 -0
  270. package/dist/resources/extensions/universal-config/format.js +178 -0
  271. package/dist/resources/extensions/universal-config/index.js +99 -0
  272. package/dist/resources/extensions/universal-config/scanners.js +574 -0
  273. package/dist/resources/extensions/universal-config/tools.js +57 -0
  274. package/dist/resources/extensions/universal-config/types.js +8 -0
  275. package/dist/resources/extensions/voice/index.js +247 -0
  276. package/dist/startup-timings.d.ts +2 -0
  277. package/dist/startup-timings.js +22 -0
  278. package/dist/tool-bootstrap.js +59 -11
  279. package/dist/worktree-cli.js +7 -7
  280. package/package.json +1 -1
  281. package/packages/pi-coding-agent/dist/core/agent-session.d.ts.map +1 -1
  282. package/packages/pi-coding-agent/dist/core/agent-session.js +9 -0
  283. package/packages/pi-coding-agent/dist/core/agent-session.js.map +1 -1
  284. package/packages/pi-coding-agent/dist/core/extensions/index.d.ts +1 -1
  285. package/packages/pi-coding-agent/dist/core/extensions/index.d.ts.map +1 -1
  286. package/packages/pi-coding-agent/dist/core/extensions/index.js +1 -1
  287. package/packages/pi-coding-agent/dist/core/extensions/index.js.map +1 -1
  288. package/packages/pi-coding-agent/dist/core/extensions/loader.d.ts +1 -0
  289. package/packages/pi-coding-agent/dist/core/extensions/loader.d.ts.map +1 -1
  290. package/packages/pi-coding-agent/dist/core/extensions/loader.js +31 -4
  291. package/packages/pi-coding-agent/dist/core/extensions/loader.js.map +1 -1
  292. package/packages/pi-coding-agent/dist/index.d.ts +1 -1
  293. package/packages/pi-coding-agent/dist/index.d.ts.map +1 -1
  294. package/packages/pi-coding-agent/dist/index.js +1 -1
  295. package/packages/pi-coding-agent/dist/index.js.map +1 -1
  296. package/packages/pi-coding-agent/package.json +1 -1
  297. package/packages/pi-coding-agent/src/core/agent-session.ts +9 -0
  298. package/packages/pi-coding-agent/src/core/extensions/index.ts +1 -0
  299. package/packages/pi-coding-agent/src/core/extensions/loader.ts +35 -4
  300. package/packages/pi-coding-agent/src/index.ts +1 -0
  301. package/pkg/package.json +1 -1
  302. package/src/resources/extensions/bg-shell/index.ts +41 -46
  303. package/src/resources/extensions/browser-tools/index.ts +156 -67
  304. package/src/resources/extensions/gsd/auto/session.ts +47 -30
  305. package/src/resources/extensions/gsd/auto-dashboard.ts +28 -131
  306. package/src/resources/extensions/gsd/auto-direct-dispatch.ts +6 -1
  307. package/src/resources/extensions/gsd/auto-dispatch.ts +135 -91
  308. package/src/resources/extensions/gsd/auto-loop.ts +1665 -0
  309. package/src/resources/extensions/gsd/auto-observability.ts +4 -2
  310. package/src/resources/extensions/gsd/auto-post-unit.ts +85 -228
  311. package/src/resources/extensions/gsd/auto-prompts.ts +138 -109
  312. package/src/resources/extensions/gsd/auto-recovery.ts +124 -118
  313. package/src/resources/extensions/gsd/auto-start.ts +440 -354
  314. package/src/resources/extensions/gsd/auto-supervisor.ts +5 -12
  315. package/src/resources/extensions/gsd/auto-timeout-recovery.ts +8 -8
  316. package/src/resources/extensions/gsd/auto-timers.ts +3 -4
  317. package/src/resources/extensions/gsd/auto-verification.ts +76 -72
  318. package/src/resources/extensions/gsd/auto-worktree-sync.ts +204 -0
  319. package/src/resources/extensions/gsd/auto-worktree.ts +453 -133
  320. package/src/resources/extensions/gsd/auto.ts +516 -1189
  321. package/src/resources/extensions/gsd/captures.ts +10 -4
  322. package/src/resources/extensions/gsd/commands-bootstrap.ts +252 -0
  323. package/src/resources/extensions/gsd/commands.ts +39 -31
  324. package/src/resources/extensions/gsd/dispatch-guard.ts +13 -9
  325. package/src/resources/extensions/gsd/docs/preferences-reference.md +25 -18
  326. package/src/resources/extensions/gsd/doctor-checks.ts +3 -4
  327. package/src/resources/extensions/gsd/git-service.ts +32 -12
  328. package/src/resources/extensions/gsd/gitignore.ts +4 -2
  329. package/src/resources/extensions/gsd/gsd-db.ts +375 -180
  330. package/src/resources/extensions/gsd/guided-flow.ts +22 -11
  331. package/src/resources/extensions/gsd/index.ts +76 -163
  332. package/src/resources/extensions/gsd/post-unit-hooks.ts +13 -13
  333. package/src/resources/extensions/gsd/progress-score.ts +65 -200
  334. package/src/resources/extensions/gsd/quick.ts +121 -76
  335. package/src/resources/extensions/gsd/repo-identity.ts +56 -22
  336. package/src/resources/extensions/gsd/session-lock.ts +17 -0
  337. package/src/resources/extensions/gsd/templates/preferences.md +1 -0
  338. package/src/resources/extensions/gsd/tests/agent-end-retry.test.ts +32 -59
  339. package/src/resources/extensions/gsd/tests/all-milestones-complete-merge.test.ts +75 -27
  340. package/src/resources/extensions/gsd/tests/auto-budget-alerts.test.ts +1 -1
  341. package/src/resources/extensions/gsd/tests/auto-lock-creation.test.ts +37 -0
  342. package/src/resources/extensions/gsd/tests/auto-loop.test.ts +1458 -0
  343. package/src/resources/extensions/gsd/tests/auto-recovery.test.ts +8 -162
  344. package/src/resources/extensions/gsd/tests/auto-secrets-gate.test.ts +2 -108
  345. package/src/resources/extensions/gsd/tests/auto-session-encapsulation.test.ts +1 -3
  346. package/src/resources/extensions/gsd/tests/auto-worktree-milestone-merge.test.ts +0 -3
  347. package/src/resources/extensions/gsd/tests/auto-worktree.test.ts +58 -0
  348. package/src/resources/extensions/gsd/tests/dispatch-guard.test.ts +0 -55
  349. package/src/resources/extensions/gsd/tests/git-service.test.ts +16 -7
  350. package/src/resources/extensions/gsd/tests/headless-query.test.ts +22 -0
  351. package/src/resources/extensions/gsd/tests/milestone-transition-worktree.test.ts +8 -11
  352. package/src/resources/extensions/gsd/tests/provider-errors.test.ts +4 -6
  353. package/src/resources/extensions/gsd/tests/quick-branch-lifecycle.test.ts +281 -0
  354. package/src/resources/extensions/gsd/tests/repo-identity-worktree.test.ts +71 -0
  355. package/src/resources/extensions/gsd/tests/run-uat.test.ts +3 -3
  356. package/src/resources/extensions/gsd/tests/session-lock-regression.test.ts +64 -0
  357. package/src/resources/extensions/gsd/tests/sidecar-queue.test.ts +181 -0
  358. package/src/resources/extensions/gsd/tests/stale-worktree-cwd.test.ts +0 -3
  359. package/src/resources/extensions/gsd/tests/token-profile.test.ts +6 -6
  360. package/src/resources/extensions/gsd/tests/triage-dispatch.test.ts +6 -6
  361. package/src/resources/extensions/gsd/tests/undo.test.ts +6 -0
  362. package/src/resources/extensions/gsd/tests/verification-evidence.test.ts +24 -26
  363. package/src/resources/extensions/gsd/tests/verification-gate.test.ts +7 -136
  364. package/src/resources/extensions/gsd/tests/worktree-db-integration.test.ts +205 -0
  365. package/src/resources/extensions/gsd/tests/worktree-db.test.ts +442 -0
  366. package/src/resources/extensions/gsd/tests/worktree-e2e.test.ts +0 -3
  367. package/src/resources/extensions/gsd/tests/worktree-resolver.test.ts +705 -0
  368. package/src/resources/extensions/gsd/tests/worktree-sync-milestones.test.ts +57 -106
  369. package/src/resources/extensions/gsd/tests/worktree.test.ts +5 -1
  370. package/src/resources/extensions/gsd/tests/write-gate.test.ts +43 -132
  371. package/src/resources/extensions/gsd/types.ts +90 -77
  372. package/src/resources/extensions/gsd/undo.ts +42 -46
  373. package/src/resources/extensions/gsd/unit-runtime.ts +14 -18
  374. package/src/resources/extensions/gsd/verification-evidence.ts +0 -2
  375. package/src/resources/extensions/gsd/verification-gate.ts +4 -16
  376. package/src/resources/extensions/gsd/worktree-command-bootstrap.ts +46 -0
  377. package/src/resources/extensions/gsd/worktree-command.ts +29 -11
  378. package/src/resources/extensions/gsd/worktree-manager.ts +2 -3
  379. package/src/resources/extensions/gsd/worktree-resolver.ts +485 -0
  380. package/src/resources/extensions/gsd/worktree.ts +7 -44
  381. package/src/resources/extensions/package.json +3 -0
  382. package/src/resources/extensions/search-the-web/command-search-provider.ts +1 -1
  383. package/src/resources/extensions/search-the-web/index.ts +35 -52
  384. package/src/resources/extensions/search-the-web/tavily.ts +1 -1
  385. package/dist/resources/extensions/ask-user-questions.ts +0 -290
  386. package/dist/resources/extensions/async-jobs/async-bash-tool.ts +0 -212
  387. package/dist/resources/extensions/async-jobs/await-tool.ts +0 -103
  388. package/dist/resources/extensions/async-jobs/cancel-job-tool.ts +0 -35
  389. package/dist/resources/extensions/async-jobs/index.ts +0 -141
  390. package/dist/resources/extensions/async-jobs/job-manager.ts +0 -211
  391. package/dist/resources/extensions/aws-auth/index.ts +0 -144
  392. package/dist/resources/extensions/bg-shell/bg-shell-command.ts +0 -219
  393. package/dist/resources/extensions/bg-shell/bg-shell-lifecycle.ts +0 -400
  394. package/dist/resources/extensions/bg-shell/bg-shell-tool.ts +0 -985
  395. package/dist/resources/extensions/bg-shell/index.ts +0 -59
  396. package/dist/resources/extensions/bg-shell/interaction.ts +0 -198
  397. package/dist/resources/extensions/bg-shell/output-formatter.ts +0 -279
  398. package/dist/resources/extensions/bg-shell/overlay.ts +0 -437
  399. package/dist/resources/extensions/bg-shell/process-manager.ts +0 -464
  400. package/dist/resources/extensions/bg-shell/readiness-detector.ts +0 -126
  401. package/dist/resources/extensions/bg-shell/types.ts +0 -303
  402. package/dist/resources/extensions/bg-shell/utilities.ts +0 -57
  403. package/dist/resources/extensions/browser-tools/capture.ts +0 -199
  404. package/dist/resources/extensions/browser-tools/core.ts +0 -1196
  405. package/dist/resources/extensions/browser-tools/index.ts +0 -71
  406. package/dist/resources/extensions/browser-tools/lifecycle.ts +0 -270
  407. package/dist/resources/extensions/browser-tools/refs.ts +0 -264
  408. package/dist/resources/extensions/browser-tools/settle.ts +0 -197
  409. package/dist/resources/extensions/browser-tools/state.ts +0 -408
  410. package/dist/resources/extensions/browser-tools/tools/action-cache.ts +0 -216
  411. package/dist/resources/extensions/browser-tools/tools/assertions.ts +0 -342
  412. package/dist/resources/extensions/browser-tools/tools/codegen.ts +0 -274
  413. package/dist/resources/extensions/browser-tools/tools/device.ts +0 -183
  414. package/dist/resources/extensions/browser-tools/tools/extract.ts +0 -229
  415. package/dist/resources/extensions/browser-tools/tools/forms.ts +0 -801
  416. package/dist/resources/extensions/browser-tools/tools/injection-detect.ts +0 -221
  417. package/dist/resources/extensions/browser-tools/tools/inspection.ts +0 -492
  418. package/dist/resources/extensions/browser-tools/tools/intent.ts +0 -614
  419. package/dist/resources/extensions/browser-tools/tools/interaction.ts +0 -865
  420. package/dist/resources/extensions/browser-tools/tools/navigation.ts +0 -232
  421. package/dist/resources/extensions/browser-tools/tools/network-mock.ts +0 -244
  422. package/dist/resources/extensions/browser-tools/tools/pages.ts +0 -303
  423. package/dist/resources/extensions/browser-tools/tools/pdf.ts +0 -92
  424. package/dist/resources/extensions/browser-tools/tools/refs.ts +0 -541
  425. package/dist/resources/extensions/browser-tools/tools/screenshot.ts +0 -101
  426. package/dist/resources/extensions/browser-tools/tools/session.ts +0 -400
  427. package/dist/resources/extensions/browser-tools/tools/state-persistence.ts +0 -202
  428. package/dist/resources/extensions/browser-tools/tools/visual-diff.ts +0 -209
  429. package/dist/resources/extensions/browser-tools/tools/wait.ts +0 -247
  430. package/dist/resources/extensions/browser-tools/tools/zoom.ts +0 -104
  431. package/dist/resources/extensions/browser-tools/utils.ts +0 -660
  432. package/dist/resources/extensions/context7/index.ts +0 -428
  433. package/dist/resources/extensions/get-secrets-from-user.ts +0 -607
  434. package/dist/resources/extensions/google-search/index.ts +0 -466
  435. package/dist/resources/extensions/gsd/activity-log.ts +0 -162
  436. package/dist/resources/extensions/gsd/atomic-write.ts +0 -35
  437. package/dist/resources/extensions/gsd/auto/session.ts +0 -236
  438. package/dist/resources/extensions/gsd/auto-budget.ts +0 -32
  439. package/dist/resources/extensions/gsd/auto-constants.ts +0 -6
  440. package/dist/resources/extensions/gsd/auto-dashboard.ts +0 -626
  441. package/dist/resources/extensions/gsd/auto-direct-dispatch.ts +0 -224
  442. package/dist/resources/extensions/gsd/auto-dispatch.ts +0 -409
  443. package/dist/resources/extensions/gsd/auto-idempotency.ts +0 -151
  444. package/dist/resources/extensions/gsd/auto-model-selection.ts +0 -179
  445. package/dist/resources/extensions/gsd/auto-observability.ts +0 -72
  446. package/dist/resources/extensions/gsd/auto-post-unit.ts +0 -618
  447. package/dist/resources/extensions/gsd/auto-prompts.ts +0 -1273
  448. package/dist/resources/extensions/gsd/auto-recovery.ts +0 -578
  449. package/dist/resources/extensions/gsd/auto-start.ts +0 -483
  450. package/dist/resources/extensions/gsd/auto-stuck-detection.ts +0 -221
  451. package/dist/resources/extensions/gsd/auto-supervisor.ts +0 -61
  452. package/dist/resources/extensions/gsd/auto-timeout-recovery.ts +0 -263
  453. package/dist/resources/extensions/gsd/auto-timers.ts +0 -224
  454. package/dist/resources/extensions/gsd/auto-tool-tracking.ts +0 -54
  455. package/dist/resources/extensions/gsd/auto-unit-closeout.ts +0 -48
  456. package/dist/resources/extensions/gsd/auto-verification.ts +0 -229
  457. package/dist/resources/extensions/gsd/auto-worktree.ts +0 -658
  458. package/dist/resources/extensions/gsd/auto.ts +0 -1834
  459. package/dist/resources/extensions/gsd/captures.ts +0 -427
  460. package/dist/resources/extensions/gsd/claude-import.ts +0 -656
  461. package/dist/resources/extensions/gsd/collision-diagnostics.ts +0 -332
  462. package/dist/resources/extensions/gsd/commands-config.ts +0 -102
  463. package/dist/resources/extensions/gsd/commands-extensions.ts +0 -328
  464. package/dist/resources/extensions/gsd/commands-handlers.ts +0 -395
  465. package/dist/resources/extensions/gsd/commands-inspect.ts +0 -91
  466. package/dist/resources/extensions/gsd/commands-logs.ts +0 -536
  467. package/dist/resources/extensions/gsd/commands-maintenance.ts +0 -206
  468. package/dist/resources/extensions/gsd/commands-prefs-wizard.ts +0 -780
  469. package/dist/resources/extensions/gsd/commands-workflow-templates.ts +0 -543
  470. package/dist/resources/extensions/gsd/commands.ts +0 -1149
  471. package/dist/resources/extensions/gsd/complexity-classifier.ts +0 -320
  472. package/dist/resources/extensions/gsd/context-budget.ts +0 -266
  473. package/dist/resources/extensions/gsd/context-store.ts +0 -195
  474. package/dist/resources/extensions/gsd/crash-recovery.ts +0 -121
  475. package/dist/resources/extensions/gsd/dashboard-overlay.ts +0 -681
  476. package/dist/resources/extensions/gsd/db-writer.ts +0 -360
  477. package/dist/resources/extensions/gsd/debug-logger.ts +0 -178
  478. package/dist/resources/extensions/gsd/detection.ts +0 -470
  479. package/dist/resources/extensions/gsd/diff-context.ts +0 -214
  480. package/dist/resources/extensions/gsd/dispatch-guard.ts +0 -81
  481. package/dist/resources/extensions/gsd/doctor-checks.ts +0 -612
  482. package/dist/resources/extensions/gsd/doctor-environment.ts +0 -497
  483. package/dist/resources/extensions/gsd/doctor-format.ts +0 -78
  484. package/dist/resources/extensions/gsd/doctor-proactive.ts +0 -292
  485. package/dist/resources/extensions/gsd/doctor-providers.ts +0 -343
  486. package/dist/resources/extensions/gsd/doctor-types.ts +0 -87
  487. package/dist/resources/extensions/gsd/doctor.ts +0 -722
  488. package/dist/resources/extensions/gsd/error-utils.ts +0 -6
  489. package/dist/resources/extensions/gsd/exit-command.ts +0 -18
  490. package/dist/resources/extensions/gsd/export.ts +0 -317
  491. package/dist/resources/extensions/gsd/file-watcher.ts +0 -97
  492. package/dist/resources/extensions/gsd/files.ts +0 -1058
  493. package/dist/resources/extensions/gsd/forensics.ts +0 -629
  494. package/dist/resources/extensions/gsd/git-self-heal.ts +0 -127
  495. package/dist/resources/extensions/gsd/git-service.ts +0 -580
  496. package/dist/resources/extensions/gsd/gsd-db.ts +0 -685
  497. package/dist/resources/extensions/gsd/guided-flow-queue.ts +0 -440
  498. package/dist/resources/extensions/gsd/guided-flow.ts +0 -1303
  499. package/dist/resources/extensions/gsd/health-widget.ts +0 -167
  500. package/dist/resources/extensions/gsd/history.ts +0 -143
  501. package/dist/resources/extensions/gsd/index.ts +0 -1390
  502. package/dist/resources/extensions/gsd/init-wizard.ts +0 -587
  503. package/dist/resources/extensions/gsd/json-persistence.ts +0 -67
  504. package/dist/resources/extensions/gsd/key-manager.ts +0 -996
  505. package/dist/resources/extensions/gsd/marketplace-discovery.ts +0 -508
  506. package/dist/resources/extensions/gsd/md-importer.ts +0 -527
  507. package/dist/resources/extensions/gsd/mechanical-completion.ts +0 -430
  508. package/dist/resources/extensions/gsd/memory-extractor.ts +0 -352
  509. package/dist/resources/extensions/gsd/memory-store.ts +0 -441
  510. package/dist/resources/extensions/gsd/metrics.ts +0 -532
  511. package/dist/resources/extensions/gsd/migrate/command.ts +0 -219
  512. package/dist/resources/extensions/gsd/migrate/index.ts +0 -42
  513. package/dist/resources/extensions/gsd/migrate/parser.ts +0 -323
  514. package/dist/resources/extensions/gsd/migrate/parsers.ts +0 -539
  515. package/dist/resources/extensions/gsd/migrate/preview.ts +0 -48
  516. package/dist/resources/extensions/gsd/migrate/transformer.ts +0 -346
  517. package/dist/resources/extensions/gsd/migrate/types.ts +0 -370
  518. package/dist/resources/extensions/gsd/migrate/validator.ts +0 -55
  519. package/dist/resources/extensions/gsd/migrate/writer.ts +0 -579
  520. package/dist/resources/extensions/gsd/migrate-external.ts +0 -140
  521. package/dist/resources/extensions/gsd/milestone-actions.ts +0 -126
  522. package/dist/resources/extensions/gsd/model-cost-table.ts +0 -65
  523. package/dist/resources/extensions/gsd/model-router.ts +0 -256
  524. package/dist/resources/extensions/gsd/namespaced-registry.ts +0 -467
  525. package/dist/resources/extensions/gsd/namespaced-resolver.ts +0 -307
  526. package/dist/resources/extensions/gsd/native-git-bridge.ts +0 -1041
  527. package/dist/resources/extensions/gsd/native-parser-bridge.ts +0 -267
  528. package/dist/resources/extensions/gsd/notifications.ts +0 -87
  529. package/dist/resources/extensions/gsd/observability-validator.ts +0 -429
  530. package/dist/resources/extensions/gsd/parallel-eligibility.ts +0 -233
  531. package/dist/resources/extensions/gsd/parallel-merge.ts +0 -157
  532. package/dist/resources/extensions/gsd/parallel-orchestrator.ts +0 -826
  533. package/dist/resources/extensions/gsd/paths.ts +0 -449
  534. package/dist/resources/extensions/gsd/plugin-importer.ts +0 -411
  535. package/dist/resources/extensions/gsd/post-unit-hooks.ts +0 -520
  536. package/dist/resources/extensions/gsd/preferences-models.ts +0 -329
  537. package/dist/resources/extensions/gsd/preferences-skills.ts +0 -169
  538. package/dist/resources/extensions/gsd/preferences-types.ts +0 -229
  539. package/dist/resources/extensions/gsd/preferences-validation.ts +0 -590
  540. package/dist/resources/extensions/gsd/preferences.ts +0 -416
  541. package/dist/resources/extensions/gsd/progress-score.ts +0 -273
  542. package/dist/resources/extensions/gsd/prompt-cache-optimizer.ts +0 -213
  543. package/dist/resources/extensions/gsd/prompt-compressor.ts +0 -508
  544. package/dist/resources/extensions/gsd/prompt-loader.ts +0 -130
  545. package/dist/resources/extensions/gsd/prompt-ordering.ts +0 -200
  546. package/dist/resources/extensions/gsd/provider-error-pause.ts +0 -88
  547. package/dist/resources/extensions/gsd/queue-order.ts +0 -230
  548. package/dist/resources/extensions/gsd/queue-reorder-ui.ts +0 -276
  549. package/dist/resources/extensions/gsd/quick.ts +0 -212
  550. package/dist/resources/extensions/gsd/repo-identity.ts +0 -169
  551. package/dist/resources/extensions/gsd/roadmap-slices.ts +0 -149
  552. package/dist/resources/extensions/gsd/routing-history.ts +0 -286
  553. package/dist/resources/extensions/gsd/safe-fs.ts +0 -47
  554. package/dist/resources/extensions/gsd/semantic-chunker.ts +0 -336
  555. package/dist/resources/extensions/gsd/session-forensics.ts +0 -537
  556. package/dist/resources/extensions/gsd/session-lock.ts +0 -426
  557. package/dist/resources/extensions/gsd/session-status-io.ts +0 -179
  558. package/dist/resources/extensions/gsd/skill-discovery.ts +0 -139
  559. package/dist/resources/extensions/gsd/skill-health.ts +0 -417
  560. package/dist/resources/extensions/gsd/state.ts +0 -727
  561. package/dist/resources/extensions/gsd/structured-data-formatter.ts +0 -144
  562. package/dist/resources/extensions/gsd/summary-distiller.ts +0 -258
  563. package/dist/resources/extensions/gsd/tests/activity-log.test.ts +0 -213
  564. package/dist/resources/extensions/gsd/tests/agent-end-retry.test.ts +0 -107
  565. package/dist/resources/extensions/gsd/tests/all-milestones-complete-merge.test.ts +0 -200
  566. package/dist/resources/extensions/gsd/tests/auto-budget-alerts.test.ts +0 -50
  567. package/dist/resources/extensions/gsd/tests/auto-dashboard.test.ts +0 -166
  568. package/dist/resources/extensions/gsd/tests/auto-dispatch-loop.test.ts +0 -691
  569. package/dist/resources/extensions/gsd/tests/auto-lock-creation.test.ts +0 -186
  570. package/dist/resources/extensions/gsd/tests/auto-preflight.test.ts +0 -40
  571. package/dist/resources/extensions/gsd/tests/auto-recovery.test.ts +0 -640
  572. package/dist/resources/extensions/gsd/tests/auto-reentrancy-guard.test.ts +0 -127
  573. package/dist/resources/extensions/gsd/tests/auto-secrets-gate.test.ts +0 -302
  574. package/dist/resources/extensions/gsd/tests/auto-session-encapsulation.test.ts +0 -257
  575. package/dist/resources/extensions/gsd/tests/auto-skip-loop.test.ts +0 -123
  576. package/dist/resources/extensions/gsd/tests/auto-worktree-milestone-merge.test.ts +0 -340
  577. package/dist/resources/extensions/gsd/tests/auto-worktree.test.ts +0 -167
  578. package/dist/resources/extensions/gsd/tests/budget-prediction.test.ts +0 -220
  579. package/dist/resources/extensions/gsd/tests/cache-staleness-regression.test.ts +0 -317
  580. package/dist/resources/extensions/gsd/tests/captures.test.ts +0 -438
  581. package/dist/resources/extensions/gsd/tests/claude-import-tui.test.ts +0 -351
  582. package/dist/resources/extensions/gsd/tests/collect-from-manifest.test.ts +0 -469
  583. package/dist/resources/extensions/gsd/tests/collision-diagnostics.test.ts +0 -705
  584. package/dist/resources/extensions/gsd/tests/commands-logs.test.ts +0 -241
  585. package/dist/resources/extensions/gsd/tests/complete-milestone.test.ts +0 -209
  586. package/dist/resources/extensions/gsd/tests/complexity-classifier.test.ts +0 -181
  587. package/dist/resources/extensions/gsd/tests/context-budget.test.ts +0 -352
  588. package/dist/resources/extensions/gsd/tests/context-compression.test.ts +0 -193
  589. package/dist/resources/extensions/gsd/tests/context-store.test.ts +0 -462
  590. package/dist/resources/extensions/gsd/tests/continue-here.test.ts +0 -285
  591. package/dist/resources/extensions/gsd/tests/cost-projection.test.ts +0 -134
  592. package/dist/resources/extensions/gsd/tests/crash-recovery.test.ts +0 -134
  593. package/dist/resources/extensions/gsd/tests/dashboard-budget.test.ts +0 -346
  594. package/dist/resources/extensions/gsd/tests/db-writer.test.ts +0 -602
  595. package/dist/resources/extensions/gsd/tests/debug-logger.test.ts +0 -185
  596. package/dist/resources/extensions/gsd/tests/derive-state-db.test.ts +0 -405
  597. package/dist/resources/extensions/gsd/tests/derive-state-deps.test.ts +0 -421
  598. package/dist/resources/extensions/gsd/tests/derive-state-draft.test.ts +0 -308
  599. package/dist/resources/extensions/gsd/tests/derive-state.test.ts +0 -788
  600. package/dist/resources/extensions/gsd/tests/detection.test.ts +0 -398
  601. package/dist/resources/extensions/gsd/tests/diff-context.test.ts +0 -136
  602. package/dist/resources/extensions/gsd/tests/discuss-prompt.test.ts +0 -15
  603. package/dist/resources/extensions/gsd/tests/dispatch-guard.test.ts +0 -128
  604. package/dist/resources/extensions/gsd/tests/dispatch-missing-task-plans.test.ts +0 -132
  605. package/dist/resources/extensions/gsd/tests/dispatch-stall-guard.test.ts +0 -126
  606. package/dist/resources/extensions/gsd/tests/doctor-environment.test.ts +0 -314
  607. package/dist/resources/extensions/gsd/tests/doctor-fixlevel.test.ts +0 -245
  608. package/dist/resources/extensions/gsd/tests/doctor-git.test.ts +0 -344
  609. package/dist/resources/extensions/gsd/tests/doctor-proactive.test.ts +0 -278
  610. package/dist/resources/extensions/gsd/tests/doctor-providers.test.ts +0 -298
  611. package/dist/resources/extensions/gsd/tests/doctor-runtime.test.ts +0 -302
  612. package/dist/resources/extensions/gsd/tests/doctor.test.ts +0 -652
  613. package/dist/resources/extensions/gsd/tests/draft-promotion.test.ts +0 -169
  614. package/dist/resources/extensions/gsd/tests/exit-command.test.ts +0 -50
  615. package/dist/resources/extensions/gsd/tests/export-html-all.test.ts +0 -105
  616. package/dist/resources/extensions/gsd/tests/export-html-enhancements.test.ts +0 -378
  617. package/dist/resources/extensions/gsd/tests/extension-selector-separator.test.ts +0 -144
  618. package/dist/resources/extensions/gsd/tests/feature-branch-lifecycle-integration.test.ts +0 -424
  619. package/dist/resources/extensions/gsd/tests/git-self-heal.test.ts +0 -131
  620. package/dist/resources/extensions/gsd/tests/git-service.test.ts +0 -1172
  621. package/dist/resources/extensions/gsd/tests/gsd-db.test.ts +0 -353
  622. package/dist/resources/extensions/gsd/tests/gsd-inspect.test.ts +0 -125
  623. package/dist/resources/extensions/gsd/tests/gsd-tools.test.ts +0 -326
  624. package/dist/resources/extensions/gsd/tests/headless-answers.test.ts +0 -340
  625. package/dist/resources/extensions/gsd/tests/headless-query.test.ts +0 -162
  626. package/dist/resources/extensions/gsd/tests/idle-recovery.test.ts +0 -485
  627. package/dist/resources/extensions/gsd/tests/in-flight-tool-tracking.test.ts +0 -32
  628. package/dist/resources/extensions/gsd/tests/init-wizard.test.ts +0 -197
  629. package/dist/resources/extensions/gsd/tests/integration/headless-command.ts +0 -534
  630. package/dist/resources/extensions/gsd/tests/integration-edge.test.ts +0 -228
  631. package/dist/resources/extensions/gsd/tests/integration-lifecycle.test.ts +0 -277
  632. package/dist/resources/extensions/gsd/tests/integration-mixed-milestones.test.ts +0 -523
  633. package/dist/resources/extensions/gsd/tests/key-manager.test.ts +0 -414
  634. package/dist/resources/extensions/gsd/tests/knowledge.test.ts +0 -161
  635. package/dist/resources/extensions/gsd/tests/loop-regression.test.ts +0 -877
  636. package/dist/resources/extensions/gsd/tests/manifest-status.test.ts +0 -283
  637. package/dist/resources/extensions/gsd/tests/marketplace-test-fixtures.ts +0 -91
  638. package/dist/resources/extensions/gsd/tests/md-importer.test.ts +0 -410
  639. package/dist/resources/extensions/gsd/tests/mechanical-completion.test.ts +0 -356
  640. package/dist/resources/extensions/gsd/tests/memory-extractor.test.ts +0 -180
  641. package/dist/resources/extensions/gsd/tests/memory-leak-guards.test.ts +0 -91
  642. package/dist/resources/extensions/gsd/tests/memory-store.test.ts +0 -345
  643. package/dist/resources/extensions/gsd/tests/metrics.test.ts +0 -253
  644. package/dist/resources/extensions/gsd/tests/migrate-command.test.ts +0 -369
  645. package/dist/resources/extensions/gsd/tests/migrate-parser.test.ts +0 -757
  646. package/dist/resources/extensions/gsd/tests/migrate-transformer.test.ts +0 -635
  647. package/dist/resources/extensions/gsd/tests/migrate-validator-parsers.test.ts +0 -414
  648. package/dist/resources/extensions/gsd/tests/migrate-writer-integration.test.ts +0 -303
  649. package/dist/resources/extensions/gsd/tests/migrate-writer.test.ts +0 -398
  650. package/dist/resources/extensions/gsd/tests/milestone-transition-worktree.test.ts +0 -147
  651. package/dist/resources/extensions/gsd/tests/model-cost-table.test.ts +0 -69
  652. package/dist/resources/extensions/gsd/tests/model-isolation.test.ts +0 -157
  653. package/dist/resources/extensions/gsd/tests/model-router.test.ts +0 -167
  654. package/dist/resources/extensions/gsd/tests/must-have-parser.test.ts +0 -291
  655. package/dist/resources/extensions/gsd/tests/namespaced-registry.test.ts +0 -1027
  656. package/dist/resources/extensions/gsd/tests/namespaced-resolver.test.ts +0 -671
  657. package/dist/resources/extensions/gsd/tests/native-has-changes-cache.test.ts +0 -61
  658. package/dist/resources/extensions/gsd/tests/next-milestone-id.test.ts +0 -23
  659. package/dist/resources/extensions/gsd/tests/none-mode-gates.test.ts +0 -114
  660. package/dist/resources/extensions/gsd/tests/notifications.test.ts +0 -67
  661. package/dist/resources/extensions/gsd/tests/overrides.test.ts +0 -131
  662. package/dist/resources/extensions/gsd/tests/parallel-budget-atomicity.test.ts +0 -331
  663. package/dist/resources/extensions/gsd/tests/parallel-crash-recovery.test.ts +0 -298
  664. package/dist/resources/extensions/gsd/tests/parallel-merge.test.ts +0 -468
  665. package/dist/resources/extensions/gsd/tests/parallel-orchestration.test.ts +0 -685
  666. package/dist/resources/extensions/gsd/tests/parallel-worker-monitoring.test.ts +0 -171
  667. package/dist/resources/extensions/gsd/tests/parallel-workers-multi-milestone-e2e.test.ts +0 -354
  668. package/dist/resources/extensions/gsd/tests/park-edge-cases.test.ts +0 -276
  669. package/dist/resources/extensions/gsd/tests/park-milestone.test.ts +0 -401
  670. package/dist/resources/extensions/gsd/tests/parsers.test.ts +0 -1704
  671. package/dist/resources/extensions/gsd/tests/plan-milestone.test.ts +0 -133
  672. package/dist/resources/extensions/gsd/tests/plan-quality-validator.test.ts +0 -363
  673. package/dist/resources/extensions/gsd/tests/plan-slice-prompt.test.ts +0 -42
  674. package/dist/resources/extensions/gsd/tests/plugin-importer-live.test.ts +0 -481
  675. package/dist/resources/extensions/gsd/tests/plugin-importer.test.ts +0 -1383
  676. package/dist/resources/extensions/gsd/tests/post-unit-hooks.test.ts +0 -337
  677. package/dist/resources/extensions/gsd/tests/preferences.test.ts +0 -276
  678. package/dist/resources/extensions/gsd/tests/progress-score.test.ts +0 -206
  679. package/dist/resources/extensions/gsd/tests/prompt-budget-enforcement.test.ts +0 -464
  680. package/dist/resources/extensions/gsd/tests/prompt-cache-optimizer.test.ts +0 -314
  681. package/dist/resources/extensions/gsd/tests/prompt-compressor.test.ts +0 -529
  682. package/dist/resources/extensions/gsd/tests/prompt-db.test.ts +0 -385
  683. package/dist/resources/extensions/gsd/tests/prompt-ordering.test.ts +0 -296
  684. package/dist/resources/extensions/gsd/tests/provider-errors.test.ts +0 -338
  685. package/dist/resources/extensions/gsd/tests/queue-draft-detection.test.ts +0 -126
  686. package/dist/resources/extensions/gsd/tests/queue-order.test.ts +0 -204
  687. package/dist/resources/extensions/gsd/tests/queue-reorder-e2e.test.ts +0 -282
  688. package/dist/resources/extensions/gsd/tests/reassess-detection.test.ts +0 -154
  689. package/dist/resources/extensions/gsd/tests/reassess-prompt.test.ts +0 -145
  690. package/dist/resources/extensions/gsd/tests/regex-hardening.test.ts +0 -281
  691. package/dist/resources/extensions/gsd/tests/remote-questions.test.ts +0 -642
  692. package/dist/resources/extensions/gsd/tests/remote-status.test.ts +0 -99
  693. package/dist/resources/extensions/gsd/tests/replan-slice.test.ts +0 -538
  694. package/dist/resources/extensions/gsd/tests/requirements.test.ts +0 -106
  695. package/dist/resources/extensions/gsd/tests/roadmap-parse-regression.test.ts +0 -358
  696. package/dist/resources/extensions/gsd/tests/roadmap-slices.test.ts +0 -66
  697. package/dist/resources/extensions/gsd/tests/routing-history.test.ts +0 -240
  698. package/dist/resources/extensions/gsd/tests/run-uat.test.ts +0 -416
  699. package/dist/resources/extensions/gsd/tests/secure-env-collect.test.ts +0 -185
  700. package/dist/resources/extensions/gsd/tests/semantic-chunker.test.ts +0 -426
  701. package/dist/resources/extensions/gsd/tests/session-lock-regression.test.ts +0 -216
  702. package/dist/resources/extensions/gsd/tests/session-lock.test.ts +0 -434
  703. package/dist/resources/extensions/gsd/tests/skill-lifecycle.test.ts +0 -126
  704. package/dist/resources/extensions/gsd/tests/smart-entry-draft.test.ts +0 -123
  705. package/dist/resources/extensions/gsd/tests/stale-worktree-cwd.test.ts +0 -142
  706. package/dist/resources/extensions/gsd/tests/stop-auto-remote.test.ts +0 -156
  707. package/dist/resources/extensions/gsd/tests/structured-data-formatter.test.ts +0 -365
  708. package/dist/resources/extensions/gsd/tests/summary-distiller.test.ts +0 -323
  709. package/dist/resources/extensions/gsd/tests/test-helpers.ts +0 -61
  710. package/dist/resources/extensions/gsd/tests/token-counter.test.ts +0 -129
  711. package/dist/resources/extensions/gsd/tests/token-optimization-benchmark.test.ts +0 -1272
  712. package/dist/resources/extensions/gsd/tests/token-optimization-prefs.test.ts +0 -164
  713. package/dist/resources/extensions/gsd/tests/token-profile.test.ts +0 -268
  714. package/dist/resources/extensions/gsd/tests/token-savings.test.ts +0 -366
  715. package/dist/resources/extensions/gsd/tests/triage-dispatch.test.ts +0 -340
  716. package/dist/resources/extensions/gsd/tests/triage-resolution.test.ts +0 -416
  717. package/dist/resources/extensions/gsd/tests/undo.test.ts +0 -136
  718. package/dist/resources/extensions/gsd/tests/unique-milestone-ids.test.ts +0 -219
  719. package/dist/resources/extensions/gsd/tests/unit-runtime.test.ts +0 -258
  720. package/dist/resources/extensions/gsd/tests/update-command.test.ts +0 -67
  721. package/dist/resources/extensions/gsd/tests/validate-directory.test.ts +0 -222
  722. package/dist/resources/extensions/gsd/tests/validate-milestone.test.ts +0 -375
  723. package/dist/resources/extensions/gsd/tests/verification-evidence.test.ts +0 -745
  724. package/dist/resources/extensions/gsd/tests/verification-gate.test.ts +0 -1208
  725. package/dist/resources/extensions/gsd/tests/visualizer-critical-path.test.ts +0 -145
  726. package/dist/resources/extensions/gsd/tests/visualizer-data.test.ts +0 -446
  727. package/dist/resources/extensions/gsd/tests/visualizer-overlay.test.ts +0 -237
  728. package/dist/resources/extensions/gsd/tests/visualizer-views.test.ts +0 -718
  729. package/dist/resources/extensions/gsd/tests/worker-registry.test.ts +0 -148
  730. package/dist/resources/extensions/gsd/tests/workflow-templates.test.ts +0 -173
  731. package/dist/resources/extensions/gsd/tests/workspace-index.test.ts +0 -38
  732. package/dist/resources/extensions/gsd/tests/worktree-bugfix.test.ts +0 -120
  733. package/dist/resources/extensions/gsd/tests/worktree-e2e.test.ts +0 -244
  734. package/dist/resources/extensions/gsd/tests/worktree-integration.test.ts +0 -207
  735. package/dist/resources/extensions/gsd/tests/worktree-manager.test.ts +0 -141
  736. package/dist/resources/extensions/gsd/tests/worktree-post-create-hook.test.ts +0 -165
  737. package/dist/resources/extensions/gsd/tests/worktree-sync-milestones.test.ts +0 -206
  738. package/dist/resources/extensions/gsd/tests/worktree.test.ts +0 -171
  739. package/dist/resources/extensions/gsd/tests/write-gate.test.ts +0 -211
  740. package/dist/resources/extensions/gsd/token-counter.ts +0 -65
  741. package/dist/resources/extensions/gsd/triage-resolution.ts +0 -284
  742. package/dist/resources/extensions/gsd/triage-ui.ts +0 -175
  743. package/dist/resources/extensions/gsd/types.ts +0 -425
  744. package/dist/resources/extensions/gsd/undo.ts +0 -223
  745. package/dist/resources/extensions/gsd/unit-id.ts +0 -14
  746. package/dist/resources/extensions/gsd/unit-runtime.ts +0 -192
  747. package/dist/resources/extensions/gsd/validate-directory.ts +0 -164
  748. package/dist/resources/extensions/gsd/verification-evidence.ts +0 -188
  749. package/dist/resources/extensions/gsd/verification-gate.ts +0 -643
  750. package/dist/resources/extensions/gsd/visualizer-data.ts +0 -866
  751. package/dist/resources/extensions/gsd/visualizer-overlay.ts +0 -566
  752. package/dist/resources/extensions/gsd/visualizer-views.ts +0 -1171
  753. package/dist/resources/extensions/gsd/workflow-templates.ts +0 -241
  754. package/dist/resources/extensions/gsd/workspace-index.ts +0 -217
  755. package/dist/resources/extensions/gsd/worktree-command.ts +0 -807
  756. package/dist/resources/extensions/gsd/worktree-manager.ts +0 -449
  757. package/dist/resources/extensions/gsd/worktree.ts +0 -257
  758. package/dist/resources/extensions/mac-tools/index.ts +0 -852
  759. package/dist/resources/extensions/mcp-client/index.ts +0 -459
  760. package/dist/resources/extensions/remote-questions/config.ts +0 -83
  761. package/dist/resources/extensions/remote-questions/discord-adapter.ts +0 -148
  762. package/dist/resources/extensions/remote-questions/format.ts +0 -315
  763. package/dist/resources/extensions/remote-questions/http-client.ts +0 -76
  764. package/dist/resources/extensions/remote-questions/manager.ts +0 -184
  765. package/dist/resources/extensions/remote-questions/notify.ts +0 -90
  766. package/dist/resources/extensions/remote-questions/remote-command.ts +0 -457
  767. package/dist/resources/extensions/remote-questions/slack-adapter.ts +0 -141
  768. package/dist/resources/extensions/remote-questions/status.ts +0 -31
  769. package/dist/resources/extensions/remote-questions/store.ts +0 -81
  770. package/dist/resources/extensions/remote-questions/telegram-adapter.ts +0 -149
  771. package/dist/resources/extensions/remote-questions/types.ts +0 -102
  772. package/dist/resources/extensions/search-the-web/cache.ts +0 -78
  773. package/dist/resources/extensions/search-the-web/command-search-provider.ts +0 -101
  774. package/dist/resources/extensions/search-the-web/format.ts +0 -258
  775. package/dist/resources/extensions/search-the-web/http.ts +0 -238
  776. package/dist/resources/extensions/search-the-web/index.ts +0 -65
  777. package/dist/resources/extensions/search-the-web/native-search.ts +0 -193
  778. package/dist/resources/extensions/search-the-web/provider.ts +0 -148
  779. package/dist/resources/extensions/search-the-web/tavily.ts +0 -116
  780. package/dist/resources/extensions/search-the-web/tool-fetch-page.ts +0 -589
  781. package/dist/resources/extensions/search-the-web/tool-llm-context.ts +0 -608
  782. package/dist/resources/extensions/search-the-web/tool-search.ts +0 -649
  783. package/dist/resources/extensions/search-the-web/url-utils.ts +0 -125
  784. package/dist/resources/extensions/shared/confirm-ui.ts +0 -126
  785. package/dist/resources/extensions/shared/frontmatter.ts +0 -117
  786. package/dist/resources/extensions/shared/interview-ui.ts +0 -613
  787. package/dist/resources/extensions/shared/next-action-ui.ts +0 -212
  788. package/dist/resources/extensions/shared/sanitize.ts +0 -19
  789. package/dist/resources/extensions/shared/terminal.ts +0 -23
  790. package/dist/resources/extensions/shared/tests/format-utils.test.ts +0 -153
  791. package/dist/resources/extensions/shared/ui.ts +0 -400
  792. package/dist/resources/extensions/shared/wizard-ui.ts +0 -551
  793. package/dist/resources/extensions/slash-commands/audit.ts +0 -88
  794. package/dist/resources/extensions/slash-commands/clear.ts +0 -10
  795. package/dist/resources/extensions/slash-commands/create-extension.ts +0 -297
  796. package/dist/resources/extensions/slash-commands/create-slash-command.ts +0 -234
  797. package/dist/resources/extensions/slash-commands/index.ts +0 -12
  798. package/dist/resources/extensions/subagent/agents.ts +0 -126
  799. package/dist/resources/extensions/subagent/index.ts +0 -1121
  800. package/dist/resources/extensions/subagent/isolation.ts +0 -501
  801. package/dist/resources/extensions/subagent/worker-registry.ts +0 -99
  802. package/dist/resources/extensions/ttsr/index.ts +0 -168
  803. package/dist/resources/extensions/ttsr/rule-loader.ts +0 -74
  804. package/dist/resources/extensions/ttsr/ttsr-manager.ts +0 -456
  805. package/dist/resources/extensions/universal-config/discovery.ts +0 -104
  806. package/dist/resources/extensions/universal-config/format.ts +0 -191
  807. package/dist/resources/extensions/universal-config/index.ts +0 -120
  808. package/dist/resources/extensions/universal-config/scanners.ts +0 -642
  809. package/dist/resources/extensions/universal-config/tests/discovery.test.ts +0 -119
  810. package/dist/resources/extensions/universal-config/tests/format.test.ts +0 -127
  811. package/dist/resources/extensions/universal-config/tests/scanners.test.ts +0 -456
  812. package/dist/resources/extensions/universal-config/tools.ts +0 -60
  813. package/dist/resources/extensions/universal-config/types.ts +0 -135
  814. package/dist/resources/extensions/voice/index.ts +0 -272
  815. package/dist/resources/skills/create-gsd-extension/templates/extension-skeleton.ts +0 -51
  816. package/dist/resources/skills/create-gsd-extension/templates/stateful-tool-skeleton.ts +0 -143
  817. package/src/resources/extensions/gsd/auto-constants.ts +0 -6
  818. package/src/resources/extensions/gsd/auto-idempotency.ts +0 -151
  819. package/src/resources/extensions/gsd/auto-stuck-detection.ts +0 -221
  820. package/src/resources/extensions/gsd/mechanical-completion.ts +0 -430
  821. package/src/resources/extensions/gsd/tests/auto-dispatch-loop.test.ts +0 -691
  822. package/src/resources/extensions/gsd/tests/auto-reentrancy-guard.test.ts +0 -127
  823. package/src/resources/extensions/gsd/tests/auto-skip-loop.test.ts +0 -123
  824. package/src/resources/extensions/gsd/tests/dispatch-stall-guard.test.ts +0 -126
  825. package/src/resources/extensions/gsd/tests/loop-regression.test.ts +0 -877
  826. package/src/resources/extensions/gsd/tests/mechanical-completion.test.ts +0 -356
  827. package/src/resources/extensions/gsd/tests/progress-score.test.ts +0 -206
  828. package/src/resources/extensions/gsd/tests/session-lock.test.ts +0 -434
@@ -18,20 +18,33 @@ import type {
18
18
 
19
19
  import { deriveState } from "./state.js";
20
20
  import type { GSDState } from "./types.js";
21
- import { loadFile, getManifestStatus, resolveAllOverrides, parsePlan, parseSummary } from "./files.js";
22
- import { loadPrompt } from "./prompt-loader.js";
23
- import { runVerificationGate, formatFailureContext, captureRuntimeErrors, runDependencyAudit } from "./verification-gate.js";
24
- import { writeVerificationJSON } from "./verification-evidence.js";
21
+ import { getManifestStatus } from "./files.js";
22
+ export { inlinePriorMilestoneSummary } from "./files.js";
25
23
  import { collectSecretsFromManifest } from "../get-secrets-from-user.js";
26
24
  import {
27
- gsdRoot, resolveMilestoneFile, resolveSliceFile, resolveSlicePath,
28
- resolveMilestonePath, resolveDir, resolveTasksDir, resolveTaskFile,
29
- milestonesDir, buildTaskFileName,
25
+ gsdRoot,
26
+ resolveMilestoneFile,
27
+ resolveSliceFile,
28
+ resolveSlicePath,
29
+ resolveMilestonePath,
30
+ resolveDir,
31
+ resolveTasksDir,
32
+ resolveTaskFile,
33
+ milestonesDir,
34
+ buildTaskFileName,
30
35
  } from "./paths.js";
31
36
  import { invalidateAllCaches } from "./cache.js";
32
- import { saveActivityLog, clearActivityLogState } from "./activity-log.js";
33
- import { synthesizeCrashRecovery, getDeepDiagnostic } from "./session-forensics.js";
34
- import { writeLock, clearLock, readCrashLock, formatCrashInfo, isLockProcessAlive } from "./crash-recovery.js";
37
+ import { clearActivityLogState } from "./activity-log.js";
38
+ import {
39
+ synthesizeCrashRecovery,
40
+ getDeepDiagnostic,
41
+ } from "./session-forensics.js";
42
+ import {
43
+ writeLock,
44
+ clearLock,
45
+ readCrashLock,
46
+ isLockProcessAlive,
47
+ } from "./crash-recovery.js";
35
48
  import {
36
49
  acquireSessionLock,
37
50
  validateSessionLock,
@@ -44,7 +57,11 @@ import {
44
57
  readUnitRuntimeRecord,
45
58
  writeUnitRuntimeRecord,
46
59
  } from "./unit-runtime.js";
47
- import { resolveAutoSupervisorConfig, loadEffectiveGSDPreferences, resolveSkillDiscoveryMode, getIsolationMode } from "./preferences.js";
60
+ import {
61
+ resolveAutoSupervisorConfig,
62
+ loadEffectiveGSDPreferences,
63
+ getIsolationMode,
64
+ } from "./preferences.js";
48
65
  import { sendDesktopNotification } from "./notifications.js";
49
66
  import type { GSDPreferences } from "./preferences.js";
50
67
  import {
@@ -69,11 +86,13 @@ import { closeoutUnit } from "./auto-unit-closeout.js";
69
86
  import { recoverTimedOutUnit } from "./auto-timeout-recovery.js";
70
87
  import { selectAndApplyModel } from "./auto-model-selection.js";
71
88
  import {
89
+ syncProjectRootToWorktree,
90
+ syncStateToProjectRoot,
72
91
  readResourceVersion,
73
92
  checkResourcesStale,
74
93
  escapeStaleWorktree,
75
- } from "./resource-version.js";
76
- import { initRoutingHistory, resetRoutingHistory, recordOutcome } from "./routing-history.js";
94
+ } from "./auto-worktree-sync.js";
95
+ import { resetRoutingHistory, recordOutcome } from "./routing-history.js";
77
96
  import {
78
97
  checkPostUnitHooks,
79
98
  getActiveHook,
@@ -85,8 +104,7 @@ import {
85
104
  restoreHookState,
86
105
  clearPersistedHookState,
87
106
  } from "./post-unit-hooks.js";
88
- import { ensureGitignore, untrackRuntimeFiles } from "./gitignore.js";
89
- import { runGSDDoctor, rebuildState, summarizeDoctorIssues } from "./doctor.js";
107
+ import { runGSDDoctor, rebuildState } from "./doctor.js";
90
108
  import {
91
109
  preDispatchHealthGate,
92
110
  recordHealthSnapshot,
@@ -95,20 +113,22 @@ import {
95
113
  formatHealthSummary,
96
114
  getConsecutiveErrorUnits,
97
115
  } from "./doctor-proactive.js";
98
- import { snapshotSkills, clearSkillSnapshot } from "./skill-discovery.js";
99
- import { captureAvailableSkills, getAndClearSkills, resetSkillTelemetry } from "./skill-telemetry.js";
116
+ import { clearSkillSnapshot } from "./skill-discovery.js";
117
+ import {
118
+ captureAvailableSkills,
119
+ resetSkillTelemetry,
120
+ } from "./skill-telemetry.js";
100
121
  import {
101
- initMetrics, resetMetrics, getLedger,
102
- getProjectTotals, formatCost, formatTokenCount,
122
+ initMetrics,
123
+ resetMetrics,
124
+ getLedger,
125
+ getProjectTotals,
126
+ formatCost,
127
+ formatTokenCount,
103
128
  } from "./metrics.js";
104
- import { computeBudgets, resolveExecutorContextWindow } from "./context-budget.js";
105
- import { GSDError, GSD_ARTIFACT_MISSING } from "./errors.js";
106
129
  import { join } from "node:path";
107
- import { sep as pathSep } from "node:path";
108
- import { parseUnitId } from "./unit-id.js";
109
- import { readdirSync, readFileSync, existsSync, mkdirSync, writeFileSync, unlinkSync, statSync } from "node:fs";
130
+ import { readFileSync, existsSync, mkdirSync } from "node:fs";
110
131
  import { atomicWriteSync } from "./atomic-write.js";
111
- import { nativeIsRepo, nativeInit, nativeAddAll, nativeCommit } from "./native-git-bridge.js";
112
132
  import {
113
133
  autoCommitCurrentBranch,
114
134
  captureIntegrationBranch,
@@ -119,9 +139,8 @@ import {
119
139
  parseSliceBranch,
120
140
  setActiveMilestoneId,
121
141
  } from "./worktree.js";
122
- import { createGitService, type TaskCommitContext } from "./git-service.js";
142
+ import { GitServiceImpl } from "./git-service.js";
123
143
  import { getPriorSliceCompletionBlocker } from "./dispatch-guard.js";
124
- import { formatGitError } from "./git-self-heal.js";
125
144
  import {
126
145
  createAutoWorktree,
127
146
  enterAutoWorktree,
@@ -131,26 +150,21 @@ import {
131
150
  getAutoWorktreeOriginalBase,
132
151
  mergeMilestoneToMain,
133
152
  autoWorktreeBranch,
153
+ syncWorktreeStateBack,
134
154
  } from "./auto-worktree.js";
135
155
  import { pruneQueueOrder } from "./queue-order.js";
136
- import { consumeSignal } from "./session-status-io.js";
137
- import { showNextAction } from "../shared/mod.js";
138
- import { debugLog, debugTime, debugCount, debugPeak, enableDebug, isDebugEnabled, writeDebugSummary, getDebugLogPath } from "./debug-logger.js";
156
+
157
+ import { debugLog, isDebugEnabled, writeDebugSummary } from "./debug-logger.js";
139
158
  import {
140
159
  resolveExpectedArtifactPath,
141
160
  verifyExpectedArtifact,
142
161
  writeBlockerPlaceholder,
143
162
  diagnoseExpectedArtifact,
144
163
  skipExecuteTask,
145
- completedKeysPath,
146
- persistCompletedKey,
147
- removePersistedKey,
148
- loadPersistedKeys,
149
- selfHealRuntimeRecords,
150
164
  buildLoopRemediationSteps,
151
165
  reconcileMergeState,
152
166
  } from "./auto-recovery.js";
153
- import { resolveDispatch, resetRewriteCircuitBreaker } from "./auto-dispatch.js";
167
+ import { resolveDispatch } from "./auto-dispatch.js";
154
168
  import {
155
169
  type AutoDashboardData,
156
170
  updateProgressWidget as _updateProgressWidget,
@@ -169,28 +183,52 @@ import {
169
183
  detectWorkingTreeActivity,
170
184
  } from "./auto-supervisor.js";
171
185
  import { isDbAvailable } from "./gsd-db.js";
172
- import { hasPendingCaptures, loadPendingCaptures, countPendingCaptures } from "./captures.js";
186
+ import { countPendingCaptures } from "./captures.js";
173
187
 
174
188
  // ── Extracted modules ──────────────────────────────────────────────────────
175
- import { startUnitSupervision, type SupervisionContext } from "./auto-timers.js";
176
- import { checkIdempotency, type IdempotencyContext } from "./auto-idempotency.js";
177
- import { checkStuckAndRecover, type StuckContext } from "./auto-stuck-detection.js";
178
- import { runPostUnitVerification, type VerificationContext } from "./auto-verification.js";
179
- import { postUnitPreVerification, postUnitPostVerification, type PostUnitContext } from "./auto-post-unit.js";
189
+ import { startUnitSupervision } from "./auto-timers.js";
190
+ import { runPostUnitVerification } from "./auto-verification.js";
191
+ import {
192
+ postUnitPreVerification,
193
+ postUnitPostVerification,
194
+ } from "./auto-post-unit.js";
180
195
  import { bootstrapAutoSession, type BootstrapDeps } from "./auto-start.js";
196
+ import { autoLoop, resolveAgentEnd, type LoopDeps } from "./auto-loop.js";
197
+ import {
198
+ WorktreeResolver,
199
+ type WorktreeResolverDeps,
200
+ } from "./worktree-resolver.js";
201
+ import { reorderForCaching } from "./prompt-ordering.js";
181
202
 
182
- // Resource staleness, stale worktree escape → resource-version.ts
203
+ // Worktree sync, resource staleness, stale worktree escape → auto-worktree-sync.ts
183
204
 
184
205
  // ─── Session State ─────────────────────────────────────────────────────────
185
206
 
186
207
  import {
187
208
  AutoSession,
188
- MAX_UNIT_DISPATCHES, STUB_RECOVERY_THRESHOLD, MAX_LIFETIME_DISPATCHES,
189
- MAX_CONSECUTIVE_SKIPS, DISPATCH_GAP_TIMEOUT_MS, MAX_SKIP_DEPTH,
190
- NEW_SESSION_TIMEOUT_MS, DISPATCH_HANG_TIMEOUT_MS,
209
+ MAX_UNIT_DISPATCHES,
210
+ STUB_RECOVERY_THRESHOLD,
211
+ MAX_LIFETIME_DISPATCHES,
212
+ NEW_SESSION_TIMEOUT_MS,
213
+ } from "./auto/session.js";
214
+ import type {
215
+ CompletedUnit,
216
+ CurrentUnit,
217
+ UnitRouting,
218
+ StartModel,
219
+ } from "./auto/session.js";
220
+ export {
221
+ MAX_UNIT_DISPATCHES,
222
+ STUB_RECOVERY_THRESHOLD,
223
+ MAX_LIFETIME_DISPATCHES,
224
+ NEW_SESSION_TIMEOUT_MS,
225
+ } from "./auto/session.js";
226
+ export type {
227
+ CompletedUnit,
228
+ CurrentUnit,
229
+ UnitRouting,
230
+ StartModel,
191
231
  } from "./auto/session.js";
192
- import type { CompletedUnit, CurrentUnit, UnitRouting, StartModel, PendingVerificationRetry } from "./auto/session.js";
193
- import { getErrorMessage } from "./error-utils.js";
194
232
 
195
233
  // ── ENCAPSULATION INVARIANT ─────────────────────────────────────────────────
196
234
  // ALL mutable auto-mode state lives in the AutoSession class (auto/session.ts).
@@ -206,7 +244,8 @@ import { getErrorMessage } from "./error-utils.js";
206
244
  // ─────────────────────────────────────────────────────────────────────────────
207
245
  const s = new AutoSession();
208
246
 
209
- import { STATE_REBUILD_MIN_INTERVAL_MS } from "./auto-constants.js";
247
+ /** Throttle STATE.md rebuilds at most once per 30 seconds */
248
+ const STATE_REBUILD_MIN_INTERVAL_MS = 30_000;
210
249
 
211
250
  export function shouldUseWorktreeIsolation(): boolean {
212
251
  const prefs = loadEffectiveGSDPreferences()?.preferences?.git;
@@ -215,7 +254,52 @@ export function shouldUseWorktreeIsolation(): boolean {
215
254
  return true; // default: worktree
216
255
  }
217
256
 
218
- // All mutable state lives in AutoSession (auto/session.ts) see encapsulation invariant above.
257
+ /** Crash recovery prompt set by startAuto, consumed by the main loop */
258
+
259
+ /** Pending verification retry — set when gate fails with retries remaining, consumed by autoLoop */
260
+
261
+ /** Verification retry count per unitId — separate from s.unitDispatchCount which tracks artifact-missing retries */
262
+
263
+ /** Session file path captured at pause — used to synthesize recovery briefing on resume */
264
+
265
+ /** Dashboard tracking */
266
+
267
+ /** Track dynamic routing decision for the current unit (for metrics) */
268
+
269
+ /** Queue of quick-task captures awaiting dispatch after triage resolution */
270
+
271
+ /**
272
+ * Model captured at auto-mode start. Used to prevent model bleed between
273
+ * concurrent GSD instances sharing the same global settings.json (#650).
274
+ * When preferences don't specify a model for a unit type, this ensures
275
+ * the session's original model is re-applied instead of reading from
276
+ * the shared global settings (which another instance may have overwritten).
277
+ */
278
+
279
+ /** Track current milestone to detect transitions */
280
+
281
+ /** Model the user had selected before auto-mode started */
282
+
283
+ /** Progress-aware timeout supervision */
284
+
285
+ /** Context-pressure continue-here monitor — fires once when context usage >= 70% */
286
+
287
+ /** Prompt character measurement for token savings analysis (R051). */
288
+
289
+ /** SIGTERM handler registered while auto-mode is active — cleared on stop/pause. */
290
+
291
+ /**
292
+ * Tool calls currently being executed — prevents false idle detection during long-running tools.
293
+ * Maps toolCallId → start timestamp (ms) so the idle watchdog can detect tools that have been
294
+ * running suspiciously long (e.g., a Bash command hung because `&` kept stdout open).
295
+ */
296
+ // Re-export budget utilities for external consumers
297
+ export {
298
+ getBudgetAlertLevel,
299
+ getNewBudgetAlertLevel,
300
+ getBudgetEnforcementAction,
301
+ } from "./auto-budget.js";
302
+
219
303
  /** Wrapper: register SIGTERM handler and store reference. */
220
304
  function registerSigtermHandler(currentBasePath: string): void {
221
305
  s.sigtermHandler = _registerSigtermHandler(currentBasePath, s.sigtermHandler);
@@ -227,6 +311,8 @@ function deregisterSigtermHandler(): void {
227
311
  s.sigtermHandler = null;
228
312
  }
229
313
 
314
+ export { type AutoDashboardData } from "./auto-dashboard.js";
315
+
230
316
  export function getAutoDashboardData(): AutoDashboardData {
231
317
  const ledger = getLedger();
232
318
  const totals = ledger ? getProjectTotals(ledger.units) : null;
@@ -239,12 +325,15 @@ export function getAutoDashboardData(): AutoDashboardData {
239
325
  } catch {
240
326
  // Non-fatal — captures module may not be loaded
241
327
  }
242
- return { active: s.active, paused: s.paused,
328
+ return {
329
+ active: s.active,
330
+ paused: s.paused,
243
331
  stepMode: s.stepMode,
244
332
  startTime: s.autoStartTime,
245
- elapsed: (s.active || s.paused) ? Date.now() - s.autoStartTime : 0,
333
+ elapsed: s.active || s.paused ? Date.now() - s.autoStartTime : 0,
246
334
  currentUnit: s.currentUnit ? { ...s.currentUnit } : null,
247
- completedUnits: [...s.completedUnits], basePath: s.basePath,
335
+ completedUnits: [...s.completedUnits],
336
+ basePath: s.basePath,
248
337
  totalCost: totals?.cost ?? 0,
249
338
  totalTokens: totals?.tokens.total ?? 0,
250
339
  pendingCaptureCount,
@@ -266,7 +355,10 @@ export function isAutoPaused(): boolean {
266
355
  * Used by error-recovery to fall back to the session's own model
267
356
  * instead of reading (potentially stale) preferences from disk (#1065).
268
357
  */
269
- export function getAutoModeStartModel(): { provider: string; id: string } | null {
358
+ export function getAutoModeStartModel(): {
359
+ provider: string;
360
+ id: string;
361
+ } | null {
270
362
  return s.autoModeStartModel;
271
363
  }
272
364
 
@@ -287,9 +379,11 @@ export function getOldestInFlightToolAgeMs(): number {
287
379
  * Return the base path to use for the auto.lock file.
288
380
  * Always uses the original project root (not the worktree) so that
289
381
  * a second terminal can discover and stop a running auto-mode session.
382
+ *
383
+ * Delegates to AutoSession.lockBasePath — the single source of truth.
290
384
  */
291
385
  function lockBase(): string {
292
- return s.originalBasePath || s.basePath;
386
+ return s.lockBasePath;
293
387
  }
294
388
 
295
389
  /**
@@ -299,7 +393,11 @@ function lockBase(): string {
299
393
  *
300
394
  * Returns true if a remote session was found and signaled, false otherwise.
301
395
  */
302
- export function stopAutoRemote(projectRoot: string): { found: boolean; pid?: number; error?: string } {
396
+ export function stopAutoRemote(projectRoot: string): {
397
+ found: boolean;
398
+ pid?: number;
399
+ error?: string;
400
+ } {
303
401
  const lock = readCrashLock(projectRoot);
304
402
  if (!lock) return { found: false };
305
403
 
@@ -340,19 +438,20 @@ function clearUnitTimeout(): void {
340
438
  s.continueHereHandle = null;
341
439
  }
342
440
  clearInFlightTools();
343
- clearDispatchGapWatchdog();
344
- }
345
-
346
- function clearDispatchGapWatchdog(): void {
347
- if (s.dispatchGapHandle) {
348
- clearTimeout(s.dispatchGapHandle);
349
- s.dispatchGapHandle = null;
350
- }
351
441
  }
352
442
 
353
443
  /** Build snapshot metric opts, enriching with continueHereFired from the runtime record. */
354
- function buildSnapshotOpts(unitType: string, unitId: string): { continueHereFired?: boolean; promptCharCount?: number; baselineCharCount?: number } & Record<string, unknown> {
355
- const runtime = s.currentUnit ? readUnitRuntimeRecord(s.basePath, unitType, unitId) : null;
444
+ function buildSnapshotOpts(
445
+ unitType: string,
446
+ unitId: string,
447
+ ): {
448
+ continueHereFired?: boolean;
449
+ promptCharCount?: number;
450
+ baselineCharCount?: number;
451
+ } & Record<string, unknown> {
452
+ const runtime = s.currentUnit
453
+ ? readUnitRuntimeRecord(s.basePath, unitType, unitId)
454
+ : null;
356
455
  return {
357
456
  promptCharCount: s.lastPromptCharCount,
358
457
  baselineCharCount: s.lastBaselineCharCount,
@@ -361,144 +460,45 @@ function buildSnapshotOpts(unitType: string, unitId: string): { continueHereFire
361
460
  };
362
461
  }
363
462
 
364
- // ─── Extracted Merge Helper ───────────────────────────────────────────────
365
-
366
- /**
367
- * Attempt to merge the current milestone branch to main.
368
- * Handles both worktree and branch isolation modes with a single code path.
369
- * Returns true if merge succeeded, false on error (non-fatal, logged).
370
- *
371
- * Extracted from 4 duplicate merge blocks in dispatchNextUnit to eliminate
372
- * the bug factory where fixing one copy didn't fix the others (#1308).
373
- */
374
- function tryMergeMilestone(ctx: ExtensionContext, milestoneId: string, mode: "transition" | "complete"): boolean {
375
- const isolationMode = getIsolationMode();
376
-
377
- // Worktree merge path
378
- if (isInAutoWorktree(s.basePath) && s.originalBasePath) {
379
- try {
380
- const roadmapPath = resolveMilestoneFile(s.originalBasePath, milestoneId, "ROADMAP");
381
- if (!roadmapPath) {
382
- teardownAutoWorktree(s.originalBasePath, milestoneId);
383
- ctx.ui.notify(`Exited worktree for ${milestoneId} (no roadmap for merge).`, "info");
384
- return false;
385
- }
386
- const roadmapContent = readFileSync(roadmapPath, "utf-8");
387
- const mergeResult = mergeMilestoneToMain(s.originalBasePath, milestoneId, roadmapContent);
388
- s.basePath = s.originalBasePath;
389
- s.gitService = createGitService(s.basePath);
390
- ctx.ui.notify(
391
- `Milestone ${milestoneId} merged to main.${mergeResult.pushed ? " Pushed to remote." : ""}`,
392
- "info",
393
- );
394
- return true;
395
- } catch (err) {
396
- ctx.ui.notify(
397
- `Milestone merge failed: ${err instanceof Error ? err.message : String(err)}`,
398
- "warning",
399
- );
400
- if (s.originalBasePath) {
401
- s.basePath = s.originalBasePath;
402
- try { process.chdir(s.basePath); } catch { /* best-effort */ }
403
- }
404
- return false;
405
- }
406
- }
407
-
408
- // Branch-mode merge path
409
- if (isolationMode === "branch") {
410
- try {
411
- const currentBranch = getCurrentBranch(s.basePath);
412
- const milestoneBranch = autoWorktreeBranch(milestoneId);
413
- if (currentBranch === milestoneBranch) {
414
- const roadmapPath = resolveMilestoneFile(s.basePath, milestoneId, "ROADMAP");
415
- if (roadmapPath) {
416
- const roadmapContent = readFileSync(roadmapPath, "utf-8");
417
- const mergeResult = mergeMilestoneToMain(s.basePath, milestoneId, roadmapContent);
418
- s.gitService = createGitService(s.basePath);
419
- ctx.ui.notify(
420
- `Milestone ${milestoneId} merged (branch mode).${mergeResult.pushed ? " Pushed to remote." : ""}`,
421
- "info",
422
- );
423
- return true;
424
- }
425
- }
426
- } catch (err) {
427
- ctx.ui.notify(
428
- `Milestone merge failed (branch mode): ${err instanceof Error ? err.message : String(err)}`,
429
- "warning",
430
- );
431
- }
432
- }
433
-
434
- return false;
435
- }
436
-
437
- /**
438
- * Start a watchdog that fires if no new unit is dispatched within DISPATCH_GAP_TIMEOUT_MS
439
- * after handleAgentEnd completes. This catches the case where the dispatch chain silently
440
- * breaks (e.g., unhandled exception in dispatchNextUnit) and auto-mode is left s.active but idle.
441
- *
442
- * The watchdog is cleared on the next successful unit dispatch (clearUnitTimeout is called
443
- * at the start of handleAgentEnd, which calls clearDispatchGapWatchdog).
444
- */
445
- function startDispatchGapWatchdog(ctx: ExtensionContext, pi: ExtensionAPI): void {
446
- clearDispatchGapWatchdog();
447
- s.dispatchGapHandle = setTimeout(async () => {
448
- s.dispatchGapHandle = null;
449
- if (!s.active || !s.cmdCtx) return;
450
-
451
- if (s.verbose) {
452
- ctx.ui.notify(
453
- "Dispatch gap detected — re-evaluating state.",
454
- "info",
455
- );
456
- }
457
-
458
- try {
459
- await dispatchNextUnit(ctx, pi);
460
- } catch (retryErr) {
461
- const message = getErrorMessage(retryErr);
462
- await stopAuto(ctx, pi, `Dispatch gap recovery failed: ${message}`);
463
- return;
464
- }
465
-
466
- if (s.active && !s.unitTimeoutHandle && !s.wrapupWarningHandle) {
467
- await stopAuto(ctx, pi, "Stalled — no dispatchable unit after retry");
468
- }
469
- }, DISPATCH_GAP_TIMEOUT_MS);
463
+ function handleLostSessionLock(ctx?: ExtensionContext): void {
464
+ debugLog("session-lock-lost", { lockBase: lockBase() });
465
+ s.active = false;
466
+ s.paused = false;
467
+ clearUnitTimeout();
468
+ deregisterSigtermHandler();
469
+ ctx?.ui.notify(
470
+ "Session lock lost another GSD process appears to have taken over. Stopping gracefully.",
471
+ "error",
472
+ );
473
+ ctx?.ui.setStatus("gsd-auto", undefined);
474
+ ctx?.ui.setWidget("gsd-progress", undefined);
475
+ ctx?.ui.setFooter(undefined);
470
476
  }
471
477
 
472
- export async function stopAuto(ctx?: ExtensionContext, pi?: ExtensionAPI, reason?: string): Promise<void> {
478
+ export async function stopAuto(
479
+ ctx?: ExtensionContext,
480
+ pi?: ExtensionAPI,
481
+ reason?: string,
482
+ ): Promise<void> {
473
483
  if (!s.active && !s.paused) return;
474
484
  const reasonSuffix = reason ? ` — ${reason}` : "";
475
485
  clearUnitTimeout();
476
- if (lockBase()) {
477
- releaseSessionLock(lockBase());
478
- clearLock(lockBase());
479
- }
486
+ if (lockBase()) clearLock(lockBase());
487
+ if (lockBase()) releaseSessionLock(lockBase());
480
488
  clearSkillSnapshot();
481
489
  resetSkillTelemetry();
482
- s.dispatching = false;
483
- s.skipDepth = 0;
484
490
 
485
491
  // Remove SIGTERM handler registered at auto-mode start
486
492
  deregisterSigtermHandler();
487
493
 
488
494
  // ── Auto-worktree: exit worktree and reset s.basePath on stop ──
489
- if (s.currentMilestoneId && isInAutoWorktree(s.basePath)) {
490
- try {
491
- try { autoCommitCurrentBranch(s.basePath, "stop", s.currentMilestoneId); } catch (e) { debugLog("stop-auto-commit-failed", { error: getErrorMessage(e) }); }
492
- teardownAutoWorktree(s.originalBasePath, s.currentMilestoneId, { preserveBranch: true });
493
- s.basePath = s.originalBasePath;
494
- s.gitService = createGitService(s.basePath);
495
- ctx?.ui.notify("Exited auto-worktree (branch preserved for resume).", "info");
496
- } catch (err) {
497
- ctx?.ui.notify(
498
- `Auto-worktree teardown failed: ${getErrorMessage(err)}`,
499
- "warning",
500
- );
501
- }
495
+ if (s.currentMilestoneId) {
496
+ const notifyCtx = ctx
497
+ ? { notify: ctx.ui.notify.bind(ctx.ui) }
498
+ : { notify: () => {} };
499
+ buildResolver().exitMilestone(s.currentMilestoneId, notifyCtx, {
500
+ preserveBranch: true,
501
+ });
502
502
  }
503
503
 
504
504
  // ── DB cleanup: close the SQLite connection ──
@@ -506,12 +506,20 @@ export async function stopAuto(ctx?: ExtensionContext, pi?: ExtensionAPI, reason
506
506
  try {
507
507
  const { closeDatabase } = await import("./gsd-db.js");
508
508
  closeDatabase();
509
- } catch (e) { debugLog("db-close-failed", { error: getErrorMessage(e) }); }
509
+ } catch (e) {
510
+ debugLog("db-close-failed", {
511
+ error: e instanceof Error ? e.message : String(e),
512
+ });
513
+ }
510
514
  }
511
515
 
512
516
  if (s.originalBasePath) {
513
517
  s.basePath = s.originalBasePath;
514
- try { process.chdir(s.basePath); } catch { /* best-effort */ }
518
+ try {
519
+ process.chdir(s.basePath);
520
+ } catch {
521
+ /* best-effort */
522
+ }
515
523
  }
516
524
 
517
525
  const ledger = getLedger();
@@ -526,7 +534,13 @@ export async function stopAuto(ctx?: ExtensionContext, pi?: ExtensionAPI, reason
526
534
  }
527
535
 
528
536
  if (s.basePath) {
529
- try { await rebuildState(s.basePath); } catch (e) { debugLog("stop-rebuild-state-failed", { error: getErrorMessage(e) }); }
537
+ try {
538
+ await rebuildState(s.basePath);
539
+ } catch (e) {
540
+ debugLog("stop-rebuild-state-failed", {
541
+ error: e instanceof Error ? e.message : String(e),
542
+ });
543
+ }
530
544
  }
531
545
 
532
546
  if (isDebugEnabled()) {
@@ -545,7 +559,6 @@ export async function stopAuto(ctx?: ExtensionContext, pi?: ExtensionAPI, reason
545
559
  s.stepMode = false;
546
560
  s.unitDispatchCount.clear();
547
561
  s.unitRecoveryCount.clear();
548
- s.unitConsecutiveSkips.clear();
549
562
  clearInFlightTools();
550
563
  s.lastBudgetAlertLevel = 0;
551
564
  s.lastStateRebuildAt = 0;
@@ -559,18 +572,19 @@ export async function stopAuto(ctx?: ExtensionContext, pi?: ExtensionAPI, reason
559
572
  clearSliceProgressCache();
560
573
  clearActivityLogState();
561
574
  resetProactiveHealing();
562
- s.recentlyEvictedKeys.clear();
563
575
  s.pendingCrashRecovery = null;
564
576
  s.pendingVerificationRetry = null;
565
577
  s.verificationRetryCount.clear();
566
578
  s.pausedSessionFile = null;
567
- s.handlingAgentEnd = false;
568
579
  ctx?.ui.setStatus("gsd-auto", undefined);
569
580
  ctx?.ui.setWidget("gsd-progress", undefined);
570
581
  ctx?.ui.setFooter(undefined);
571
582
 
572
583
  if (pi && ctx && s.originalModelId && s.originalModelProvider) {
573
- const original = ctx.modelRegistry.find(s.originalModelProvider, s.originalModelId);
584
+ const original = ctx.modelRegistry.find(
585
+ s.originalModelProvider,
586
+ s.originalModelId,
587
+ );
574
588
  if (original) await pi.setModel(original);
575
589
  s.originalModelId = null;
576
590
  s.originalModelProvider = null;
@@ -584,16 +598,17 @@ export async function stopAuto(ctx?: ExtensionContext, pi?: ExtensionAPI, reason
584
598
  * The user can interact with the agent, then `/gsd auto` resumes
585
599
  * from disk state. Called when the user presses Escape during auto-mode.
586
600
  */
587
- export async function pauseAuto(ctx?: ExtensionContext, _pi?: ExtensionAPI): Promise<void> {
601
+ export async function pauseAuto(
602
+ ctx?: ExtensionContext,
603
+ _pi?: ExtensionAPI,
604
+ ): Promise<void> {
588
605
  if (!s.active) return;
589
606
  clearUnitTimeout();
590
607
 
591
608
  s.pausedSessionFile = ctx?.sessionManager?.getSessionFile() ?? null;
592
609
 
593
- if (lockBase()) {
594
- releaseSessionLock(lockBase());
595
- clearLock(lockBase());
596
- }
610
+ if (lockBase()) clearLock(lockBase());
611
+ if (lockBase()) releaseSessionLock(lockBase());
597
612
 
598
613
  deregisterSigtermHandler();
599
614
 
@@ -611,6 +626,158 @@ export async function pauseAuto(ctx?: ExtensionContext, _pi?: ExtensionAPI): Pro
611
626
  );
612
627
  }
613
628
 
629
+ /**
630
+ * Build a WorktreeResolverDeps from auto.ts private scope.
631
+ * Shared by buildResolver() and buildLoopDeps().
632
+ */
633
+ function buildResolverDeps(): WorktreeResolverDeps {
634
+ return {
635
+ isInAutoWorktree,
636
+ shouldUseWorktreeIsolation,
637
+ getIsolationMode,
638
+ mergeMilestoneToMain,
639
+ syncWorktreeStateBack,
640
+ teardownAutoWorktree,
641
+ createAutoWorktree,
642
+ enterAutoWorktree,
643
+ getAutoWorktreePath,
644
+ autoCommitCurrentBranch,
645
+ getCurrentBranch,
646
+ autoWorktreeBranch,
647
+ resolveMilestoneFile,
648
+ readFileSync: (path: string, encoding: string) =>
649
+ readFileSync(path, encoding as BufferEncoding),
650
+ GitServiceImpl:
651
+ GitServiceImpl as unknown as WorktreeResolverDeps["GitServiceImpl"],
652
+ loadEffectiveGSDPreferences:
653
+ loadEffectiveGSDPreferences as unknown as WorktreeResolverDeps["loadEffectiveGSDPreferences"],
654
+ invalidateAllCaches,
655
+ captureIntegrationBranch,
656
+ };
657
+ }
658
+
659
+ /**
660
+ * Build a WorktreeResolver wrapping the current session.
661
+ * Cheap to construct — it's just a thin wrapper over `s` + deps.
662
+ * Used by stopAuto(), resume path, and buildLoopDeps().
663
+ */
664
+ function buildResolver(): WorktreeResolver {
665
+ return new WorktreeResolver(s, buildResolverDeps());
666
+ }
667
+
668
+ /**
669
+ * Build the LoopDeps object from auto.ts private scope.
670
+ * This bundles all private functions that autoLoop needs without exporting them.
671
+ */
672
+ function buildLoopDeps(): LoopDeps {
673
+ return {
674
+ lockBase,
675
+ buildSnapshotOpts,
676
+ stopAuto,
677
+ pauseAuto,
678
+ clearUnitTimeout,
679
+ updateProgressWidget,
680
+
681
+ // State and cache
682
+ invalidateAllCaches,
683
+ deriveState,
684
+ loadEffectiveGSDPreferences,
685
+
686
+ // Pre-dispatch health gate
687
+ preDispatchHealthGate,
688
+
689
+ // Worktree sync
690
+ syncProjectRootToWorktree,
691
+
692
+ // Resource version guard
693
+ checkResourcesStale,
694
+
695
+ // Session lock
696
+ validateSessionLock,
697
+ updateSessionLock,
698
+ handleLostSessionLock,
699
+
700
+ // Milestone transition
701
+ sendDesktopNotification,
702
+ setActiveMilestoneId,
703
+ pruneQueueOrder,
704
+ isInAutoWorktree,
705
+ shouldUseWorktreeIsolation,
706
+ mergeMilestoneToMain,
707
+ teardownAutoWorktree,
708
+ createAutoWorktree,
709
+ captureIntegrationBranch,
710
+ getIsolationMode,
711
+ getCurrentBranch,
712
+ autoWorktreeBranch,
713
+ resolveMilestoneFile,
714
+ reconcileMergeState,
715
+
716
+ // Budget/context/secrets
717
+ getLedger,
718
+ getProjectTotals,
719
+ formatCost,
720
+ getBudgetAlertLevel,
721
+ getNewBudgetAlertLevel,
722
+ getBudgetEnforcementAction,
723
+ getManifestStatus,
724
+ collectSecretsFromManifest,
725
+
726
+ // Dispatch
727
+ resolveDispatch,
728
+ runPreDispatchHooks,
729
+ getPriorSliceCompletionBlocker,
730
+ getMainBranch,
731
+ collectObservabilityWarnings: _collectObservabilityWarnings,
732
+ buildObservabilityRepairBlock,
733
+
734
+ // Unit closeout + runtime records
735
+ closeoutUnit,
736
+ verifyExpectedArtifact,
737
+ clearUnitRuntimeRecord,
738
+ writeUnitRuntimeRecord,
739
+ recordOutcome,
740
+ writeLock,
741
+ captureAvailableSkills,
742
+ ensurePreconditions,
743
+ updateSliceProgressCache,
744
+
745
+ // Model selection + supervision
746
+ selectAndApplyModel,
747
+ startUnitSupervision,
748
+
749
+ // Prompt helpers
750
+ getDeepDiagnostic,
751
+ isDbAvailable,
752
+ reorderForCaching,
753
+
754
+ // Filesystem
755
+ existsSync,
756
+ readFileSync: (path: string, encoding: string) =>
757
+ readFileSync(path, encoding as BufferEncoding),
758
+ atomicWriteSync,
759
+
760
+ // Git
761
+ GitServiceImpl: GitServiceImpl as unknown as LoopDeps["GitServiceImpl"],
762
+
763
+ // WorktreeResolver
764
+ resolver: buildResolver(),
765
+
766
+ // Post-unit processing
767
+ postUnitPreVerification,
768
+ runPostUnitVerification,
769
+ postUnitPostVerification,
770
+
771
+ // Session manager
772
+ getSessionFile: (ctx: ExtensionContext) => {
773
+ try {
774
+ return ctx.sessionManager?.getSessionFile() ?? "";
775
+ } catch {
776
+ return "";
777
+ }
778
+ },
779
+ } as unknown as LoopDeps;
780
+ }
614
781
 
615
782
  export async function startAuto(
616
783
  ctx: ExtensionCommandContext,
@@ -626,13 +793,9 @@ export async function startAuto(
626
793
 
627
794
  // If resuming from paused state, just re-activate and dispatch next unit.
628
795
  if (s.paused) {
629
- // Re-acquire session lock before resuming
630
796
  const resumeLock = acquireSessionLock(base);
631
797
  if (!resumeLock.acquired) {
632
- ctx.ui.notify(
633
- `Cannot resume: ${resumeLock.reason}`,
634
- "error",
635
- );
798
+ ctx.ui.notify(`Cannot resume: ${resumeLock.reason}`, "error");
636
799
  return;
637
800
  }
638
801
 
@@ -644,47 +807,52 @@ export async function startAuto(
644
807
  s.basePath = base;
645
808
  s.unitDispatchCount.clear();
646
809
  s.unitLifetimeDispatches.clear();
647
- s.unitConsecutiveSkips.clear();
648
810
  if (!getLedger()) initMetrics(base);
649
811
  if (s.currentMilestoneId) setActiveMilestoneId(base, s.currentMilestoneId);
650
812
 
651
813
  // ── Auto-worktree: re-enter worktree on resume ──
652
- if (s.currentMilestoneId && shouldUseWorktreeIsolation() && s.originalBasePath && !isInAutoWorktree(s.basePath) && !detectWorktreeName(s.basePath) && !detectWorktreeName(s.originalBasePath)) {
653
- try {
654
- const existingWtPath = getAutoWorktreePath(s.originalBasePath, s.currentMilestoneId);
655
- if (existingWtPath) {
656
- const wtPath = enterAutoWorktree(s.originalBasePath, s.currentMilestoneId);
657
- s.basePath = wtPath;
658
- s.gitService = createGitService(s.basePath);
659
- ctx.ui.notify(`Re-entered auto-worktree at ${wtPath}`, "info");
660
- } else {
661
- const wtPath = createAutoWorktree(s.originalBasePath, s.currentMilestoneId);
662
- s.basePath = wtPath;
663
- s.gitService = createGitService(s.basePath);
664
- ctx.ui.notify(`Recreated auto-worktree at ${wtPath}`, "info");
665
- }
666
- } catch (err) {
667
- ctx.ui.notify(
668
- `Auto-worktree re-entry failed: ${getErrorMessage(err)}. Continuing at current path.`,
669
- "warning",
670
- );
671
- }
814
+ if (
815
+ s.currentMilestoneId &&
816
+ shouldUseWorktreeIsolation() &&
817
+ s.originalBasePath &&
818
+ !isInAutoWorktree(s.basePath) &&
819
+ !detectWorktreeName(s.basePath) &&
820
+ !detectWorktreeName(s.originalBasePath)
821
+ ) {
822
+ buildResolver().enterMilestone(s.currentMilestoneId, {
823
+ notify: ctx.ui.notify.bind(ctx.ui),
824
+ });
672
825
  }
673
826
 
674
827
  registerSigtermHandler(lockBase());
675
828
 
676
829
  ctx.ui.setStatus("gsd-auto", s.stepMode ? "next" : "auto");
677
830
  ctx.ui.setFooter(hideFooter);
678
- ctx.ui.notify(s.stepMode ? "Step-mode resumed." : "Auto-mode resumed.", "info");
831
+ ctx.ui.notify(
832
+ s.stepMode ? "Step-mode resumed." : "Auto-mode resumed.",
833
+ "info",
834
+ );
679
835
  restoreHookState(s.basePath);
680
- try { await rebuildState(s.basePath); } catch (e) { debugLog("resume-rebuild-state-failed", { error: getErrorMessage(e) }); }
836
+ try {
837
+ await rebuildState(s.basePath);
838
+ } catch (e) {
839
+ debugLog("resume-rebuild-state-failed", {
840
+ error: e instanceof Error ? e.message : String(e),
841
+ });
842
+ }
681
843
  try {
682
844
  const report = await runGSDDoctor(s.basePath, { fix: true });
683
845
  if (report.fixesApplied.length > 0) {
684
- ctx.ui.notify(`Resume: applied ${report.fixesApplied.length} fix(es) to state.`, "info");
846
+ ctx.ui.notify(
847
+ `Resume: applied ${report.fixesApplied.length} fix(es) to state.`,
848
+ "info",
849
+ );
685
850
  }
686
- } catch (e) { debugLog("resume-doctor-failed", { error: getErrorMessage(e) }); }
687
- await selfHealRuntimeRecords(s.basePath, ctx, s.completedKeySet);
851
+ } catch (e) {
852
+ debugLog("resume-doctor-failed", {
853
+ error: e instanceof Error ? e.message : String(e),
854
+ });
855
+ }
688
856
  invalidateAllCaches();
689
857
 
690
858
  if (s.pausedSessionFile) {
@@ -692,7 +860,8 @@ export async function startAuto(
692
860
  const recovery = synthesizeCrashRecovery(
693
861
  s.basePath,
694
862
  s.currentUnit?.type ?? "unknown",
695
- s.currentUnit?.id ?? "unknown", s.pausedSessionFile ?? undefined,
863
+ s.currentUnit?.id ?? "unknown",
864
+ s.pausedSessionFile ?? undefined,
696
865
  activityDir,
697
866
  );
698
867
  if (recovery && recovery.trace.toolCallCount > 0) {
@@ -705,42 +874,20 @@ export async function startAuto(
705
874
  s.pausedSessionFile = null;
706
875
  }
707
876
 
708
- // If resuming from a secrets pause, re-collect before dispatching (#1146)
709
- if (s.pausedForSecrets && s.currentMilestoneId) {
710
- try {
711
- const manifestStatus = await getManifestStatus(s.basePath, s.currentMilestoneId);
712
- if (manifestStatus && manifestStatus.pending.length > 0) {
713
- const result = await collectSecretsFromManifest(s.basePath, s.currentMilestoneId, ctx);
714
- if (result && result.applied.length > 0) {
715
- ctx.ui.notify(
716
- `Secrets collected: ${result.applied.length} applied, ${result.skipped.length} skipped, ${result.existingSkipped.length} already set.`,
717
- "info",
718
- );
719
- } else if (result && result.applied.length === 0 && result.skipped.length > 0) {
720
- // All keys were skipped — still pending, re-pause
721
- s.paused = true;
722
- s.active = false;
723
- ctx.ui.notify(
724
- `All env variables were skipped. Auto-mode remains paused.\nCollect them with /gsd secrets, then resume with /gsd auto.`,
725
- "warning",
726
- );
727
- ctx.ui.setStatus("gsd-auto", "paused");
728
- return;
729
- }
730
- }
731
- } catch (err) {
732
- ctx.ui.notify(
733
- `Secrets check error: ${getErrorMessage(err)}. Continuing without secrets.`,
734
- "warning",
735
- );
736
- }
737
- s.pausedForSecrets = false;
738
- }
739
-
740
- updateSessionLock(lockBase(), "resuming", s.currentMilestoneId ?? "unknown", s.completedUnits.length);
741
- writeLock(lockBase(), "resuming", s.currentMilestoneId ?? "unknown", s.completedUnits.length);
877
+ updateSessionLock(
878
+ lockBase(),
879
+ "resuming",
880
+ s.currentMilestoneId ?? "unknown",
881
+ s.completedUnits.length,
882
+ );
883
+ writeLock(
884
+ lockBase(),
885
+ "resuming",
886
+ s.currentMilestoneId ?? "unknown",
887
+ s.completedUnits.length,
888
+ );
742
889
 
743
- await dispatchNextUnit(ctx, pi);
890
+ await autoLoop(ctx, pi, s, buildLoopDeps());
744
891
  return;
745
892
  }
746
893
 
@@ -749,210 +896,45 @@ export async function startAuto(
749
896
  shouldUseWorktreeIsolation,
750
897
  registerSigtermHandler,
751
898
  lockBase,
899
+ buildResolver,
752
900
  };
753
901
 
754
- const ready = await bootstrapAutoSession(s, ctx, pi, base, verboseMode, requestedStepMode, bootstrapDeps);
755
- if (!ready) return;
756
-
757
- // Dispatch the first unit
758
- await dispatchNextUnit(ctx, pi);
759
- }
760
-
761
- // ─── Agent End Handler ────────────────────────────────────────────────────────
762
-
763
- /** Guard against concurrent handleAgentEnd execution. */
764
-
765
- export async function handleAgentEnd(
766
- ctx: ExtensionContext,
767
- pi: ExtensionAPI,
768
- ): Promise<void> {
769
- if (!s.active || !s.cmdCtx) return;
770
- if (s.handlingAgentEnd) {
771
- // Another agent_end arrived while we're still processing the previous one.
772
- // This happens when a unit dispatched inside handleAgentEnd (e.g. via hooks,
773
- // triage, or quick-task early-dispatch paths) completes before the outer
774
- // handleAgentEnd returns. Queue a retry so the completed unit's agent_end
775
- // is not silently dropped (#1072).
776
- s.pendingAgentEndRetry = true;
777
- return;
778
- }
779
- s.handlingAgentEnd = true;
780
-
781
- try {
782
-
783
- // Unit completed — clear its timeout
784
- clearUnitTimeout();
785
-
786
- // ── Pre-verification processing (commit, doctor, state rebuild, etc.) ──
787
- const postUnitCtx: PostUnitContext = {
902
+ const ready = await bootstrapAutoSession(
788
903
  s,
789
904
  ctx,
790
905
  pi,
791
- buildSnapshotOpts,
792
- lockBase,
793
- stopAuto,
794
- pauseAuto,
795
- updateProgressWidget,
796
- };
797
-
798
- const preResult = await postUnitPreVerification(postUnitCtx);
799
- if (preResult === "dispatched") return;
800
-
801
- // ── Verification gate: run typecheck/lint/test after execute-task ──
802
- const verificationResult = await runPostUnitVerification(
803
- { s, ctx, pi },
804
- dispatchNextUnit,
805
- startDispatchGapWatchdog,
806
- pauseAuto,
906
+ base,
907
+ verboseMode,
908
+ requestedStepMode,
909
+ bootstrapDeps,
807
910
  );
808
- if (verificationResult === "retry" || verificationResult === "pause") return;
809
-
810
- // ── Post-verification processing (DB dual-write, hooks, triage, quick-tasks) ──
811
- const postResult = await postUnitPostVerification(postUnitCtx);
812
- if (postResult === "dispatched" || postResult === "stopped") return;
813
- if (postResult === "step-wizard") {
814
- await showStepWizard(ctx, pi);
815
- return;
816
- }
817
-
818
- // ── Dispatch with hang detection (#1073) ────────────────────────────────
819
- // Start a safety watchdog BEFORE calling dispatchNextUnit. If dispatch
820
- // hangs at any await (newSession, model selection, etc.), the gap watchdog
821
- // inside handleAgentEnd never fires because we never reach the check.
822
- // This pre-dispatch watchdog ensures recovery even when dispatchNextUnit
823
- // itself is permanently blocked.
824
- const dispatchHangGuard = setTimeout(() => {
825
- if (!s.active) return;
826
- // dispatchNextUnit has been running for too long — it's likely hung.
827
- // Start the gap watchdog which will retry dispatch from scratch.
828
- if (!s.unitTimeoutHandle && !s.wrapupWarningHandle) {
829
- ctx.ui.notify(
830
- `Dispatch hang detected (${DISPATCH_HANG_TIMEOUT_MS / 1000}s without completion). Starting recovery watchdog.`,
831
- "warning",
832
- );
833
- startDispatchGapWatchdog(ctx, pi);
834
- }
835
- }, DISPATCH_HANG_TIMEOUT_MS);
836
-
837
- try {
838
- await dispatchNextUnit(ctx, pi);
839
- } catch (dispatchErr) {
840
- const message = getErrorMessage(dispatchErr);
841
- ctx.ui.notify(
842
- `Dispatch error after unit completion: ${message}. Retrying in ${DISPATCH_GAP_TIMEOUT_MS / 1000}s.`,
843
- "error",
844
- );
845
- startDispatchGapWatchdog(ctx, pi);
846
- return;
847
- } finally {
848
- clearTimeout(dispatchHangGuard);
849
- }
850
-
851
- if (s.active && !s.unitTimeoutHandle && !s.wrapupWarningHandle) {
852
- startDispatchGapWatchdog(ctx, pi);
853
- }
911
+ if (!ready) return;
854
912
 
855
- } finally {
856
- s.handlingAgentEnd = false;
857
-
858
- // If an agent_end event was dropped by the reentrancy guard while we were
859
- // processing, re-enter handleAgentEnd on the next microtask. This prevents
860
- // the summarizing phase stall (#1072) where a unit dispatched inside
861
- // handleAgentEnd (hooks, triage, quick-task) completes before we return,
862
- // and its agent_end is silently dropped — leaving auto-mode active but
863
- // permanently stalled with no unit running and no watchdog set.
864
- if (s.pendingAgentEndRetry) {
865
- s.pendingAgentEndRetry = false;
866
- // Clear gap watchdog from the previous cycle to prevent concurrent
867
- // dispatch when the deferred handleAgentEnd calls dispatchNextUnit (#1272).
868
- clearDispatchGapWatchdog();
869
- setImmediate(() => {
870
- handleAgentEnd(ctx, pi).catch((err) => {
871
- const msg = getErrorMessage(err);
872
- ctx.ui.notify(`Deferred agent_end retry failed: ${msg}`, "error");
873
- pauseAuto(ctx, pi).catch(() => {});
874
- });
875
- });
876
- }
877
- }
913
+ // Dispatch the first unit
914
+ await autoLoop(ctx, pi, s, buildLoopDeps());
878
915
  }
879
916
 
880
- // ─── Step Mode Wizard ─────────────────────────────────────────────────────
917
+ // ─── Agent End Handler ────────────────────────────────────────────────────────
881
918
 
882
919
  /**
883
- * Show the step-mode wizard after a unit completes.
920
+ * Deprecated thin wrapper kept as export for backward compatibility.
921
+ * The actual agent_end processing now happens via resolveAgentEnd() in auto-loop.ts,
922
+ * which is called directly from index.ts. The autoLoop() while loop handles all
923
+ * post-unit processing (verification, hooks, dispatch) that this function used to do.
924
+ *
925
+ * If called by straggler code, it simply resolves the pending promise so the loop
926
+ * can continue.
884
927
  */
885
- async function showStepWizard(
928
+ export async function handleAgentEnd(
886
929
  ctx: ExtensionContext,
887
930
  pi: ExtensionAPI,
888
931
  ): Promise<void> {
889
- if (!s.cmdCtx) return;
890
-
891
- const state = await deriveState(s.basePath);
892
- const mid = state.activeMilestone?.id;
893
-
894
- const justFinished = s.currentUnit
895
- ? `${unitVerb(s.currentUnit.type)} ${s.currentUnit.id}`
896
- : "previous unit";
897
-
898
- if (!mid || state.phase === "complete") {
899
- const incomplete = (state.registry ?? []).filter(m => m.status !== "complete" && m.status !== "parked");
900
- if (incomplete.length > 0 && state.phase !== "complete" && state.phase !== "blocked" && state.phase !== "pre-planning") {
901
- const ids = incomplete.map(m => m.id).join(", ");
902
- const diag = `basePath=${s.basePath}, milestones=[${state.registry.map(m => `${m.id}:${m.status}`).join(", ")}], phase=${state.phase}`;
903
- ctx.ui.notify(`Unexpected: ${incomplete.length} incomplete milestone(s) (${ids}) but no active milestone.\n Diagnostic: ${diag}`, "error");
904
- await stopAuto(ctx, pi, `No active milestone — ${incomplete.length} incomplete (${ids})`);
905
- } else {
906
- await stopAuto(ctx, pi, state.phase === "complete" ? "All work complete" : "No active milestone");
907
- }
908
- return;
909
- }
910
-
911
- const nextDesc = _describeNextUnit(state);
912
-
913
- const choice = await showNextAction(s.cmdCtx, {
914
- title: `GSD — ${justFinished} complete`,
915
- summary: [
916
- `${mid}: ${state.activeMilestone?.title ?? mid}`,
917
- ...(state.activeSlice ? [`${state.activeSlice.id}: ${state.activeSlice.title}`] : []),
918
- ],
919
- actions: [
920
- {
921
- id: "continue",
922
- label: nextDesc.label,
923
- description: nextDesc.description,
924
- recommended: true,
925
- },
926
- {
927
- id: "auto",
928
- label: "Switch to auto",
929
- description: "Continue without pausing between steps.",
930
- },
931
- {
932
- id: "status",
933
- label: "View status",
934
- description: "Open the dashboard.",
935
- },
936
- ],
937
- notYetMessage: "Run /gsd next when ready to continue.",
938
- });
939
-
940
- if (choice === "continue") {
941
- await dispatchNextUnit(ctx, pi);
942
- } else if (choice === "auto") {
943
- s.stepMode = false;
944
- ctx.ui.setStatus("gsd-auto", "auto");
945
- ctx.ui.notify("Switched to auto-mode.", "info");
946
- await dispatchNextUnit(ctx, pi);
947
- } else if (choice === "status") {
948
- const { fireStatusViaCommand } = await import("./commands.js");
949
- await fireStatusViaCommand(ctx as ExtensionCommandContext);
950
- await showStepWizard(ctx, pi);
951
- } else {
952
- await pauseAuto(ctx, pi);
953
- }
932
+ if (!s.active || !s.cmdCtx) return;
933
+ clearUnitTimeout();
934
+ resolveAgentEnd({ messages: [] });
954
935
  }
955
-
936
+ // describeNextUnit is imported from auto-dashboard.ts and re-exported
937
+ export { describeNextUnit } from "./auto-dashboard.js";
956
938
 
957
939
  /** Thin wrapper: delegates to auto-dashboard.ts, passing state accessors. */
958
940
  function updateProgressWidget(
@@ -962,9 +944,17 @@ function updateProgressWidget(
962
944
  state: GSDState,
963
945
  ): void {
964
946
  const badge = s.currentUnitRouting?.tier
965
- ? ({ light: "L", standard: "S", heavy: "H" }[s.currentUnitRouting.tier] ?? undefined)
947
+ ? ({ light: "L", standard: "S", heavy: "H" }[s.currentUnitRouting.tier] ??
948
+ undefined)
966
949
  : undefined;
967
- _updateProgressWidget(ctx, unitType, unitId, state, widgetStateAccessors, badge);
950
+ _updateProgressWidget(
951
+ ctx,
952
+ unitType,
953
+ unitId,
954
+ state,
955
+ widgetStateAccessors,
956
+ badge,
957
+ );
968
958
  }
969
959
 
970
960
  /** State accessors for the widget — closures over module globals. */
@@ -976,695 +966,6 @@ const widgetStateAccessors: WidgetStateAccessors = {
976
966
  isVerbose: () => s.verbose,
977
967
  };
978
968
 
979
- // ─── Core Loop ────────────────────────────────────────────────────────────────
980
-
981
- async function dispatchNextUnit(
982
- ctx: ExtensionContext,
983
- pi: ExtensionAPI,
984
- ): Promise<void> {
985
- if (!s.active || !s.cmdCtx) {
986
- debugLog(`dispatchNextUnit early return — active=${s.active}, cmdCtx=${!!s.cmdCtx}`);
987
- if (s.active && !s.cmdCtx) {
988
- ctx.ui.notify("Auto-mode session expired. Run /gsd auto to restart.", "info");
989
- }
990
- return;
991
- }
992
-
993
- // ── Session lock validation: detect if another process has taken over ──
994
- if (lockBase() && !validateSessionLock(lockBase())) {
995
- debugLog("dispatchNextUnit session-lock-lost — another process may have taken over");
996
- ctx.ui.notify(
997
- "Session lock lost — another GSD process appears to have taken over. Stopping gracefully.",
998
- "error",
999
- );
1000
- // Don't call stopAuto here to avoid releasing the lock we don't own
1001
- s.active = false;
1002
- s.paused = false;
1003
- clearUnitTimeout();
1004
- deregisterSigtermHandler();
1005
- ctx.ui.setStatus("gsd-auto", undefined);
1006
- ctx.ui.setWidget("gsd-progress", undefined);
1007
- ctx.ui.setFooter(undefined);
1008
- return;
1009
- }
1010
-
1011
- // Reentrancy guard — unconditional to prevent concurrent dispatch from
1012
- // gap watchdog or pendingAgentEndRetry during skip chains (#1272).
1013
- // Previously the guard was bypassed when skipDepth > 0, but the recursive
1014
- // skip chain's inner finally block resets s.dispatching = false before the
1015
- // outer call's finally runs, opening a window for concurrent entry.
1016
- if (s.dispatching) {
1017
- debugLog("dispatchNextUnit reentrancy guard — another dispatch in progress, bailing");
1018
- return;
1019
- }
1020
- s.dispatching = true;
1021
- try {
1022
- // Recursion depth guard
1023
- if (s.skipDepth > MAX_SKIP_DEPTH) {
1024
- s.skipDepth = 0;
1025
- ctx.ui.notify(`Skipped ${MAX_SKIP_DEPTH}+ completed units. Yielding to UI before continuing.`, "info");
1026
- await new Promise(r => setTimeout(r, 200));
1027
- }
1028
-
1029
- // Resource version guard
1030
- const staleMsg = checkResourcesStale(s.resourceVersionOnStart);
1031
- if (staleMsg) {
1032
- await stopAuto(ctx, pi, staleMsg);
1033
- return;
1034
- }
1035
-
1036
- invalidateAllCaches();
1037
- s.lastPromptCharCount = undefined;
1038
- s.lastBaselineCharCount = undefined;
1039
-
1040
- // ── Pre-dispatch health gate ──
1041
- try {
1042
- const healthGate = await preDispatchHealthGate(s.basePath);
1043
- if (healthGate.fixesApplied.length > 0) {
1044
- ctx.ui.notify(`Pre-dispatch: ${healthGate.fixesApplied.join(", ")}`, "info");
1045
- }
1046
- if (!healthGate.proceed) {
1047
- ctx.ui.notify(healthGate.reason ?? "Pre-dispatch health check failed.", "error");
1048
- await pauseAuto(ctx, pi);
1049
- return;
1050
- }
1051
- } catch {
1052
- // Non-fatal
1053
- }
1054
-
1055
- const stopDeriveTimer = debugTime("derive-state");
1056
- let state = await deriveState(s.basePath);
1057
- stopDeriveTimer({
1058
- phase: state.phase,
1059
- milestone: state.activeMilestone?.id,
1060
- slice: state.activeSlice?.id,
1061
- task: state.activeTask?.id,
1062
- });
1063
- let mid = state.activeMilestone?.id;
1064
- let midTitle = state.activeMilestone?.title;
1065
-
1066
- // Detect milestone transition
1067
- if (mid && s.currentMilestoneId && mid !== s.currentMilestoneId) {
1068
- ctx.ui.notify(
1069
- `Milestone ${ s.currentMilestoneId } complete. Advancing to ${mid}: ${midTitle}.`,
1070
- "info",
1071
- );
1072
- sendDesktopNotification("GSD", `Milestone ${s.currentMilestoneId} complete!`, "success", "milestone");
1073
- const vizPrefs = loadEffectiveGSDPreferences()?.preferences;
1074
- if (vizPrefs?.auto_visualize) {
1075
- ctx.ui.notify("Run /gsd visualize to see progress overview.", "info");
1076
- }
1077
- if (vizPrefs?.auto_report !== false) {
1078
- try {
1079
- const { loadVisualizerData } = await import("./visualizer-data.js");
1080
- const { generateHtmlReport } = await import("./export-html.js");
1081
- const { writeReportSnapshot, reportsDir } = await import("./reports.js");
1082
- const { basename } = await import("node:path");
1083
- const snapData = await loadVisualizerData(s.basePath);
1084
- const completedMs = snapData.milestones.find(m => m.id === s.currentMilestoneId);
1085
- const msTitle = completedMs?.title ?? s.currentMilestoneId;
1086
- const gsdVersion = process.env.GSD_VERSION ?? "0.0.0";
1087
- const projName = basename(s.basePath);
1088
- const doneSlices = snapData.milestones.reduce((s, m) => s + m.slices.filter(sl => sl.done).length, 0);
1089
- const totalSlices = snapData.milestones.reduce((s, m) => s + m.slices.length, 0);
1090
- const outPath = writeReportSnapshot({ basePath: s.basePath,
1091
- html: generateHtmlReport(snapData, {
1092
- projectName: projName,
1093
- projectPath: s.basePath,
1094
- gsdVersion,
1095
- milestoneId: s.currentMilestoneId,
1096
- indexRelPath: "index.html",
1097
- }),
1098
- milestoneId: s.currentMilestoneId,
1099
- milestoneTitle: msTitle,
1100
- kind: "milestone",
1101
- projectName: projName,
1102
- projectPath: s.basePath,
1103
- gsdVersion,
1104
- totalCost: snapData.totals?.cost ?? 0,
1105
- totalTokens: snapData.totals?.tokens.total ?? 0,
1106
- totalDuration: snapData.totals?.duration ?? 0,
1107
- doneSlices,
1108
- totalSlices,
1109
- doneMilestones: snapData.milestones.filter(m => m.status === "complete").length,
1110
- totalMilestones: snapData.milestones.length,
1111
- phase: snapData.phase,
1112
- });
1113
- ctx.ui.notify(
1114
- `Report saved: .gsd/reports/${basename(outPath)} — open index.html to browse progression.`,
1115
- "info",
1116
- );
1117
- } catch (err) {
1118
- ctx.ui.notify(
1119
- `Report generation failed: ${getErrorMessage(err)}`,
1120
- "warning",
1121
- );
1122
- }
1123
- }
1124
- // Reset stuck detection for new milestone
1125
- s.unitDispatchCount.clear();
1126
- s.unitRecoveryCount.clear();
1127
- s.unitConsecutiveSkips.clear();
1128
- s.unitLifetimeDispatches.clear();
1129
- try {
1130
- const file = completedKeysPath(s.basePath);
1131
- if (existsSync(file)) {
1132
- atomicWriteSync(file, JSON.stringify([]));
1133
- }
1134
- s.completedKeySet.clear();
1135
- } catch (e) { debugLog("completed-keys-reset-failed", { error: getErrorMessage(e) }); }
1136
-
1137
- // ── Worktree lifecycle on milestone transition (#616) ──
1138
- if ((isInAutoWorktree(s.basePath) || getIsolationMode() === "branch") && shouldUseWorktreeIsolation()) {
1139
- tryMergeMilestone(ctx, s.currentMilestoneId, "transition");
1140
-
1141
- // Reset to project root and re-derive state for the new milestone
1142
- if (s.originalBasePath) {
1143
- s.basePath = s.originalBasePath;
1144
- s.gitService = createGitService(s.basePath);
1145
- }
1146
- invalidateAllCaches();
1147
-
1148
- state = await deriveState(s.basePath);
1149
- mid = state.activeMilestone?.id;
1150
- midTitle = state.activeMilestone?.title;
1151
-
1152
- if (mid) {
1153
- captureIntegrationBranch(s.basePath, mid);
1154
- try {
1155
- const wtPath = createAutoWorktree(s.basePath, mid);
1156
- s.basePath = wtPath;
1157
- s.gitService = createGitService(s.basePath);
1158
- ctx.ui.notify(`Created auto-worktree for ${mid} at ${wtPath}`, "info");
1159
- } catch (err) {
1160
- ctx.ui.notify(
1161
- `Auto-worktree creation for ${mid} failed: ${getErrorMessage(err)}. Continuing in project root.`,
1162
- "warning",
1163
- );
1164
- }
1165
- }
1166
- } else {
1167
- if (getIsolationMode() !== "none") {
1168
- captureIntegrationBranch(s.originalBasePath || s.basePath, mid);
1169
- }
1170
- }
1171
-
1172
- const pendingIds = (state.registry ?? [])
1173
- .filter(m => m.status !== "complete")
1174
- .map(m => m.id);
1175
- pruneQueueOrder(s.basePath, pendingIds);
1176
- }
1177
- if (mid) {
1178
- s.currentMilestoneId = mid;
1179
- setActiveMilestoneId(s.basePath, mid);
1180
- }
1181
-
1182
- if (!mid) {
1183
- if (s.currentUnit) {
1184
- await closeoutUnit(ctx, s.basePath, s.currentUnit.type, s.currentUnit.id, s.currentUnit.startedAt, buildSnapshotOpts(s.currentUnit.type, s.currentUnit.id));
1185
- }
1186
-
1187
- const incomplete = (state.registry ?? []).filter(m => m.status !== "complete" && m.status !== "parked");
1188
- if (incomplete.length === 0) {
1189
- // Genuinely all complete (parked milestones excluded) — merge milestone branch to main before stopping (#962)
1190
- if (s.currentMilestoneId) {
1191
- tryMergeMilestone(ctx, s.currentMilestoneId, "complete");
1192
- }
1193
- sendDesktopNotification("GSD", "All milestones complete!", "success", "milestone");
1194
- await stopAuto(ctx, pi, "All milestones complete");
1195
- } else if (state.phase === "blocked") {
1196
- const blockerMsg = `Blocked: ${state.blockers.join(", ")}`;
1197
- await stopAuto(ctx, pi, blockerMsg);
1198
- ctx.ui.notify(`${blockerMsg}. Fix and run /gsd auto.`, "warning");
1199
- sendDesktopNotification("GSD", blockerMsg, "error", "attention");
1200
- } else {
1201
- const ids = incomplete.map(m => m.id).join(", ");
1202
- const diag = `basePath=${s.basePath}, milestones=[${state.registry.map(m => `${m.id}:${m.status}`).join(", ")}], phase=${state.phase}`;
1203
- ctx.ui.notify(`Unexpected: ${incomplete.length} incomplete milestone(s) (${ids}) but no active milestone.\n Diagnostic: ${diag}`, "error");
1204
- await stopAuto(ctx, pi, `No active milestone — ${incomplete.length} incomplete (${ids}), see diagnostic above`);
1205
- }
1206
- return;
1207
- }
1208
-
1209
- if (!midTitle) {
1210
- midTitle = mid;
1211
- ctx.ui.notify(`Milestone ${mid} has no title in roadmap — using ID as fallback.`, "warning");
1212
- }
1213
-
1214
- // ── Mid-merge safety check ──
1215
- if (reconcileMergeState(s.basePath, ctx)) {
1216
- invalidateAllCaches();
1217
- state = await deriveState(s.basePath);
1218
- mid = state.activeMilestone?.id;
1219
- midTitle = state.activeMilestone?.title;
1220
- }
1221
-
1222
- if (!mid || !midTitle) {
1223
- if (s.currentUnit) {
1224
- await closeoutUnit(ctx, s.basePath, s.currentUnit.type, s.currentUnit.id, s.currentUnit.startedAt, buildSnapshotOpts(s.currentUnit.type, s.currentUnit.id));
1225
- }
1226
- const noMilestoneReason = !mid
1227
- ? "No active milestone after merge reconciliation"
1228
- : `Milestone ${mid} has no title after reconciliation`;
1229
- await stopAuto(ctx, pi, noMilestoneReason);
1230
- return;
1231
- }
1232
-
1233
- // Determine next unit
1234
- let unitType: string;
1235
- let unitId: string;
1236
- let prompt: string;
1237
-
1238
- if (state.phase === "complete") {
1239
- if (s.currentUnit) {
1240
- await closeoutUnit(ctx, s.basePath, s.currentUnit.type, s.currentUnit.id, s.currentUnit.startedAt, buildSnapshotOpts(s.currentUnit.type, s.currentUnit.id));
1241
- }
1242
- try {
1243
- const file = completedKeysPath(s.basePath);
1244
- if (existsSync(file)) {
1245
- atomicWriteSync(file, JSON.stringify([]));
1246
- }
1247
- s.completedKeySet.clear();
1248
- } catch (e) { debugLog("completed-keys-reset-failed", { error: getErrorMessage(e) }); }
1249
- // ── Milestone merge ──
1250
- if (s.currentMilestoneId) {
1251
- tryMergeMilestone(ctx, s.currentMilestoneId, "complete");
1252
- }
1253
- sendDesktopNotification("GSD", `Milestone ${mid} complete!`, "success", "milestone");
1254
- await stopAuto(ctx, pi, `Milestone ${mid} complete`);
1255
- return;
1256
- }
1257
-
1258
- if (state.phase === "blocked") {
1259
- if (s.currentUnit) {
1260
- await closeoutUnit(ctx, s.basePath, s.currentUnit.type, s.currentUnit.id, s.currentUnit.startedAt, buildSnapshotOpts(s.currentUnit.type, s.currentUnit.id));
1261
- }
1262
- const blockerMsg = `Blocked: ${state.blockers.join(", ")}`;
1263
- await stopAuto(ctx, pi, blockerMsg);
1264
- ctx.ui.notify(`${blockerMsg}. Fix and run /gsd auto.`, "warning");
1265
- sendDesktopNotification("GSD", blockerMsg, "error", "attention");
1266
- return;
1267
- }
1268
-
1269
- // Budget ceiling guard, context window guard, secrets gate, dispatch table
1270
- const prefs = loadEffectiveGSDPreferences()?.preferences;
1271
-
1272
- const budgetCeiling = prefs?.budget_ceiling;
1273
- if (budgetCeiling !== undefined && budgetCeiling > 0) {
1274
- const currentLedger = getLedger();
1275
- const totalCost = currentLedger ? getProjectTotals(currentLedger.units).cost : 0;
1276
- const budgetPct = totalCost / budgetCeiling;
1277
- const budgetAlertLevel = getBudgetAlertLevel(budgetPct);
1278
- const newBudgetAlertLevel = getNewBudgetAlertLevel(s.lastBudgetAlertLevel, budgetPct);
1279
- const enforcement = prefs?.budget_enforcement ?? "pause";
1280
-
1281
- const budgetEnforcementAction = getBudgetEnforcementAction(enforcement, budgetPct);
1282
-
1283
- if (newBudgetAlertLevel === 100 && budgetEnforcementAction !== "none") {
1284
- const msg = `Budget ceiling ${formatCost(budgetCeiling)} reached (spent ${formatCost(totalCost)}).`;
1285
- s.lastBudgetAlertLevel = newBudgetAlertLevel;
1286
- if (budgetEnforcementAction === "halt") {
1287
- sendDesktopNotification("GSD", msg, "error", "budget");
1288
- await stopAuto(ctx, pi, "Budget ceiling reached");
1289
- return;
1290
- }
1291
- if (budgetEnforcementAction === "pause") {
1292
- ctx.ui.notify(`${msg} Pausing auto-mode — /gsd auto to override and continue.`, "warning");
1293
- sendDesktopNotification("GSD", msg, "warning", "budget");
1294
- await pauseAuto(ctx, pi);
1295
- return;
1296
- }
1297
- ctx.ui.notify(`${msg} Continuing (enforcement: warn).`, "warning");
1298
- sendDesktopNotification("GSD", msg, "warning", "budget");
1299
- } else if (newBudgetAlertLevel === 90) {
1300
- s.lastBudgetAlertLevel = newBudgetAlertLevel;
1301
- ctx.ui.notify(`Budget 90%: ${formatCost(totalCost)} / ${formatCost(budgetCeiling)}`, "warning");
1302
- sendDesktopNotification("GSD", `Budget 90%: ${formatCost(totalCost)} / ${formatCost(budgetCeiling)}`, "warning", "budget");
1303
- } else if (newBudgetAlertLevel === 80) {
1304
- s.lastBudgetAlertLevel = newBudgetAlertLevel;
1305
- ctx.ui.notify(`Approaching budget ceiling — 80%: ${formatCost(totalCost)} / ${formatCost(budgetCeiling)}`, "warning");
1306
- sendDesktopNotification("GSD", `Approaching budget ceiling — 80%: ${formatCost(totalCost)} / ${formatCost(budgetCeiling)}`, "warning", "budget");
1307
- } else if (newBudgetAlertLevel === 75) {
1308
- s.lastBudgetAlertLevel = newBudgetAlertLevel;
1309
- ctx.ui.notify(`Budget 75%: ${formatCost(totalCost)} / ${formatCost(budgetCeiling)}`, "info");
1310
- sendDesktopNotification("GSD", `Budget 75%: ${formatCost(totalCost)} / ${formatCost(budgetCeiling)}`, "info", "budget");
1311
- } else if (budgetAlertLevel === 0) {
1312
- s.lastBudgetAlertLevel = 0;
1313
- }
1314
- } else {
1315
- s.lastBudgetAlertLevel = 0;
1316
- }
1317
-
1318
- const contextThreshold = prefs?.context_pause_threshold ?? 0;
1319
- if (contextThreshold > 0 && s.cmdCtx) {
1320
- const contextUsage = s.cmdCtx.getContextUsage();
1321
- if (contextUsage && contextUsage.percent !== null && contextUsage.percent >= contextThreshold) {
1322
- const msg = `Context window at ${contextUsage.percent}% (threshold: ${contextThreshold}%). Pausing to prevent truncated output.`;
1323
- ctx.ui.notify(`${msg} Run /gsd auto to continue (will start fresh session).`, "warning");
1324
- sendDesktopNotification("GSD", `Context ${contextUsage.percent}% — paused`, "warning", "attention");
1325
- await pauseAuto(ctx, pi);
1326
- return;
1327
- }
1328
- }
1329
-
1330
- // Secrets re-check gate
1331
- const runSecretsGate = async () => {
1332
- try {
1333
- const manifestStatus = await getManifestStatus(s.basePath, mid);
1334
- if (manifestStatus && manifestStatus.pending.length > 0) {
1335
- const result = await collectSecretsFromManifest(s.basePath, mid, ctx);
1336
- if (result && result.applied && result.skipped && result.existingSkipped) {
1337
- ctx.ui.notify(
1338
- `Secrets collected: ${result.applied.length} applied, ${result.skipped.length} skipped, ${result.existingSkipped.length} already set.`,
1339
- "info",
1340
- );
1341
- } else {
1342
- ctx.ui.notify("Secrets collection skipped.", "info");
1343
- }
1344
- }
1345
- } catch (err) {
1346
- ctx.ui.notify(
1347
- `Secrets collection error: ${getErrorMessage(err)}. Continuing with next task.`,
1348
- "warning",
1349
- );
1350
- }
1351
- };
1352
-
1353
- await runSecretsGate();
1354
-
1355
- // ── Interactive discussion gate ──
1356
- // If the active milestone needs discussion (has CONTEXT-DRAFT.md but no roadmap),
1357
- // stop auto-mode and route to the interactive discussion flow. The guided-flow
1358
- // handles needs-discussion correctly — it just needs to be called instead of
1359
- // letting the dispatch table fire "needs-discussion → stop" (#1170).
1360
- if (state.phase === "needs-discussion") {
1361
- if (s.currentUnit) {
1362
- await closeoutUnit(ctx, s.basePath, s.currentUnit.type, s.currentUnit.id, s.currentUnit.startedAt, buildSnapshotOpts(s.currentUnit.type, s.currentUnit.id));
1363
- }
1364
- const cmdCtx = s.cmdCtx!;
1365
- const basePath = s.basePath;
1366
- await stopAuto(ctx, pi, `${mid}: ${midTitle} needs discussion before planning.`);
1367
- const { showSmartEntry } = await import("./guided-flow.js");
1368
- await showSmartEntry(cmdCtx, pi, basePath);
1369
- return;
1370
- }
1371
-
1372
- // ── Dispatch table ──
1373
- const dispatchResult = await resolveDispatch({ basePath: s.basePath, mid, midTitle: midTitle!, state, prefs,
1374
- });
1375
-
1376
- if (dispatchResult.action === "stop") {
1377
- if (s.currentUnit) {
1378
- await closeoutUnit(ctx, s.basePath, s.currentUnit.type, s.currentUnit.id, s.currentUnit.startedAt, buildSnapshotOpts(s.currentUnit.type, s.currentUnit.id));
1379
- }
1380
- await stopAuto(ctx, pi, dispatchResult.reason);
1381
- return;
1382
- }
1383
-
1384
- if (dispatchResult.action !== "dispatch") {
1385
- // Defer re-dispatch to next microtask so s.dispatching is released first,
1386
- // preventing reentrancy guard bypass during concurrent entry (#1272).
1387
- setImmediate(() => dispatchNextUnit(ctx, pi).catch(err => {
1388
- ctx.ui.notify(`Deferred dispatch failed: ${err instanceof Error ? err.message : String(err)}`, "error");
1389
- pauseAuto(ctx, pi).catch(() => {});
1390
- }));
1391
- return;
1392
- }
1393
-
1394
- unitType = dispatchResult.unitType;
1395
- unitId = dispatchResult.unitId;
1396
- prompt = dispatchResult.prompt;
1397
-
1398
- // ── Pre-dispatch hooks ──
1399
- const preDispatchResult = runPreDispatchHooks(unitType, unitId, prompt, s.basePath);
1400
- if (preDispatchResult.firedHooks.length > 0) {
1401
- ctx.ui.notify(
1402
- `Pre-dispatch hook${preDispatchResult.firedHooks.length > 1 ? "s" : ""}: ${preDispatchResult.firedHooks.join(", ")}`,
1403
- "info",
1404
- );
1405
- }
1406
- if (preDispatchResult.action === "skip") {
1407
- ctx.ui.notify(`Skipping ${unitType} ${unitId} (pre-dispatch hook).`, "info");
1408
- setImmediate(() => dispatchNextUnit(ctx, pi).catch(err => {
1409
- ctx.ui.notify(`Deferred dispatch failed: ${err instanceof Error ? err.message : String(err)}`, "error");
1410
- pauseAuto(ctx, pi).catch(() => {});
1411
- }));
1412
- return;
1413
- }
1414
- if (preDispatchResult.action === "replace") {
1415
- prompt = preDispatchResult.prompt ?? prompt;
1416
- if (preDispatchResult.unitType) unitType = preDispatchResult.unitType;
1417
- } else if (preDispatchResult.prompt) {
1418
- prompt = preDispatchResult.prompt;
1419
- }
1420
-
1421
- const priorSliceBlocker = getPriorSliceCompletionBlocker(s.basePath, getMainBranch(s.basePath), unitType, unitId);
1422
- if (priorSliceBlocker) {
1423
- await stopAuto(ctx, pi, priorSliceBlocker);
1424
- return;
1425
- }
1426
-
1427
- const observabilityIssues = await _collectObservabilityWarnings(ctx, s.basePath, unitType, unitId);
1428
-
1429
- // ── Idempotency check (delegated to auto-idempotency.ts) ──
1430
- const idempotencyResult = checkIdempotency({
1431
- s,
1432
- unitType,
1433
- unitId,
1434
- basePath: s.basePath,
1435
- notify: (msg, level) => ctx.ui.notify(msg, level),
1436
- });
1437
-
1438
- if (idempotencyResult.action === "skip") {
1439
- if (idempotencyResult.reason === "completed" || idempotencyResult.reason === "fallback-persisted" || idempotencyResult.reason === "phantom-loop-cleared" || idempotencyResult.reason === "evicted") {
1440
- if (!s.active) return;
1441
- s.skipDepth++;
1442
- const skipDelay = idempotencyResult.reason === "phantom-loop-cleared" ? 50 : 150;
1443
- // Defer re-dispatch so s.dispatching is released first (#1272).
1444
- setTimeout(() => {
1445
- dispatchNextUnit(ctx, pi).catch(err => {
1446
- ctx.ui.notify(`Deferred skip-dispatch failed: ${err instanceof Error ? err.message : String(err)}`, "error");
1447
- pauseAuto(ctx, pi).catch(() => {});
1448
- }).finally(() => {
1449
- s.skipDepth = Math.max(0, s.skipDepth - 1);
1450
- });
1451
- }, skipDelay);
1452
- return;
1453
- }
1454
- } else if (idempotencyResult.action === "stop") {
1455
- await stopAuto(ctx, pi, idempotencyResult.reason);
1456
- ctx.ui.notify(
1457
- `Hard loop detected: ${unitType} ${unitId} hit lifetime cap during skip cycle.`,
1458
- "error",
1459
- );
1460
- return;
1461
- }
1462
- // "rerun" and "proceed" fall through to stuck detection
1463
-
1464
- // ── Stuck detection (delegated to auto-stuck-detection.ts) ──
1465
- const stuckResult = await checkStuckAndRecover({
1466
- s,
1467
- ctx,
1468
- unitType,
1469
- unitId,
1470
- basePath: s.basePath,
1471
- buildSnapshotOpts: () => buildSnapshotOpts(unitType, unitId),
1472
- });
1473
-
1474
- if (stuckResult.action === "stop") {
1475
- await stopAuto(ctx, pi, stuckResult.reason);
1476
- if (stuckResult.notifyMessage) {
1477
- ctx.ui.notify(stuckResult.notifyMessage, "error");
1478
- }
1479
- return;
1480
- }
1481
- if (stuckResult.action === "recovered" && stuckResult.dispatchAgain) {
1482
- // Defer re-dispatch so s.dispatching is released first (#1272).
1483
- setImmediate(() => dispatchNextUnit(ctx, pi).catch(err => {
1484
- ctx.ui.notify(`Deferred recovery-dispatch failed: ${err instanceof Error ? err.message : String(err)}`, "error");
1485
- pauseAuto(ctx, pi).catch(() => {});
1486
- }));
1487
- return;
1488
- }
1489
-
1490
- // Snapshot metrics + activity log for the PREVIOUS unit before we reassign.
1491
- if (s.currentUnit) {
1492
- await closeoutUnit(ctx, s.basePath, s.currentUnit.type, s.currentUnit.id, s.currentUnit.startedAt, buildSnapshotOpts(s.currentUnit.type, s.currentUnit.id));
1493
-
1494
- if (s.currentUnitRouting) {
1495
- const isRetry = s.currentUnit.type === unitType && s.currentUnit.id === unitId;
1496
- recordOutcome(
1497
- s.currentUnit.type,
1498
- s.currentUnitRouting.tier as "light" | "standard" | "heavy",
1499
- !isRetry,
1500
- );
1501
- }
1502
-
1503
- const closeoutKey = `${s.currentUnit.type}/${s.currentUnit.id}`;
1504
- const incomingKey = `${unitType}/${unitId}`;
1505
- const isHookUnit = s.currentUnit.type.startsWith("hook/");
1506
- const artifactVerified = isHookUnit || verifyExpectedArtifact(s.currentUnit.type, s.currentUnit.id, s.basePath);
1507
- if (closeoutKey !== incomingKey && artifactVerified) {
1508
- if (!isHookUnit) {
1509
- persistCompletedKey(s.basePath, closeoutKey);
1510
- s.completedKeySet.add(closeoutKey);
1511
- }
1512
-
1513
- s.completedUnits.push({
1514
- type: s.currentUnit.type,
1515
- id: s.currentUnit.id,
1516
- startedAt: s.currentUnit.startedAt,
1517
- finishedAt: Date.now(),
1518
- });
1519
- if (s.completedUnits.length > 200) {
1520
- s.completedUnits = s.completedUnits.slice(-200);
1521
- }
1522
- clearUnitRuntimeRecord(s.basePath, s.currentUnit.type, s.currentUnit.id);
1523
- s.unitDispatchCount.delete(`${s.currentUnit.type}/${s.currentUnit.id}`);
1524
- s.unitRecoveryCount.delete(`${s.currentUnit.type}/${s.currentUnit.id}`);
1525
- }
1526
- }
1527
- s.currentUnit = { type: unitType, id: unitId, startedAt: Date.now() };
1528
- captureAvailableSkills();
1529
- writeUnitRuntimeRecord(s.basePath, unitType, unitId, s.currentUnit.startedAt, {
1530
- phase: "dispatched",
1531
- wrapupWarningSent: false,
1532
- timeoutAt: null,
1533
- lastProgressAt: s.currentUnit.startedAt,
1534
- progressCount: 0,
1535
- lastProgressKind: "dispatch",
1536
- });
1537
-
1538
- // Status bar + progress widget
1539
- ctx.ui.setStatus("gsd-auto", "auto");
1540
- if (mid) updateSliceProgressCache(s.basePath, mid, state.activeSlice?.id);
1541
- updateProgressWidget(ctx, unitType, unitId, state);
1542
-
1543
- ensurePreconditions(unitType, unitId, s.basePath, state);
1544
-
1545
- // Fresh session — with timeout to prevent permanent hangs (#1073).
1546
- // If newSession() hangs (e.g., session manager deadlock, network issue),
1547
- // without this timeout the entire dispatch chain stalls permanently: no
1548
- // timeouts are set, no gap watchdog fires, and auto-mode is left active
1549
- // but idle until the user Ctrl+C's.
1550
- let result: { cancelled: boolean };
1551
- try {
1552
- const sessionPromise = s.cmdCtx!.newSession();
1553
- const timeoutPromise = new Promise<{ cancelled: true }>((resolve) =>
1554
- setTimeout(() => resolve({ cancelled: true }), NEW_SESSION_TIMEOUT_MS),
1555
- );
1556
- result = await Promise.race([sessionPromise, timeoutPromise]);
1557
- } catch (sessionErr) {
1558
- const msg = getErrorMessage(sessionErr);
1559
- ctx.ui.notify(`Session creation failed: ${msg}. Retrying via watchdog.`, "error");
1560
- throw new Error(`newSession() failed: ${msg}`);
1561
- }
1562
- if (result.cancelled) {
1563
- ctx.ui.notify(
1564
- `Session creation timed out or was cancelled for ${unitType} ${unitId}. Will retry.`,
1565
- "warning",
1566
- );
1567
- await stopAuto(ctx, pi, "Session creation failed");
1568
- return;
1569
- }
1570
-
1571
- const sessionFile = ctx.sessionManager.getSessionFile();
1572
- updateSessionLock(lockBase(), unitType, unitId, s.completedUnits.length, sessionFile);
1573
- writeLock(lockBase(), unitType, unitId, s.completedUnits.length, sessionFile);
1574
-
1575
- // Prompt injection
1576
- const MAX_RECOVERY_CHARS = 50_000;
1577
- let finalPrompt = prompt;
1578
-
1579
- if (s.pendingVerificationRetry) {
1580
- const retryCtx = s.pendingVerificationRetry;
1581
- s.pendingVerificationRetry = null;
1582
- const capped = retryCtx.failureContext.length > MAX_RECOVERY_CHARS
1583
- ? retryCtx.failureContext.slice(0, MAX_RECOVERY_CHARS) + "\n\n[...failure context truncated]"
1584
- : retryCtx.failureContext;
1585
- finalPrompt = `**VERIFICATION FAILED — AUTO-FIX ATTEMPT ${retryCtx.attempt}**\n\nThe verification gate ran after your previous attempt and found failures. Fix these issues before completing the task.\n\n${capped}\n\n---\n\n${finalPrompt}`;
1586
- }
1587
-
1588
- if (s.pendingCrashRecovery) {
1589
- const capped = s.pendingCrashRecovery.length > MAX_RECOVERY_CHARS
1590
- ? s.pendingCrashRecovery.slice(0, MAX_RECOVERY_CHARS) + "\n\n[...recovery briefing truncated to prevent memory exhaustion]"
1591
- : s.pendingCrashRecovery;
1592
- finalPrompt = `${capped}\n\n---\n\n${finalPrompt}`;
1593
- s.pendingCrashRecovery = null;
1594
- } else if ((s.unitDispatchCount.get(`${unitType}/${unitId}`) ?? 0) > 1) {
1595
- const diagnostic = getDeepDiagnostic(s.basePath);
1596
- if (diagnostic) {
1597
- const cappedDiag = diagnostic.length > MAX_RECOVERY_CHARS
1598
- ? diagnostic.slice(0, MAX_RECOVERY_CHARS) + "\n\n[...diagnostic truncated to prevent memory exhaustion]"
1599
- : diagnostic;
1600
- finalPrompt = `**RETRY — your previous attempt did not produce the required artifact.**\n\nDiagnostic from previous attempt:\n${cappedDiag}\n\nFix whatever went wrong and make sure you write the required file this time.\n\n---\n\n${finalPrompt}`;
1601
- }
1602
- }
1603
-
1604
- const repairBlock = buildObservabilityRepairBlock(observabilityIssues);
1605
- if (repairBlock) {
1606
- finalPrompt = `${finalPrompt}${repairBlock}`;
1607
- }
1608
-
1609
- // ── Prompt char measurement ──
1610
- s.lastPromptCharCount = finalPrompt.length;
1611
- s.lastBaselineCharCount = undefined;
1612
- if (isDbAvailable()) {
1613
- try {
1614
- const { inlineGsdRootFile } = await import("./auto-prompts.js");
1615
- const [decisionsContent, requirementsContent, projectContent] = await Promise.all([
1616
- inlineGsdRootFile(s.basePath, "decisions.md", "Decisions"),
1617
- inlineGsdRootFile(s.basePath, "requirements.md", "Requirements"),
1618
- inlineGsdRootFile(s.basePath, "project.md", "Project"),
1619
- ]);
1620
- s.lastBaselineCharCount =
1621
- (decisionsContent?.length ?? 0) +
1622
- (requirementsContent?.length ?? 0) +
1623
- (projectContent?.length ?? 0);
1624
- } catch {
1625
- // Non-fatal
1626
- }
1627
- }
1628
-
1629
- // Cache-optimize prompt section ordering
1630
- try {
1631
- const { reorderForCaching } = await import("./prompt-ordering.js");
1632
- finalPrompt = reorderForCaching(finalPrompt);
1633
- } catch (reorderErr) {
1634
- const msg = getErrorMessage(reorderErr);
1635
- process.stderr.write(`[gsd] prompt reorder failed (non-fatal): ${msg}\n`);
1636
- }
1637
-
1638
- // Select and apply model
1639
- const modelResult = await selectAndApplyModel(ctx, pi, unitType, unitId, s.basePath, prefs, s.verbose, s.autoModeStartModel);
1640
- s.currentUnitRouting = modelResult.routing;
1641
-
1642
- // ── Start unit supervision (delegated to auto-timers.ts) ──
1643
- clearUnitTimeout();
1644
- startUnitSupervision({
1645
- s,
1646
- ctx,
1647
- pi,
1648
- unitType,
1649
- unitId,
1650
- prefs,
1651
- buildSnapshotOpts: () => buildSnapshotOpts(unitType, unitId),
1652
- buildRecoveryContext: () => buildRecoveryContext(),
1653
- pauseAuto,
1654
- });
1655
-
1656
- // Inject prompt
1657
- if (!s.active) return;
1658
- pi.sendMessage(
1659
- { customType: "gsd-auto", content: finalPrompt, display: s.verbose },
1660
- { triggerTurn: true },
1661
- );
1662
-
1663
- } finally {
1664
- s.dispatching = false;
1665
- }
1666
- }
1667
-
1668
969
  // ─── Preconditions ────────────────────────────────────────────────────────────
1669
970
 
1670
971
  /**
@@ -1672,9 +973,13 @@ async function dispatchNextUnit(
1672
973
  * dispatching a unit. The LLM should never need to mkdir or git checkout.
1673
974
  */
1674
975
  function ensurePreconditions(
1675
- unitType: string, unitId: string, base: string, state: GSDState,
976
+ unitType: string,
977
+ unitId: string,
978
+ base: string,
979
+ state: GSDState,
1676
980
  ): void {
1677
- const { milestone: mid } = parseUnitId(unitId);
981
+ const parts = unitId.split("/");
982
+ const mid = parts[0]!;
1678
983
 
1679
984
  const mDir = resolveMilestonePath(base, mid);
1680
985
  if (!mDir) {
@@ -1682,8 +987,8 @@ function ensurePreconditions(
1682
987
  mkdirSync(join(newDir, "slices"), { recursive: true });
1683
988
  }
1684
989
 
1685
- const sid = parseUnitId(unitId).slice;
1686
- if (sid) {
990
+ if (parts.length >= 2) {
991
+ const sid = parts[1]!;
1687
992
 
1688
993
  const mDirResolved = resolveMilestonePath(base, mid);
1689
994
  if (mDirResolved) {
@@ -1699,16 +1004,17 @@ function ensurePreconditions(
1699
1004
  }
1700
1005
  }
1701
1006
  }
1702
-
1703
1007
  }
1704
1008
 
1705
1009
  // ─── Diagnostics ──────────────────────────────────────────────────────────────
1706
1010
 
1707
1011
  /** Build recovery context from module state for recoverTimedOutUnit */
1708
1012
  function buildRecoveryContext(): import("./auto-timeout-recovery.js").RecoveryContext {
1709
- return { basePath: s.basePath, verbose: s.verbose,
1710
- currentUnitStartedAt: s.currentUnit?.startedAt ?? Date.now(), unitRecoveryCount: s.unitRecoveryCount,
1711
- dispatchNextUnit,
1013
+ return {
1014
+ basePath: s.basePath,
1015
+ verbose: s.verbose,
1016
+ currentUnitStartedAt: s.currentUnit?.startedAt ?? Date.now(),
1017
+ unitRecoveryCount: s.unitRecoveryCount,
1712
1018
  };
1713
1019
  }
1714
1020
 
@@ -1725,17 +1031,6 @@ export {
1725
1031
  * Test-only: expose skip-loop state for unit tests.
1726
1032
  * Not part of the public API.
1727
1033
  */
1728
- export function _getUnitConsecutiveSkips(): Map<string, number> { return s.unitConsecutiveSkips; }
1729
- export function _resetUnitConsecutiveSkips(): void { s.unitConsecutiveSkips.clear(); }
1730
-
1731
- /**
1732
- * Test-only: expose dispatching / skipDepth state for reentrancy guard tests.
1733
- * Not part of the public API.
1734
- */
1735
- export function _getDispatching(): boolean { return s.dispatching; }
1736
- export function _setDispatching(v: boolean): void { s.dispatching = v; }
1737
- export function _getSkipDepth(): number { return s.skipDepth; }
1738
- export function _setSkipDepth(v: number): void { s.skipDepth = v; }
1739
1034
 
1740
1035
  /**
1741
1036
  * Dispatch a hook unit directly, bypassing normal pre-dispatch hooks.
@@ -1765,7 +1060,11 @@ export async function dispatchHookUnit(
1765
1060
  const hookUnitType = `hook/${hookName}`;
1766
1061
  const hookStartedAt = Date.now();
1767
1062
 
1768
- s.currentUnit = { type: triggerUnitType, id: triggerUnitId, startedAt: hookStartedAt };
1063
+ s.currentUnit = {
1064
+ type: triggerUnitType,
1065
+ id: triggerUnitId,
1066
+ startedAt: hookStartedAt,
1067
+ };
1769
1068
 
1770
1069
  const result = await s.cmdCtx!.newSession();
1771
1070
  if (result.cancelled) {
@@ -1773,32 +1072,49 @@ export async function dispatchHookUnit(
1773
1072
  return false;
1774
1073
  }
1775
1074
 
1776
- s.currentUnit = { type: hookUnitType, id: triggerUnitId, startedAt: hookStartedAt };
1075
+ s.currentUnit = {
1076
+ type: hookUnitType,
1077
+ id: triggerUnitId,
1078
+ startedAt: hookStartedAt,
1079
+ };
1777
1080
 
1778
- writeUnitRuntimeRecord(s.basePath, hookUnitType, triggerUnitId, hookStartedAt, {
1779
- phase: "dispatched",
1780
- wrapupWarningSent: false,
1781
- timeoutAt: null,
1782
- lastProgressAt: hookStartedAt,
1783
- progressCount: 0,
1784
- lastProgressKind: "dispatch",
1785
- });
1081
+ writeUnitRuntimeRecord(
1082
+ s.basePath,
1083
+ hookUnitType,
1084
+ triggerUnitId,
1085
+ hookStartedAt,
1086
+ {
1087
+ phase: "dispatched",
1088
+ wrapupWarningSent: false,
1089
+ timeoutAt: null,
1090
+ lastProgressAt: hookStartedAt,
1091
+ progressCount: 0,
1092
+ lastProgressKind: "dispatch",
1093
+ },
1094
+ );
1786
1095
 
1787
1096
  if (hookModel) {
1788
1097
  const availableModels = ctx.modelRegistry.getAvailable();
1789
- const match = availableModels.find(m =>
1790
- m.id === hookModel || `${m.provider}/${m.id}` === hookModel,
1098
+ const match = availableModels.find(
1099
+ (m) => m.id === hookModel || `${m.provider}/${m.id}` === hookModel,
1791
1100
  );
1792
1101
  if (match) {
1793
1102
  try {
1794
1103
  await pi.setModel(match);
1795
- } catch { /* non-fatal */ }
1104
+ } catch {
1105
+ /* non-fatal */
1106
+ }
1796
1107
  }
1797
1108
  }
1798
1109
 
1799
1110
  const sessionFile = ctx.sessionManager.getSessionFile();
1800
- updateSessionLock(lockBase(), hookUnitType, triggerUnitId, s.completedUnits.length, sessionFile);
1801
- writeLock(lockBase(), hookUnitType, triggerUnitId, s.completedUnits.length, sessionFile);
1111
+ writeLock(
1112
+ lockBase(),
1113
+ hookUnitType,
1114
+ triggerUnitId,
1115
+ s.completedUnits.length,
1116
+ sessionFile,
1117
+ );
1802
1118
 
1803
1119
  clearUnitTimeout();
1804
1120
  const supervisor = resolveAutoSupervisorConfig();
@@ -1807,10 +1123,16 @@ export async function dispatchHookUnit(
1807
1123
  s.unitTimeoutHandle = null;
1808
1124
  if (!s.active) return;
1809
1125
  if (s.currentUnit) {
1810
- writeUnitRuntimeRecord(s.basePath, hookUnitType, triggerUnitId, hookStartedAt, {
1811
- phase: "timeout",
1812
- timeoutAt: Date.now(),
1813
- });
1126
+ writeUnitRuntimeRecord(
1127
+ s.basePath,
1128
+ hookUnitType,
1129
+ triggerUnitId,
1130
+ hookStartedAt,
1131
+ {
1132
+ phase: "timeout",
1133
+ timeoutAt: Date.now(),
1134
+ },
1135
+ );
1814
1136
  }
1815
1137
  ctx.ui.notify(
1816
1138
  `Hook ${hookName} exceeded ${supervisor.hard_timeout_minutes ?? 30}min timeout. Pausing auto-mode.`,
@@ -1823,6 +1145,10 @@ export async function dispatchHookUnit(
1823
1145
  ctx.ui.setStatus("gsd-auto", s.stepMode ? "next" : "auto");
1824
1146
  ctx.ui.notify(`Running post-unit hook: ${hookName}`, "info");
1825
1147
 
1148
+ debugLog("dispatchHookUnit", {
1149
+ phase: "send-message",
1150
+ promptLength: hookPrompt.length,
1151
+ });
1826
1152
  pi.sendMessage(
1827
1153
  { customType: "gsd-auto", content: hookPrompt, display: true },
1828
1154
  { triggerTurn: true },
@@ -1831,4 +1157,5 @@ export async function dispatchHookUnit(
1831
1157
  return true;
1832
1158
  }
1833
1159
 
1834
-
1160
+ // Direct phase dispatch → auto-direct-dispatch.ts
1161
+ export { dispatchDirectPhase } from "./auto-direct-dispatch.js";