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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (260) hide show
  1. package/README.md +128 -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 +27 -3
  5. package/dist/bridge/bridge-chat-provider-command.js +131 -26
  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.service.d.ts +29 -12
  17. package/dist/bridge/bridge.service.js +215 -380
  18. package/dist/bridge/bridge.types.d.ts +21 -0
  19. package/dist/bridge/bridge.types.js +2 -1
  20. package/dist/bridge/default-session-service.d.ts +13 -0
  21. package/dist/bridge/default-session-service.js +22 -0
  22. package/dist/bridge/dispatch-offer-policy.d.ts +22 -0
  23. package/dist/bridge/dispatch-offer-policy.js +58 -0
  24. package/dist/bridge/in-flight-registry.d.ts +62 -0
  25. package/dist/bridge/in-flight-registry.js +207 -0
  26. package/dist/bridge/readiness-result-outbox.d.ts +5 -1
  27. package/dist/bridge/readiness-result-outbox.js +20 -0
  28. package/dist/bridge/runner-host-capabilities.js +14 -1
  29. package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
  30. package/dist/bridge/sandbox-resource-accounting.js +150 -0
  31. package/dist/bridge/windows-bash-resolution.d.ts +31 -0
  32. package/dist/bridge/windows-bash-resolution.js +153 -0
  33. package/dist/cleanup/cleanup-wip.d.ts +12 -0
  34. package/dist/cleanup/cleanup-wip.js +66 -0
  35. package/dist/cleanup/cleanup.service.d.ts +11 -1
  36. package/dist/cleanup/cleanup.service.js +80 -62
  37. package/dist/cleanup/cleanup.types.d.ts +2 -0
  38. package/dist/cleanup/forge-owned-paths.d.ts +2 -0
  39. package/dist/cleanup/forge-owned-paths.js +9 -0
  40. package/dist/cleanup/host-runtime-ledger.d.ts +2 -0
  41. package/dist/cleanup/host-runtime-ledger.js +30 -9
  42. package/dist/cli/cli.help.js +57 -13
  43. package/dist/cli/cli.service.d.ts +3 -10
  44. package/dist/cli/cli.service.js +20 -213
  45. package/dist/cli/idle-status.d.ts +84 -0
  46. package/dist/cli/idle-status.js +181 -0
  47. package/dist/cli/local-config.d.ts +14 -1
  48. package/dist/cli/local-config.js +42 -2
  49. package/dist/cli/provider-cli-advertising.d.ts +24 -0
  50. package/dist/cli/provider-cli-advertising.js +88 -0
  51. package/dist/cli/provider-cli-detection.d.ts +10 -0
  52. package/dist/cli/provider-cli-detection.js +160 -0
  53. package/dist/runtime/aspnet-runtime-prebuild.d.ts +20 -0
  54. package/dist/runtime/aspnet-runtime-prebuild.js +104 -26
  55. package/dist/runtime/attempt-database-broker.d.ts +1 -1
  56. package/dist/runtime/attempt-node-runtime-launcher.d.ts +36 -0
  57. package/dist/runtime/attempt-node-runtime-launcher.js +169 -0
  58. package/dist/runtime/attempt-process-supervisor.d.ts +2 -0
  59. package/dist/runtime/attempt-process-supervisor.js +12 -6
  60. package/dist/runtime/docker-engine-probe.d.ts +5 -0
  61. package/dist/runtime/docker-engine-probe.js +7 -0
  62. package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
  63. package/dist/runtime/dotnet-build-outputs.js +402 -0
  64. package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
  65. package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
  66. package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
  67. package/dist/runtime/ephemeral-test-postgres.js +303 -0
  68. package/dist/runtime/host-listener-inspector.d.ts +26 -0
  69. package/dist/runtime/host-listener-inspector.js +84 -3
  70. package/dist/runtime/host-load-admission.d.ts +5 -0
  71. package/dist/runtime/host-load-capacity.d.ts +198 -0
  72. package/dist/runtime/host-load-capacity.js +353 -0
  73. package/dist/runtime/host-load-child-environment.d.ts +13 -0
  74. package/dist/runtime/host-load-child-environment.js +35 -1
  75. package/dist/runtime/host-load-governor-config.d.ts +33 -3
  76. package/dist/runtime/host-load-governor-config.js +24 -3
  77. package/dist/runtime/host-load-governor.d.ts +91 -2
  78. package/dist/runtime/host-load-governor.js +217 -18
  79. package/dist/runtime/host-load-ledger-lock.js +6 -4
  80. package/dist/runtime/host-load-live-test-slots.d.ts +61 -0
  81. package/dist/runtime/host-load-live-test-slots.js +193 -0
  82. package/dist/runtime/host-load-runtime-settings.js +4 -2
  83. package/dist/runtime/host-load-sampler.d.ts +25 -1
  84. package/dist/runtime/host-load-sampler.js +38 -7
  85. package/dist/runtime/host-load-step-run.d.ts +37 -3
  86. package/dist/runtime/host-load-step-run.js +63 -7
  87. package/dist/runtime/host-load-test-slot.d.ts +3 -0
  88. package/dist/runtime/host-load-test-slot.js +26 -7
  89. package/dist/runtime/host-runtime-contract.d.ts +12 -0
  90. package/dist/runtime/host-runtime-contract.js +35 -5
  91. package/dist/runtime/host-runtime-lease.d.ts +28 -3
  92. package/dist/runtime/host-runtime-lease.js +140 -296
  93. package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
  94. package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
  95. package/dist/runtime/host-runtime-promotion.d.ts +78 -2
  96. package/dist/runtime/host-runtime-promotion.js +307 -14
  97. package/dist/runtime/managed-command-teardown.js +5 -16
  98. package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
  99. package/dist/runtime/native-test-postgres-fallback.js +60 -8
  100. package/dist/runtime/prepared-runtime-identity.d.ts +4 -0
  101. package/dist/runtime/prepared-runtime-identity.js +130 -9
  102. package/dist/runtime/prepared-runtime-readiness.d.ts +23 -1
  103. package/dist/runtime/prepared-runtime-readiness.js +89 -18
  104. package/dist/runtime/runner-settings.d.ts +4 -0
  105. package/dist/runtime/runner-settings.js +22 -0
  106. package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
  107. package/dist/runtime/supervised-runtime-build-guard.js +112 -0
  108. package/dist/sandbox/host-capacity-broker.d.ts +3 -1
  109. package/dist/sandbox/host-capacity-broker.js +4 -2
  110. package/dist/sandbox/managed-branch.d.ts +13 -0
  111. package/dist/sandbox/managed-branch.js +90 -0
  112. package/dist/sandbox/provider-auth/codex.js +11 -11
  113. package/dist/sandbox/runtime.d.ts +1 -2
  114. package/dist/sandbox/runtime.js +9 -19
  115. package/dist/sandbox/sandbox-input.d.ts +22 -0
  116. package/dist/sandbox/sandbox-input.js +49 -0
  117. package/dist/sandbox/workspace.service.js +15 -2
  118. package/dist/session/managed-attempt-tools.d.ts +0 -7
  119. package/dist/session/managed-attempt-tools.js +54 -109
  120. package/dist/session/managed-build-coordinator.d.ts +16 -0
  121. package/dist/session/managed-build-coordinator.js +10 -0
  122. package/dist/session/managed-build-receipt.d.ts +7 -0
  123. package/dist/session/managed-build-receipt.js +11 -3
  124. package/dist/session/managed-command-environment.d.ts +8 -0
  125. package/dist/session/managed-command-environment.js +28 -0
  126. package/dist/session/managed-command-host-load.d.ts +10 -5
  127. package/dist/session/managed-command-host-load.js +18 -14
  128. package/dist/session/phase-completion.artifact-bundle.d.ts +20 -0
  129. package/dist/session/phase-completion.artifact-bundle.js +167 -0
  130. package/dist/session/phase-completion.artifacts.d.ts +2 -17
  131. package/dist/session/phase-completion.artifacts.js +65 -166
  132. package/dist/session/phase-completion.d.ts +27 -2
  133. package/dist/session/phase-completion.helpers.js +5 -53
  134. package/dist/session/phase-completion.js +15 -32
  135. package/dist/session/phase-completion.mcp-args.d.ts +9 -0
  136. package/dist/session/phase-completion.mcp-args.js +195 -0
  137. package/dist/session/phase-completion.phase-aliases.d.ts +5 -0
  138. package/dist/session/phase-completion.phase-aliases.js +43 -0
  139. package/dist/session/phase-completion.pr-review-schema.d.ts +1 -0
  140. package/dist/session/phase-completion.pr-review-schema.js +75 -0
  141. package/dist/session/phase-completion.pr-review-validation.d.ts +11 -0
  142. package/dist/session/phase-completion.pr-review-validation.js +212 -0
  143. package/dist/session/phase-completion.pr-review.d.ts +36 -0
  144. package/dist/session/phase-completion.pr-review.js +294 -0
  145. package/dist/session/phase-completion.prompts.d.ts +1 -1
  146. package/dist/session/phase-completion.prompts.js +14 -0
  147. package/dist/session/phase-completion.runtime.d.ts +8 -9
  148. package/dist/session/phase-completion.runtime.js +65 -196
  149. package/dist/session/phase-completion.schemas.js +12 -2
  150. package/dist/session/phase-completion.validation.d.ts +1 -0
  151. package/dist/session/phase-completion.validation.js +9 -1
  152. package/dist/session/pr-review-diff-base.d.ts +18 -0
  153. package/dist/session/pr-review-diff-base.js +44 -0
  154. package/dist/session/pr-review-placement.d.ts +50 -0
  155. package/dist/session/pr-review-placement.js +91 -0
  156. package/dist/session/pre-publication-change-set.d.ts +62 -0
  157. package/dist/session/pre-publication-change-set.js +166 -0
  158. package/dist/session/pre-publication-host-load.js +6 -5
  159. package/dist/session/pre-publication-native-postgres.d.ts +30 -0
  160. package/dist/session/pre-publication-native-postgres.js +111 -0
  161. package/dist/session/pre-publication-process.js +13 -12
  162. package/dist/session/pre-publication-step-execution.d.ts +2 -1
  163. package/dist/session/pre-publication-step-execution.js +6 -5
  164. package/dist/session/pre-publication-validation.d.ts +9 -4
  165. package/dist/session/pre-publication-validation.js +62 -65
  166. package/dist/session/provider-cli/claude-background-work.d.ts +3 -2
  167. package/dist/session/provider-cli/claude-background-work.js +4 -3
  168. package/dist/session/provider-cli/dispatch-target-branch.d.ts +7 -0
  169. package/dist/session/provider-cli/dispatch-target-branch.js +8 -0
  170. package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
  171. package/dist/session/provider-cli/host-build-lock.js +30 -0
  172. package/dist/session/provider-cli/pr-review-credential-isolation.d.ts +83 -0
  173. package/dist/session/provider-cli/pr-review-credential-isolation.js +144 -0
  174. package/dist/session/provider-cli/pr-review-guardrails.d.ts +70 -0
  175. package/dist/session/provider-cli/pr-review-guardrails.js +360 -0
  176. package/dist/session/provider-cli/pr-review-prompt.d.ts +2 -0
  177. package/dist/session/provider-cli/pr-review-prompt.js +119 -0
  178. package/dist/session/provider-cli/pre-publication-repair.d.ts +16 -0
  179. package/dist/session/provider-cli/pre-publication-repair.js +41 -3
  180. package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
  181. package/dist/session/provider-cli/provider-cli.child-environment.js +4 -2
  182. package/dist/session/provider-cli/provider-cli.deterministic.d.ts +1 -0
  183. package/dist/session/provider-cli/provider-cli.deterministic.js +5 -0
  184. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +6 -3
  185. package/dist/session/provider-cli/provider-cli.merge-integrity.js +29 -10
  186. package/dist/session/provider-cli/provider-cli.pr-review.d.ts +23 -0
  187. package/dist/session/provider-cli/provider-cli.pr-review.js +213 -0
  188. package/dist/session/provider-cli/provider-cli.process.d.ts +2 -14
  189. package/dist/session/provider-cli/provider-cli.process.js +4 -94
  190. package/dist/session/provider-cli/provider-cli.prompts.d.ts +13 -3
  191. package/dist/session/provider-cli/provider-cli.prompts.js +137 -84
  192. package/dist/session/provider-cli/provider-cli.reapply-conflicts.d.ts +10 -0
  193. package/dist/session/provider-cli/provider-cli.reapply-conflicts.js +37 -0
  194. package/dist/session/provider-cli/provider-cli.runtime.d.ts +15 -0
  195. package/dist/session/provider-cli/provider-cli.runtime.js +37 -2
  196. package/dist/session/provider-cli/provider-cli.service-support.d.ts +37 -0
  197. package/dist/session/provider-cli/provider-cli.service-support.js +146 -0
  198. package/dist/session/provider-cli/provider-cli.service.d.ts +15 -18
  199. package/dist/session/provider-cli/provider-cli.service.js +59 -190
  200. package/dist/session/provider-cli/provider-cli.types.d.ts +7 -2
  201. package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
  202. package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
  203. package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
  204. package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
  205. package/dist/session/qa-sidecar-validation.d.ts +6 -0
  206. package/dist/session/qa-sidecar-validation.js +28 -0
  207. package/dist/session/sandbox-host-capacity-gate.d.ts +22 -1
  208. package/dist/session/sandbox-host-capacity-gate.js +63 -22
  209. package/dist/session/session-host-project.d.ts +22 -0
  210. package/dist/session/session-host-project.js +98 -0
  211. package/dist/session/session-redaction.js +31 -181
  212. package/dist/session/session.parse-helpers.d.ts +10 -0
  213. package/dist/session/session.parse-helpers.js +84 -0
  214. package/dist/session/session.runtime-refresh.d.ts +46 -0
  215. package/dist/session/session.runtime-refresh.js +116 -0
  216. package/dist/session/session.service.d.ts +8 -1
  217. package/dist/session/session.service.js +177 -239
  218. package/dist/session/session.types.d.ts +5 -0
  219. package/dist/session/session.types.js +9 -79
  220. package/dist/session/session.types.pr-review.d.ts +48 -0
  221. package/dist/session/session.types.pr-review.js +51 -0
  222. package/dist/session/sidecar-json-shape.d.ts +31 -0
  223. package/dist/session/sidecar-json-shape.js +217 -0
  224. package/dist/shared/fs/file-identity.d.ts +10 -0
  225. package/dist/shared/fs/file-identity.js +15 -0
  226. package/dist/shared/fs/replace-file.d.ts +7 -0
  227. package/dist/shared/fs/replace-file.js +33 -0
  228. package/dist/shared/process/host-process-recovery.d.ts +14 -3
  229. package/dist/shared/process/host-process-recovery.js +23 -3
  230. package/dist/shared/process/host-process-supervisor.d.ts +13 -1
  231. package/dist/shared/process/host-process-supervisor.js +66 -14
  232. package/dist/shared/provider-capabilities.d.ts +2 -0
  233. package/dist/shared/provider-capabilities.js +18 -1
  234. package/dist/version.d.ts +1 -1
  235. package/dist/version.js +1 -1
  236. package/dist/worktree/artifact-injector.js +24 -0
  237. package/dist/worktree/orphan-relink.d.ts +19 -0
  238. package/dist/worktree/orphan-relink.js +106 -0
  239. package/dist/worktree/wip-git.d.ts +58 -0
  240. package/dist/worktree/wip-git.js +182 -0
  241. package/dist/worktree/wip-refs.d.ts +85 -0
  242. package/dist/worktree/wip-refs.js +169 -0
  243. package/dist/worktree/wip-restore.d.ts +51 -0
  244. package/dist/worktree/wip-restore.js +324 -0
  245. package/dist/worktree/wip-snapshot.d.ts +53 -0
  246. package/dist/worktree/wip-snapshot.js +270 -0
  247. package/dist/worktree/worktree-inputs.d.ts +8 -0
  248. package/dist/worktree/worktree-inputs.js +134 -0
  249. package/dist/worktree/worktree-origin-sync.d.ts +35 -0
  250. package/dist/worktree/worktree-origin-sync.js +128 -0
  251. package/dist/worktree/worktree-wip-events.d.ts +20 -0
  252. package/dist/worktree/worktree-wip-events.js +148 -0
  253. package/dist/worktree/worktree-wip.d.ts +57 -0
  254. package/dist/worktree/worktree-wip.js +200 -0
  255. package/dist/worktree/worktree.base.d.ts +7 -1
  256. package/dist/worktree/worktree.service.d.ts +49 -5
  257. package/dist/worktree/worktree.service.js +223 -187
  258. package/dist/worktree/worktree.types.d.ts +47 -0
  259. package/package.json +1 -1
  260. package/runtime/windows-listener-owner.ps1 +12 -1
