gsd-pi 2.78.0-dev.aeeb2ca00 → 2.78.1-dev.84a383f51

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 (383) hide show
  1. package/README.md +7 -7
  2. package/dist/claude-cli-check.js +64 -37
  3. package/dist/cli-policy.d.ts +13 -0
  4. package/dist/cli-policy.js +17 -0
  5. package/dist/cli.js +95 -55
  6. package/dist/headless-query.d.ts +22 -0
  7. package/dist/headless-query.js +24 -4
  8. package/dist/headless.d.ts +10 -0
  9. package/dist/headless.js +16 -1
  10. package/dist/loader.js +7 -10
  11. package/dist/onboarding.d.ts +10 -0
  12. package/dist/onboarding.js +2 -2
  13. package/dist/provider-migrations.d.ts +2 -2
  14. package/dist/provider-migrations.js +5 -2
  15. package/dist/resource-loader.d.ts +5 -2
  16. package/dist/resource-loader.js +28 -5
  17. package/dist/resources/.managed-resources-content-hash +1 -0
  18. package/dist/resources/extensions/claude-code-cli/readiness.js +77 -45
  19. package/dist/resources/extensions/gsd/auto/loop.js +23 -0
  20. package/dist/resources/extensions/gsd/auto/phases.js +2 -2
  21. package/dist/resources/extensions/gsd/auto/run-unit.js +3 -1
  22. package/dist/resources/extensions/gsd/auto/session.js +3 -0
  23. package/dist/resources/extensions/gsd/auto-recovery.js +43 -4
  24. package/dist/resources/extensions/gsd/auto-runtime-state.js +31 -0
  25. package/dist/resources/extensions/gsd/auto-start.js +1 -1
  26. package/dist/resources/extensions/gsd/auto-tool-tracking.js +2 -2
  27. package/dist/resources/extensions/gsd/auto-worktree.js +30 -0
  28. package/dist/resources/extensions/gsd/auto.js +14 -5
  29. package/dist/resources/extensions/gsd/bootstrap/db-tools.js +14 -2
  30. package/dist/resources/extensions/gsd/bootstrap/exec-tools.js +7 -5
  31. package/dist/resources/extensions/gsd/bootstrap/query-tools.js +2 -2
  32. package/dist/resources/extensions/gsd/bootstrap/register-extension.js +5 -4
  33. package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +94 -31
  34. package/dist/resources/extensions/gsd/bootstrap/register-shortcuts.js +11 -6
  35. package/dist/resources/extensions/gsd/bootstrap/system-context.js +34 -8
  36. package/dist/resources/extensions/gsd/bootstrap/write-gate.js +38 -2
  37. package/dist/resources/extensions/gsd/commands/catalog.js +69 -5
  38. package/dist/resources/extensions/gsd/commands/handlers/core.js +22 -1
  39. package/dist/resources/extensions/gsd/commands-mcp-status.js +3 -1
  40. package/dist/resources/extensions/gsd/commands-prefs-wizard.js +10 -1
  41. package/dist/resources/extensions/gsd/dashboard-overlay.js +1 -1
  42. package/dist/resources/extensions/gsd/docs/preferences-reference.md +4 -0
  43. package/dist/resources/extensions/gsd/doctor-runtime-checks.js +39 -1
  44. package/dist/resources/extensions/gsd/error-classifier.js +1 -1
  45. package/dist/resources/extensions/gsd/forensics.js +2 -2
  46. package/dist/resources/extensions/gsd/git-service.js +12 -5
  47. package/dist/resources/extensions/gsd/gsd-db.js +11 -2
  48. package/dist/resources/extensions/gsd/guided-flow.js +23 -23
  49. package/dist/resources/extensions/gsd/memory-store.js +66 -31
  50. package/dist/resources/extensions/gsd/milestone-id-reservation.js +36 -0
  51. package/dist/resources/extensions/gsd/model-router.js +114 -9
  52. package/dist/resources/extensions/gsd/native-git-bridge.js +7 -1
  53. package/dist/resources/extensions/gsd/preferences-models.js +91 -15
  54. package/dist/resources/extensions/gsd/preferences-types.js +2 -0
  55. package/dist/resources/extensions/gsd/preferences-validation.js +32 -0
  56. package/dist/resources/extensions/gsd/preferences.js +5 -3
  57. package/dist/resources/extensions/gsd/prompt-loader.js +23 -12
  58. package/dist/resources/extensions/gsd/slice-parallel-orchestrator.js +9 -3
  59. package/dist/resources/extensions/gsd/state.js +42 -0
  60. package/dist/resources/extensions/gsd/templates/PREFERENCES.md +1 -0
  61. package/dist/resources/extensions/gsd/tools/memory-tools.js +18 -1
  62. package/dist/resources/extensions/gsd/visualizer-overlay.js +1 -1
  63. package/dist/resources/extensions/gsd/watch/header-renderer.js +3 -1
  64. package/dist/resources/extensions/gsd/worktree-command.js +26 -46
  65. package/dist/resources/extensions/gsd/worktree-session-state.js +33 -0
  66. package/dist/resources/extensions/mcp-client/index.js +6 -3
  67. package/dist/resources/extensions/slash-commands/create-extension.js +36 -22
  68. package/dist/resources/skills/create-gsd-extension/SKILL.md +9 -5
  69. package/dist/resources/skills/create-gsd-extension/references/custom-commands.md +1 -1
  70. package/dist/resources/skills/create-gsd-extension/references/custom-rendering.md +5 -5
  71. package/dist/resources/skills/create-gsd-extension/references/custom-tools.md +4 -4
  72. package/dist/resources/skills/create-gsd-extension/references/custom-ui.md +6 -6
  73. package/dist/resources/skills/create-gsd-extension/references/events-reference.md +3 -3
  74. package/dist/resources/skills/create-gsd-extension/references/packaging-distribution.md +1 -1
  75. package/dist/resources/skills/create-gsd-extension/references/remote-execution-overrides.md +3 -3
  76. package/dist/resources/skills/create-gsd-extension/workflows/create-extension.md +32 -12
  77. package/dist/rtk-shared.d.ts +3 -0
  78. package/dist/rtk-shared.js +17 -0
  79. package/dist/rtk.d.ts +2 -5
  80. package/dist/rtk.js +3 -20
  81. package/dist/runtime-checks.d.ts +27 -0
  82. package/dist/runtime-checks.js +38 -0
  83. package/dist/tsconfig.extensions.tsbuildinfo +1 -1
  84. package/dist/web/standalone/.next/BUILD_ID +1 -1
  85. package/dist/web/standalone/.next/app-path-routes-manifest.json +12 -12
  86. package/dist/web/standalone/.next/build-manifest.json +3 -3
  87. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  88. package/dist/web/standalone/.next/react-loadable-manifest.json +44 -4
  89. package/dist/web/standalone/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  90. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  91. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  92. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  93. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  94. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  95. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  96. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  97. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  98. package/dist/web/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  99. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  100. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  101. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  102. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  103. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  104. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  105. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  106. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  107. package/dist/web/standalone/.next/server/app/api/boot/route.js +1 -1
  108. package/dist/web/standalone/.next/server/app/api/git/route.js +1 -1
  109. package/dist/web/standalone/.next/server/app/api/session/events/route.js +4 -2
  110. package/dist/web/standalone/.next/server/app/api/shutdown/route.js +1 -1
  111. package/dist/web/standalone/.next/server/app/index.html +1 -1
  112. package/dist/web/standalone/.next/server/app/index.rsc +2 -2
  113. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
  114. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +2 -2
  115. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  116. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  117. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  118. package/dist/web/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
  119. package/dist/web/standalone/.next/server/app-paths-manifest.json +12 -12
  120. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  121. package/dist/web/standalone/.next/server/middleware-manifest.json +5 -5
  122. package/dist/web/standalone/.next/server/middleware-react-loadable-manifest.js +1 -1
  123. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  124. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  125. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  126. package/dist/web/standalone/.next/server/webpack-runtime.js +1 -1
  127. package/dist/web/standalone/.next/static/chunks/2556.0527fea66e123b7f.js +1 -0
  128. package/dist/web/standalone/.next/static/chunks/2824.08296bc2f9654698.js +1 -0
  129. package/dist/web/standalone/.next/static/chunks/3026.3af53b279375f082.js +1 -0
  130. package/dist/web/standalone/.next/static/chunks/315.6f68ae79b67d25cf.js +1 -0
  131. package/dist/web/standalone/.next/static/chunks/3497.4bfc60a3b3dea717.js +1 -0
  132. package/dist/web/standalone/.next/static/chunks/5516.4a07c872b5c3a663.js +1 -0
  133. package/dist/web/standalone/.next/static/chunks/8336.31b019697882acfb.js +10 -0
  134. package/dist/web/standalone/.next/static/chunks/8845.c9702695e8c5a9c5.js +2 -0
  135. package/dist/web/standalone/.next/static/chunks/9058.01ef3a463bda88f1.js +20 -0
  136. package/dist/web/standalone/.next/static/chunks/9441.1081da1125d1764f.js +1 -0
  137. package/dist/web/standalone/.next/static/chunks/app/{page-5b113fd32bc2a1c3.js → page-9bf2e0c50fb2ca05.js} +1 -1
  138. package/dist/web/standalone/.next/static/chunks/webpack-f9f0dc45e4f3ac10.js +1 -0
  139. package/dist/web/standalone/package.json +2 -1
  140. package/dist/worktree-status-banner.d.ts +1 -0
  141. package/dist/worktree-status-banner.js +132 -0
  142. package/package.json +1 -1
  143. package/packages/daemon/package.json +2 -2
  144. package/packages/mcp-server/dist/alias-telemetry.d.ts +8 -0
  145. package/packages/mcp-server/dist/alias-telemetry.d.ts.map +1 -0
  146. package/packages/mcp-server/dist/alias-telemetry.js +30 -0
  147. package/packages/mcp-server/dist/alias-telemetry.js.map +1 -0
  148. package/packages/mcp-server/dist/workflow-tools.d.ts.map +1 -1
  149. package/packages/mcp-server/dist/workflow-tools.js +74 -46
  150. package/packages/mcp-server/dist/workflow-tools.js.map +1 -1
  151. package/packages/mcp-server/package.json +2 -2
  152. package/packages/mcp-server/src/alias-telemetry.test.ts +78 -0
  153. package/packages/mcp-server/src/alias-telemetry.ts +30 -0
  154. package/packages/mcp-server/src/workflow-tools.test.ts +26 -0
  155. package/packages/mcp-server/src/workflow-tools.ts +93 -58
  156. package/packages/mcp-server/tsconfig.tsbuildinfo +1 -1
  157. package/packages/native/package.json +1 -1
  158. package/packages/pi-agent-core/package.json +1 -1
  159. package/packages/pi-agent-core/tsconfig.tsbuildinfo +1 -1
  160. package/packages/pi-ai/dist/providers/anthropic-shared.cache-breakpoint.test.d.ts +2 -0
  161. package/packages/pi-ai/dist/providers/anthropic-shared.cache-breakpoint.test.d.ts.map +1 -0
  162. package/packages/pi-ai/dist/providers/anthropic-shared.cache-breakpoint.test.js +231 -0
  163. package/packages/pi-ai/dist/providers/anthropic-shared.cache-breakpoint.test.js.map +1 -0
  164. package/packages/pi-ai/dist/providers/anthropic-shared.d.ts.map +1 -1
  165. package/packages/pi-ai/dist/providers/anthropic-shared.js +48 -19
  166. package/packages/pi-ai/dist/providers/anthropic-shared.js.map +1 -1
  167. package/packages/pi-ai/dist/types.d.ts +13 -0
  168. package/packages/pi-ai/dist/types.d.ts.map +1 -1
  169. package/packages/pi-ai/dist/types.js.map +1 -1
  170. package/packages/pi-ai/dist/utils/repair-tool-json.d.ts.map +1 -1
  171. package/packages/pi-ai/dist/utils/repair-tool-json.js +24 -3
  172. package/packages/pi-ai/dist/utils/repair-tool-json.js.map +1 -1
  173. package/packages/pi-ai/dist/utils/tests/repair-tool-json.test.js +26 -0
  174. package/packages/pi-ai/dist/utils/tests/repair-tool-json.test.js.map +1 -1
  175. package/packages/pi-ai/package.json +1 -1
  176. package/packages/pi-ai/src/providers/anthropic-shared.cache-breakpoint.test.ts +289 -0
  177. package/packages/pi-ai/src/providers/anthropic-shared.ts +52 -20
  178. package/packages/pi-ai/src/types.ts +13 -0
  179. package/packages/pi-ai/src/utils/repair-tool-json.ts +24 -3
  180. package/packages/pi-ai/src/utils/tests/repair-tool-json.test.ts +32 -0
  181. package/packages/pi-ai/tsconfig.tsbuildinfo +1 -1
  182. package/packages/pi-coding-agent/dist/core/agent-session.d.ts.map +1 -1
  183. package/packages/pi-coding-agent/dist/core/agent-session.js +6 -0
  184. package/packages/pi-coding-agent/dist/core/agent-session.js.map +1 -1
  185. package/packages/pi-coding-agent/dist/core/messages.d.ts.map +1 -1
  186. package/packages/pi-coding-agent/dist/core/messages.js +4 -0
  187. package/packages/pi-coding-agent/dist/core/messages.js.map +1 -1
  188. package/packages/pi-coding-agent/dist/core/model-registry-auth-mode.test.js +19 -2
  189. package/packages/pi-coding-agent/dist/core/model-registry-auth-mode.test.js.map +1 -1
  190. package/packages/pi-coding-agent/dist/core/model-registry.d.ts +10 -0
  191. package/packages/pi-coding-agent/dist/core/model-registry.d.ts.map +1 -1
  192. package/packages/pi-coding-agent/dist/core/model-registry.js +18 -0
  193. package/packages/pi-coding-agent/dist/core/model-registry.js.map +1 -1
  194. package/packages/pi-coding-agent/dist/core/system-prompt.d.ts +13 -0
  195. package/packages/pi-coding-agent/dist/core/system-prompt.d.ts.map +1 -1
  196. package/packages/pi-coding-agent/dist/core/system-prompt.js +20 -16
  197. package/packages/pi-coding-agent/dist/core/system-prompt.js.map +1 -1
  198. package/packages/pi-coding-agent/dist/core/token-telemetry.d.ts +37 -0
  199. package/packages/pi-coding-agent/dist/core/token-telemetry.d.ts.map +1 -0
  200. package/packages/pi-coding-agent/dist/core/token-telemetry.js +49 -0
  201. package/packages/pi-coding-agent/dist/core/token-telemetry.js.map +1 -0
  202. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-card-cleanup-and-success-runtime.test.d.ts +2 -0
  203. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-card-cleanup-and-success-runtime.test.d.ts.map +1 -0
  204. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-card-cleanup-and-success-runtime.test.js +133 -0
  205. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-card-cleanup-and-success-runtime.test.js.map +1 -0
  206. package/packages/pi-coding-agent/dist/modes/interactive/controllers/input-controller.js +1 -1
  207. package/packages/pi-coding-agent/dist/modes/interactive/controllers/input-controller.js.map +1 -1
  208. package/packages/pi-coding-agent/dist/modes/interactive/controllers/input-controller.test.js +14 -1
  209. package/packages/pi-coding-agent/dist/modes/interactive/controllers/input-controller.test.js.map +1 -1
  210. package/packages/pi-coding-agent/dist/tests/system-prompt-cache-stability.test.d.ts +2 -0
  211. package/packages/pi-coding-agent/dist/tests/system-prompt-cache-stability.test.d.ts.map +1 -0
  212. package/packages/pi-coding-agent/dist/tests/system-prompt-cache-stability.test.js +78 -0
  213. package/packages/pi-coding-agent/dist/tests/system-prompt-cache-stability.test.js.map +1 -0
  214. package/packages/pi-coding-agent/dist/tests/token-telemetry.test.d.ts +2 -0
  215. package/packages/pi-coding-agent/dist/tests/token-telemetry.test.d.ts.map +1 -0
  216. package/packages/pi-coding-agent/dist/tests/token-telemetry.test.js +181 -0
  217. package/packages/pi-coding-agent/dist/tests/token-telemetry.test.js.map +1 -0
  218. package/packages/pi-coding-agent/package.json +1 -1
  219. package/packages/pi-coding-agent/src/core/agent-session.ts +7 -0
  220. package/packages/pi-coding-agent/src/core/messages.ts +4 -0
  221. package/packages/pi-coding-agent/src/core/model-registry-auth-mode.test.ts +32 -2
  222. package/packages/pi-coding-agent/src/core/model-registry.ts +21 -0
  223. package/packages/pi-coding-agent/src/core/system-prompt.ts +33 -15
  224. package/packages/pi-coding-agent/src/core/token-telemetry.ts +77 -0
  225. package/packages/pi-coding-agent/src/modes/interactive/components/tool-card-cleanup-and-success-runtime.test.ts +212 -0
  226. package/packages/pi-coding-agent/src/modes/interactive/controllers/input-controller.test.ts +17 -1
  227. package/packages/pi-coding-agent/src/modes/interactive/controllers/input-controller.ts +1 -1
  228. package/packages/pi-coding-agent/src/tests/system-prompt-cache-stability.test.ts +102 -0
  229. package/packages/pi-coding-agent/src/tests/token-telemetry.test.ts +200 -0
  230. package/packages/pi-coding-agent/tsconfig.tsbuildinfo +1 -1
  231. package/packages/pi-tui/dist/__tests__/autocomplete.test.js +17 -3
  232. package/packages/pi-tui/dist/__tests__/autocomplete.test.js.map +1 -1
  233. package/packages/pi-tui/dist/components/__tests__/leak-fixes-runtime.test.d.ts +2 -0
  234. package/packages/pi-tui/dist/components/__tests__/leak-fixes-runtime.test.d.ts.map +1 -0
  235. package/packages/pi-tui/dist/components/__tests__/leak-fixes-runtime.test.js +161 -0
  236. package/packages/pi-tui/dist/components/__tests__/leak-fixes-runtime.test.js.map +1 -0
  237. package/packages/pi-tui/package.json +1 -1
  238. package/packages/pi-tui/src/__tests__/autocomplete.test.ts +20 -3
  239. package/packages/pi-tui/src/components/__tests__/leak-fixes-runtime.test.ts +219 -0
  240. package/packages/pi-tui/tsconfig.tsbuildinfo +1 -1
  241. package/packages/rpc-client/package.json +1 -1
  242. package/pkg/package.json +1 -1
  243. package/src/resources/extensions/claude-code-cli/readiness.ts +78 -46
  244. package/src/resources/extensions/gsd/auto/loop.ts +24 -2
  245. package/src/resources/extensions/gsd/auto/phases.ts +3 -3
  246. package/src/resources/extensions/gsd/auto/run-unit.ts +3 -1
  247. package/src/resources/extensions/gsd/auto/session.ts +3 -0
  248. package/src/resources/extensions/gsd/auto/types.ts +1 -0
  249. package/src/resources/extensions/gsd/auto-recovery.ts +46 -8
  250. package/src/resources/extensions/gsd/auto-runtime-state.ts +51 -0
  251. package/src/resources/extensions/gsd/auto-start.ts +1 -1
  252. package/src/resources/extensions/gsd/auto-tool-tracking.ts +2 -4
  253. package/src/resources/extensions/gsd/auto-worktree.ts +38 -0
  254. package/src/resources/extensions/gsd/auto.ts +14 -4
  255. package/src/resources/extensions/gsd/bootstrap/db-tools.ts +15 -13
  256. package/src/resources/extensions/gsd/bootstrap/exec-tools.ts +8 -7
  257. package/src/resources/extensions/gsd/bootstrap/query-tools.ts +2 -2
  258. package/src/resources/extensions/gsd/bootstrap/register-extension.ts +10 -9
  259. package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +102 -31
  260. package/src/resources/extensions/gsd/bootstrap/register-shortcuts.ts +12 -6
  261. package/src/resources/extensions/gsd/bootstrap/system-context.ts +39 -8
  262. package/src/resources/extensions/gsd/bootstrap/write-gate.ts +39 -11
  263. package/src/resources/extensions/gsd/commands/catalog.ts +75 -5
  264. package/src/resources/extensions/gsd/commands/handlers/core.ts +22 -1
  265. package/src/resources/extensions/gsd/commands-mcp-status.ts +3 -1
  266. package/src/resources/extensions/gsd/commands-prefs-wizard.ts +15 -1
  267. package/src/resources/extensions/gsd/dashboard-overlay.ts +1 -1
  268. package/src/resources/extensions/gsd/docs/preferences-reference.md +4 -0
  269. package/src/resources/extensions/gsd/doctor-runtime-checks.ts +39 -1
  270. package/src/resources/extensions/gsd/doctor-types.ts +3 -1
  271. package/src/resources/extensions/gsd/error-classifier.ts +1 -1
  272. package/src/resources/extensions/gsd/forensics.ts +2 -2
  273. package/src/resources/extensions/gsd/git-service.ts +13 -5
  274. package/src/resources/extensions/gsd/gsd-db.ts +12 -2
  275. package/src/resources/extensions/gsd/guided-flow.ts +25 -25
  276. package/src/resources/extensions/gsd/memory-store.ts +81 -28
  277. package/src/resources/extensions/gsd/milestone-id-reservation.ts +47 -0
  278. package/src/resources/extensions/gsd/model-router.ts +172 -9
  279. package/src/resources/extensions/gsd/native-git-bridge.ts +7 -1
  280. package/src/resources/extensions/gsd/preferences-models.ts +101 -15
  281. package/src/resources/extensions/gsd/preferences-types.ts +6 -0
  282. package/src/resources/extensions/gsd/preferences-validation.ts +35 -0
  283. package/src/resources/extensions/gsd/preferences.ts +16 -2
  284. package/src/resources/extensions/gsd/prompt-loader.ts +26 -12
  285. package/src/resources/extensions/gsd/slice-parallel-orchestrator.ts +9 -3
  286. package/src/resources/extensions/gsd/state.ts +42 -0
  287. package/src/resources/extensions/gsd/templates/PREFERENCES.md +1 -0
  288. package/src/resources/extensions/gsd/tests/auto-loop.test.ts +178 -1
  289. package/src/resources/extensions/gsd/tests/auto-recovery.test.ts +58 -0
  290. package/src/resources/extensions/gsd/tests/auto-session-encapsulation.test.ts +9 -5
  291. package/src/resources/extensions/gsd/tests/auto-supervisor.test.mjs +21 -4
  292. package/src/resources/extensions/gsd/tests/bootstrap-derive-state-db-open.test.ts +1 -1
  293. package/src/resources/extensions/gsd/tests/budget-prediction.test.ts +138 -211
  294. package/src/resources/extensions/gsd/tests/complete-slice-verification-gate.test.ts +142 -59
  295. package/src/resources/extensions/gsd/tests/complete-slice.test.ts +7 -4
  296. package/src/resources/extensions/gsd/tests/completed-at-reconcile.test.ts +89 -32
  297. package/src/resources/extensions/gsd/tests/custom-engine-loop-integration.test.ts +41 -23
  298. package/src/resources/extensions/gsd/tests/db-path-worktree-symlink.test.ts +3 -43
  299. package/src/resources/extensions/gsd/tests/debug-logger.test.ts +5 -3
  300. package/src/resources/extensions/gsd/tests/deferred-milestone-dir-4996.test.ts +116 -0
  301. package/src/resources/extensions/gsd/tests/discuss-empty-db-fallback.test.ts +22 -87
  302. package/src/resources/extensions/gsd/tests/discuss-queued-milestones.test.ts +7 -118
  303. package/src/resources/extensions/gsd/tests/discuss-tool-scope-leak.test.ts +18 -60
  304. package/src/resources/extensions/gsd/tests/doctor-orphan-milestone-4996.test.ts +100 -0
  305. package/src/resources/extensions/gsd/tests/double-merge-guard.test.ts +14 -76
  306. package/src/resources/extensions/gsd/tests/ensure-preconditions-guard-4996.test.ts +93 -0
  307. package/src/resources/extensions/gsd/tests/false-degraded-mode-warning.test.ts +22 -83
  308. package/src/resources/extensions/gsd/tests/finalize-timeout-guard.test.ts +1 -63
  309. package/src/resources/extensions/gsd/tests/find-missing-summaries-closed-runtime.test.ts +47 -0
  310. package/src/resources/extensions/gsd/tests/forensics-stuck-loops.test.ts +26 -1
  311. package/src/resources/extensions/gsd/tests/gitignore-bg-shell-runtime.test.ts +63 -0
  312. package/src/resources/extensions/gsd/tests/gsd-db.test.ts +30 -0
  313. package/src/resources/extensions/gsd/tests/gsd-no-project-error-runtime.test.ts +81 -0
  314. package/src/resources/extensions/gsd/tests/headless-answers.test.ts +14 -4
  315. package/src/resources/extensions/gsd/tests/health-widget.test.ts +22 -12
  316. package/src/resources/extensions/gsd/tests/help-menu-coverage.test.ts +57 -0
  317. package/src/resources/extensions/gsd/tests/import-done-milestones-runtime.test.ts +145 -0
  318. package/src/resources/extensions/gsd/tests/init-prefs-routing.test.ts +64 -1
  319. package/src/resources/extensions/gsd/tests/integration/auto-worktree.test.ts +22 -0
  320. package/src/resources/extensions/gsd/tests/integration/token-savings.test.ts +0 -23
  321. package/src/resources/extensions/gsd/tests/memory-store.test.ts +128 -0
  322. package/src/resources/extensions/gsd/tests/memory-tools.test.ts +33 -1
  323. package/src/resources/extensions/gsd/tests/merge-self-branch-guard.test.ts +124 -0
  324. package/src/resources/extensions/gsd/tests/milestone-id-gap-reuse-4996.test.ts +152 -0
  325. package/src/resources/extensions/gsd/tests/model-router.test.ts +169 -8
  326. package/src/resources/extensions/gsd/tests/native-git-infra-errors.test.ts +50 -0
  327. package/src/resources/extensions/gsd/tests/orphaned-worktree-audit.test.ts +8 -0
  328. package/src/resources/extensions/gsd/tests/parallel-crash-recovery.test.ts +32 -43
  329. package/src/resources/extensions/gsd/tests/phases-merge-error-stops-auto.test.ts +4 -10
  330. package/src/resources/extensions/gsd/tests/preferences.test.ts +127 -0
  331. package/src/resources/extensions/gsd/tests/prompt-step-ordering.test.ts +16 -0
  332. package/src/resources/extensions/gsd/tests/provider-errors.test.ts +7 -0
  333. package/src/resources/extensions/gsd/tests/quick-turn-end-cleanup.test.ts +6 -6
  334. package/src/resources/extensions/gsd/tests/register-hooks-compaction-checkpoint.test.ts +93 -0
  335. package/src/resources/extensions/gsd/tests/session-start-footer.test.ts +168 -19
  336. package/src/resources/extensions/gsd/tests/slice-parallel-orchestrator.test.ts +7 -1
  337. package/src/resources/extensions/gsd/tests/smart-entry-complete.test.ts +23 -1
  338. package/src/resources/extensions/gsd/tests/system-context-message-routing.test.ts +101 -0
  339. package/src/resources/extensions/gsd/tests/token-profile.test.ts +51 -4
  340. package/src/resources/extensions/gsd/tests/turn-epoch.test.ts +7 -16
  341. package/src/resources/extensions/gsd/tests/unstructured-continue-context-injection.test.ts +5 -7
  342. package/src/resources/extensions/gsd/tests/uok-gitops-turn-action.test.ts +15 -1
  343. package/src/resources/extensions/gsd/tests/visualizer-overlay.test.ts +6 -6
  344. package/src/resources/extensions/gsd/tests/write-gate-planning-unit.test.ts +15 -0
  345. package/src/resources/extensions/gsd/tools/memory-tools.ts +17 -1
  346. package/src/resources/extensions/gsd/unit-context-manifest.ts +8 -8
  347. package/src/resources/extensions/gsd/visualizer-overlay.ts +1 -1
  348. package/src/resources/extensions/gsd/watch/header-renderer.ts +3 -1
  349. package/src/resources/extensions/gsd/workflow-logger.ts +1 -0
  350. package/src/resources/extensions/gsd/worktree-command.ts +31 -44
  351. package/src/resources/extensions/gsd/worktree-session-state.ts +35 -0
  352. package/src/resources/extensions/mcp-client/index.ts +6 -3
  353. package/src/resources/extensions/mcp-client/tests/global-config.test.ts +91 -0
  354. package/src/resources/extensions/slash-commands/create-extension.ts +38 -24
  355. package/src/resources/skills/create-gsd-extension/SKILL.md +9 -5
  356. package/src/resources/skills/create-gsd-extension/references/custom-commands.md +1 -1
  357. package/src/resources/skills/create-gsd-extension/references/custom-rendering.md +5 -5
  358. package/src/resources/skills/create-gsd-extension/references/custom-tools.md +4 -4
  359. package/src/resources/skills/create-gsd-extension/references/custom-ui.md +6 -6
  360. package/src/resources/skills/create-gsd-extension/references/events-reference.md +3 -3
  361. package/src/resources/skills/create-gsd-extension/references/packaging-distribution.md +1 -1
  362. package/src/resources/skills/create-gsd-extension/references/remote-execution-overrides.md +3 -3
  363. package/src/resources/skills/create-gsd-extension/templates/extension-skeleton.ts +2 -2
  364. package/src/resources/skills/create-gsd-extension/templates/stateful-tool-skeleton.ts +3 -3
  365. package/src/resources/skills/create-gsd-extension/templates/templates.test.ts +58 -0
  366. package/src/resources/skills/create-gsd-extension/workflows/create-extension.md +32 -12
  367. package/dist/resources/extensions/browser-tools/tests/browser-tools-integration.test.mjs +0 -601
  368. package/dist/resources/extensions/browser-tools/tests/browser-tools-unit.test.cjs +0 -651
  369. package/dist/resources/extensions/browser-tools/tests/capture-sharp-optional.test.cjs +0 -91
  370. package/dist/resources/extensions/gsd/tests/auto-supervisor.test.mjs +0 -53
  371. package/dist/resources/extensions/gsd/tests/dist-redirect.mjs +0 -112
  372. package/dist/resources/extensions/gsd/tests/resolve-ts-hooks.mjs +0 -23
  373. package/dist/resources/extensions/gsd/tests/resolve-ts.mjs +0 -5
  374. package/dist/resources/skills/github-workflows/references/gh/tests/__init__.py +0 -0
  375. package/dist/resources/skills/github-workflows/references/gh/tests/test_github_project_setup.py +0 -608
  376. package/dist/web/standalone/.next/static/chunks/2826.e9f5195e91f9cad2.js +0 -11
  377. package/dist/web/standalone/.next/static/chunks/3621.fc7480022c972438.js +0 -20
  378. package/dist/web/standalone/.next/static/chunks/webpack-2e68521d7c82f7c2.js +0 -1
  379. package/src/resources/extensions/gsd/tests/copy-planning-artifacts-samepath.test.ts +0 -22
  380. package/src/resources/extensions/gsd/tests/discuss-slice-structured-questions.test.ts +0 -47
  381. package/src/resources/extensions/gsd/tests/empty-content-abort-loop.test.ts +0 -75
  382. /package/dist/web/standalone/.next/static/{cAJH99yNS1UPbeSEiNRrV → UF5VF4F1tB0miEtJS7LyX}/_buildManifest.js +0 -0
  383. /package/dist/web/standalone/.next/static/{cAJH99yNS1UPbeSEiNRrV → UF5VF4F1tB0miEtJS7LyX}/_ssgManifest.js +0 -0
