@loucompanion/forge-bridge 0.1.4-dev.fb770705136a → 0.2.1-dev.0f07274d438b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +183 -4
- package/dist/bridge/bridge-chat-giphy-look.d.ts +48 -0
- package/dist/bridge/bridge-chat-giphy-look.js +55 -0
- package/dist/bridge/bridge-chat-provider-command.d.ts +40 -0
- package/dist/bridge/bridge-chat-provider-command.js +230 -0
- package/dist/bridge/bridge-chat.types.d.ts +20 -0
- package/dist/bridge/bridge-chat.types.js +28 -1
- package/dist/bridge/bridge-state-file.d.ts +161 -0
- package/dist/bridge/bridge-state-file.js +376 -0
- package/dist/bridge/bridge-state-io.d.ts +15 -0
- package/dist/bridge/bridge-state-io.js +68 -0
- package/dist/bridge/bridge-state-lock.d.ts +11 -0
- package/dist/bridge/bridge-state-lock.js +102 -0
- package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
- package/dist/bridge/bridge-state-unpublished.js +111 -0
- package/dist/bridge/bridge.base.d.ts +9 -0
- package/dist/bridge/bridge.service.d.ts +102 -14
- package/dist/bridge/bridge.service.js +499 -471
- package/dist/bridge/bridge.types.d.ts +37 -0
- package/dist/bridge/bridge.types.js +2 -1
- package/dist/bridge/default-session-service.d.ts +13 -0
- package/dist/bridge/default-session-service.js +22 -0
- package/dist/bridge/dispatch-offer-policy.d.ts +22 -0
- package/dist/bridge/dispatch-offer-policy.js +58 -0
- package/dist/bridge/in-flight-registry.d.ts +62 -0
- package/dist/bridge/in-flight-registry.js +207 -0
- package/dist/bridge/local-yield-flag.d.ts +6 -0
- package/dist/bridge/local-yield-flag.js +34 -0
- package/dist/bridge/readiness-result-outbox.d.ts +5 -1
- package/dist/bridge/readiness-result-outbox.js +20 -0
- package/dist/bridge/runner-host-capabilities.d.ts +5 -0
- package/dist/bridge/runner-host-capabilities.js +31 -1
- package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
- package/dist/bridge/sandbox-resource-accounting.js +150 -0
- package/dist/bridge/test-postgres-capability.d.ts +14 -0
- package/dist/bridge/test-postgres-capability.js +120 -0
- package/dist/bridge/windows-bash-resolution.d.ts +31 -0
- package/dist/bridge/windows-bash-resolution.js +153 -0
- package/dist/cleanup/cleanup-wip.d.ts +12 -0
- package/dist/cleanup/cleanup-wip.js +66 -0
- package/dist/cleanup/cleanup.service.d.ts +20 -1
- package/dist/cleanup/cleanup.service.js +150 -169
- package/dist/cleanup/cleanup.types.d.ts +6 -0
- package/dist/cleanup/forge-owned-paths.d.ts +11 -0
- package/dist/cleanup/forge-owned-paths.js +62 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +7 -0
- package/dist/cleanup/host-runtime-ledger.js +130 -0
- package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
- package/dist/cleanup/managed-branch-sweep.js +111 -0
- package/dist/cli/cli.help.js +75 -13
- package/dist/cli/cli.service.d.ts +19 -10
- package/dist/cli/cli.service.js +161 -228
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +18 -1
- package/dist/cli/local-config.js +67 -5
- package/dist/cli/provider-cli-advertising.d.ts +24 -0
- package/dist/cli/provider-cli-advertising.js +88 -0
- package/dist/cli/provider-cli-detection.d.ts +10 -0
- package/dist/cli/provider-cli-detection.js +160 -0
- package/dist/runtime/aspnet-runtime-prebuild.d.ts +20 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +184 -18
- package/dist/runtime/attempt-database-broker.d.ts +1 -1
- package/dist/runtime/attempt-node-runtime-launcher.d.ts +36 -0
- package/dist/runtime/attempt-node-runtime-launcher.js +169 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +2 -0
- package/dist/runtime/attempt-process-supervisor.js +12 -6
- package/dist/runtime/docker-engine-probe.d.ts +5 -0
- package/dist/runtime/docker-engine-probe.js +7 -0
- package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
- package/dist/runtime/dotnet-build-outputs.js +402 -0
- package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
- package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
- package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
- package/dist/runtime/ephemeral-test-postgres.js +303 -0
- package/dist/runtime/host-facts.d.ts +2 -1
- package/dist/runtime/host-listener-inspector.d.ts +26 -0
- package/dist/runtime/host-listener-inspector.js +84 -3
- package/dist/runtime/host-load-admission.d.ts +72 -0
- package/dist/runtime/host-load-admission.js +99 -0
- package/dist/runtime/host-load-capacity.d.ts +198 -0
- package/dist/runtime/host-load-capacity.js +353 -0
- package/dist/runtime/host-load-child-environment.d.ts +40 -0
- package/dist/runtime/host-load-child-environment.js +110 -0
- package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
- package/dist/runtime/host-load-forge-cgroups.js +140 -0
- package/dist/runtime/host-load-governor-config.d.ts +82 -0
- package/dist/runtime/host-load-governor-config.js +104 -0
- package/dist/runtime/host-load-governor.d.ts +273 -0
- package/dist/runtime/host-load-governor.js +831 -0
- package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
- package/dist/runtime/host-load-ledger-lock.js +187 -0
- package/dist/runtime/host-load-live-test-slots.d.ts +61 -0
- package/dist/runtime/host-load-live-test-slots.js +193 -0
- package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
- package/dist/runtime/host-load-runtime-settings.js +80 -0
- package/dist/runtime/host-load-sampler.d.ts +92 -2
- package/dist/runtime/host-load-sampler.js +166 -8
- package/dist/runtime/host-load-step-class.d.ts +70 -0
- package/dist/runtime/host-load-step-class.js +161 -0
- package/dist/runtime/host-load-step-reaper.d.ts +27 -0
- package/dist/runtime/host-load-step-reaper.js +95 -0
- package/dist/runtime/host-load-step-run.d.ts +107 -0
- package/dist/runtime/host-load-step-run.js +158 -0
- package/dist/runtime/host-load-test-slot.d.ts +46 -0
- package/dist/runtime/host-load-test-slot.js +100 -0
- package/dist/runtime/host-load-token-ledger.d.ts +200 -0
- package/dist/runtime/host-load-token-ledger.js +453 -0
- package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
- package/dist/runtime/host-load-windows-cpu.js +85 -0
- package/dist/runtime/host-pressure-stall.d.ts +21 -1
- package/dist/runtime/host-pressure-stall.js +48 -1
- package/dist/runtime/host-runtime-contract.d.ts +15 -0
- package/dist/runtime/host-runtime-contract.js +39 -6
- package/dist/runtime/host-runtime-lease.d.ts +101 -6
- package/dist/runtime/host-runtime-lease.js +408 -294
- package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
- package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
- package/dist/runtime/host-runtime-promotion.d.ts +101 -2
- package/dist/runtime/host-runtime-promotion.js +355 -14
- package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
- package/dist/runtime/host-runtime-requirements-check.js +29 -0
- package/dist/runtime/host-runtime-requirements.d.ts +36 -0
- package/dist/runtime/host-runtime-requirements.js +117 -0
- package/dist/runtime/managed-command-teardown.js +5 -16
- package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
- package/dist/runtime/native-test-postgres-fallback.js +60 -8
- package/dist/runtime/playwright-host-runtime-adapter.d.ts +7 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
- package/dist/runtime/prepared-runtime-identity.d.ts +4 -0
- package/dist/runtime/prepared-runtime-identity.js +130 -9
- package/dist/runtime/prepared-runtime-readiness.d.ts +23 -1
- package/dist/runtime/prepared-runtime-readiness.js +89 -18
- package/dist/runtime/runner-settings.d.ts +104 -0
- package/dist/runtime/runner-settings.js +236 -0
- package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
- package/dist/runtime/supervised-runtime-build-guard.js +112 -0
- package/dist/sandbox/host-capacity-broker.d.ts +115 -0
- package/dist/sandbox/host-capacity-broker.js +336 -0
- package/dist/sandbox/managed-branch.d.ts +13 -0
- package/dist/sandbox/managed-branch.js +90 -0
- package/dist/sandbox/provider-auth/codex.js +11 -11
- package/dist/sandbox/runtime.d.ts +11 -3
- package/dist/sandbox/runtime.js +53 -20
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -0
- package/dist/sandbox/sandbox-input.d.ts +22 -0
- package/dist/sandbox/sandbox-input.js +49 -0
- package/dist/sandbox/workspace.service.js +15 -2
- package/dist/session/architect-waits.d.ts +2 -0
- package/dist/session/architect-waits.js +138 -0
- package/dist/session/managed-attempt-tools.d.ts +2 -7
- package/dist/session/managed-attempt-tools.js +204 -141
- package/dist/session/managed-build-coordinator.d.ts +16 -0
- package/dist/session/managed-build-coordinator.js +10 -0
- package/dist/session/managed-build-receipt.d.ts +7 -0
- package/dist/session/managed-build-receipt.js +11 -3
- package/dist/session/managed-command-environment.d.ts +8 -0
- package/dist/session/managed-command-environment.js +28 -0
- package/dist/session/managed-command-host-load.d.ts +52 -0
- package/dist/session/managed-command-host-load.js +87 -0
- package/dist/session/mcp-argument-coercion.d.ts +23 -0
- package/dist/session/mcp-argument-coercion.js +121 -0
- package/dist/session/phase-completion.artifact-bundle.d.ts +20 -0
- package/dist/session/phase-completion.artifact-bundle.js +167 -0
- package/dist/session/phase-completion.artifacts.d.ts +9 -17
- package/dist/session/phase-completion.artifacts.js +158 -190
- package/dist/session/phase-completion.command-validation.d.ts +7 -0
- package/dist/session/phase-completion.command-validation.js +77 -0
- package/dist/session/phase-completion.d.ts +31 -2
- package/dist/session/phase-completion.helpers.js +18 -65
- package/dist/session/phase-completion.js +19 -32
- package/dist/session/phase-completion.mcp-args.d.ts +9 -0
- package/dist/session/phase-completion.mcp-args.js +195 -0
- package/dist/session/phase-completion.phase-aliases.d.ts +5 -0
- package/dist/session/phase-completion.phase-aliases.js +43 -0
- package/dist/session/phase-completion.pr-review-schema.d.ts +1 -0
- package/dist/session/phase-completion.pr-review-schema.js +75 -0
- package/dist/session/phase-completion.pr-review-validation.d.ts +11 -0
- package/dist/session/phase-completion.pr-review-validation.js +212 -0
- package/dist/session/phase-completion.pr-review.d.ts +36 -0
- package/dist/session/phase-completion.pr-review.js +294 -0
- package/dist/session/phase-completion.prompts.d.ts +1 -1
- package/dist/session/phase-completion.prompts.js +20 -1
- package/dist/session/phase-completion.runtime.d.ts +13 -12
- package/dist/session/phase-completion.runtime.js +113 -214
- package/dist/session/phase-completion.schema-parts.d.ts +19 -0
- package/dist/session/phase-completion.schema-parts.js +188 -0
- package/dist/session/phase-completion.schemas.d.ts +3 -3
- package/dist/session/phase-completion.schemas.js +219 -232
- package/dist/session/phase-completion.validation.d.ts +3 -3
- package/dist/session/phase-completion.validation.js +58 -94
- package/dist/session/pr-review-diff-base.d.ts +18 -0
- package/dist/session/pr-review-diff-base.js +44 -0
- package/dist/session/pr-review-placement.d.ts +50 -0
- package/dist/session/pr-review-placement.js +91 -0
- package/dist/session/pre-publication-change-set.d.ts +62 -0
- package/dist/session/pre-publication-change-set.js +166 -0
- package/dist/session/pre-publication-host-load.d.ts +27 -0
- package/dist/session/pre-publication-host-load.js +112 -0
- package/dist/session/pre-publication-native-postgres.d.ts +30 -0
- package/dist/session/pre-publication-native-postgres.js +111 -0
- package/dist/session/pre-publication-pass.d.ts +61 -0
- package/dist/session/pre-publication-pass.js +148 -0
- package/dist/session/pre-publication-process.d.ts +3 -0
- package/dist/session/pre-publication-process.js +32 -19
- package/dist/session/pre-publication-step-execution.d.ts +12 -0
- package/dist/session/pre-publication-step-execution.js +50 -0
- package/dist/session/pre-publication-validation.d.ts +39 -22
- package/dist/session/pre-publication-validation.js +241 -207
- package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
- package/dist/session/provider-cli/claude-background-work.js +181 -0
- package/dist/session/provider-cli/dispatch-target-branch.d.ts +7 -0
- package/dist/session/provider-cli/dispatch-target-branch.js +8 -0
- package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
- package/dist/session/provider-cli/host-build-lock.js +30 -0
- package/dist/session/provider-cli/pr-review-credential-isolation.d.ts +83 -0
- package/dist/session/provider-cli/pr-review-credential-isolation.js +144 -0
- package/dist/session/provider-cli/pr-review-guardrails.d.ts +70 -0
- package/dist/session/provider-cli/pr-review-guardrails.js +360 -0
- package/dist/session/provider-cli/pr-review-prompt.d.ts +2 -0
- package/dist/session/provider-cli/pr-review-prompt.js +119 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
- package/dist/session/provider-cli/pre-publication-repair.js +281 -0
- package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
- package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +75 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
- package/dist/session/provider-cli/provider-cli.deterministic.d.ts +1 -0
- package/dist/session/provider-cli/provider-cli.deterministic.js +5 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +6 -3
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +29 -10
- package/dist/session/provider-cli/provider-cli.pr-review.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.pr-review.js +213 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +15 -36
- package/dist/session/provider-cli/provider-cli.process.js +41 -432
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +15 -3
- package/dist/session/provider-cli/provider-cli.prompts.js +183 -90
- package/dist/session/provider-cli/provider-cli.reapply-conflicts.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.reapply-conflicts.js +37 -0
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +15 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +43 -1
- package/dist/session/provider-cli/provider-cli.service-support.d.ts +37 -0
- package/dist/session/provider-cli/provider-cli.service-support.js +146 -0
- package/dist/session/provider-cli/provider-cli.service.d.ts +18 -18
- package/dist/session/provider-cli/provider-cli.service.js +127 -317
- package/dist/session/provider-cli/provider-cli.types.d.ts +35 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +4 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +45 -0
- package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
- package/dist/session/provider-cli/provider-output-pipes.js +67 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +2 -0
- package/dist/session/provider-cli/provider-output-state.js +6 -0
- package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
- package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
- package/dist/session/qa-sidecar-validation.d.ts +6 -0
- package/dist/session/qa-sidecar-validation.js +28 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +51 -0
- package/dist/session/sandbox-host-capacity-gate.js +279 -0
- package/dist/session/session-host-project.d.ts +22 -0
- package/dist/session/session-host-project.js +98 -0
- package/dist/session/session-redaction.js +31 -181
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.parse-helpers.d.ts +10 -0
- package/dist/session/session.parse-helpers.js +84 -0
- package/dist/session/session.runtime-refresh.d.ts +46 -0
- package/dist/session/session.runtime-refresh.js +116 -0
- package/dist/session/session.service.d.ts +16 -2
- package/dist/session/session.service.js +208 -155
- package/dist/session/session.types.d.ts +8 -0
- package/dist/session/session.types.js +13 -83
- package/dist/session/session.types.pr-review.d.ts +48 -0
- package/dist/session/session.types.pr-review.js +51 -0
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -0
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -0
- package/dist/shared/fs/file-identity.d.ts +10 -0
- package/dist/shared/fs/file-identity.js +15 -0
- package/dist/shared/fs/replace-file.d.ts +7 -0
- package/dist/shared/fs/replace-file.js +33 -0
- package/dist/shared/process/host-process-recovery.d.ts +14 -3
- package/dist/shared/process/host-process-recovery.js +23 -3
- package/dist/shared/process/host-process-supervisor.d.ts +14 -1
- package/dist/shared/process/host-process-supervisor.js +67 -15
- package/dist/shared/process/process-tree.d.ts +52 -0
- package/dist/shared/process/process-tree.js +144 -0
- package/dist/shared/process/process.d.ts +67 -0
- package/dist/shared/process/process.js +213 -11
- package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
- package/dist/shared/process/windows-app-execution-alias.js +45 -0
- package/dist/shared/process/windows-launch.d.ts +18 -0
- package/dist/shared/process/windows-launch.js +68 -0
- package/dist/shared/provider-capabilities.d.ts +2 -0
- package/dist/shared/provider-capabilities.js +23 -7
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/artifact-injector.js +24 -0
- package/dist/worktree/dependency-warmer.d.ts +25 -0
- package/dist/worktree/dependency-warmer.js +46 -10
- package/dist/worktree/orphan-relink.d.ts +19 -0
- package/dist/worktree/orphan-relink.js +106 -0
- package/dist/worktree/wip-git.d.ts +58 -0
- package/dist/worktree/wip-git.js +182 -0
- package/dist/worktree/wip-refs.d.ts +85 -0
- package/dist/worktree/wip-refs.js +169 -0
- package/dist/worktree/wip-restore.d.ts +51 -0
- package/dist/worktree/wip-restore.js +324 -0
- package/dist/worktree/wip-snapshot.d.ts +53 -0
- package/dist/worktree/wip-snapshot.js +270 -0
- package/dist/worktree/worktree-inputs.d.ts +8 -0
- package/dist/worktree/worktree-inputs.js +134 -0
- package/dist/worktree/worktree-origin-sync.d.ts +35 -0
- package/dist/worktree/worktree-origin-sync.js +128 -0
- package/dist/worktree/worktree-wip-events.d.ts +20 -0
- package/dist/worktree/worktree-wip-events.js +148 -0
- package/dist/worktree/worktree-wip.d.ts +57 -0
- package/dist/worktree/worktree-wip.js +200 -0
- package/dist/worktree/worktree.base.d.ts +7 -1
- package/dist/worktree/worktree.service.d.ts +58 -5
- package/dist/worktree/worktree.service.js +237 -161
- package/dist/worktree/worktree.types.d.ts +54 -0
- package/package.json +2 -2
- package/runtime/windows-listener-owner.ps1 +12 -1
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { HostPortCollisionError } from "../../runtime/host-port-broker.js";
|
|
2
|
+
import { runtimeAdmissionPriority } from "../../runtime/host-runtime-lease.js";
|
|
3
|
+
import { runtimeRestartCheckId } from "../pre-publication-pass.js";
|
|
4
|
+
import { PrePublicationValidationError, } from "../pre-publication-validation.js";
|
|
5
|
+
import { prepareCompletionToolRuntime } from "../phase-completion.js";
|
|
6
|
+
import { ForgeFailureError } from "../session.types.js";
|
|
7
|
+
import { dispatchTargetBranch } from "./dispatch-target-branch.js";
|
|
8
|
+
import { buildProviderCliCommand, buildProviderCliPrompt, shouldPipePromptToStdin, usesManagedWindowsHost, } from "./provider-cli.prompts.js";
|
|
9
|
+
import { prePublicationValidationEnv, providerProcessEnv } from "./provider-cli.runtime.js";
|
|
10
|
+
import { clip } from "./provider-output-state.js";
|
|
11
|
+
// Pre-publication validation with bounded in-place repair: each pass restarts the attempt's runtime
|
|
12
|
+
// stack when the workspace changed, runs every check that can still meaningfully run, and hands all
|
|
13
|
+
// of the pass's failures to one resumed provider turn, up to the repair budget.
|
|
14
|
+
const defaultRepairTurns = 4;
|
|
15
|
+
const maximumRepairTurns = 10;
|
|
16
|
+
const repairTurnsEnvironment = "FORGE_PREPUBLICATION_REPAIR_TURNS";
|
|
17
|
+
// The repair prompt's diagnostics: each failed check gets an equal share of the total, between the
|
|
18
|
+
// floor and the ceiling (validation already clips each check's own output to the ceiling). The
|
|
19
|
+
// total keeps a prompt passed as a command-line argument within Windows' 32,767-character limit.
|
|
20
|
+
const repairPromptDetailBudget = 18_000;
|
|
21
|
+
const repairPromptDetailCeiling = 6000;
|
|
22
|
+
const repairPromptDetailFloor = 1500;
|
|
23
|
+
/**
|
|
24
|
+
* The in-place repair budget: FORGE_PREPUBLICATION_REPAIR_TURNS when it is a whole number from 1
|
|
25
|
+
* (capped at 10), otherwise 4.
|
|
26
|
+
*/
|
|
27
|
+
export function prePublicationRepairTurnsFromEnvironment(environment = process.env) {
|
|
28
|
+
const configured = environment[repairTurnsEnvironment]?.trim() ?? "";
|
|
29
|
+
return /^\d+$/u.test(configured) && Number(configured) >= 1
|
|
30
|
+
? Math.min(Number(configured), maximumRepairTurns)
|
|
31
|
+
: defaultRepairTurns;
|
|
32
|
+
}
|
|
33
|
+
/** The environments a pass and its repair turn use; a runtime restart assigns new ports, so all move together. */
|
|
34
|
+
class RepairEnvironments {
|
|
35
|
+
options;
|
|
36
|
+
repair;
|
|
37
|
+
constructor(options) {
|
|
38
|
+
this.options = options;
|
|
39
|
+
this.repair = options.repairEnvironment;
|
|
40
|
+
}
|
|
41
|
+
get provider() {
|
|
42
|
+
return providerProcessEnv(this.options.context.dispatch, this.repair);
|
|
43
|
+
}
|
|
44
|
+
get validation() {
|
|
45
|
+
return prePublicationValidationEnv(this.options.context.dispatch, this.repair);
|
|
46
|
+
}
|
|
47
|
+
async refresh(runtimeEnvironment) {
|
|
48
|
+
this.repair = this.options.onRuntimeEnvironmentRefreshed
|
|
49
|
+
? await this.options.onRuntimeEnvironmentRefreshed(runtimeEnvironment)
|
|
50
|
+
: runtimeEnvironment;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The restart stopped the stack and released its ports before it failed, so the URLs the pass and
|
|
54
|
+
* repair turn would inherit name ports another attempt may now hold. Both run without them; the
|
|
55
|
+
* next pass restarts the stack and supplies fresh ones.
|
|
56
|
+
*/
|
|
57
|
+
async withdrawRuntimeStack() {
|
|
58
|
+
await this.refresh(withoutRuntimeStack(this.repair, this.options.context.runtimeStackEnvironmentKeys ?? []));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export async function validatePrePublicationWithRepair(options, dependencies) {
|
|
62
|
+
const { context, outputState } = options;
|
|
63
|
+
const { maxRepairTurns } = dependencies;
|
|
64
|
+
const environments = new RepairEnvironments(options);
|
|
65
|
+
for (let repairTurn = 0;; repairTurn += 1) {
|
|
66
|
+
const failure = await runValidationPass(options, dependencies, environments, repairTurn);
|
|
67
|
+
if (!failure) {
|
|
68
|
+
if (repairTurn > 0) {
|
|
69
|
+
await context.emit(repairEvent("checkpoint", "prepublication_repair_completed", `Pre-publication validation passed after ${repairTurn} in-place repair turn${repairTurn === 1 ? "" : "s"}.`, { repairTurn, maxRepairTurns }));
|
|
70
|
+
}
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (repairTurn >= maxRepairTurns) {
|
|
74
|
+
await context.emit(repairEvent("error", "prepublication_repair_exhausted", `Pre-publication validation still fails after ${maxRepairTurns} in-place repair turns: ${clip(failure.message, 4000)}`, { checkId: failure.checkId, checkIds: failure.checkIds, repairTurns: repairTurn, maxRepairTurns }));
|
|
75
|
+
throw failure;
|
|
76
|
+
}
|
|
77
|
+
const providerThreadId = outputState.providerThreadId?.trim();
|
|
78
|
+
if (!providerThreadId) {
|
|
79
|
+
throw new Error(`prepublication_repair_unavailable: ${failure.message}; provider did not report a resumable thread id, so Forge preserved the dirty worktree without starting a blind replacement run.`, { cause: failure });
|
|
80
|
+
}
|
|
81
|
+
const nextRepairTurn = repairTurn + 1;
|
|
82
|
+
await context.emit(repairEvent("checkpoint", "prepublication_repair_started", `Resuming ${context.dispatch.execution.provider} ${outputState.sessionLabel ?? "provider thread"} for bounded pre-publication repair ${nextRepairTurn}/${maxRepairTurns} after ${describeFailedChecks(failure.checkIds)} failed.`, { checkId: failure.checkId, checkIds: failure.checkIds, repairTurn: nextRepairTurn, maxRepairTurns }));
|
|
83
|
+
await dependencies.runRepairTurn({
|
|
84
|
+
prompt: buildPrePublicationRepairPrompt(failure, nextRepairTurn, maxRepairTurns, options.repairScope),
|
|
85
|
+
repairTurn: nextRepairTurn,
|
|
86
|
+
maxRepairTurns,
|
|
87
|
+
providerThreadId,
|
|
88
|
+
repairEnvironment: environments.repair,
|
|
89
|
+
environment: environments.provider,
|
|
90
|
+
failure,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The resumed command for one pre-publication repair turn. The main turn's Forge MCP server was
|
|
96
|
+
* cleaned up when that turn exited, so the repair turn gets its own: the managed-attempt tools its
|
|
97
|
+
* prompt directs long checks to, without the completion tools whose artifacts are already recorded.
|
|
98
|
+
* The caller owns the returned runtime and cleans it up when the turn exits.
|
|
99
|
+
*/
|
|
100
|
+
export async function prepareRepairTurnLaunch(context, turn) {
|
|
101
|
+
const { dispatch, worktree } = context;
|
|
102
|
+
const { prompt: focusedPrompt, repairEnvironment } = turn;
|
|
103
|
+
const repairDispatch = {
|
|
104
|
+
...dispatch,
|
|
105
|
+
session: { ...dispatch.session, resumeProviderThreadId: turn.providerThreadId },
|
|
106
|
+
};
|
|
107
|
+
const providerPrompt = buildProviderCliPrompt(repairDispatch, focusedPrompt, repairEnvironment);
|
|
108
|
+
const pipePromptToStdin = shouldPipePromptToStdin(repairDispatch.execution.provider, providerPrompt, usesManagedWindowsHost(repairDispatch));
|
|
109
|
+
const completionTools = await prepareCompletionToolRuntime({
|
|
110
|
+
dispatch: repairDispatch,
|
|
111
|
+
worktree,
|
|
112
|
+
runtimeEnvironment: repairEnvironment,
|
|
113
|
+
hostLoadEnvironment: context.hostLoadEnvironment,
|
|
114
|
+
managedToolsOnly: true,
|
|
115
|
+
});
|
|
116
|
+
const command = buildProviderCliCommand(repairDispatch, {
|
|
117
|
+
worktreePath: worktree.worktreePath,
|
|
118
|
+
prompt: focusedPrompt,
|
|
119
|
+
promptFromStdin: pipePromptToStdin,
|
|
120
|
+
completionTools,
|
|
121
|
+
runtimeEnvironment: repairEnvironment,
|
|
122
|
+
});
|
|
123
|
+
return { repairDispatch, providerPrompt, pipePromptToStdin, completionTools, command };
|
|
124
|
+
}
|
|
125
|
+
/** Restarts the runtime stack if needed, then validates; returns every failure of the pass, or null. */
|
|
126
|
+
async function runValidationPass(options, dependencies, environments, repairTurn) {
|
|
127
|
+
const { context, validationProfile, preparedHeadSha } = options;
|
|
128
|
+
let runtimeRestartFailure;
|
|
129
|
+
try {
|
|
130
|
+
const refreshed = await refreshPrePublicationRuntime(context, validationProfile, repairTurn);
|
|
131
|
+
if (refreshed)
|
|
132
|
+
await environments.refresh(refreshed);
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
if (!(error instanceof PrePublicationValidationError))
|
|
136
|
+
throw error;
|
|
137
|
+
// The pass still runs the checks that do not need the stack, so the repair turn sees them too.
|
|
138
|
+
runtimeRestartFailure = error;
|
|
139
|
+
await environments.withdrawRuntimeStack();
|
|
140
|
+
}
|
|
141
|
+
try {
|
|
142
|
+
await dependencies.validator.validate(context.worktree.worktreePath, validationProfile, publicationCapabilities(context, environments.repair), context.emit, context.signal, {
|
|
143
|
+
...prePublicationExecution(context, environments.validation, dependencies.defaultProcessRunner, preparedHeadSha),
|
|
144
|
+
runtimeRestartFailure,
|
|
145
|
+
});
|
|
146
|
+
// The validator reports the restart failure with its own; the restart failed either way.
|
|
147
|
+
return runtimeRestartFailure ?? null;
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
if (!(error instanceof PrePublicationValidationError))
|
|
151
|
+
throw error;
|
|
152
|
+
return runtimeRestartFailure && !error.checkIds.includes(runtimeRestartCheckId)
|
|
153
|
+
? new PrePublicationValidationError(runtimeRestartFailure.checkId, runtimeRestartFailure.exitCode, runtimeRestartFailure.command, runtimeRestartFailure.args, runtimeRestartFailure.detail, error.failures)
|
|
154
|
+
: error;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function describeFailedChecks(checkIds) {
|
|
158
|
+
const quoted = checkIds.map(checkId => `'${checkId}'`);
|
|
159
|
+
return quoted.length <= 1
|
|
160
|
+
? quoted.join("")
|
|
161
|
+
: `${quoted.slice(0, -1).join(", ")} and ${quoted.at(-1)}`;
|
|
162
|
+
}
|
|
163
|
+
function repairEvent(kind, eventType, content, data) {
|
|
164
|
+
return { role: "runner", kind, content, eventType, data: JSON.stringify(data) };
|
|
165
|
+
}
|
|
166
|
+
export function buildPrePublicationRepairPrompt(error, repairTurn, maxRepairTurns, repairScope) {
|
|
167
|
+
const { failures } = error;
|
|
168
|
+
const several = failures.length > 1;
|
|
169
|
+
const detailLimit = Math.min(repairPromptDetailCeiling, Math.max(repairPromptDetailFloor, Math.floor(repairPromptDetailBudget / failures.length)));
|
|
170
|
+
const priorWork = repairScope === "implementation"
|
|
171
|
+
? "Keep the completed implementation and its Forge-owned completion artifacts intact."
|
|
172
|
+
: "Keep the existing PR-comment or CI repairs intact.";
|
|
173
|
+
const sections = failures.map((failure, index) => [
|
|
174
|
+
several ? `Failed check ${index + 1}/${failures.length}: ${failure.checkId}` : `Failed check: ${failure.checkId}`,
|
|
175
|
+
`Command: ${[failure.command, ...failure.args].join(" ")}`,
|
|
176
|
+
`Exit code: ${failure.exitCode}`,
|
|
177
|
+
"Diagnostics:",
|
|
178
|
+
clip(failure.detail, detailLimit) || "The validation command returned no diagnostic output.",
|
|
179
|
+
].join("\n\n"));
|
|
180
|
+
return [
|
|
181
|
+
`Forge pre-publication validation failed after your ${repairScope === "implementation" ? "implementation" : "PR repair"} turn.`,
|
|
182
|
+
`This is bounded in-place repair turn ${repairTurn}/${maxRepairTurns}.`,
|
|
183
|
+
...(several
|
|
184
|
+
? [`${failures.length} checks failed in the same validation pass: ${error.checkIds.join(", ")}. Fix every one of them in this turn.`]
|
|
185
|
+
: []),
|
|
186
|
+
...sections,
|
|
187
|
+
several
|
|
188
|
+
? "Fix the root cause of each failed check in the current worktree and run each focused failing check."
|
|
189
|
+
: "Fix the root cause in the current worktree and run the focused failing check.",
|
|
190
|
+
`${priorWork} Do not commit, push, rebase, or modify Forge-owned protocol artifacts.`,
|
|
191
|
+
`When the focused check${several ? "s pass" : " passes"}, stop; Bridge will rerun the complete required pre-publication profile and owns commit/push.`,
|
|
192
|
+
].join("\n\n");
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Restarts the attempt's runtime stack when the workspace changed since it was
|
|
196
|
+
* launched, before a validation pass runs against it. A build of the changed
|
|
197
|
+
* source that fails is a validation failure the bounded repair turn can fix.
|
|
198
|
+
*/
|
|
199
|
+
async function refreshPrePublicationRuntime(context, validationProfile, repairTurn) {
|
|
200
|
+
if (!context.refreshRuntimeEnvironment)
|
|
201
|
+
return null;
|
|
202
|
+
let refreshed;
|
|
203
|
+
try {
|
|
204
|
+
refreshed = await context.refreshRuntimeEnvironment(context.signal);
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
// A restart that fails to build, start or become ready reflects the changed source, which a
|
|
208
|
+
// bounded repair turn can fix; the next pass restarts again. Cancellation, a released lease
|
|
209
|
+
// and a changed runtime contract still end the attempt.
|
|
210
|
+
if (restartFailureForRepair(error)) {
|
|
211
|
+
throw new PrePublicationValidationError(runtimeRestartCheckId, 1, "forge-host-runtime-restart", [],
|
|
212
|
+
// The session's host_runtime_restart_started event records why it restarted.
|
|
213
|
+
`Forge restarted the attempt runtime stack before validation, and the restart failed: ${error.message}`);
|
|
214
|
+
}
|
|
215
|
+
throw error;
|
|
216
|
+
}
|
|
217
|
+
if (!refreshed)
|
|
218
|
+
return null;
|
|
219
|
+
const { environment: restarted, reason, changes } = refreshed;
|
|
220
|
+
const apiUrl = restarted.FORGE_E2E_API_URL ?? restarted.FORGE_API_URL ?? null;
|
|
221
|
+
const webUrl = restarted.FORGE_E2E_WEB_URL ?? restarted.FORGE_WEB_URL ?? restarted.FORGE_PLAYWRIGHT_BASE_URL ?? null;
|
|
222
|
+
await context.emit(repairEvent("checkpoint", "prepublication_runtime_restarted", `Restarted the attempt runtime stack before pre-publication validation because ${restartReasonText[reason]}; validation${repairTurn > 0 ? " and repair turns" : ""} now use${apiUrl ? ` API ${apiUrl}` : " the refreshed runtime URLs"}${webUrl ? ` and web ${webUrl}` : ""}.`, { reason, changes, validationProfile, repairTurn, apiUrl, webUrl }));
|
|
223
|
+
return restarted;
|
|
224
|
+
}
|
|
225
|
+
const restartReasonText = {
|
|
226
|
+
deferred_start: "its start was deferred until the restored work's re-apply conflicts were resolved",
|
|
227
|
+
previous_restart_incomplete: "the previous restart did not complete",
|
|
228
|
+
fingerprint_unavailable: "the workspace state could not be compared with the stack's",
|
|
229
|
+
workspace_changed: "the workspace changed since it was launched",
|
|
230
|
+
};
|
|
231
|
+
/** The environment with the runtime stack's URLs and ports withheld and the stack marked unavailable. */
|
|
232
|
+
function withoutRuntimeStack(environment, stackKeys) {
|
|
233
|
+
const remaining = { ...(environment ?? {}) };
|
|
234
|
+
for (const key of stackKeys)
|
|
235
|
+
delete remaining[key];
|
|
236
|
+
remaining.FORGE_RUNTIME_STACK = "unavailable";
|
|
237
|
+
return remaining;
|
|
238
|
+
}
|
|
239
|
+
const restartFailuresForRepair = new Set([
|
|
240
|
+
"host_runtime_project_start_failed",
|
|
241
|
+
"host_runtime_process_exited",
|
|
242
|
+
"host_runtime_listener_timeout",
|
|
243
|
+
"host_runtime_http_readiness_timeout",
|
|
244
|
+
"host_port_collision",
|
|
245
|
+
]);
|
|
246
|
+
function restartFailureForRepair(error) {
|
|
247
|
+
if (error instanceof ForgeFailureError)
|
|
248
|
+
return restartFailuresForRepair.has(error.failureCode);
|
|
249
|
+
// The port broker throws an untyped collision once its launch retries are exhausted.
|
|
250
|
+
return error instanceof HostPortCollisionError;
|
|
251
|
+
}
|
|
252
|
+
function publicationCapabilities(context, runtimeEnvironment) {
|
|
253
|
+
const capabilities = new Set();
|
|
254
|
+
const launchTarget = context.dispatch.qaBrowser?.launchTarget;
|
|
255
|
+
if (runtimeEnvironment?.FORGE_PLAYWRIGHT_CONFIG
|
|
256
|
+
|| launchTarget?.url
|
|
257
|
+
|| launchTarget?.command
|
|
258
|
+
|| launchTarget?.managed_runtime_port) {
|
|
259
|
+
capabilities.add("browser_launch");
|
|
260
|
+
}
|
|
261
|
+
return capabilities;
|
|
262
|
+
}
|
|
263
|
+
function prePublicationExecution(context, environment, defaultRunner, baselineRevision) {
|
|
264
|
+
const hostLoadOwner = {
|
|
265
|
+
dispatchAttemptId: context.dispatch.sandbox?.dispatchAttemptId ?? null,
|
|
266
|
+
priority: runtimeAdmissionPriority(context.dispatch),
|
|
267
|
+
};
|
|
268
|
+
// The branch the lane prompt tells the agent to merge; only a merge of it scopes the pass.
|
|
269
|
+
const targetBranch = dispatchTargetBranch(context.dispatch);
|
|
270
|
+
const common = { baselineRevision, targetBranch, environment, hostLoadOwner };
|
|
271
|
+
if (context.processRunner)
|
|
272
|
+
return { ...common, processRunner: context.processRunner };
|
|
273
|
+
if (context.dispatch.sandbox?.executionMode !== "docker")
|
|
274
|
+
return common;
|
|
275
|
+
const expectedSandboxId = context.dispatch.sandbox.dispatchAttemptId;
|
|
276
|
+
const observedSandboxId = context.runtimeEnvironment?.FORGE_SANDBOX_ID ?? process.env.FORGE_SANDBOX_ID;
|
|
277
|
+
if (observedSandboxId !== expectedSandboxId) {
|
|
278
|
+
throw new ForgeFailureError("prepublication_execution_scope_invalid", `prepublication_execution_scope_invalid: Docker attempt ${expectedSandboxId} has no runner proven to execute inside that sandbox.`, "bridge");
|
|
279
|
+
}
|
|
280
|
+
return { ...common, processRunner: defaultRunner };
|
|
281
|
+
}
|
|
@@ -4,6 +4,7 @@ export interface ProviderCliService {
|
|
|
4
4
|
runArchitect(context: ProviderCliRunContext): Promise<ProviderCliRunResult>;
|
|
5
5
|
runCiRepair(context: ProviderCliRunContext): Promise<ProviderCliRunResult>;
|
|
6
6
|
runConflictResolve(context: ProviderCliRunContext): Promise<ProviderCliRunResult>;
|
|
7
|
+
runPrReview(context: ProviderCliRunContext): Promise<ProviderCliRunResult>;
|
|
7
8
|
runQa(context: ProviderCliRunContext): Promise<ProviderCliRunResult>;
|
|
8
9
|
runDraft(context: ProviderCliDraftContext): Promise<ProviderCliRunResult>;
|
|
9
10
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface ProviderChildEnvironmentOptions {
|
|
2
|
+
readonly parentEnv?: NodeJS.ProcessEnv;
|
|
3
|
+
readonly platform?: NodeJS.Platform;
|
|
4
|
+
readonly homeDir?: string;
|
|
5
|
+
readonly arch?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function buildProviderChildEnvironment(requestEnv?: Readonly<Record<string, string>>, options?: ProviderChildEnvironmentOptions): NodeJS.ProcessEnv;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
import { normalizeWindowsProviderEnvironment, windowsAllowedProviderParentEnvNames } from "./provider-cli.windows-environment.js";
|
|
3
|
+
// The environment a provider child process starts with: an allowlist of the Bridge's own
|
|
4
|
+
// variables, the request's values, the Windows defaults, then the .NET build-server settings.
|
|
5
|
+
// CLAUDE_CONFIG_DIR is not passed: it would point Claude Code at a user configuration directory
|
|
6
|
+
// of the host's choosing (provider-user-config-isolation.ts). Claude signs in from the provider
|
|
7
|
+
// home's default `.claude` directory under HOME or USERPROFILE, or with a Forge-granted API key.
|
|
8
|
+
const allowedProviderParentEnvNames = [
|
|
9
|
+
"PATH",
|
|
10
|
+
"HOME",
|
|
11
|
+
"USERPROFILE",
|
|
12
|
+
"TMPDIR",
|
|
13
|
+
"TEMP",
|
|
14
|
+
"TMP",
|
|
15
|
+
"LANG"
|
|
16
|
+
];
|
|
17
|
+
export function buildProviderChildEnvironment(requestEnv, options = {}) {
|
|
18
|
+
const parentEnv = options.parentEnv ?? process.env;
|
|
19
|
+
const platform = options.platform ?? process.platform;
|
|
20
|
+
const env = {};
|
|
21
|
+
for (const [key, value] of Object.entries(parentEnv)) {
|
|
22
|
+
if (typeof value === "string" && isAllowedProviderParentEnv(key, platform)) {
|
|
23
|
+
env[key] = value;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (requestEnv) {
|
|
27
|
+
for (const [key, value] of Object.entries(requestEnv)) {
|
|
28
|
+
const trimmedKey = key.trim();
|
|
29
|
+
if (trimmedKey.length > 0) {
|
|
30
|
+
env[trimmedKey] = value;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (platform === "win32") {
|
|
35
|
+
normalizeWindowsProviderEnvironment(env, parentEnv, options.homeDir ?? os.homedir(), options.arch ?? os.arch());
|
|
36
|
+
}
|
|
37
|
+
normalizeProviderBuildEnvironment(env);
|
|
38
|
+
return env;
|
|
39
|
+
}
|
|
40
|
+
function normalizeProviderBuildEnvironment(env) {
|
|
41
|
+
// Provider sessions are long lived and commonly run many dotnet builds. Persistent
|
|
42
|
+
// MSBuild and Roslyn compiler servers otherwise survive individual commands and can
|
|
43
|
+
// retain more memory than the active Forge lane. Keep those caches process-scoped by
|
|
44
|
+
// default on every runner OS; an explicitly supplied request value still wins.
|
|
45
|
+
setCanonicalProviderBuildEnvironmentValue(env, "DOTNET_CLI_USE_MSBUILD_SERVER", "0");
|
|
46
|
+
setCanonicalProviderBuildEnvironmentValue(env, "MSBUILDDISABLENODEREUSE", "1");
|
|
47
|
+
setCanonicalProviderBuildEnvironmentValue(env, "UseSharedCompilation", "false");
|
|
48
|
+
}
|
|
49
|
+
function setCanonicalProviderBuildEnvironmentValue(env, name, value) {
|
|
50
|
+
// The dotnet CLI uses case-sensitive environment lookup on POSIX, while MSBuild
|
|
51
|
+
// property names are case-insensitive on every OS. Collapse request aliases to
|
|
52
|
+
// one canonical key so the explicit value wins without producing ambiguity.
|
|
53
|
+
const exact = env[name];
|
|
54
|
+
const alias = Object.entries(env).find(([key, candidate]) => key !== name
|
|
55
|
+
&& key.toLowerCase() === name.toLowerCase()
|
|
56
|
+
&& typeof candidate === "string"
|
|
57
|
+
&& candidate.trim().length > 0)?.[1];
|
|
58
|
+
const resolved = typeof exact === "string" && exact.trim().length > 0
|
|
59
|
+
? exact
|
|
60
|
+
: alias ?? value;
|
|
61
|
+
for (const key of Object.keys(env)) {
|
|
62
|
+
if (key !== name && key.toLowerCase() === name.toLowerCase()) {
|
|
63
|
+
delete env[key];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
env[name] = resolved;
|
|
67
|
+
}
|
|
68
|
+
function isAllowedProviderParentEnv(key, platform = process.platform) {
|
|
69
|
+
return isAllowedProviderParentEnvName(key, allowedProviderParentEnvNames)
|
|
70
|
+
|| key.toUpperCase().startsWith("LC_")
|
|
71
|
+
|| (platform === "win32" && isAllowedProviderParentEnvName(key, windowsAllowedProviderParentEnvNames));
|
|
72
|
+
}
|
|
73
|
+
function isAllowedProviderParentEnvName(key, allowedNames) {
|
|
74
|
+
return allowedNames.some((allowed) => allowed.toLowerCase() === key.toLowerCase());
|
|
75
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ProviderProcessRunResult } from "./provider-cli.process.js";
|
|
2
|
+
export declare function isCodexModelsCacheSchemaFailure(result: ProviderProcessRunResult): boolean;
|
|
3
|
+
export declare function quarantineIncompatibleCodexModelsCache(requestEnv?: Readonly<Record<string, string>>): Promise<boolean>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { readEnvironmentValue } from "./provider-cli.windows-environment.js";
|
|
6
|
+
const maximumRecoverableCodexModelsCacheBytes = 16 * 1024 * 1024;
|
|
7
|
+
export function isCodexModelsCacheSchemaFailure(result) {
|
|
8
|
+
const output = `${result.stderr}\n${result.stdout}`.toLowerCase();
|
|
9
|
+
return output.includes("base_instructions")
|
|
10
|
+
&& output.includes("missing field")
|
|
11
|
+
&& (output.includes("models_cache") || output.includes("models cache") || output.includes("model cache"));
|
|
12
|
+
}
|
|
13
|
+
export async function quarantineIncompatibleCodexModelsCache(requestEnv) {
|
|
14
|
+
const configuredHome = readEnvironmentValue(requestEnv ?? {}, "CODEX_HOME")
|
|
15
|
+
?? readEnvironmentValue(process.env, "CODEX_HOME")
|
|
16
|
+
?? readEnvironmentValue(process.env, "FORGE_CODEX_HOME");
|
|
17
|
+
const codexHome = path.resolve(configuredHome ?? path.join(os.homedir(), ".codex"));
|
|
18
|
+
if (!path.isAbsolute(codexHome) || codexHome === path.parse(codexHome).root)
|
|
19
|
+
return false;
|
|
20
|
+
const cachePath = path.join(codexHome, "models_cache.json");
|
|
21
|
+
const cacheStat = await fs.promises.lstat(cachePath).catch(error => {
|
|
22
|
+
if (error.code === "ENOENT")
|
|
23
|
+
return null;
|
|
24
|
+
throw error;
|
|
25
|
+
});
|
|
26
|
+
if (!cacheStat
|
|
27
|
+
|| !cacheStat.isFile()
|
|
28
|
+
|| cacheStat.isSymbolicLink()
|
|
29
|
+
|| cacheStat.nlink !== 1
|
|
30
|
+
|| cacheStat.size <= 0
|
|
31
|
+
|| cacheStat.size > maximumRecoverableCodexModelsCacheBytes) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
const quarantinePath = path.join(codexHome, `models_cache.forge-incompatible-${Date.now()}-${randomUUID()}.json`);
|
|
35
|
+
await fs.promises.rename(cachePath, quarantinePath);
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
@@ -10,5 +10,6 @@ export declare class DeterministicProviderCliService implements ProviderCliServi
|
|
|
10
10
|
runQa(context: ProviderCliRunContext): Promise<ProviderCliRunResult>;
|
|
11
11
|
runCiRepair(context: ProviderCliRunContext): Promise<ProviderCliRunResult>;
|
|
12
12
|
runConflictResolve(context: ProviderCliRunContext): Promise<ProviderCliRunResult>;
|
|
13
|
+
runPrReview(_context: ProviderCliRunContext): Promise<ProviderCliRunResult>;
|
|
13
14
|
private runPullRequestRepair;
|
|
14
15
|
}
|
|
@@ -3,6 +3,7 @@ import path from "node:path";
|
|
|
3
3
|
import { GitClient } from "../../shared/git/git.js";
|
|
4
4
|
import { buildSpecBody, selectLaneCommand } from "../../worktree/artifact-injector.js";
|
|
5
5
|
import { completionPhaseFromDispatch, debugCompletionPhaseOrder, expectedCompletionToolName, expectedDebugCompletionToolName, expectedQaCompletionToolName, qaCompletionGateOrder, readCompletionArtifact, usesDebugCycleCompletion, usesDevelopCycleCompletion, writeCompletionArtifact } from "../phase-completion.js";
|
|
6
|
+
import { ForgeFailureError } from "../session.types.js";
|
|
6
7
|
import { commitWorktreeChanges, emitArchitectStructuredEvents, emitCompletionArtifactRecorded, emitQaArtifactRecorded, emitQaGateAccepted, emitQaStructuredEvents, isDebugCompletionPhaseForProvider, nextQaGate, phaseCompleteEventType, qaArtifactRootForDispatch, readQaCompletionArtifactBundle, readQaGateArtifact } from "./provider-cli.artifacts.js";
|
|
7
8
|
import { deterministicBrowserCheck, deterministicBrowserSidecar, hasLaunchTarget, writeQaSidecarFiles } from "./provider-cli.qa-sidecars.js";
|
|
8
9
|
import { buildProviderCliCommand, formatProviderCliCommand, isPullRequestCheckRepairDispatch, isPullRequestCommentsDispatch, singleLine } from "./provider-cli.prompts.js";
|
|
@@ -210,6 +211,10 @@ export class DeterministicProviderCliService {
|
|
|
210
211
|
async runConflictResolve(context) {
|
|
211
212
|
return await this.runPullRequestRepair(context, "conflict_resolve");
|
|
212
213
|
}
|
|
214
|
+
async runPrReview(_context) {
|
|
215
|
+
// The review lane never falls back to the deterministic implementation worker.
|
|
216
|
+
throw new ForgeFailureError("pr_review_unsupported_worker", "pr_review_unsupported_worker: the deterministic fake worker cannot perform a pull request review.", "bridge");
|
|
217
|
+
}
|
|
213
218
|
async runPullRequestRepair(context, route) {
|
|
214
219
|
const { dispatch, worktree } = context;
|
|
215
220
|
await assertRepairHeadEpoch(context, this.git);
|
|
@@ -57,17 +57,20 @@ export declare class MergeResolutionUnresolvedConflictError extends ForgeFailure
|
|
|
57
57
|
export declare function isMergeInProgress(git: GitRunner, worktreePath: string): Promise<boolean>;
|
|
58
58
|
export declare function readInProgressMerge(git: GitRunner, worktreePath: string): Promise<InProgressMerge | null>;
|
|
59
59
|
/**
|
|
60
|
-
* Fails before `git add -A` can silently resolve a conflict
|
|
60
|
+
* Fails before `git add -A` can silently resolve a conflict, during a merge or whenever the index
|
|
61
|
+
* holds unmerged paths without one (a WIP snapshot re-applied across a branch move that conflicted,
|
|
62
|
+
* see wip-restore.ts):
|
|
61
63
|
* - a modify/delete conflict, by keeping whatever is on disk;
|
|
62
64
|
* - a binary (or other marker-less) conflict, by staging whichever side is on disk;
|
|
63
65
|
* - a content conflict, by staging its conflict markers. This includes markers
|
|
64
66
|
* the provider already staged, which clears the unmerged stages, so every path
|
|
65
|
-
* both sides changed is checked too
|
|
67
|
+
* both sides of the merge changed is checked too, or without a merge every path
|
|
68
|
+
* the worktree's WIP re-apply conflict record lists.
|
|
66
69
|
* A text conflict the agent resolved in the working tree without `git add` is
|
|
67
70
|
* still unmerged here and is accepted once its markers are gone.
|
|
68
71
|
*/
|
|
69
72
|
export declare function assertNoUnresolvedMergeConflicts(git: GitRunner, worktreePath: string): Promise<void>;
|
|
70
|
-
export declare function readUnresolvedMergeConflicts(git: GitRunner, worktreePath: string, merge: InProgressMerge): Promise<readonly UnresolvedMergeConflict[]>;
|
|
73
|
+
export declare function readUnresolvedMergeConflicts(git: GitRunner, worktreePath: string, merge: InProgressMerge | null): Promise<readonly UnresolvedMergeConflict[]>;
|
|
71
74
|
/**
|
|
72
75
|
* Staging excludes some worktree changes (Forge runtime output) by unstaging them
|
|
73
76
|
* back to HEAD. During a merge HEAD is the story side, so an excluded path the merge
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { hasConflictMarkerLines, parseReapplyConflictRecord, wipReapplyConflictRecordName } from "../../worktree/wip-refs.js";
|
|
3
4
|
import { ForgeFailureError } from "../session.types.js";
|
|
4
5
|
const maxListedPaths = 20;
|
|
5
6
|
const pathArgumentChunkSize = 100;
|
|
@@ -61,19 +62,20 @@ export async function readInProgressMerge(git, worktreePath) {
|
|
|
61
62
|
return { headSha, mergeHeadSha, mergeBaseSha };
|
|
62
63
|
}
|
|
63
64
|
/**
|
|
64
|
-
* Fails before `git add -A` can silently resolve a conflict
|
|
65
|
+
* Fails before `git add -A` can silently resolve a conflict, during a merge or whenever the index
|
|
66
|
+
* holds unmerged paths without one (a WIP snapshot re-applied across a branch move that conflicted,
|
|
67
|
+
* see wip-restore.ts):
|
|
65
68
|
* - a modify/delete conflict, by keeping whatever is on disk;
|
|
66
69
|
* - a binary (or other marker-less) conflict, by staging whichever side is on disk;
|
|
67
70
|
* - a content conflict, by staging its conflict markers. This includes markers
|
|
68
71
|
* the provider already staged, which clears the unmerged stages, so every path
|
|
69
|
-
* both sides changed is checked too
|
|
72
|
+
* both sides of the merge changed is checked too, or without a merge every path
|
|
73
|
+
* the worktree's WIP re-apply conflict record lists.
|
|
70
74
|
* A text conflict the agent resolved in the working tree without `git add` is
|
|
71
75
|
* still unmerged here and is accepted once its markers are gone.
|
|
72
76
|
*/
|
|
73
77
|
export async function assertNoUnresolvedMergeConflicts(git, worktreePath) {
|
|
74
78
|
const merge = await readInProgressMerge(git, worktreePath);
|
|
75
|
-
if (!merge)
|
|
76
|
-
return;
|
|
77
79
|
const conflicts = await readUnresolvedMergeConflicts(git, worktreePath, merge);
|
|
78
80
|
if (conflicts.length > 0) {
|
|
79
81
|
throw new MergeResolutionUnresolvedConflictError(conflicts);
|
|
@@ -117,16 +119,34 @@ export async function readUnresolvedMergeConflicts(git, worktreePath, merge) {
|
|
|
117
119
|
else if (hasConflictMarkers(content))
|
|
118
120
|
conflicts.push({ path: filePath, kind: "conflict_markers" });
|
|
119
121
|
}
|
|
122
|
+
const unmergedPaths = new Set(stagesByPath.keys());
|
|
123
|
+
conflicts.push(...await markerConflicts(worktreePath, unmergedPaths, merge
|
|
124
|
+
? await bothChangedPaths(git, worktreePath, merge)
|
|
125
|
+
: await reapplyConflictPaths(git, worktreePath)));
|
|
126
|
+
return conflicts.sort((left, right) => left.path.localeCompare(right.path));
|
|
127
|
+
}
|
|
128
|
+
/** Paths both sides of the merge changed. */
|
|
129
|
+
async function bothChangedPaths(git, worktreePath, merge) {
|
|
120
130
|
const storyChanged = new Set(await diffNames(git, worktreePath, [merge.mergeBaseSha, merge.headSha]));
|
|
121
|
-
|
|
122
|
-
.filter(filePath => storyChanged.has(filePath)
|
|
123
|
-
|
|
131
|
+
return (await diffNames(git, worktreePath, [merge.mergeBaseSha, merge.mergeHeadSha]))
|
|
132
|
+
.filter(filePath => storyChanged.has(filePath));
|
|
133
|
+
}
|
|
134
|
+
/** Paths a WIP re-apply left conflicted, from the worktree's record (wip-refs.ts); [] without one. */
|
|
135
|
+
async function reapplyConflictPaths(git, worktreePath) {
|
|
136
|
+
const raw = (await git.run(worktreePath, ["rev-parse", "--git-path", wipReapplyConflictRecordName])).trim();
|
|
137
|
+
const record = path.isAbsolute(raw) ? raw : path.resolve(worktreePath, raw);
|
|
138
|
+
return parseReapplyConflictRecord(await fs.readFile(record, "utf8").catch(() => null));
|
|
139
|
+
}
|
|
140
|
+
/** Candidate conflict paths whose markers the provider already staged (no unmerged stages left). */
|
|
141
|
+
async function markerConflicts(worktreePath, unmergedPaths, candidates) {
|
|
142
|
+
const conflicts = [];
|
|
143
|
+
for (const filePath of candidates.filter(candidate => !unmergedPaths.has(candidate))) {
|
|
124
144
|
const content = await readWorkingFile(worktreePath, filePath);
|
|
125
145
|
if (content && !isBinary(content) && hasConflictMarkers(content)) {
|
|
126
146
|
conflicts.push({ path: filePath, kind: "conflict_markers" });
|
|
127
147
|
}
|
|
128
148
|
}
|
|
129
|
-
return conflicts
|
|
149
|
+
return conflicts;
|
|
130
150
|
}
|
|
131
151
|
/**
|
|
132
152
|
* Staging excludes some worktree changes (Forge runtime output) by unstaging them
|
|
@@ -265,9 +285,8 @@ function chunks(paths) {
|
|
|
265
285
|
}
|
|
266
286
|
return result;
|
|
267
287
|
}
|
|
268
|
-
const conflictMarkerPattern = /^<{7}(?: |$)[\s\S]*^>{7}(?: |$)/mu;
|
|
269
288
|
function hasConflictMarkers(content) {
|
|
270
|
-
return
|
|
289
|
+
return hasConflictMarkerLines(content.toString("utf8"));
|
|
271
290
|
}
|
|
272
291
|
/**
|
|
273
292
|
* Paths whose effective `merge` attribute selects Git's binary merge driver, which
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { GitClient } from "../../shared/git/git.js";
|
|
2
|
+
import type { ProviderCliRunContext, ProviderCliRunResult } from "./provider-cli.types.js";
|
|
3
|
+
import { type ProviderProcessRunner } from "./provider-cli.process.js";
|
|
4
|
+
/** What a review-only session needs from the provider CLI service that hosts it. */
|
|
5
|
+
export interface PrReviewRunServices {
|
|
6
|
+
readonly git: GitClient;
|
|
7
|
+
readonly processRunner: ProviderProcessRunner;
|
|
8
|
+
readonly providerToolHeartbeatIntervalMs: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A review session is read-only and publish-free only where the provider launch itself enforces it:
|
|
12
|
+
* Claude (tool deny rules, any platform) and Codex (POSIX only, because the Windows launch has no git/gh
|
|
13
|
+
* shim; its read-only sandbox on a host, the container in Docker: codexReviewSandboxMode). Every other provider or
|
|
14
|
+
* platform fails closed before anything starts.
|
|
15
|
+
*/
|
|
16
|
+
export declare function assertPrReviewProviderSupported(provider: string, platform?: NodeJS.Platform): void;
|
|
17
|
+
/**
|
|
18
|
+
* Review-only session for a pull request head. Never routed through implementation: the worktree
|
|
19
|
+
* is detached at the dispatched head, the provider cannot change or publish anything, and the
|
|
20
|
+
* review is handed to Forge only through the completion tool. No commit, push or GitHub call
|
|
21
|
+
* is made here; a worktree that differs after the session fails with `guardrail_violation`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function runPrReviewSession(services: PrReviewRunServices, runContext: ProviderCliRunContext): Promise<ProviderCliRunResult>;
|