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

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,213 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { artifactExecutionBody, selectLaneCommand } from "../../worktree/artifact-injector.js";
4
+ import { prepareCompletionToolRuntime, prReviewContextFromDispatch, readCompletionArtifact, recordedPrReviewArtifactProblem, } from "../phase-completion.js";
5
+ import { resolveReviewDiffBase, withReviewDiffBase } from "../pr-review-diff-base.js";
6
+ import { ForgeFailureError } from "../session.types.js";
7
+ import { cleanupCompletionTools, emitCompletionArtifactRecorded, emitPhaseCompletionEvent } from "./provider-cli.artifacts.js";
8
+ import { buildPrReviewPrompt, buildProviderCliCommand, buildProviderCliPrompt, formatProviderCliCommandForCheckpoint, shouldPipePromptToStdin, usesManagedWindowsHost } from "./provider-cli.prompts.js";
9
+ import { providerCompletionToolMissingFailure, recoveringProviderProcessRunner } from "./provider-cli.process.js";
10
+ import { emitProviderUsageEvent, prReviewProviderProcessEnv } from "./provider-cli.runtime.js";
11
+ import { ProviderToolActivityHeartbeat, providerCliExitFailure } from "./provider-cli.service-support.js";
12
+ import { assertReviewRefsUnchanged, assertReviewRemoteHeadUnchanged, assertWorktreeUnchanged, installPrReviewCommandShims, listRemotes, preparePrReviewCredentialIsolation, readReviewRemoteHead, reviewRefPatterns, snapshotReviewRefs, snapshotWorktree, } from "./pr-review-guardrails.js";
13
+ import { createProviderOutputState } from "./provider-output-state.js";
14
+ /**
15
+ * A review session is read-only and publish-free only where the provider launch itself enforces it:
16
+ * Claude (tool deny rules, any platform) and Codex (POSIX only, because the Windows launch has no git/gh
17
+ * shim; its read-only sandbox on a host, the container in Docker: codexReviewSandboxMode). Every other provider or
18
+ * platform fails closed before anything starts.
19
+ */
20
+ export function assertPrReviewProviderSupported(provider, platform = process.platform) {
21
+ const normalized = provider.trim().toLowerCase();
22
+ const supported = normalized === "claude" || (normalized === "codex" && platform !== "win32");
23
+ if (!supported) {
24
+ throw new ForgeFailureError("pr_review_provider_unsupported", `pr_review_provider_unsupported: the '${provider}' provider on ${platform} cannot be launched read-only with publication denied, so Forge did not start the review.`, "bridge");
25
+ }
26
+ }
27
+ /** The dispatched head the review is bound to; throws unless the worktree is checked out at it. */
28
+ async function requireDispatchedHead(git, context) {
29
+ const { dispatch, worktree } = context;
30
+ const headSha = (dispatch.prReview?.headSha || dispatch.pullRequest?.headSha || "").trim().toLowerCase();
31
+ if (!headSha) {
32
+ throw new ForgeFailureError("pr_review_head_missing", "pr_review_head_missing: the pr_review dispatch did not name a head_sha.", "bridge");
33
+ }
34
+ const checkedOutHead = (await git.run(worktree.worktreePath, ["rev-parse", "HEAD"])).trim().toLowerCase();
35
+ if (checkedOutHead !== headSha) {
36
+ throw new ForgeFailureError("pr_review_head_mismatch", `pr_review_head_mismatch: the worktree is at ${checkedOutHead}, expected the dispatched head ${headSha}.`, "bridge");
37
+ }
38
+ return headSha;
39
+ }
40
+ /** Writes the Story spec from the payload, when there is one; the lane command body is prompt text only. */
41
+ async function writeReviewStorySpec(context) {
42
+ const { dispatch, worktree } = context;
43
+ const metadataRoot = path.join(worktree.worktreePath, ".forge", "work-items", dispatch.workItem.id);
44
+ await fs.mkdir(metadataRoot, { recursive: true });
45
+ const storySpec = dispatch.prReview?.storySpec ?? "";
46
+ if (storySpec.trim().length === 0) {
47
+ return null;
48
+ }
49
+ const specPath = path.join(metadataRoot, "spec.md");
50
+ await fs.writeFile(specPath, storySpec, "utf8");
51
+ await fs.writeFile(path.join(metadataRoot, "spec.meta.json"), `${JSON.stringify({ schema_version: 1, status: "approved", produced_by: "forge-story-spec" })}\n`, "utf8");
52
+ return { repoPath: worktree.worktreePath, path: specPath, body: storySpec, producedBy: "forge-story-spec", status: "approved" };
53
+ }
54
+ function buildPrReviewLaunch(context, headSha, completionTools, laneCommandBody) {
55
+ const { dispatch, worktree } = context;
56
+ const reviewPrompt = buildPrReviewPrompt(dispatch, laneCommandBody.replaceAll("{workItemId}", dispatch.workItem.id), headSha);
57
+ const providerPrompt = buildProviderCliPrompt(dispatch, reviewPrompt, context.runtimeEnvironment, { reviewOnly: true });
58
+ const pipePromptToStdin = shouldPipePromptToStdin(dispatch.execution.provider, providerPrompt, usesManagedWindowsHost(dispatch));
59
+ const command = buildProviderCliCommand(dispatch, {
60
+ worktreePath: worktree.worktreePath,
61
+ prompt: reviewPrompt,
62
+ promptFromStdin: pipePromptToStdin,
63
+ completionTools,
64
+ runtimeEnvironment: context.runtimeEnvironment,
65
+ reviewOnly: true,
66
+ });
67
+ return { command, providerPrompt, pipePromptToStdin };
68
+ }
69
+ /**
70
+ * Runs the review-only provider under the guardrails: the worktree and the review's refs are
71
+ * snapshotted before launch (and, on a host, the pull request branch on origin is read with the bridge's
72
+ * own git), the provider gets an environment with no credential Forge controls and empty git and gh
73
+ * configuration (pr-review-credential-isolation.ts), and command shims deny
74
+ * git writes and GitHub calls. Always releases the completion tools and the isolation directory.
75
+ */
76
+ async function superviseReviewProvider(services, context, launch, completionTools, outputState, snapshotOptions) {
77
+ const { dispatch, worktree } = context;
78
+ const toolHeartbeat = new ProviderToolActivityHeartbeat(outputState, context.emit, services.providerToolHeartbeatIntervalMs);
79
+ let shims = null;
80
+ let isolation = null;
81
+ let providerStarted = false;
82
+ try {
83
+ // Setup lives inside the try so a failure here still releases the completion tools.
84
+ const baseline = await snapshotWorktree(services.git, worktree.worktreePath, snapshotOptions);
85
+ const remotes = await listRemotes(services.git, worktree.worktreePath);
86
+ const patterns = reviewRefPatterns(dispatch.pullRequest?.sourceBranch, remotes);
87
+ const refs = {
88
+ patterns,
89
+ snapshot: await snapshotReviewRefs(services.git, worktree.worktreePath, patterns),
90
+ remoteHead: await readReviewRemoteHead(services.git, worktree.worktreePath, dispatch),
91
+ };
92
+ isolation = await preparePrReviewCredentialIsolation({ remotes, safeDirectories: [worktree.worktreePath, worktree.repoPath] });
93
+ shims = await installPrReviewCommandShims();
94
+ const result = await recoveringProviderProcessRunner(context.processRunner ?? services.processRunner).run({
95
+ command: launch.command.command,
96
+ args: launch.command.args,
97
+ cwd: worktree.worktreePath,
98
+ env: prReviewProviderProcessEnv(dispatch, context.runtimeEnvironment, shims?.directory, isolation.env),
99
+ resumesProviderThread: Boolean(dispatch.session.resumeProviderThreadId),
100
+ stdin: launch.pipePromptToStdin ? launch.providerPrompt : undefined
101
+ }, {
102
+ onStarted: async () => {
103
+ await context.emit({ role: "runner", kind: "checkpoint", content: "Provider CLI PR review is supervised and ready.", eventType: "provider_cli_started" });
104
+ providerStarted = true;
105
+ },
106
+ isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
107
+ onGenerationStart: toolHeartbeat.startGeneration,
108
+ onStdoutLine: async (line) => {
109
+ await toolHeartbeat.consume(line);
110
+ }
111
+ }, context.signal);
112
+ return { result, baseline, refs };
113
+ }
114
+ finally {
115
+ toolHeartbeat.stop();
116
+ try {
117
+ if (providerStarted) {
118
+ await context.emit({ role: "runner", kind: "checkpoint", content: "Provider CLI PR review turn exited.", eventType: "provider_cli_completed" });
119
+ }
120
+ }
121
+ finally {
122
+ try {
123
+ await cleanupCompletionTools(completionTools, context.emit);
124
+ }
125
+ finally {
126
+ await shims?.cleanup();
127
+ await isolation?.cleanup();
128
+ }
129
+ }
130
+ }
131
+ }
132
+ async function emitPrReviewLaunchCheckpoints(context, launch) {
133
+ await context.emit({
134
+ role: "runner",
135
+ kind: "checkpoint",
136
+ content: "Forge PR review completion tool configured; the review-only provider must call forge.complete_pr_review. Forge denies git push, commit, rebase, reset, checkout, gh and GitHub API calls, and publishes nothing.",
137
+ eventType: "completion_tools_configured",
138
+ });
139
+ await context.emit({
140
+ role: "runner",
141
+ kind: "checkpoint",
142
+ content: `Starting provider CLI PR review: ${formatProviderCliCommandForCheckpoint(launch.command)} in ${context.worktree.worktreePath}`,
143
+ eventType: "provider_cli_starting",
144
+ });
145
+ }
146
+ /** Reads the accepted review artifact and announces it; throws when the provider never completed. */
147
+ async function recordReviewArtifact(context, outputState, result, headSha) {
148
+ const { dispatch, worktree } = context;
149
+ const reviewArtifact = await readCompletionArtifact(worktree.worktreePath, dispatch.workItem.id, "pr_review");
150
+ if (!reviewArtifact) {
151
+ throw providerCompletionToolMissingFailure("Provider CLI completed but did not call forge.complete_pr_review. Forge recorded no review.", result);
152
+ }
153
+ // The session can write the result file itself, so hold the file to the completion tool's rules again.
154
+ const problem = await recordedPrReviewArtifactProblem(worktree.worktreePath, dispatch.workItem.id, reviewArtifact.verdictJson, prReviewContextFromDispatch(dispatch));
155
+ if (problem) {
156
+ throw new ForgeFailureError("pr_review_artifact_invalid", `pr_review_artifact_invalid: ${problem}. Forge recorded no review.`, "bridge");
157
+ }
158
+ await emitCompletionArtifactRecorded(context.emit, worktree.worktreePath, reviewArtifact);
159
+ await emitPhaseCompletionEvent(context.emit, reviewArtifact);
160
+ await emitProviderUsageEvent(context.emit, dispatch, outputState);
161
+ await context.emit({
162
+ role: "assistant",
163
+ kind: "message",
164
+ content: outputState.finalMessage || `${dispatch.execution.provider} CLI reviewed pull request head ${headSha.slice(0, 12)}.`,
165
+ eventType: "pr_review_complete",
166
+ });
167
+ return reviewArtifact;
168
+ }
169
+ /**
170
+ * Review-only session for a pull request head. Never routed through implementation: the worktree
171
+ * is detached at the dispatched head, the provider cannot change or publish anything, and the
172
+ * review is handed to Forge only through the completion tool. No commit, push or GitHub call
173
+ * is made here; a worktree that differs after the session fails with `guardrail_violation`.
174
+ */
175
+ export async function runPrReviewSession(services, runContext) {
176
+ assertPrReviewProviderSupported(runContext.dispatch.execution.provider);
177
+ const headSha = await requireDispatchedHead(services.git, runContext);
178
+ // The prompt, the completion tool and the recorded review all diff against the merge base, a commit the worktree has.
179
+ const diffBase = await resolveReviewDiffBase(runContext.dispatch, (args) => services.git.run(runContext.worktree.worktreePath, args));
180
+ const context = { ...runContext, dispatch: withReviewDiffBase(runContext.dispatch, diffBase) };
181
+ const { dispatch, worktree } = context;
182
+ const laneCommand = selectLaneCommand(dispatch.artifacts, dispatch.execution.lane, dispatch.cycleRun.phase);
183
+ if (!laneCommand) {
184
+ throw new Error(`PR review readiness failed: lane command for '${dispatch.execution.lane}' was not resolved.`);
185
+ }
186
+ const reviewSpec = await writeReviewStorySpec(context);
187
+ const completionTools = await prepareCompletionToolRuntime({
188
+ dispatch, worktree, phase: "pr_review", runtimeEnvironment: context.runtimeEnvironment, hostLoadEnvironment: context.hostLoadEnvironment,
189
+ });
190
+ const launch = buildPrReviewLaunch(context, headSha, completionTools, artifactExecutionBody(laneCommand));
191
+ await emitPrReviewLaunchCheckpoints(context, launch);
192
+ const snapshotOptions = { ignoredDirectories: context.runtimeEnvironment?.FORGE_TEST_OUTPUT_DIR ? [context.runtimeEnvironment.FORGE_TEST_OUTPUT_DIR] : [] };
193
+ const outputState = createProviderOutputState(dispatch.execution.provider);
194
+ const { result, baseline, refs } = await superviseReviewProvider(services, context, launch, completionTools, outputState, snapshotOptions);
195
+ // A ref the session moved is a guardrail violation whether or not the provider exited cleanly.
196
+ await assertReviewRefsUnchanged(services.git, worktree.worktreePath, refs.patterns, refs.snapshot);
197
+ // A push leaves the local refs alone; the pull request branch on origin, read with the bridge's own git, does not.
198
+ await assertReviewRemoteHeadUnchanged(services.git, worktree.worktreePath, refs.remoteHead);
199
+ if (result.exitCode !== 0) {
200
+ throw providerCliExitFailure(launch.command.command, result);
201
+ }
202
+ // The worktree must be exactly as the review found it, whatever the review concluded.
203
+ await assertWorktreeUnchanged(services.git, worktree.worktreePath, baseline, snapshotOptions);
204
+ const reviewArtifact = await recordReviewArtifact(context, outputState, result, headSha);
205
+ return {
206
+ summary: `${dispatch.execution.provider} CLI reviewed pull request head ${headSha.slice(0, 12)} (${(reviewArtifact.status ?? "unknown").trim() || "unknown"}).`,
207
+ resultCommitSha: null,
208
+ publishedCommitSha: null,
209
+ spec: reviewSpec,
210
+ artifact: reviewArtifact,
211
+ artifacts: [reviewArtifact],
212
+ };
213
+ }
@@ -1,7 +1,10 @@
1
- import { type LaunchCommand } from "../../shared/process/windows-launch.js";
1
+ import type { LaunchCommand } from "../../shared/process/windows-launch.js";
2
2
  import { ForgeFailureError } from "../session.types.js";