package/README.md CHANGED
@@ -625,19 +625,19 @@ Start GSD with `gsd --debug` to enable structured JSONL diagnostic logging. Debu
625
625
 
626
626
  ### Token Optimization
627
627
 
628
- GSD includes a coordinated token optimization system that reduces usage by 40-60% on cost-sensitive workloads. Set a single preference to coordinate model selection, phase skipping, and context compression:
628
+ GSD includes a coordinated token optimization system that reduces usage by 40-60% on cost-sensitive workloads. Set a single preference to coordinate model tier selection, phase skipping, and context compression:
629
629
 
630
630
  ```yaml
631
631
  token_profile: budget # or balanced (default), quality
632
632
  ```
633
633
 
634
- | Profile | Savings | What It Does |
635
- | ---------- | ------- | -------------------------------------------------------------- |
636
- | `budget` | 40-60% | Cheap models, skip research/reassess, minimal context inlining |
637
- | `balanced` | 10-20% | Default models, skip slice research, standard context |
638
- | `quality` | 0% | All phases, all context, full model power |
634
+ | Profile | Savings | What It Does |
635
+ | ---------- | ------- | -------------------------------------------------------------------------------- |
636
+ | `budget` | 40-60% | Light/standard tier defaults, skip research/reassess, minimal context inlining |
637
+ | `balanced` | 10-20% | Standard tier for core work, light tier for simple work, standard context |
638
+ | `quality` | 0% | Heavy tier for planning, standard tier for core work, full context |
639
639
 
