@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,22 +1,182 @@
1
- import { redactSecrets } from "../shared/redaction/redaction.js";
1
+ import { redactRunnerDispatchEvent, redactRunOnceResultPacket } from "./session-redaction.js";
2
+ import { randomUUID } from "node:crypto";
2
3
  import { RoutingProviderCliService } from "./provider-cli/provider-cli.service.js";
3
- import { GitWorktreeService } from "../worktree/worktree.service.js";
4
+ import { ForgeFailureError, waitKindForEvent, waitWakeCondition } from "./session.types.js";
5
+ import { emitWipRestoreEvent, GitWorktreeService, sessionWipOutcome, settleWorktree } from "../worktree/worktree.service.js";
6
+ import { SandboxWorkspaceService } from "../sandbox/workspace.service.js";
7
+ import { HostRuntimeAdmissionExpiredError, hostRuntimeEventResources, hostRuntimeStackEnvironmentKeys, runtimeAdmissionPriority, } from "../runtime/host-runtime-lease.js";
8
+ import { configuredLaunchPortNames, hostRuntimeContractFingerprint, hostRuntimeParallelEligible, } from "../runtime/host-runtime-promotion.js";
9
+ import { readWorkspaceRuntimeFingerprint, sameWorkspaceRuntimeFingerprint, workspaceRuntimeFingerprintChanges, } from "./workspace-runtime-fingerprint.js";
10
+ const minimumReadinessProbeStartupBudgetMs = 150_000;
4
11
  export class BridgeSessionService {
5
12
  worktrees;
6
13
  providerCli;
7
- constructor(worktrees = new GitWorktreeService(), providerCli = new RoutingProviderCliService()) {
14
+ hostRuntime;
15
+ workspaceFingerprint;
16
+ constructor(worktrees = process.env.FORGE_SANDBOX_ID
17
+ ? new SandboxWorkspaceService()
18
+ : new GitWorktreeService(), providerCli = new RoutingProviderCliService(), hostRuntime, workspaceFingerprint = readWorkspaceRuntimeFingerprint) {
8
19
  this.worktrees = worktrees;
9
20
  this.providerCli = providerCli;
21
+ this.hostRuntime = hostRuntime;
22
+ this.workspaceFingerprint = workspaceFingerprint;
23
+ }
24
+ setHostRequirementsCheck(check) {
25
+ this.hostRuntime?.setRequirementsCheck?.(check);
26
+ }
27
+ runnerLimitDefaults() {
28
+ return this.hostRuntime?.capacityLimitDefaults?.() ?? null;
29
+ }
30
+ applyRunnerLimits(limits) {
31
+ this.hostRuntime?.applyCapacityLimits?.(limits);
32
+ }
33
+ async updateLease(dispatchAttemptId, fencingToken, expiresAt) {
34
+ await this.hostRuntime?.updateLease(dispatchAttemptId, fencingToken, expiresAt);
35
+ }
36
+ async reapHostRuntime(options) {
37
+ return await this.hostRuntime?.reap?.(options) ?? null;
38
+ }
39
+ runtimeCapacity() {
40
+ return this.hostRuntime?.snapshot?.() ?? null;
41
+ }
42
+ async probeHostRuntime(request, signal) {
43
+ if (!this.hostRuntime) {
44
+ return failedProbe("host_runtime_unavailable", "This bridge does not provide managed host runtime isolation.");
45
+ }
46
+ const dispatch = readinessProbeDispatch(request);
47
+ let worktree = null;
48
+ let admissionAcquired = false;
49
+ let runtimeStarted = false;
50
+ let result;
51
+ let cleanupFailure = null;
52
+ try {
53
+ throwIfAborted(signal);
54
+ await this.hostRuntime.acquire(dispatch, signal);
55
+ admissionAcquired = true;
56
+ // Readiness probes acquire background-exclusive project admission. Only
57
+ // invalidate the prior proof after that fence is held so a user lane can
58
+ // never observe the proof disappear underneath shared admission.
59
+ await this.hostRuntime.invalidatePromotion?.(request.repoId, "discovery");
60
+ assertReadinessProbeStartupBudget(request.expiresAt);
61
+ worktree = await this.worktrees.prepare({
62
+ repo: dispatch.repo,
63
+ workItem: dispatch.workItem,
64
+ baseBranch: request.revision,
65
+ worktreeKey: dispatch.lease.worktreeKey,
66
+ ownerType: "project",
67
+ ownerId: request.projectId,
68
+ lane: "runtime_readiness",
69
+ phase: "readiness_probe",
70
+ allowedRepoRoot: request.repoRoot,
71
+ // Readiness probes are disposable infrastructure checks, not agent lanes.
72
+ // Always remove their worktree even when the bridge is configured to retain
73
+ // failed agent worktrees for inspection.
74
+ cleanupWorktrees: dispatch.serverLocal.cleanupWorktrees,
75
+ artifacts: [],
76
+ hostLoadOwner: { dispatchAttemptId: dispatch.sandbox?.dispatchAttemptId ?? null, priority: "background" },
77
+ signal,
78
+ });
79
+ assertReadinessProbeStartupBudget(request.expiresAt);
80
+ let started = await this.hostRuntime.start(dispatch, worktree.worktreePath, signal);
81
+ runtimeStarted = true;
82
+ const discovery = started.runtimeContract.discovery;
83
+ if (!hostRuntimeParallelEligible(started.runtimeContract)) {
84
+ result = {
85
+ status: "serialized",
86
+ runtimeContractFingerprint: hostRuntimeContractFingerprint(started.runtimeContract),
87
+ runtimeContractSource: started.runtimeContract.source,
88
+ runtimeRequirements: started.runtimeContract.contract.requires ?? null,
89
+ reasonCode: discovery?.reasonCode ?? "host_runtime_contract_serialized",
90
+ reasonMessage: discovery?.summary ?? "The detected runtime requires serialized host execution.",
91
+ checkedAt: new Date().toISOString(),
92
+ };
93
+ }
94
+ else {
95
+ assertReadinessProbeStartupBudget(request.expiresAt);
96
+ started = await this.hostRuntime.startConfiguredProject(request.requestId, request.fencingToken, signal);
97
+ const requiredPorts = configuredLaunchPortNames(started.runtimeContract);
98
+ const verifiedPorts = started.lease.resources.ports.map(port => port.name);
99
+ const verified = requiredPorts.length > 0 && requiredPorts.every(name => verifiedPorts.includes(name));
100
+ result = verified
101
+ ? {
102
+ status: "parallel_ready",
103
+ runtimeContractFingerprint: hostRuntimeContractFingerprint(started.runtimeContract),
104
+ runtimeContractSource: started.runtimeContract.source,
105
+ runtimeRequirements: started.runtimeContract.contract.requires ?? null,
106
+ reasonCode: null,
107
+ reasonMessage: null,
108
+ qaAppLaunchTarget: managedQaLaunchTarget(started.runtimeContract),
109
+ checkedAt: new Date().toISOString(),
110
+ }
111
+ : failedProbe("host_runtime_probe_unverified", "The application did not prove ownership and readiness on every Forge-assigned port.");
112
+ }
113
+ }
114
+ catch (error) {
115
+ result = failedProbe(probeFailureCode(error), probeFailureMessage(error));
116
+ }
117
+ finally {
118
+ if (runtimeStarted || admissionAcquired) {
119
+ try {
120
+ const released = await this.hostRuntime.release(request.requestId, request.fencingToken);
121
+ if (runtimeStarted && !released)
122
+ cleanupFailure = new Error("The runtime lease was no longer current during cleanup.");
123
+ }
124
+ catch (error) {
125
+ cleanupFailure = error instanceof Error ? error : new Error(String(error));
126
+ }
127
+ }
128
+ if (worktree) {
129
+ try {
130
+ await this.worktrees.release(worktree);
131
+ }
132
+ catch (error) {
133
+ cleanupFailure ??= error instanceof Error ? error : new Error(String(error));
134
+ }
135
+ }
136
+ }
137
+ if (cleanupFailure) {
138
+ await this.hostRuntime.invalidatePromotion?.(request.repoId).catch(() => undefined);
139
+ return failedProbe("host_runtime_cleanup_degraded", `Forge could not prove exact readiness cleanup: ${cleanupFailure.message}`);
140
+ }
141
+ return result;
10
142
  }
11
143
  async runOnce(dispatch, sink, signal) {
12
144
  validateApiKeySecretGrant(dispatch);
13
145
  const redactionSecrets = exactSecrets(dispatch);
14
146
  const events = [];
147
+ let waitObservationVersion = 0;
148
+ const waitFirstObservedAt = new Map();
149
+ const waitObservation = (eventType, queuePosition) => {
150
+ const occurredAt = new Date().toISOString();
151
+ const kind = waitKindForEvent(eventType);
152
+ const firstObservedAt = waitFirstObservedAt.get(kind) ?? occurredAt;
153
+ waitFirstObservedAt.set(kind, firstObservedAt);
154
+ waitObservationVersion += 1;
155
+ const wait = {
156
+ schemaVersion: 2,
157
+ kind,
158
+ scope: "project",
159
+ resourceKeys: [`project-runtime:${dispatch.repo.id}`],
160
+ ...(queuePosition === undefined ? {} : { queuePosition }),
161
+ wakeCondition: waitWakeCondition(kind),
162
+ firstObservedAt,
163
+ observationVersion: waitObservationVersion,
164
+ contractOrigin: "bridge_v2",
165
+ };
166
+ return { occurredAt, wait };
167
+ };
15
168
  const emit = async (event) => {
16
169
  if (signal?.aborted) {
17
170
  return;
18
171
  }
19
- const redacted = redactSecrets(event, redactionSecrets);
172
+ const redacted = redactRunnerDispatchEvent({ ...event, eventId: event.eventId ?? randomUUID() }, redactionSecrets);
173
+ if (redacted.eventType !== "provider_tool_heartbeat") {
174
+ events.push(redacted);
175
+ }
176
+ await sink.emit(redacted);
177
+ };
178
+ const emitLifecycle = async (event) => {
179
+ const redacted = redactRunnerDispatchEvent({ ...event, eventId: event.eventId ?? randomUUID() }, redactionSecrets);
20
180
  events.push(redacted);
21
181
  await sink.emit(redacted);
22
182
  };
@@ -27,75 +187,338 @@ export class BridgeSessionService {
27
187
  content: "forge-bridge accepted run-once dispatch.",
28
188
  eventType: "dispatch_accepted"
29
189
  });
30
- if (dispatch.draft) {
31
- const run = await this.providerCli.runDraft({
32
- dispatch,
33
- emit,
34
- signal
35
- });
36
- throwIfAborted(signal);
37
- return redactSecrets({
38
- schemaVersion: 1,
39
- exitCode: 0,
40
- summary: run.summary,
41
- events,
42
- spec: run.spec ?? null,
43
- artifact: run.artifact ?? null,
44
- artifacts: run.artifacts?.length ? run.artifacts : run.artifact ? [run.artifact] : []
45
- }, redactionSecrets);
46
- }
47
- const worktree = await this.worktrees.prepare({
48
- repo: dispatch.repo,
49
- workItem: dispatch.workItem,
50
- baseBranch: dispatch.cycleRun.baseBranch || dispatch.cycleRun.requestedBase,
51
- worktreeKey: dispatch.lease.worktreeKey,
52
- ownerType: dispatch.cycleRun.ownerType ?? dispatch.lease.ownerType ?? null,
53
- ownerId: dispatch.cycleRun.ownerId ?? dispatch.lease.ownerId ?? null,
54
- lane: dispatch.execution.lane,
55
- phase: dispatch.cycleRun.phase,
56
- allowedRepoRoot: dispatch.serverLocal.repoRoot,
57
- cleanupWorktrees: dispatch.serverLocal.cleanupWorktrees,
58
- artifacts: dispatch.artifacts,
59
- qaRework: dispatch.qaRework,
60
- warmPathOverrides: dispatch.warmPathOverrides
61
- });
62
- const providerDispatch = withPreparedQaReworkPacket(dispatch, worktree.qaReworkPacketPath);
63
- throwIfAborted(signal);
64
- await emit({
65
- role: "runner",
66
- kind: "checkpoint",
67
- content: `Prepared worktree ${worktree.branchName}.`,
68
- eventType: "worktree_prepared"
69
- });
70
- if (worktree.dependencyWarm) {
71
- await emitDependencyWarmEvents(worktree.dependencyWarm, emit);
72
- }
190
+ let worktree = null;
191
+ let hostSingletonKeys = null;
192
+ let hostLease = null;
193
+ let succeeded = false;
73
194
  try {
195
+ if (dispatch.sandbox?.executionMode === "host" && this.hostRuntime) {
196
+ const capacity = this.hostRuntime.snapshot?.() ?? null;
197
+ const projectCapacity = capacity?.projects.find(project => project.repoId === dispatch.repo.id) ?? null;
198
+ const admissionWait = waitObservation("host_runtime_admission_waiting", capacity ? capacity.waitingAttempts + 1 : undefined);
199
+ await emitLifecycle({
200
+ role: "runner",
201
+ kind: "checkpoint",
202
+ content: capacity
203
+ ? `Waiting for host-runtime admission before preparing the worktree (queue position ${capacity.waitingAttempts + 1}; runner ${capacity.activeAttempts} active, ${capacity.reservedAttempts} reserved; project ${projectCapacity?.activeAttempts ?? 0} active, ${projectCapacity?.waitingAttempts ?? 0} already waiting). This wait can be caused by the project serialization policy, readiness proof, or resource headroom; Forge will continue automatically when admission is available.`
204
+ : "Waiting for host-runtime admission before preparing the worktree. Forge will continue automatically when admission is available.",
205
+ eventType: "host_runtime_admission_waiting",
206
+ ...admissionWait,
207
+ data: capacity ? JSON.stringify({
208
+ queue_position: capacity.waitingAttempts + 1,
209
+ runner_active_attempts: capacity.activeAttempts,
210
+ runner_reserved_attempts: capacity.reservedAttempts,
211
+ runner_waiting_attempts: capacity.waitingAttempts,
212
+ project_active_attempts: projectCapacity?.activeAttempts ?? 0,
213
+ project_reserved_attempts: projectCapacity?.reservedAttempts ?? 0,
214
+ project_waiting_attempts: projectCapacity?.waitingAttempts ?? 0,
215
+ project_safety_class: projectCapacity?.safetyClass ?? "unknown",
216
+ }) : undefined,
217
+ });
218
+ try {
219
+ hostSingletonKeys = await (this.hostRuntime.acquirePreparation?.(dispatch, signal)
220
+ ?? this.hostRuntime.acquire(dispatch, signal));
221
+ }
222
+ catch (error) {
223
+ if (error instanceof HostRuntimeAdmissionExpiredError) {
224
+ await emitLifecycle({
225
+ role: "runner",
226
+ kind: "error",
227
+ content: "Managed host admission expired while the project singleton remained busy; no worktree or runtime resources were created.",
228
+ eventType: "host_runtime_admission_expired",
229
+ }).catch(() => undefined);
230
+ }
231
+ throw error;
232
+ }
233
+ throwIfAborted(signal);
234
+ const admissionAcquired = waitObservation("host_runtime_admission_acquired");
235
+ await emitLifecycle({
236
+ role: "runner",
237
+ kind: "checkpoint",
238
+ content: this.hostRuntime.acquirePreparation
239
+ ? "Acquired worktree-preparation capacity. Prepared runtime verification must finish before agent admission."
240
+ : hostSingletonKeys.length > 0
241
+ ? `Acquired managed host singleton ${hostSingletonKeys.join(", ")}.`
242
+ : "Observed assigned-port evidence permits provisional parallel host admission; the prepared runtime contract must still match before launch.",
243
+ eventType: "host_runtime_admission_acquired",
244
+ ...admissionAcquired,
245
+ });
246
+ }
247
+ try {
248
+ worktree = await this.worktrees.prepare({
249
+ repo: dispatch.repo,
250
+ workItem: dispatch.workItem,
251
+ baseBranch: dispatch.cycleRun.baseBranch || dispatch.cycleRun.requestedBase,
252
+ worktreeKey: dispatch.lease.worktreeKey,
253
+ ownerType: dispatch.cycleRun.ownerType ?? dispatch.lease.ownerType ?? null,
254
+ ownerId: dispatch.cycleRun.ownerId ?? dispatch.lease.ownerId ?? null,
255
+ lane: dispatch.execution.lane,
256
+ phase: dispatch.cycleRun.phase,
257
+ allowedRepoRoot: dispatch.serverLocal.repoRoot,
258
+ cleanupWorktrees: dispatch.serverLocal.cleanupWorktrees,
259
+ artifacts: dispatch.artifacts,
260
+ priorPhaseArtifacts: dispatch.priorPhaseArtifacts,
261
+ storyQa: dispatch.storyQa,
262
+ referenceRunId: dispatch.sandbox?.dispatchAttemptId ?? dispatch.cycleRun.id,
263
+ referenceCycleRunId: dispatch.cycleRun.id,
264
+ effectivePlanAmendmentHash: dispatch.cycleRun.effectivePlanAmendmentHash,
265
+ qaRework: dispatch.qaRework,
266
+ warmPathOverrides: dispatch.warmPathOverrides,
267
+ applicationRuntimeRequired: dispatch.runtimeIntent.applicationRuntimeRequired,
268
+ preserveExistingState: Boolean(dispatch.session.resumedFromSessionId),
269
+ sessionId: dispatch.session.id,
270
+ hostLoadOwner: {
271
+ dispatchAttemptId: dispatch.sandbox?.dispatchAttemptId ?? null,
272
+ priority: runtimeAdmissionPriority(dispatch),
273
+ },
274
+ signal,
275
+ });
276
+ }
277
+ catch (error) {
278
+ throw new ForgeFailureError("worktree_prepare_failed", `worktree_prepare_failed: ${failureMessage(error)}`, "bridge", { cause: error });
279
+ }
280
+ let providerDispatch = withPreparedQaReworkPacket(dispatch, worktree.qaReworkPacketPath);
281
+ throwIfAborted(signal);
282
+ await emit({
283
+ role: "runner",
284
+ kind: "checkpoint",
285
+ content: dispatch.session.resumedFromSessionId
286
+ ? `Reattached to worktree ${worktree.branchName} without resetting source or clearing attempt artifacts.`
287
+ : `Prepared worktree ${worktree.branchName}.`,
288
+ eventType: dispatch.session.resumedFromSessionId ? "worktree_reattached" : "worktree_prepared"
289
+ });
290
+ await emitWipRestoreEvent(worktree, emit);
291
+ if ((worktree.hydratedPriorPhaseArtifactCount ?? 0) > 0) {
292
+ await emit({
293
+ role: "runner",
294
+ kind: "checkpoint",
295
+ content: `Hydrated ${worktree.hydratedPriorPhaseArtifactCount} persisted prior-phase artifact(s) into the prepared worktree.`,
296
+ eventType: "prior_phase_artifacts_hydrated"
297
+ });
298
+ }
299
+ if (worktree.dependencyWarm) {
300
+ await emitDependencyWarmEvents(worktree.dependencyWarm, emit);
301
+ }
302
+ if (dispatch.sandbox?.executionMode === "host" && this.hostRuntime) {
303
+ hostLease = await this.hostRuntime.start(dispatch, worktree.worktreePath, signal, async (checkpoint) => {
304
+ const observation = waitObservation(checkpoint.code);
305
+ await emitLifecycle({
306
+ role: "runner",
307
+ kind: "checkpoint",
308
+ content: checkpoint.message,
309
+ eventType: checkpoint.code,
310
+ ...observation,
311
+ data: JSON.stringify({ expires_at: checkpoint.expiresAt }),
312
+ });
313
+ });
314
+ await emitLifecycle({
315
+ role: "runner",
316
+ kind: "checkpoint",
317
+ content: `Host runtime lease ${hostLease.lease.leaseId} is active for this worktree.`,
318
+ eventType: "sandbox_started",
319
+ occurredAt: hostLease.lease.stateChangedAt,
320
+ data: JSON.stringify(hostRuntimeEventResources(hostLease.lease, hostLease.runtimeContract, hostLease.executionClass)),
321
+ });
322
+ await emitLifecycle({
323
+ role: "runner",
324
+ kind: "checkpoint",
325
+ content: "Managed host fallback isolates the worktree, attempt paths, assigned loopback ports, and supervised process trees, but not the host filesystem, network, credentials, or kernel. Serialized projects also hold a runner-local singleton. Enable Run in Docker in Project Settings when stronger isolation is required.",
326
+ eventType: "host_runtime_isolation_notice",
327
+ data: JSON.stringify({
328
+ isolationStrength: "managed_host_process",
329
+ remediation: "Enable Run in Docker in Project Settings.",
330
+ }),
331
+ });
332
+ const unconfiguredPortCount = hostLease.lease.resources.ports.length;
333
+ hostLease = await this.hostRuntime.startConfiguredProject(dispatch.sandbox.dispatchAttemptId, dispatch.lease.fencingToken, signal, async (checkpoint) => {
334
+ await emitLifecycle({
335
+ role: "runner",
336
+ kind: "checkpoint",
337
+ content: checkpoint.message,
338
+ eventType: checkpoint.code,
339
+ data: checkpoint.data ? JSON.stringify(checkpoint.data) : undefined,
340
+ });
341
+ });
342
+ if (hostLease.lease.resources.ports.length > unconfiguredPortCount) {
343
+ const assigned = hostLease.lease.resources.ports.at(-1);
344
+ await emitLifecycle({
345
+ role: "runner",
346
+ kind: "checkpoint",
347
+ content: `Verified supervised project runtime ${assigned.name} on ${assigned.hostIp}:${assigned.hostPort}.`,
348
+ eventType: "host_runtime_project_ready",
349
+ data: JSON.stringify(hostRuntimeEventResources(hostLease.lease, hostLease.runtimeContract, hostLease.executionClass)),
350
+ });
351
+ }
352
+ }
353
+ // The stack was built and launched from this workspace state. Pre-publication
354
+ // validation restarts it when the provider has changed the source since.
355
+ let refreshRuntimeEnvironment;
356
+ const hostRuntime = this.hostRuntime;
357
+ if (hostLease && dispatch.sandbox && hostRuntime?.restartConfiguredProject
358
+ && hostLease.executionClass === "managed_runtime"
359
+ && configuredLaunchPortNames(hostLease.runtimeContract).length > 0) {
360
+ const worktreePath = worktree.worktreePath;
361
+ const dispatchAttemptId = dispatch.sandbox.dispatchAttemptId;
362
+ const fencingToken = dispatch.lease.fencingToken;
363
+ const restartConfiguredProject = hostRuntime.restartConfiguredProject.bind(hostRuntime);
364
+ let launchFingerprint = await this.workspaceFingerprint(worktreePath)
365
+ .catch(() => null);
366
+ // Set while the stack may not match the workspace: a failed restart is retried on the next pass.
367
+ let restartPending = false;
368
+ refreshRuntimeEnvironment = async (refreshSignal) => {
369
+ const current = await this.workspaceFingerprint(worktreePath).catch(() => null);
370
+ if (!restartPending && sameWorkspaceRuntimeFingerprint(launchFingerprint, current))
371
+ return null;
372
+ // Every cause that applies is reported; `reason` is the first of them. Changes are named
373
+ // only when both states were read: an unreadable baseline is not a workspace change.
374
+ const comparable = launchFingerprint !== null && current !== null;
375
+ const changes = comparable ? workspaceRuntimeFingerprintChanges(launchFingerprint, current) : [];
376
+ const causes = [
377
+ ...(restartPending ? ["previous_restart_incomplete"] : []),
378
+ ...(comparable ? [] : ["fingerprint_unavailable"]),
379
+ ...(changes.length > 0 ? ["workspace_changed"] : []),
380
+ ];
381
+ const reason = causes[0] ?? "workspace_changed";
382
+ const changeText = changes.length > 0 ? ` The workspace also changed since launch (${changes.join(", ")}).` : "";
383
+ await emitLifecycle({
384
+ role: "runner",
385
+ kind: "checkpoint",
386
+ content: reason === "workspace_changed"
387
+ ? `The workspace changed since the attempt runtime stack was launched (${changes.join(", ")}); restarting it so validation runs against the current source.`
388
+ : reason === "previous_restart_incomplete"
389
+ ? `The previous attempt runtime restart did not complete; restarting it again so validation runs against the current source.${changeText}`
390
+ : `The workspace state could not be compared with the attempt runtime stack; restarting it so validation runs against the current source.`,
391
+ eventType: "host_runtime_restart_started",
392
+ data: JSON.stringify({
393
+ reason,
394
+ causes,
395
+ changes,
396
+ head_sha: current?.headSha ?? null,
397
+ merge_in_progress: Boolean(current?.mergeHead),
398
+ }),
399
+ });
400
+ restartPending = true;
401
+ let restarted;
402
+ try {
403
+ restarted = await restartConfiguredProject(dispatchAttemptId, fencingToken, refreshSignal ?? signal, async (checkpoint) => {
404
+ await emitLifecycle({
405
+ role: "runner",
406
+ kind: "checkpoint",
407
+ content: checkpoint.message,
408
+ eventType: checkpoint.code,
409
+ data: checkpoint.data ? JSON.stringify(checkpoint.data) : undefined,
410
+ });
411
+ });
412
+ }
413
+ catch (error) {
414
+ await emitLifecycle({
415
+ role: "runner",
416
+ kind: "error",
417
+ content: `Restarting the attempt runtime stack failed: ${failureMessage(error)}`,
418
+ eventType: "host_runtime_restart_failed",
419
+ data: JSON.stringify({ reason, causes, changes }),
420
+ }).catch(() => undefined);
421
+ throw error;
422
+ }
423
+ hostLease = restarted;
424
+ // The restarted stack serves the workspace as it is now. Read that state again rather than
425
+ // keep the pre-restart reading, which is null when it could not be collected; a null
426
+ // baseline never matches, so every later pass would restart and rotate ports again.
427
+ launchFingerprint = await this.workspaceFingerprint(worktreePath).catch(() => current);
428
+ restartPending = false;
429
+ await emitLifecycle({
430
+ role: "runner",
431
+ kind: "checkpoint",
432
+ content: `Restarted the supervised project runtime on ${restarted.lease.resources.ports.map(port => `${port.name} ${port.hostIp}:${port.hostPort}`).join(", ") || "no ports"}.`,
433
+ eventType: "host_runtime_restarted",
434
+ data: JSON.stringify(hostRuntimeEventResources(restarted.lease, restarted.runtimeContract, restarted.executionClass)),
435
+ });
436
+ return { environment: restarted.environment, reason, changes };
437
+ };
438
+ }
439
+ providerDispatch = withMaterializedManagedQaTarget(providerDispatch, hostLease);
440
+ const providerEnvironment = {
441
+ runtimeEnvironment: hostLease?.environment,
442
+ // Only the completion MCP server gets these: its managed commands share the host ledger.
443
+ hostLoadEnvironment: hostLease ? this.hostRuntime?.hostLoadChildEnvironment?.() : undefined,
444
+ };
445
+ if (dispatch.draft) {
446
+ throwIfAborted(signal);
447
+ const processRunner = hostLease && dispatch.sandbox
448
+ ? this.hostRuntime?.providerProcessRunner?.(dispatch.sandbox.dispatchAttemptId, dispatch.lease.fencingToken) ?? undefined
449
+ : undefined;
450
+ const run = await this.providerCli.runDraft({
451
+ dispatch: providerDispatch,
452
+ worktree,
453
+ ...providerEnvironment,
454
+ processRunner,
455
+ emit,
456
+ signal
457
+ });
458
+ throwIfAborted(signal);
459
+ const draftArtifacts = run.artifacts?.length ? run.artifacts : run.artifact ? [run.artifact] : [];
460
+ succeeded = true;
461
+ return redactRunOnceResultPacket({
462
+ schemaVersion: 2,
463
+ exitCode: 0,
464
+ summary: run.summary,
465
+ events,
466
+ spec: run.spec ?? null,
467
+ artifact: run.artifact ?? null,
468
+ artifacts: draftArtifacts
469
+ }, redactionSecrets);
470
+ }
74
471
  throwIfAborted(signal);
75
- const lane = dispatch.execution.lane.toLowerCase();
76
- const role = dispatch.execution.role.toLowerCase();
472
+ const lane = dispatch.execution.lane.trim().toLowerCase();
473
+ const role = dispatch.execution.role.trim().toLowerCase();
474
+ const cycleKind = dispatch.cycleRun.kind.trim().toLowerCase();
77
475
  const isQa = role === "qa" || lane === "qa";
78
- const isArchitect = role === "architect" || lane === "architect" || dispatch.cycleRun.kind.toLowerCase() === "architect";
476
+ const isArchitect = role === "architect" || lane === "architect" || cycleKind === "architect";
477
+ const isCiRepair = role === "ci_repair" || lane === "ci_repair" || cycleKind === "pr_checks";
79
478
  const isConflictResolve = role === "conflict_resolve" || lane === "conflict_resolve";
80
479
  const context = {
81
480
  dispatch: providerDispatch,
82
481
  worktree,
482
+ ...providerEnvironment,
483
+ processRunner: hostLease && dispatch.sandbox
484
+ ? this.hostRuntime?.providerProcessRunner?.(dispatch.sandbox.dispatchAttemptId, dispatch.lease.fencingToken) ?? undefined
485
+ : undefined,
486
+ ...(refreshRuntimeEnvironment && hostLease
487
+ ? { refreshRuntimeEnvironment, runtimeStackEnvironmentKeys: hostRuntimeStackEnvironmentKeys(hostLease.runtimeContract) }
488
+ : {}),
83
489
  emit,
84
490
  signal
85
491
  };
86
- const run = isQa
87
- ? await this.providerCli.runQa(context)
88
- : isArchitect
89
- ? await this.providerCli.runArchitect(context)
90
- : isConflictResolve
91
- ? await this.providerCli.runConflictResolve(context)
92
- : await this.providerCli.runImplementation(context);
492
+ let run;
493
+ try {
494
+ run = isQa
495
+ ? await this.providerCli.runQa(context)
496
+ : isArchitect
497
+ ? await this.providerCli.runArchitect(context)
498
+ : isCiRepair
499
+ ? await this.providerCli.runCiRepair(context)
500
+ : isConflictResolve
501
+ ? await this.providerCli.runConflictResolve(context)
502
+ : await this.providerCli.runImplementation(context);
503
+ }
504
+ catch (error) {
505
+ const message = failureMessage(error);
506
+ if (error instanceof ForgeFailureError
507
+ && (error.failureCode === "attempt_process_supervisor_start_failed"
508
+ || error.failureCode === "attempt_process_supervisor_start_timeout")) {
509
+ throw new ForgeFailureError("provider_start_unavailable", `provider_start_unavailable: ${message}`, "bridge", { cause: error });
510
+ }
511
+ throw error;
512
+ }
93
513
  throwIfAborted(signal);
94
514
  const phaseArtifacts = run.artifacts?.length ? run.artifacts : run.artifact ? [run.artifact] : [];
95
- return redactSecrets({
96
- schemaVersion: 1,
515
+ succeeded = true;
516
+ return redactRunOnceResultPacket({
517
+ schemaVersion: 2,
97
518
  exitCode: 0,
98
519
  summary: run.summary,
520
+ resultCommitSha: run.resultCommitSha ?? null,
521
+ publishedCommitSha: run.publishedCommitSha ?? null,
99
522
  events,
100
523
  spec: run.spec ?? null,
101
524
  artifact: run.artifact ?? null,
@@ -103,9 +526,217 @@ export class BridgeSessionService {
103
526
  }, redactionSecrets);
104
527
  }
105
528
  finally {
106
- await this.worktrees.release(worktree);
529
+ await this.releaseHostRuntime(dispatch, hostLease, hostSingletonKeys, emitLifecycle);
530
+ if (worktree) {
531
+ await settleWorktree(this.worktrees, worktree, sessionWipOutcome(signal, events, succeeded), signal, emitLifecycle);
532
+ }
107
533
  }
108
534
  }
535
+ /** Reports the provider's peak memory and releases the attempt's host runtime lease. */
536
+ async releaseHostRuntime(dispatch, hostLease, hostSingletonKeys, emitLifecycle) {
537
+ if (hostLease && dispatch.sandbox) {
538
+ const providerMemory = this.hostRuntime?.providerMemoryTelemetry?.(dispatch.sandbox.dispatchAttemptId, dispatch.lease.fencingToken);
539
+ if (providerMemory) {
540
+ await emitLifecycle({
541
+ role: "runner",
542
+ kind: "checkpoint",
543
+ content: `Observed managed-host provider process-tree peak memory ${formatMemoryBytes(providerMemory.peakMemoryBytes)} from ${providerMemory.sampleCount} sample${providerMemory.sampleCount === 1 ? "" : "s"}.`,
544
+ eventType: "sandbox_peak_memory_observed",
545
+ occurredAt: providerMemory.observedAt,
546
+ data: JSON.stringify({
547
+ peakMemoryBytes: providerMemory.peakMemoryBytes,
548
+ sampleCount: providerMemory.sampleCount,
549
+ source: providerMemory.source,
550
+ containers: [{
551
+ role: "agent",
552
+ peakMemoryBytes: providerMemory.peakMemoryBytes,
553
+ }],
554
+ }),
555
+ }).catch(() => undefined);
556
+ }
557
+ const teardownAt = new Date().toISOString();
558
+ await emitLifecycle({
559
+ role: "runner",
560
+ kind: "checkpoint",
561
+ content: `Releasing host runtime lease ${hostLease.lease.leaseId}.`,
562
+ eventType: "sandbox_teardown_started",
563
+ occurredAt: teardownAt,
564
+ }).catch(() => undefined);
565
+ try {
566
+ const released = await this.hostRuntime?.release(dispatch.sandbox.dispatchAttemptId, dispatch.lease.fencingToken);
567
+ if (!released) {
568
+ await emitLifecycle({
569
+ role: "runner",
570
+ kind: "error",
571
+ content: "Host runtime cleanup requires reconciliation: the runtime lease was not current during release.",
572
+ eventType: "teardown_failed",
573
+ occurredAt: new Date().toISOString(),
574
+ }).catch(() => undefined);
575
+ }
576
+ else {
577
+ await emitLifecycle({
578
+ role: "runner",
579
+ kind: "checkpoint",
580
+ content: `Released host runtime lease ${released.leaseId}. Diagnostics remain runner-local.`,
581
+ eventType: "sandbox_teardown_completed",
582
+ occurredAt: released.releasedAt,
583
+ }).catch(() => undefined);
584
+ }
585
+ }
586
+ catch (error) {
587
+ await emitLifecycle({
588
+ role: "runner",
589
+ kind: "error",
590
+ content: `Host runtime cleanup requires reconciliation: ${error instanceof Error ? error.message : String(error)}`,
591
+ eventType: "teardown_failed",
592
+ occurredAt: new Date().toISOString(),
593
+ }).catch(() => undefined);
594
+ }
595
+ }
596
+ if (!hostLease && hostSingletonKeys && dispatch.sandbox) {
597
+ await this.hostRuntime?.release(dispatch.sandbox.dispatchAttemptId, dispatch.lease.fencingToken).catch(() => undefined);
598
+ }
599
+ }
600
+ }
601
+ function failureMessage(error) {
602
+ return error instanceof Error ? error.message : String(error);
603
+ }
604
+ function formatMemoryBytes(bytes) {
605
+ return `${(bytes / (1024 ** 2)).toFixed(bytes >= 1024 ** 3 ? 0 : 1)} MiB`;
606
+ }
607
+ function readinessProbeDispatch(request) {
608
+ return {
609
+ schemaVersion: 2,
610
+ userId: request.userId,
611
+ workItem: {
612
+ id: request.projectId,
613
+ kind: "runtime_readiness",
614
+ title: "Automatic host-isolation readiness check",
615
+ description: "Internal readiness proof without a provider agent.",
616
+ acceptanceCriteria: "",
617
+ reproSteps: "",
618
+ systemInfo: "",
619
+ },
620
+ repo: {
621
+ id: request.repoId,
622
+ name: request.repoName,
623
+ remoteUrl: request.remoteUrl,
624
+ defaultBranch: request.defaultBranch,
625
+ cloneOnDemand: request.cloneOnDemand,
626
+ serverLocalPath: request.runnerRepoLocalPath,
627
+ },
628
+ cycleRun: {
629
+ id: request.requestId,
630
+ ownerType: "project",
631
+ ownerId: request.projectId,
632
+ kind: "runtime_readiness",
633
+ phase: "readiness_probe",
634
+ requestedBase: request.revision,
635
+ baseBranch: request.revision,
636
+ attempt: request.attempt,
637
+ model: "none",
638
+ },
639
+ session: { id: request.requestId, model: "none", lane: "runtime_readiness" },
640
+ lease: {
641
+ id: request.requestId,
642
+ ownerType: "project",
643
+ ownerId: request.projectId,
644
+ worktreeKey: `runtime-readiness-${request.requestId}`,
645
+ lane: "runtime_readiness",
646
+ fencingToken: request.fencingToken,
647
+ expiresAt: request.expiresAt,
648
+ },
649
+ execution: {
650
+ provider: "none",
651
+ model: "none",
652
+ authKind: "none",
653
+ location: "bridge",
654
+ runnerId: request.runnerId,
655
+ repoId: request.repoId,
656
+ role: "runtime_readiness",
657
+ lane: "runtime_readiness",
658
+ requiresApiKeySecretGrant: false,
659
+ runnerRepoLocalPath: request.runnerRepoLocalPath,
660
+ },
661
+ runtimeIntent: { executionClass: "managed_runtime", applicationRuntimeRequired: true },
662
+ serverLocal: { repoRoot: request.repoRoot, cleanupWorktrees: true },
663
+ sandbox: {
664
+ dispatchAttemptId: request.requestId,
665
+ executionLeaseId: request.requestId,
666
+ runnerInstanceId: request.runnerInstanceId,
667
+ executionMode: "host",
668
+ executionPolicy: "host_allowed",
669
+ networkPolicy: { mode: "offline", allowedHosts: [] },
670
+ requestedResources: {
671
+ sandboxSlots: 1,
672
+ cpuMillis: 2000,
673
+ workerMemoryLimitBytes: 1024 * 1024 * 1024,
674
+ serviceMemoryLimitBytes: 1024 * 1024 * 1024,
675
+ runtimeOverheadBytes: 256 * 1024 * 1024,
676
+ memoryBytes: 2 * 1024 * 1024 * 1024,
677
+ workspaceBytes: 10 * 1024 * 1024 * 1024,
678
+ pids: 512,
679
+ buildSlots: 1,
680
+ },
681
+ publicationMode: "shared_filesystem",
682
+ },
683
+ artifacts: [],
684
+ };
685
+ }
686
+ function failedProbe(reasonCode, reasonMessage) {
687
+ return { status: "failed", reasonCode, reasonMessage, checkedAt: new Date().toISOString() };
688
+ }
689
+ function assertReadinessProbeStartupBudget(expiresAt) {
690
+ const remainingMs = Date.parse(expiresAt) - Date.now();
691
+ if (!Number.isFinite(remainingMs) || remainingMs < minimumReadinessProbeStartupBudgetMs) {
692
+ throw new Error("host_runtime_probe_deadline_insufficient: readiness admission completed too close to the probe deadline; Forge released the reservation before launching the application.");
693
+ }
694
+ }
695
+ function managedQaLaunchTarget(runtimeContract) {
696
+ const playwright = runtimeContract.contract.runtime.playwright;
697
+ if (!playwright)
698
+ return null;
699
+ const port = runtimeContract.contract.runtime.ports.find(candidate => candidate.name === playwright.baseUrlPort);
700
+ return port?.launch && port.baseUrlEnv && port.format
701
+ ? { managedRuntimePort: port.name, routes: ["/"] }
702
+ : null;
703
+ }
704
+ function withMaterializedManagedQaTarget(dispatch, hostLease) {
705
+ const target = dispatch.qaBrowser?.launchTarget;
706
+ const portName = target?.managed_runtime_port?.trim().toLowerCase();
707
+ if (!target || !portName)
708
+ return dispatch;
709
+ if (!hostLease) {
710
+ throw new Error("qa_managed_runtime_unavailable: Browser QA requires the verified managed host runtime selected during readiness.");
711
+ }
712
+ const normalizedName = portName.toUpperCase().replaceAll(/[^A-Z0-9]/gu, "_");
713
+ const url = hostLease.environment[`FORGE_${normalizedName}_URL`];
714
+ if (!url) {
715
+ throw new Error(`qa_managed_runtime_unavailable: verified runtime port '${portName}' was not launched for this attempt.`);
716
+ }
717
+ return {
718
+ ...dispatch,
719
+ qaBrowser: dispatch.qaBrowser ? {
720
+ ...dispatch.qaBrowser,
721
+ launchTarget: {
722
+ ...target,
723
+ url: target.url ?? url,
724
+ ready_url: target.ready_url ?? url,
725
+ notes: [target.notes, "Forge launched and verified this URL inside the current fenced attempt."]
726
+ .filter(Boolean)
727
+ .join(" "),
728
+ },
729
+ } : dispatch.qaBrowser,
730
+ };
731
+ }
732
+ function probeFailureCode(error) {
733
+ const message = error instanceof Error ? error.message : String(error);
734
+ const candidate = message.split(":", 1)[0]?.trim().toLowerCase() ?? "";
735
+ return /^[a-z][a-z0-9_.-]{2,159}$/u.test(candidate) ? candidate : "host_runtime_probe_failed";
736
+ }
737
+ function probeFailureMessage(error) {
738
+ const message = error instanceof Error ? error.message : String(error);
739
+ return message.length > 1000 ? `${message.slice(0, 997)}...` : message;
109
740
  }
110
741
  function throwIfAborted(signal) {
111
742
  if (signal?.aborted) {
@@ -147,6 +778,23 @@ function withPreparedQaReworkPacket(dispatch, packetPath) {
147
778
  };
148
779
  }
149
780
  async function emitDependencyWarmEvents(warm, emit) {
781
+ for (const receipt of warm.receipts) {
782
+ await emit({
783
+ role: "runner",
784
+ kind: "checkpoint",
785
+ content: receipt.cacheHit
786
+ ? `Reused verified ${receipt.ecosystem} dependency preparation receipt ${receipt.fingerprint} in ${receipt.packageRoot}.`
787
+ : `Published ${receipt.ecosystem} dependency preparation receipt ${receipt.fingerprint} in ${receipt.packageRoot}.`,
788
+ eventType: receipt.cacheHit ? "dependencies_preparation_cached" : "dependencies_preparation_receipt_published",
789
+ data: JSON.stringify({
790
+ ecosystem: receipt.ecosystem,
791
+ package_root: receipt.packageRoot,
792
+ cache_hit: receipt.cacheHit,
793
+ fingerprint: receipt.fingerprint,
794
+ receipt_path: receipt.receiptPath,
795
+ }),
796
+ });
797
+ }
150
798
  if (warm.linked.length > 0) {
151
799
  await emit({
152
800
  role: "runner",