@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,67 @@
1
+ import { ForgeFailureError } from "../session.types.js";
2
+ import type { ProviderProcessHandlers, ProviderProcessRunner, ProviderProcessRunRequest, ProviderProcessRunResult } from "./provider-cli.process.js";
3
+ /**
4
+ * Removes the `run_in_background` parameter from Bash, PowerShell and the Agent tool, runs
5
+ * forked subagents and forked skills in the foreground, and stops Claude Code from moving long
6
+ * shell commands, subagents and MCP calls to the background on its own. Cron disables the
7
+ * session-scoped scheduled tasks (`CronCreate`, `/loop`). Applied last, so a project's runtime
8
+ * environment cannot turn them back on.
9
+ */
10
+ export declare const claudeHeadlessEnvironment: Readonly<Record<string, string>>;
11
+ /**
12
+ * Tools whose only purpose is work that reports after the turn. `CLAUDE_CODE_DISABLE_BACKGROUND_TASKS`
13
+ * leaves Monitor running in the background, so it is removed here, together with self-paced
14
+ * wakeups, workflows (which run their agents in the background), cloud routines, cron
15
+ * (also disabled by environment), SendMessage, which resumes an earlier subagent in the
16
+ * background, and agent teams, whose teammates run alongside the turn. Foreground subagents
17
+ * stay available: they block the turn until they finish.
18
+ */
19
+ export declare const claudeHeadlessDisallowedTools: readonly string[];
20
+ /**
21
+ * The Claude Code arguments that apply the restrictions: the tool deny list, and the environment
22
+ * again as flag settings, which outrank a user's or repository's settings `env` block. Other flag
23
+ * settings (`provider-user-config-isolation.ts`) share the one `--settings` value.
24
+ */
25
+ export declare function claudeHeadlessToolArgs(additionalSettings?: Readonly<Record<string, unknown>>): readonly string[];
26
+ /**
27
+ * The provider ended its turn while background work it started (a background subagent or
28
+ * shell, a Monitor watch, a wakeup) was still live. Claude Code withholds the turn's terminal
29
+ * result for such work, and nothing started in the background reports to Forge, so Forge stops
30
+ * the provider at once instead of waiting for an idle watchdog. Retryable: the harness, not the
31
+ * task, ended the run.
32
+ */
33
+ export declare function providerTurnEndedWithBackgroundWorkFailure(message: string): ForgeFailureError;
34
+ /**
35
+ * Fails every provider run Forge stopped because its turn ended with background work still live,
36
+ * whether or not the turn recorded a completion first: the stop cut that work short, so nothing
37
+ * may validate, commit or publish the worktree it left behind.
38
+ */
39
+ export declare class BackgroundWorkStopFailingRunner implements ProviderProcessRunner {
40
+ private readonly inner;
41
+ constructor(inner: ProviderProcessRunner);
42
+ run(request: ProviderProcessRunRequest, handlers?: ProviderProcessHandlers, signal?: AbortSignal): Promise<ProviderProcessRunResult>;
43
+ }
44
+ /**
45
+ * Recognizes a main-conversation turn that ended while background tasks it started were still
46
+ * live, the case in which Claude Code withholds the turn's `result`. The turn end is Claude
47
+ * Code's `post_turn_summary` event; the live set is the documented `background_tasks_changed`
48
+ * event (Claude Code's own `ambient` tasks and `awaited` ones do not count). After `graceMs`
49
+ * without the result or new main-conversation activity, it calls `onTurnEndedWithBackgroundWork`
50
+ * once, so the runner can stop the provider instead of waiting on work no one will collect.
51
+ */
52
+ export declare class ClaudeBackgroundTurnEndWatch {
53
+ private readonly graceMs;
54
+ private readonly onTurnEndedWithBackgroundWork;
55
+ private liveBackgroundTasks;
56
+ private terminalSinceMainActivity;
57
+ private mainTurnEnded;
58
+ private timer;
59
+ private stopped;
60
+ private readonly enabled;
61
+ /** Watches only Claude Code, by its executable `command`; other output is left alone. */
62
+ constructor(command: string, graceMs: number, onTurnEndedWithBackgroundWork: () => void);
63
+ consume(line: string): void;
64
+ stop(): void;
65
+ private armIfTurnEndedWithBackgroundWork;
66
+ private cancel;
67
+ }
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Headless Claude Code runs must not start work that outlives the turn.
3
+ *
4
+ * Forge runs `claude -p` and treats the turn's terminal `result` event as the end of the run.
5
+ * When background work is still live at the end of a turn (a background subagent or shell, a
6
+ * Monitor watch, a scheduled wakeup), Claude Code withholds that `result` and keeps the process
7
+ * open for the work, so Forge sees a silent provider instead of a finished one. The launch
8
+ * restrictions below remove the ways to start such work; `ClaudeBackgroundTurnEndWatch` is the
9
+ * backstop for anything that still gets through.
10
+ */
11
+ import path from "node:path";
12
+ import { ForgeFailureError } from "../session.types.js";
13
+ /**
14
+ * Removes the `run_in_background` parameter from Bash, PowerShell and the Agent tool, runs
15
+ * forked subagents and forked skills in the foreground, and stops Claude Code from moving long
16
+ * shell commands, subagents and MCP calls to the background on its own. Cron disables the
17
+ * session-scoped scheduled tasks (`CronCreate`, `/loop`). Applied last, so a project's runtime
18
+ * environment cannot turn them back on.
19
+ */
20
+ export const claudeHeadlessEnvironment = Object.freeze({
21
+ CLAUDE_CODE_DISABLE_BACKGROUND_TASKS: "1",
22
+ CLAUDE_CODE_DISABLE_CRON: "1",
23
+ });
24
+ /**
25
+ * Tools whose only purpose is work that reports after the turn. `CLAUDE_CODE_DISABLE_BACKGROUND_TASKS`
26
+ * leaves Monitor running in the background, so it is removed here, together with self-paced
27
+ * wakeups, workflows (which run their agents in the background), cloud routines, cron
28
+ * (also disabled by environment), SendMessage, which resumes an earlier subagent in the
29
+ * background, and agent teams, whose teammates run alongside the turn. Foreground subagents
30
+ * stay available: they block the turn until they finish.
31
+ */
32
+ export const claudeHeadlessDisallowedTools = Object.freeze([
33
+ "Monitor",
34
+ "ScheduleWakeup",
35
+ "Workflow",
36
+ "RemoteTrigger",
37
+ "CronCreate",
38
+ "SendMessage",
39
+ "TeamCreate",
40
+ ]);
41
+ /**
42
+ * The Claude Code arguments that apply the restrictions: the tool deny list, and the environment
43
+ * again as flag settings, which outrank a user's or repository's settings `env` block. Other flag
44
+ * settings (`provider-user-config-isolation.ts`) share the one `--settings` value.
45
+ */
46
+ export function claudeHeadlessToolArgs(additionalSettings = {}) {
47
+ return [
48
+ "--disallowedTools", claudeHeadlessDisallowedTools.join(","),
49
+ "--settings", JSON.stringify({ ...additionalSettings, env: claudeHeadlessEnvironment }),
50
+ ];
51
+ }
52
+ /**
53
+ * The provider ended its turn while background work it started (a background subagent or
54
+ * shell, a Monitor watch, a wakeup) was still live. Claude Code withholds the turn's terminal
55
+ * result for such work, and nothing started in the background reports to Forge, so Forge stops
56
+ * the provider at once instead of waiting for an idle watchdog. Retryable: the harness, not the
57
+ * task, ended the run.
58
+ */
59
+ export function providerTurnEndedWithBackgroundWorkFailure(message) {
60
+ return new ForgeFailureError("provider_turn_ended_with_background_work", `${message} The provider ended its turn while background work it started was still running, so it never delivered a terminal result; Forge stopped it instead of waiting.`);
61
+ }
62
+ /**
63
+ * Fails every provider run Forge stopped because its turn ended with background work still live,
64
+ * whether or not the turn recorded a completion first: the stop cut that work short, so nothing
65
+ * may validate, commit or publish the worktree it left behind.
66
+ */
67
+ export class BackgroundWorkStopFailingRunner {
68
+ inner;
69
+ constructor(inner) {
70
+ this.inner = inner;
71
+ }
72
+ async run(request, handlers, signal) {
73
+ const result = await this.inner.run(request, handlers, signal);
74
+ if (result.terminalStopReason === "turn_ended_with_background_work") {
75
+ throw providerTurnEndedWithBackgroundWorkFailure("The provider turn did not finish.");
76
+ }
77
+ return result;
78
+ }
79
+ }
80
+ /**
81
+ * Recognizes a main-conversation turn that ended while background tasks it started were still
82
+ * live, the case in which Claude Code withholds the turn's `result`. The turn end is Claude
83
+ * Code's `post_turn_summary` event; the live set is the documented `background_tasks_changed`
84
+ * event (Claude Code's own `ambient` tasks and `awaited` ones do not count). After `graceMs`
85
+ * without the result or new main-conversation activity, it calls `onTurnEndedWithBackgroundWork`
86
+ * once, so the runner can stop the provider instead of waiting on work no one will collect.
87
+ */
88
+ export class ClaudeBackgroundTurnEndWatch {
89
+ graceMs;
90
+ onTurnEndedWithBackgroundWork;
91
+ liveBackgroundTasks = 0;
92
+ terminalSinceMainActivity = false;
93
+ mainTurnEnded = false;
94
+ timer = null;
95
+ stopped = false;
96
+ enabled;
97
+ /** Watches only Claude Code, by its executable `command`; other output is left alone. */
98
+ constructor(command, graceMs, onTurnEndedWithBackgroundWork) {
99
+ this.graceMs = graceMs;
100
+ this.onTurnEndedWithBackgroundWork = onTurnEndedWithBackgroundWork;
101
+ this.enabled = path.parse(command).name.toLowerCase() === "claude";
102
+ }
103
+ consume(line) {
104
+ if (!this.enabled || this.stopped)
105
+ return;
106
+ const event = parseStreamEvent(line);
107
+ if (!event)
108
+ return;
109
+ if (isTerminalEvent(event)) {
110
+ this.terminalSinceMainActivity = true;
111
+ this.cancel();
112
+ }
113
+ else if (event.type === "system" && event.subtype === "background_tasks_changed") {
114
+ this.liveBackgroundTasks = liveBackgroundTaskCount(event.tasks);
115
+ // The work settled: Claude Code now delivers the result or starts a turn for it, and a
116
+ // follow-up turn can think for a while before its first event.
117
+ if (this.liveBackgroundTasks === 0)
118
+ this.cancel();
119
+ // A task can be reported just after the turn summary, as the turn ends.
120
+ else if (this.mainTurnEnded)
121
+ this.armIfTurnEndedWithBackgroundWork();
122
+ }
123
+ else if (event.type === "system" && event.subtype === "post_turn_summary") {
124
+ this.mainTurnEnded = true;
125
+ this.armIfTurnEndedWithBackgroundWork();
126
+ }
127
+ else if ((event.type === "assistant" || event.type === "user") && !event.parent_tool_use_id) {
128
+ // The main conversation is working again (a new turn, or a turn that is still going).
129
+ this.terminalSinceMainActivity = false;
130
+ this.mainTurnEnded = false;
131
+ this.cancel();
132
+ }
133
+ }
134
+ stop() {
135
+ this.stopped = true;
136
+ this.cancel();
137
+ }
138
+ armIfTurnEndedWithBackgroundWork() {
139
+ if (this.timer || this.terminalSinceMainActivity || this.liveBackgroundTasks === 0)
140
+ return;
141
+ this.timer = setTimeout(() => {
142
+ this.timer = null;
143
+ this.stopped = true;
144
+ this.onTurnEndedWithBackgroundWork();
145
+ }, this.graceMs);
146
+ this.timer.unref?.();
147
+ }
148
+ cancel() {
149
+ if (!this.timer)
150
+ return;
151
+ clearTimeout(this.timer);
152
+ this.timer = null;
153
+ }
154
+ }
155
+ function parseStreamEvent(line) {
156
+ const trimmed = line.trim();
157
+ if (!trimmed.startsWith("{"))
158
+ return null;
159
+ try {
160
+ const parsed = JSON.parse(trimmed);
161
+ return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
162
+ }
163
+ catch {
164
+ return null;
165
+ }
166
+ }
167
+ function isTerminalEvent(event) {
168
+ return event.type === "result" || event.type === "error";
169
+ }
170
+ /**
171
+ * Tasks that keep the turn's result back: not Claude Code's own `ambient` tasks, and not
172
+ * `awaited` ones, which a still-running tool call of the turn waits for.
173
+ */
174
+ function liveBackgroundTaskCount(tasks) {
175
+ if (!Array.isArray(tasks))
176
+ return 0;
177
+ return tasks.filter(task => {
178
+ const entry = task && typeof task === "object" ? task : {};
179
+ return entry.ambient !== true && entry.awaited !== true;
180
+ }).length;
181
+ }
@@ -0,0 +1,7 @@
1
+ import type { RunOnceDispatchPacket } from "../session.types.js";
2
+ /**
3
+ * The branch an attempt publishes into: the pull request's target, else the requested base, else the
4
+ * repository's default branch. The lane prompts name it as the branch to merge or compare with, and the
5
+ * pre-publication gate verifies a merge parent against it, so both read it from here.
6
+ */
7
+ export declare function dispatchTargetBranch(dispatch: RunOnceDispatchPacket): string;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The branch an attempt publishes into: the pull request's target, else the requested base, else the
3
+ * repository's default branch. The lane prompts name it as the branch to merge or compare with, and the
4
+ * pre-publication gate verifies a merge parent against it, so both read it from here.
5
+ */
6
+ export function dispatchTargetBranch(dispatch) {
7
+ return dispatch.pullRequest?.targetBranch || dispatch.cycleRun.requestedBase || dispatch.repo.defaultBranch || "main";
8
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * A runner host can allow only one local .NET build or test at a time across everything that runs
3
+ * on it: Forge agents, the owner's own sessions and their tools. Parallel builds there exhaust
4
+ * memory and break each other's shared test output. The host's owner names the lock wrapper in the
5
+ * bridge's own environment; Forge passes it to every host-mode agent turn and Bridge Chat turn and
6
+ * tells the agent to run its .NET builds and tests through it. The rule reaches agents only from Forge, never from a
7
+ * user-level instruction file (provider-user-config-isolation.ts).
8
+ */
9
+ export declare const hostDotnetBuildLockVariable = "FORGE_HOST_DOTNET_BUILD_LOCK";
10
+ /** The host's .NET build lock wrapper, when the bridge's environment names one. */
11
+ export declare function hostDotnetBuildLock(environment?: NodeJS.ProcessEnv): string | null;
12
+ export declare function hostDotnetBuildLockEnvironment(environment?: NodeJS.ProcessEnv): Readonly<Record<string, string>>;
13
+ /**
14
+ * The runtime-context instruction for a host that names a .NET build lock, or an empty string.
15
+ * Session turns also hear that the commands Forge runs for them are scheduled by Forge; Bridge
16
+ * Chat turns have no Forge tools.
17
+ */
18
+ export declare function hostDotnetBuildLockInstruction(environment?: NodeJS.ProcessEnv, turn?: "session" | "chat"): string;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * A runner host can allow only one local .NET build or test at a time across everything that runs
3
+ * on it: Forge agents, the owner's own sessions and their tools. Parallel builds there exhaust
4
+ * memory and break each other's shared test output. The host's owner names the lock wrapper in the
5
+ * bridge's own environment; Forge passes it to every host-mode agent turn and Bridge Chat turn and
6
+ * tells the agent to run its .NET builds and tests through it. The rule reaches agents only from Forge, never from a
7
+ * user-level instruction file (provider-user-config-isolation.ts).
8
+ */
9
+ export const hostDotnetBuildLockVariable = "FORGE_HOST_DOTNET_BUILD_LOCK";
10
+ /** The host's .NET build lock wrapper, when the bridge's environment names one. */
11
+ export function hostDotnetBuildLock(environment = process.env) {
12
+ return environment[hostDotnetBuildLockVariable]?.trim() || null;
13
+ }
14
+ export function hostDotnetBuildLockEnvironment(environment = process.env) {
15
+ const lock = hostDotnetBuildLock(environment);
16
+ return lock ? { [hostDotnetBuildLockVariable]: lock } : {};
17
+ }
18
+ /**
19
+ * The runtime-context instruction for a host that names a .NET build lock, or an empty string.
20
+ * Session turns also hear that the commands Forge runs for them are scheduled by Forge; Bridge
21
+ * Chat turns have no Forge tools.
22
+ */
23
+ export function hostDotnetBuildLockInstruction(environment = process.env, turn = "session") {
24
+ if (!hostDotnetBuildLock(environment))
25
+ return "";
26
+ const forgeScheduled = turn === "session"
27
+ ? " Commands Forge runs for you (`forge.start_managed_verification`, pre-publication checks) are scheduled by Forge."
28
+ : "";
29
+ return `\n- This host runs one local .NET build or test at a time. Run every \`dotnet build\` and \`dotnet test\` you start yourself through the host lock in \`${hostDotnetBuildLockVariable}\`, for example \`"$${hostDotnetBuildLockVariable}" dotnet test <project> --filter <tests>\`. It waits while another build or test holds the lock and exits 75 if the wait times out; wait and retry rather than running without it.${forgeScheduled}`;
30
+ }
@@ -0,0 +1,83 @@
1
+ import type { GitClient } from "../../shared/git/git.js";
2
+ /** The failure code of every review session that changed or published something it must not. */
3
+ export declare const prReviewGuardrailViolationCode = "guardrail_violation";
4
+ /**
5
+ * The primary publication control for a review-only session, for every provider: the session's
6
+ * environment holds no way to authenticate to a git host and no way to push. Tool deny rules and
7
+ * command shims are a second layer on top of this one.
8
+ *
9
+ * - git reads an empty global configuration (GIT_CONFIG_GLOBAL) and no system configuration
10
+ * (GIT_CONFIG_NOSYSTEM), so no user- or machine-wide credential helper, `url.insteadOf` or token
11
+ * header applies.
12
+ * - Command-scope configuration (GIT_CONFIG_COUNT) clears `credential.helper` (an empty value resets
13
+ * the helper list, including one from the repository's own config), disables every transport
14
+ * (`protocol.allow=never`) and points each remote's push URL at a transport that does not exist.
15
+ * - The GitHub CLI reads an empty configuration directory (GH_CONFIG_DIR), so it has no stored login.
16
+ * - GitHub tokens, Git Credential Manager settings, askpass programs and SSH agent sockets are removed.
17
+ *
18
+ * HOME is not changed: the provider signs in from its own configuration under it. What the environment
19
+ * cannot take away is anything the bridge user can read: the operating system's credential store
20
+ * (Windows Credential Manager, the macOS keychain), which a session can still reach by naming a helper
21
+ * explicitly (`git -c credential.helper=...`), and credential files under HOME. The tool deny rules
22
+ * refuse the commands they recognise (Claude). After the session, Forge compares the review's local refs
23
+ * and, on a host placement, the pull request branch's head on origin (read with the bridge's own git,
24
+ * outside the session's environment) with their values before it, and fails a session that moved them.
25
+ * A push to another branch or repository, or a credential the session read and sent elsewhere, is not
26
+ * detected. That is why a review runs only in the Docker sandbox unless the runner's owner opted in
27
+ * (session/pr-review-placement.ts): none of this is a boundary on a plain host.
28
+ */
29
+ export interface PrReviewCredentialIsolation {
30
+ readonly directory: string;
31
+ readonly env: Readonly<Record<string, string>>;
32
+ cleanup(): Promise<void>;
33
+ }
34
+ /** A push URL no git transport handles, so a push fails before any network or credential lookup. */
35
+ export declare const prReviewDisabledPushUrl = "forge-review-push-disabled://publication-is-not-allowed";
36
+ export interface PrReviewCredentialIsolationOptions {
37
+ /** Directories git must trust although the global configuration that may have listed them is empty. */
38
+ readonly safeDirectories?: readonly string[];
39
+ /** Remote names whose push URL is disabled. */
40
+ readonly remotes?: readonly string[];
41
+ readonly tempRoot?: string;
42
+ }
43
+ /** The git and gh environment for a review session whose isolation directory is `directory`. */
44
+ export declare function prReviewIsolatedGitEnvironment(directory: string, options?: Pick<PrReviewCredentialIsolationOptions, "safeDirectories" | "remotes">): Readonly<Record<string, string>>;
45
+ /** Creates the empty global git configuration and gh configuration directory for one session. */
46
+ export declare function preparePrReviewCredentialIsolation(options?: PrReviewCredentialIsolationOptions): Promise<PrReviewCredentialIsolation>;
47
+ /** The repository's remote names, read before the session starts. */
48
+ export declare function listRemotes(git: GitClient, worktreePath: string): Promise<readonly string[]>;
49
+ export interface ReviewRefSnapshot {
50
+ readonly refs: ReadonlyMap<string, string>;
51
+ }
52
+ /**
53
+ * The refs a review session could move: the pull request's source branch (local and every
54
+ * remote-tracking copy) and the namespaces only history-rewriting or bookkeeping commands write
55
+ * (notes, replace, stash, bisect, per-worktree refs, filter-branch backups). Other branches and tags
56
+ * are left out on purpose: the repository is shared with Forge's other sessions, whose fetches move
57
+ * them while this review runs.
58
+ */
59
+ export declare function reviewRefPatterns(sourceBranch: string | undefined, remotes: readonly string[]): readonly string[];
60
+ export declare function snapshotReviewRefs(git: GitClient, worktreePath: string, patterns: readonly string[]): Promise<ReviewRefSnapshot>;
61
+ /** Throws `guardrail_violation` when a ref in the review's scope was created, moved or deleted. */
62
+ export declare function assertReviewRefsUnchanged(git: GitClient, worktreePath: string, patterns: readonly string[], baseline: ReviewRefSnapshot): Promise<void>;
63
+ /** The pull request branch's head on origin before the session; null when the review runs in Docker. */
64
+ export interface ReviewRemoteHead {
65
+ readonly branch: string;
66
+ readonly sha: string;
67
+ }
68
+ /**
69
+ * Reads the pull request branch's head on origin with the bridge's own git environment, never the
70
+ * session's. In the Docker sandbox there is nothing to read: the container's workspace has no remote
71
+ * and no credential, so the session has nowhere to push. On a host placement a read that fails, or a
72
+ * dispatch without the branch, fails closed: a moved branch could not be detected.
73
+ */
74
+ export declare function readReviewRemoteHead(git: GitClient, worktreePath: string, dispatch: {
75
+ readonly pullRequest?: {
76
+ readonly sourceBranch?: string;
77
+ } | null;
78
+ readonly sandbox?: {
79
+ readonly executionMode?: string;
80
+ } | null;
81
+ }): Promise<ReviewRemoteHead | null>;
82
+ /** Throws `guardrail_violation` when the pull request branch on origin moved, appeared or vanished during the session. */
83
+ export declare function assertReviewRemoteHeadUnchanged(git: GitClient, worktreePath: string, before: ReviewRemoteHead | null): Promise<void>;
@@ -0,0 +1,144 @@
1
+ import fs from "node:fs/promises";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { ForgeFailureError } from "../session.types.js";
5
+ /** The failure code of every review session that changed or published something it must not. */
6
+ export const prReviewGuardrailViolationCode = "guardrail_violation";
7
+ /** A push URL no git transport handles, so a push fails before any network or credential lookup. */
8
+ export const prReviewDisabledPushUrl = "forge-review-push-disabled://publication-is-not-allowed";
9
+ /** The git and gh environment for a review session whose isolation directory is `directory`. */
10
+ export function prReviewIsolatedGitEnvironment(directory, options = {}) {
11
+ const entries = [
12
+ ["credential.helper", ""],
13
+ ["credential.interactive", "false"],
14
+ ["protocol.allow", "never"],
15
+ ["http.extraHeader", ""],
16
+ ["core.askPass", ""],
17
+ ...(options.remotes ?? ["origin"]).map((remote) => [`remote.${remote}.pushurl`, prReviewDisabledPushUrl]),
18
+ ...(options.safeDirectories ?? []).map((directory) => ["safe.directory", directory.replaceAll("\\", "/")]),
19
+ ];
20
+ const env = {
21
+ GIT_CONFIG_GLOBAL: path.join(directory, "gitconfig"),
22
+ GIT_CONFIG_NOSYSTEM: "1",
23
+ GIT_CONFIG_COUNT: String(entries.length),
24
+ GIT_TERMINAL_PROMPT: "0",
25
+ GIT_ASKPASS: "",
26
+ SSH_ASKPASS: "",
27
+ GCM_INTERACTIVE: "never",
28
+ GH_CONFIG_DIR: path.join(directory, "gh"),
29
+ GH_PROMPT_DISABLED: "1",
30
+ GH_NO_UPDATE_NOTIFIER: "1",
31
+ };
32
+ entries.forEach(([key, value], index) => {
33
+ env[`GIT_CONFIG_KEY_${index}`] = key;
34
+ env[`GIT_CONFIG_VALUE_${index}`] = value;
35
+ });
36
+ return env;
37
+ }
38
+ /** Creates the empty global git configuration and gh configuration directory for one session. */
39
+ export async function preparePrReviewCredentialIsolation(options = {}) {
40
+ const directory = await fs.mkdtemp(path.join(options.tempRoot ?? os.tmpdir(), "forge-pr-review-git-"));
41
+ try {
42
+ await fs.writeFile(path.join(directory, "gitconfig"), "", "utf8");
43
+ await fs.mkdir(path.join(directory, "gh"));
44
+ }
45
+ catch (error) {
46
+ await fs.rm(directory, { recursive: true, force: true }).catch(() => undefined);
47
+ throw error;
48
+ }
49
+ return {
50
+ directory,
51
+ env: prReviewIsolatedGitEnvironment(directory, options),
52
+ cleanup: async () => {
53
+ await fs.rm(directory, { recursive: true, force: true }).catch(() => undefined);
54
+ },
55
+ };
56
+ }
57
+ /** The repository's remote names, read before the session starts. */
58
+ export async function listRemotes(git, worktreePath) {
59
+ const output = await git.run(worktreePath, ["remote"]).catch(() => "");
60
+ const remotes = output.split(/\r?\n/u).map((line) => line.trim()).filter((line) => /^[A-Za-z0-9._/-]+$/u.test(line));
61
+ return remotes.length > 0 ? remotes : ["origin"];
62
+ }
63
+ /**
64
+ * The refs a review session could move: the pull request's source branch (local and every
65
+ * remote-tracking copy) and the namespaces only history-rewriting or bookkeeping commands write
66
+ * (notes, replace, stash, bisect, per-worktree refs, filter-branch backups). Other branches and tags
67
+ * are left out on purpose: the repository is shared with Forge's other sessions, whose fetches move
68
+ * them while this review runs.
69
+ */
70
+ export function reviewRefPatterns(sourceBranch, remotes) {
71
+ const branch = sourceBranch?.trim();
72
+ return [
73
+ ...(branch ? [`refs/heads/${branch}`, ...remotes.map((remote) => `refs/remotes/${remote}/${branch}`)] : []),
74
+ "refs/notes",
75
+ "refs/replace",
76
+ "refs/stash",
77
+ "refs/bisect",
78
+ "refs/worktree",
79
+ "refs/original",
80
+ ];
81
+ }
82
+ export async function snapshotReviewRefs(git, worktreePath, patterns) {
83
+ const output = await git.run(worktreePath, ["for-each-ref", "--format=%(refname) %(objectname)", ...patterns]);
84
+ const refs = new Map();
85
+ for (const line of output.split(/\r?\n/u)) {
86
+ const separator = line.lastIndexOf(" ");
87
+ if (separator > 0) {
88
+ refs.set(line.slice(0, separator), line.slice(separator + 1).trim().toLowerCase());
89
+ }
90
+ }
91
+ return { refs };
92
+ }
93
+ /** Throws `guardrail_violation` when a ref in the review's scope was created, moved or deleted. */
94
+ export async function assertReviewRefsUnchanged(git, worktreePath, patterns, baseline) {
95
+ const after = await snapshotReviewRefs(git, worktreePath, patterns);
96
+ const problems = [];
97
+ for (const [ref, sha] of after.refs) {
98
+ const before = baseline.refs.get(ref);
99
+ if (before === undefined)
100
+ problems.push(`${ref} was created`);
101
+ else if (before !== sha)
102
+ problems.push(`${ref} moved from ${before.slice(0, 12)} to ${sha.slice(0, 12)}`);
103
+ }
104
+ for (const ref of baseline.refs.keys()) {
105
+ if (!after.refs.has(ref))
106
+ problems.push(`${ref} was deleted`);
107
+ }
108
+ if (problems.length > 0) {
109
+ throw new ForgeFailureError(prReviewGuardrailViolationCode, `guardrail_violation: the review-only session changed git refs (${problems.slice(0, 10).join("; ")}). Forge discards the review and publishes nothing.`, "bridge");
110
+ }
111
+ }
112
+ /**
113
+ * Reads the pull request branch's head on origin with the bridge's own git environment, never the
114
+ * session's. In the Docker sandbox there is nothing to read: the container's workspace has no remote
115
+ * and no credential, so the session has nowhere to push. On a host placement a read that fails, or a
116
+ * dispatch without the branch, fails closed: a moved branch could not be detected.
117
+ */
118
+ export async function readReviewRemoteHead(git, worktreePath, dispatch) {
119
+ if (dispatch.sandbox?.executionMode === "docker") {
120
+ return null;
121
+ }
122
+ const branch = dispatch.pullRequest?.sourceBranch?.trim() ?? "";
123
+ const unreadable = (detail, cause) => new ForgeFailureError("pr_review_remote_head_unreadable", `pr_review_remote_head_unreadable: ${detail}, so a push from the review could not be detected. Forge did not record the review.`, "bridge", cause === undefined ? undefined : { cause });
124
+ if (!branch) {
125
+ throw unreadable("the review dispatch did not name the pull request branch");
126
+ }
127
+ const output = await git.run(worktreePath, ["ls-remote", "--heads", "origin", `refs/heads/${branch}`])
128
+ .catch((error) => { throw unreadable(`origin could not be read for ${branch}`, error); });
129
+ const sha = output.split(/\r?\n/u)
130
+ .map((line) => line.trim().split(/\s+/u))
131
+ .find(([, ref]) => ref === `refs/heads/${branch}`)?.[0]?.toLowerCase() ?? "";
132
+ return { branch, sha };
133
+ }
134
+ /** Throws `guardrail_violation` when the pull request branch on origin moved, appeared or vanished during the session. */
135
+ export async function assertReviewRemoteHeadUnchanged(git, worktreePath, before) {
136
+ if (!before) {
137
+ return;
138
+ }
139
+ const after = await readReviewRemoteHead(git, worktreePath, { pullRequest: { sourceBranch: before.branch } });
140
+ if (after?.sha !== before.sha) {
141
+ const describe = (sha) => (sha ? sha.slice(0, 12) : "absent");
142
+ throw new ForgeFailureError(prReviewGuardrailViolationCode, `guardrail_violation: the pull request branch ${before.branch} on origin moved from ${describe(before.sha)} to ${describe(after?.sha)} while the review-only session ran. Forge discards the review and publishes nothing.`, "bridge");
143
+ }
144
+ }
@@ -0,0 +1,70 @@
1
+ import { GitClient } from "../../shared/git/git.js";
2
+ /**
3
+ * Guardrails for the review-only pr_review provider session. The session reads a pull request
4
+ * at a pinned head and hands Forge one review through the completion tool; it never changes the
5
+ * checkout, never publishes, and never talks to GitHub. The isolation is the Docker sandbox; a host
6
+ * review runs only where its owner opted in (pr-review-placement.ts), and there everything below is
7
+ * defence in depth. The environment, the same for every provider (pr-review-credential-isolation.ts),
8
+ * carries no credential Forge controls and points git and gh at empty configuration. On top of it: a
9
+ * provider tool deny list (Claude), `git`/`gh` command shims on PATH (POSIX), and post-run worktree,
10
+ * ref and (on a host) remote-head comparisons that fail the session when anything changed.
11
+ */
12
+ export { assertReviewRefsUnchanged, assertReviewRemoteHeadUnchanged, listRemotes, preparePrReviewCredentialIsolation, prReviewGuardrailViolationCode, readReviewRemoteHead, reviewRefPatterns, snapshotReviewRefs, type PrReviewCredentialIsolation, type ReviewRefSnapshot, type ReviewRemoteHead, } from "./pr-review-credential-isolation.js";
13
+ /**
14
+ * Git subcommands that move HEAD, rewrite history, change refs, configuration or the checkout,
15
+ * create other worktrees, or publish. A review only reads (log, diff, show, blame, grep, ...).
16
+ */
17
+ export declare const prReviewDeniedGitSubcommands: readonly string[];
18
+ /**
19
+ * Provider tool rules (Claude Code syntax) the review session is launched without. Deny rules apply
20
+ * even under `--permission-mode bypassPermissions`, which every Forge provider run (reviews included)
21
+ * uses. They are a second layer over the environment (pr-review-credential-isolation.ts), and neither is
22
+ * a boundary on a host: only the Docker sandbox is. The file tools are denied outright, because a
23
+ * review changes nothing and hands its result over only through the completion tool.
24
+ */
25
+ export declare function prReviewDisallowedTools(): readonly string[];
26
+ /**
27
+ * Removes GitHub and publication credentials from a provider environment and disables
28
+ * interactive credential prompts. The provider's own model API key is kept.
29
+ */
30
+ export declare function stripPublicationCredentials(env: Readonly<Record<string, string>>): Readonly<Record<string, string>>;
31
+ export interface PrReviewCommandShims {
32
+ readonly directory: string;
33
+ cleanup(): Promise<void>;
34
+ }
35
+ /**
36
+ * Writes `git` and `gh` wrappers that refuse the denied commands and otherwise run the real
37
+ * binary. POSIX only. Windows has no shim, so command-level enforcement there comes from the
38
+ * provider launch itself: Claude's deny rules (prReviewDisallowedTools) and Codex's read-only
39
+ * sandbox, which has no write or network access. Other providers are refused before launch.
40
+ */
41
+ export declare function installPrReviewCommandShims(parentPath?: string | undefined, platform?: NodeJS.Platform): Promise<PrReviewCommandShims | null>;
42
+ /** `PATH` with the shim directory first. */
43
+ export declare function pathWithShims(shimDirectory: string, parentPath?: string | undefined): string;
44
+ export interface WorktreeSnapshot {
45
+ readonly head: string;
46
+ readonly entries: ReadonlyMap<string, string>;
47
+ }
48
+ export interface WorktreeSnapshotOptions {
49
+ /** Absolute directories whose contents are not part of the checkout (for example test output). */
50
+ readonly ignoredDirectories?: readonly string[];
51
+ }
52
+ /**
53
+ * Records HEAD plus every tracked-modified, untracked or git-ignored path with a content hash
54
+ * (ignored files, which can hold `.env` or build output, use a size and mtime fingerprint). Comparing a
55
+ * before and an after snapshot catches commits, branch moves, edits and new files, including
56
+ * edits to files that were already dirty before the provider started (injected `.forge` files).
57
+ */
58
+ export declare function snapshotWorktree(git: GitClient, worktreePath: string, options?: WorktreeSnapshotOptions): Promise<WorktreeSnapshot>;
59
+ /** Throws `guardrail_violation` when the worktree differs from the pre-session snapshot. */
60
+ export declare function assertWorktreeUnchanged(git: GitClient, worktreePath: string, baseline: WorktreeSnapshot, options?: WorktreeSnapshotOptions): Promise<void>;
61
+ /**
62
+ * Codex's sandbox for a review-only session. On a host it is `read-only`. In the Docker sandbox it is
63
+ * `danger-full-access`, as for every other Docker lane: Codex's Linux sandbox needs kernel facilities
64
+ * (Landlock and seccomp filters, or bubblewrap's user namespaces) that the hardened container
65
+ * (`--cap-drop ALL`, `no-new-privileges`, read-only root, Docker's seccomp profile) does not reliably grant,
66
+ * and where it cannot start, every shell command fails and the review can only end blocked. The container
67
+ * (no git credential, no remote, no host home) is the isolation, and the review stays read-only through its
68
+ * guardrails: the git and gh shims, the worktree, ref and artifact checks, and no publication grant.
69
+ */
70
+ export declare function codexReviewSandboxMode(executionMode?: string): "read-only" | "danger-full-access";