@loucompanion/forge-bridge 0.1.4-dev.fb770705136a → 0.2.1-dev.0f07274d438b

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 (329) hide show
  1. package/README.md +183 -4
  2. package/dist/bridge/bridge-chat-giphy-look.d.ts +48 -0
  3. package/dist/bridge/bridge-chat-giphy-look.js +55 -0
  4. package/dist/bridge/bridge-chat-provider-command.d.ts +40 -0
  5. package/dist/bridge/bridge-chat-provider-command.js +230 -0
  6. package/dist/bridge/bridge-chat.types.d.ts +20 -0
  7. package/dist/bridge/bridge-chat.types.js +28 -1
  8. package/dist/bridge/bridge-state-file.d.ts +161 -0
  9. package/dist/bridge/bridge-state-file.js +376 -0
  10. package/dist/bridge/bridge-state-io.d.ts +15 -0
  11. package/dist/bridge/bridge-state-io.js +68 -0
  12. package/dist/bridge/bridge-state-lock.d.ts +11 -0
  13. package/dist/bridge/bridge-state-lock.js +102 -0
  14. package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
  15. package/dist/bridge/bridge-state-unpublished.js +111 -0
  16. package/dist/bridge/bridge.base.d.ts +9 -0
  17. package/dist/bridge/bridge.service.d.ts +102 -14
  18. package/dist/bridge/bridge.service.js +499 -471
  19. package/dist/bridge/bridge.types.d.ts +37 -0
  20. package/dist/bridge/bridge.types.js +2 -1
  21. package/dist/bridge/default-session-service.d.ts +13 -0
  22. package/dist/bridge/default-session-service.js +22 -0
  23. package/dist/bridge/dispatch-offer-policy.d.ts +22 -0
  24. package/dist/bridge/dispatch-offer-policy.js +58 -0
  25. package/dist/bridge/in-flight-registry.d.ts +62 -0
  26. package/dist/bridge/in-flight-registry.js +207 -0
  27. package/dist/bridge/local-yield-flag.d.ts +6 -0
  28. package/dist/bridge/local-yield-flag.js +34 -0
  29. package/dist/bridge/readiness-result-outbox.d.ts +5 -1
  30. package/dist/bridge/readiness-result-outbox.js +20 -0
  31. package/dist/bridge/runner-host-capabilities.d.ts +5 -0
  32. package/dist/bridge/runner-host-capabilities.js +31 -1
  33. package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
  34. package/dist/bridge/sandbox-resource-accounting.js +150 -0
  35. package/dist/bridge/test-postgres-capability.d.ts +14 -0
  36. package/dist/bridge/test-postgres-capability.js +120 -0
  37. package/dist/bridge/windows-bash-resolution.d.ts +31 -0
  38. package/dist/bridge/windows-bash-resolution.js +153 -0
  39. package/dist/cleanup/cleanup-wip.d.ts +12 -0
  40. package/dist/cleanup/cleanup-wip.js +66 -0
  41. package/dist/cleanup/cleanup.service.d.ts +20 -1
  42. package/dist/cleanup/cleanup.service.js +150 -169
  43. package/dist/cleanup/cleanup.types.d.ts +6 -0
  44. package/dist/cleanup/forge-owned-paths.d.ts +11 -0
  45. package/dist/cleanup/forge-owned-paths.js +62 -0
  46. package/dist/cleanup/host-runtime-ledger.d.ts +7 -0
  47. package/dist/cleanup/host-runtime-ledger.js +130 -0
  48. package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
  49. package/dist/cleanup/managed-branch-sweep.js +111 -0
  50. package/dist/cli/cli.help.js +75 -13
  51. package/dist/cli/cli.service.d.ts +19 -10
  52. package/dist/cli/cli.service.js +161 -228
  53. package/dist/cli/idle-status.d.ts +84 -0
  54. package/dist/cli/idle-status.js +181 -0
  55. package/dist/cli/local-config.d.ts +18 -1
  56. package/dist/cli/local-config.js +67 -5
  57. package/dist/cli/provider-cli-advertising.d.ts +24 -0
  58. package/dist/cli/provider-cli-advertising.js +88 -0
  59. package/dist/cli/provider-cli-detection.d.ts +10 -0
  60. package/dist/cli/provider-cli-detection.js +160 -0
  61. package/dist/runtime/aspnet-runtime-prebuild.d.ts +20 -0
  62. package/dist/runtime/aspnet-runtime-prebuild.js +184 -18
  63. package/dist/runtime/attempt-database-broker.d.ts +1 -1
  64. package/dist/runtime/attempt-node-runtime-launcher.d.ts +36 -0
  65. package/dist/runtime/attempt-node-runtime-launcher.js +169 -0
  66. package/dist/runtime/attempt-process-supervisor.d.ts +2 -0
  67. package/dist/runtime/attempt-process-supervisor.js +12 -6
  68. package/dist/runtime/docker-engine-probe.d.ts +5 -0
  69. package/dist/runtime/docker-engine-probe.js +7 -0
  70. package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
  71. package/dist/runtime/dotnet-build-outputs.js +402 -0
  72. package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
  73. package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
  74. package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
  75. package/dist/runtime/ephemeral-test-postgres.js +303 -0
  76. package/dist/runtime/host-facts.d.ts +2 -1
  77. package/dist/runtime/host-listener-inspector.d.ts +26 -0
  78. package/dist/runtime/host-listener-inspector.js +84 -3
  79. package/dist/runtime/host-load-admission.d.ts +72 -0
  80. package/dist/runtime/host-load-admission.js +99 -0
  81. package/dist/runtime/host-load-capacity.d.ts +198 -0
  82. package/dist/runtime/host-load-capacity.js +353 -0
  83. package/dist/runtime/host-load-child-environment.d.ts +40 -0
  84. package/dist/runtime/host-load-child-environment.js +110 -0
  85. package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
  86. package/dist/runtime/host-load-forge-cgroups.js +140 -0
  87. package/dist/runtime/host-load-governor-config.d.ts +82 -0
  88. package/dist/runtime/host-load-governor-config.js +104 -0
  89. package/dist/runtime/host-load-governor.d.ts +273 -0
  90. package/dist/runtime/host-load-governor.js +831 -0
  91. package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
  92. package/dist/runtime/host-load-ledger-lock.js +187 -0
  93. package/dist/runtime/host-load-live-test-slots.d.ts +61 -0
  94. package/dist/runtime/host-load-live-test-slots.js +193 -0
  95. package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
  96. package/dist/runtime/host-load-runtime-settings.js +80 -0
  97. package/dist/runtime/host-load-sampler.d.ts +92 -2
  98. package/dist/runtime/host-load-sampler.js +166 -8
  99. package/dist/runtime/host-load-step-class.d.ts +70 -0
  100. package/dist/runtime/host-load-step-class.js +161 -0
  101. package/dist/runtime/host-load-step-reaper.d.ts +27 -0
  102. package/dist/runtime/host-load-step-reaper.js +95 -0
  103. package/dist/runtime/host-load-step-run.d.ts +107 -0
  104. package/dist/runtime/host-load-step-run.js +158 -0
  105. package/dist/runtime/host-load-test-slot.d.ts +46 -0
  106. package/dist/runtime/host-load-test-slot.js +100 -0
  107. package/dist/runtime/host-load-token-ledger.d.ts +200 -0
  108. package/dist/runtime/host-load-token-ledger.js +453 -0
  109. package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
  110. package/dist/runtime/host-load-windows-cpu.js +85 -0
  111. package/dist/runtime/host-pressure-stall.d.ts +21 -1
  112. package/dist/runtime/host-pressure-stall.js +48 -1
  113. package/dist/runtime/host-runtime-contract.d.ts +15 -0
  114. package/dist/runtime/host-runtime-contract.js +39 -6
  115. package/dist/runtime/host-runtime-lease.d.ts +101 -6
  116. package/dist/runtime/host-runtime-lease.js +408 -294
  117. package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
  118. package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
  119. package/dist/runtime/host-runtime-promotion.d.ts +101 -2
  120. package/dist/runtime/host-runtime-promotion.js +355 -14
  121. package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
  122. package/dist/runtime/host-runtime-requirements-check.js +29 -0
  123. package/dist/runtime/host-runtime-requirements.d.ts +36 -0
  124. package/dist/runtime/host-runtime-requirements.js +117 -0
  125. package/dist/runtime/managed-command-teardown.js +5 -16
  126. package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
  127. package/dist/runtime/native-test-postgres-fallback.js +60 -8
  128. package/dist/runtime/playwright-host-runtime-adapter.d.ts +7 -0
  129. package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
  130. package/dist/runtime/prepared-runtime-identity.d.ts +4 -0
  131. package/dist/runtime/prepared-runtime-identity.js +130 -9
  132. package/dist/runtime/prepared-runtime-readiness.d.ts +23 -1
  133. package/dist/runtime/prepared-runtime-readiness.js +89 -18
  134. package/dist/runtime/runner-settings.d.ts +104 -0
  135. package/dist/runtime/runner-settings.js +236 -0
  136. package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
  137. package/dist/runtime/supervised-runtime-build-guard.js +112 -0
  138. package/dist/sandbox/host-capacity-broker.d.ts +115 -0
  139. package/dist/sandbox/host-capacity-broker.js +336 -0
  140. package/dist/sandbox/managed-branch.d.ts +13 -0
  141. package/dist/sandbox/managed-branch.js +90 -0
  142. package/dist/sandbox/provider-auth/codex.js +11 -11
  143. package/dist/sandbox/runtime.d.ts +11 -3
  144. package/dist/sandbox/runtime.js +53 -20
  145. package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
  146. package/dist/sandbox/sandbox-cgroups.js +42 -0
  147. package/dist/sandbox/sandbox-input.d.ts +22 -0
  148. package/dist/sandbox/sandbox-input.js +49 -0
  149. package/dist/sandbox/workspace.service.js +15 -2
  150. package/dist/session/architect-waits.d.ts +2 -0
  151. package/dist/session/architect-waits.js +138 -0
  152. package/dist/session/managed-attempt-tools.d.ts +2 -7
  153. package/dist/session/managed-attempt-tools.js +204 -141
  154. package/dist/session/managed-build-coordinator.d.ts +16 -0
  155. package/dist/session/managed-build-coordinator.js +10 -0
  156. package/dist/session/managed-build-receipt.d.ts +7 -0
  157. package/dist/session/managed-build-receipt.js +11 -3
  158. package/dist/session/managed-command-environment.d.ts +8 -0
  159. package/dist/session/managed-command-environment.js +28 -0
  160. package/dist/session/managed-command-host-load.d.ts +52 -0
  161. package/dist/session/managed-command-host-load.js +87 -0
  162. package/dist/session/mcp-argument-coercion.d.ts +23 -0
  163. package/dist/session/mcp-argument-coercion.js +121 -0
  164. package/dist/session/phase-completion.artifact-bundle.d.ts +20 -0
  165. package/dist/session/phase-completion.artifact-bundle.js +167 -0
  166. package/dist/session/phase-completion.artifacts.d.ts +9 -17
  167. package/dist/session/phase-completion.artifacts.js +158 -190
  168. package/dist/session/phase-completion.command-validation.d.ts +7 -0
  169. package/dist/session/phase-completion.command-validation.js +77 -0
  170. package/dist/session/phase-completion.d.ts +31 -2
  171. package/dist/session/phase-completion.helpers.js +18 -65
  172. package/dist/session/phase-completion.js +19 -32
  173. package/dist/session/phase-completion.mcp-args.d.ts +9 -0
  174. package/dist/session/phase-completion.mcp-args.js +195 -0
  175. package/dist/session/phase-completion.phase-aliases.d.ts +5 -0
  176. package/dist/session/phase-completion.phase-aliases.js +43 -0
  177. package/dist/session/phase-completion.pr-review-schema.d.ts +1 -0
  178. package/dist/session/phase-completion.pr-review-schema.js +75 -0
  179. package/dist/session/phase-completion.pr-review-validation.d.ts +11 -0
  180. package/dist/session/phase-completion.pr-review-validation.js +212 -0
  181. package/dist/session/phase-completion.pr-review.d.ts +36 -0
  182. package/dist/session/phase-completion.pr-review.js +294 -0
  183. package/dist/session/phase-completion.prompts.d.ts +1 -1
  184. package/dist/session/phase-completion.prompts.js +20 -1
  185. package/dist/session/phase-completion.runtime.d.ts +13 -12
  186. package/dist/session/phase-completion.runtime.js +113 -214
  187. package/dist/session/phase-completion.schema-parts.d.ts +19 -0
  188. package/dist/session/phase-completion.schema-parts.js +188 -0
  189. package/dist/session/phase-completion.schemas.d.ts +3 -3
  190. package/dist/session/phase-completion.schemas.js +219 -232
  191. package/dist/session/phase-completion.validation.d.ts +3 -3
  192. package/dist/session/phase-completion.validation.js +58 -94
  193. package/dist/session/pr-review-diff-base.d.ts +18 -0
  194. package/dist/session/pr-review-diff-base.js +44 -0
  195. package/dist/session/pr-review-placement.d.ts +50 -0
  196. package/dist/session/pr-review-placement.js +91 -0
  197. package/dist/session/pre-publication-change-set.d.ts +62 -0
  198. package/dist/session/pre-publication-change-set.js +166 -0
  199. package/dist/session/pre-publication-host-load.d.ts +27 -0
  200. package/dist/session/pre-publication-host-load.js +112 -0
  201. package/dist/session/pre-publication-native-postgres.d.ts +30 -0
  202. package/dist/session/pre-publication-native-postgres.js +111 -0
  203. package/dist/session/pre-publication-pass.d.ts +61 -0
  204. package/dist/session/pre-publication-pass.js +148 -0
  205. package/dist/session/pre-publication-process.d.ts +3 -0
  206. package/dist/session/pre-publication-process.js +32 -19
  207. package/dist/session/pre-publication-step-execution.d.ts +12 -0
  208. package/dist/session/pre-publication-step-execution.js +50 -0
  209. package/dist/session/pre-publication-validation.d.ts +39 -22
  210. package/dist/session/pre-publication-validation.js +241 -207
  211. package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
  212. package/dist/session/provider-cli/claude-background-work.js +181 -0
  213. package/dist/session/provider-cli/dispatch-target-branch.d.ts +7 -0
  214. package/dist/session/provider-cli/dispatch-target-branch.js +8 -0
  215. package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
  216. package/dist/session/provider-cli/host-build-lock.js +30 -0
  217. package/dist/session/provider-cli/pr-review-credential-isolation.d.ts +83 -0
  218. package/dist/session/provider-cli/pr-review-credential-isolation.js +144 -0
  219. package/dist/session/provider-cli/pr-review-guardrails.d.ts +70 -0
  220. package/dist/session/provider-cli/pr-review-guardrails.js +360 -0
  221. package/dist/session/provider-cli/pr-review-prompt.d.ts +2 -0
  222. package/dist/session/provider-cli/pr-review-prompt.js +119 -0
  223. package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
  224. package/dist/session/provider-cli/pre-publication-repair.js +281 -0
  225. package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
  226. package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
  227. package/dist/session/provider-cli/provider-cli.child-environment.js +75 -0
  228. package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
  229. package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
  230. package/dist/session/provider-cli/provider-cli.deterministic.d.ts +1 -0
  231. package/dist/session/provider-cli/provider-cli.deterministic.js +5 -0
  232. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +6 -3
  233. package/dist/session/provider-cli/provider-cli.merge-integrity.js +29 -10
  234. package/dist/session/provider-cli/provider-cli.pr-review.d.ts +23 -0
  235. package/dist/session/provider-cli/provider-cli.pr-review.js +213 -0
  236. package/dist/session/provider-cli/provider-cli.process.d.ts +15 -36
  237. package/dist/session/provider-cli/provider-cli.process.js +41 -432
  238. package/dist/session/provider-cli/provider-cli.prompts.d.ts +15 -3
  239. package/dist/session/provider-cli/provider-cli.prompts.js +183 -90
  240. package/dist/session/provider-cli/provider-cli.reapply-conflicts.d.ts +10 -0
  241. package/dist/session/provider-cli/provider-cli.reapply-conflicts.js +37 -0
  242. package/dist/session/provider-cli/provider-cli.runtime.d.ts +15 -0
  243. package/dist/session/provider-cli/provider-cli.runtime.js +43 -1
  244. package/dist/session/provider-cli/provider-cli.service-support.d.ts +37 -0
  245. package/dist/session/provider-cli/provider-cli.service-support.js +146 -0
  246. package/dist/session/provider-cli/provider-cli.service.d.ts +18 -18
  247. package/dist/session/provider-cli/provider-cli.service.js +127 -317
  248. package/dist/session/provider-cli/provider-cli.types.d.ts +35 -0
  249. package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
  250. package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
  251. package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
  252. package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
  253. package/dist/session/provider-cli/provider-in-flight-work.d.ts +4 -0
  254. package/dist/session/provider-cli/provider-in-flight-work.js +45 -0
  255. package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
  256. package/dist/session/provider-cli/provider-output-pipes.js +67 -0
  257. package/dist/session/provider-cli/provider-output-state.d.ts +2 -0
  258. package/dist/session/provider-cli/provider-output-state.js +6 -0
  259. package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
  260. package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
  261. package/dist/session/qa-sidecar-validation.d.ts +6 -0
  262. package/dist/session/qa-sidecar-validation.js +28 -0
  263. package/dist/session/sandbox-host-capacity-gate.d.ts +51 -0
  264. package/dist/session/sandbox-host-capacity-gate.js +279 -0
  265. package/dist/session/session-host-project.d.ts +22 -0
  266. package/dist/session/session-host-project.js +98 -0
  267. package/dist/session/session-redaction.js +31 -181
  268. package/dist/session/session.base.d.ts +9 -1
  269. package/dist/session/session.parse-helpers.d.ts +10 -0
  270. package/dist/session/session.parse-helpers.js +84 -0
  271. package/dist/session/session.runtime-refresh.d.ts +46 -0
  272. package/dist/session/session.runtime-refresh.js +116 -0
  273. package/dist/session/session.service.d.ts +16 -2
  274. package/dist/session/session.service.js +208 -155
  275. package/dist/session/session.types.d.ts +8 -0
  276. package/dist/session/session.types.js +13 -83
  277. package/dist/session/session.types.pr-review.d.ts +48 -0
  278. package/dist/session/session.types.pr-review.js +51 -0
  279. package/dist/session/sidecar-json-shape.d.ts +31 -0
  280. package/dist/session/sidecar-json-shape.js +217 -0
  281. package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
  282. package/dist/session/workspace-runtime-fingerprint.js +138 -0
  283. package/dist/shared/fs/file-identity.d.ts +10 -0
  284. package/dist/shared/fs/file-identity.js +15 -0
  285. package/dist/shared/fs/replace-file.d.ts +7 -0
  286. package/dist/shared/fs/replace-file.js +33 -0
  287. package/dist/shared/process/host-process-recovery.d.ts +14 -3
  288. package/dist/shared/process/host-process-recovery.js +23 -3
  289. package/dist/shared/process/host-process-supervisor.d.ts +14 -1
  290. package/dist/shared/process/host-process-supervisor.js +67 -15
  291. package/dist/shared/process/process-tree.d.ts +52 -0
  292. package/dist/shared/process/process-tree.js +144 -0
  293. package/dist/shared/process/process.d.ts +67 -0
  294. package/dist/shared/process/process.js +213 -11
  295. package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
  296. package/dist/shared/process/windows-app-execution-alias.js +45 -0
  297. package/dist/shared/process/windows-launch.d.ts +18 -0
  298. package/dist/shared/process/windows-launch.js +68 -0
  299. package/dist/shared/provider-capabilities.d.ts +2 -0
  300. package/dist/shared/provider-capabilities.js +23 -7
  301. package/dist/version.d.ts +1 -1
  302. package/dist/version.js +1 -1
  303. package/dist/worktree/artifact-injector.js +24 -0
  304. package/dist/worktree/dependency-warmer.d.ts +25 -0
  305. package/dist/worktree/dependency-warmer.js +46 -10
  306. package/dist/worktree/orphan-relink.d.ts +19 -0
  307. package/dist/worktree/orphan-relink.js +106 -0
  308. package/dist/worktree/wip-git.d.ts +58 -0
  309. package/dist/worktree/wip-git.js +182 -0
  310. package/dist/worktree/wip-refs.d.ts +85 -0
  311. package/dist/worktree/wip-refs.js +169 -0
  312. package/dist/worktree/wip-restore.d.ts +51 -0
  313. package/dist/worktree/wip-restore.js +324 -0
  314. package/dist/worktree/wip-snapshot.d.ts +53 -0
  315. package/dist/worktree/wip-snapshot.js +270 -0
  316. package/dist/worktree/worktree-inputs.d.ts +8 -0
  317. package/dist/worktree/worktree-inputs.js +134 -0
  318. package/dist/worktree/worktree-origin-sync.d.ts +35 -0
  319. package/dist/worktree/worktree-origin-sync.js +128 -0
  320. package/dist/worktree/worktree-wip-events.d.ts +20 -0
  321. package/dist/worktree/worktree-wip-events.js +148 -0
  322. package/dist/worktree/worktree-wip.d.ts +57 -0
  323. package/dist/worktree/worktree-wip.js +200 -0
  324. package/dist/worktree/worktree.base.d.ts +7 -1
  325. package/dist/worktree/worktree.service.d.ts +58 -5
  326. package/dist/worktree/worktree.service.js +237 -161
  327. package/dist/worktree/worktree.types.d.ts +54 -0
  328. package/package.json +2 -2
  329. package/runtime/windows-listener-owner.ps1 +12 -1
