@opengsd/gsd-pi 1.2.0-dev.b1abb545 → 1.2.0-dev.fb12b103

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 (520) hide show
  1. package/dist/cli-style.d.ts +17 -0
  2. package/dist/cli-style.js +28 -0
  3. package/dist/cli.js +1 -1
  4. package/dist/headless-events.d.ts +4 -2
  5. package/dist/headless-events.js +7 -29
  6. package/dist/models-resolver.d.ts +3 -13
  7. package/dist/models-resolver.js +3 -22
  8. package/dist/resource-loader.js +2 -14
  9. package/dist/resources/.managed-resources-content-hash +1 -1
  10. package/dist/resources/extensions/async-jobs/async-bash-tool.js +30 -64
  11. package/dist/resources/extensions/async-jobs/await-tool.js +80 -12
  12. package/dist/resources/extensions/async-jobs/index.js +65 -0
  13. package/dist/resources/extensions/async-jobs/job-manager.js +12 -1
  14. package/dist/resources/extensions/bg-shell/bg-shell-command.js +6 -6
  15. package/dist/resources/extensions/bg-shell/bg-shell-tool.js +10 -7
  16. package/dist/resources/extensions/bg-shell/overlay.js +9 -6
  17. package/dist/resources/extensions/bg-shell/process-manager.js +54 -25
  18. package/dist/resources/extensions/bg-shell/readiness-detector.js +11 -0
  19. package/dist/resources/extensions/bg-shell/utilities.js +5 -2
  20. package/dist/resources/extensions/browser-tools/engine/managed-gsd-browser.js +209 -88
  21. package/dist/resources/extensions/browser-tools/engine/selection.js +73 -5
  22. package/dist/resources/extensions/browser-tools/index.js +69 -12
  23. package/dist/resources/extensions/claude-code-cli/models.js +9 -0
  24. package/dist/resources/extensions/claude-code-cli/stream-adapter.js +38 -6
  25. package/dist/resources/extensions/gsd/auto/orchestrator.js +40 -9
  26. package/dist/resources/extensions/gsd/auto/phases.js +6 -1
  27. package/dist/resources/extensions/gsd/auto-dispatch.js +12 -1
  28. package/dist/resources/extensions/gsd/auto-model-selection.js +25 -6
  29. package/dist/resources/extensions/gsd/auto-post-unit.js +19 -8
  30. package/dist/resources/extensions/gsd/auto-prompts.js +15 -10
  31. package/dist/resources/extensions/gsd/auto-start.js +21 -21
  32. package/dist/resources/extensions/gsd/auto-tool-tracking.js +18 -0
  33. package/dist/resources/extensions/gsd/auto-unit-tool-scope.js +7 -16
  34. package/dist/resources/extensions/gsd/auto-worktree-repair.js +10 -2
  35. package/dist/resources/extensions/gsd/auto-worktree.js +35 -352
  36. package/dist/resources/extensions/gsd/auto.js +8 -20
  37. package/dist/resources/extensions/gsd/bootstrap/agent-end-recovery.js +3 -2
  38. package/dist/resources/extensions/gsd/bootstrap/dynamic-tools.js +32 -12
  39. package/dist/resources/extensions/gsd/bootstrap/register-extension.js +19 -0
  40. package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +151 -20
  41. package/dist/resources/extensions/gsd/bootstrap/write-gate.js +30 -4
  42. package/dist/resources/extensions/gsd/branch-patterns.js +2 -0
  43. package/dist/resources/extensions/gsd/browser-daemon-auto-prep.js +83 -0
  44. package/dist/resources/extensions/gsd/browser-evidence.js +8 -2
  45. package/dist/resources/extensions/gsd/captures.js +5 -15
  46. package/dist/resources/extensions/gsd/closeout-recovery.js +3 -2
  47. package/dist/resources/extensions/gsd/commands/catalog.js +6 -62
  48. package/dist/resources/extensions/gsd/constants.js +0 -2
  49. package/dist/resources/extensions/gsd/crash-recovery.js +4 -12
  50. package/dist/resources/extensions/gsd/db/engine.js +755 -0
  51. package/dist/resources/extensions/gsd/db/queries.js +372 -0
  52. package/dist/resources/extensions/gsd/db/sql-constants.js +11 -0
  53. package/dist/resources/extensions/gsd/db/writers/cascades.js +194 -0
  54. package/dist/resources/extensions/gsd/db/writers/import-restore.js +182 -0
  55. package/dist/resources/extensions/gsd/db/writers/memory.js +149 -0
  56. package/dist/resources/extensions/gsd/db/writers/reconcile.js +458 -0
  57. package/dist/resources/extensions/gsd/db/writers/status.js +70 -0
  58. package/dist/resources/extensions/gsd/doctor-environment.js +5 -11
  59. package/dist/resources/extensions/gsd/doctor-format.js +9 -6
  60. package/dist/resources/extensions/gsd/doctor-git-checks.js +4 -3
  61. package/dist/resources/extensions/gsd/doctor-runtime-checks.js +21 -16
  62. package/dist/resources/extensions/gsd/error-classifier.js +9 -0
  63. package/dist/resources/extensions/gsd/exec-sandbox.js +30 -10
  64. package/dist/resources/extensions/gsd/git-service.js +1 -0
  65. package/dist/resources/extensions/gsd/gitignore.js +3 -0
  66. package/dist/resources/extensions/gsd/gsd-db.js +171 -2048
  67. package/dist/resources/extensions/gsd/guidance.js +98 -0
  68. package/dist/resources/extensions/gsd/guided-flow.js +51 -5
  69. package/dist/resources/extensions/gsd/mcp-filter.js +2 -19
  70. package/dist/resources/extensions/gsd/mcp-tool-name.js +5 -13
  71. package/dist/resources/extensions/gsd/memory-consolidation-scanner.js +1 -1
  72. package/dist/resources/extensions/gsd/migrate/safety.js +20 -9
  73. package/dist/resources/extensions/gsd/migration-auto-check.js +24 -3
  74. package/dist/resources/extensions/gsd/model-cost-table.js +1 -0
  75. package/dist/resources/extensions/gsd/model-router.js +3 -0
  76. package/dist/resources/extensions/gsd/notification-store.js +11 -4
  77. package/dist/resources/extensions/gsd/parallel-merge.js +14 -11
  78. package/dist/resources/extensions/gsd/parallel-monitor-overlay.js +11 -7
  79. package/dist/resources/extensions/gsd/paths.js +37 -24
  80. package/dist/resources/extensions/gsd/pre-execution-checks.js +91 -3
  81. package/dist/resources/extensions/gsd/preferences-models.js +14 -48
  82. package/dist/resources/extensions/gsd/preferences.js +14 -0
  83. package/dist/resources/extensions/gsd/prompts/complete-slice.md +1 -1
  84. package/dist/resources/extensions/gsd/prompts/plan-slice.md +1 -1
  85. package/dist/resources/extensions/gsd/prompts/refine-slice.md +1 -1
  86. package/dist/resources/extensions/gsd/prompts/replan-slice.md +1 -1
  87. package/dist/resources/extensions/gsd/prompts/run-uat.md +1 -1
  88. package/dist/resources/extensions/gsd/prompts/system.md +5 -2
  89. package/dist/resources/extensions/gsd/provider-error-guidance.js +1 -5
  90. package/dist/resources/extensions/gsd/provider-switch-observer.js +1 -1
  91. package/dist/resources/extensions/gsd/publication.js +87 -0
  92. package/dist/resources/extensions/gsd/recovery-classification.js +41 -87
  93. package/dist/resources/extensions/gsd/safety/destructive-confirmation.js +108 -0
  94. package/dist/resources/extensions/gsd/safety/evidence-collector.js +37 -4
  95. package/dist/resources/extensions/gsd/safety/evidence-cross-ref.js +7 -2
  96. package/dist/resources/extensions/gsd/safety/file-change-validator.js +10 -0
  97. package/dist/resources/extensions/gsd/state-transition-matrix.js +38 -0
  98. package/dist/resources/extensions/gsd/state.js +1 -20
  99. package/dist/resources/extensions/gsd/status-guards.js +56 -8
  100. package/dist/resources/extensions/gsd/stop-notice.js +57 -0
  101. package/dist/resources/extensions/gsd/tool-surface-readiness.js +56 -0
  102. package/dist/resources/extensions/gsd/tools/complete-slice.js +24 -43
  103. package/dist/resources/extensions/gsd/tools/exec-tool.js +10 -8
  104. package/dist/resources/extensions/gsd/tools/plan-slice.js +12 -6
  105. package/dist/resources/extensions/gsd/tools/reopen-milestone.js +11 -29
  106. package/dist/resources/extensions/gsd/tools/reopen-slice.js +14 -33
  107. package/dist/resources/extensions/gsd/tools/skip-slice.js +18 -36
  108. package/dist/resources/extensions/gsd/uat-policy.js +2 -1
  109. package/dist/resources/extensions/gsd/undo.js +8 -7
  110. package/dist/resources/extensions/gsd/unit-closeout.js +138 -0
  111. package/dist/resources/extensions/gsd/unit-context-composer.js +74 -1
  112. package/dist/resources/extensions/gsd/unit-context-manifest.js +4 -27
  113. package/dist/resources/extensions/gsd/unit-registry.js +337 -0
  114. package/dist/resources/extensions/gsd/unit-tool-contracts.js +9 -182
  115. package/dist/resources/extensions/gsd/web-app-uat.js +45 -8
  116. package/dist/resources/extensions/gsd/workflow-tool-surface.js +1 -1
  117. package/dist/resources/extensions/gsd/worktree-git-recovery.js +293 -0
  118. package/dist/resources/extensions/gsd/worktree-lifecycle.js +9 -1
  119. package/dist/resources/extensions/gsd/worktree-manager.js +45 -28
  120. package/dist/resources/extensions/gsd/worktree-placement.js +59 -0
  121. package/dist/resources/extensions/gsd/worktree-reentry.js +12 -8
  122. package/dist/resources/extensions/gsd/worktree-root.js +28 -6
  123. package/dist/resources/extensions/gsd/worktree-safety.js +8 -5
  124. package/dist/resources/extensions/gsd/worktree-session-state.js +12 -11
  125. package/dist/resources/extensions/search-the-web/native-search.js +5 -3
  126. package/dist/resources/extensions/shared/browser-contract.js +59 -0
  127. package/dist/resources/extensions/shared/gsd-browser-cli.js +96 -5
  128. package/dist/resources/shared/package.json +3 -0
  129. package/dist/resources/skills/create-skill/references/executable-code.md +1 -1
  130. package/dist/resources/skills/create-skill/workflows/add-reference.md +8 -3
  131. package/dist/resources/skills/create-skill/workflows/add-script.md +4 -2
  132. package/dist/resources/skills/create-skill/workflows/add-template.md +3 -1
  133. package/dist/resources/skills/create-skill/workflows/add-workflow.md +8 -3
  134. package/dist/resources/skills/create-skill/workflows/upgrade-to-router.md +10 -5
  135. package/dist/resources/skills/create-skill/workflows/verify-skill.md +9 -4
  136. package/dist/resources/skills/gsd-browser/SKILL.md +1 -1
  137. package/dist/resources/skills/spike-wrap-up/SKILL.md +9 -9
  138. package/dist/tsconfig.extensions.tsbuildinfo +1 -1
  139. package/dist/web/standalone/.next/BUILD_ID +1 -1
  140. package/dist/web/standalone/.next/app-path-routes-manifest.json +10 -10
  141. package/dist/web/standalone/.next/build-manifest.json +3 -3
  142. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  143. package/dist/web/standalone/.next/react-loadable-manifest.json +1 -1
  144. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  145. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  146. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  147. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  148. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  149. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  150. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  151. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  152. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  153. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  154. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  155. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  156. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  157. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  158. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  159. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  160. package/dist/web/standalone/.next/server/app/api/boot/route.js.nft.json +1 -1
  161. package/dist/web/standalone/.next/server/app/api/bridge-terminal/input/route.js.nft.json +1 -1
  162. package/dist/web/standalone/.next/server/app/api/bridge-terminal/resize/route.js.nft.json +1 -1
  163. package/dist/web/standalone/.next/server/app/api/bridge-terminal/stream/route.js.nft.json +1 -1
  164. package/dist/web/standalone/.next/server/app/api/captures/route.js.nft.json +1 -1
  165. package/dist/web/standalone/.next/server/app/api/cleanup/route.js.nft.json +1 -1
  166. package/dist/web/standalone/.next/server/app/api/doctor/route.js.nft.json +1 -1
  167. package/dist/web/standalone/.next/server/app/api/export-data/route.js.nft.json +1 -1
  168. package/dist/web/standalone/.next/server/app/api/files/route.js.nft.json +1 -1
  169. package/dist/web/standalone/.next/server/app/api/forensics/route.js.nft.json +1 -1
  170. package/dist/web/standalone/.next/server/app/api/git/route.js.nft.json +1 -1
  171. package/dist/web/standalone/.next/server/app/api/history/route.js.nft.json +1 -1
  172. package/dist/web/standalone/.next/server/app/api/hooks/route.js.nft.json +1 -1
  173. package/dist/web/standalone/.next/server/app/api/inspect/route.js.nft.json +1 -1
  174. package/dist/web/standalone/.next/server/app/api/knowledge/route.js.nft.json +1 -1
  175. package/dist/web/standalone/.next/server/app/api/live-state/route.js.nft.json +1 -1
  176. package/dist/web/standalone/.next/server/app/api/mcp-connections/route.js.nft.json +1 -1
  177. package/dist/web/standalone/.next/server/app/api/notifications/route.js.nft.json +1 -1
  178. package/dist/web/standalone/.next/server/app/api/onboarding/route.js.nft.json +1 -1
  179. package/dist/web/standalone/.next/server/app/api/projects/route.js.nft.json +1 -1
  180. package/dist/web/standalone/.next/server/app/api/recovery/route.js.nft.json +1 -1
  181. package/dist/web/standalone/.next/server/app/api/session/browser/route.js.nft.json +1 -1
  182. package/dist/web/standalone/.next/server/app/api/session/command/route.js.nft.json +1 -1
  183. package/dist/web/standalone/.next/server/app/api/session/events/route.js.nft.json +1 -1
  184. package/dist/web/standalone/.next/server/app/api/session/manage/route.js.nft.json +1 -1
  185. package/dist/web/standalone/.next/server/app/api/settings-data/route.js.nft.json +1 -1
  186. package/dist/web/standalone/.next/server/app/api/shutdown/route.js.nft.json +1 -1
  187. package/dist/web/standalone/.next/server/app/api/skill-health/route.js.nft.json +1 -1
  188. package/dist/web/standalone/.next/server/app/api/steer/route.js.nft.json +1 -1
  189. package/dist/web/standalone/.next/server/app/api/switch-root/route.js.nft.json +1 -1
  190. package/dist/web/standalone/.next/server/app/api/terminal/sessions/route.js.nft.json +1 -1
  191. package/dist/web/standalone/.next/server/app/api/terminal/stream/route.js.nft.json +1 -1
  192. package/dist/web/standalone/.next/server/app/api/undo/route.js.nft.json +1 -1
  193. package/dist/web/standalone/.next/server/app/api/update/route.js +1 -1
  194. package/dist/web/standalone/.next/server/app/api/update/route.js.nft.json +1 -1
  195. package/dist/web/standalone/.next/server/app/api/visualizer/route.js.nft.json +1 -1
  196. package/dist/web/standalone/.next/server/app/index.html +1 -1
  197. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  198. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  199. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  200. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  201. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  202. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  203. package/dist/web/standalone/.next/server/app-paths-manifest.json +10 -10
  204. package/dist/web/standalone/.next/server/chunks/5124.js +1 -1
  205. package/dist/web/standalone/.next/server/chunks/{5047.js → 5942.js} +2 -2
  206. package/dist/web/standalone/.next/server/chunks/8357.js +1 -1
  207. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  208. package/dist/web/standalone/.next/server/middleware-react-loadable-manifest.js +1 -1
  209. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  210. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  211. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  212. package/dist/web/standalone/.next/static/chunks/{796.cf859a427a2cb2ac.js → 796.e0bdc932325d7e03.js} +1 -1
  213. package/dist/web/standalone/.next/static/chunks/{webpack-fbea77b5f9953368.js → webpack-f0285ce91d4ec9ef.js} +1 -1
  214. package/dist/web/standalone/node_modules/node-pty/build/Makefile +1 -1
  215. package/dist/web/standalone/node_modules/postcss/lib/container.js +18 -26
  216. package/dist/web/standalone/node_modules/postcss/lib/css-syntax-error.js +14 -47
  217. package/dist/web/standalone/node_modules/postcss/lib/declaration.js +4 -4
  218. package/dist/web/standalone/node_modules/postcss/lib/fromJSON.js +3 -3
  219. package/dist/web/standalone/node_modules/postcss/lib/input.js +29 -54
  220. package/dist/web/standalone/node_modules/postcss/lib/lazy-result.js +37 -47
  221. package/dist/web/standalone/node_modules/postcss/lib/map-generator.js +9 -26
  222. package/dist/web/standalone/node_modules/postcss/lib/no-work-result.js +55 -57
  223. package/dist/web/standalone/node_modules/postcss/lib/node.js +31 -99
  224. package/dist/web/standalone/node_modules/postcss/lib/parse.js +1 -1
  225. package/dist/web/standalone/node_modules/postcss/lib/parser.js +9 -10
  226. package/dist/web/standalone/node_modules/postcss/lib/postcss.js +12 -12
  227. package/dist/web/standalone/node_modules/postcss/lib/previous-map.js +11 -30
  228. package/dist/web/standalone/node_modules/postcss/lib/processor.js +7 -7
  229. package/dist/web/standalone/node_modules/postcss/lib/result.js +5 -5
  230. package/dist/web/standalone/node_modules/postcss/lib/rule.js +6 -6
  231. package/dist/web/standalone/node_modules/postcss/lib/stringifier.js +28 -69
  232. package/dist/web/standalone/node_modules/postcss/lib/tokenize.js +2 -6
  233. package/dist/web/standalone/node_modules/postcss/package.json +48 -48
  234. package/dist/web/standalone/package.json +1 -1
  235. package/dist/worktree-cli.js +3 -6
  236. package/dist/worktree-status-banner.js +7 -11
  237. package/package.json +1 -1
  238. package/packages/cloud-mcp-gateway/package.json +2 -2
  239. package/packages/contracts/dist/rpc.d.ts +1 -0
  240. package/packages/contracts/dist/rpc.d.ts.map +1 -1
  241. package/packages/contracts/dist/rpc.js.map +1 -1
  242. package/packages/contracts/dist/workflow.d.ts +4 -0
  243. package/packages/contracts/dist/workflow.d.ts.map +1 -1
  244. package/packages/contracts/dist/workflow.js.map +1 -1
  245. package/packages/contracts/package.json +1 -1
  246. package/packages/daemon/package.json +4 -4
  247. package/packages/gsd-agent-core/package.json +5 -5
  248. package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.d.ts +5 -0
  249. package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  250. package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.js +8 -0
  251. package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.js.map +1 -1
  252. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.d.ts.map +1 -1
  253. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.js +7 -0
  254. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.js.map +1 -1
  255. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/input-controller.d.ts.map +1 -1
  256. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/input-controller.js +8 -1
  257. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/input-controller.js.map +1 -1
  258. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-chat-render.d.ts.map +1 -1
  259. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-chat-render.js +11 -1
  260. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-chat-render.js.map +1 -1
  261. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-selectors-auth.d.ts.map +1 -1
  262. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-selectors-auth.js +4 -4
  263. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-selectors-auth.js.map +1 -1
  264. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  265. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-mode.js +3 -1
  266. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-mode.js.map +1 -1
  267. package/packages/gsd-agent-modes/package.json +7 -7
  268. package/packages/mcp-server/dist/cli.js +6 -3
  269. package/packages/mcp-server/dist/cli.js.map +1 -1
  270. package/packages/mcp-server/dist/workflow-tools.d.ts +8 -0
  271. package/packages/mcp-server/dist/workflow-tools.d.ts.map +1 -1
  272. package/packages/mcp-server/dist/workflow-tools.js +46 -21
  273. package/packages/mcp-server/dist/workflow-tools.js.map +1 -1
  274. package/packages/mcp-server/package.json +3 -3
  275. package/packages/native/package.json +1 -1
  276. package/packages/pi-agent-core/dist/harness/env/nodejs.d.ts +1 -0
  277. package/packages/pi-agent-core/dist/harness/env/nodejs.d.ts.map +1 -1
  278. package/packages/pi-agent-core/dist/harness/env/nodejs.js +34 -3
  279. package/packages/pi-agent-core/dist/harness/env/nodejs.js.map +1 -1
  280. package/packages/pi-agent-core/dist/index.d.ts +1 -0
  281. package/packages/pi-agent-core/dist/index.d.ts.map +1 -1
  282. package/packages/pi-agent-core/dist/index.js +3 -0
  283. package/packages/pi-agent-core/dist/index.js.map +1 -1
  284. package/packages/pi-agent-core/package.json +1 -1
  285. package/packages/pi-ai/dist/image-models.generated.d.ts +2 -2
  286. package/packages/pi-ai/dist/image-models.generated.js +6 -6
  287. package/packages/pi-ai/dist/image-models.generated.js.map +1 -1
  288. package/packages/pi-ai/dist/models.generated.d.ts +478 -484
  289. package/packages/pi-ai/dist/models.generated.d.ts.map +1 -1
  290. package/packages/pi-ai/dist/models.generated.js +500 -533
  291. package/packages/pi-ai/dist/models.generated.js.map +1 -1
  292. package/packages/pi-ai/package.json +1 -1
  293. package/packages/pi-coding-agent/dist/core/auth-storage.d.ts +2 -2
  294. package/packages/pi-coding-agent/dist/core/auth-storage.d.ts.map +1 -1
  295. package/packages/pi-coding-agent/dist/core/auth-storage.js +19 -13
  296. package/packages/pi-coding-agent/dist/core/auth-storage.js.map +1 -1
  297. package/packages/pi-coding-agent/dist/core/capability-patches.d.ts.map +1 -1
  298. package/packages/pi-coding-agent/dist/core/capability-patches.js +3 -1
  299. package/packages/pi-coding-agent/dist/core/capability-patches.js.map +1 -1
  300. package/packages/pi-coding-agent/dist/core/provider-readiness.d.ts.map +1 -1
  301. package/packages/pi-coding-agent/dist/core/provider-readiness.js +13 -6
  302. package/packages/pi-coding-agent/dist/core/provider-readiness.js.map +1 -1
  303. package/packages/pi-coding-agent/dist/core/tools/bash.d.ts +11 -0
  304. package/packages/pi-coding-agent/dist/core/tools/bash.d.ts.map +1 -1
  305. package/packages/pi-coding-agent/dist/core/tools/bash.js +53 -11
  306. package/packages/pi-coding-agent/dist/core/tools/bash.js.map +1 -1
  307. package/packages/pi-coding-agent/dist/index.d.ts +1 -1
  308. package/packages/pi-coding-agent/dist/index.d.ts.map +1 -1
  309. package/packages/pi-coding-agent/dist/index.js +1 -1
  310. package/packages/pi-coding-agent/dist/index.js.map +1 -1
  311. package/packages/pi-coding-agent/dist/utils/shell.d.ts +28 -2
  312. package/packages/pi-coding-agent/dist/utils/shell.d.ts.map +1 -1
  313. package/packages/pi-coding-agent/dist/utils/shell.js +56 -10
  314. package/packages/pi-coding-agent/dist/utils/shell.js.map +1 -1
  315. package/packages/pi-coding-agent/package.json +7 -7
  316. package/packages/pi-tui/dist/tui.d.ts.map +1 -1
  317. package/packages/pi-tui/dist/tui.js +9 -0
  318. package/packages/pi-tui/dist/tui.js.map +1 -1
  319. package/packages/pi-tui/package.json +2 -2
  320. package/packages/rpc-client/package.json +2 -2
  321. package/pkg/package.json +1 -1
  322. package/src/resources/extensions/async-jobs/async-bash-cancel.test.ts +360 -0
  323. package/src/resources/extensions/async-jobs/async-bash-tool.ts +33 -56
  324. package/src/resources/extensions/async-jobs/await-tool.test.ts +139 -0
  325. package/src/resources/extensions/async-jobs/await-tool.ts +82 -12
  326. package/src/resources/extensions/async-jobs/index.ts +79 -0
  327. package/src/resources/extensions/async-jobs/job-manager.ts +21 -1
  328. package/src/resources/extensions/bg-shell/bg-shell-command.ts +6 -6
  329. package/src/resources/extensions/bg-shell/bg-shell-tool.ts +10 -6
  330. package/src/resources/extensions/bg-shell/overlay.ts +9 -5
  331. package/src/resources/extensions/bg-shell/process-manager.ts +50 -25
  332. package/src/resources/extensions/bg-shell/readiness-detector.ts +12 -0
  333. package/src/resources/extensions/bg-shell/tests/lifecycle-and-utilities.test.ts +48 -1
  334. package/src/resources/extensions/bg-shell/utilities.ts +5 -2
  335. package/src/resources/extensions/browser-tools/engine/managed-gsd-browser.ts +265 -98
  336. package/src/resources/extensions/browser-tools/engine/selection.ts +90 -4
  337. package/src/resources/extensions/browser-tools/index.ts +71 -13
  338. package/src/resources/extensions/browser-tools/tests/browser-engine-selection.test.mjs +83 -13
  339. package/src/resources/extensions/browser-tools/tests/gsd-browser-launch-config.test.mjs +29 -1
  340. package/src/resources/extensions/browser-tools/tests/managed-gsd-browser-tools.test.mjs +136 -0
  341. package/src/resources/extensions/claude-code-cli/models.ts +9 -0
  342. package/src/resources/extensions/claude-code-cli/stream-adapter.ts +40 -4
  343. package/src/resources/extensions/claude-code-cli/tests/stream-adapter.test.ts +28 -0
  344. package/src/resources/extensions/gsd/auto/loop-deps.ts +1 -1
  345. package/src/resources/extensions/gsd/auto/orchestrator.ts +46 -10
  346. package/src/resources/extensions/gsd/auto/phases.ts +10 -1
  347. package/src/resources/extensions/gsd/auto-dispatch.ts +12 -0
  348. package/src/resources/extensions/gsd/auto-model-selection.ts +25 -5
  349. package/src/resources/extensions/gsd/auto-post-unit.ts +25 -7
  350. package/src/resources/extensions/gsd/auto-prompts.ts +40 -26
  351. package/src/resources/extensions/gsd/auto-start.ts +21 -22
  352. package/src/resources/extensions/gsd/auto-tool-tracking.ts +19 -0
  353. package/src/resources/extensions/gsd/auto-unit-tool-scope.ts +10 -17
  354. package/src/resources/extensions/gsd/auto-worktree-repair.ts +13 -2
  355. package/src/resources/extensions/gsd/auto-worktree.ts +41 -364
  356. package/src/resources/extensions/gsd/auto.ts +20 -24
  357. package/src/resources/extensions/gsd/bootstrap/agent-end-recovery.ts +3 -5
  358. package/src/resources/extensions/gsd/bootstrap/dynamic-tools.ts +33 -12
  359. package/src/resources/extensions/gsd/bootstrap/register-extension.ts +24 -0
  360. package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +180 -15
  361. package/src/resources/extensions/gsd/bootstrap/write-gate.ts +29 -3
  362. package/src/resources/extensions/gsd/branch-patterns.ts +3 -0
  363. package/src/resources/extensions/gsd/browser-daemon-auto-prep.ts +108 -0
  364. package/src/resources/extensions/gsd/browser-evidence.ts +18 -2
  365. package/src/resources/extensions/gsd/captures.ts +5 -16
  366. package/src/resources/extensions/gsd/closeout-recovery.ts +2 -1
  367. package/src/resources/extensions/gsd/commands/catalog.ts +6 -68
  368. package/src/resources/extensions/gsd/constants.ts +0 -3
  369. package/src/resources/extensions/gsd/crash-recovery.ts +3 -9
  370. package/src/resources/extensions/gsd/db/engine.ts +809 -0
  371. package/src/resources/extensions/gsd/db/queries.ts +453 -0
  372. package/src/resources/extensions/gsd/db/sql-constants.ts +12 -0
  373. package/src/resources/extensions/gsd/db/writers/cascades.ts +237 -0
  374. package/src/resources/extensions/gsd/db/writers/import-restore.ts +310 -0
  375. package/src/resources/extensions/gsd/db/writers/memory.ts +220 -0
  376. package/src/resources/extensions/gsd/db/writers/reconcile.ts +500 -0
  377. package/src/resources/extensions/gsd/db/writers/status.ts +88 -0
  378. package/src/resources/extensions/gsd/doctor-environment.ts +5 -13
  379. package/src/resources/extensions/gsd/doctor-format.ts +12 -7
  380. package/src/resources/extensions/gsd/doctor-git-checks.ts +3 -3
  381. package/src/resources/extensions/gsd/doctor-runtime-checks.ts +22 -17
  382. package/src/resources/extensions/gsd/error-classifier.ts +11 -0
  383. package/src/resources/extensions/gsd/exec-sandbox.ts +49 -9
  384. package/src/resources/extensions/gsd/git-service.ts +1 -0
  385. package/src/resources/extensions/gsd/gitignore.ts +3 -0
  386. package/src/resources/extensions/gsd/gsd-db.ts +173 -2373
  387. package/src/resources/extensions/gsd/guidance.ts +139 -0
  388. package/src/resources/extensions/gsd/guided-flow.ts +50 -5
  389. package/src/resources/extensions/gsd/mcp-filter.ts +2 -23
  390. package/src/resources/extensions/gsd/mcp-tool-name.ts +6 -11
  391. package/src/resources/extensions/gsd/memory-consolidation-scanner.ts +1 -1
  392. package/src/resources/extensions/gsd/migrate/safety.ts +18 -7
  393. package/src/resources/extensions/gsd/migration-auto-check.ts +28 -3
  394. package/src/resources/extensions/gsd/model-cost-table.ts +1 -0
  395. package/src/resources/extensions/gsd/model-router.ts +3 -0
  396. package/src/resources/extensions/gsd/notification-store.ts +26 -3
  397. package/src/resources/extensions/gsd/parallel-merge.ts +12 -9
  398. package/src/resources/extensions/gsd/parallel-monitor-overlay.ts +10 -7
  399. package/src/resources/extensions/gsd/paths.ts +42 -22
  400. package/src/resources/extensions/gsd/pre-execution-checks.ts +109 -3
  401. package/src/resources/extensions/gsd/preferences-models.ts +12 -47
  402. package/src/resources/extensions/gsd/preferences.ts +18 -0
  403. package/src/resources/extensions/gsd/prompts/complete-slice.md +1 -1
  404. package/src/resources/extensions/gsd/prompts/plan-slice.md +1 -1
  405. package/src/resources/extensions/gsd/prompts/refine-slice.md +1 -1
  406. package/src/resources/extensions/gsd/prompts/replan-slice.md +1 -1
  407. package/src/resources/extensions/gsd/prompts/run-uat.md +1 -1
  408. package/src/resources/extensions/gsd/prompts/system.md +5 -2
  409. package/src/resources/extensions/gsd/provider-error-guidance.ts +4 -9
  410. package/src/resources/extensions/gsd/provider-switch-observer.ts +1 -1
  411. package/src/resources/extensions/gsd/publication.ts +122 -0
  412. package/src/resources/extensions/gsd/recovery-classification.ts +47 -88
  413. package/src/resources/extensions/gsd/safety/destructive-confirmation.ts +134 -0
  414. package/src/resources/extensions/gsd/safety/evidence-collector.ts +36 -4
  415. package/src/resources/extensions/gsd/safety/evidence-cross-ref.ts +7 -2
  416. package/src/resources/extensions/gsd/safety/file-change-validator.ts +14 -0
  417. package/src/resources/extensions/gsd/state-transition-matrix.ts +42 -0
  418. package/src/resources/extensions/gsd/state.ts +4 -21
  419. package/src/resources/extensions/gsd/status-guards.ts +59 -8
  420. package/src/resources/extensions/gsd/stop-notice.ts +75 -0
  421. package/src/resources/extensions/gsd/tests/auto-loop.test.ts +123 -0
  422. package/src/resources/extensions/gsd/tests/auto-model-selection.test.ts +22 -0
  423. package/src/resources/extensions/gsd/tests/auto-orchestrator.test.ts +16 -19
  424. package/src/resources/extensions/gsd/tests/auto-paused-ui-cleanup.test.ts +3 -1
  425. package/src/resources/extensions/gsd/tests/auto-post-unit-evidence-crossref-4909.test.ts +46 -0
  426. package/src/resources/extensions/gsd/tests/auto-worktree-registry.test.ts +2 -2
  427. package/src/resources/extensions/gsd/tests/auto-worktree-repair.test.ts +4 -2
  428. package/src/resources/extensions/gsd/tests/browser-automation-contract-fixture.ts +39 -0
  429. package/src/resources/extensions/gsd/tests/browser-contract.test.ts +44 -0
  430. package/src/resources/extensions/gsd/tests/browser-daemon-auto-prep.test.ts +144 -0
  431. package/src/resources/extensions/gsd/tests/checkout-branch-stash-guard.test.ts +66 -1
  432. package/src/resources/extensions/gsd/tests/clear-stale-autostart.test.ts +44 -0
  433. package/src/resources/extensions/gsd/tests/commands-verdict.test.ts +8 -7
  434. package/src/resources/extensions/gsd/tests/destructive-confirmation.test.ts +303 -0
  435. package/src/resources/extensions/gsd/tests/dispatch-run-uat-browser-tools.test.ts +2 -1
  436. package/src/resources/extensions/gsd/tests/dynamic-bash-no-cap.test.ts +132 -0
  437. package/src/resources/extensions/gsd/tests/evidence-xref-gsd-exec.test.ts +157 -0
  438. package/src/resources/extensions/gsd/tests/exec-graceful-kill.test.ts +193 -0
  439. package/src/resources/extensions/gsd/tests/exec-tool.test.ts +29 -1
  440. package/src/resources/extensions/gsd/tests/extension-bootstrap-isolation.test.ts +35 -1
  441. package/src/resources/extensions/gsd/tests/file-change-validator.test.ts +33 -1
  442. package/src/resources/extensions/gsd/tests/guidance.test.ts +125 -0
  443. package/src/resources/extensions/gsd/tests/integration/auto-worktree-milestone-merge.test.ts +58 -15
  444. package/src/resources/extensions/gsd/tests/integration/auto-worktree.test.ts +74 -59
  445. package/src/resources/extensions/gsd/tests/integration/git-service.test.ts +3 -2
  446. package/src/resources/extensions/gsd/tests/integration/gsd-integration-fixture.ts +80 -0
  447. package/src/resources/extensions/gsd/tests/mcp-project-config.test.ts +3 -1
  448. package/src/resources/extensions/gsd/tests/migration-auto-check.test.ts +85 -1
  449. package/src/resources/extensions/gsd/tests/model-unittype-mapping.test.ts +32 -1
  450. package/src/resources/extensions/gsd/tests/notification-store.test.ts +32 -0
  451. package/src/resources/extensions/gsd/tests/oauth-api-model-routing.test.ts +167 -0
  452. package/src/resources/extensions/gsd/tests/pre-execution-checks.test.ts +193 -1
  453. package/src/resources/extensions/gsd/tests/provider-error-guidance.test.ts +3 -3
  454. package/src/resources/extensions/gsd/tests/publication.test.ts +120 -0
  455. package/src/resources/extensions/gsd/tests/recovery-classification-illegal-transition.test.ts +30 -0
  456. package/src/resources/extensions/gsd/tests/register-hooks-depth-verification.test.ts +248 -1
  457. package/src/resources/extensions/gsd/tests/runtime-invariant-modules.test.ts +1 -0
  458. package/src/resources/extensions/gsd/tests/safety-harness-false-positives.test.ts +38 -0
  459. package/src/resources/extensions/gsd/tests/session-switch-clears-pending-autostart.test.ts +108 -0
  460. package/src/resources/extensions/gsd/tests/single-writer-invariant.test.ts +43 -6
  461. package/src/resources/extensions/gsd/tests/state-transition-matrix.test.ts +36 -0
  462. package/src/resources/extensions/gsd/tests/status-guards.test.ts +38 -0
  463. package/src/resources/extensions/gsd/tests/stop-notice.test.ts +70 -0
  464. package/src/resources/extensions/gsd/tests/token-tool-gating.test.ts +76 -0
  465. package/src/resources/extensions/gsd/tests/tool-invocation-error-loop-break.test.ts +8 -0
  466. package/src/resources/extensions/gsd/tests/tool-surface-readiness.test.ts +155 -0
  467. package/src/resources/extensions/gsd/tests/uat-policy.test.ts +24 -29
  468. package/src/resources/extensions/gsd/tests/unit-closeout.test.ts +209 -0
  469. package/src/resources/extensions/gsd/tests/unit-context-composer.test.ts +67 -2
  470. package/src/resources/extensions/gsd/tests/unit-registry.test.ts +163 -0
  471. package/src/resources/extensions/gsd/tests/web-app-uat.test.ts +44 -1
  472. package/src/resources/extensions/gsd/tests/workflow-mcp.test.ts +2 -2
  473. package/src/resources/extensions/gsd/tests/workflow-tool-executors.test.ts +2 -2
  474. package/src/resources/extensions/gsd/tests/worktree-lifecycle.test.ts +41 -4
  475. package/src/resources/extensions/gsd/tests/worktree-manager.test.ts +22 -1
  476. package/src/resources/extensions/gsd/tests/worktree-placement.test.ts +113 -0
  477. package/src/resources/extensions/gsd/tests/worktree-reentry.test.ts +1 -1
  478. package/src/resources/extensions/gsd/tests/worktree-safety.test.ts +3 -1
  479. package/src/resources/extensions/gsd/tests/worktree-symlink-removal.test.ts +12 -6
  480. package/src/resources/extensions/gsd/tests/worktree-teardown-safety.test.ts +2 -2
  481. package/src/resources/extensions/gsd/tests/write-gate.test.ts +42 -0
  482. package/src/resources/extensions/gsd/tool-surface-readiness.ts +76 -0
  483. package/src/resources/extensions/gsd/tools/complete-slice.ts +23 -58
  484. package/src/resources/extensions/gsd/tools/exec-tool.ts +9 -8
  485. package/src/resources/extensions/gsd/tools/plan-slice.ts +12 -6
  486. package/src/resources/extensions/gsd/tools/reopen-milestone.ts +11 -38
  487. package/src/resources/extensions/gsd/tools/reopen-slice.ts +14 -42
  488. package/src/resources/extensions/gsd/tools/skip-slice.ts +18 -44
  489. package/src/resources/extensions/gsd/uat-policy.ts +2 -1
  490. package/src/resources/extensions/gsd/undo.ts +9 -8
  491. package/src/resources/extensions/gsd/unit-closeout.ts +201 -0
  492. package/src/resources/extensions/gsd/unit-context-composer.ts +111 -1
  493. package/src/resources/extensions/gsd/unit-context-manifest.ts +4 -28
  494. package/src/resources/extensions/gsd/unit-registry.ts +412 -0
  495. package/src/resources/extensions/gsd/unit-tool-contracts.ts +27 -192
  496. package/src/resources/extensions/gsd/web-app-uat.ts +51 -8
  497. package/src/resources/extensions/gsd/workflow-tool-surface.ts +4 -1
  498. package/src/resources/extensions/gsd/worktree-git-recovery.ts +314 -0
  499. package/src/resources/extensions/gsd/worktree-lifecycle.ts +10 -1
  500. package/src/resources/extensions/gsd/worktree-manager.ts +47 -28
  501. package/src/resources/extensions/gsd/worktree-placement.ts +63 -0
  502. package/src/resources/extensions/gsd/worktree-reentry.ts +10 -7
  503. package/src/resources/extensions/gsd/worktree-root.ts +29 -6
  504. package/src/resources/extensions/gsd/worktree-safety.ts +8 -5
  505. package/src/resources/extensions/gsd/worktree-session-state.ts +11 -11
  506. package/src/resources/extensions/search-the-web/native-search.ts +5 -3
  507. package/src/resources/extensions/shared/browser-contract.ts +66 -0
  508. package/src/resources/extensions/shared/gsd-browser-cli.ts +119 -5
  509. package/src/resources/shared/package.json +3 -0
  510. package/src/resources/skills/create-skill/references/executable-code.md +1 -1
  511. package/src/resources/skills/create-skill/workflows/add-reference.md +8 -3
  512. package/src/resources/skills/create-skill/workflows/add-script.md +4 -2
  513. package/src/resources/skills/create-skill/workflows/add-template.md +3 -1
  514. package/src/resources/skills/create-skill/workflows/add-workflow.md +8 -3
  515. package/src/resources/skills/create-skill/workflows/upgrade-to-router.md +10 -5
  516. package/src/resources/skills/create-skill/workflows/verify-skill.md +9 -4
  517. package/src/resources/skills/gsd-browser/SKILL.md +1 -1
  518. package/src/resources/skills/spike-wrap-up/SKILL.md +9 -9
  519. /package/dist/web/standalone/.next/static/{3PtrU9qGPEXwNLWkIyiqk → mU4QIDlpVHDdjDpeEKh5W}/_buildManifest.js +0 -0
  520. /package/dist/web/standalone/.next/static/{3PtrU9qGPEXwNLWkIyiqk → mU4QIDlpVHDdjDpeEKh5W}/_ssgManifest.js +0 -0