3
+ export { chooseWindowsCommandCandidate, resolveWindowsCommandFromPath } from "../../shared/process/windows-launch.js";
4
+ export { buildProviderChildEnvironment, type ProviderChildEnvironmentOptions } from "./provider-cli.child-environment.js";
3
5
  export declare const PROVIDER_OUTPUT_CAPTURE_LIMIT_CHARS: number;
4
6
  export type ProviderCliCommand = LaunchCommand;
7
+ export { resolveClaudeNpmDirectLaunch, resolveCodexNpmDirectLaunch, resolvePackageManagerDirectLaunch } from "./provider-cli.windows-launch.js";
5
8
  export interface ProviderProcessRunRequest {
6
9
  readonly command: string;
7
10
  readonly args: readonly string[];
@@ -22,8 +25,8 @@ export interface ProviderProcessRunRequest {
22
25
  */
23
26
  readonly resumesProviderThread?: boolean;
24
27
  }
25
- /** Why Forge stopped a provider that was still resident after a successful turn. */
26
- export type ProviderTerminalStopReason = "turn_exit_grace" | "success_ceiling";
28
+ /** Why Forge stopped a provider still resident after its turn (or its background work, for Claude). */
29
+ export type ProviderTerminalStopReason = "turn_exit_grace" | "success_ceiling" | "turn_ended_with_background_work";
27
30
  export interface ProviderProcessRunResult {
28
31
  readonly exitCode: number;
29
32
  readonly stdout: string;
@@ -34,8 +37,10 @@ export interface ProviderProcessRunResult {
34
37
  readonly memoryObservedAt?: string;
35
38
  /** Present when the caller's cancellation stopped the process before it exited on its own. */
36
39
  readonly cancelled?: true;
37
- /** Present when Forge stopped a provider that stayed resident after a successful turn. */
40
+ /** Present when Forge stopped a provider that stayed resident after its turn ended. */
38
41
  readonly terminalStopReason?: ProviderTerminalStopReason;
42
+ /** Present when Forge closed output pipes a descendant still held after the provider exited. */
43
+ readonly outputPipesReleasedAfterExit?: true;
39
44
  }
40
45
  export interface ProviderProcessRunner {
41
46
  run(request: ProviderProcessRunRequest, handlers?: ProviderProcessHandlers, signal?: AbortSignal): Promise<ProviderProcessRunResult>;
@@ -59,7 +64,8 @@ export interface ProviderProcessHandlers {
59
64
  onGenerationStart?(): void;
60
65
  }
61
66
  /** Recovery must wrap the attempt coordinator, never its raw OS runner. Each
62
- * relaunch needs a new fenced child generation and exclusive launch files. */
67
+ * relaunch needs a new fenced child generation and exclusive launch files. The outer
68
+ * layer fails any run Forge stopped because its turn ended with background work live. */
63
69
  export declare function recoveringProviderProcessRunner(inner: ProviderProcessRunner): ProviderProcessRunner;
64
70
  /**
65
71
  * Codex Desktop and an independently installed Codex CLI can briefly disagree
@@ -88,48 +94,21 @@ export declare class CodexResumeRecoveringProcessRunner implements ProviderProce
88
94
  * arbitrary tool/command output and therefore cannot mint retry authority.
89
95
  */
90
96
  export declare function isTransientCodexProviderNotFoundFailure(command: string, result: ProviderProcessRunResult): boolean;
91
- interface ProviderChildEnvironmentOptions {
92
- readonly parentEnv?: NodeJS.ProcessEnv;
93
- readonly platform?: NodeJS.Platform;
94
- readonly homeDir?: string;
95
- }
96
- export declare function buildProviderChildEnvironment(requestEnv?: Readonly<Record<string, string>>, options?: ProviderChildEnvironmentOptions): NodeJS.ProcessEnv;
97
97
  export declare class StreamingProviderProcessRunner implements ProviderProcessRunner {
98
98
  private readonly terminalExitGraceMs;
99
99
  private readonly terminalSuccessCeilingMs;
100
100
  private readonly terminalWorkPollMs;
101
- constructor(terminalExitGraceMs?: number, terminalSuccessCeilingMs?: number, terminalWorkPollMs?: number);
101
+ private readonly outputPipeReleaseGraceMs;
102
+ constructor(terminalExitGraceMs?: number, terminalSuccessCeilingMs?: number, terminalWorkPollMs?: number, outputPipeReleaseGraceMs?: number);
102
103
  run(request: ProviderProcessRunRequest, handlers?: ProviderProcessHandlers, signal?: AbortSignal): Promise<ProviderProcessRunResult>;
103
104
  }
104
105
  /**
105
106
  * The typed failure for a provider run that ended without calling its required Forge
106
- * completion tool. A run Forge stopped at the success ceiling is reported as such, so it
107
- * is not mistaken for an agent that simply ended its turn.
107
+ * completion tool. A run Forge stopped at the success ceiling or for background work is
108
+ * reported as such, so it is not mistaken for an agent that simply ended its turn.
108
109
  */
109
110
  export declare function providerCompletionToolMissingFailure(message: string, result?: Pick<ProviderProcessRunResult, "terminalStopReason"> | null): ForgeFailureError;
110
111
  /** Returns aggregate resident bytes for the exact supervised Unix process group. */
111
112
  export declare function processGroupResidentMemoryBytes(processGroupId: number, platform?: NodeJS.Platform, procRoot?: string): number | null;
112
113
  export declare const UNIX_PROVIDER_START_GRANT_LINE = "forge-provider-start-granted\n";
113
114
  export declare function buildUnixProviderStartGateLaunch(command: string, args: readonly string[]): LaunchCommand;
114
- export declare function resolveCodexNpmDirectLaunch(commandPath: string, args: readonly string[]): LaunchCommand | null;
115
- /**
116
- * npm installs of Claude Code (`npm i -g @anthropic-ai/claude-code`) put a `claude.cmd` shim on
117
- * PATH; launch its cli.js directly for the same Job Object reasons as Codex. The native installer
118
- * ships `claude.exe`, which is preferred by PATH resolution and needs no rewrite.
119
- */
120
- export declare function resolveClaudeNpmDirectLaunch(commandPath: string, args: readonly string[]): LaunchCommand | null;
121
- /**
122
- * Avoids cmd.exe's nested-quote handling for package-manager shims. That
123
- * quoting loses executable paths containing spaces after the command is
124
- * wrapped by the Windows Job Object supervisor.
125
- */
126
- export declare function resolvePackageManagerDirectLaunch(commandPath: string, args: readonly string[]): LaunchCommand | null;
127
- /**
128
- * Resolves Windows commands without spawning where.exe. Runtime launches can
129
- * happen while the machine is under enough process pressure for where.exe to
130
- * miss its timeout; returning the unresolved package-manager name in that case
131
- * makes Node fall back to a shell shim that cannot survive Job Object wrapping.
132
- */
133
- export declare function resolveWindowsCommandFromPath(command: string, pathValue?: string, pathExtValue?: string): string | null;
134
- export declare function chooseWindowsCommandCandidate(candidates: readonly string[]): string | null;
135
- export {};