@@ -1,15 +1,16 @@
1
1
  import fs from "node:fs/promises";
2
2
  import os from "node:os";
3
3
  import path from "node:path";
4
- import { attemptDatabaseCapabilityEnvironment, attemptDatabaseCapabilitySecrets, } from "../runtime/attempt-database-broker.js";
5
4
  import { completionPhaseFromDispatch, completionPhaseOrder, completionRedactionSecretsEnv, completionToolNamesForDebugGate, completionToolNamesForDecomposeGate, completionToolNamesForDraftGate, completionToolNamesForPhase, completionToolNamesForQaGate, debugCompletionPhaseOrder, decomposeCompletionGateOrder, draftCompletionGateOrder, qaCompletionGateOrder, toolServerName, usesArchitectCycleCompletion, usesDebugCycleCompletion, usesDevelopCycleCompletion, usesQaCycleCompletion } from "./phase-completion.js";
6
- import { CompletionPayloadValidationError, asDebugCompletionPhase, asJsonRpcMessage, asMutableRecord, asRecord, artifactOwnerRelativeRoot, decomposeGateFromToolName, draftGateFromToolName, errorMessage, forgeBridgeCliBinPath, isDebugCompletionPhase, isDecomposeDispatch, isDevelopCompletionPhase, normalizedOwnerType, parseCompletionRedactionSecrets, parseOptionalJsonObject, parseStrictCompletionPhase, phaseFromToolName, qaGateFromToolName, requiredString, rpcError, tomlString, tomlStringArray, writeFileAtomic, writeJsonRpc } from "./phase-completion.validation.js";
5
+ import { CompletionPayloadValidationError, asDebugCompletionPhase, asJsonRpcMessage, asMutableRecord, asRecord, artifactOwnerRelativeRoot, decomposeGateFromToolName, draftGateFromToolName, errorMessage, forgeBridgeCliBinPath, isDebugCompletionPhase, isDecomposeDispatch, normalizedOwnerType, phaseFromToolName, qaGateFromToolName, requiredString, rpcError, tomlString, tomlStringArray, writeJsonRpc } from "./phase-completion.validation.js";
7
6
  import { completionPromptForDebugCycle, completionPromptForDecomposeCycle, completionPromptForDevelopCycle, completionPromptForDraftCycle, completionPromptForPhase, completionPromptForQaCycle, completionToolNextInstruction, completionToolNextInstructionForDebugGate, completionToolNextInstructionForDecomposeGate, completionToolNextInstructionForDraftGate, completionToolNextInstructionForQaGate, nextDebugPhaseAfter, nextPhaseAfter } from "./phase-completion.prompts.js";