@@ -1,8 +1,10 @@
1
1
  // Project/App: gsd-pi
2
- // File Purpose: Web-app detection and Playwright/UAT guidance for planning and slice closeout.
2
+ // File Purpose: Web-app detection and browser-UAT guidance for planning and slice closeout.
3
3
  import { existsSync, readFileSync } from "node:fs";
4
4
  import { resolve } from "node:path";
5
+ import { resolveAmbientBrowserEngineResolution } from "../browser-tools/engine/selection.js";
5
6
  import { detectWebApp } from "../browser-tools/web-app-detect.js";
7
+ import { UAT_MODE_POLICIES } from "./uat-policy.js";
6
8
  export { detectWebApp };
7
9
  function readPackageJson(projectRoot) {
8
10
  const packageJsonPath = resolve(projectRoot, "package.json");
@@ -39,24 +41,56 @@ export function findPlaywrightTestScript(projectRoot) {
39
41
  }
40
42
  return null;
41
43
  }
44
+ function describeBrowserToolBacking(engineResolution) {
45
+ switch (engineResolution.engine) {
46
+ case "gsd-browser":
47
+ return "This project looks browser-facing. GSD exposes `browser_*` tools backed by the managed gsd-browser engine for run-uat.";
48
+ case "legacy":
49
+ return "This project looks browser-facing. GSD exposes Playwright-backed `browser_*` tools for run-uat.";
50
+ case "off":
51
+ return "This project looks browser-facing, but Pi browser tools are disabled (GSD_BROWSER_ENGINE=off) — prefer `runtime-executable` UAT with automated browser test commands.";
52
+ }
53
+ }
54
+ // One bullet per recommended UAT mode; `mode` keys into UAT_MODE_POLICIES so
55
+ // modes that require browser tools drop out of the guidance when the resolved
56
+ // engine provides none (mixed/live-runtime share one bullet and one policy bit).
57
+ const UAT_MODE_GUIDANCE = [
58
+ {
59
+ mode: "browser-executable",
60
+ bullet: "- `browser-executable` — navigate to `http://localhost:…`, click, screenshot, assert via `browser_*` tools during run-uat",
61
+ },
62
+ {
63
+ mode: "runtime-executable",
64
+ bullet: "- `runtime-executable` — run an automated browser test command via `gsd_uat_exec` (for example `npx playwright test`)",
65
+ },
66
+ {
67
+ mode: "mixed",
68
+ bullet: "- `mixed` / `live-runtime` — combine runtime startup checks with interactive browser verification",
69
+ },
70
+ ];
42
71
  /**
43
72
  * Markdown block injected into plan/complete-slice prompts when the project
44
- * looks browser-facing. Returns null for CLI/library-only repos.
73
+ * looks browser-facing. Returns null for CLI/library-only repos. Guidance is
74
+ * composed from the resolved Browser Automation Engine so prompts never claim
75
+ * an engine the runtime is not using; `engineResolution` is injectable for
76
+ * tests and defaults to the ambient resolution.
45
77
  */
