@loucompanion/forge-bridge 0.1.3-dev.f66395c3ac21 → 0.1.4-dev.0098fdb4e213

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 (381) hide show
  1. package/README.md +306 -1
  2. package/dist/bridge/bridge-chat-provider-command.d.ts +19 -0
  3. package/dist/bridge/bridge-chat-provider-command.js +132 -0
  4. package/dist/bridge/bridge-chat.types.d.ts +121 -0
  5. package/dist/bridge/bridge-chat.types.js +416 -0
  6. package/dist/bridge/bridge-state-file.d.ts +161 -0
  7. package/dist/bridge/bridge-state-file.js +376 -0
  8. package/dist/bridge/bridge-state-io.d.ts +11 -0
  9. package/dist/bridge/bridge-state-io.js +50 -0
  10. package/dist/bridge/bridge-state-lock.d.ts +11 -0
  11. package/dist/bridge/bridge-state-lock.js +102 -0
  12. package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
  13. package/dist/bridge/bridge-state-unpublished.js +111 -0
  14. package/dist/bridge/bridge.base.d.ts +18 -1
  15. package/dist/bridge/bridge.service.d.ts +216 -4
  16. package/dist/bridge/bridge.service.js +2574 -90
  17. package/dist/bridge/bridge.types.d.ts +245 -2
  18. package/dist/bridge/dispatch-result-outbox.d.ts +35 -0
  19. package/dist/bridge/dispatch-result-outbox.js +87 -0
  20. package/dist/bridge/dispatch-result-worker.d.ts +2 -0
  21. package/dist/bridge/dispatch-result-worker.js +122 -0
  22. package/dist/bridge/in-flight-registry.d.ts +62 -0
  23. package/dist/bridge/in-flight-registry.js +207 -0
  24. package/dist/bridge/internals.d.ts +2 -0
  25. package/dist/bridge/internals.js +1 -0
  26. package/dist/bridge/local-yield-flag.d.ts +6 -0
  27. package/dist/bridge/local-yield-flag.js +34 -0
  28. package/dist/bridge/readiness-result-outbox.d.ts +25 -0
  29. package/dist/bridge/readiness-result-outbox.js +74 -0
  30. package/dist/bridge/readiness-result-worker.d.ts +2 -0
  31. package/dist/bridge/readiness-result-worker.js +121 -0
  32. package/dist/bridge/runner-host-capabilities.d.ts +20 -0
  33. package/dist/bridge/runner-host-capabilities.js +110 -0
  34. package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
  35. package/dist/bridge/sandbox-resource-accounting.js +150 -0
  36. package/dist/bridge/test-postgres-capability.d.ts +14 -0
  37. package/dist/bridge/test-postgres-capability.js +120 -0
  38. package/dist/cleanup/cleanup-wip.d.ts +12 -0
  39. package/dist/cleanup/cleanup-wip.js +66 -0
  40. package/dist/cleanup/cleanup.service.d.ts +33 -2
  41. package/dist/cleanup/cleanup.service.js +477 -3
  42. package/dist/cleanup/cleanup.types.d.ts +16 -0
  43. package/dist/cleanup/forge-owned-paths.d.ts +9 -0
  44. package/dist/cleanup/forge-owned-paths.js +53 -0
  45. package/dist/cleanup/host-runtime-ledger.d.ts +7 -0
  46. package/dist/cleanup/host-runtime-ledger.js +130 -0
  47. package/dist/cleanup/index.d.ts +1 -1
  48. package/dist/cleanup/index.js +1 -1
  49. package/dist/cleanup/internals.d.ts +2 -2
  50. package/dist/cleanup/internals.js +1 -1
  51. package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
  52. package/dist/cleanup/managed-branch-sweep.js +111 -0
  53. package/dist/cli/cli.help.d.ts +2 -0
  54. package/dist/cli/cli.help.js +279 -0
  55. package/dist/cli/cli.service.d.ts +69 -12
  56. package/dist/cli/cli.service.js +557 -382
  57. package/dist/cli/idle-status.d.ts +84 -0
  58. package/dist/cli/idle-status.js +181 -0
  59. package/dist/cli/local-config.d.ts +13 -0
  60. package/dist/cli/local-config.js +82 -6
  61. package/dist/cli/provider-cli-detection.d.ts +10 -0
  62. package/dist/cli/provider-cli-detection.js +160 -0
  63. package/dist/runtime/aspnet-runtime-prebuild.d.ts +41 -0
  64. package/dist/runtime/aspnet-runtime-prebuild.js +474 -0
  65. package/dist/runtime/attempt-database-broker.d.ts +89 -0
  66. package/dist/runtime/attempt-database-broker.js +390 -0
  67. package/dist/runtime/attempt-node-runtime-launcher.d.ts +18 -0
  68. package/dist/runtime/attempt-node-runtime-launcher.js +140 -0
  69. package/dist/runtime/attempt-path-operation.d.ts +21 -0
  70. package/dist/runtime/attempt-path-operation.js +94 -0
  71. package/dist/runtime/attempt-private-directory.d.ts +6 -0
  72. package/dist/runtime/attempt-private-directory.js +54 -0
  73. package/dist/runtime/attempt-process-supervisor-registry.d.ts +20 -0
  74. package/dist/runtime/attempt-process-supervisor-registry.js +64 -0
  75. package/dist/runtime/attempt-process-supervisor.d.ts +121 -0
  76. package/dist/runtime/attempt-process-supervisor.js +471 -0
  77. package/dist/runtime/canonical-source-file.d.ts +3 -0
  78. package/dist/runtime/canonical-source-file.js +54 -0
  79. package/dist/runtime/docker-engine-probe.d.ts +95 -0
  80. package/dist/runtime/docker-engine-probe.js +340 -0
  81. package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
  82. package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
  83. package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
  84. package/dist/runtime/ephemeral-test-postgres.js +303 -0
  85. package/dist/runtime/generated-output-reset.d.ts +20 -0
  86. package/dist/runtime/generated-output-reset.js +157 -0
  87. package/dist/runtime/host-database-capability-boundary.d.ts +16 -0
  88. package/dist/runtime/host-database-capability-boundary.js +63 -0
  89. package/dist/runtime/host-diagnostics.d.ts +11 -0
  90. package/dist/runtime/host-diagnostics.js +192 -0
  91. package/dist/runtime/host-execution-root.d.ts +4 -0
  92. package/dist/runtime/host-execution-root.js +39 -0
  93. package/dist/runtime/host-facts.d.ts +36 -0
  94. package/dist/runtime/host-facts.js +95 -0
  95. package/dist/runtime/host-listener-inspector.d.ts +51 -0
  96. package/dist/runtime/host-listener-inspector.js +385 -0
  97. package/dist/runtime/host-load-admission.d.ts +67 -0
  98. package/dist/runtime/host-load-admission.js +99 -0
  99. package/dist/runtime/host-load-child-environment.d.ts +27 -0
  100. package/dist/runtime/host-load-child-environment.js +76 -0
  101. package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
  102. package/dist/runtime/host-load-forge-cgroups.js +140 -0
  103. package/dist/runtime/host-load-governor-config.d.ts +52 -0
  104. package/dist/runtime/host-load-governor-config.js +83 -0
  105. package/dist/runtime/host-load-governor.d.ts +186 -0
  106. package/dist/runtime/host-load-governor.js +632 -0
  107. package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
  108. package/dist/runtime/host-load-ledger-lock.js +187 -0
  109. package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
  110. package/dist/runtime/host-load-runtime-settings.js +80 -0
  111. package/dist/runtime/host-load-sampler.d.ts +156 -0
  112. package/dist/runtime/host-load-sampler.js +298 -0
  113. package/dist/runtime/host-load-step-class.d.ts +70 -0
  114. package/dist/runtime/host-load-step-class.js +161 -0
  115. package/dist/runtime/host-load-step-reaper.d.ts +27 -0
  116. package/dist/runtime/host-load-step-reaper.js +95 -0
  117. package/dist/runtime/host-load-step-run.d.ts +73 -0
  118. package/dist/runtime/host-load-step-run.js +102 -0
  119. package/dist/runtime/host-load-test-slot.d.ts +43 -0
  120. package/dist/runtime/host-load-test-slot.js +81 -0
  121. package/dist/runtime/host-load-token-ledger.d.ts +200 -0
  122. package/dist/runtime/host-load-token-ledger.js +453 -0
  123. package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
  124. package/dist/runtime/host-load-windows-cpu.js +85 -0
  125. package/dist/runtime/host-port-broker.d.ts +76 -0
  126. package/dist/runtime/host-port-broker.js +333 -0
  127. package/dist/runtime/host-pressure-stall.d.ts +61 -0
  128. package/dist/runtime/host-pressure-stall.js +168 -0
  129. package/dist/runtime/host-runtime-contract.d.ts +74 -0
  130. package/dist/runtime/host-runtime-contract.js +846 -0
  131. package/dist/runtime/host-runtime-lease.d.ts +287 -0
  132. package/dist/runtime/host-runtime-lease.js +2763 -0
  133. package/dist/runtime/host-runtime-promotion.d.ts +55 -0
  134. package/dist/runtime/host-runtime-promotion.js +254 -0
  135. package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
  136. package/dist/runtime/host-runtime-requirements-check.js +29 -0
  137. package/dist/runtime/host-runtime-requirements.d.ts +36 -0
  138. package/dist/runtime/host-runtime-requirements.js +117 -0
  139. package/dist/runtime/managed-command-teardown.d.ts +62 -0
  140. package/dist/runtime/managed-command-teardown.js +596 -0
  141. package/dist/runtime/memory-capacity.d.ts +70 -0
  142. package/dist/runtime/memory-capacity.js +123 -0
  143. package/dist/runtime/native-test-postgres-fallback.d.ts +69 -0
  144. package/dist/runtime/native-test-postgres-fallback.js +143 -0
  145. package/dist/runtime/node-host-runtime-adapter.d.ts +54 -0
  146. package/dist/runtime/node-host-runtime-adapter.js +286 -0
  147. package/dist/runtime/pinned-directory-process.d.ts +9 -0
  148. package/dist/runtime/pinned-directory-process.js +61 -0
  149. package/dist/runtime/pinned-source-directory.d.ts +17 -0
  150. package/dist/runtime/pinned-source-directory.js +94 -0
  151. package/dist/runtime/playwright-browser-cache.d.ts +39 -0
  152. package/dist/runtime/playwright-browser-cache.js +227 -0
  153. package/dist/runtime/playwright-host-runtime-adapter.d.ts +39 -0
  154. package/dist/runtime/playwright-host-runtime-adapter.js +274 -0
  155. package/dist/runtime/prepared-runtime-identity.d.ts +6 -0
  156. package/dist/runtime/prepared-runtime-identity.js +218 -0
  157. package/dist/runtime/prepared-runtime-readiness.d.ts +30 -0
  158. package/dist/runtime/prepared-runtime-readiness.js +285 -0
  159. package/dist/runtime/runner-settings.d.ts +104 -0
  160. package/dist/runtime/runner-settings.js +236 -0
  161. package/dist/runtime/runtime-isolation-lease.d.ts +67 -0
  162. package/dist/runtime/runtime-isolation-lease.js +161 -0
  163. package/dist/runtime/workspace-resource-estimator.d.ts +17 -0
  164. package/dist/runtime/workspace-resource-estimator.js +174 -0
  165. package/dist/sandbox/command-runner.d.ts +4 -0
  166. package/dist/sandbox/command-runner.js +47 -0
  167. package/dist/sandbox/contract.d.ts +5 -0
  168. package/dist/sandbox/contract.js +276 -0
  169. package/dist/sandbox/event-budget.d.ts +11 -0
  170. package/dist/sandbox/event-budget.js +27 -0
  171. package/dist/sandbox/host-capacity-broker.d.ts +115 -0
  172. package/dist/sandbox/host-capacity-broker.js +336 -0
  173. package/dist/sandbox/image-policy.d.ts +35 -0
  174. package/dist/sandbox/image-policy.js +247 -0
  175. package/dist/sandbox/index.d.ts +5 -0
  176. package/dist/sandbox/index.js +5 -0
  177. package/dist/sandbox/lease-watchdog.d.ts +18 -0
  178. package/dist/sandbox/lease-watchdog.js +67 -0
  179. package/dist/sandbox/managed-branch.d.ts +13 -0
  180. package/dist/sandbox/managed-branch.js +36 -0
  181. package/dist/sandbox/preflight.d.ts +84 -0
  182. package/dist/sandbox/preflight.js +521 -0
  183. package/dist/sandbox/process.d.ts +20 -0
  184. package/dist/sandbox/process.js +209 -0
  185. package/dist/sandbox/provider-auth/codex.d.ts +26 -0
  186. package/dist/sandbox/provider-auth/codex.js +212 -0
  187. package/dist/sandbox/repository-lock.d.ts +6 -0
  188. package/dist/sandbox/repository-lock.js +129 -0
  189. package/dist/sandbox/runtime.d.ts +311 -0
  190. package/dist/sandbox/runtime.js +2407 -0
  191. package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
  192. package/dist/sandbox/sandbox-cgroups.js +42 -0
  193. package/dist/sandbox/sandbox.types.d.ts +93 -0
  194. package/dist/sandbox/sandbox.types.js +1 -0
  195. package/dist/sandbox/smoke.d.ts +76 -0
  196. package/dist/sandbox/smoke.js +380 -0
  197. package/dist/sandbox/worker-supervisor.d.ts +13 -0
  198. package/dist/sandbox/worker-supervisor.js +36 -0
  199. package/dist/sandbox/worker.d.ts +1 -0
  200. package/dist/sandbox/worker.js +225 -0
  201. package/dist/sandbox/workspace.service.d.ts +13 -0
  202. package/dist/sandbox/workspace.service.js +74 -0
  203. package/dist/session/architect-waits.d.ts +2 -0
  204. package/dist/session/architect-waits.js +138 -0
  205. package/dist/session/managed-attempt-tools.d.ts +48 -0
  206. package/dist/session/managed-attempt-tools.js +1299 -0
  207. package/dist/session/managed-build-coordinator.d.ts +5 -0
  208. package/dist/session/managed-build-coordinator.js +109 -0
  209. package/dist/session/managed-build-receipt.d.ts +26 -0
  210. package/dist/session/managed-build-receipt.js +342 -0
  211. package/dist/session/managed-command-host-load.d.ts +47 -0
  212. package/dist/session/managed-command-host-load.js +83 -0
  213. package/dist/session/managed-verification-timeouts.d.ts +8 -0
  214. package/dist/session/managed-verification-timeouts.js +17 -0
  215. package/dist/session/mcp-argument-coercion.d.ts +23 -0
  216. package/dist/session/mcp-argument-coercion.js +121 -0
  217. package/dist/session/phase-completion.artifacts.d.ts +34 -0
  218. package/dist/session/phase-completion.artifacts.js +903 -0
  219. package/dist/session/phase-completion.command-validation.d.ts +7 -0
  220. package/dist/session/phase-completion.command-validation.js +77 -0
  221. package/dist/session/phase-completion.d.ts +65 -42
  222. package/dist/session/phase-completion.helpers.d.ts +117 -0
  223. package/dist/session/phase-completion.helpers.js +708 -0
  224. package/dist/session/phase-completion.js +130 -3007
  225. package/dist/session/phase-completion.mcp-args.d.ts +9 -0
  226. package/dist/session/phase-completion.mcp-args.js +156 -0
  227. package/dist/session/phase-completion.prompts.d.ts +14 -0
  228. package/dist/session/phase-completion.prompts.js +238 -0
  229. package/dist/session/phase-completion.runtime.d.ts +43 -0
  230. package/dist/session/phase-completion.runtime.js +721 -0
  231. package/dist/session/phase-completion.schema-parts.d.ts +19 -0
  232. package/dist/session/phase-completion.schema-parts.js +188 -0
  233. package/dist/session/phase-completion.schemas.d.ts +3 -0
  234. package/dist/session/phase-completion.schemas.js +836 -0
  235. package/dist/session/phase-completion.validation.d.ts +37 -0
  236. package/dist/session/phase-completion.validation.js +874 -0
  237. package/dist/session/pre-publication-host-load.d.ts +27 -0
  238. package/dist/session/pre-publication-host-load.js +111 -0
  239. package/dist/session/pre-publication-native-postgres.d.ts +30 -0
  240. package/dist/session/pre-publication-native-postgres.js +111 -0
  241. package/dist/session/pre-publication-pass.d.ts +61 -0
  242. package/dist/session/pre-publication-pass.js +148 -0
  243. package/dist/session/pre-publication-process.d.ts +23 -0
  244. package/dist/session/pre-publication-process.js +109 -0
  245. package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
  246. package/dist/session/pre-publication-skipped-tests.js +109 -0
  247. package/dist/session/pre-publication-step-execution.d.ts +12 -0
  248. package/dist/session/pre-publication-step-execution.js +50 -0
  249. package/dist/session/pre-publication-validation.d.ts +91 -0
  250. package/dist/session/pre-publication-validation.js +670 -0
  251. package/dist/session/provider-cli/bridge-cli.conformance-fixtures.d.ts +72 -0
  252. package/dist/session/provider-cli/bridge-cli.conformance-fixtures.js +462 -0
  253. package/dist/session/provider-cli/ci-repair-readiness.d.ts +16 -0
  254. package/dist/session/provider-cli/ci-repair-readiness.js +110 -0
  255. package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
  256. package/dist/session/provider-cli/claude-background-work.js +181 -0
  257. package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
  258. package/dist/session/provider-cli/host-build-lock.js +30 -0
  259. package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
  260. package/dist/session/provider-cli/pre-publication-repair.js +276 -0
  261. package/dist/session/provider-cli/provider-cli.artifacts.d.ts +96 -0
  262. package/dist/session/provider-cli/provider-cli.artifacts.js +818 -0
  263. package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
  264. package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
  265. package/dist/session/provider-cli/provider-cli.child-environment.js +75 -0
  266. package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
  267. package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
  268. package/dist/session/provider-cli/provider-cli.deterministic-payloads.d.ts +12 -0
  269. package/dist/session/provider-cli/provider-cli.deterministic-payloads.js +279 -0
  270. package/dist/session/provider-cli/provider-cli.deterministic.d.ts +14 -0
  271. package/dist/session/provider-cli/provider-cli.deterministic.js +407 -0
  272. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
  273. package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
  274. package/dist/session/provider-cli/provider-cli.process.d.ts +114 -0
  275. package/dist/session/provider-cli/provider-cli.process.js +757 -0
  276. package/dist/session/provider-cli/provider-cli.prompts.d.ts +62 -0
  277. package/dist/session/provider-cli/provider-cli.prompts.js +770 -0
  278. package/dist/session/provider-cli/provider-cli.qa-sidecars.d.ts +11 -0
  279. package/dist/session/provider-cli/provider-cli.qa-sidecars.js +66 -0
  280. package/dist/session/provider-cli/provider-cli.repair-epoch.d.ts +6 -0
  281. package/dist/session/provider-cli/provider-cli.repair-epoch.js +11 -0
  282. package/dist/session/provider-cli/provider-cli.runtime.d.ts +30 -0
  283. package/dist/session/provider-cli/provider-cli.runtime.js +120 -0
  284. package/dist/session/provider-cli/provider-cli.service.d.ts +53 -53
  285. package/dist/session/provider-cli/provider-cli.service.js +1299 -2523
  286. package/dist/session/provider-cli/provider-cli.types.d.ts +38 -0
  287. package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
  288. package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
  289. package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
  290. package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
  291. package/dist/session/provider-cli/provider-in-flight-work.d.ts +10 -0
  292. package/dist/session/provider-cli/provider-in-flight-work.js +92 -0
  293. package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
  294. package/dist/session/provider-cli/provider-output-pipes.js +67 -0
  295. package/dist/session/provider-cli/provider-output-state.d.ts +40 -0
  296. package/dist/session/provider-cli/provider-output-state.js +832 -0
  297. package/dist/session/provider-cli/provider-usage.d.ts +9 -1
  298. package/dist/session/provider-cli/provider-usage.js +28 -5
  299. package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
  300. package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
  301. package/dist/session/publishable-worktree-changes.d.ts +54 -0
  302. package/dist/session/publishable-worktree-changes.js +193 -0
  303. package/dist/session/qa-sidecar-validation.d.ts +6 -0
  304. package/dist/session/qa-sidecar-validation.js +28 -0
  305. package/dist/session/sandbox-host-capacity-gate.d.ts +51 -0
  306. package/dist/session/sandbox-host-capacity-gate.js +257 -0
  307. package/dist/session/session-redaction.d.ts +3 -0
  308. package/dist/session/session-redaction.js +298 -0
  309. package/dist/session/session.base.d.ts +14 -1
  310. package/dist/session/session.service.d.ts +17 -2
  311. package/dist/session/session.service.js +708 -60
  312. package/dist/session/session.types.d.ts +327 -3
  313. package/dist/session/session.types.js +951 -10
  314. package/dist/session/sidecar-json-shape.d.ts +31 -0
  315. package/dist/session/sidecar-json-shape.js +217 -0
  316. package/dist/session/unreferenced-exports.d.ts +12 -0
  317. package/dist/session/unreferenced-exports.js +59 -0
  318. package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
  319. package/dist/session/workspace-runtime-fingerprint.js +138 -0
  320. package/dist/shared/format/format-bytes.d.ts +1 -0
  321. package/dist/shared/format/format-bytes.js +9 -0
  322. package/dist/shared/fs/file-identity.d.ts +10 -0
  323. package/dist/shared/fs/file-identity.js +15 -0
  324. package/dist/shared/fs/replace-file.d.ts +7 -0
  325. package/dist/shared/fs/replace-file.js +33 -0
  326. package/dist/shared/git/git.js +2 -1
  327. package/dist/shared/path/path.d.ts +1 -0
  328. package/dist/shared/path/path.js +21 -1
  329. package/dist/shared/process/dotnet-toolchain.d.ts +17 -0
  330. package/dist/shared/process/dotnet-toolchain.js +307 -0
  331. package/dist/shared/process/host-process-recovery.d.ts +23 -0
  332. package/dist/shared/process/host-process-recovery.js +99 -0
  333. package/dist/shared/process/host-process-supervisor.d.ts +72 -0
  334. package/dist/shared/process/host-process-supervisor.js +383 -0
  335. package/dist/shared/process/process-tree.d.ts +52 -0
  336. package/dist/shared/process/process-tree.js +144 -0
  337. package/dist/shared/process/process.d.ts +70 -0
  338. package/dist/shared/process/process.js +224 -16
  339. package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
  340. package/dist/shared/process/windows-app-execution-alias.js +45 -0
  341. package/dist/shared/process/windows-launch.d.ts +26 -0
  342. package/dist/shared/process/windows-launch.js +109 -0
  343. package/dist/shared/provider-capabilities.d.ts +4 -0
  344. package/dist/shared/provider-capabilities.js +95 -0
  345. package/dist/shared/redaction/redaction.d.ts +1 -0
  346. package/dist/shared/redaction/redaction.js +47 -4
  347. package/dist/shared/time/monotonic.d.ts +1 -0
  348. package/dist/shared/time/monotonic.js +8 -0
  349. package/dist/version.d.ts +1 -1
  350. package/dist/version.js +1 -1
  351. package/dist/worktree/artifact-injector.d.ts +3 -2
  352. package/dist/worktree/artifact-injector.js +82 -10
  353. package/dist/worktree/dependency-warmer.d.ts +78 -1
  354. package/dist/worktree/dependency-warmer.js +731 -13
  355. package/dist/worktree/index.d.ts +2 -1
  356. package/dist/worktree/index.js +1 -0
  357. package/dist/worktree/prior-phase-artifact-hydrator.d.ts +2 -0
  358. package/dist/worktree/prior-phase-artifact-hydrator.js +136 -0
  359. package/dist/worktree/story-qa-reference-hydrator.d.ts +4 -0
  360. package/dist/worktree/story-qa-reference-hydrator.js +253 -0
  361. package/dist/worktree/wip-git.d.ts +33 -0
  362. package/dist/worktree/wip-git.js +122 -0
  363. package/dist/worktree/wip-refs.d.ts +62 -0
  364. package/dist/worktree/wip-refs.js +119 -0
  365. package/dist/worktree/wip-restore.d.ts +38 -0
  366. package/dist/worktree/wip-restore.js +190 -0
  367. package/dist/worktree/wip-snapshot.d.ts +50 -0
  368. package/dist/worktree/wip-snapshot.js +268 -0
  369. package/dist/worktree/worktree-paths.d.ts +4 -0
  370. package/dist/worktree/worktree-paths.js +30 -0
  371. package/dist/worktree/worktree-wip-events.d.ts +18 -0
  372. package/dist/worktree/worktree-wip-events.js +98 -0
  373. package/dist/worktree/worktree-wip.d.ts +49 -0
  374. package/dist/worktree/worktree-wip.js +182 -0
  375. package/dist/worktree/worktree.base.d.ts +10 -1
  376. package/dist/worktree/worktree.service.d.ts +30 -4
  377. package/dist/worktree/worktree.service.js +379 -54
  378. package/dist/worktree/worktree.types.d.ts +38 -1
  379. package/package.json +12 -7
  380. package/runtime/windows-job-supervisor.ps1 +722 -0
  381. package/runtime/windows-listener-owner.ps1 +33 -0