8
7
  import { configuredNativeTestPostgresFallbackPath, nativeTestPostgresFallbackConfigEnvironment, } from "../runtime/native-test-postgres-fallback.js";
9
8
  import { isHostLoadChildEnvironmentName } from "../runtime/host-load-child-environment.js";
9
+ import { isProviderUserConfigIsolated, providerUserConfigIsolationUnsupported } from "./provider-cli/provider-user-config-isolation.js";
10
10
  import { toolDescription, toolInputSchema } from "./phase-completion.schemas.js";
11
11
  import { coerceJsonStringArguments, emptyToolInputHint, isEmptyToolInput } from "./mcp-argument-coercion.js";
12
12
  import { writeCompletionArtifact, writeDecomposeGateCompletionArtifact, writeDraftGateCompletionArtifact } from "./phase-completion.artifacts.js";
13
+ import { buildCompletionToolServerArgs } from "./phase-completion.mcp-args.js";
13
14
  import { callManagedAttemptTool, isManagedAttemptTool, managedAttemptToolDefinition, managedAttemptToolInputSchema, managedAttemptToolNames, runWithOwnerShutdown, } from "./managed-attempt-tools.js";
14
15
  export async function prepareCompletionToolRuntime(options) {
15
16
  const phase = options.phase ?? completionPhaseFromDispatch(options.dispatch);
@@ -17,6 +18,8 @@ export async function prepareCompletionToolRuntime(options) {
17
18
  const workItemId = options.dispatch.workItem.id;
18
19
  const ownerType = normalizedOwnerType(options.dispatch.cycleRun.ownerType) ?? "work_item";
19
20
  const ownerId = options.dispatch.cycleRun.ownerId ?? workItemId;
21
+ // A managed-tools-only server records no completion artifact, so it takes no cycle mode.
22
+ const cycles = !options.managedToolsOnly;
20
23
  const mcpArgs = buildCompletionToolServerArgs({
21
24
  worktreePath,
22
25
  workItemId,
@@ -24,15 +27,18 @@ export async function prepareCompletionToolRuntime(options) {
24
27
  ownerId,
25
28
  phase,
26
29
  producedBy: `${options.dispatch.execution.provider}-cli`,
27
- developCycle: usesDevelopCycleCompletion(options.dispatch),
28
- qaCycle: usesQaCycleCompletion(options.dispatch),
29
- debugCycle: usesDebugCycleCompletion(options.dispatch),
30
- architectCycle: usesArchitectCycleCompletion(options.dispatch),
31
- draftCycle: (phase === "draft"
32
- || options.dispatch.execution.lane.trim().toLowerCase() === "draft"
33
- || options.dispatch.cycleRun.kind.trim().toLowerCase() === "draft")
30
+ managedToolsOnly: options.managedToolsOnly,
31
+ developCycle: cycles && usesDevelopCycleCompletion(options.dispatch),
32
+ qaCycle: cycles && usesQaCycleCompletion(options.dispatch),
33
+ debugCycle: cycles && usesDebugCycleCompletion(options.dispatch),
34
+ architectCycle: cycles && usesArchitectCycleCompletion(options.dispatch),
35
+ draftCycle: cycles
36
+ && (phase === "draft"
37
+ || options.dispatch.execution.lane.trim().toLowerCase() === "draft"
38
+ || options.dispatch.cycleRun.kind.trim().toLowerCase() === "draft")
34
39
  && !isDecomposeDispatch(options.dispatch),
35
- decomposeCycle: isDecomposeDispatch(options.dispatch)
40
+ decomposeCycle: cycles && isDecomposeDispatch(options.dispatch),
41
+ prReview: phase === "pr_review" ? prReviewContextFromDispatch(options.dispatch) : undefined
36
42
  });
37
43
  const runtime = {
38
44
  serverName: toolServerName,
@@ -42,49 +48,32 @@ export async function prepareCompletionToolRuntime(options) {
42
48
  cleanup: async () => undefined
43
49
  };
44
50
  const provider = options.dispatch.execution.provider.trim().toLowerCase();
45
- if (provider === "cursor") {
46
- return await prepareCursorCompletionToolRuntime(worktreePath, runtime);
51
+ // Provider phases refuse these at entry (admitUserConfigIsolatedProvider, provider-cli.runtime.ts);
52
+ // this guards any other caller before the Claude MCP config is written.
53
+ if (!isProviderUserConfigIsolated(provider)) {
54
+ throw providerUserConfigIsolationUnsupported(options.dispatch.execution.provider);
47
55
  }
48
56
  if (provider === "claude") {
49
57
  return await prepareClaudeCompletionToolRuntime(runtime);
50
58
  }
51
59
  return runtime;
52
60
  }
53
- export function buildCompletionToolServerArgs(config) {
54
- const args = [
55
- "mcp",
56
- "--worktree",
57
- path.resolve(config.worktreePath),
58
- "--work-item-id",
59
- config.workItemId,
60
- "--phase",
61
- config.phase,
62
- "--produced-by",
63
- config.producedBy ?? "forge-completion-tool"
64
- ];
65
- if (config.ownerType || config.ownerId) {
66
- args.push("--owner-type", normalizedOwnerType(config.ownerType) ?? "work_item");
67
- args.push("--owner-id", config.ownerId ?? config.workItemId);
68
- }
69
- if (config.developCycle) {
70
- args.push("--develop-cycle");
71
- }
72
- if (config.qaCycle) {
73
- args.push("--qa-cycle");
74
- }
75
- if (config.debugCycle) {
76
- args.push("--debug-cycle");
77
- }
78
- if (config.architectCycle) {
79
- args.push("--architect-cycle");
80
- }
81
- if (config.draftCycle) {
82
- args.push("--draft-cycle");
83
- }
84
- if (config.decomposeCycle) {
85
- args.push("--decompose-cycle");
61
+ /**
62
+ * The pull-request facts the pr_review completion tool holds a review to: the admitted head
63
+ * (prReview.headSha, never the live pull request head) and the prior review threads the
64
+ * dispatch lists, and the dispatched base commit the payload's base_sha must resolve to.
65
+ */
66
+ export function prReviewContextFromDispatch(dispatch) {
67
+ const prReview = dispatch.prReview;
68
+ if (!prReview) {
69
+ return undefined;
86
70
  }
87
- return args;
71
+ const threadIds = prReview.priorThreads.map((thread) => thread.threadId);
72
+ return {
73
+ headSha: prReview.headSha.trim() || undefined,
74
+ baseSha: prReview.baseSha.trim() || undefined,
75
+ threadIds: threadIds.length > 0 ? threadIds : undefined
76
+ };
88
77
  }
89
78
  export function codexMcpConfigArgs(runtime) {
90
79
  const prefix = `mcp_servers.${runtime.serverName}`;
@@ -133,6 +122,10 @@ export function completionToolNamesForServer(config) {
133
122
  ? completionToolNamesForPhase("architect")
134
123
  : completionToolNamesForPhase(config.phase);
135
124
  }
125
+ const managedToolsOnlyInstructions = "Forge serves only its managed-attempt tools in this turn: "
126
+ + "forge.start_managed_verification, forge.start_managed_command, forge.wait_managed_command, forge.get_managed_command, "
127
+ + "forge.run_managed_command and forge.reset_generated_outputs. No completion tool is available; the phase's completion "
128
+ + "artifacts are already recorded and must stay as they are.";
136
129
  export class CompletionToolServerSession {
137
130
  config;
138
131
  currentPhase;
@@ -146,20 +139,24 @@ export class CompletionToolServerSession {
146
139
  this.currentPhase = config.phase;
147
140
  }
148
141
  get instructions() {
149
- return this.config.decomposeCycle
150
- ? completionPromptForDecomposeCycle(this.currentDecomposeGate)
151
- : this.config.draftCycle
152
- ? completionPromptForDraftCycle(this.currentDraftGate)
153
- : this.config.debugCycle
154
- ? completionPromptForDebugCycle(asDebugCompletionPhase(this.currentPhase))
155
- : this.config.qaCycle
156
- ? completionPromptForQaCycle(this.currentQaGate, artifactOwnerRelativeRoot(this.config.ownerType, this.config.ownerId, this.config.workItemId))
157
- : this.config.developCycle
158
- ? completionPromptForDevelopCycle(this.currentPhase)
159
- : completionPromptForPhase(this.currentPhase, artifactOwnerRelativeRoot(this.config.ownerType, this.config.ownerId, this.config.workItemId));
142
+ return this.config.managedToolsOnly
143
+ ? managedToolsOnlyInstructions
144
+ : this.config.decomposeCycle
145
+ ? completionPromptForDecomposeCycle(this.currentDecomposeGate)
146
+ : this.config.draftCycle
147
+ ? completionPromptForDraftCycle(this.currentDraftGate)
148
+ : this.config.debugCycle
149
+ ? completionPromptForDebugCycle(asDebugCompletionPhase(this.currentPhase))
150
+ : this.config.qaCycle
151
+ ? completionPromptForQaCycle(this.currentQaGate, artifactOwnerRelativeRoot(this.config.ownerType, this.config.ownerId, this.config.workItemId))
152
+ : this.config.developCycle
153
+ ? completionPromptForDevelopCycle(this.currentPhase)
154
+ : completionPromptForPhase(this.currentPhase, artifactOwnerRelativeRoot(this.config.ownerType, this.config.ownerId, this.config.workItemId));
160
155
  }
161
156
  toolDefinitions() {
162
- const completionTools = completionToolNamesForServer(this.config).map(toolDefinition);
157
+ const completionTools = this.config.managedToolsOnly
158
+ ? []
159
+ : completionToolNamesForServer(this.config).map(toolDefinition);
163
160
  return managedAttemptToolsAvailable()
164
161
  ? [...completionTools, ...managedAttemptToolNames.map(managedAttemptToolDefinition)]
165
162
  : completionTools;
@@ -176,6 +173,9 @@ export class CompletionToolServerSession {
176
173
  }
177
174
  return result;
178
175
  }
176
+ if (this.config.managedToolsOnly) {
177
+ throw new Error(`${toolName} is not available in this turn: Forge serves only its managed-attempt tools during a pre-publication repair turn, and the phase's completion artifacts are already recorded. Fix the failing checks and stop; Bridge reruns validation.`);
178
+ }
179
179
  const requestedPhase = phaseFromToolName(toolName);
180
180
  // Clients sometimes send a declared array/object argument as its JSON text.
181
181
  const input = coerceJsonStringArguments(rawInput, completionToolInputSchema(toolName));
@@ -200,7 +200,8 @@ export class CompletionToolServerSession {
200
200
  const completedPhase = this.currentPhase;
201
201
  const reference = await writeCompletionArtifact({ ...this.config, phase: completedPhase }, toolName, input);
202
202
  const status = reference.status.trim().toLowerCase();
203
- const pass = status === "pass";
203
+ // pr_review accepts reviewed, stale_head and blocked; each ends the lane, and an invalid payload throws above.
204
+ const pass = completedPhase === "pr_review" || status === "pass";
204
205
  const nextPhase = pass
205
206
  ? this.advanceAfterPass(completedPhase)
206
207
  : completedPhase;
@@ -383,6 +384,10 @@ export class CompletionToolServerSession {
383
384
  };
384
385
  }
385
386
  advanceAfterPass(phase) {
387
+ if (phase === "pr_review") {
388
+ this.completed = true;
389
+ return "pr_review_complete";
390
+ }
386
391
  if (phase === "qa") {
387
392
  this.completed = true;
388
393
  return "sign_off_ready";
@@ -491,7 +496,7 @@ export function completionToolRuntimeEnvironment(runtimeEnvironment, nativeTestP
491
496
  env[name] = value.trim();
492
497
  }
493
498
  // Managed verification reads the operator's native test cluster only through
494
- // this explicit path, and only while Docker is unavailable.
499
+ // this explicit path; the file's `use` decides whether Docker comes first.
495
500
  if (runtimeEnvironment && nativeTestPostgresFallbackPath) {
496
501
  env[nativeTestPostgresFallbackConfigEnvironment] = nativeTestPostgresFallbackPath;
497
502
  }
@@ -599,148 +604,12 @@ export async function runCompletionMcpServer(config) {
599
604
  }
600
605
  });
601
606
  }
602
- export function parseCompletionMcpArgs(argv) {
603
- let worktreePath = null;
604
- let workItemId = null;
605
- let phase = "implementation";
606
- let ownerType;
607
- let ownerId;
608
- let producedBy;
609
- let developCycle = false;
610
- let qaCycle = false;
611
- let debugCycle = false;
612
- let architectCycle = false;
613
- let draftCycle = false;
614
- let decomposeCycle = false;
615
- for (let index = 1; index < argv.length; index += 1) {
616
- const arg = argv[index];
617
- if (arg === "--worktree") {
618
- worktreePath = argv[++index] ?? null;
619
- }
620
- else if (arg === "--work-item-id") {
621
- workItemId = argv[++index] ?? null;
622
- }
623
- else if (arg === "--owner-type") {
624
- ownerType = normalizedOwnerType(argv[++index]);
625
- if (!ownerType) {
626
- return { ok: false, error: "mcp --owner-type must be work_item or story." };
627
- }
628
- }
629
- else if (arg === "--owner-id") {
630
- ownerId = argv[++index] ?? undefined;
631
- }
632
- else if (arg === "--phase") {
633
- const rawPhase = argv[++index];
634
- const parsedPhase = parseStrictCompletionPhase(rawPhase);
635
- if (!parsedPhase) {
636
- return { ok: false, error: "mcp --phase must be one of: implementation, self-review, validation, qa, architect, draft, decompose, ci-repair, comment-repair, debug-repro, debug-root-cause, debug-fix, debug-regression." };
637
- }
638
- phase = parsedPhase;
639
- }
640
- else if (arg === "--produced-by") {
641
- producedBy = argv[++index] ?? undefined;
642
- }
643
- else if (arg === "--develop-cycle") {
644
- developCycle = true;
645
- }
646
- else if (arg === "--qa-cycle") {
647
- qaCycle = true;
648
- }
649
- else if (arg === "--debug-cycle") {
650
- debugCycle = true;
651
- }
652
- else if (arg === "--architect-cycle") {
653
- architectCycle = true;
654
- }
655
- else if (arg === "--draft-cycle") {
656
- draftCycle = true;
657
- }
658
- else if (arg === "--decompose-cycle") {
659
- decomposeCycle = true;
660
- }
661
- else {
662
- return { ok: false, error: `Unknown mcp argument: ${arg}` };
663
- }
664
- }
665
- if (!worktreePath?.trim() || !workItemId?.trim()) {
666
- return { ok: false, error: "mcp requires --worktree and --work-item-id." };
667
- }
668
- if ([developCycle, qaCycle, debugCycle, architectCycle, draftCycle, decomposeCycle].filter(Boolean).length > 1) {
669
- return { ok: false, error: "mcp accepts only one cycle mode." };
670
- }
671
- if (developCycle && !isDevelopCompletionPhase(phase)) {
672
- return { ok: false, error: "mcp --develop-cycle requires --phase implementation, self-review, or validation." };
673
- }
674
- if (qaCycle && phase !== "qa") {
675
- return { ok: false, error: "mcp --qa-cycle requires --phase qa." };
676
- }
677
- if (debugCycle && !isDebugCompletionPhase(phase)) {
678
- return { ok: false, error: "mcp --debug-cycle requires --phase debug-repro, debug-root-cause, debug-fix, or debug-regression." };
679
- }
680
- if (architectCycle && phase !== "architect") {
681
- return { ok: false, error: "mcp --architect-cycle requires --phase architect." };
682
- }
683
- if (draftCycle && phase !== "draft") {
684
- return { ok: false, error: "mcp --draft-cycle requires --phase draft." };
685
- }
686
- if (decomposeCycle && phase !== "decompose") {
687
- return { ok: false, error: "mcp --decompose-cycle requires --phase decompose." };
688
- }
689
- return {
690
- ok: true,
691
- config: {
692
- worktreePath: path.resolve(worktreePath),
693
- workItemId,
694
- ownerType,
695
- ownerId,
696
- phase,
697
- producedBy,
698
- redactionSecrets: [
699
- ...parseCompletionRedactionSecrets(process.env[completionRedactionSecretsEnv]),
700
- ...attemptDatabaseCapabilitySecrets(process.env[attemptDatabaseCapabilityEnvironment]),
701
- ],
702
- developCycle,
703
- qaCycle,
704
- debugCycle,
705
- architectCycle,
706
- draftCycle,
707
- decomposeCycle
708
- }
709
- };
710
- }
711
607
  export function completionRedactionEnv(secrets) {
712
608
  const filtered = secrets.filter((secret) => secret.length > 0);
713
609
  return filtered.length > 0
714
610
  ? { [completionRedactionSecretsEnv]: JSON.stringify(filtered) }
715
611
  : {};
716
612
  }
717
- async function prepareCursorCompletionToolRuntime(worktreePath, runtime) {
718
- const cursorDir = path.join(worktreePath, ".cursor");
719
- const configPath = path.join(cursorDir, "mcp.json");
720
- const original = await fs.readFile(configPath, "utf8").then((content) => ({ existed: true, content }), () => ({ existed: false, content: "" }));
721
- const existing = original.existed ? parseOptionalJsonObject(original.content, configPath) : {};
722
- const servers = asMutableRecord(existing.mcpServers);
723
- servers[runtime.serverName] = cursorMcpServerConfig(runtime);
724
- const next = {
725
- ...existing,
726
- mcpServers: servers
727
- };
728
- await fs.mkdir(cursorDir, { recursive: true });
729
- await writeFileAtomic(configPath, `${JSON.stringify(next, null, 2)}\n`);
730
- return {
731
- ...runtime,
732
- cursorMcpConfigPath: configPath,
733
- cleanup: async () => {
734
- if (original.existed) {
735
- await writeFileAtomic(configPath, original.content);
736
- }
737
- else {
738
- await fs.rm(configPath, { force: true });
739
- await fs.rmdir(cursorDir).catch(() => undefined);
740
- }
741
- }
742
- };
743
- }
744
613
  /**
745
614
  * Claude Code takes MCP servers from `--mcp-config <file>`. The file lives in an attempt-owned
746
615
  * temp directory (never the worktree) because its env block can carry redaction secrets, and
@@ -1,5 +1,6 @@
1
1
  import { decomposeGateFileNames, decomposeStatuses, draftStatuses, isDebugCompletionPhase, phaseFiles, qaBlockerReasons, qaGateFileNames } from "./phase-completion.js";
2
2
  import { browserCheckSchema, qaSidecarsSchema, qaEvidenceWrapperSchema, qaGateEvidenceWrapperSchema, findingEvidenceSchema, objectToolSchema, evidenceObjectSchema, qaScopeSchema, commandEvidenceSchema, resolvedFindingSchema, acceptanceCriteriaSchema, reviewSectionSchema, reviewSectionProperties } from "./phase-completion.schema-parts.js";
3
+ import { prReviewToolInputSchema } from "./phase-completion.pr-review-schema.js";
3
4
  import { architectNonPassProperties } from "./architect-waits.js";
4
5
  export function toolDescription(phase, qaGate = null, decomposeGate = null, draftGate = null) {
5
6
  if (qaGate) {
@@ -30,6 +31,9 @@ export function toolDescription(phase, qaGate = null, decomposeGate = null, draf
30
31
  if (phase === "comment_repair") {
31
32
  return "Complete Forge pull-request comment repair by recording one evidence-backed disposition for every actionable finding in the dispatch snapshot.";
32
33
  }
34
+ if (phase === "pr_review") {
35
+ return "Complete Forge pull-request review by recording one comment-only review bound to the reviewed head: a verdict, overview, security summary, and inline comments anchored on new-side diff lines. Forge posts it afterwards; this tool does not publish. Use stale_head when the worktree is not at the dispatched head and blocked when the diff cannot be read.";
36
+ }
33
37
  if (phase === "self_review") {
34
38
  return "Complete Forge self-review by writing self-review.report.json with diff review, findings, security, edge-case, design, deterministic-comparison, fixes, and remaining-risk evidence.";
35
39
  }
@@ -41,8 +45,8 @@ export function toolDescription(phase, qaGate = null, decomposeGate = null, draf
41
45
  }
42
46
  return "Complete Forge validation by writing validation.verdict.json with command, build/test/lint/design, drift, acceptance-criteria, and ready-for-dev-test evidence.";
43
47
  }
44
- export function toolInputSchema(phase, qaGate = null, decomposeGate = null, draftGate = null) {
45
- const baseProperties = {
48
+ function baseToolProperties() {
49
+ return {
46
50
  status: {
47
51
  type: "string",
48
52
  enum: ["pass", "needs_rework", "fail", "failed"],
@@ -60,6 +64,9 @@ export function toolInputSchema(phase, qaGate = null, decomposeGate = null, draf
60
64
  })
61
65
  }
62
66
  };
67
+ }
68
+ export function toolInputSchema(phase, qaGate = null, decomposeGate = null, draftGate = null) {
69
+ const baseProperties = baseToolProperties();
63
70
  if (qaGate && qaGate !== "qa_verdict") {
64
71
  return qaGateToolInputSchema(qaGate);
65
72
  }
@@ -204,6 +211,9 @@ export function toolInputSchema(phase, qaGate = null, decomposeGate = null, draf
204
211
  }
205
212
  }, ["status", "summary", "repair_head_sha", "repair_issue_key", "dispositions", "changed_files", "validation"], "Use status pass after every actionable finding has an evidence-backed disposition. Rejected and needs_decision are legitimate outcomes and must not be disguised as code changes.");
206
213
  }
214
+ if (phase === "pr_review") {
215
+ return prReviewToolInputSchema();
216
+ }
207
217
  if (phase === "implementation") {
208
218
  return objectToolSchema({
209
219
  ...baseProperties,
@@ -1,5 +1,6 @@
1
1
  import { type CompletionPhase, type DebugCompletionPhase, type QaCompletionGate } from "./phase-completion.js";
2
2
  export { validateQaGatePassingCommands } from "./phase-completion.command-validation.js";
3
+ export { validatePrReviewPayloadShape } from "./phase-completion.pr-review-validation.js";
3
4
  export declare const qaEvidenceGates: ReadonlySet<QaCompletionGate>;
4
5
  export declare function normalizeCompletionStatus(value: string, phase?: CompletionPhase): string;
5
6
  export declare function normalizeQaGateStatus(value: string): string;
@@ -1,8 +1,9 @@
1
- import { qaBlockerReasons, qaCandidateBugActions, qaFindingScopes, qaFindingSeverities, qaGateToolNames, qaScopeAuthorities, qaScopeCapabilities, qaScopeConfidence, qaScopeEvidence, qaScopeFields, qaScopeSources, qaScopeSurfaces } from "./phase-completion.js";
1
+ import { qaBlockerReasons, qaCandidateBugActions, qaFindingScopes, qaFindingSeverities, qaGateToolNames, qaScopeAuthorities, qaScopeCapabilities, qaScopeConfidence, qaScopeEvidence, qaScopeFields, qaScopeSources, qaScopeSurfaces, prReviewStatuses } from "./phase-completion.js";
2
2
  import { structuredTypeHint } from "./mcp-argument-coercion.js";
3
3
  import { validateArchitectWaits } from "./architect-waits.js";
4
4
  import { validateQaGatePassingCommands } from "./phase-completion.command-validation.js";
5
5
  export { validateQaGatePassingCommands } from "./phase-completion.command-validation.js";
6
+ export { validatePrReviewPayloadShape } from "./phase-completion.pr-review-validation.js";
6
7
  export const qaEvidenceGates = new Set(["qa_regression", "qa_api", "qa_manual_web", "qa_bug_repro"]);
7
8
  export function normalizeCompletionStatus(value, phase) {
8
9
  const normalized = value.trim().toLowerCase().replace(/-/g, "_");
@@ -13,6 +14,13 @@ export function normalizeCompletionStatus(value, phase) {
13
14
  }
14
15
  return canonical;
15
16
  }
17
+ if (phase === "pr_review") {
18
+ const canonical = normalized === "stalehead" ? "stale_head" : normalized;
19
+ if (!prReviewStatuses.includes(canonical)) {
20
+ throw new Error(`pr_review status must be one of ${prReviewStatuses.join(", ")}.`);
21
+ }
22
+ return canonical;
23
+ }
16
24
  if (phase === "architect") {
17
25
  const canonical = normalized === "needsrevision" ? "needs_revision" : normalized;
18
26
  if (canonical !== "pass" && canonical !== "needs_revision" && canonical !== "blocked") {
@@ -0,0 +1,18 @@
1
+ import type { RunOnceDispatchPacket } from "./session.types.js";
2
+ /** Runs git in the review's repository: resolves with stdout, rejects when git fails. */
3
+ export type ReviewDiffBaseGit = (args: readonly string[]) => Promise<string>;
4
+ /**
5
+ * The commit a Forge PR review diffs against: the merge base of the dispatched base and the head, the
6
+ * same `base...head` diff the pull request shows. The provider's base (GitHub's `base.sha`) is the base
7
+ * branch tip at the pull request's last sync, which is not an ancestor of the head once the base moves
8
+ * on and the branch has not merged it; a Docker sandbox imports only the head's ancestry, so that tip
9
+ * is not there, but the merge base always is. Resolved with the bridge's own git, fetching the base by
10
+ * its SHA when the checkout lacks it and falling back to the base branch on origin when the base commit
11
+ * is gone. Null when the dispatch is not a review or no base can be found: the dispatch is then unchanged.
12
+ */
13
+ export declare function resolveReviewDiffBase(dispatch: Pick<RunOnceDispatchPacket, "execution" | "cycleRun" | "prReview" | "pullRequest">, git: ReviewDiffBaseGit): Promise<string | null>;
14
+ /**
15
+ * The dispatch with its review base set to the diff base, keeping the base tip it replaced, so the prompt,
16
+ * the completion tool's anchor check and the recorded review all use one commit that is in the worktree.
17
+ */
18
+ export declare function withReviewDiffBase(dispatch: RunOnceDispatchPacket, diffBase: string | null): RunOnceDispatchPacket;
@@ -0,0 +1,44 @@
1
+ import { prReviewDispatchHeadSha } from "./pr-review-placement.js";
2
+ const fullObjectId = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/u;
3
+ /**
4
+ * The commit a Forge PR review diffs against: the merge base of the dispatched base and the head, the
5
+ * same `base...head` diff the pull request shows. The provider's base (GitHub's `base.sha`) is the base
6
+ * branch tip at the pull request's last sync, which is not an ancestor of the head once the base moves
7
+ * on and the branch has not merged it; a Docker sandbox imports only the head's ancestry, so that tip
8
+ * is not there, but the merge base always is. Resolved with the bridge's own git, fetching the base by
9
+ * its SHA when the checkout lacks it and falling back to the base branch on origin when the base commit
10
+ * is gone. Null when the dispatch is not a review or no base can be found: the dispatch is then unchanged.
11
+ */
12
+ export async function resolveReviewDiffBase(dispatch, git) {
13
+ const headSha = prReviewDispatchHeadSha(dispatch);
14
+ const baseSha = (dispatch.prReview?.baseSha ?? "").trim().toLowerCase();
15
+ if (!headSha || !baseSha) {
16
+ return null;
17
+ }
18
+ const commit = async (rev) => {
19
+ const sha = (await git(["rev-parse", "--verify", "--quiet", `${rev}^{commit}`]).catch(() => "")).trim().toLowerCase();
20
+ return fullObjectId.test(sha) ? sha : null;
21
+ };
22
+ let base = await commit(baseSha);
23
+ if (!base) {
24
+ await git(["fetch", "--no-tags", "--no-write-fetch-head", "origin", baseSha]).catch(() => undefined);
25
+ const baseBranch = (dispatch.prReview?.baseBranch || dispatch.cycleRun.baseBranch || "").trim();
26
+ base = await commit(baseSha) ?? (baseBranch ? await commit(`refs/remotes/origin/${baseBranch}`) : null);
27
+ }
28
+ if (!base) {
29
+ return null;
30
+ }
31
+ const mergeBase = (await git(["merge-base", base, headSha]).catch(() => "")).trim().toLowerCase();
32
+ return fullObjectId.test(mergeBase) ? mergeBase : null;
33
+ }
34
+ /**
35
+ * The dispatch with its review base set to the diff base, keeping the base tip it replaced, so the prompt,
36
+ * the completion tool's anchor check and the recorded review all use one commit that is in the worktree.
37
+ */
38
+ export function withReviewDiffBase(dispatch, diffBase) {
39
+ const prReview = dispatch.prReview;
40
+ if (!diffBase || !prReview || prReview.baseSha.trim().toLowerCase() === diffBase) {
41
+ return dispatch;
42
+ }
43
+ return { ...dispatch, prReview: { ...prReview, baseSha: diffBase, baseTipSha: prReview.baseTipSha || prReview.baseSha } };
44
+ }
@@ -0,0 +1,50 @@
1
+ import { type RunnerDispatchEvent, type RunOnceDispatchPacket, type RunOnceResultPacket } from "./session.types.js";
2
+ /**
3
+ * Where a Forge PR review may run. A review reads pull request code an author controls, and the only
4
+ * operating-system isolation this bridge enforces is its Docker sandbox: a container with no git
5
+ * credential, no remote and no host home directory. On a plain host the provider runs as the
6
+ * bridge's user, beside that user's git credentials and provider sign-in, and the review guardrails
7
+ * (credential-free git environment, tool deny rules, command shims, the post-run ref and remote-head
8
+ * checks) are defence in depth, not a boundary. So a review placed on the host is refused before any
9
+ * provider starts unless the runner's owner opted in with `allowUnsandboxedPrReview: true` in
10
+ * bridge.json, accepting that risk.
11
+ */
12
+ export declare const prReviewUnsandboxedHostCode = "pr_review.unsandboxed_host";
13
+ /**
14
+ * A review placed in this bridge's Docker sandbox for a project whose sandbox contract it cannot read or build:
15
+ * refused before any provider starts, and never retried on this runner (a capacity wait would only expire).
16
+ */
17
+ export declare const prReviewSandboxUnavailableCode = "pr_review.sandbox_unavailable";
18
+ /** The execution facility a runner advertises when its owner opted in to host-placed reviews. */
19
+ export declare const prReviewUnsandboxedHostFacility = "pr_review_unsandboxed_host";
20
+ /** The warning a host-placed review carries when the runner's owner opted in. */
21
+ export declare const prReviewUnsandboxedHostWarningEvent = "pr_review_unsandboxed_host_warning";
22
+ /** A dispatch for the review-only pr_review session, by role, lane or cycle kind. */
23
+ export declare function isPrReviewDispatch(dispatch: Pick<RunOnceDispatchPacket, "execution" | "cycleRun">): boolean;
24
+ /** The pull request head a review dispatch reads, lowercased, or null for any other dispatch. */
25
+ export declare function prReviewDispatchHeadSha(dispatch: Pick<RunOnceDispatchPacket, "execution" | "cycleRun" | "prReview" | "pullRequest">): string | null;
26
+ /** Why this bridge refuses the dispatch, or null: a review placed outside Docker without the opt-in. */
27
+ export declare function prReviewPlacementRefusal(dispatch: Pick<RunOnceDispatchPacket, "execution" | "cycleRun" | "sandbox">, allowUnsandboxedPrReview: boolean | undefined): string | null;
28
+ /** The warning for a review that runs on the host because the runner's owner opted in, or null. */
29
+ export declare function prReviewUnsandboxedHostWarning(dispatch: Pick<RunOnceDispatchPacket, "execution" | "cycleRun" | "sandbox">, allowUnsandboxedPrReview: boolean | undefined): string | null;
30
+ /** The terminal failure for a refused review (see {@link prReviewPlacementRefusal}), or null. */
31
+ export declare function prReviewPlacementRefusalResult(dispatch: Pick<RunOnceDispatchPacket, "execution" | "cycleRun" | "sandbox">, allowUnsandboxedPrReview: boolean | undefined): RunOnceResultPacket | null;
32
+ /**
33
+ * Set by the server-local runner on a run-once whose Forge PR review it admitted on its host (in its container
34
+ * sandbox, or because the runner opted in to host reviews). Nothing else sets it.
35
+ */
36
+ export declare const prReviewHostAdmittedEnv = "FORGE_PR_REVIEW_HOST_ADMITTED";
37
+ /**
38
+ * forge-bridge run-once (which the server-local runner launches): a Forge PR review placed outside Docker runs
39
+ * only when the server-local runner admitted it on this host; any other is refused before a provider starts.
40
+ */
41
+ export declare function runOnceWithReviewPlacement(dispatch: RunOnceDispatchPacket, run: (dispatch: RunOnceDispatchPacket) => Promise<RunOnceResultPacket>, env?: NodeJS.ProcessEnv): Promise<RunOnceResultPacket>;
42
+ /** The execution facilities that tell Forge this runner's owner opted in to host-placed reviews. */
43
+ export declare function prReviewExecutionFacilities(allowUnsandboxedPrReview: boolean | undefined): readonly string[];
44
+ /**
45
+ * Runs the dispatch; a review that runs on the host by the owner's opt-in is logged, announced as a
46
+ * session event and reported in the result summary as a warning.
47
+ */
48
+ export declare function runWithUnsandboxedReviewWarning(dispatch: Pick<RunOnceDispatchPacket, "execution" | "cycleRun" | "sandbox">, allowUnsandboxedPrReview: boolean | undefined, sink: {
49
+ emit(event: RunnerDispatchEvent): Promise<void>;
50
+ }, log: (message: string) => void, run: () => Promise<RunOnceResultPacket>): Promise<RunOnceResultPacket>;