46
- export function buildWebAppUatGuidanceBlock(projectRoot) {
78
+ export function buildWebAppUatGuidanceBlock(projectRoot, engineResolution) {
47
79
  if (!detectWebApp(projectRoot))
48
80
  return null;
81
+ const resolvedEngine = engineResolution ?? resolveAmbientBrowserEngineResolution(projectRoot);
82
+ const browserToolsAvailable = resolvedEngine.engine !== "off";
49
83
  const playwrightScript = findPlaywrightTestScript(projectRoot);
50
84
  const hasPlaywright = hasPlaywrightTestDependency(projectRoot) || playwrightScript !== null;
51
85
  const lines = [
52
86
  "### Web App UAT (detected)",
53
87
  "",
54
- "This project looks browser-facing. GSD exposes Playwright-backed `browser_*` tools by default for run-uat.",
88
+ describeBrowserToolBacking(resolvedEngine),
55
89
  "",
56
90
  "**UAT modes (pick one per slice — do not use `artifact-driven` for browser steps):**",
57
- "- `browser-executable` — navigate to `http://localhost:…`, click, screenshot, assert via `browser_*` tools during run-uat",
58
- "- `runtime-executable` run an automated browser test command via `gsd_uat_exec` (for example `npx playwright test`)",
59
- "- `mixed` / `live-runtime` — combine runtime startup checks with interactive browser verification",
91
+ ...UAT_MODE_GUIDANCE
92
+ .filter(({ mode }) => browserToolsAvailable || !UAT_MODE_POLICIES[mode].browserTools)
93
+ .map(({ bullet }) => bullet),
60
94
  "",
61
95
  "**Planning / closeout rules:**",
62
96
  "- Preconditions must name the dev-server command and URL (for example `npm run dev` → `http://localhost:3000`)",
@@ -74,7 +108,10 @@ export function buildWebAppUatGuidanceBlock(projectRoot) {
74
108
  lines.push("- Name concrete spec paths in slice Verification (for example `e2e/smoke.spec.ts`)");
75
109
  }
76
110
  else {
77
- lines.push("", "**Playwright scaffolding (first UI slice):** no `playwright` / `@playwright/test` dependency yet.", "- Add a planning task that installs Playwright, adds `playwright.config.ts`, and creates a minimal smoke spec (for example `e2e/smoke.spec.ts`)", "- Task `verify` should run `npx playwright test` (or the focused spec) with a safe, simple command", "- Until specs exist, use `browser-executable` UAT with localhost preconditions and interactive `browser_*` checks at slice closeout");
111
+ lines.push("", "**Playwright scaffolding (first UI slice):** no `playwright` / `@playwright/test` dependency yet.", "- Add a planning task that installs Playwright, adds `playwright.config.ts`, and creates a minimal smoke spec (for example `e2e/smoke.spec.ts`)", "- Task `verify` should run `npx playwright test` (or the focused spec) with a safe, simple command");
112
+ if (browserToolsAvailable) {
113
+ lines.push("- Until specs exist, use `browser-executable` UAT with localhost preconditions and interactive `browser_*` checks at slice closeout");
114
+ }
78
115
  }
79
116
  return lines.join("\n");
80
117
  }
@@ -8,7 +8,7 @@ export const WORKFLOW_TOOL_ALIAS_NAMES = CONTRACT_WORKFLOW_TOOL_ALIAS_NAMES;
8
8
  export const DB_WORKFLOW_TOOL_NAMES = CONTRACT_WORKFLOW_TOOL_NAMES;
9
9
  export const WORKFLOW_TOOL_ALIAS_PAIRS = WORKFLOW_TOOL_CONTRACTS.flatMap((tool) => tool.aliases.map((alias) => ({ canonical: tool.canonicalName, alias })));
10
10
  export const WORKFLOW_TOOL_ALIAS_TO_CANONICAL = Object.fromEntries(WORKFLOW_TOOL_ALIAS_PAIRS.map(({ alias, canonical }) => [alias, canonical]));
11
- const WORKFLOW_MCP_ADAPTER_TOOL_NAMES = [
11
+ export const WORKFLOW_MCP_ADAPTER_TOOL_NAMES = [
12
12
  "gsd_cancel",
13
13
  "gsd_captures",
14
14
  "ask_user_questions",
@@ -0,0 +1,293 @@
1
+ // Project/App: gsd-pi
2
+ // File Purpose: Git checkout/stash/merge-state recovery primitives for worktree operations.
3
+ /**
4
+ * Worktree Git Recovery — the recurring-bug hot spot, in one place.
5
+ *
6
+ * Owns the verbs that recover a repository from interrupted or conflicting
7
+ * git operations during worktree transitions:
8
+ *
9
+ * - `checkoutBranchWithStashGuard` — branch switch with stash protection,
10
+ * including the stash-pop EEXIST collision recovery for untracked files
11
+ * (force-checkout + targeted stash drop; #645 broadened it beyond `.gsd/`,
12
+ * guarded by "no non-.gsd unmerged entries remain").
13
+ * - `removeMergeStateFiles` — clears SQUASH_MSG / MERGE_HEAD / etc. left by
14
+ * a failed merge so subsequent merges don't fail on stale state.
15
+ * - `cleanupConflictState` — merge-abort + index reset + state-file cleanup
16
+ * after a conflicted (including squash) merge.
17
+ * - stash helpers (`popStashByRef`, `stashRefFromError`,
18
+ * `stashAlreadyExistsFilesFromError`, `gsdJsonlFilesWithConflictMarkers`)
19
+ * used by the merge pipeline in auto-worktree.ts.
20
+ *
21
+ * Extracted from auto-worktree.ts so recovery fixes land here instead of as
22
+ * embedded special cases in a 2,600-line orchestration module, and so the
23
+ * rules can be tested against scripted git states.
24
+ *
25
+ * The State Reconciliation drift repair (`state-reconciliation/drift/
26
+ * merge-state.ts`) keeps its own merge-state primitive by design — drift
27
+ * repairs own their raw primitives (see CONTEXT.md, Drift repair).
28
+ */
29
+ import { execFileSync } from "node:child_process";
30
+ import { existsSync, readFileSync, unlinkSync } from "node:fs";
31
+ import { isAbsolute, join, resolve } from "node:path";
32
+ import { debugLog } from "./debug-logger.js";
33
+ import { logError, logWarning } from "./workflow-logger.js";
34
+ import { nativeAddPaths, nativeCheckoutBranch, nativeConflictFiles, nativeLsFiles, nativeMergeAbort, nativeWorkingTreeStatus, } from "./native-git-bridge.js";
35
+ import { resolveGitDir } from "./worktree-manager.js";
36
+ /**
37
+ * Pop the stash entry created with `stashMarker` in its subject, resolving it
38
+ * to a concrete `stash@{n}` ref first so a concurrent stash push cannot make
39
+ * `git stash pop` grab the wrong entry.
40
+ *
41
+ * If `stashMarker` is null or no longer present in the stash list (e.g. a
42
+ * concurrent process popped/dropped it), leaves the stash list untouched and
43
+ * returns null.
44
+ *
45
+ * Throws on pop failure so callers can handle conflict cases the same way
46
+ * they would with the prior `git stash pop` form. When throwing after a
47
+ * targeted pop attempt, the error is annotated with the targeted stash ref.
48
+ *
49
+ * (Issue #4980 HIGH-6)
50
+ */
51
+ export function popStashByRef(basePath, stashMarker) {
52
+ let popArg = null;
53
+ if (stashMarker) {
54
+ try {
55
+ const list = execFileSync("git", ["stash", "list", "--format=%gd%x00%s"], {
56
+ cwd: basePath,
57
+ stdio: ["ignore", "pipe", "pipe"],
58
+ encoding: "utf-8",
59
+ }).trim().split("\n").filter(Boolean);
60
+ for (const entry of list) {
61
+ const [ref, subject] = entry.split("\0");
62
+ if (ref && subject?.includes(stashMarker)) {
63
+ popArg = ref;
64
+ break;
65
+ }
66
+ }
67
+ }
68
+ catch (err) {
69
+ logWarning("worktree", `stash list lookup failed; leaving stash untouched: ${err instanceof Error ? err.message : String(err)}`);
70
+ }
71
+ }
72
+ if (!popArg) {
73
+ logWarning("worktree", "recorded stash entry could not be resolved; skipping automatic pop");
74
+ return null;
75
+ }
76
+ try {
77
+ execFileSync("git", ["stash", "pop", popArg], {
78
+ cwd: basePath,
79
+ stdio: ["ignore", "pipe", "pipe"],
80
+ encoding: "utf-8",
81
+ });
82
+ }
83
+ catch (err) {
84
+ if (err && typeof err === "object") {
85
+ err.stashRef = popArg;
86
+ }
87
+ throw err;
88
+ }
89
+ return popArg;
90
+ }
91
+ /**
92
+ * Extract a stash ref annotation injected by popStashByRef() when git stash
93
+ * pop fails and we need to conditionally drop the exact stash entry later.
94
+ */
95
+ export function stashRefFromError(err) {
96
+ if (!err || typeof err !== "object")
97
+ return null;
98
+ const stashRef = err.stashRef;
99
+ return typeof stashRef === "string" && stashRef.length > 0 ? stashRef : null;
100
+ }
101
+ export function stashAlreadyExistsFilesFromError(err) {
102
+ if (!err || typeof err !== "object")
103
+ return [];
104
+ const stderr = err.stderr;
105
+ const stderrText = typeof stderr === "string"
106
+ ? stderr
107
+ : stderr instanceof Uint8Array
108
+ ? Buffer.from(stderr).toString("utf-8")
109
+ : "";
110
+ const message = err instanceof Error ? err.message : String(err);
111
+ const text = `${stderrText}\n${message}`;
112
+ const files = new Set();
113
+ for (const line of text.split("\n")) {
114
+ const m = line.match(/^(.*?)\s+already exists, no checkout\s*$/i);
115
+ if (!m)
116
+ continue;
117
+ const filePath = m[1]?.trim();
118
+ if (filePath)
119
+ files.add(filePath);
120
+ }
121
+ return [...files];
122
+ }
123
+ /**
124
+ * Detect whether an on-disk file still contains unresolved merge conflict
125
+ * markers from a failed stash-pop or merge attempt.
126
+ *
127
+ * Returns false when the file cannot be read.
128
+ */
129
+ export function hasConflictMarkers(filePath) {
130
+ try {
131
+ const content = readFileSync(filePath, "utf-8");
132
+ return content.includes("<<<<<<<") && content.includes("=======") && content.includes(">>>>>>>");
133
+ }
134
+ catch {
135
+ return false;
136
+ }
137
+ }
138
+ export function gsdJsonlFilesWithConflictMarkers(basePath) {
139
+ return nativeLsFiles(basePath, ".gsd/*.jsonl").filter((f) => hasConflictMarkers(join(basePath, f)));
140
+ }
141
+ export function removeMergeStateFiles(basePath, contextLabel) {
142
+ try {
143
+ for (const f of ["SQUASH_MSG", "MERGE_MSG", "MERGE_MODE", "MERGE_HEAD", "AUTO_MERGE"]) {
144
+ const rawPath = execFileSync("git", ["rev-parse", "--git-path", f], {
145
+ cwd: basePath,
146
+ stdio: ["ignore", "pipe", "pipe"],
147
+ encoding: "utf-8",
148
+ }).trim();
149
+ const p = rawPath.length > 0
150
+ ? (isAbsolute(rawPath) ? rawPath : resolve(basePath, rawPath))
151
+ : join(resolveGitDir(basePath), f);
152
+ if (existsSync(p))
153
+ unlinkSync(p);
154
+ }
155
+ }
156
+ catch (err) {
157
+ logError("worktree", `${contextLabel} merge state cleanup failed: ${err instanceof Error ? err.message : String(err)}`);
158
+ }
159
+ }
160
+ export function cleanupConflictState(basePath) {
161
+ // Merge conflicts can leave unmerged index entries; merge-abort alone is not
162
+ // enough for squash merges (MERGE_HEAD is never written). Reset the merge
163
+ // index, then remove merge message files that native/libgit2 paths may have
164
+ // created.
165
+ try {
166
+ nativeMergeAbort(basePath);
167
+ }
168
+ catch (err) {
169
+ // MERGE_HEAD absent (squash merge path) — abort is a no-op, which is fine.
170
+ debugLog("conflict-cleanup:merge-abort-skipped", {
171
+ error: err instanceof Error ? err.message : String(err),
172
+ });
173
+ }
174
+ try {
175
+ execFileSync("git", ["reset", "--merge"], {
176
+ cwd: basePath,
177
+ stdio: ["ignore", "pipe", "pipe"],
178
+ encoding: "utf-8",
179
+ });
180
+ }
181
+ catch (err) {
182
+ logError("worktree", `git reset --merge failed after merge conflict: ${err instanceof Error ? err.message : String(err)}`);
183
+ }
184
+ removeMergeStateFiles(basePath, "conflict");
185
+ }
186
+ export function checkoutBranchWithStashGuard(basePath, branch, reason) {
187
+ let stashMarker = null;
188
+ let stashed = false;
189
+ const status = nativeWorkingTreeStatus(basePath).trim();
190
+ if (status.length > 0) {
191
+ stashMarker = `gsd-checkout-stash:${reason}:${process.pid}:${Date.now()}:${process.hrtime.bigint().toString(36)}`;
192
+ const stashListBefore = execFileSync("git", ["stash", "list"], {
193
+ cwd: basePath,
194
+ stdio: ["ignore", "pipe", "pipe"],
195
+ encoding: "utf-8",
196
+ });
197
+ execFileSync("git", ["stash", "push", "--include-untracked", "-m", `gsd: checkout stash [${stashMarker}]`], {
198
+ cwd: basePath,
199
+ stdio: ["ignore", "pipe", "pipe"],
200
+ encoding: "utf-8",
201
+ });
202
+ const stashListAfter = execFileSync("git", ["stash", "list"], {
203
+ cwd: basePath,
204
+ stdio: ["ignore", "pipe", "pipe"],
205
+ encoding: "utf-8",
206
+ });
207
+ stashed = stashListAfter !== stashListBefore;
208
+ }
209
+ // Checkout and stash-restore are split so we can distinguish two failure
210
+ // modes: (a) checkout failed → HEAD did not move, restore stash and rethrow;
211
+ // (b) checkout succeeded but stash pop failed → HEAD moved to `branch` but
212
+ // the working-tree changes remain in the stash list. We surface a distinct
213
+ // error in case (b) so callers don't assume the branch switch was rolled back.
214
+ try {
215
+ nativeCheckoutBranch(basePath, branch);
216
+ }
217
+ catch (checkoutErr) {
218
+ if (stashed) {
219
+ try {
220
+ popStashByRef(basePath, stashMarker);
221
+ }
222
+ catch (restoreErr) {
223
+ logWarning("worktree", `git stash pop failed during checkout restore: ${restoreErr instanceof Error ? restoreErr.message : String(restoreErr)}`);
224
+ }
225
+ }
226
+ throw checkoutErr;
227
+ }
228
+ if (stashed) {
229
+ try {
230
+ popStashByRef(basePath, stashMarker);
231
+ }
232
+ catch (popErr) {
233
+ const msg = popErr instanceof Error ? popErr.message : String(popErr);
234
+ const stderr = popErr && typeof popErr === "object"
235
+ ? popErr.stderr
236
+ : undefined;
237
+ const stderrText = typeof stderr === "string"
238
+ ? stderr
239
+ : stderr instanceof Uint8Array
240
+ ? Buffer.from(stderr).toString("utf-8")
241
+ : "";
242
+ const stashPopMessage = `${stderrText}\n${msg}`.trim();
243
+ const alreadyExists = stashAlreadyExistsFilesFromError(popErr);
244
+ const isUntrackedRestoreFailure = stashPopMessage.includes("could not restore untracked files from stash");
245
+ const stashRefForDrop = stashRefFromError(popErr);
246
+ const allConflictFiles = nativeConflictFiles(basePath);
247
+ const nonGsdUnmerged = allConflictFiles.filter((f) => !f.startsWith(".gsd/"));
248
+ const gsdUnmerged = allConflictFiles.filter((f) => f.startsWith(".gsd/"));
249
+ const gsdContentConflicts = isUntrackedRestoreFailure
250
+ ? gsdJsonlFilesWithConflictMarkers(basePath)
251
+ : [];
252
+ // Resolve ALL untracked-collision files by accepting HEAD — files in
253
+ // alreadyExists were untracked on the source branch by definition of the
254
+ // "already exists, no checkout" failure, so target HEAD is authoritative.
255
+ // gsdUnmerged: .gsd/ index conflicts left by the partial stash pop are
256
+ // also resolved via HEAD — .gsd/ runtime state is always authoritative
257
+ // on the target branch, so accepting HEAD is safe here too.
258
+ const resolvable = [...new Set([...alreadyExists, ...gsdContentConflicts, ...gsdUnmerged])];
259
+ if (isUntrackedRestoreFailure &&
260
+ resolvable.length > 0 &&
261
+ nonGsdUnmerged.length === 0) {
262
+ for (const f of resolvable) {
263
+ execFileSync("git", ["checkout", "HEAD", "--", f], {
264
+ cwd: basePath,
265
+ stdio: ["ignore", "pipe", "pipe"],
266
+ encoding: "utf-8",
267
+ });
268
+ nativeAddPaths(basePath, [f]);
269
+ }
270
+ if (stashRefForDrop) {
271
+ try {
272
+ execFileSync("git", ["stash", "drop", stashRefForDrop], {
273
+ cwd: basePath,
274
+ stdio: ["ignore", "pipe", "pipe"],
275
+ encoding: "utf-8",
276
+ });
277
+ }
278
+ catch (err) { /* stash may already be consumed */
279
+ logWarning("worktree", `git stash drop failed: ${err instanceof Error ? err.message : String(err)}`);
280
+ }
281
+ }
282
+ else {
283
+ logWarning("worktree", "recorded stash entry could not be resolved; skipping automatic drop");
284
+ }
285
+ return;
286
+ }
287
+ const wrapped = new Error(`checkout to '${branch}' succeeded but stash restore failed; working tree changes remain in the stash list. Original error: ${msg}`);
288
+ if (stashRefForDrop)
289
+ wrapped.stashRef = stashRefForDrop;
290
+ throw wrapped;
291
+ }
292
+ }
293
+ }
@@ -327,7 +327,15 @@ export function _enterMilestoneCore(s, deps, milestoneId, ctx, opts = {}) {
327
327
  // Handles the case where originalBasePath is falsy and basePath is itself
328
328
  // a worktree path — prevents double-nested worktree paths (#3729).
329
329
  const basePath = resolveWorktreeProjectRoot(s.basePath, s.originalBasePath);
330
- const mode = opts.modeOverride ?? getIsolationMode(basePath);
330
+ // A stranded-recovery session that adopted the milestone branch in the
331
+ // project root must keep re-entering in that mode: the root checkout holds
332
+ // the branch, so creating the canonical worktree would fail with "already
333
+ // in use by another worktree". The override clears when the recovered
334
+ // milestone merges (_mergeAndExit), restoring configured isolation for
335
+ // subsequent milestones.
336
+ const mode = opts.modeOverride ??
337
+ s.strandedRecoveryIsolationMode ??
338
+ getIsolationMode(basePath);
331
339
  if (s.isolationDegraded) {
332
340
  if (mode === "worktree") {
333
341
  try {
@@ -3,7 +3,8 @@
3
3
  /**
4
4
  * GSD Worktree Manager
5
5
  *
6
- * Creates and manages git worktrees under .gsd/worktrees/<name>/.
6
+ * Creates and manages git worktrees under .gsd-worktrees/<name>/ (canonical;
7
+ * legacy .gsd/worktrees/<name>/ stays recognized — see worktree-placement.ts).
7
8
  * Each worktree gets its own branch (worktree/<name>) and a full
8
9
  * working copy of the project, enabling parallel work streams.
9
10
  *
@@ -11,7 +12,7 @@
11
12
  * the main branch, then dispatches an LLM-guided merge flow.
12
13
  *
13
14
  * Flow:
14
- * 1. create() — git worktree add .gsd/worktrees/<name> -b worktree/<name>
15
+ * 1. create() — git worktree add .gsd-worktrees/<name> -b worktree/<name>
15
16
  * 2. user works in the worktree (new plans, milestones, etc.)
16
17
  * 3. merge() — LLM-guided reconciliation of .gsd/ artifacts back to main
17
18
  * 4. remove() — git worktree remove + branch cleanup
@@ -24,6 +25,7 @@ import { logWarning } from "./workflow-logger.js";
24
25
  import { nativeBranchList, nativeBranchDelete, nativeBranchExists, nativeBranchForceReset, nativeCommit, nativeDetectMainBranch, nativeDiffContent, nativeDiffNameStatus, nativeDiffNumstat, nativeGetCurrentBranch, nativeIsAncestor, nativeLogOneline, nativeMergeSquash, nativeWorktreeAdd, nativeWorktreeList, nativeWorktreePrune, nativeWorktreeRemove, } from "./native-git-bridge.js";
25
26
  import { emitCanonicalRootRedirect } from "./worktree-telemetry.js";
26
27
  import { isGsdWorktreePath, normalizeWorktreePathForCompare, resolveWorktreeProjectRoot, } from "./worktree-root.js";
28
+ import { canonicalWorktreesDir, worktreePathFor, worktreesDirs } from "./worktree-placement.js";
27
29
  function deleteBranchIfPresent(basePath, branch, warningPrefix) {
28
30
  try {
29
31
  if (!nativeBranchExists(basePath, branch))
@@ -81,30 +83,39 @@ export function resolveGitDir(basePath) {
81
83
  }
82
84
  return gitPath;
83
85
  }
86
+ /** Canonical container for new worktrees. For scans that must also see legacy
87
+ * worktrees, use allWorktreesDirs(). */
84
88
  export function worktreesDir(basePath) {
85
- return join(resolveWorktreeProjectRoot(basePath), ".gsd", "worktrees");
89
+ return canonicalWorktreesDir(resolveWorktreeProjectRoot(basePath));
86
90
  }
91
+ /** Every container a GSD worktree may live in (canonical + legacy), canonical first. */
92
+ export function allWorktreesDirs(basePath) {
93
+ return worktreesDirs(resolveWorktreeProjectRoot(basePath));
94
+ }
95
+ /** Path for worktree `name` — an existing legacy worktree keeps its location. */
87
96
  export function worktreePath(basePath, name) {
88
- return join(worktreesDir(basePath), name);
97
+ return worktreePathFor(resolveWorktreeProjectRoot(basePath), name);
89
98
  }
90
99
  export function worktreeBranchName(name) {
91
100
  return `worktree/${name}`;
92
101
  }
93
102
  /**
94
- * Validate that a path is inside the .gsd/worktrees/ directory.
95
- * Resolves symlinks and normalizes ".." traversals before comparison
96
- * so that a symlink-resolved or crafted path cannot escape containment.
103
+ * Validate that a path is inside a GSD worktrees container (canonical
104
+ * .gsd-worktrees/ or legacy .gsd/worktrees/). Resolves symlinks and
105
+ * normalizes ".." traversals before comparison so that a symlink-resolved
106
+ * or crafted path cannot escape containment.
97
107
  *
98
108
  * Used as a safety gate before any destructive operation (rmSync,
99
109
  * nativeWorktreeRemove --force) to prevent #2365-style data loss.
100
110
  */
101
111
  export function isInsideWorktreesDir(basePath, targetPath) {
102
- const wtDirPath = worktreesDir(basePath);
103
- const wtDir = existsSync(wtDirPath) ? realpathSync(wtDirPath) : resolve(wtDirPath);
104
112
  const resolved = existsSync(targetPath) ? realpathSync(targetPath) : resolve(targetPath);
105
- // The resolved path must start with the worktrees dir followed by a separator,
106
- // not merely be a prefix match (e.g. ".gsd/worktrees-extra" must not match).
107
- return resolved === wtDir || resolved.startsWith(wtDir + sep);
113
+ return allWorktreesDirs(basePath).some((wtDirPath) => {
114
+ const wtDir = existsSync(wtDirPath) ? realpathSync(wtDirPath) : resolve(wtDirPath);
115
+ // The resolved path must start with the worktrees dir followed by a separator,
116
+ // not merely be a prefix match (e.g. ".gsd/worktrees-extra" must not match).
117
+ return resolved === wtDir || resolved.startsWith(wtDir + sep);
118
+ });
108
119
  }
109
120
  function isRegisteredGitWorktreeAtPath(basePath, wtPath) {
110
121
  try {
@@ -200,11 +211,11 @@ export function buildManualValidationGuidance(basePath, milestoneId, opts = {})
200
211
  if (!milestoneId)
201
212
  return null;
202
213
  const validationRoot = resolveCanonicalMilestoneRoot(basePath, milestoneId);
203
- const inWorktree = validationRoot.includes(`${sep}.gsd${sep}worktrees${sep}`);
214
+ const inWorktree = isGsdWorktreePath(validationRoot);
204
215
  const lines = [`Validate the work here: ${validationRoot}`];
205
216
  if (inWorktree) {
206
- lines.push("This milestone runs in a git worktree, so the code lives under the hidden " +
207
- `\`.gsd/worktrees/\` path. Open it with: cd "${validationRoot}"`);
217
+ lines.push("This milestone runs in a git worktree, so the code lives under the " +
218
+ `GSD worktrees directory. Open it with: cd "${validationRoot}"`);
208
219
  }
209
220
  if (opts.uatPath) {
210
221
  lines.push(`Follow the UAT checklist at: ${opts.uatPath}`);
@@ -224,21 +235,29 @@ export function createWorktree(basePath, name, opts = {}) {
224
235
  if (!/^[a-zA-Z0-9_-]+$/.test(name)) {
225
236
  throw new GSDError(GSD_PARSE_ERROR, `Invalid worktree name "${name}". Use only letters, numbers, hyphens, and underscores.`);
226
237
  }
227
- const wtPath = worktreePath(basePath, name);
238
+ const existingPath = worktreePath(basePath, name);
228
239
  const branch = opts.branch ?? worktreeBranchName(name);
229
- if (existsSync(wtPath)) {
240
+ if (existsSync(existingPath)) {
230
241
  // A valid git worktree is registered in `git worktree list` and has a .git
231
242
  // *file* with a gitdir: pointer. Leftover directories (no .git, a standalone
232
243
  // .git directory from accidental `git init`, or an orphan pointer) block
233
244
  // creation unless removed.
234
- if (isRegisteredGitWorktreeAtPath(basePath, wtPath)) {
235
- throw new GSDError(GSD_STALE_STATE, `Worktree "${name}" already exists at ${wtPath}`);
245
+ if (isRegisteredGitWorktreeAtPath(basePath, existingPath)) {
246
+ throw new GSDError(GSD_STALE_STATE, `Worktree "${name}" already exists at ${existingPath}`);
236
247
  }
237
- removeStaleWorktreeDirectory(wtPath, name);
248
+ removeStaleWorktreeDirectory(existingPath, name);
238
249
  }
239
- // Ensure the .gsd/worktrees/ directory exists
250
+ // New worktrees always land in the canonical container, even when a stale
251
+ // legacy directory was just cleaned up.
240
252
  const wtDir = worktreesDir(basePath);
253
+ const wtPath = join(wtDir, name);
241
254
  mkdirSync(wtDir, { recursive: true });
255
+ // When existingPath resolved to a legacy location, the canonical target may
256
+ // still hold a stale directory from a prior aborted creation (no .git marker).
257
+ // Remove it so git worktree add does not fail with "path already exists".
258
+ if (existingPath !== wtPath && existsSync(wtPath) && !isRegisteredGitWorktreeAtPath(basePath, wtPath)) {
259
+ removeStaleWorktreeDirectory(wtPath, name);
260
+ }
242
261
  // Prune any stale worktree entries from a previous removal
243
262
  nativeWorktreePrune(basePath);
244
263
  // Use the explicit start point (e.g. integration branch) if provided,
@@ -305,7 +324,8 @@ export function createWorktree(basePath, name, opts = {}) {
305
324
  }
306
325
  /**
307
326
  * List all GSD-managed worktrees.
308
- * Uses native worktree list and filters to those under .gsd/worktrees/.
327
+ * Uses native worktree list and filters to those under a GSD worktrees
328
+ * container (canonical .gsd-worktrees/ or legacy .gsd/worktrees/).
309
329
  */
310
330
  export function listWorktrees(basePath) {
311
331
  basePath = normalizeBasePathForWorktreeOps(basePath);
@@ -315,12 +335,8 @@ export function listWorktrees(basePath) {
315
335
  }
316
336
  const seenRoots = new Set();
317
337
  const worktreeRoots = baseVariants
318
- .map(baseVariant => {
319
- const path = join(baseVariant, ".gsd", "worktrees");
320
- return {
321
- normalized: normalizePathForComparison(path),
322
- };
323
- })
338
+ .flatMap(baseVariant => worktreesDirs(baseVariant))
339
+ .map(path => ({ normalized: normalizePathForComparison(path) }))
324
340
  .filter(root => {
325
341
  if (seenRoots.has(root.normalized))
326
342
  return false;
@@ -645,6 +661,7 @@ export function removeWorktree(basePath, name, opts = {}) {
645
661
  * This module uses a split representation (paths/exact/prefixes) for efficient matching.
646
662
  */
647
663
  const SKIP_PATHS = [
664
+ ".gsd-worktrees/",
648
665
  ".gsd/worktrees/",
649
666
  ".gsd/runtime/",
650
667
  ".gsd/activity/",
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Worktree Placement module — owns WHERE GSD worktrees physically live.
3
+ *
4
+ * Canonical placement: `<projectRoot>/.gsd-worktrees/<name>` — a real
5
+ * directory that never crosses the `.gsd` symlink managed by repo-identity.
6
+ * Under the external-state layout (`.gsd → ~/.gsd/projects/<hash>/`), the
7
+ * legacy `.gsd/worktrees/` location materialised worktrees inside the user's
8
+ * home directory behind an opaque hash path; the canonical sibling keeps the
9
+ * working copy at the project root regardless of where `.gsd` state lives.
10
+ *
11
+ * Legacy placement (`<projectRoot>/.gsd/worktrees/<name>`, possibly resolving
12
+ * through the symlink to `~/.gsd/projects/<hash>/worktrees/<name>`) stays
13
+ * recognized so in-flight milestones keep working across upgrades:
14
+ * - creation always uses the canonical location;
15
+ * - resolution prefers an existing legacy worktree for the same name;
16
+ * - containment checks accept membership in either location.
17
+ *
18
+ * Path → project identification lives in worktree-root.ts; this module owns
19
+ * only the forward direction (project + name → physical path).
20
+ */
21
+ import { existsSync } from "node:fs";
22
+ import { join } from "node:path";
23
+ /** Directory name of the canonical worktrees container at the project root. */
24
+ export const CANONICAL_WORKTREES_DIRNAME = ".gsd-worktrees";
25
+ /** Canonical container for newly created worktrees. Never crosses the `.gsd` symlink. */
26
+ export function canonicalWorktreesDir(projectRoot) {
27
+ return join(projectRoot, CANONICAL_WORKTREES_DIRNAME);
28
+ }
29
+ /** Legacy container (`.gsd/worktrees/`) — may resolve through the external-state symlink. */
30
+ export function legacyWorktreesDir(projectRoot) {
31
+ return join(projectRoot, ".gsd", "worktrees");
32
+ }
33
+ /**
34
+ * All containers a GSD worktree may live in, canonical first.
35
+ * Use for listing, scanning, and containment checks.
36
+ */
37
+ export function worktreesDirs(projectRoot) {
38
+ return [canonicalWorktreesDir(projectRoot), legacyWorktreesDir(projectRoot)];
39
+ }
40
+ /**
41
+ * Physical path for the worktree `name` under `projectRoot`.
42
+ *
43
+ * Canonical wins only when it has a `.git` marker (i.e. is a live worktree).
44
+ * A bare directory with no `.git` — a stale leftover from an aborted create
45
+ * or a partial cleanup — does not shadow an existing legacy worktree, so the
46
+ * legacy path is tried next. The legacy check remains a plain existsSync;
47
+ * callers that need a *registered* worktree validate the `.git` marker
48
+ * themselves (resolveCanonicalMilestoneRoot, getAutoWorktreePath).
49
+ * Falls back to canonical for new-worktree creation when neither path exists.
50
+ */
51
+ export function worktreePathFor(projectRoot, name) {
52
+ const canonical = join(canonicalWorktreesDir(projectRoot), name);
53
+ if (existsSync(canonical) && existsSync(join(canonical, ".git")))
54
+ return canonical;
55
+ const legacy = join(legacyWorktreesDir(projectRoot), name);
56
+ if (existsSync(legacy))
57
+ return legacy;
58
+ return canonical;
59
+ }
@@ -8,19 +8,23 @@
8
8
  import { readdirSync } from "node:fs";
9
9
  import { enterAutoWorktree, getAutoWorktreePath } from "./auto-worktree.js";
10
10
  import { getIsolationMode } from "./preferences.js";
11
- import { worktreesDir } from "./worktree-manager.js";
11
+ import { allWorktreesDirs } from "./worktree-manager.js";
12
12
  import { isGsdWorktreePath, resolveWorktreeProjectRoot } from "./worktree-root.js";
13
13
  /**
14
- * Enumerate the live (valid git) auto-worktrees under <projectRoot>/.gsd/worktrees/.
14
+ * Enumerate the live (valid git) auto-worktrees in the project's worktree
15
+ * containers (canonical .gsd-worktrees/ and legacy .gsd/worktrees/).
15
16
  * Reuses getAutoWorktreePath's validation so stray directories are ignored.
16
17
  */
17
18
  function liveMilestoneWorktrees(projectRoot) {
18
- let names;
19
- try {
20
- names = readdirSync(worktreesDir(projectRoot));
21
- }
22
- catch {
23
- return [];
19
+ const names = new Set();
20
+ for (const dir of allWorktreesDirs(projectRoot)) {
21
+ try {
22
+ for (const name of readdirSync(dir))
23
+ names.add(name);
24
+ }
25
+ catch {
26
+ // container absent — skip
27
+ }
24
28
  }
25
29
  const live = [];
26
30
  for (const id of names) {