640
- **Complexity-based routing** automatically classifies tasks as simple/standard/complex and routes to appropriate models. Simple docs tasks get Haiku; complex architectural work gets Opus. The classification is heuristic (sub-millisecond, no LLM calls) and learns from outcomes via a persistent routing history.
640
+ **Complexity-based routing** automatically classifies tasks as simple/standard/complex and routes to appropriate available models. Token profiles define provider-agnostic tier intentions, so simple docs tasks use a light-tier configured model and complex architectural work can use a heavy-tier configured model. The classification is heuristic (sub-millisecond, no LLM calls) and learns from outcomes via a persistent routing history.
641
641
 
642
642
  **Budget pressure** graduates model downgrading as you approach your budget ceiling — 50%, 75%, and 90% thresholds progressively shift work to cheaper tiers.
643
643
 
@@ -1,6 +1,9 @@
1
1
  // GSD2 — Claude CLI binary detection for onboarding
2
2
  // Lightweight check used at onboarding time (before extensions load).
3
3
  // The full readiness check with caching lives in the claude-code-cli extension.
4
+ //
5
+ // Set GSD_CLAUDE_DEBUG=1 to log probe output to stderr. Useful when
6
+ // diagnosing platform-specific detection failures (Issue #4997).
4
7
  import { execFileSync } from 'node:child_process';