@@ -1,61 +1,117 @@
1
+ import { randomUUID } from "node:crypto";
1
2
  import fs from "node:fs/promises";
2
3
  import path from "node:path";
4
+ import { RepositoryCoordinatorLock } from "../sandbox/repository-lock.js";
3
5
  import { GitClient } from "../shared/git/git.js";
4
6
  import { ensureDirectory, isSubPath, resolveExistingDirectoryPath, safeSegment } from "../shared/path/path.js";
5
7
  import { filterArtifactsForLane, injectWorktreeArtifacts } from "./artifact-injector.js";
8
+ import { hydratePriorPhaseArtifacts } from "./prior-phase-artifact-hydrator.js";
9
+ import { materializeStoryQaReferences } from "./story-qa-reference-hydrator.js";
6
10
  import { warmWorktreeDependencies } from "./dependency-warmer.js";
11
+ import { guardBranchReset, guardWorktreeRelease, guardWorktreeReset, restoreWorktreeWip, settleSessionWip, sweepBranchesAfterRelease, worktreeReleased, } from "./worktree-wip.js";
12
+ import { defaultWorktreeCoordinatorStateRoot, managedRepoRoot, resolveManagedWorktreeRoot, } from "./worktree-paths.js";
13
+ export { emitWipRestoreEvent, sessionWipOutcome, settleWorktree } from "./worktree-wip-events.js";
14
+ // Bounds the branch sweep that runs after each release, so one release never holds the repository lock long.
15
+ const releaseSweepLimit = 25;
7
16
  export class GitWorktreeService {
8
17
  git;
9
- constructor(git = new GitClient()) {
18
+ coordinator;
19
+ hostLoadGate;
20
+ leaseStateRoot;
21
+ constructor(git = new GitClient(), coordinator = new RepositoryCoordinatorLock(defaultWorktreeCoordinatorStateRoot()),
22
+ /** Gates dependency install fallbacks; inert unless the governor is on. */
23
+ hostLoadGate,
24
+ /** Holds the host runtime lease ledger; branches of live leases are never swept on release. */
25
+ leaseStateRoot = defaultWorktreeCoordinatorStateRoot()) {
10
26
  this.git = git;
27
+ this.coordinator = coordinator;
28
+ this.hostLoadGate = hostLoadGate;
29
+ this.leaseStateRoot = leaseStateRoot;
11
30
  }
12
31
  async prepare(request) {
13
32
  const allowedRoot = await ensureDirectory(request.allowedRepoRoot);
14
33
  const baseBranch = normalizeBranchName(request.baseBranch, "develop");
15
- const repoPath = await this.resolveRepoPath(request.repo, allowedRoot, baseBranch);
16
- await this.ensureGitIdentity(repoPath);
17
- await this.ensureBaseBranch(repoPath, baseBranch);
18
34
  const shortId = request.workItem.id.replace(/-/g, "").slice(0, 12);
19
35
  const kind = safeSegment(request.workItem.kind, "work-item");
20
36
  const fallbackWorktreeKey = `${kind}/${shortId}`;
21
37
  const worktreeKey = request.worktreeKey?.trim() || fallbackWorktreeKey;
22
38
  const worktreeSegments = worktreeKeySegments(worktreeKey, kind, shortId);
23
39
  const branchName = normalizeBranchName(worktreeSegments.join("/"), "work-item/unknown");
24
- const worktreeRoot = resolveWorktreeRoot(allowedRoot, repoPath);
25
- const worktreePath = path.join(worktreeRoot, ...worktreeSegments);
26
- const resolvedWorktreeParent = await ensureDirectory(path.dirname(worktreePath));
27
- if (!isSubPath(allowedRoot, resolvedWorktreeParent)) {
28
- throw new Error(`Worktree path must stay under ${allowedRoot}.`);
29
- }
30
- const exists = await directoryExists(worktreePath);
31
- let resolvedWorktreePath;
32
- if (!exists) {
33
- await this.git.run(repoPath, ["worktree", "add", "-B", branchName, worktreePath, baseBranch]);
34
- resolvedWorktreePath = await resolveExistingDirectoryPath(worktreePath);
35
- }
36
- else {
37
- resolvedWorktreePath = await resolveExistingDirectoryPath(worktreePath);
38
- if (!isSubPath(allowedRoot, resolvedWorktreePath)) {
40
+ const creationCoordinationPath = this.repoCreationCoordinationPath(request.repo, allowedRoot);
41
+ const repoPath = await this.coordinator.withLock(creationCoordinationPath, async () => {
42
+ return await this.resolveRepoPath(request.repo, allowedRoot, baseBranch);
43
+ });
44
+ const { worktreePath: resolvedWorktreePath, wipRestore } = await this.coordinator.withLock(repoPath, async () => {
45
+ await this.ensureGitIdentity(repoPath);
46
+ const baseStartPoint = await this.resolveBaseStartPoint(repoPath, baseBranch);
47
+ const worktreeRoot = resolveManagedWorktreeRoot(allowedRoot, repoPath);
48
+ const worktreePath = path.join(worktreeRoot, ...worktreeSegments);
49
+ const resolvedWorktreeParent = await ensureDirectory(path.dirname(worktreePath));
50
+ if (!isSubPath(allowedRoot, resolvedWorktreeParent)) {
51
+ throw new Error(`Worktree path must stay under ${allowedRoot}.`);
52
+ }
53
+ let selectedWorktreePath = worktreePath;
54
+ if (!(await directoryExists(worktreePath))) {
55
+ // A prior runner can disappear after Git registers its worktree but before
56
+ // normal cleanup completes. Release that missing-directory registration
57
+ // immediately so retrying the same lease remains idempotent.
58
+ await this.git.run(repoPath, ["worktree", "prune", "--expire", "now"]);
59
+ const registeredWorktreePath = await this.registeredManagedWorktreePath(repoPath, branchName, allowedRoot, worktreeSegments);
60
+ if (!registeredWorktreePath) {
61
+ const branchRef = `refs/heads/${branchName}`;
62
+ if (request.preserveExistingState && await this.gitRefExists(repoPath, branchRef)) {
63
+ // The checkout directory can disappear while its branch still
64
+ // contains completed agent work. Reattach that branch verbatim;
65
+ // `-B ... baseStartPoint` would silently reset it and lose progress.
66
+ await this.git.run(repoPath, ["worktree", "add", worktreePath, branchName]);
67
+ }
68
+ else {
69
+ await guardBranchReset(this.git, repoPath, branchName, baseStartPoint);
70
+ await this.git.run(repoPath, ["worktree", "add", "-B", branchName, worktreePath, baseStartPoint]);
71
+ }
72
+ return await this.withRestoredWip(request, repoPath, branchName, await resolveExistingDirectoryPath(worktreePath));
73
+ }
74
+ // The selected checkout can change when a Bridge reconnects or a local
75
+ // runner takes over. Its managed root therefore changes even though the
76
+ // deterministic lease branch does not. Reattach to the registered,
77
+ // Forge-owned worktree instead of trying to check out that branch twice.
78
+ selectedWorktreePath = registeredWorktreePath;
79
+ }
80
+ const existingWorktreePath = await resolveExistingDirectoryPath(selectedWorktreePath);
81
+ if (!isSubPath(allowedRoot, existingWorktreePath)) {
39
82
  throw new Error(`Worktree path must stay under ${allowedRoot}.`);
40
83
  }
41
- const currentBranch = await this.currentBranch(resolvedWorktreePath);
84
+ if (!(await gitMetadataExists(existingWorktreePath, allowedRoot))) {
85
+ await this.restoreOrphanedWorktree({
86
+ repoPath,
87
+ worktreePath: existingWorktreePath,
88
+ branchName,
89
+ baseStartPoint,
90
+ allowedRoot,
91
+ });
92
+ }
93
+ const currentBranch = await this.currentBranch(existingWorktreePath);
42
94
  if (currentBranch !== branchName) {
43
- throw new Error(`Existing worktree ${resolvedWorktreePath} is on branch '${currentBranch}', expected '${branchName}'.`);
95
+ throw new Error(`Existing worktree ${existingWorktreePath} is on branch '${currentBranch}', expected '${branchName}'.`);
96
+ }
97
+ if (!request.preserveExistingState && shouldResetExistingWorktree(request)) {
98
+ await guardWorktreeReset(existingWorktreePath, branchName, request);
99
+ await this.resetWorktreeToBase(existingWorktreePath, baseStartPoint);
44
100
  }
101
+ return await this.withRestoredWip(request, repoPath, branchName, existingWorktreePath);
102
+ });
103
+ // Reference inputs and an exact-tree local repair checkpoint must survive output cleanup.
104
+ await materializeStoryQaReferences(resolvedWorktreePath, request, this.git);
105
+ if (!request.preserveExistingState) {
106
+ await clearRunArtifactRoots(resolvedWorktreePath, request);
45
107
  }
46
- await this.ensureGitIdentity(resolvedWorktreePath);
47
- await clearRunArtifactRoots(resolvedWorktreePath, request);
108
+ const hydratedPriorPhaseArtifactCount = await hydratePriorPhaseArtifacts(resolvedWorktreePath, request.priorPhaseArtifacts);
48
109
  const qaReworkPacketPath = await materializeQaReworkPacket(resolvedWorktreePath, request);
49
110
  const artifacts = filterArtifactsForLane(request.artifacts, request.lane, request.phase);
50
111
  if (artifacts.length > 0) {
51
- await injectWorktreeArtifacts(resolvedWorktreePath, artifacts);
112
+ await injectWorktreeArtifacts(resolvedWorktreePath, artifacts, await this.trackedForgePaths(resolvedWorktreePath));
52
113
  }
53
- const dependencyWarm = await warmWorktreeDependencies({
54
- baseCheckoutPath: repoPath,
55
- worktreePath: resolvedWorktreePath,
56
- allowedRoot,
57
- warmPathOverrides: request.warmPathOverrides
58
- });
114
+ const dependencyWarm = await this.warmDependencies(request, repoPath, resolvedWorktreePath, allowedRoot);
59
115
  return {
60
116
  repoPath,
61
117
  worktreePath: resolvedWorktreePath,
@@ -63,19 +119,126 @@ export class GitWorktreeService {
63
119
  baseBranch,
64
120
  cleanupWorktrees: request.cleanupWorktrees,
65
121
  dependencyWarm,
66
- qaReworkPacketPath
122
+ qaReworkPacketPath,
123
+ hydratedPriorPhaseArtifactCount,
124
+ sessionId: request.sessionId ?? null,
125
+ lane: request.lane,
126
+ ...(wipRestore ? { wipRestore } : {}),
67
127
  };
68
128
  }
129
+ async warmDependencies(request, repoPath, worktreePath, allowedRoot) {
130
+ if (!requiresMutableEnvironmentPreparation(request))
131
+ return undefined;
132
+ return await warmWorktreeDependencies({
133
+ baseCheckoutPath: repoPath,
134
+ worktreePath,
135
+ allowedRoot,
136
+ warmPathOverrides: request.warmPathOverrides,
137
+ hostLoad: this.hostLoadGate?.enabled
138
+ ? {
139
+ gate: this.hostLoadGate,
140
+ dispatchAttemptId: request.hostLoadOwner?.dispatchAttemptId ?? null,
141
+ priority: request.hostLoadOwner?.priority ?? "foreground",
142
+ }
143
+ : undefined,
144
+ signal: request.signal,
145
+ });
146
+ }
147
+ /** Restores the story's saved WIP (still under the repository lock, before the provider starts). */
148
+ async withRestoredWip(request, repoPath, branchName, worktreePath) {
149
+ const wipRestore = await restoreWorktreeWip({ worktreePath, repoPath, branchName, sessionId: request.sessionId, lane: request.lane });
150
+ return { worktreePath, ...(wipRestore ? { wipRestore } : {}) };
151
+ }
152
+ async settleWip(handle, outcome) {
153
+ return await settleSessionWip(handle, outcome);
154
+ }
155
+ async trackedForgePaths(worktreePath) {
156
+ const output = await this.git.run(worktreePath, ["ls-files", "-z", "--", ".forge"]);
157
+ return new Set(output.split("\0").filter(Boolean).map(value => value.replaceAll("\\", "/")));
158
+ }
159
+ async registeredManagedWorktreePath(repoPath, branchName, allowedRoot, worktreeSegments) {
160
+ const listing = await this.git.run(repoPath, ["worktree", "list", "--porcelain", "-z"]);
161
+ const registered = parseRegisteredWorktrees(repoPath, listing)
162
+ .find(entry => entry.branchName === `refs/heads/${branchName}`);
163
+ if (!registered) {
164
+ return null;
165
+ }
166
+ const resolved = await resolveExistingDirectoryPath(registered.worktreePath);
167
+ if (!isManagedLeaseWorktreePath(allowedRoot, resolved, worktreeSegments)) {
168
+ throw new Error(`Branch '${branchName}' is already checked out outside its Forge-managed lease path at ${resolved}.`);
169
+ }
170
+ return resolved;
171
+ }
172
+ repoCreationCoordinationPath(repo, allowedRoot) {
173
+ if (repo.serverLocalPath && repo.serverLocalPath.trim().length > 0) {
174
+ return path.resolve(repo.serverLocalPath);
175
+ }
176
+ return this.managedRepoPath(repo, allowedRoot);
177
+ }
69
178
  async release(handle) {
70
- if (!handle.cleanupWorktrees || !(await directoryExists(handle.worktreePath))) {
179
+ if (!handle.cleanupWorktrees) {
71
180
  return;
72
181
  }
182
+ await this.coordinator.withLock(handle.repoPath, async () => {
183
+ if (await directoryExists(handle.worktreePath)) {
184
+ // Never delete work that could not be saved: this throws and keeps the worktree.
185
+ await guardWorktreeRelease(handle);
186
+ // On Windows, `git worktree remove` can delete the `.git` link and then
187
+ // fail on a locked build output. That leaves a full source tree which is
188
+ // no longer a Git worktree and makes every retry fail during prepare.
189
+ // Move the tree out of its stable lease path first. If the rename fails,
190
+ // leave the valid worktree untouched rather than partially unregistering it.
191
+ const releasePath = `${handle.worktreePath}.forge-release-${randomUUID()}`;
192
+ await renameWorktreeForRelease(handle.worktreePath, releasePath);
193
+ await this.git.run(handle.repoPath, ["worktree", "prune", "--expire", "now"]);
194
+ await fs.rm(releasePath, {
195
+ recursive: true,
196
+ force: true,
197
+ maxRetries: 10,
198
+ retryDelay: 100,
199
+ }).catch(() => undefined);
200
+ }
201
+ // The process can disappear after Git registers a worktree but before the
202
+ // directory is fully materialized (or after an external cleanup removes it).
203
+ // Always prune so those missing-directory registrations do not accumulate.
204
+ await this.git.run(handle.repoPath, ["worktree", "prune", "--expire", "now"]).catch(() => undefined);
205
+ worktreeReleased(handle);
206
+ // A readiness probe's branch goes with its worktree. Other Forge branches on this device
207
+ // whose work is already merged into the base go too; branches with unmerged work stay.
208
+ // A lease can be live while its worktree is briefly missing, so its branch is protected
209
+ // even when no worktree has it checked out. If the ledger can't be read, sweep nothing.
210
+ await sweepBranchesAfterRelease(this.git, handle, this.leaseStateRoot, releaseSweepLimit);
211
+ });
212
+ }
213
+ async restoreOrphanedWorktree(input) {
214
+ const orphanStat = await fs.lstat(input.worktreePath);
215
+ if (orphanStat.isSymbolicLink() || !orphanStat.isDirectory()) {
216
+ throw new Error(`Refusing to recover redirected or non-directory worktree ${input.worktreePath}.`);
217
+ }
218
+ const quarantinePath = `${input.worktreePath}.forge-orphan-${randomUUID()}`;
219
+ if (!isSubPath(input.allowedRoot, quarantinePath)) {
220
+ throw new Error(`Worktree recovery path must stay under ${input.allowedRoot}.`);
221
+ }
222
+ await guardBranchReset(this.git, input.repoPath, input.branchName, input.baseStartPoint);
223
+ await fs.rename(input.worktreePath, quarantinePath);
73
224
  try {
74
- await this.git.run(handle.repoPath, ["worktree", "remove", "--force", handle.worktreePath]);
75
- await this.git.run(handle.repoPath, ["worktree", "prune"]);
225
+ await this.git.run(input.repoPath, ["worktree", "prune", "--expire", "now"]);
226
+ await this.git.run(input.repoPath, [
227
+ "worktree",
228
+ "add",
229
+ "-B",
230
+ input.branchName,
231
+ input.worktreePath,
232
+ input.baseStartPoint,
233
+ ]);
234
+ await overlayOrphanedWorktree(input.worktreePath, quarantinePath);
235
+ await fs.rm(quarantinePath, { recursive: true, force: true });
76
236
  }
77
- catch {
78
- await fs.rm(handle.worktreePath, { recursive: true, force: true });
237
+ catch (error) {
238
+ await this.git.run(input.repoPath, ["worktree", "remove", "--force", input.worktreePath]).catch(() => undefined);
239
+ await fs.rm(input.worktreePath, { recursive: true, force: true }).catch(() => undefined);
240
+ await fs.rename(quarantinePath, input.worktreePath).catch(() => undefined);
241
+ throw new Error(`Failed to recover orphaned worktree ${input.worktreePath}.`, { cause: error });
79
242
  }
80
243
  }
81
244
  async resolveRepoPath(repo, allowedRoot, baseBranch) {
@@ -93,7 +256,7 @@ export class GitWorktreeService {
93
256
  if (discovered) {
94
257
  return discovered;
95
258
  }
96
- const repoPath = path.join(managedRepoRoot(allowedRoot), `${safeSegment(repo.name, "repo")}-${repo.id.replace(/-/g, "")}`);
259
+ const repoPath = this.managedRepoPath(repo, allowedRoot);
97
260
  if (!(await gitMetadataExists(repoPath, allowedRoot))) {
98
261
  const repoPathExists = await pathExists(repoPath);
99
262
  if (repoPathExists) {
@@ -124,6 +287,9 @@ export class GitWorktreeService {
124
287
  }
125
288
  return resolved;
126
289
  }
290
+ managedRepoPath(repo, allowedRoot) {
291
+ return path.join(managedRepoRoot(allowedRoot), `${safeSegment(repo.name, "repo")}-${repo.id.replace(/-/g, "")}`);
292
+ }
127
293
  async findExistingRepoPath(repo, allowedRoot) {
128
294
  const expectedRemote = normalizeRemote(repo.remoteUrl);
129
295
  const rawName = repo.name.trim();
@@ -164,21 +330,34 @@ export class GitWorktreeService {
164
330
  const resolved = await resolveExistingDirectoryPath(candidate);
165
331
  return isSubPath(allowedRoot, resolved) ? resolved : null;
166
332
  }
167
- async ensureBaseBranch(repoPath, baseBranch) {
168
- if (await this.gitRefExists(repoPath, `refs/heads/${baseBranch}`)) {
169
- return;
333
+ async resolveBaseStartPoint(repoPath, baseBranch) {
334
+ if (baseBranch === "HEAD") {
335
+ const head = (await this.git.run(repoPath, ["rev-parse", "--verify", "HEAD^{commit}"])).trim();
336
+ if (!/^[0-9a-f]{40,64}$/iu.test(head)) {
337
+ throw new Error("The repository checkout does not have a valid committed HEAD revision.");
338
+ }
339
+ return head;
170
340
  }
341
+ const localRef = `refs/heads/${baseBranch}`;
342
+ const remoteRef = `refs/remotes/origin/${baseBranch}`;
171
343
  const origin = await this.git.run(repoPath, ["remote", "get-url", "origin"]).catch(() => "");
172
- if (origin.trim().length === 0) {
173
- throw new Error(`Base branch '${baseBranch}' was not found in the local checkout.`);
344
+ if (origin.trim().length > 0) {
345
+ const fetched = await this.git.run(repoPath, ["fetch", "--prune", "origin"])
346
+ .then(() => true)
347
+ .catch(() => false);
348
+ if (fetched && await this.gitRefExists(repoPath, remoteRef)) {
349
+ return remoteRef;
350
+ }
174
351
  }
175
- await this.git.run(repoPath, ["fetch", "origin", `${baseBranch}:refs/remotes/origin/${baseBranch}`]).catch(() => "");
176
- if (await this.gitRefExists(repoPath, `refs/remotes/origin/${baseBranch}`)) {
177
- await this.git.run(repoPath, ["branch", baseBranch, `refs/remotes/origin/${baseBranch}`]);
178
- return;
352
+ if (await this.gitRefExists(repoPath, localRef)) {
353
+ return localRef;
179
354
  }
180
355
  throw new Error(`Base branch '${baseBranch}' was not found locally or on origin.`);
181
356
  }
357
+ async resetWorktreeToBase(worktreePath, baseStartPoint) {
358
+ await this.git.run(worktreePath, ["reset", "--hard", baseStartPoint]);
359
+ await this.git.run(worktreePath, ["clean", "-fd"]);
360
+ }
182
361
  async gitRefExists(repoPath, gitRef) {
183
362
  return this.git.run(repoPath, ["show-ref", "--verify", "--quiet", gitRef]).then(() => true).catch(() => false);
184
363
  }
@@ -190,14 +369,31 @@ export class GitWorktreeService {
190
369
  await this.git.run(repoPath, ["config", "user.name", "Forge Bridge"]);
191
370
  }
192
371
  }
193
- function managedRepoRoot(allowedRoot) {
194
- return path.join(allowedRoot, ".forge-worktrees", "_repos");
372
+ export async function renameWorktreeForRelease(source, destination, rename = fs.rename, wait = milliseconds => new Promise(resolve => setTimeout(resolve, milliseconds)), maxAttempts = 8) {
373
+ const attempts = Number.isFinite(maxAttempts) && maxAttempts > 0
374
+ ? Math.max(1, Math.floor(maxAttempts))
375
+ : 1;
376
+ for (let attempt = 1; attempt <= attempts; attempt += 1) {
377
+ try {
378
+ await rename(source, destination);
379
+ return;
380
+ }
381
+ catch (error) {
382
+ if (!isTransientWorktreeRenameError(error) || attempt === attempts)
383
+ throw error;
384
+ await wait(Math.min(1_000, 100 * (2 ** (attempt - 1))));
385
+ }
386
+ }
195
387
  }
196
- function resolveWorktreeRoot(allowedRoot, repoPath) {
197
- const baseName = path.basename(repoPath);
198
- return isSubPath(managedRepoRoot(allowedRoot), repoPath)
199
- ? path.join(allowedRoot, ".forge-worktrees", baseName)
200
- : path.join(path.dirname(repoPath), ".forge-worktrees", baseName);
388
+ function isTransientWorktreeRenameError(error) {
389
+ if (!error || typeof error !== "object" || !("code" in error))
390
+ return false;
391
+ const code = String(error.code ?? "").toUpperCase();
392
+ return code === "EPERM" || code === "EACCES" || code === "EBUSY" || code === "ENOTEMPTY";
393
+ }
394
+ export function requiresMutableEnvironmentPreparation(request) {
395
+ // Missing runtime intent is treated conservatively for older dispatch packets.
396
+ return request.applicationRuntimeRequired !== false;
201
397
  }
202
398
  function isCloneableRemote(remoteUrl) {
203
399
  const trimmed = remoteUrl?.trim() ?? "";
@@ -206,9 +402,12 @@ function isCloneableRemote(remoteUrl) {
206
402
  }
207
403
  return trimmed.startsWith("git@") || trimmed.includes("://") || path.isAbsolute(trimmed);
208
404
  }
209
- async function clearRunArtifactRoots(worktreePath, request) {
405
+ export async function clearRunArtifactRoots(worktreePath, request) {
210
406
  const roots = new Set();
211
407
  roots.add(workItemArtifactRoot(worktreePath, request.workItem.id));
408
+ for (const artifact of request.priorPhaseArtifacts ?? []) {
409
+ roots.add(workItemArtifactRoot(worktreePath, artifact.workItemId));
410
+ }
212
411
  const ownerType = normalizeOwnerType(request.ownerType);
213
412
  const ownerId = request.ownerId?.trim();
214
413
  if (ownerType && ownerId) {
@@ -269,6 +468,132 @@ function normalizeOwnerType(value) {
269
468
  }
270
469
  return null;
271
470
  }
471
+ function shouldResetExistingWorktree(request) {
472
+ const lane = request.lane.trim().toLowerCase();
473
+ const phase = request.phase.trim().toLowerCase().replace(/-/g, "_");
474
+ if (lane === "develop" && (phase === "implementation" || phase === "self_review" || phase === "validation")) {
475
+ return false;
476
+ }
477
+ if (lane === "qa" || phase === "qa") {
478
+ return false;
479
+ }
480
+ return true;
481
+ }
482
+ function parseRegisteredWorktrees(repoPath, output) {
483
+ const worktrees = [];
484
+ let current = null;
485
+ for (const field of output.split("\0")) {
486
+ if (field.startsWith("worktree ")) {
487
+ if (current)
488
+ worktrees.push(current);
489
+ const rawPath = field.slice("worktree ".length);
490
+ current = {
491
+ worktreePath: path.resolve(path.isAbsolute(rawPath) ? rawPath : path.join(repoPath, rawPath)),
492
+ branchName: null,
493
+ };
494
+ }
495
+ else if (field.startsWith("branch ") && current) {
496
+ current.branchName = field.slice("branch ".length).trim();
497
+ }
498
+ }
499
+ if (current)
500
+ worktrees.push(current);
501
+ return worktrees;
502
+ }
503
+ function isManagedLeaseWorktreePath(allowedRoot, candidate, worktreeSegments) {
504
+ if (!isSubPath(allowedRoot, candidate)) {
505
+ return false;
506
+ }
507
+ const relativeSegments = path.relative(path.resolve(allowedRoot), path.resolve(candidate))
508
+ .split(path.sep)
509
+ .filter(Boolean);
510
+ const normalize = (value) => process.platform === "win32" ? value.toLowerCase() : value;
511
+ if (normalize(relativeSegments[0] ?? "") !== ".forge-worktrees"
512
+ || relativeSegments.length !== 2 + worktreeSegments.length) {
513
+ return false;
514
+ }
515
+ const suffix = relativeSegments.slice(-worktreeSegments.length).map(normalize);
516
+ return suffix.every((segment, index) => segment === normalize(worktreeSegments[index] ?? ""));
517
+ }
518
+ async function overlayOrphanedWorktree(worktreePath, orphanPath) {
519
+ // A failed Windows cleanup can remove only part of a worktree before its
520
+ // `.git` link disappears. Start from Git's clean checkout so missing tracked
521
+ // files are restored, then overlay every surviving agent file. Moving entries
522
+ // on the same volume preserves pnpm junctions without requiring symlink
523
+ // privileges, unlike fs.cp.
524
+ const backupRoot = `${worktreePath}.forge-base-${randomUUID()}`;
525
+ const moves = [];
526
+ try {
527
+ await fs.mkdir(backupRoot, { recursive: true });
528
+ const orphanEntries = await fs.readdir(orphanPath, { withFileTypes: true });
529
+ for (const entry of orphanEntries) {
530
+ if (entry.name === ".git") {
531
+ continue;
532
+ }
533
+ await overlayEntry({
534
+ sourcePath: path.join(orphanPath, entry.name),
535
+ destinationPath: path.join(worktreePath, entry.name),
536
+ backupPath: path.join(backupRoot, entry.name),
537
+ moves,
538
+ });
539
+ }
540
+ await fs.rm(backupRoot, { recursive: true, force: true });
541
+ }
542
+ catch (error) {
543
+ for (const move of moves.reverse()) {
544
+ await fs.mkdir(path.dirname(move.sourcePath), { recursive: true }).catch(() => undefined);
545
+ await fs.rename(move.destinationPath, move.sourcePath).catch(() => undefined);
546
+ if (move.backupPath) {
547
+ await fs.mkdir(path.dirname(move.destinationPath), { recursive: true }).catch(() => undefined);
548
+ await fs.rename(move.backupPath, move.destinationPath).catch(() => undefined);
549
+ }
550
+ }
551
+ await fs.rm(backupRoot, { recursive: true, force: true }).catch(() => undefined);
552
+ throw error;
553
+ }
554
+ }
555
+ async function overlayEntry(input) {
556
+ const sourceStat = await fs.lstat(input.sourcePath);
557
+ const destinationStat = await fs.lstat(input.destinationPath).catch(() => null);
558
+ if (sourceStat.isDirectory() &&
559
+ !sourceStat.isSymbolicLink() &&
560
+ destinationStat?.isDirectory() &&
561
+ !destinationStat.isSymbolicLink()) {
562
+ const entries = await fs.readdir(input.sourcePath, { withFileTypes: true });
563
+ for (const entry of entries) {
564
+ await overlayEntry({
565
+ sourcePath: path.join(input.sourcePath, entry.name),
566
+ destinationPath: path.join(input.destinationPath, entry.name),
567
+ backupPath: path.join(input.backupPath, entry.name),
568
+ moves: input.moves,
569
+ });
570
+ }
571
+ return;
572
+ }
573
+ let preservedBasePath;
574
+ if (destinationStat) {
575
+ await fs.mkdir(path.dirname(input.backupPath), { recursive: true });
576
+ await fs.rename(input.destinationPath, input.backupPath);
577
+ preservedBasePath = input.backupPath;
578
+ }
579
+ else {
580
+ await fs.mkdir(path.dirname(input.destinationPath), { recursive: true });
581
+ }
582
+ try {
583
+ await fs.rename(input.sourcePath, input.destinationPath);
584
+ }
585
+ catch (error) {
586
+ if (preservedBasePath) {
587
+ await fs.rename(preservedBasePath, input.destinationPath).catch(() => undefined);
588
+ }
589
+ throw error;
590
+ }
591
+ input.moves.push({
592
+ sourcePath: input.sourcePath,
593
+ destinationPath: input.destinationPath,
594
+ backupPath: preservedBasePath,
595
+ });
596
+ }
272
597
  function qaReworkPacketFileName(packetPath) {
273
598
  const normalized = packetPath.trim().replace(/\\/g, "/");
274
599
  const fileName = normalized.split("/").filter(Boolean).at(-1) ?? "";
@@ -1,5 +1,8 @@
1
- import type { DispatchQaReworkContext, DispatchRepo, DispatchWorkItem, DispatchResolvedArtifact } from "../session/session.types.js";
1
+ import type { DispatchQaReworkContext, DispatchPriorPhaseArtifact, DispatchRepo, DispatchWorkItem, DispatchResolvedArtifact, DispatchStoryQaContext } from "../session/session.types.js";
2
2
  import type { WarmDependenciesResult } from "./dependency-warmer.js";
3
+ import type { WipSnapshotReason } from "./wip-refs.js";
4
+ import type { WipRestoreOutcome } from "./wip-restore.js";
5
+ import type { WipSnapshotResult } from "./wip-snapshot.js";
3
6
  export interface WorktreePrepareRequest {
4
7
  readonly repo: DispatchRepo;
5
8
  readonly workItem: DispatchWorkItem;
@@ -12,8 +15,24 @@ export interface WorktreePrepareRequest {
12
15
  readonly allowedRepoRoot: string;
13
16
  readonly cleanupWorktrees: boolean;
14
17
  readonly artifacts: readonly DispatchResolvedArtifact[];
18
+ readonly priorPhaseArtifacts?: readonly DispatchPriorPhaseArtifact[];
19
+ readonly storyQa?: DispatchStoryQaContext | null;
20
+ readonly referenceRunId?: string;
21
+ readonly referenceCycleRunId?: string;
22
+ readonly effectivePlanAmendmentHash?: string | null;
15
23
  readonly qaRework?: DispatchQaReworkContext | null;
16
24
  readonly warmPathOverrides?: readonly string[];
25
+ readonly applicationRuntimeRequired?: boolean;
26
+ readonly preserveExistingState?: boolean;
27
+ /** The session this worktree is prepared for; names its WIP snapshots and enables restoring one. */
28
+ readonly sessionId?: string | null;
29
+ /** The attempt dependency installs reserve host capacity for (decision 0013). */
30
+ readonly hostLoadOwner?: {
31
+ readonly dispatchAttemptId: string | null;
32
+ readonly priority: "foreground" | "background";
33
+ };
34
+ /** The attempt's cancellation: queued installs stop waiting and running ones are stopped. */
35
+ readonly signal?: AbortSignal;
17
36
  }
18
37
  export interface WorktreeHandle {
19
38
  readonly repoPath: string;
@@ -23,4 +42,22 @@ export interface WorktreeHandle {
23
42
  readonly cleanupWorktrees: boolean;
24
43
  readonly dependencyWarm?: WarmDependenciesResult;
25
44
  readonly qaReworkPacketPath?: string;
45
+ readonly hydratedPriorPhaseArtifactCount?: number;
46
+ readonly sessionId?: string | null;
47
+ readonly lane?: string;
48
+ /** What happened to the story's saved WIP when this worktree was prepared. */
49
+ readonly wipRestore?: WipRestoreOutcome;
50
+ }
51
+ /** How a session ended, for its WIP snapshot: null when it succeeded. */
52
+ export interface WipSessionOutcome {
53
+ readonly reason: WipSnapshotReason | null;
54
+ }
55
+ export interface WipSettlement {
56
+ readonly snapshot?: WipSnapshotResult;
57
+ readonly error?: {
58
+ readonly code: string;
59
+ readonly message: string;
60
+ };
61
+ /** The restored snapshot's ref, deleted because this session's work supersedes it. */
62
+ readonly retiredRef?: string | null;
26
63
  }
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@loucompanion/forge-bridge",
3
- "version": "0.1.3-dev.f66395c3ac21",
3
+ "version": "0.1.4-dev.0098fdb4e213",
4
4
  "description": "Forge runner bridge CLI for connecting local developer machines to Forge dispatch.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
7
7
  "bin": {
8
+ "forge": "dist/cli/bin.js",
8
9
  "forge-bridge": "dist/cli/bin.js"
9
10
  },
10
11
  "main": "./dist/index.js",
@@ -18,6 +19,7 @@
18
19
  },
19
20
  "files": [
20
21
  "dist",
22
+ "runtime",
21
23
  "README.md"
22
24
  ],
23
25
  "repository": {
@@ -30,20 +32,22 @@
30
32
  "url": "https://github.com/coleman399/Forge/issues"
31
33
  },
32
34
  "engines": {
33
- "node": ">=22.13.0"
35
+ "node": "^22.13.0 || >=24.0.0"
34
36
  },
35
37
  "publishConfig": {
36
38
  "access": "public"
37
39
  },
38
40
  "scripts": {
39
41
  "build": "tsc -p tsconfig.json",
40
- "test": "vitest run",
42
+ "test": "node scripts/run-owned-tests.mjs",
43
+ "test:residue": "node scripts/run-owned-residue-gate.mjs",
41
44
  "test:watch": "vitest",
42
- "smoke:package": "npm run build && node scripts/smoke-package.mjs",
43
- "lint": "eslint \"src/**/*.ts\" \"scripts/**/*.mjs\" \"vitest.config.ts\""
45
+ "smoke:package": "tsc -p tsconfig.json && node scripts/smoke-package.mjs",
46
+ "lint": "eslint \"src/**/*.ts\" \"scripts/**/*.mjs\" \"vitest.config.ts\" \"vitest.setup.ts\" && node ../../scripts/class-design/check-eslint-ratchet.mjs bridge"
44
47
  },
45
48
  "dependencies": {
46
- "@microsoft/signalr": "^8.0.17"
49
+ "@microsoft/signalr": "^8.0.17",
50
+ "yaml": "^2.9.0"
47
51
  },
48
52
  "devDependencies": {
49
53
  "@eslint/js": "^10.0.1",
@@ -52,6 +56,7 @@
52
56
  "globals": "^17.6.0",
53
57
  "typescript": "^5.8.3",
54
58
  "typescript-eslint": "^8.61.1",
55
- "vitest": "^3.2.3"
59
+ "vite": "^7.3.7",
60
+ "vitest": "^4.1.12"
56
61
  }
57
62
  }