@@ -0,0 +1,148 @@
1
+ /** Reports what the prepare did with the story's saved WIP, before the provider starts. */
2
+ export async function emitWipRestoreEvent(worktree, emit) {
3
+ const outcome = worktree.wipRestore;
4
+ if (!outcome || outcome.status === "none")
5
+ return;
6
+ if (outcome.status === "restored" && outcome.reapplied) {
7
+ await emit(checkpoint("worktree_wip_restored", reappliedSummary(worktree.branchName, outcome, outcome.reapplied), outcome));
8
+ }
9
+ else if (outcome.status === "restored") {
10
+ await emit(checkpoint("worktree_wip_restored", `Restored uncommitted work saved in ${outcome.ref}${outcome.sourceSessionId ? ` by session ${outcome.sourceSessionId}` : ""} `
11
+ + `(${outcome.changedPaths} path(s)${outcome.mergeInProgress ? ", with its merge still in progress" : ""}) onto ${worktree.branchName} before the provider started.`
12
+ + carriedConflictsText(outcome.reapplyConflicts), outcome));
13
+ }
14
+ else if (outcome.status === "not_restored") {
15
+ await emit(checkpoint("worktree_wip_not_restored", `Did not restore the uncommitted work saved in ${outcome.ref}: ${outcome.reason === "branch_moved" ? "the story branch has moved since it was saved" : "it could not be applied"}. `
16
+ + `${outcome.detail} This pass starts from a clean worktree; the ref is kept on origin.`, outcome));
17
+ }
18
+ else if (outcome.status === "skipped_dirty") {
19
+ await emit(checkpoint("worktree_wip_restore_skipped", `${worktree.branchName} already has uncommitted changes in its reattached worktree, so ${outcome.ref} was not applied on top of them.`, outcome));
20
+ }
21
+ else {
22
+ await emit(checkpoint("worktree_wip_restore_unavailable", `Could not check origin for saved uncommitted work on ${worktree.branchName}: ${outcome.detail}`, outcome));
23
+ }
24
+ }
25
+ /** The checkpoint for a snapshot re-applied across a branch move: clean, or with the paths left for the agent. */
26
+ function reappliedSummary(branchName, outcome, reapplied) {
27
+ const moved = `${branchName} had moved from ${reapplied.snapshotBaseHead.slice(0, 12)} to ${outcome.baseHead.slice(0, 12)} since it was saved`;
28
+ if (reapplied.conflictedPaths.length === 0) {
29
+ return `Re-applied the uncommitted work saved in ${outcome.ref} across a branch move (${moved}): a 3-way merge onto the new HEAD `
30
+ + `was clean (${outcome.changedPaths} path(s)) and is restored before the provider started.`;
31
+ }
32
+ const listed = reapplied.conflictedPaths.slice(0, maxListedConflicts).join(", ");
33
+ const more = reapplied.conflictedPaths.length > maxListedConflicts ? ` and ${reapplied.conflictedPaths.length - maxListedConflicts} more` : "";
34
+ return `Re-applied the uncommitted work saved in ${outcome.ref} across a branch move with ${reapplied.conflictedPaths.length} conflict(s) `
35
+ + `left for the agent to resolve: ${listed}${more}. ${moved}; the conflicted paths are unmerged with conflict markers, `
36
+ + `Forge will not publish them unresolved, and the ref is kept on origin.`;
37
+ }
38
+ const maxListedConflicts = 20;
39
+ /** For a snapshot restored as it was: the unresolved conflicts an earlier re-apply left in it. */
40
+ function carriedConflictsText(paths) {
41
+ if (paths.length === 0)
42
+ return "";
43
+ const more = paths.length > maxListedConflicts ? ` and ${paths.length - maxListedConflicts} more` : "";
44
+ return ` It still holds ${paths.length} conflict(s) from an earlier re-apply for the agent to resolve: `
45
+ + `${paths.slice(0, maxListedConflicts).join(", ")}${more}.`;
46
+ }
47
+ /** How a session ended, for the snapshot it leaves behind. */
48
+ export function sessionWipOutcome(signal, events, succeeded) {
49
+ if (succeeded)
50
+ return { reason: null };
51
+ if (signal?.aborted)
52
+ return { reason: isPauseRequested(signal) ? "session_paused" : "session_stopped" };
53
+ const repairLimit = events.some(event => event.eventType === "prepublication_repair_exhausted");
54
+ return { reason: repairLimit ? "repair_limit" : "session_failed" };
55
+ }
56
+ /**
57
+ * Ends a session's use of its worktree: first saves its WIP (or retires the snapshot it started
58
+ * from) and reports that, then, as a separate step, releases the worktree unless the session
59
+ * paused or its WIP could not be saved. Nothing here throws over the session's own result or
60
+ * failure: a release that refuses to delete unsaved work, or that fails (a Windows process still
61
+ * holding a cwd in the worktree makes the rename fail), keeps the worktree on this runner and is
62
+ * reported as a cleanup failure.
63
+ */
64
+ export async function settleWorktree(worktrees, worktree, outcome, signal, emit) {
65
+ const settlement = await worktrees.settleWip?.(worktree, outcome)
66
+ .catch((error) => ({ error: { code: "wip_snapshot_failed", message: messageOf(error) } }));
67
+ if (settlement)
68
+ await emitSettlement(worktree, outcome, settlement, emit).catch(() => undefined);
69
+ // A paused session keeps its worktree for the resume, exactly as before. So does a session whose
70
+ // work could not be saved: the release's own snapshot is never applied automatically, so letting
71
+ // it succeed after this one failed would delete the only copy a later pass would restore.
72
+ if (isPauseRequested(signal) || settlement?.error)
73
+ return;
74
+ try {
75
+ await worktrees.release(worktree);
76
+ }
77
+ catch (error) {
78
+ if (!(error instanceof Error) || error.name !== "WipPreservationError") {
79
+ await emit({
80
+ role: "runner",
81
+ kind: "error",
82
+ content: `Could not remove the worktree ${worktree.worktreePath} after the session (${messageOf(error)}); it stays on this runner.`,
83
+ eventType: "worktree_release_failed",
84
+ data: JSON.stringify({ stage: "release", worktreePath: worktree.worktreePath, message: messageOf(error) }),
85
+ }).catch(() => undefined);
86
+ return;
87
+ }
88
+ await emit({
89
+ role: "runner",
90
+ kind: "error",
91
+ content: `Kept the worktree ${worktree.worktreePath} on this runner instead of removing it: its uncommitted work could not be saved (${error.message}).`,
92
+ eventType: "worktree_wip_snapshot_failed",
93
+ data: JSON.stringify({ code: error.code ?? "wip_snapshot_failed", stage: "release", worktreePath: worktree.worktreePath }),
94
+ }).catch(() => undefined);
95
+ }
96
+ }
97
+ async function emitSettlement(worktree, outcome, settlement, emit) {
98
+ const snapshot = settlement.snapshot;
99
+ if (snapshot && snapshot.status !== "clean") {
100
+ await emit(checkpoint("worktree_wip_saved", `Saved this session's uncommitted work (${snapshot.changedPaths} path(s)) to ${snapshot.ref}${snapshot.pushed ? " on origin" : " in the runner's repository (it has no origin)"} `
101
+ + `before the session ended (${outcome.reason}). The next pass on ${worktree.branchName} restores it, re-applying it if the branch has moved.`, { ...snapshot, reason: outcome.reason, lane: worktree.lane ?? null }));
102
+ }
103
+ if (settlement.error) {
104
+ await emit({
105
+ role: "runner",
106
+ kind: "error",
107
+ content: `Could not save this session's uncommitted work to a WIP ref (${settlement.error.message}). Forge will not delete the worktree ${worktree.worktreePath}; the work stays on this runner only.`,
108
+ eventType: "worktree_wip_snapshot_failed",
109
+ data: JSON.stringify({ ...settlement.error, stage: "session_end", reason: outcome.reason, worktreePath: worktree.worktreePath }),
110
+ });
111
+ }
112
+ if (settlement.retiredRef) {
113
+ await emit(checkpoint("worktree_wip_retired", `Deleted ${settlement.retiredRef}: the work restored from it is now ${outcome.reason ? "saved again by this session" : "published by this session"}.`, { ref: settlement.retiredRef }));
114
+ }
115
+ }
116
+ function isPauseRequested(signal) {
117
+ return signal?.aborted === true && String(signal.reason ?? "").trim().toLowerCase() === "session pause requested";
118
+ }
119
+ function checkpoint(eventType, content, data) {
120
+ return { role: "runner", kind: "checkpoint", content, eventType, data: JSON.stringify(data) };
121
+ }
122
+ function messageOf(error) {
123
+ return error instanceof Error ? error.message : String(error);
124
+ }
125
+ // A WIP re-apply across a branch move can leave conflicts for the agent to resolve (wip-restore.ts):
126
+ // unmerged paths with conflict markers, kept in the worktree's re-apply conflict record. Those
127
+ // markers break any build of the worktree, so a host-runtime project start (the ASP.NET prebuild)
128
+ // would fail in prepare, before the agent could ever resolve them; the failure would be saved into
129
+ // the next snapshot, re-applied, and fail the same way on every retry. So while recorded conflicts
130
+ // are unresolved the session does not start the project stack: the agent runs first, is told which
131
+ // paths to resolve, and pre-publication validation then starts the stack from the resolved source
132
+ // (a failure there is a repair turn, not a prepare failure). The prepared-readiness probe skips such
133
+ // a worktree too (prepared-runtime-readiness.ts), and the prompt names the paths
134
+ // (withReapplyConflictInstruction in provider-cli.prompts.ts).
135
+ /** The checkpoint for a project start held back until the agent resolves the re-apply conflicts. */
136
+ export function deferredProjectStartEvent(paths) {
137
+ const listed = paths.slice(0, maxListedConflicts).join(", ");
138
+ const more = paths.length > maxListedConflicts ? ` and ${paths.length - maxListedConflicts} more` : "";
139
+ return {
140
+ role: "runner",
141
+ kind: "checkpoint",
142
+ content: `Deferred the attempt's application stack start: ${paths.length} path(s) restored from saved work still have unresolved `
143
+ + `re-apply conflicts (${listed}${more}), which would fail its build. The agent resolves them first; Forge starts the stack `
144
+ + "before pre-publication validation.",
145
+ eventType: "host_runtime_project_start_deferred",
146
+ data: JSON.stringify({ reason: "wip_reapply_conflicts", reapply_conflicts: paths }),
147
+ };
148
+ }
@@ -0,0 +1,57 @@
1
+ import { GitClient } from "../shared/git/git.js";
2
+ import { type WipRestoreOutcome } from "./wip-restore.js";
3
+ import { type WipSnapshotResult } from "./wip-snapshot.js";
4
+ import type { WipSessionOutcome, WipSettlement, WorktreeHandle } from "./worktree.types.js";
5
+ export { relinkOrphanedWorktree } from "./orphan-relink.js";
6
+ /**
7
+ * Saves uncommitted work before `git reset --hard` / `git clean` on an existing worktree; a later
8
+ * pass may apply it by itself only when it came from a publishing lane.
9
+ * Throws when it could not be saved: losing work is worse than a failed prepare.
10
+ */
11
+ export declare function guardWorktreeReset(worktreePath: string, branchName: string, owner: {
12
+ readonly sessionId?: string | null;
13
+ readonly lane: string;
14
+ readonly wipAttempt?: number | null;
15
+ }): Promise<WipSnapshotResult>;
16
+ /**
17
+ * Before a local branch is re-pointed at a new start point (`worktree add -B`), saves any commits
18
+ * on it that neither the start point nor origin has, as a `forge.wip.v1` snapshot like any other:
19
+ * its tree is the tip's, its first parent the tip (so the commits are `<ref>^1` and its ancestors),
20
+ * and it is never applied automatically. Throws when they could not be saved.
21
+ */
22
+ export declare function guardBranchReset(git: GitClient, repoPath: string, branchName: string, startPoint: string): Promise<void>;
23
+ /** Puts the newest restorable snapshot back on a freshly prepared worktree of a publishing lane. */
24
+ export declare function restoreWorktreeWip(input: {
25
+ readonly worktreePath: string;
26
+ readonly repoPath: string;
27
+ readonly branchName: string;
28
+ readonly sessionId?: string | null;
29
+ readonly lane: string;
30
+ }): Promise<WipRestoreOutcome | undefined>;
31
+ /**
32
+ * The worktree's recorded WIP re-apply conflicts that still have conflict stages or markers (see
33
+ * wipReapplyConflictRecordName); [] when there are none. Throws when the record or the index cannot
34
+ * be read: an unknown conflict state is never treated as conflict-free.
35
+ */
36
+ export declare function unresolvedWorktreeReapplyConflicts(worktreePath: string): Promise<readonly string[]>;
37
+ /**
38
+ * Saves a worktree that is about to be deleted. Its snapshot is never applied automatically (a
39
+ * session that ended without succeeding has already saved its own work under its id; what is
40
+ * left after a successful pass was deliberately not published). Throws when it could not be saved.
41
+ */
42
+ export declare function guardWorktreeRelease(handle: WorktreeHandle): Promise<WipSnapshotResult>;
43
+ /** Forgets what this process saved for a worktree once it is gone. */
44
+ export declare function worktreeReleased(handle: WorktreeHandle): void;
45
+ /**
46
+ * At the end of a session: saves its uncommitted work unless it succeeded, and deletes the
47
+ * snapshot it started from once that work is safe elsewhere: saved again here, or (after a
48
+ * success) published, which is only certain when nothing is left uncommitted. Leftovers keep the
49
+ * ref; the release's own snapshot of them is never applied automatically.
50
+ * Never throws; a failure is reported in the result.
51
+ */
52
+ export declare function settleSessionWip(handle: WorktreeHandle, outcome: WipSessionOutcome): Promise<WipSettlement>;
53
+ /**
54
+ * After a release: deletes the readiness probe's branch, and other Forge branches whose work is
55
+ * already on the base. Branches of live leases are kept; when the ledger can't be read, nothing is.
56
+ */
57
+ export declare function sweepBranchesAfterRelease(git: GitClient, handle: WorktreeHandle, leaseStateRoot: string, limit: number): Promise<void>;
@@ -0,0 +1,200 @@
1
+ import { liveLeaseBranches, readHostRuntimeLeases } from "../cleanup/host-runtime-ledger.js";
2
+ import { deleteBranchIfUnused, isRuntimeReadinessBranch, sweepManagedBranches } from "../cleanup/managed-branch-sweep.js";
3
+ import { unresolvedReapplyConflicts, WipGit } from "./wip-git.js";
4
+ import { formatWipCommitMessage, unorderedWipAttempt, wipMetadataSchema, WipPreservationError, wipRefId, wipRefName, } from "./wip-refs.js";
5
+ import { deleteWipRef, hasNoUnsavedWork, restoreLatestWip } from "./wip-restore.js";
6
+ import { forgetPreservedWip, forgetPreservedWipRef, preserveWorktreeWip } from "./wip-snapshot.js";
7
+ // How the worktree lifecycle keeps uncommitted work (see wip-refs.ts for the ref layout):
8
+ // - every path that could destroy it (a reset to the base, re-pointing the branch, a release that
9
+ // deletes the checkout) saves it to a WIP ref first and does not run when that fails;
10
+ // - a session that ends without succeeding saves it under the session's id;
11
+ // - a publishing lane's next pass puts the newest snapshot back, re-applying it with a 3-way merge
12
+ // when the branch has moved since (wip-restore.ts);
13
+ // - a checkout that lost only its `.git` link is reattached to Git's admin directory for it, which
14
+ // holds its index and MERGE_HEAD, instead of being recreated (orphan-relink.ts).
15
+ export { relinkOrphanedWorktree } from "./orphan-relink.js";
16
+ /** Lanes whose work the bridge publishes, and so whose snapshots a later pass may apply by itself. */
17
+ const restoreLanes = new Set(["develop", "debug", "conflict_resolve", "ci_repair"]);
18
+ function isWipRestoreLane(lane) {
19
+ return restoreLanes.has((lane ?? "").trim().toLowerCase());
20
+ }
21
+ /**
22
+ * Saves uncommitted work before `git reset --hard` / `git clean` on an existing worktree; a later
23
+ * pass may apply it by itself only when it came from a publishing lane.
24
+ * Throws when it could not be saved: losing work is worse than a failed prepare.
25
+ */
26
+ export async function guardWorktreeReset(worktreePath, branchName, owner) {
27
+ try {
28
+ return await preserveWorktreeWip({
29
+ worktreePath,
30
+ branchName,
31
+ reason: "pre_reset",
32
+ sessionId: owner.sessionId,
33
+ lane: owner.lane,
34
+ attempt: owner.wipAttempt,
35
+ autoRestore: isWipRestoreLane(owner.lane),
36
+ });
37
+ }
38
+ catch (error) {
39
+ throw new Error(`Refusing to reset ${worktreePath} to its base: its uncommitted work could not be saved to a WIP ref (${errorMessage(error)}).`, { cause: error });
40
+ }
41
+ }
42
+ /**
43
+ * Before a local branch is re-pointed at a new start point (`worktree add -B`), saves any commits
44
+ * on it that neither the start point nor origin has, as a `forge.wip.v1` snapshot like any other:
45
+ * its tree is the tip's, its first parent the tip (so the commits are `<ref>^1` and its ancestors),
46
+ * and it is never applied automatically. Throws when they could not be saved.
47
+ */
48
+ export async function guardBranchReset(git, repoPath, branchName, startPoint) {
49
+ const tip = (await git.run(repoPath, ["rev-parse", "-q", "--verify", `refs/heads/${branchName}^{commit}`]).catch(() => "")).trim();
50
+ if (!tip)
51
+ return;
52
+ const onStartPoint = await git.run(repoPath, ["merge-base", "--is-ancestor", tip, startPoint]).then(() => true, () => false);
53
+ if (onStartPoint)
54
+ return;
55
+ const onOrigin = (await git.run(repoPath, ["branch", "-r", "--contains", tip]).catch(() => "")).trim().length > 0;
56
+ if (onOrigin)
57
+ return;
58
+ const now = new Date();
59
+ const ref = wipRefName(branchName, wipRefId("pre_branch_reset", null, now));
60
+ const origin = (await git.run(repoPath, ["remote", "get-url", "origin"]).catch(() => "")).trim();
61
+ try {
62
+ const snapshot = await branchTipSnapshot(repoPath, branchName, tip, now);
63
+ await git.run(repoPath, origin ? ["push", "--porcelain", "origin", `${snapshot}:${ref}`] : ["update-ref", ref, snapshot]);
64
+ }
65
+ catch (error) {
66
+ throw new Error(`Refusing to re-point ${branchName} at ${startPoint}: its unpublished commits (${tip.slice(0, 12)}) could not be saved to ${ref} (${errorMessage(error)}).`, { cause: error });
67
+ }
68
+ }
69
+ /** A snapshot commit holding a branch tip: nothing uncommitted, so its tree and index are the tip's. */
70
+ async function branchTipSnapshot(repoPath, branchName, tip, now) {
71
+ const git = new WipGit();
72
+ const tree = (await git.run(repoPath, ["rev-parse", `${tip}^{tree}`])).trim();
73
+ const indexCommit = (await git.run(repoPath, ["commit-tree", tree, "-p", tip, "-m", "forge wip index snapshot"])).trim();
74
+ const message = formatWipCommitMessage({
75
+ schema: wipMetadataSchema,
76
+ branch: branchName,
77
+ baseHead: tip,
78
+ sessionId: null,
79
+ lane: null,
80
+ reason: "pre_branch_reset",
81
+ attempt: unorderedWipAttempt,
82
+ autoRestore: false,
83
+ createdAt: now.toISOString(),
84
+ createdAtMs: now.getTime(),
85
+ mergeHead: null,
86
+ mergeMessage: null,
87
+ mergeMode: null,
88
+ unmerged: [],
89
+ reapplyConflicts: [],
90
+ changedPaths: 0,
91
+ bytes: 0,
92
+ });
93
+ return (await git.run(repoPath, ["commit-tree", tree, "-p", tip, "-p", indexCommit, "-m", message])).trim();
94
+ }
95
+ /** Puts the newest restorable snapshot back on a freshly prepared worktree of a publishing lane. */
96
+ export async function restoreWorktreeWip(input) {
97
+ if (!input.sessionId || !isWipRestoreLane(input.lane))
98
+ return undefined;
99
+ return await restoreLatestWip(input);
100
+ }
101
+ /**
102
+ * The worktree's recorded WIP re-apply conflicts that still have conflict stages or markers (see
103
+ * wipReapplyConflictRecordName); [] when there are none. Throws when the record or the index cannot
104
+ * be read: an unknown conflict state is never treated as conflict-free.
105
+ */
106
+ export async function unresolvedWorktreeReapplyConflicts(worktreePath) {
107
+ return await unresolvedReapplyConflicts(new WipGit(), worktreePath).catch((error) => {
108
+ throw new Error(`the record of conflicts from re-applied saved work could not be read: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
109
+ });
110
+ }
111
+ /**
112
+ * Saves a worktree that is about to be deleted. Its snapshot is never applied automatically (a
113
+ * session that ended without succeeding has already saved its own work under its id; what is
114
+ * left after a successful pass was deliberately not published). Throws when it could not be saved.
115
+ */
116
+ export async function guardWorktreeRelease(handle) {
117
+ // A readiness probe never runs an agent; its checkout only ever holds the app's own output.
118
+ if (isRuntimeReadinessBranch(handle.branchName))
119
+ return { status: "clean" };
120
+ return await preserveWorktreeWip({
121
+ worktreePath: handle.worktreePath,
122
+ branchName: handle.branchName,
123
+ reason: "pre_release",
124
+ sessionId: handle.sessionId,
125
+ lane: handle.lane,
126
+ attempt: handle.wipAttempt,
127
+ autoRestore: false,
128
+ });
129
+ }
130
+ /** Forgets what this process saved for a worktree once it is gone. */
131
+ export function worktreeReleased(handle) {
132
+ forgetPreservedWip(handle.worktreePath);
133
+ }
134
+ /**
135
+ * At the end of a session: saves its uncommitted work unless it succeeded, and deletes the
136
+ * snapshot it started from once that work is safe elsewhere: saved again here, or (after a
137
+ * success) published, which is only certain when nothing is left uncommitted. Leftovers keep the
138
+ * ref; the release's own snapshot of them is never applied automatically.
139
+ * Never throws; a failure is reported in the result.
140
+ */
141
+ export async function settleSessionWip(handle, outcome) {
142
+ let snapshot;
143
+ if (outcome.reason) {
144
+ try {
145
+ snapshot = await preserveWorktreeWip({
146
+ worktreePath: handle.worktreePath,
147
+ branchName: handle.branchName,
148
+ reason: outcome.reason,
149
+ sessionId: handle.sessionId,
150
+ lane: handle.lane,
151
+ attempt: handle.wipAttempt,
152
+ autoRestore: isWipRestoreLane(handle.lane),
153
+ });
154
+ }
155
+ catch (error) {
156
+ return {
157
+ error: {
158
+ code: error instanceof WipPreservationError ? error.code : "wip_snapshot_failed",
159
+ message: errorMessage(error),
160
+ },
161
+ };
162
+ }
163
+ }
164
+ const restored = handle.wipRestore?.status === "restored" ? handle.wipRestore.ref : null;
165
+ // A failed session that left a clean worktree may have thrown the restored work away; keep its ref.
166
+ const supersededBy = snapshot && snapshot.status !== "clean" ? snapshot.ref : null;
167
+ const safeElsewhere = outcome.reason === null
168
+ ? await hasNoUnsavedWork(handle.worktreePath).catch(() => false)
169
+ : Boolean(supersededBy && supersededBy !== restored);
170
+ const retire = restored && safeElsewhere ? restored : null;
171
+ if (retire)
172
+ forgetPreservedWipRef(retire);
173
+ const retiredRef = retire && await deleteWipRef(handle.repoPath, retire) ? retire : null;
174
+ return { ...(snapshot ? { snapshot } : {}), retiredRef };
175
+ }
176
+ /**
177
+ * After a release: deletes the readiness probe's branch, and other Forge branches whose work is
178
+ * already on the base. Branches of live leases are kept; when the ledger can't be read, nothing is.
179
+ */
180
+ export async function sweepBranchesAfterRelease(git, handle, leaseStateRoot, limit) {
181
+ const protectedBranches = await readHostRuntimeLeases(leaseStateRoot)
182
+ .then(liveLeaseBranches)
183
+ .catch(() => null);
184
+ if (!protectedBranches)
185
+ return;
186
+ let budget = limit;
187
+ if (isRuntimeReadinessBranch(handle.branchName) && !protectedBranches.has(handle.branchName)
188
+ && await deleteBranchIfUnused(git, handle.repoPath, handle.branchName)) {
189
+ budget -= 1;
190
+ }
191
+ await sweepManagedBranches(git, handle.repoPath, {
192
+ baseBranch: handle.baseBranch,
193
+ includeMergedWorkBranches: true,
194
+ protectedBranches,
195
+ limit: budget,
196
+ }).catch(() => undefined);
197
+ }
198
+ function errorMessage(error) {
199
+ return error instanceof Error ? error.message : String(error);
200
+ }
@@ -1,7 +1,13 @@
1
- import type { WorktreeHandle, WorktreePrepareRequest } from "./worktree.types.js";
1
+ import type { WipSessionOutcome, WipSettlement, WorktreeHandle, WorktreePrepareRequest } from "./worktree.types.js";
2
2
  export interface WorktreeService {
3
3
  prepare(request: WorktreePrepareRequest): Promise<WorktreeHandle>;
4
+ /**
5
+ * Must not delete uncommitted work it could not save first: it keeps the worktree and throws a
6
+ * WipPreservationError instead.
7
+ */
4
8
  release(handle: WorktreeHandle): Promise<void>;
9
+ /** Saves (or retires) the session's WIP when it ends; never throws. */
10
+ settleWip?(handle: WorktreeHandle, outcome: WipSessionOutcome): Promise<WipSettlement>;
5
11
  }
6
12
  export interface WorktreeLifecycleCoordinator {
7
13
  withLock<T>(repoPath: string, action: () => Promise<T>, signal?: AbortSignal): Promise<T>;
@@ -1,20 +1,75 @@
1
1
  import { GitClient } from "../shared/git/git.js";
2
+ import type { HostLoadStepGate } from "../runtime/host-load-governor.js";
2
3
  import type { WorktreeLifecycleCoordinator, WorktreeService } from "./worktree.base.js";
3
- import type { WorktreeHandle, WorktreePrepareRequest } from "./worktree.types.js";
4
+ import type { WipSessionOutcome, WipSettlement, WorktreeHandle, WorktreePrepareRequest } from "./worktree.types.js";
5
+ import { type BridgeLog } from "./worktree-origin-sync.js";
6
+ export { deferredProjectStartEvent, emitWipRestoreEvent, sessionWipOutcome, settleWorktree } from "./worktree-wip-events.js";
7
+ export { emitWorktreePreparedEvents } from "./worktree-origin-sync.js";
8
+ export { clearRunArtifactRoots } from "./worktree-inputs.js";
4
9
  export declare class GitWorktreeService implements WorktreeService {
5
10
  private readonly git;
6
11
  private readonly coordinator;
7
- constructor(git?: GitClient, coordinator?: WorktreeLifecycleCoordinator);
12
+ /** Gates dependency install fallbacks; inert unless the governor is on. */
13
+ private readonly hostLoadGate?;
14
+ /** Holds the host runtime lease ledger; branches of live leases are never swept on release. */
15
+ private readonly leaseStateRoot;
16
+ /** The bridge log: prepare records its start point and what it did to a reused worktree. */
17
+ private readonly log;
18
+ constructor(git?: GitClient, coordinator?: WorktreeLifecycleCoordinator,
19
+ /** Gates dependency install fallbacks; inert unless the governor is on. */
20
+ hostLoadGate?: HostLoadStepGate | undefined,
21
+ /** Holds the host runtime lease ledger; branches of live leases are never swept on release. */
22
+ leaseStateRoot?: string,
23
+ /** The bridge log: prepare records its start point and what it did to a reused worktree. */
24
+ log?: BridgeLog);
8
25
  prepare(request: WorktreePrepareRequest): Promise<WorktreeHandle>;
9
- private trackedForgePaths;
26
+ /**
27
+ * Creates the lease's worktree. A review's is detached at the review head: no lease branch is
28
+ * created and no WIP is restored. Any other is on the lease branch with the story's WIP restored.
29
+ */
30
+ private createWorktree;
31
+ /**
32
+ * Readies a surviving worktree. A review reads one exact commit, so whatever state a prior attempt
33
+ * left behind is discarded. Any other must still be on the lease branch; it is refreshed for this
34
+ * pass and given the story's WIP.
35
+ */
36
+ private reuseWorktree;
37
+ /**
38
+ * Finds the review head in the repository, fetching it when the local clone has not seen it
39
+ * yet, and returns the full commit id.
40
+ */
41
+ private resolveReviewHead;
42
+ private assertDetachedAtHead;
43
+ private warmDependencies;
44
+ /** Restores the story's saved WIP (still under the repository lock, before the provider starts). */
45
+ private withRestoredWip;
46
+ /** Creates the lease's worktree; see describeNewWorktreeStart for what it reports. */
47
+ private addWorktree;
48
+ /**
49
+ * Readies a surviving worktree for this pass: lanes that start from their base are reset to it;
50
+ * the others keep their state but are brought up to origin's head when only behind it
51
+ * (worktree-origin-sync.ts). A resumed session keeps its worktree exactly as it was.
52
+ */
53
+ private refreshReusedWorktree;
54
+ settleWip(handle: WorktreeHandle, outcome: WipSessionOutcome): Promise<WipSettlement>;
10
55
  private registeredManagedWorktreePath;
11
56
  private repoCreationCoordinationPath;
12
57
  release(handle: WorktreeHandle): Promise<void>;
58
+ /**
59
+ * Removes a review worktree without saving anything from it (see settleWip). A failed removal leaves
60
+ * the folder for the next prepare of that head, which resets and cleans it, or for stale cleanup.
61
+ */
62
+ private removeReviewWorktree;
13
63
  private restoreOrphanedWorktree;
14
64
  private resolveRepoPath;
15
65
  private managedRepoPath;
16
66
  private findExistingRepoPath;
17
67
  private resolveMatchingRepo;
68
+ /**
69
+ * The start point for the lease's base: origin's freshly fetched head when origin has the
70
+ * branch, else the local branch. When the fetch fails, the local branch is used only if origin
71
+ * has never had the base or the lease branch: otherwise the worktree could run on stale code.
72
+ */
18
73
  private resolveBaseStartPoint;
19
74
  private resetWorktreeToBase;
20
75
  private gitRefExists;
@@ -25,6 +80,4 @@ type WorktreeRename = (source: string, destination: string) => Promise<void>;
25
80
  type WorktreeRenameDelay = (milliseconds: number) => Promise<void>;
26
81
  export declare function renameWorktreeForRelease(source: string, destination: string, rename?: WorktreeRename, wait?: WorktreeRenameDelay, maxAttempts?: number): Promise<void>;
27
82
  export declare function requiresMutableEnvironmentPreparation(request: Pick<WorktreePrepareRequest, "applicationRuntimeRequired">): boolean;
28
- export declare function clearRunArtifactRoots(worktreePath: string, request: WorktreePrepareRequest): Promise<void>;
29
83
  export declare function normalizeBranchName(value: string | null | undefined, fallback: string): string;
30
- export {};