5
8
  /**
6
9
  * Platform-correct binary name for the Claude Code CLI.
@@ -20,38 +23,41 @@ export const CLAUDE_COMMAND = process.platform === 'win32' ? 'claude.cmd' : 'cla
20
23
  * expose a bare `claude` shim. Try all three so no valid install is missed.
21
24
  */
22
25
  const CLAUDE_COMMAND_CANDIDATES = process.platform === 'win32' ? [CLAUDE_COMMAND, 'claude.exe', 'claude'] : [CLAUDE_COMMAND];
23
- // Codes treated as "this candidate didn't run — try the next one" rather than
24
- // fatal failures. ETIMEDOUT/EAGAIN cover slow-spawn cases on Windows where
25
- // cmd.exe wrapping plus the Claude CLI startup path together exceed the
26
- // per-attempt timeout (Issue #4997 regression on Windows + Node 25).
27
- const SOFT_FAIL_CODES = new Set(['ENOENT', 'EINVAL', 'ETIMEDOUT', 'EAGAIN']);
28
26
  const VERSION_TIMEOUT_MS = 5_000;
29
27
  // Auth probe needs more headroom on Windows because the spawn goes through
30
28
  // cmd.exe → claude.cmd → node → Claude CLI.
31
29
  const AUTH_TIMEOUT_MS = 15_000;
