@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,5 +1,479 @@
1
- export class NoopCleanupService {
2
- async run(_request) {
3
- return { removedWorktrees: 0 };
1
+ import { randomUUID } from "node:crypto";
2
+ import fs from "node:fs/promises";
3
+ import path from "node:path";
4
+ import { RepositoryCoordinatorLock } from "../sandbox/repository-lock.js";
5
+ import { GitClient } from "../shared/git/git.js";
6
+ import { isSubPath, resolveExistingDirectoryPath, resolvePathIdentity } from "../shared/path/path.js";
7
+ import { defaultWorktreeCoordinatorStateRoot, resolveManagedWorktreeRootForRepo, } from "../worktree/worktree-paths.js";
8
+ import { saveStaleWorktreeWork } from "./cleanup-wip.js";
9
+ import { isForgeOwnedWorktreePath, isForgeWorktreeContainer, isRuntimeReadinessName } from "./forge-owned-paths.js";
10
+ import { liveLeaseBranches, readHostRuntimeLeases, resolveRuntimeLeasePath } from "./host-runtime-ledger.js";
11
+ import { sweepManagedBranches } from "./managed-branch-sweep.js";
12
+ const staleRuntimeReadinessAgeMs = 30 * 60 * 1000;
13
+ export class ManagedWorktreeCleanupService {
14
+ stateRoot;
15
+ git;
16
+ coordinator;
17
+ warn;
18
+ constructor(stateRoot = defaultWorktreeCoordinatorStateRoot(), git = new GitClient(), coordinator = new RepositoryCoordinatorLock(stateRoot),
19
+ /** Where cleanup explains each worktree it kept because its work could not be saved. */
20
+ warn = message => process.stderr.write(`${message}\n`)) {
21
+ this.stateRoot = stateRoot;
22
+ this.git = git;
23
+ this.coordinator = coordinator;
24
+ this.warn = warn;
4
25
  }
26
+ async run(request) {
27
+ const [repoPath, allowedRepoRoot] = await Promise.all([
28
+ resolveExistingDirectoryPath(request.repoRoot),
29
+ request.allowedRepoRoot
30
+ ? resolvePathIdentity(request.allowedRepoRoot)
31
+ : Promise.resolve(undefined),
32
+ ]);
33
+ const worktreeRoot = resolveManagedWorktreeRootForRepo(repoPath, allowedRepoRoot);
34
+ return await this.coordinator.withLock(repoPath, async () => {
35
+ return await this.runLocked(repoPath, worktreeRoot, request);
36
+ });
37
+ }
38
+ async runLocked(repoPath, worktreeRoot, request) {
39
+ if (request.mode === "merged") {
40
+ if (!request.force)
41
+ return emptyResult(worktreeRoot, request.force);
42
+ await this.git.run(repoPath, ["worktree", "prune"]);
43
+ // Forge branches whose work is already on the base, and leftover readiness branches.
44
+ const baseBranch = await this.remoteBaseBranch(repoPath);
45
+ const sweep = await sweepManagedBranches(this.git, repoPath, {
46
+ ...(baseBranch ? { baseBranch } : {}),
47
+ includeMergedWorkBranches: baseBranch !== null,
48
+ protectedBranches: liveLeaseBranches(await this.readRuntimeLeases()),
49
+ });
50
+ return {
51
+ ...emptyResult(worktreeRoot, request.force),
52
+ deletedBranches: sweep.deletedBranches.length,
53
+ ...(baseBranch ? {} : { mergedBaseUnresolved: true }),
54
+ };
55
+ }
56
+ const safeRoot = await resolveSafeManagedRoot(worktreeRoot);
57
+ if (!safeRoot) {
58
+ if (!request.force)
59
+ return emptyResult(worktreeRoot, request.force);
60
+ await this.git.run(repoPath, ["worktree", "prune"]);
61
+ // No managed root left, but readiness branches can outlive it.
62
+ const sweep = await this.sweepReadinessBranches(repoPath);
63
+ return { ...emptyResult(worktreeRoot, request.force), deletedBranches: sweep.deletedBranches.length };
64
+ }
65
+ const [listedWorktrees, runtimeLeases] = await Promise.all([
66
+ this.listWorktrees(repoPath),
67
+ this.readRuntimeLeases(),
68
+ ]);
69
+ const activeRuntimePaths = await Promise.all(runtimeLeases
70
+ .filter(lease => lease.state !== "released")
71
+ .map(lease => resolveRuntimeLeasePath(lease.worktreePath)));
72
+ const metadataRoot = await this.worktreeMetadataRoot(repoPath);
73
+ const staleReadinessPaths = await this.staleRuntimeReadinessPaths(safeRoot, listedWorktrees, activeRuntimePaths);
74
+ const activeWorktrees = activePaths(listedWorktrees)
75
+ .filter(activePath => !staleReadinessPaths.some(stalePath => samePath(stalePath, activePath)));
76
+ if (request.mode === "all") {
77
+ return await this.removeWholeRoot(repoPath, safeRoot, metadataRoot, activeWorktrees, activeRuntimePaths, request.force);
78
+ }
79
+ const scan = await this.scanManagedCandidates(metadataRoot, safeRoot, activeWorktrees, activeRuntimePaths);
80
+ if (!request.force) {
81
+ return {
82
+ worktreeRoot: safeRoot,
83
+ removedWorktrees: 0,
84
+ candidateWorktrees: scan.candidates.length,
85
+ protectedWorktrees: scan.protectedWorktrees,
86
+ skippedUnownedDirectories: scan.skippedUnownedDirectories,
87
+ removedRoot: false,
88
+ dryRun: true,
89
+ };
90
+ }
91
+ let removedWorktrees = 0;
92
+ let preservedWorktrees = 0;
93
+ for (const candidate of scan.candidates) {
94
+ if (await this.isProtectedNow(repoPath, safeRoot, candidate)) {
95
+ continue;
96
+ }
97
+ const candidateIdentity = await forgeManagedCandidateIdentity(metadataRoot, candidate);
98
+ if (!candidateIdentity) {
99
+ continue;
100
+ }
101
+ // Never delete uncommitted work that could not be saved first.
102
+ if (await this.saveCandidatesWork(repoPath, safeRoot, [candidate]) > 0) {
103
+ preservedWorktrees += 1;
104
+ continue;
105
+ }
106
+ if (await quarantineAndRemoveCandidate(safeRoot, candidate, candidateIdentity)) {
107
+ removedWorktrees += 1;
108
+ }
109
+ }
110
+ await this.git.run(repoPath, ["worktree", "prune"]);
111
+ // A readiness branch goes with its worktree; this also clears ones whose worktree is long gone.
112
+ const sweep = await this.sweepReadinessBranches(repoPath);
113
+ return {
114
+ worktreeRoot: safeRoot,
115
+ removedWorktrees,
116
+ candidateWorktrees: scan.candidates.length,
117
+ protectedWorktrees: scan.protectedWorktrees,
118
+ skippedUnownedDirectories: scan.skippedUnownedDirectories,
119
+ removedRoot: false,
120
+ dryRun: false,
121
+ deletedBranches: sweep.deletedBranches.length,
122
+ preservedWorktrees,
123
+ };
124
+ }
125
+ /** All mode: removes the managed root itself once nothing in it is active, unowned or unsaved. */
126
+ async removeWholeRoot(repoPath, safeRoot, metadataRoot, activeWorktrees, activeRuntimePaths, force) {
127
+ const protectedPaths = uniquePaths([
128
+ ...activeWorktrees.filter(activePath => isSubPath(safeRoot, activePath)),
129
+ ...activeRuntimePaths.filter(activePath => isSubPath(safeRoot, activePath)),
130
+ ]);
131
+ if (protectedPaths.length > 0) {
132
+ throw new Error(`Refusing to remove managed worktree root ${safeRoot}; ${protectedPaths.length} active worktree or runtime lease(s) remain.`);
133
+ }
134
+ const scan = await this.scanManagedCandidates(metadataRoot, safeRoot, activeWorktrees, activeRuntimePaths);
135
+ if (force && !scan.rootRemovalSafe) {
136
+ throw new Error(`Refusing to remove managed worktree root ${safeRoot}; unowned content remains (${scan.skippedUnownedDirectories} skipped director${scan.skippedUnownedDirectories === 1 ? "y" : "ies"}).`);
137
+ }
138
+ if (force) {
139
+ // Every candidate's work is saved first; one that can't be saved keeps the whole root.
140
+ const kept = await this.saveCandidatesWork(repoPath, safeRoot, scan.candidates);
141
+ if (kept > 0) {
142
+ throw new Error(`Refusing to remove managed worktree root ${safeRoot}; ${kept} worktree(s) hold uncommitted work that could not be saved to a WIP ref.`);
143
+ }
144
+ await quarantineAndRemoveRoot(safeRoot);
145
+ await this.git.run(repoPath, ["worktree", "prune"]);
146
+ }
147
+ return {
148
+ worktreeRoot: safeRoot,
149
+ removedWorktrees: force ? scan.candidates.length : 0,
150
+ candidateWorktrees: scan.candidates.length,
151
+ protectedWorktrees: scan.protectedWorktrees,
152
+ skippedUnownedDirectories: scan.skippedUnownedDirectories,
153
+ removedRoot: force,
154
+ dryRun: !force,
155
+ };
156
+ }
157
+ /** Re-reads registrations and leases: a candidate may have become active since the scan. */
158
+ async isProtectedNow(repoPath, safeRoot, candidate) {
159
+ const [currentWorktrees, currentLeases] = await Promise.all([
160
+ this.listWorktrees(repoPath),
161
+ this.readRuntimeLeases(),
162
+ ]);
163
+ const currentRuntimePaths = await Promise.all(currentLeases
164
+ .filter(lease => lease.state !== "released")
165
+ .map(lease => resolveRuntimeLeasePath(lease.worktreePath)));
166
+ const currentStaleReadinessPaths = await this.staleRuntimeReadinessPaths(safeRoot, currentWorktrees, currentRuntimePaths);
167
+ const currentlyProtected = [
168
+ ...activePaths(currentWorktrees)
169
+ .filter(activePath => !currentStaleReadinessPaths.some(stalePath => samePath(stalePath, activePath))),
170
+ ...currentRuntimePaths,
171
+ ];
172
+ return worktreePathState(candidate, currentlyProtected) !== "none";
173
+ }
174
+ /** Saves each candidate's uncommitted work to a WIP ref; returns how many could not be saved. */
175
+ async saveCandidatesWork(repoPath, safeRoot, candidates) {
176
+ let kept = 0;
177
+ for (const candidate of candidates) {
178
+ const outcome = await saveStaleWorktreeWork(this.git, repoPath, safeRoot, candidate);
179
+ if (outcome.status === "saved") {
180
+ this.warn(`Saved uncommitted work in stale worktree ${candidate} to ${outcome.ref} before removing it.`);
181
+ }
182
+ else if (outcome.status === "failed") {
183
+ kept += 1;
184
+ this.warn(`Kept stale worktree ${candidate}: its uncommitted work could not be saved to a WIP ref (${outcome.reason}).`);
185
+ }
186
+ }
187
+ return kept;
188
+ }
189
+ async sweepReadinessBranches(repoPath) {
190
+ return await sweepManagedBranches(this.git, repoPath, {
191
+ includeMergedWorkBranches: false,
192
+ protectedBranches: liveLeaseBranches(await this.readRuntimeLeases()),
193
+ });
194
+ }
195
+ /**
196
+ * The branch merged work lands on: origin/HEAD when it points at a remote-tracking ref that
197
+ * exists, otherwise the only one of origin/develop, origin/main and origin/master that exists.
198
+ * Null when that's ambiguous or none exist, so the merged sweep is skipped (and reported)
199
+ * rather than measured against the wrong base.
200
+ */
201
+ async remoteBaseBranch(repoPath) {
202
+ const originHead = await this.git.run(repoPath, ["symbolic-ref", "--quiet", "--short", "refs/remotes/origin/HEAD"])
203
+ .catch(() => "");
204
+ const headBranch = originHead.trim().replace(/^origin\//, "");
205
+ // A stale origin/HEAD can name a branch whose remote-tracking ref has been pruned.
206
+ if (headBranch && await this.remoteBranchExists(repoPath, headBranch))
207
+ return headBranch;
208
+ const present = [];
209
+ for (const candidate of ["develop", "main", "master"]) {
210
+ if (await this.remoteBranchExists(repoPath, candidate))
211
+ present.push(candidate);
212
+ }
213
+ return present.length === 1 ? present[0] : null;
214
+ }
215
+ async remoteBranchExists(repoPath, branch) {
216
+ return await this.git.run(repoPath, ["rev-parse", "--verify", "--quiet", `refs/remotes/origin/${branch}^{commit}`])
217
+ .then(() => true, () => false);
218
+ }
219
+ async listWorktrees(repoPath) {
220
+ const output = await this.git.run(repoPath, ["worktree", "list", "--porcelain", "-z"]);
221
+ return parseWorktreeListing(repoPath, output);
222
+ }
223
+ async staleRuntimeReadinessPaths(worktreeRoot, worktrees, runtimePaths) {
224
+ const stale = [];
225
+ for (const worktree of worktrees) {
226
+ if (worktree.prunable || !isRuntimeReadinessWorktree(worktreeRoot, worktree))
227
+ continue;
228
+ if (worktreePathState(worktree.worktreePath, runtimePaths) !== "none")
229
+ continue;
230
+ const stat = await fs.stat(worktree.worktreePath).catch(error => {
231
+ if (isEnoent(error))
232
+ return null;
233
+ throw error;
234
+ });
235
+ if (stat && Date.now() - stat.mtimeMs >= staleRuntimeReadinessAgeMs) {
236
+ stale.push(worktree.worktreePath);
237
+ }
238
+ }
239
+ return stale;
240
+ }
241
+ async scanManagedCandidates(metadataRoot, worktreeRoot, activeWorktrees, runtimePaths) {
242
+ const candidates = [];
243
+ let protectedWorktrees = 0;
244
+ let skippedUnownedDirectories = 0;
245
+ const visit = async (currentPath, root = false) => {
246
+ const entries = await fs.readdir(currentPath, { withFileTypes: true }).catch(error => {
247
+ if (isEnoent(error))
248
+ return [];
249
+ throw error;
250
+ });
251
+ let containsManagedDirectory = false;
252
+ let containsUnownedContent = false;
253
+ for (const entry of entries) {
254
+ if (entry.name === ".forge-cleanup-quarantine") {
255
+ containsUnownedContent = true;
256
+ continue;
257
+ }
258
+ const entryPath = path.join(currentPath, entry.name);
259
+ const stat = await fs.lstat(entryPath).catch(error => {
260
+ if (isEnoent(error))
261
+ return null;
262
+ throw error;
263
+ });
264
+ if (!stat)
265
+ continue;
266
+ if (stat.isSymbolicLink() || !stat.isDirectory()) {
267
+ containsUnownedContent = true;
268
+ continue;
269
+ }
270
+ const realEntry = await fs.realpath(entryPath).catch(error => {
271
+ if (isEnoent(error))
272
+ return null;
273
+ throw error;
274
+ });
275
+ if (!realEntry)
276
+ continue;
277
+ if (!isSubPath(worktreeRoot, realEntry)) {
278
+ throw new Error(`Managed worktree cleanup path escaped ${worktreeRoot}: ${realEntry}.`);
279
+ }
280
+ const activeState = worktreePathState(realEntry, activeWorktrees);
281
+ const runtimeState = worktreePathState(realEntry, runtimePaths);
282
+ if (activeState === "active" || runtimeState === "active") {
283
+ protectedWorktrees += 1;
284
+ containsManagedDirectory = true;
285
+ continue;
286
+ }
287
+ if (activeState === "ancestor" || runtimeState === "ancestor") {
288
+ containsManagedDirectory = await visit(realEntry) || containsManagedDirectory;
289
+ continue;
290
+ }
291
+ const relativePath = path.relative(worktreeRoot, realEntry);
292
+ if (isForgeOwnedWorktreePath(relativePath) && await forgeManagedCandidateIdentity(metadataRoot, realEntry)) {
293
+ candidates.push(realEntry);
294
+ containsManagedDirectory = true;
295
+ continue;
296
+ }
297
+ if (isForgeWorktreeContainer(relativePath) && await visit(realEntry)) {
298
+ containsManagedDirectory = true;
299
+ continue;
300
+ }
301
+ skippedUnownedDirectories += 1;
302
+ containsUnownedContent = true;
303
+ }
304
+ return !containsUnownedContent && (root || containsManagedDirectory);
305
+ };
306
+ const rootRemovalSafe = await visit(worktreeRoot, true);
307
+ return { candidates, protectedWorktrees, skippedUnownedDirectories, rootRemovalSafe };
308
+ }
309
+ async readRuntimeLeases() {
310
+ return await readHostRuntimeLeases(this.stateRoot);
311
+ }
312
+ async worktreeMetadataRoot(repoPath) {
313
+ const commonDirRaw = (await this.git.run(repoPath, ["rev-parse", "--git-common-dir"])).trim();
314
+ const commonDirPath = path.isAbsolute(commonDirRaw) ? commonDirRaw : path.resolve(repoPath, commonDirRaw);
315
+ return path.join(await fs.realpath(commonDirPath), "worktrees");
316
+ }
317
+ }
318
+ function emptyResult(worktreeRoot, force) {
319
+ return {
320
+ worktreeRoot: path.resolve(worktreeRoot),
321
+ removedWorktrees: 0,
322
+ candidateWorktrees: 0,
323
+ protectedWorktrees: 0,
324
+ skippedUnownedDirectories: 0,
325
+ removedRoot: false,
326
+ dryRun: !force,
327
+ };
328
+ }
329
+ async function resolveSafeManagedRoot(worktreeRoot) {
330
+ const rootPath = path.resolve(worktreeRoot);
331
+ const rootStat = await fs.lstat(rootPath).catch(error => {
332
+ if (isEnoent(error))
333
+ return null;
334
+ throw error;
335
+ });
336
+ if (!rootStat)
337
+ return null;
338
+ if (rootStat.isSymbolicLink() || !rootStat.isDirectory()) {
339
+ throw new Error(`Refusing cleanup for redirected or non-directory managed worktree root ${rootPath}.`);
340
+ }
341
+ const parentPath = path.dirname(rootPath);
342
+ const parentStat = await fs.lstat(parentPath);
343
+ if (parentStat.isSymbolicLink() || !parentStat.isDirectory()) {
344
+ throw new Error(`Refusing cleanup for redirected managed worktree root parent ${parentPath}.`);
345
+ }
346
+ const [realParent, realRoot] = await Promise.all([fs.realpath(parentPath), fs.realpath(rootPath)]);
347
+ if (!samePath(path.join(realParent, path.basename(rootPath)), realRoot)) {
348
+ throw new Error(`Refusing cleanup for redirected managed worktree root ${rootPath}.`);
349
+ }
350
+ return realRoot;
351
+ }
352
+ async function forgeManagedCandidateIdentity(metadataRoot, candidatePath) {
353
+ const gitFile = path.join(candidatePath, ".git");
354
+ const stat = await fs.lstat(gitFile).catch(error => {
355
+ if (isEnoent(error))
356
+ return null;
357
+ throw error;
358
+ });
359
+ if (!stat || stat.isSymbolicLink() || !stat.isFile() || stat.size > 16 * 1024)
360
+ return null;
361
+ const contents = (await fs.readFile(gitFile, "utf8")).trim();
362
+ if (!contents.toLowerCase().startsWith("gitdir:"))
363
+ return null;
364
+ const gitDir = contents.slice("gitdir:".length).trim();
365
+ if (!gitDir)
366
+ return null;
367
+ const candidateGitDir = path.resolve(candidatePath, gitDir);
368
+ return !samePath(metadataRoot, candidateGitDir) && isSubPath(metadataRoot, candidateGitDir)
369
+ ? contents
370
+ : null;
371
+ }
372
+ async function quarantineAndRemoveCandidate(worktreeRoot, candidatePath, expectedIdentity) {
373
+ const quarantineRoot = path.join(worktreeRoot, ".forge-cleanup-quarantine");
374
+ await ensureSafeQuarantineRoot(worktreeRoot, quarantineRoot);
375
+ const quarantinePath = path.join(quarantineRoot, randomUUID());
376
+ try {
377
+ await fs.rename(candidatePath, quarantinePath);
378
+ }
379
+ catch (error) {
380
+ if (isEnoent(error))
381
+ return false;
382
+ throw error;
383
+ }
384
+ const quarantinedIdentity = await readGitFileIdentity(quarantinePath);
385
+ if (quarantinedIdentity !== expectedIdentity) {
386
+ await fs.rename(quarantinePath, candidatePath).catch(() => undefined);
387
+ throw new Error(`Refusing cleanup because managed worktree ownership changed while quarantining ${candidatePath}.`);
388
+ }
389
+ await fs.rm(quarantinePath, { recursive: true, force: true });
390
+ await fs.rmdir(quarantineRoot).catch(error => {
391
+ if (!isEnoent(error) && error.code !== "ENOTEMPTY")
392
+ throw error;
393
+ });
394
+ return true;
395
+ }
396
+ async function readGitFileIdentity(candidatePath) {
397
+ const gitFile = path.join(candidatePath, ".git");
398
+ const stat = await fs.lstat(gitFile).catch(error => {
399
+ if (isEnoent(error))
400
+ return null;
401
+ throw error;
402
+ });
403
+ if (!stat || stat.isSymbolicLink() || !stat.isFile() || stat.size > 16 * 1024)
404
+ return null;
405
+ return (await fs.readFile(gitFile, "utf8")).trim();
406
+ }
407
+ async function ensureSafeQuarantineRoot(worktreeRoot, quarantineRoot) {
408
+ await fs.mkdir(quarantineRoot, { recursive: true, mode: 0o700 });
409
+ const stat = await fs.lstat(quarantineRoot);
410
+ if (stat.isSymbolicLink() || !stat.isDirectory()) {
411
+ throw new Error(`Refusing cleanup through redirected quarantine root ${quarantineRoot}.`);
412
+ }
413
+ const realQuarantine = await fs.realpath(quarantineRoot);
414
+ if (!isSubPath(worktreeRoot, realQuarantine)) {
415
+ throw new Error(`Cleanup quarantine escaped managed worktree root ${worktreeRoot}.`);
416
+ }
417
+ }
418
+ async function quarantineAndRemoveRoot(worktreeRoot) {
419
+ const parent = path.dirname(worktreeRoot);
420
+ const quarantinePath = path.join(parent, `.forge-cleanup-${path.basename(worktreeRoot)}-${randomUUID()}`);
421
+ await fs.rename(worktreeRoot, quarantinePath);
422
+ await fs.rm(quarantinePath, { recursive: true, force: true });
423
+ }
424
+ function parseWorktreeListing(repoPath, output) {
425
+ const worktrees = [];
426
+ let current = null;
427
+ for (const field of output.split("\0")) {
428
+ if (field.startsWith("worktree ")) {
429
+ if (current)
430
+ worktrees.push(current);
431
+ const rawPath = field.slice("worktree ".length);
432
+ current = {
433
+ worktreePath: path.resolve(path.isAbsolute(rawPath) ? rawPath : path.join(repoPath, rawPath)),
434
+ prunable: false,
435
+ branchName: null,
436
+ };
437
+ }
438
+ else if (field.startsWith("prunable") && current) {
439
+ current.prunable = true;
440
+ }
441
+ else if (field.startsWith("branch ") && current) {
442
+ current.branchName = field.slice("branch ".length).trim();
443
+ }
444
+ }
445
+ if (current)
446
+ worktrees.push(current);
447
+ return worktrees;
448
+ }
449
+ // A registered worktree counts as a readiness probe only when Forge made it: its folder sits
450
+ // directly in the managed root under the probe's exact name, and it has the probe's exact branch.
451
+ function isRuntimeReadinessWorktree(worktreeRoot, worktree) {
452
+ const folderName = path.basename(worktree.worktreePath);
453
+ return samePath(path.dirname(worktree.worktreePath), worktreeRoot)
454
+ && isRuntimeReadinessName(folderName)
455
+ && worktree.branchName === `refs/heads/${folderName}`;
456
+ }
457
+ function activePaths(worktrees) {
458
+ return worktrees.filter(entry => !entry.prunable).map(entry => entry.worktreePath);
459
+ }
460
+ function worktreePathState(candidate, activePathsToCheck) {
461
+ if (activePathsToCheck.some(activePath => samePath(activePath, candidate)))
462
+ return "active";
463
+ if (activePathsToCheck.some(activePath => isSubPath(candidate, activePath)))
464
+ return "ancestor";
465
+ return "none";
466
+ }
467
+ function uniquePaths(values) {
468
+ return values.filter((value, index) => values.findIndex(candidate => samePath(candidate, value)) === index);
469
+ }
470
+ function samePath(left, right) {
471
+ const normalizedLeft = path.resolve(left);
472
+ const normalizedRight = path.resolve(right);
473
+ return process.platform === "win32"
474
+ ? normalizedLeft.toLowerCase() === normalizedRight.toLowerCase()
475
+ : normalizedLeft === normalizedRight;
476
+ }
477
+ function isEnoent(error) {
478
+ return error?.code === "ENOENT";
5
479
  }
@@ -1,6 +1,22 @@
1
+ export type CleanupMode = "stale" | "merged" | "all";
1
2
  export interface CleanupRequest {
2
3
  readonly repoRoot: string;
4
+ readonly allowedRepoRoot?: string;
5
+ readonly mode: CleanupMode;
6
+ readonly force: boolean;
3
7
  }
4
8
  export interface CleanupResult {
9
+ readonly worktreeRoot: string;
5
10
  readonly removedWorktrees: number;
11
+ readonly candidateWorktrees: number;
12
+ readonly protectedWorktrees: number;
13
+ readonly skippedUnownedDirectories: number;
14
+ readonly removedRoot: boolean;
15
+ readonly dryRun: boolean;
16
+ /** Forge-created local branches deleted by this run: readiness branches, and in merged mode also merged work branches. */
17
+ readonly deletedBranches?: number;
18
+ /** Merged mode only: origin/HEAD was unset or stale and origin had none or several of develop, main and master, so merged work branches were left alone. */
19
+ readonly mergedBaseUnresolved?: boolean;
20
+ /** Stale mode only: stale worktrees kept because their uncommitted work could not be saved first. */
21
+ readonly preservedWorktrees?: number;
6
22
  }
@@ -0,0 +1,9 @@
1
+ import path from "node:path";
2
+ type PathSeparator = typeof path.posix.sep | typeof path.win32.sep;
3
+ /** True when `relativePath` (relative to the managed root) is a worktree path Forge creates. */
4
+ export declare function isForgeOwnedWorktreePath(relativePath: string, separator?: PathSeparator): boolean;
5
+ /** True when `relativePath` is one of the folders Forge groups its worktrees in. */
6
+ export declare function isForgeWorktreeContainer(relativePath: string, separator?: PathSeparator): boolean;
7
+ /** True for a readiness probe's exact folder or branch name: runtime-readiness-<UUID>. */
8
+ export declare function isRuntimeReadinessName(name: string): boolean;
9
+ export {};
@@ -0,0 +1,53 @@
1
+ // Cleanup may delete a worktree folder only when Forge itself created it for one of its own
2
+ // attempts. Forge places every such worktree at an exact path under the repository's managed root
3
+ // (`<repo parent>/.forge-worktrees/<repo name>`), built from the lease's worktree key:
4
+ // <kind>/<12 hex> a work item (story, task, bug, feature, work_order) or
5
+ // its Architect phase (architect)
6
+ // decompose/<feature|work_order>/<12 hex> a decompose session
7
+ // runtime-readiness-<UUID> a runtime readiness probe (session.service.ts)
8
+ // draft-<32 hex> a drafting session (DraftingService on the server)
9
+ // A release that couldn't finish deleting can leave `<one of those>.forge-release-<UUID>` beside it.
10
+ // Anything else under the root, such as a folder a person or another tool made there, is never
11
+ // removed, even if it is a Git worktree of the same repository.
12
+ import path from "node:path";
13
+ const hex12 = "[0-9a-f]{12}";
14
+ const uuid = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
15
+ const releaseSuffix = `(?:\\.forge-release-${uuid})?`;
16
+ const forgeOwnedWorktreePathPattern = new RegExp("^(?:"
17
+ + `(?:story|task|bug|feature|work_order|architect)/${hex12}`
18
+ + `|decompose/(?:feature|work_order)/${hex12}`
19
+ + `|runtime-readiness-${uuid}`
20
+ + "|draft-[0-9a-f]{32}"
21
+ + `)${releaseSuffix}$`);
22
+ const runtimeReadinessNamePattern = new RegExp(`^runtime-readiness-${uuid}$`);
23
+ // Folders that only group Forge's worktrees; cleanup may look inside them but never removes them.
24
+ const forgeWorktreeContainers = new Set([
25
+ "story",
26
+ "task",
27
+ "bug",
28
+ "feature",
29
+ "work_order",
30
+ "architect",
31
+ "decompose",
32
+ "decompose/feature",
33
+ "decompose/work_order",
34
+ ]);
35
+ // Split only on the separators the filesystem itself uses. On POSIX a backslash is an ordinary
36
+ // filename character, so a folder a person named `story\0123456789ab` must not read as Forge's
37
+ // `story/0123456789ab`. Windows accepts both `\` and `/`.
38
+ function normalizeRelativePath(relativePath, separator) {
39
+ const separators = separator === path.win32.sep ? /[\\/]+/u : /\/+/u;
40
+ return relativePath.split(separators).filter(segment => segment.length > 0).join("/");
41
+ }
42
+ /** True when `relativePath` (relative to the managed root) is a worktree path Forge creates. */
43
+ export function isForgeOwnedWorktreePath(relativePath, separator = path.sep) {
44
+ return forgeOwnedWorktreePathPattern.test(normalizeRelativePath(relativePath, separator));
45
+ }
46
+ /** True when `relativePath` is one of the folders Forge groups its worktrees in. */
47
+ export function isForgeWorktreeContainer(relativePath, separator = path.sep) {
48
+ return forgeWorktreeContainers.has(normalizeRelativePath(relativePath, separator));
49
+ }
50
+ /** True for a readiness probe's exact folder or branch name: runtime-readiness-<UUID>. */
51
+ export function isRuntimeReadinessName(name) {
52
+ return runtimeReadinessNamePattern.test(name);
53
+ }
@@ -0,0 +1,7 @@
1
+ import { type RuntimeIsolationLease } from "../runtime/runtime-isolation-lease.js";
2
+ /** Reads every host runtime lease, or throws if any ledger file can't be trusted. */
3
+ export declare function readHostRuntimeLeases(stateRoot: string): Promise<readonly RuntimeIsolationLease[]>;
4
+ /** Branches that a lease which isn't released yet may still use. */
5
+ export declare function liveLeaseBranches(leases: readonly RuntimeIsolationLease[]): ReadonlySet<string>;
6
+ /** A runtime lease's worktree path, resolved; throws when it is redirected or changes while being resolved. */
7
+ export declare function resolveRuntimeLeasePath(leasePath: string): Promise<string>;