30
+ function debugLog(...parts) {
31
+ if (process.env.GSD_CLAUDE_DEBUG) {
32
+ process.stderr.write(`[claude-cli-check] ${parts.map(p => (typeof p === 'string' ? p : JSON.stringify(p))).join(' ')}\n`);
33
+ }
34
+ }
32
35
  /**
33
- * Try to run `args` against each candidate binary.
34
- * Returns the output buffer on first success, throws the last error if all fail.
36
+ * Find the first candidate that responds to `--version`. Returns the
37
+ * candidate name on success, null if none worked.
38
+ *
39
+ * On Windows with `shell: true`, a missing candidate surfaces as a
40
+ * non-zero exit from cmd.exe rather than ENOENT — so we cannot rely on
41
+ * the error code to decide "try next". Treat any failure as "try next"
42
+ * for the version probe.
35
43
  */
36
- function execClaudeCheck(args, timeoutMs) {
37
- let lastError;
44
+ function findWorkingCommand() {
38
45
  for (const command of CLAUDE_COMMAND_CANDIDATES) {
39
46
  try {
40
- return execFileSync(command, args, {
41
- timeout: timeoutMs,
47
+ execFileSync(command, ['--version'], {
48
+ timeout: VERSION_TIMEOUT_MS,
42
49
  stdio: 'pipe',
43
50
  shell: process.platform === 'win32',
44
51
  });
52
+ debugLog('version probe ok via', command);
53
+ return command;
45
54
  }
46
55
  catch (error) {
47
- lastError = error;
48
- const code = error?.code;
49
- if (code && SOFT_FAIL_CODES.has(code))
50
- continue;
51
- throw error;
56
+ debugLog('version probe failed for', command, 'code=', error?.code);
57
+ continue;
52
58
  }
53
59
  }
54
- throw lastError ?? new Error(`Claude CLI not found (tried: ${CLAUDE_COMMAND_CANDIDATES.join(', ')})`);
60
+ return null;
55
61
  }
56
62
  /**
57
63
  * Decide auth state from `claude auth status` output.
@@ -62,6 +68,8 @@ function execClaudeCheck(args, timeoutMs) {
62
68
  */
63
69
  function parseAuthStatus(output) {
64
70
  const trimmed = output.trim();
71
+ if (!trimmed)
72
+ return null;
65
73
  if (trimmed.startsWith('{')) {
66
74
  try {
67
75
  const parsed = JSON.parse(trimmed);
@@ -77,35 +85,54 @@ function parseAuthStatus(output) {
77
85
  if (/not logged in|no credentials|unauthenticated|not authenticated/.test(lower)) {
78
86
  return false;
79
87
  }
80
- return true;
88
+ if (/logged in|authenticated|signed in|email|subscription/.test(lower)) {
89
+ return true;
90
+ }
91
+ return null;
92
+ }
93
+ function probeAuth(command) {
94
+ // Try --json first (newer CLIs).
95
+ try {
96
+ const out = execFileSync(command, ['auth', 'status', '--json'], {
97
+ timeout: AUTH_TIMEOUT_MS,
98
+ stdio: 'pipe',
99
+ shell: process.platform === 'win32',
100
+ }).toString();
101
+ debugLog('auth status --json output:', out.slice(0, 200));
102
+ const parsed = parseAuthStatus(out);
103
+ if (parsed !== null)
104
+ return parsed;
105
+ }
106
+ catch (error) {
107
+ debugLog('auth status --json threw:', error.message?.slice(0, 200));
108
+ }
109
+ // Fallback: plain `auth status` (older CLIs that don't accept --json).
110
+ try {
111
+ const out = execFileSync(command, ['auth', 'status'], {
112
+ timeout: AUTH_TIMEOUT_MS,
113
+ stdio: 'pipe',
114
+ shell: process.platform === 'win32',
115
+ }).toString();
116
+ debugLog('auth status output:', out.slice(0, 200));
117
+ return parseAuthStatus(out);
118
+ }
119
+ catch (error) {
120
+ debugLog('auth status threw:', error.message?.slice(0, 200));
121
+ return null;
122
+ }
81
123
  }
82
124
  /**
83
125
  * Check if the `claude` binary is installed (regardless of auth state).
84
126
  */
85
127
  export function isClaudeBinaryInstalled() {
86
- try {
87
- execClaudeCheck(['--version'], VERSION_TIMEOUT_MS);
88
- return true;
89
- }
90
- catch {
91
- return false;
92
- }
128
+ return findWorkingCommand() !== null;
93
129
  }
94
130
  /**
95
131
  * Check if the `claude` CLI is installed AND authenticated.
96
132
  */
97
133
  export function isClaudeCliReady() {
98
- try {
99
- execClaudeCheck(['--version'], VERSION_TIMEOUT_MS);
100
- }
101
- catch {
102
- return false;
103
- }
104
- try {
105
- const output = execClaudeCheck(['auth', 'status', '--json'], AUTH_TIMEOUT_MS).toString();
106
- return parseAuthStatus(output);
107
- }
108
- catch {
134
+ const command = findWorkingCommand();
135
+ if (!command)
109
136
  return false;
110
- }
137
+ return probeAuth(command) === true;
111
138
  }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Subcommands that must bypass the managed-resource-mismatch gate.
3
+ *
4
+ * When the synced resource manifest claims a newer gsd version than the
5
+ * running binary, exitIfManagedResourcesAreNewer() blocks every command
6
+ * with a "Version mismatch detected" diagnostic. The `update` subcommand
7
+ * MUST bypass that gate so the user can recover by upgrading the binary —
8
+ * otherwise they're stuck in a broken state with no escape hatch.
9
+ *
10
+ * Any new bypassed subcommand goes here. cli.ts dispatches on this
11
+ * predicate before calling exitIfManagedResourcesAreNewer().
12
+ */
13
+ export declare function shouldBypassManagedResourceMismatchGate(firstMessage: string | undefined): boolean;
@@ -0,0 +1,17 @@
1
+ // Policy helpers for cli.ts — extracted as pure functions so they can be
2
+ // unit-tested without executing cli.ts's top-level script body.
3
+ /**
4
+ * Subcommands that must bypass the managed-resource-mismatch gate.
5
+ *
6
+ * When the synced resource manifest claims a newer gsd version than the
7
+ * running binary, exitIfManagedResourcesAreNewer() blocks every command
8
+ * with a "Version mismatch detected" diagnostic. The `update` subcommand
9
+ * MUST bypass that gate so the user can recover by upgrading the binary —
10
+ * otherwise they're stuck in a broken state with no escape hatch.
11
+ *
12
+ * Any new bypassed subcommand goes here. cli.ts dispatches on this
13
+ * predicate before calling exitIfManagedResourcesAreNewer().
14
+ */
15
+ export function shouldBypassManagedResourceMismatchGate(firstMessage) {
16
+ return firstMessage === 'update';
17
+ }
package/dist/cli.js CHANGED
@@ -1,4 +1,3 @@
1
- import { AuthStorage, DefaultResourceLoader, ModelRegistry, runPackageCommand, SettingsManager, SessionManager, createAgentSession, InteractiveMode, runPrintMode, runRpcMode, } from '@gsd/pi-coding-agent';
2
1
  import { readFileSync } from 'node:fs';
3
2
  import { join } from 'node:path';
4
3
  import { agentDir, sessionsDir, authFilePath } from './app-paths.js';
@@ -9,6 +8,7 @@ import { migratePiCredentials } from './pi-migration.js';
9
8
  import { shouldRunOnboarding, runOnboarding } from './onboarding.js';
10
9
  import chalk from 'chalk';
11
10
  import { checkForUpdates } from './update-check.js';
11
+ import { shouldBypassManagedResourceMismatchGate } from './cli-policy.js';
12
12
  import { printHelp, printSubcommandHelp } from './help-text.js';
13
13
  import { applySecurityOverrides } from './security-overrides.js';
14
14
  import { validateConfiguredModel } from './startup-model-validation.js';
@@ -17,8 +17,11 @@ import { buildHeadlessAutoArgs, parseCliArgs, runWebCliBranch, migrateLegacyFlat
17
17
  import { stopWebMode } from './web-mode.js';
18
18
  import { getProjectSessionsDir } from './project-sessions.js';
19
19
  import { markStartup, printStartupTimings } from './startup-timings.js';
20
- import { bootstrapRtk, GSD_RTK_DISABLED_ENV } from './rtk.js';
21
- import { loadEffectiveGSDPreferences } from './resources/extensions/gsd/preferences.js';
20
+ import { applyRtkProcessEnv, GSD_RTK_DISABLED_ENV, isTruthy } from './rtk-shared.js';
21
+ let piCodingAgentModulePromise;
22
+ function loadPiCodingAgentModule() {
23
+ return (piCodingAgentModulePromise ??= import('@gsd/pi-coding-agent'));
24
+ }
22
25
  // ---------------------------------------------------------------------------
23
26
  // V8 compile cache — Node 22+ can cache compiled bytecode across runs,
24
27
  // eliminating repeated parse/compile overhead for unchanged modules.
@@ -129,27 +132,53 @@ if (process.argv.includes('--help') || process.argv.includes('-h')) {
129
132
  // so concurrent callers await the same initialization.
130
133
  let rtkBootstrapPromise;
131
134
  async function doRtkBootstrap() {
135
+ let rtkStatus;
136
+ let rtkDisabled = isTruthy(process.env[GSD_RTK_DISABLED_ENV]);
132
137
  // RTK is opt-in via experimental.rtk preference. Default: disabled.
133
138
  // Honor GSD_RTK_DISABLED if already explicitly set in the environment
134
139
  // (env var takes precedence over preferences for manual override).
135
- if (!process.env[GSD_RTK_DISABLED_ENV]) {
140
+ if (!rtkDisabled) {
141
+ const { loadEffectiveGSDPreferences } = await import('./resources/extensions/gsd/preferences.js');
136
142
  const prefs = loadEffectiveGSDPreferences();
137
143
  const rtkEnabled = prefs?.preferences.experimental?.rtk === true;
138
144
  if (!rtkEnabled) {
139
145
  process.env[GSD_RTK_DISABLED_ENV] = '1';
146
+ rtkDisabled = true;
140
147
  }
141
148
  }
142
- const rtkStatus = await bootstrapRtk();
149
+ markStartup('rtkPreferenceCheck');
150
+ if (rtkDisabled) {
151
+ applyRtkProcessEnv(process.env);
152
+ rtkStatus = {
153
+ enabled: false,
154
+ supported: true,
155
+ available: false,
156
+ source: 'disabled',
157
+ reason: `${GSD_RTK_DISABLED_ENV} is set`,
158
+ };
159
+ }
160
+ else {
161
+ const { bootstrapRtk } = await import('./rtk.js');
162
+ rtkStatus = await bootstrapRtk();
163
+ }
143
164
  markStartup('bootstrapRtk');
144
165
  if (!rtkStatus.available && rtkStatus.supported && rtkStatus.enabled && rtkStatus.reason) {
145
166
  process.stderr.write(`[gsd] Warning: RTK unavailable — continuing without shell-command compression (${rtkStatus.reason}).\n`);
146
167
  }
147
168
  }
148
169
  function ensureRtkBootstrap() {
149
- return (rtkBootstrapPromise ??= doRtkBootstrap());
150
- }
151
- // `gsd update` — update to the latest version via npm
152
- if (cliFlags.messages[0] === 'update') {
170
+ if (!rtkBootstrapPromise) {
171
+ markStartup('preRtkBootstrap');
172
+ rtkBootstrapPromise = doRtkBootstrap();
173
+ }
174
+ return rtkBootstrapPromise;
175
+ }
176
+ // `gsd update` — update to the latest version via npm.
177
+ // MUST run before exitIfManagedResourcesAreNewer(): when the bundled resource
178
+ // manifest is from a newer version than the running binary, every other
179
+ // command is blocked — only `update` should bypass the gate so the user can
180
+ // actually upgrade out of the broken state. See shouldBypassManagedResourceMismatchGate.
181
+ if (shouldBypassManagedResourceMismatchGate(cliFlags.messages[0])) {
153
182
  const { runUpdate } = await import('./update-cmd.js');
154
183
  await runUpdate();
155
184
  process.exit(0);
@@ -246,20 +275,25 @@ const hasSubcommand = cliFlags.messages.length > 0;
246
275
  if (!process.stdin.isTTY && !isPrintMode && !hasSubcommand && !cliFlags.listModels && !cliFlags.web) {
247
276
  printNonTtyErrorAndExit(undefined, false);
248
277
  }
249
- const packageCommand = await runPackageCommand({
250
- appName: 'gsd',
251
- args: process.argv.slice(2),
252
- cwd: process.cwd(),
253
- agentDir,
254
- stdout: process.stdout,
255
- stderr: process.stderr,
256
- allowedCommands: new Set(['install', 'remove', 'list']),
257
- });
258
- if (packageCommand.handled) {
259
- process.exit(packageCommand.exitCode);
278
+ const packageCommandNames = new Set(['install', 'remove', 'list']);
279
+ if (packageCommandNames.has(cliFlags.messages[0])) {
280
+ const { runPackageCommand } = await loadPiCodingAgentModule();
281
+ const packageCommand = await runPackageCommand({
282
+ appName: 'gsd',
283
+ args: process.argv.slice(2),
284
+ cwd: process.cwd(),
285
+ agentDir,
286
+ stdout: process.stdout,
287
+ stderr: process.stderr,
288
+ allowedCommands: packageCommandNames,
289
+ });
290
+ if (packageCommand.handled) {
291
+ process.exit(packageCommand.exitCode);
292
+ }
260
293
  }
261
294
  // `gsd config` — replay the setup wizard and exit
262
295
  if (cliFlags.messages[0] === 'config') {
296
+ const { AuthStorage } = await loadPiCodingAgentModule();
263
297
  const authStorage = AuthStorage.create(authFilePath);
264
298
  loadStoredEnvKeys(authStorage);
265
299
  await runOnboarding(authStorage);
@@ -291,6 +325,7 @@ if (cliFlags.web || (cliFlags.messages[0] === 'web' && cliFlags.messages[1] !==
291
325
  }
292
326
  // `gsd sessions` — list past sessions and pick one to resume
293
327
  if (cliFlags.messages[0] === 'sessions') {
328
+ const { SessionManager } = await loadPiCodingAgentModule();
294
329
  const cwd = process.cwd();
295
330
  const safePath = `--${cwd.replace(/^[/\\]/, '').replace(/[/\\:]/g, '-')}--`;
296
331
  const projectSessionsDir = join(sessionsDir, safePath);
@@ -380,6 +415,35 @@ function flushPendingProviderRegistrations(resourceLoader, modelRegistry) {
380
415
  if (cliFlags.messages[0] === 'auto') {
381
416
  await runHeadlessFromAuto(buildHeadlessAutoArgs(cliFlags));
382
417
  }
418
+ // ---------------------------------------------------------------------------
419
+ // Worktree subcommand — `gsd worktree <list|merge|clean|remove>`
420
+ // ---------------------------------------------------------------------------
421
+ if (!isPrintMode &&
422
+ cliFlags.listModels === undefined &&
423
+ (cliFlags.messages[0] === 'worktree' || cliFlags.messages[0] === 'wt')) {
424
+ const { handleList, handleMerge, handleClean, handleRemove } = await import('./worktree-cli.js');
425
+ const sub = cliFlags.messages[1];
426
+ const subArgs = cliFlags.messages.slice(2);
427
+ if (!sub || sub === 'list') {
428
+ await handleList(process.cwd());
429
+ }
430
+ else if (sub === 'merge') {
431
+ await handleMerge(process.cwd(), subArgs);
432
+ }
433
+ else if (sub === 'clean') {
434
+ await handleClean(process.cwd());
435
+ }
436
+ else if (sub === 'remove' || sub === 'rm') {
437
+ await handleRemove(process.cwd(), subArgs);
438
+ }
439
+ else {
440
+ process.stderr.write(`Unknown worktree command: ${sub}\n`);
441
+ process.stderr.write('Commands: list, merge [name], clean, remove <name>\n');
442
+ }
443
+ process.exit(0);
444
+ }
445
+ const { AuthStorage, DefaultResourceLoader, ModelRegistry, SettingsManager, SessionManager, createAgentSession, InteractiveMode, runPrintMode, runRpcMode, } = await loadPiCodingAgentModule();
446
+ markStartup('loadPiCodingAgent');
383
447
  // Pi's tool bootstrap can mis-detect already-installed fd/rg on some systems
384
448
  // because spawnSync(..., ["--version"]) returns EPERM despite a zero exit code.
385
449
  // Provision local managed binaries first so Pi sees them without probing PATH.
@@ -431,11 +495,7 @@ if (cliFlags.listModels !== undefined) {
431
495
  additionalExtensionPaths: cliFlags.extensions.length > 0 ? cliFlags.extensions : undefined,
432
496
  });
433
497
  await listModelsLoader.reload();
434
- const listModelsExtensions = listModelsLoader.getExtensions();
435
- for (const { name, config } of listModelsExtensions.runtime.pendingProviderRegistrations) {
436
- modelRegistry.registerProvider(name, config);
437
- }
438
- listModelsExtensions.runtime.pendingProviderRegistrations = [];
498
+ flushPendingProviderRegistrations(listModelsLoader, modelRegistry);
439
499
  const models = modelRegistry.getAvailable();
440
500
  if (models.length === 0) {
441
501
  console.log('No models available. Set API keys in environment variables.');
@@ -483,6 +543,7 @@ if (!settingsManager.getQuietStartup()) {
483
543
  if (!settingsManager.getCollapseChangelog()) {
484
544
  settingsManager.setCollapseChangelog(true);
485
545
  }
546
+ markStartup('startupSettings');
486
547
  // ---------------------------------------------------------------------------
487
548
  // Print / subagent mode — single-shot execution, no TTY required
488
549
  // ---------------------------------------------------------------------------
@@ -515,7 +576,7 @@ if (isPrintMode) {
515
576
  flushPendingProviderRegistrations(resourceLoader, modelRegistry);
516
577
  migrateAnthropicDefaultToClaudeCode({
517
578
  authStorage,
518
- isClaudeCodeReady: modelRegistry.isProviderRequestReady('claude-code'),
579
+ isClaudeCodeReady: () => modelRegistry.isProviderRequestReady('claude-code'),
519
580
  settingsManager,
520
581
  modelRegistry,
521
582
  });
@@ -577,31 +638,6 @@ if (isPrintMode) {
577
638
  process.exit(0);
578
639
  }
579
640
  // ---------------------------------------------------------------------------
580
- // Worktree subcommand — `gsd worktree <list|merge|clean|remove>`
581
- // ---------------------------------------------------------------------------
582
- if (cliFlags.messages[0] === 'worktree' || cliFlags.messages[0] === 'wt') {
583
- const { handleList, handleMerge, handleClean, handleRemove } = await import('./worktree-cli.js');
584
- const sub = cliFlags.messages[1];
585
- const subArgs = cliFlags.messages.slice(2);
586
- if (!sub || sub === 'list') {
587
- await handleList(process.cwd());
588
- }
589
- else if (sub === 'merge') {
590
- await handleMerge(process.cwd(), subArgs);
591
- }
592
- else if (sub === 'clean') {
593
- await handleClean(process.cwd());
594
- }
595
- else if (sub === 'remove' || sub === 'rm') {
596
- await handleRemove(process.cwd(), subArgs);
597
- }
598
- else {
599
- process.stderr.write(`Unknown worktree command: ${sub}\n`);
600
- process.stderr.write('Commands: list, merge [name], clean, remove <name>\n');
601
- }
602
- process.exit(0);
603
- }
604
- // ---------------------------------------------------------------------------
605
641
  // Worktree flag (-w) — create/resume a worktree for the interactive session
606
642
  // ---------------------------------------------------------------------------
607
643
  if (cliFlags.worktree) {
@@ -613,11 +649,12 @@ if (cliFlags.worktree) {
613
649
  // ---------------------------------------------------------------------------
614
650
  if (!cliFlags.worktree && !isPrintMode) {
615
651
  try {
616
- const { handleStatusBanner } = await import('./worktree-cli.js');
617
- await handleStatusBanner(process.cwd());
652
+ const { showWorktreeStatusBanner } = await import('./worktree-status-banner.js');
653
+ showWorktreeStatusBanner(process.cwd());
618
654
  }
619
655
  catch { /* non-fatal */ }
620
656
  }
657
+ markStartup('worktreeStatusBanner');
621
658
  // ---------------------------------------------------------------------------
622
659
  // Auto-redirect: `gsd auto` with piped stdout → headless mode (#2732)
623
660
  // When stdout is not a TTY (e.g. `gsd auto | cat`, `gsd auto > file`),
@@ -651,7 +688,9 @@ markStartup('initResources');
651
688
  // Overlap resource loading with session manager setup — both are independent.
652
689
  // resourceLoader.reload() is the most expensive step (jiti compilation), so
653
690
  // starting it early shaves ~50-200ms off interactive startup.
654
- const resourceLoader = buildResourceLoader(agentDir);
691
+ const resourceLoader = await buildResourceLoader(agentDir, {
692
+ additionalExtensionPaths: cliFlags.extensions.length > 0 ? cliFlags.extensions : undefined,
693
+ });
655
694
  const resourceLoadPromise = resourceLoader.reload();
656
695
  // While resources load, let session manager finish any async I/O it needs.
657
696
  // Then await the resource promise before creating the agent session.
@@ -660,10 +699,11 @@ markStartup('resourceLoader.reload');
660
699
  flushPendingProviderRegistrations(resourceLoader, modelRegistry);
661
700
  migrateAnthropicDefaultToClaudeCode({
662
701
  authStorage,
663
- isClaudeCodeReady: modelRegistry.isProviderRequestReady('claude-code'),
702
+ isClaudeCodeReady: () => modelRegistry.isProviderRequestReady('claude-code'),
664
703
  settingsManager,
665
704
  modelRegistry,
666
705
  });
706
+ markStartup('providerMigrations');
667
707
  const { session, extensionsResult, modelFallbackMessage: interactiveFallbackMsg } = await createAgentSession({
668
708
  authStorage,
669
709
  modelRegistry,
@@ -14,6 +14,28 @@
14
14
  * bypassing the extension loader's jiti setup (#1137).
15
15
  */
16
16
  import type { GSDState } from './resources/extensions/gsd/types.js';
17
+ /**
18
+ * Resolve the GSD extensions root for headless-query. Prefers the synced
19
+ * agent directory (so headless-query loads the same extension copy as
20
+ * interactive/auto modes — #3471) and falls back to the bundled source
21
+ * resource for source-tree dev workflows.
22
+ *
23
+ * Pure on the given inputs (env + fs probe + bundled resolver) so the
24
+ * #3471 contract can be exercised in tests without spawning a subprocess.
25
+ */
26
+ export declare function resolveGsdAgentExtensionsDir(env?: NodeJS.ProcessEnv): string;
27
+ /**
28
+ * Decide whether headless-query should load extensions from the agent
29
+ * sync directory (#3471) or fall back to bundled source. Returns the
30
+ * agent dir alongside the decision so a caller can use it directly.
31
+ */
32
+ export declare function shouldUseAgentExtensionsDir(opts: {
33
+ env?: NodeJS.ProcessEnv;
34
+ fileExists?: (path: string) => boolean;
35
+ }): {
36
+ agentDir: string;
37
+ useAgentDir: boolean;
38
+ };
17
39
  export interface QuerySnapshot {
18
40
  state: GSDState;
19
41
  next: {
@@ -19,11 +19,31 @@ import { join } from 'node:path';
19
19
  import { homedir } from 'node:os';
20
20
  import { resolveBundledSourceResource } from './bundled-resource-path.js';
21
21
  const jiti = createJiti(fileURLToPath(import.meta.url), { interopDefault: true, debug: false });
22
- // Resolve extensions from the synced agent directory so headless-query
23
- // loads the same extension copy as interactive/auto modes (#3471).
24
- // Falls back to bundled source for source-tree dev workflows.
25
- const agentExtensionsDir = join(process.env.GSD_AGENT_DIR || join(homedir(), '.gsd', 'agent'), 'extensions', 'gsd');
26
22
  const { existsSync } = await import('node:fs');
23
+ /**
24
+ * Resolve the GSD extensions root for headless-query. Prefers the synced
25
+ * agent directory (so headless-query loads the same extension copy as
26
+ * interactive/auto modes — #3471) and falls back to the bundled source
27
+ * resource for source-tree dev workflows.
28
+ *
29
+ * Pure on the given inputs (env + fs probe + bundled resolver) so the
30
+ * #3471 contract can be exercised in tests without spawning a subprocess.
31
+ */
32
+ export function resolveGsdAgentExtensionsDir(env = process.env) {
33
+ return join(env.GSD_AGENT_DIR || join(homedir(), '.gsd', 'agent'), 'extensions', 'gsd');
34
+ }
35
+ /**
36
+ * Decide whether headless-query should load extensions from the agent
37
+ * sync directory (#3471) or fall back to bundled source. Returns the
38
+ * agent dir alongside the decision so a caller can use it directly.
39
+ */
40
+ export function shouldUseAgentExtensionsDir(opts) {
41
+ const env = opts.env ?? process.env;
42
+ const fileExists = opts.fileExists ?? existsSync;
43
+ const agentDir = resolveGsdAgentExtensionsDir(env);
44
+ return { agentDir, useAgentDir: fileExists(join(agentDir, 'state.ts')) };
45
+ }
46
+ const agentExtensionsDir = resolveGsdAgentExtensionsDir();
27
47
  const useAgentDir = existsSync(join(agentExtensionsDir, 'state.ts'));
28
48
  const gsdExtensionPath = (...segments) => useAgentDir
29
49
  ? join(agentExtensionsDir, ...segments)
@@ -32,6 +32,16 @@ export interface HeadlessOptions {
32
32
  resumeSession?: string;
33
33
  bare?: boolean;
34
34
  }
35
+ /**
36
+ * Commands classified as multi-turn in headless mode: they involve multiple
37
+ * question rounds, codebase scanning, and artifact writing before the workflow
38
+ * completes (#3547). Multi-turn commands suppress single-execution-complete
39
+ * exit and disable the default 5-minute timeout.
40
+ *
41
+ * Exported so the regression test can exercise the real classifier rather
42
+ * than grepping the source for identifier names.
43
+ */
44
+ export declare function isMultiTurnHeadlessCommand(command: string): boolean;
35
45
  export interface ResumeSessionResult {
36
46
  session?: SessionInfo;
37
47
  error?: string;
package/dist/headless.js CHANGED
@@ -21,6 +21,21 @@ import { isTerminalNotification, isBlockedNotification, isMilestoneReadyNotifica
21
21
  import { VALID_OUTPUT_FORMATS } from './headless-types.js';
22
22
  import { handleExtensionUIRequest, formatProgress, formatThinkingLine, formatTextStart, formatTextEnd, formatThinkingStart, formatThinkingEnd, startSupervisedStdinReader, } from './headless-ui.js';
23
23
  import { loadContext, bootstrapGsdProject, } from './headless-context.js';
24
+ /**
25
+ * Commands classified as multi-turn in headless mode: they involve multiple
26
+ * question rounds, codebase scanning, and artifact writing before the workflow
27
+ * completes (#3547). Multi-turn commands suppress single-execution-complete
28
+ * exit and disable the default 5-minute timeout.
29
+ *
30
+ * Exported so the regression test can exercise the real classifier rather
31
+ * than grepping the source for identifier names.
32
+ */
33
+ export function isMultiTurnHeadlessCommand(command) {
34
+ return (command === 'auto' ||
35
+ command === 'next' ||
36
+ command === 'discuss' ||
37
+ command === 'plan');
38
+ }
24
39
  /**
25
40
  * Resolve a session prefix to a single session.
26
41
  * Exact id match is preferred over prefix match.
@@ -186,7 +201,7 @@ async function runHeadlessOnce(options, restartCount) {
186
201
  const isAutoMode = options.command === 'auto';
187
202
  // discuss and plan are multi-turn: they involve multiple question rounds,
188
203
  // codebase scanning, and artifact writing before the workflow completes (#3547).
189
- const isMultiTurnCommand = options.command === 'auto' || options.command === 'next' || options.command === 'discuss' || options.command === 'plan';
204
+ const isMultiTurnCommand = isMultiTurnHeadlessCommand(options.command);
190
205
  if (isAutoMode && options.timeout === 300_000) {
191
206
  options.timeout = 0;
192
207
  }
package/dist/loader.js CHANGED
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
  // GSD Startup Loader
3
- // Copyright (c) 2026 Jeremy McSpadden <jeremy@fluxlabs.net>
4
3
  import { fileURLToPath } from 'url';
5
4
  import { dirname, resolve, join, relative, delimiter } from 'path';
6
5
  import { existsSync, readFileSync, readdirSync, statSync, mkdirSync, symlinkSync, cpSync } from 'fs';
@@ -32,14 +31,14 @@ if (firstArg === '--help' || firstArg === '-h') {
32
31
  // package.json (already parsed above) and verifies git is available.
33
32
  // ---------------------------------------------------------------------------
34
33
  {
35
- const MIN_NODE_MAJOR = 22;
34
+ const { MIN_NODE_MAJOR, checkNodeVersion, requireGit } = await import('./runtime-checks.js');
36
35
  const red = '\x1b[31m';
37
36
  const bold = '\x1b[1m';
38
37
  const dim = '\x1b[2m';
39
38
  const reset = '\x1b[0m';
40
39
  // -- Node version --
41
- const nodeMajor = parseInt(process.versions.node.split('.')[0], 10);
42
- if (nodeMajor < MIN_NODE_MAJOR) {
40
+ const nodeCheck = checkNodeVersion(process.versions.node, MIN_NODE_MAJOR);
41
+ if (!nodeCheck.ok) {
43
42
  process.stderr.write(`\n${red}${bold}Error:${reset} GSD requires Node.js >= ${MIN_NODE_MAJOR}.0.0\n` +
44
43
  ` You are running Node.js ${process.versions.node}\n\n` +
45
44
  `${dim}Install a supported version:${reset}\n` +
@@ -49,11 +48,9 @@ if (firstArg === '--help' || firstArg === '-h') {
49
48
  process.exit(1);
50
49
  }
51
50
  // -- git --
52
- try {
53
- const { execFileSync } = await import('child_process');
54
- execFileSync('git', ['--version'], { stdio: 'ignore' });
55
- }
56
- catch {
51
+ const { execFileSync } = await import('child_process');
52
+ const gitOk = requireGit((cmd, args) => execFileSync(cmd, args, { stdio: 'ignore' }));
53
+ if (!gitOk) {
57
54
  process.stderr.write(`\n${red}${bold}Error:${reset} GSD requires git but it was not found on PATH.\n\n` +
58
55
  `${dim}Install git:${reset}\n` +
59
56
  ` https://git-scm.com/downloads\n\n`);
@@ -61,7 +58,7 @@ if (firstArg === '--help' || firstArg === '-h') {
61
58
  }
62
59
  }
63
60
  import { agentDir, appRoot } from './app-paths.js';
64
- import { applyRtkProcessEnv } from './rtk.js';
61
+ import { applyRtkProcessEnv } from './rtk-shared.js';
65
62
  import { serializeBundledExtensionPaths } from './bundled-extension-paths.js';
66
63
  import { discoverExtensionEntryPaths } from './extension-discovery.js';
67
64
  import { loadRegistry, readManifestFromEntryPath, isExtensionEnabled } from './extension-registry.js';
@@ -24,6 +24,16 @@ interface RunOnboardingOptions {
24
24
  /** Show logo + intro banner. Disable when onboarding is launched inside an active TUI session. */
25
25
  showIntro?: boolean;
26
26
  }
27
+ export declare const OTHER_PROVIDERS: ({
28
+ value: string;
29
+ label: string;
30
+ hint: string;
31
+ } | {
32
+ value: string;
33
+ label: string;
34
+ hint?: undefined;
35
+ })[];
36
+ export declare function detectNativeProviderFromBaseUrl(baseUrl: string): 'minimax' | 'minimax-cn' | null;
27
37
  /**
28
38
  * Determine if the onboarding wizard should run.
29
39
  *