@loucompanion/forge-bridge 0.1.3-dev.fbe15023cdfe → 0.1.4-dev.0098fdb4e213
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +232 -5
- package/dist/bridge/bridge-chat-provider-command.d.ts +19 -0
- package/dist/bridge/bridge-chat-provider-command.js +132 -0
- package/dist/bridge/bridge-chat.types.d.ts +121 -0
- package/dist/bridge/bridge-chat.types.js +416 -0
- 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 +11 -0
- package/dist/bridge/bridge-state-io.js +50 -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 +13 -1
- package/dist/bridge/bridge.service.d.ts +169 -14
- package/dist/bridge/bridge.service.js +1868 -330
- package/dist/bridge/bridge.types.d.ts +73 -1
- package/dist/bridge/dispatch-result-outbox.d.ts +35 -0
- package/dist/bridge/dispatch-result-outbox.js +87 -0
- package/dist/bridge/dispatch-result-worker.d.ts +2 -0
- package/dist/bridge/dispatch-result-worker.js +122 -0
- package/dist/bridge/in-flight-registry.d.ts +62 -0
- package/dist/bridge/in-flight-registry.js +207 -0
- package/dist/bridge/internals.d.ts +2 -0
- package/dist/bridge/internals.js +1 -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 +25 -0
- package/dist/bridge/readiness-result-outbox.js +74 -0
- package/dist/bridge/readiness-result-worker.d.ts +2 -0
- package/dist/bridge/readiness-result-worker.js +121 -0
- package/dist/bridge/runner-host-capabilities.d.ts +20 -0
- package/dist/bridge/runner-host-capabilities.js +110 -0
- 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/cleanup/cleanup-wip.d.ts +12 -0
- package/dist/cleanup/cleanup-wip.js +66 -0
- package/dist/cleanup/cleanup.service.d.ts +21 -1
- package/dist/cleanup/cleanup.service.js +185 -143
- package/dist/cleanup/cleanup.types.d.ts +6 -0
- package/dist/cleanup/forge-owned-paths.d.ts +9 -0
- package/dist/cleanup/forge-owned-paths.js +53 -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 +78 -16
- package/dist/cli/cli.service.d.ts +32 -15
- package/dist/cli/cli.service.js +206 -182
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +7 -0
- package/dist/cli/local-config.js +36 -4
- 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 +41 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +474 -0
- package/dist/runtime/attempt-database-broker.d.ts +89 -0
- package/dist/runtime/attempt-database-broker.js +390 -0
- package/dist/runtime/attempt-node-runtime-launcher.d.ts +2 -1
- package/dist/runtime/attempt-node-runtime-launcher.js +57 -18
- package/dist/runtime/attempt-path-operation.d.ts +21 -0
- package/dist/runtime/attempt-path-operation.js +94 -0
- package/dist/runtime/attempt-private-directory.d.ts +6 -0
- package/dist/runtime/attempt-private-directory.js +54 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +35 -0
- package/dist/runtime/attempt-process-supervisor.js +144 -23
- package/dist/runtime/canonical-source-file.d.ts +3 -0
- package/dist/runtime/canonical-source-file.js +54 -0
- package/dist/runtime/docker-engine-probe.d.ts +95 -0
- package/dist/runtime/docker-engine-probe.js +340 -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/generated-output-reset.d.ts +10 -0
- package/dist/runtime/generated-output-reset.js +62 -8
- package/dist/runtime/host-database-capability-boundary.d.ts +16 -0
- package/dist/runtime/host-database-capability-boundary.js +63 -0
- package/dist/runtime/host-diagnostics.d.ts +11 -0
- package/dist/runtime/host-diagnostics.js +192 -0
- package/dist/runtime/host-execution-root.d.ts +4 -0
- package/dist/runtime/host-execution-root.js +39 -0
- package/dist/runtime/host-facts.d.ts +36 -0
- package/dist/runtime/host-facts.js +95 -0
- package/dist/runtime/host-listener-inspector.d.ts +8 -1
- package/dist/runtime/host-listener-inspector.js +121 -60
- package/dist/runtime/host-load-admission.d.ts +67 -0
- package/dist/runtime/host-load-admission.js +99 -0
- package/dist/runtime/host-load-child-environment.d.ts +27 -0
- package/dist/runtime/host-load-child-environment.js +76 -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 +52 -0
- package/dist/runtime/host-load-governor-config.js +83 -0
- package/dist/runtime/host-load-governor.d.ts +186 -0
- package/dist/runtime/host-load-governor.js +632 -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-runtime-settings.d.ts +25 -0
- package/dist/runtime/host-load-runtime-settings.js +80 -0
- package/dist/runtime/host-load-sampler.d.ts +156 -0
- package/dist/runtime/host-load-sampler.js +298 -0
- 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 +73 -0
- package/dist/runtime/host-load-step-run.js +102 -0
- package/dist/runtime/host-load-test-slot.d.ts +43 -0
- package/dist/runtime/host-load-test-slot.js +81 -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 +61 -0
- package/dist/runtime/host-pressure-stall.js +168 -0
- package/dist/runtime/host-runtime-contract.d.ts +28 -1
- package/dist/runtime/host-runtime-contract.js +203 -57
- package/dist/runtime/host-runtime-lease.d.ts +163 -9
- package/dist/runtime/host-runtime-lease.js +1427 -124
- package/dist/runtime/host-runtime-promotion.d.ts +35 -3
- package/dist/runtime/host-runtime-promotion.js +107 -12
- 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.d.ts +62 -0
- package/dist/runtime/managed-command-teardown.js +596 -0
- package/dist/runtime/memory-capacity.d.ts +70 -0
- package/dist/runtime/memory-capacity.js +123 -0
- package/dist/runtime/native-test-postgres-fallback.d.ts +69 -0
- package/dist/runtime/native-test-postgres-fallback.js +143 -0
- package/dist/runtime/node-host-runtime-adapter.d.ts +3 -0
- package/dist/runtime/node-host-runtime-adapter.js +29 -11
- package/dist/runtime/pinned-directory-process.d.ts +9 -0
- package/dist/runtime/pinned-directory-process.js +61 -0
- package/dist/runtime/pinned-source-directory.d.ts +17 -0
- package/dist/runtime/pinned-source-directory.js +94 -0
- package/dist/runtime/playwright-browser-cache.d.ts +39 -0
- package/dist/runtime/playwright-browser-cache.js +227 -0
- package/dist/runtime/playwright-host-runtime-adapter.d.ts +19 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +113 -59
- package/dist/runtime/prepared-runtime-identity.d.ts +6 -0
- package/dist/runtime/prepared-runtime-identity.js +218 -0
- package/dist/runtime/prepared-runtime-readiness.d.ts +30 -0
- package/dist/runtime/prepared-runtime-readiness.js +285 -0
- package/dist/runtime/runner-settings.d.ts +104 -0
- package/dist/runtime/runner-settings.js +236 -0
- package/dist/runtime/runtime-isolation-lease.js +4 -1
- package/dist/runtime/workspace-resource-estimator.d.ts +17 -0
- package/dist/runtime/workspace-resource-estimator.js +174 -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 +36 -0
- package/dist/sandbox/preflight.d.ts +31 -1
- package/dist/sandbox/preflight.js +237 -51
- package/dist/sandbox/provider-auth/codex.js +11 -11
- package/dist/sandbox/repository-lock.d.ts +2 -1
- package/dist/sandbox/repository-lock.js +19 -9
- package/dist/sandbox/runtime.d.ts +16 -2
- package/dist/sandbox/runtime.js +183 -114
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -0
- package/dist/sandbox/sandbox.types.d.ts +7 -0
- package/dist/sandbox/workspace.service.js +2 -0
- 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 +37 -1
- package/dist/session/managed-attempt-tools.js +822 -84
- package/dist/session/managed-build-coordinator.d.ts +5 -0
- package/dist/session/managed-build-coordinator.js +109 -0
- package/dist/session/managed-build-receipt.d.ts +26 -0
- package/dist/session/managed-build-receipt.js +342 -0
- package/dist/session/managed-command-host-load.d.ts +47 -0
- package/dist/session/managed-command-host-load.js +83 -0
- package/dist/session/managed-verification-timeouts.d.ts +8 -0
- package/dist/session/managed-verification-timeouts.js +17 -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.artifacts.d.ts +24 -0
- package/dist/session/phase-completion.artifacts.js +321 -45
- 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 +23 -1
- package/dist/session/phase-completion.helpers.d.ts +5 -0
- package/dist/session/phase-completion.helpers.js +43 -19
- package/dist/session/phase-completion.js +19 -3
- package/dist/session/phase-completion.mcp-args.d.ts +9 -0
- package/dist/session/phase-completion.mcp-args.js +156 -0
- package/dist/session/phase-completion.prompts.js +22 -18
- package/dist/session/phase-completion.runtime.d.ts +6 -10
- package/dist/session/phase-completion.runtime.js +214 -224
- 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 +250 -226
- package/dist/session/phase-completion.validation.d.ts +3 -3
- package/dist/session/phase-completion.validation.js +135 -89
- package/dist/session/pre-publication-host-load.d.ts +27 -0
- package/dist/session/pre-publication-host-load.js +111 -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 +23 -0
- package/dist/session/pre-publication-process.js +109 -0
- package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
- package/dist/session/pre-publication-skipped-tests.js +109 -0
- 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 +91 -0
- package/dist/session/pre-publication-validation.js +670 -0
- package/dist/session/provider-cli/bridge-cli.conformance-fixtures.d.ts +72 -0
- package/dist/session/provider-cli/bridge-cli.conformance-fixtures.js +462 -0
- package/dist/session/provider-cli/ci-repair-readiness.d.ts +8 -0
- package/dist/session/provider-cli/ci-repair-readiness.js +23 -3
- 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/host-build-lock.d.ts +18 -0
- package/dist/session/provider-cli/host-build-lock.js +30 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
- package/dist/session/provider-cli/pre-publication-repair.js +276 -0
- package/dist/session/provider-cli/provider-cli.artifacts.d.ts +6 -3
- package/dist/session/provider-cli/provider-cli.artifacts.js +62 -22
- 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.js +34 -2
- package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +85 -19
- package/dist/session/provider-cli/provider-cli.process.js +566 -283
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +15 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +211 -36
- package/dist/session/provider-cli/provider-cli.repair-epoch.d.ts +6 -0
- package/dist/session/provider-cli/provider-cli.repair-epoch.js +11 -0
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +22 -1
- package/dist/session/provider-cli/provider-cli.runtime.js +83 -4
- package/dist/session/provider-cli/provider-cli.service.d.ts +36 -5
- package/dist/session/provider-cli/provider-cli.service.js +818 -99
- package/dist/session/provider-cli/provider-cli.types.d.ts +32 -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 +10 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +92 -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 +18 -0
- package/dist/session/provider-cli/provider-output-state.js +376 -17
- package/dist/session/provider-cli/provider-usage.d.ts +9 -1
- package/dist/session/provider-cli/provider-usage.js +28 -5
- 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/publishable-worktree-changes.d.ts +54 -0
- package/dist/session/publishable-worktree-changes.js +193 -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 +257 -0
- package/dist/session/session-redaction.js +284 -9
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.service.d.ts +11 -2
- package/dist/session/session.service.js +301 -58
- package/dist/session/session.types.d.ts +150 -2
- package/dist/session/session.types.js +599 -7
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -0
- package/dist/session/unreferenced-exports.d.ts +12 -0
- package/dist/session/unreferenced-exports.js +59 -0
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -0
- package/dist/shared/format/format-bytes.d.ts +1 -0
- package/dist/shared/format/format-bytes.js +9 -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/git/git.js +2 -1
- package/dist/shared/path/path.d.ts +1 -0
- package/dist/shared/path/path.js +18 -0
- package/dist/shared/process/dotnet-toolchain.d.ts +17 -0
- package/dist/shared/process/dotnet-toolchain.js +307 -0
- package/dist/shared/process/host-process-recovery.d.ts +14 -3
- package/dist/shared/process/host-process-recovery.js +26 -5
- package/dist/shared/process/host-process-supervisor.d.ts +16 -1
- package/dist/shared/process/host-process-supervisor.js +124 -23
- 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 +69 -0
- package/dist/shared/process/process.js +223 -16
- 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 +3 -0
- package/dist/shared/provider-capabilities.js +92 -0
- package/dist/shared/redaction/redaction.d.ts +1 -0
- package/dist/shared/redaction/redaction.js +39 -3
- package/dist/shared/time/monotonic.d.ts +1 -0
- package/dist/shared/time/monotonic.js +8 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/dependency-warmer.d.ts +66 -9
- package/dist/worktree/dependency-warmer.js +609 -24
- package/dist/worktree/index.d.ts +1 -1
- package/dist/worktree/story-qa-reference-hydrator.d.ts +4 -0
- package/dist/worktree/story-qa-reference-hydrator.js +253 -0
- package/dist/worktree/wip-git.d.ts +33 -0
- package/dist/worktree/wip-git.js +122 -0
- package/dist/worktree/wip-refs.d.ts +62 -0
- package/dist/worktree/wip-refs.js +119 -0
- package/dist/worktree/wip-restore.d.ts +38 -0
- package/dist/worktree/wip-restore.js +190 -0
- package/dist/worktree/wip-snapshot.d.ts +50 -0
- package/dist/worktree/wip-snapshot.js +268 -0
- package/dist/worktree/worktree-wip-events.d.ts +18 -0
- package/dist/worktree/worktree-wip-events.js +98 -0
- package/dist/worktree/worktree-wip.d.ts +49 -0
- package/dist/worktree/worktree-wip.js +182 -0
- package/dist/worktree/worktree.base.d.ts +7 -1
- package/dist/worktree/worktree.service.d.ts +22 -2
- package/dist/worktree/worktree.service.js +302 -25
- package/dist/worktree/worktree.types.d.ts +36 -1
- package/package.json +8 -6
- package/runtime/windows-job-supervisor.ps1 +380 -14
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { constants as fsConstants } from "node:fs";
|
|
3
|
+
import fs from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { HostCapacityTimeoutError, } from "../runtime/host-load-governor.js";
|
|
6
|
+
import { defaultHostLoadGovernorConfig } from "../runtime/host-load-governor-config.js";
|
|
7
|
+
import { HostCapacityTokenFencedError } from "../runtime/host-load-token-ledger.js";
|
|
8
|
+
import { sandboxHostCapacityBrokerEnvironment, sandboxHostCapacityBrokerProtocol, sandboxHostCapacityLineType, sandboxHostCapacityMaxWaitEnvironment, sandboxHostCapacityResponseOwnerUid, sandboxHostCapacityResponseRoot, } from "../sandbox/host-capacity-broker.js";
|
|
9
|
+
import { monotonicNowMs } from "../shared/time/monotonic.js";
|
|
10
|
+
import { ForgeFailureError } from "./session.types.js";
|
|
11
|
+
/**
|
|
12
|
+
* Inside the Linux sandbox a reply is the bridge's when the trusted uid (root)
|
|
13
|
+
* owns it and no one else can write it: the sandbox user can create neither.
|
|
14
|
+
* Windows has no such proof in a file's stat (Node reports uid 0 for every file
|
|
15
|
+
* and derives the mode from the read-only attribute alone), so there no reply
|
|
16
|
+
* is ever trusted: the gate fails closed rather than read a read-only file as root's.
|
|
17
|
+
*/
|
|
18
|
+
export function posixReplyOwnership(trustedOwnerUid, platform = process.platform) {
|
|
19
|
+
return stat => {
|
|
20
|
+
if (platform === "win32")
|
|
21
|
+
return "file ownership cannot be proven on Windows";
|
|
22
|
+
if (stat.uid !== BigInt(trustedOwnerUid))
|
|
23
|
+
return `it is owned by uid ${stat.uid}, not the bridge`;
|
|
24
|
+
if ((stat.mode & 18n) !== 0n)
|
|
25
|
+
return "others can write it";
|
|
26
|
+
return null;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export class SandboxBrokeredHostLoadGate {
|
|
30
|
+
enabled = true;
|
|
31
|
+
write;
|
|
32
|
+
responseRoot;
|
|
33
|
+
pollMs;
|
|
34
|
+
replyOwnership;
|
|
35
|
+
maxWaitMs;
|
|
36
|
+
constructor(options = {}) {
|
|
37
|
+
this.write = options.write ?? (line => { process.stdout.write(line); });
|
|
38
|
+
this.responseRoot = options.responseRoot ?? sandboxHostCapacityResponseRoot;
|
|
39
|
+
this.pollMs = options.pollMs ?? 250;
|
|
40
|
+
this.replyOwnership = options.replyOwnership
|
|
41
|
+
?? posixReplyOwnership(options.trustedOwnerUid ?? sandboxHostCapacityResponseOwnerUid);
|
|
42
|
+
this.maxWaitMs = options.maxWaitMs ?? defaultHostLoadGovernorConfig.maxWaitMs + 2 * 60_000;
|
|
43
|
+
}
|
|
44
|
+
async acquire(request, options = {}) {
|
|
45
|
+
const requestId = randomUUID();
|
|
46
|
+
const responsePath = path.join(this.responseRoot, `${requestId}.json`);
|
|
47
|
+
const startedAtMs = monotonicNowMs();
|
|
48
|
+
this.send("acquire", requestId, request);
|
|
49
|
+
let waitingReported = false;
|
|
50
|
+
try {
|
|
51
|
+
while (true) {
|
|
52
|
+
if (options.signal?.aborted)
|
|
53
|
+
throw options.signal.reason ?? new Error("The host capacity wait was cancelled.");
|
|
54
|
+
const response = await readResponse(responsePath, requestId, this.replyOwnership);
|
|
55
|
+
if (response?.status === "waiting" && !waitingReported) {
|
|
56
|
+
waitingReported = true;
|
|
57
|
+
void Promise.resolve(options.onWaiting?.(decision(false, response))).catch(() => undefined);
|
|
58
|
+
}
|
|
59
|
+
if (response?.status === "admitted")
|
|
60
|
+
return this.admission(requestId, responsePath, request, response);
|
|
61
|
+
if (response?.status === "failed" || response?.status === "fenced")
|
|
62
|
+
throw responseError(request, response);
|
|
63
|
+
if (monotonicNowMs() - startedAtMs > this.maxWaitMs) {
|
|
64
|
+
throw new HostCapacityTimeoutError(request.stepClass, request.label, monotonicNowMs() - startedAtMs, "the host bridge did not answer the sandbox's host capacity request.");
|
|
65
|
+
}
|
|
66
|
+
await delay(this.pollMs);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
this.send("release", requestId, request);
|
|
71
|
+
await fs.rm(responsePath, { force: true }).catch(() => undefined);
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
admission(requestId, responsePath, request, response) {
|
|
76
|
+
const fenced = new AbortController();
|
|
77
|
+
// The bridge rewrites the response as "fenced" if it lost the token; the step then stops.
|
|
78
|
+
const watch = setInterval(() => {
|
|
79
|
+
void readResponse(responsePath, requestId, this.replyOwnership).then(current => {
|
|
80
|
+
if (current?.status === "fenced" && !fenced.signal.aborted) {
|
|
81
|
+
fenced.abort(new HostCapacityTokenFencedError(requestId, "renew"));
|
|
82
|
+
}
|
|
83
|
+
}, (error) => {
|
|
84
|
+
// A reply that is not the bridge's: the reservation can no longer be trusted.
|
|
85
|
+
if (!fenced.signal.aborted)
|
|
86
|
+
fenced.abort(error);
|
|
87
|
+
});
|
|
88
|
+
}, Math.max(this.pollMs, 1_000));
|
|
89
|
+
watch.unref?.();
|
|
90
|
+
let released = false;
|
|
91
|
+
let holding = false;
|
|
92
|
+
let retainTimer = null;
|
|
93
|
+
const giveBack = async () => {
|
|
94
|
+
if (released)
|
|
95
|
+
return;
|
|
96
|
+
released = true;
|
|
97
|
+
clearInterval(watch);
|
|
98
|
+
if (retainTimer)
|
|
99
|
+
clearInterval(retainTimer);
|
|
100
|
+
this.send("release", requestId, request);
|
|
101
|
+
await fs.rm(responsePath, { force: true }).catch(() => undefined);
|
|
102
|
+
};
|
|
103
|
+
return {
|
|
104
|
+
tokenId: requestId,
|
|
105
|
+
fencingToken: 0,
|
|
106
|
+
stepClass: request.stepClass,
|
|
107
|
+
waitMs: response.waitMs ?? 0,
|
|
108
|
+
decision: decision(true, response),
|
|
109
|
+
fenced: fenced.signal,
|
|
110
|
+
// The container's processes are stopped with the sandbox; nothing to record host-side.
|
|
111
|
+
attachProcess: async () => undefined,
|
|
112
|
+
release: async () => {
|
|
113
|
+
if (released || holding)
|
|
114
|
+
return;
|
|
115
|
+
await giveBack();
|
|
116
|
+
if (fenced.signal.aborted)
|
|
117
|
+
throw fenced.signal.reason;
|
|
118
|
+
},
|
|
119
|
+
// Part of the step's tree may still run in the container: the request stays
|
|
120
|
+
// outstanding, so the bridge keeps the host token, until the check proves it
|
|
121
|
+
// gone. Without a check it is kept until the container exits, which stops every
|
|
122
|
+
// process in it and makes the bridge return the token.
|
|
123
|
+
retainUntilStopped: (stillGone, reason) => {
|
|
124
|
+
if (released || holding)
|
|
125
|
+
return;
|
|
126
|
+
holding = true;
|
|
127
|
+
if (!fenced.signal.aborted)
|
|
128
|
+
fenced.abort(reason);
|
|
129
|
+
// The bridge marks the host token retained, so this attempt's next step does not wait for it.
|
|
130
|
+
this.send("retain", requestId, request);
|
|
131
|
+
if (!stillGone)
|
|
132
|
+
return;
|
|
133
|
+
let checking = false;
|
|
134
|
+
retainTimer = setInterval(() => {
|
|
135
|
+
if (checking)
|
|
136
|
+
return;
|
|
137
|
+
checking = true;
|
|
138
|
+
void stillGone()
|
|
139
|
+
.then(gone => gone ? giveBack() : undefined, () => undefined)
|
|
140
|
+
.finally(() => { checking = false; });
|
|
141
|
+
}, Math.max(this.pollMs, 1_000));
|
|
142
|
+
retainTimer.unref?.();
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
send(action, requestId, request) {
|
|
147
|
+
this.write(`${JSON.stringify({
|
|
148
|
+
type: sandboxHostCapacityLineType,
|
|
149
|
+
version: 1,
|
|
150
|
+
action,
|
|
151
|
+
requestId,
|
|
152
|
+
stepClass: request.stepClass,
|
|
153
|
+
label: request.label,
|
|
154
|
+
})}\n`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
let cachedGate = null;
|
|
158
|
+
/**
|
|
159
|
+
* The brokered gate when the host bridge enabled it for this sandbox. The
|
|
160
|
+
* variable is removed once read, so commands the sandbox runs never inherit it
|
|
161
|
+
* (a nested Forge process must not queue behind its parent's token).
|
|
162
|
+
*/
|
|
163
|
+
export function sandboxHostLoadGateFromEnvironment(environment = process.env) {
|
|
164
|
+
if (cachedGate !== null)
|
|
165
|
+
return cachedGate;
|
|
166
|
+
const protocol = environment[sandboxHostCapacityBrokerEnvironment];
|
|
167
|
+
const hostMaxWaitMs = Number(environment[sandboxHostCapacityMaxWaitEnvironment]);
|
|
168
|
+
delete environment[sandboxHostCapacityBrokerEnvironment];
|
|
169
|
+
delete environment[sandboxHostCapacityMaxWaitEnvironment];
|
|
170
|
+
cachedGate = environment.FORGE_RUNTIME_MODE === "docker" && protocol === sandboxHostCapacityBrokerProtocol
|
|
171
|
+
// The host's own maximum wait (the operator may have changed it) plus slack for the reply.
|
|
172
|
+
? new SandboxBrokeredHostLoadGate(Number.isFinite(hostMaxWaitMs) && hostMaxWaitMs > 0
|
|
173
|
+
? { maxWaitMs: hostMaxWaitMs + 2 * 60_000 }
|
|
174
|
+
: {})
|
|
175
|
+
: undefined;
|
|
176
|
+
return cachedGate;
|
|
177
|
+
}
|
|
178
|
+
/** Test support: forgets the cached gate. */
|
|
179
|
+
export function resetSandboxHostLoadGateForTesting() {
|
|
180
|
+
cachedGate = null;
|
|
181
|
+
}
|
|
182
|
+
function decision(admitted, response) {
|
|
183
|
+
return {
|
|
184
|
+
admitted,
|
|
185
|
+
reason: (response.reason ?? (admitted ? "admitted" : "cpu_budget")),
|
|
186
|
+
cpuBudgetCores: null,
|
|
187
|
+
memoryBudgetBytes: null,
|
|
188
|
+
reservedCpuCores: 0,
|
|
189
|
+
reservedMemoryBytes: 0,
|
|
190
|
+
detail: response.detail ?? (admitted ? "The host bridge admitted the step." : "The host is at capacity."),
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function responseError(request, response) {
|
|
194
|
+
const message = response.message ?? "The host bridge refused the sandbox's host capacity request.";
|
|
195
|
+
if (response.code === "host_capacity_timeout") {
|
|
196
|
+
return new HostCapacityTimeoutError(request.stepClass, request.label, response.waitMs ?? 0, message);
|
|
197
|
+
}
|
|
198
|
+
return new ForgeFailureError(response.code ?? "host_capacity_broker_failed", message, "bridge");
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* The bridge's reply, or null while there is none (or the one opened was just
|
|
202
|
+
* replaced by a newer reply). Only a regular file with a single link that the
|
|
203
|
+
* reply ownership rule proves the bridge's (in the sandbox: owned by the trusted
|
|
204
|
+
* uid and writable by no one else) is the bridge's: the sandbox user can create
|
|
205
|
+
* none of those (see host-capacity-broker.ts).
|
|
206
|
+
* Anything else fails closed with sandbox_host_capacity_reply_untrusted.
|
|
207
|
+
*/
|
|
208
|
+
async function readResponse(responsePath, requestId, replyOwnership) {
|
|
209
|
+
let handle;
|
|
210
|
+
try {
|
|
211
|
+
handle = await fs.open(responsePath, fsConstants.O_RDONLY | (fsConstants.O_NOFOLLOW ?? 0));
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
if (error.code === "ENOENT")
|
|
215
|
+
return null;
|
|
216
|
+
throw untrustedReply(responsePath, `it could not be opened safely (${error.code ?? "error"})`);
|
|
217
|
+
}
|
|
218
|
+
let content;
|
|
219
|
+
try {
|
|
220
|
+
const stat = await handle.stat({ bigint: true });
|
|
221
|
+
// No link left: the bridge renamed a newer reply over this one after it was opened
|
|
222
|
+
// (waiting -> admitted, admitted -> fenced). It is not a forgery, and nothing is read
|
|
223
|
+
// from it; the next poll opens the newer reply. Only the bridge can replace a reply,
|
|
224
|
+
// since the directory is root-owned and not writable by the sandbox user.
|
|
225
|
+
if (stat.isFile() && stat.nlink === 0n)
|
|
226
|
+
return null;
|
|
227
|
+
if (!stat.isFile() || stat.nlink !== 1n)
|
|
228
|
+
throw untrustedReply(responsePath, "it is not a regular file with a single link");
|
|
229
|
+
const notTheBridges = replyOwnership(stat);
|
|
230
|
+
if (notTheBridges !== null)
|
|
231
|
+
throw untrustedReply(responsePath, notTheBridges);
|
|
232
|
+
content = await handle.readFile("utf8");
|
|
233
|
+
}
|
|
234
|
+
finally {
|
|
235
|
+
await handle.close();
|
|
236
|
+
}
|
|
237
|
+
try {
|
|
238
|
+
const value = JSON.parse(content);
|
|
239
|
+
if (!value || typeof value.status !== "string")
|
|
240
|
+
return null;
|
|
241
|
+
if (value.requestId !== requestId)
|
|
242
|
+
throw untrustedReply(responsePath, "it answers another request");
|
|
243
|
+
return value;
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
if (error instanceof ForgeFailureError)
|
|
247
|
+
throw error;
|
|
248
|
+
// Mid-write is impossible (replies are renamed into place); treat garbage as no reply yet.
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
function untrustedReply(responsePath, reason) {
|
|
253
|
+
return new ForgeFailureError("sandbox_host_capacity_reply_untrusted", `sandbox_host_capacity_reply_untrusted: ${path.basename(responsePath)} was not written by the host bridge (${reason}); the step does not run on it.`, "sandbox");
|
|
254
|
+
}
|
|
255
|
+
async function delay(ms) {
|
|
256
|
+
await new Promise(resolve => setTimeout(resolve, ms));
|
|
257
|
+
}
|
|
@@ -1,23 +1,298 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { redactText, shouldRedactJsonProperty } from "../shared/redaction/redaction.js";
|
|
2
|
+
import { decodeJsonEscapesLeniently, decodeJsonStringToken, inspectJsonText, isJsonPunctuation, isJsonWhitespace, JsonShapeError, sidecarJsonShapeProblem, } from "./sidecar-json-shape.js";
|
|
3
|
+
import { ForgeFailureError } from "./session.types.js";
|
|
2
4
|
const integrityProtectedEventDataTypes = new Set(["sandbox_started"]);
|
|
5
|
+
const structuralSecretMessage = "runner result structural metadata contains protected secret material and cannot be redacted without changing protocol identity.";
|
|
6
|
+
const sidecarSecretMessage = "runner result sidecar contains protected secret material and cannot be redacted without invalidating integrity metadata.";
|
|
7
|
+
const artifactJsonMessage = "runner result artifact JSON is invalid or exceeds safe inspection limits; transport was rejected.";
|
|
8
|
+
const artifactJsonKeySecretMessage = "runner result artifact JSON property name contains protected secret material and cannot be redacted without changing protocol identity.";
|
|
9
|
+
const artifactJsonPrimitiveSecretMessage = "runner result artifact JSON primitive contains protected secret material and cannot be redacted without changing protocol identity.";
|
|
10
|
+
// Stable failure code for a sidecar that starts like JSON but does not parse (see sidecar-json-shape.ts).
|
|
11
|
+
const malformedSidecarFailureCode = "runner_result_sidecar_malformed";
|
|
3
12
|
export function redactRunnerDispatchEvent(event, exactSecrets = []) {
|
|
4
|
-
|
|
5
|
-
|
|
13
|
+
assertStructuralFieldsDoNotContainSecrets([
|
|
14
|
+
event.role,
|
|
15
|
+
event.kind,
|
|
16
|
+
event.eventType,
|
|
17
|
+
event.wait?.kind,
|
|
18
|
+
event.wait?.scope,
|
|
19
|
+
event.wait?.wakeCondition,
|
|
20
|
+
event.wait?.contractOrigin,
|
|
21
|
+
...(event.wait?.resourceKeys ?? []),
|
|
22
|
+
], exactSecrets);
|
|
23
|
+
if (event.data !== undefined
|
|
24
|
+
&& event.data !== null
|
|
25
|
+
&& integrityProtectedEventDataTypes.has(event.eventType)) {
|
|
26
|
+
// Integrity-protected data cannot be rewritten because the runtime lease repeats the
|
|
27
|
+
// dispatch fence. Check the complete serialized payload so current and future resource
|
|
28
|
+
// identity fields cannot carry pending secret material across this boundary.
|
|
29
|
+
assertSerializedJsonDoesNotContainSecrets(event.data, exactSecrets, structuralSecretMessage);
|
|
6
30
|
}
|
|
7
31
|
// sandbox_started data is runner-authored protocol metadata. Its runtime
|
|
8
32
|
// lease repeats the dispatch fence so the API can validate ownership. The
|
|
9
33
|
// transcript redactor treats any serialized `*Token` field as a secret and
|
|
10
34
|
// must not rewrite that identity before transport or result persistence.
|
|
11
|
-
const { data, ...transcript } = event;
|
|
12
35
|
return {
|
|
13
|
-
...
|
|
14
|
-
|
|
36
|
+
...event,
|
|
37
|
+
content: redactContent(event.content, exactSecrets),
|
|
38
|
+
...(event.wait === undefined
|
|
39
|
+
? {}
|
|
40
|
+
: { wait: event.wait === null ? null : redactWait(event.wait, exactSecrets) }),
|
|
41
|
+
...(event.data === undefined || event.data === null
|
|
42
|
+
? {}
|
|
43
|
+
: {
|
|
44
|
+
data: integrityProtectedEventDataTypes.has(event.eventType)
|
|
45
|
+
? event.data
|
|
46
|
+
: redactContent(event.data, exactSecrets),
|
|
47
|
+
}),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function redactWait(wait, exactSecrets) {
|
|
51
|
+
return {
|
|
52
|
+
...wait,
|
|
53
|
+
...(wait.blockerTitle === undefined || wait.blockerTitle === null
|
|
54
|
+
? {}
|
|
55
|
+
: { blockerTitle: redactContent(wait.blockerTitle, exactSecrets).slice(0, 500) }),
|
|
15
56
|
};
|
|
16
57
|
}
|
|
17
58
|
export function redactRunOnceResultPacket(result, exactSecrets = []) {
|
|
18
|
-
|
|
59
|
+
assertStructuralFieldsDoNotContainSecrets([result.resultCommitSha, result.publishedCommitSha], exactSecrets);
|
|
60
|
+
return {
|
|
61
|
+
...result,
|
|
62
|
+
summary: redactContent(result.summary, exactSecrets),
|
|
63
|
+
...(result.failure !== undefined
|
|
64
|
+
? { failure: result.failure === null ? null : redactFailure(result.failure, exactSecrets) }
|
|
65
|
+
: {}),
|
|
66
|
+
...(result.spec !== undefined
|
|
67
|
+
? { spec: result.spec === null ? null : redactSpec(result.spec, exactSecrets) }
|
|
68
|
+
: {}),
|
|
69
|
+
...(result.artifact !== undefined
|
|
70
|
+
? { artifact: result.artifact === null ? null : redactArtifact(result.artifact, exactSecrets) }
|
|
71
|
+
: {}),
|
|
72
|
+
...(result.artifacts !== undefined
|
|
73
|
+
? {
|
|
74
|
+
artifacts: result.artifacts === null
|
|
75
|
+
? null
|
|
76
|
+
: result.artifacts.map(item => redactArtifact(item, exactSecrets)),
|
|
77
|
+
}
|
|
78
|
+
: {}),
|
|
79
|
+
events: result.events.map(event => redactRunnerDispatchEvent(event, exactSecrets)),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function redactFailure(failure, exactSecrets) {
|
|
83
|
+
assertStructuralFieldsDoNotContainSecrets([failure.code, ...failure.causalChain.map(cause => cause.code)], exactSecrets);
|
|
84
|
+
return {
|
|
85
|
+
...failure,
|
|
86
|
+
message: redactContent(failure.message, exactSecrets),
|
|
87
|
+
causalChain: failure.causalChain.map(cause => ({
|
|
88
|
+
...cause,
|
|
89
|
+
message: redactContent(cause.message, exactSecrets),
|
|
90
|
+
})),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function redactSpec(spec, exactSecrets) {
|
|
94
|
+
assertStructuralFieldsDoNotContainSecrets([spec.repoPath, spec.path, spec.producedBy, spec.status], exactSecrets);
|
|
95
|
+
return { ...spec, body: redactContent(spec.body, exactSecrets) };
|
|
96
|
+
}
|
|
97
|
+
function redactArtifact(artifact, exactSecrets) {
|
|
98
|
+
assertStructuralFieldsDoNotContainSecrets([artifact.repoPath, artifact.path, artifact.producedBy, artifact.status, artifact.phase], exactSecrets);
|
|
99
|
+
assertSidecarsDoNotContainSecrets(artifact.sidecars, exactSecrets);
|
|
19
100
|
return {
|
|
20
|
-
...
|
|
21
|
-
|
|
101
|
+
...artifact,
|
|
102
|
+
verdictJson: redactArtifactJson(artifact.verdictJson, exactSecrets),
|
|
103
|
+
...(artifact.planJson === undefined || artifact.planJson === null
|
|
104
|
+
? {}
|
|
105
|
+
: { planJson: redactArtifactJson(artifact.planJson, exactSecrets) }),
|
|
106
|
+
...(artifact.evidenceJson === undefined || artifact.evidenceJson === null
|
|
107
|
+
? {}
|
|
108
|
+
: { evidenceJson: redactArtifactJson(artifact.evidenceJson, exactSecrets) }),
|
|
109
|
+
...(artifact.findingsJson === undefined || artifact.findingsJson === null
|
|
110
|
+
? {}
|
|
111
|
+
: { findingsJson: redactArtifactJson(artifact.findingsJson, exactSecrets) }),
|
|
112
|
+
...(artifact.implementationPlanJson === undefined || artifact.implementationPlanJson === null
|
|
113
|
+
? {}
|
|
114
|
+
: { implementationPlanJson: redactArtifactJson(artifact.implementationPlanJson, exactSecrets) }),
|
|
115
|
+
...(artifact.qaPlanJson === undefined || artifact.qaPlanJson === null
|
|
116
|
+
? {}
|
|
117
|
+
: { qaPlanJson: redactArtifactJson(artifact.qaPlanJson, exactSecrets) }),
|
|
118
|
+
report: redactContent(artifact.report, exactSecrets),
|
|
119
|
+
// These bytes already passed the QA path/hash/size checks. The generic
|
|
120
|
+
// redactor strips contentBase64 fields and must not corrupt the payload.
|
|
121
|
+
...(artifact.sidecars !== undefined ? { sidecars: artifact.sidecars } : {}),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function redactArtifactJson(value, exactSecrets) {
|
|
125
|
+
// Validate the original before redaction. Replacing an invalid value must never
|
|
126
|
+
// turn a malformed evidence bundle into an apparently valid QA artifact.
|
|
127
|
+
inspectJsonStringTokens(value, [], artifactJsonMessage);
|
|
128
|
+
const chunks = [];
|
|
129
|
+
let unchangedStart = 0;
|
|
130
|
+
let index = 0;
|
|
131
|
+
const replace = (start, end, replacement) => {
|
|
132
|
+
if (value.slice(start, end) === replacement)
|
|
133
|
+
return;
|
|
134
|
+
chunks.push(value.slice(unchangedStart, start), replacement);
|
|
135
|
+
unchangedStart = end;
|
|
22
136
|
};
|
|
137
|
+
while (index < value.length) {
|
|
138
|
+
if (value.charCodeAt(index) !== 0x22) {
|
|
139
|
+
const code = value.charCodeAt(index);
|
|
140
|
+
if (isJsonWhitespace(code) || isJsonPunctuation(code)) {
|
|
141
|
+
index += 1;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
const end = jsonValueEnd(value, index);
|
|
145
|
+
// Numeric credentials and other exact primitive matches are still secrets.
|
|
146
|
+
// Fail closed instead of silently changing evidence types to strings.
|
|
147
|
+
assertJsonStringDoesNotContainSecrets(value.slice(index, end), exactSecrets, artifactJsonPrimitiveSecretMessage);
|
|
148
|
+
index = end;
|
|
149
|
+
}
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
const token = decodeArtifactJsonStringToken(value, index);
|
|
153
|
+
const afterToken = skipJsonWhitespace(value, token.nextIndex);
|
|
154
|
+
if (value.charCodeAt(afterToken) === 0x3a) {
|
|
155
|
+
assertJsonStringDoesNotContainSecrets(token.decoded, exactSecrets, artifactJsonKeySecretMessage);
|
|
156
|
+
if (redactText(token.decoded, exactSecrets) !== token.decoded)
|
|
157
|
+
throw new Error(artifactJsonKeySecretMessage);
|
|
158
|
+
if (shouldRedactJsonProperty(token.decoded)) {
|
|
159
|
+
const valueStart = skipJsonWhitespace(value, afterToken + 1);
|
|
160
|
+
const valueEnd = jsonValueEnd(value, valueStart);
|
|
161
|
+
if (value[valueStart] !== '"'
|
|
162
|
+
|| decodeArtifactJsonStringToken(value, valueStart).decoded !== "[REDACTED]") {
|
|
163
|
+
replace(valueStart, valueEnd, '"[REDACTED]"');
|
|
164
|
+
}
|
|
165
|
+
index = valueEnd;
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
const redacted = redactText(token.decoded, exactSecrets);
|
|
171
|
+
if (redacted !== token.decoded)
|
|
172
|
+
replace(index, token.nextIndex, JSON.stringify(redacted));
|
|
173
|
+
}
|
|
174
|
+
index = token.nextIndex;
|
|
175
|
+
}
|
|
176
|
+
if (chunks.length === 0)
|
|
177
|
+
return value;
|
|
178
|
+
chunks.push(value.slice(unchangedStart));
|
|
179
|
+
const redacted = chunks.join("");
|
|
180
|
+
// Retain the same bounded contract even when a short exact secret expands into
|
|
181
|
+
// a longer redaction marker. No raw JSON regex or parse/stringify round-trip:
|
|
182
|
+
// untouched escapes, whitespace, duplicate properties and numeric text survive.
|
|
183
|
+
inspectJsonStringTokens(redacted, [], artifactJsonMessage);
|
|
184
|
+
return redacted;
|
|
185
|
+
}
|
|
186
|
+
function skipJsonWhitespace(value, start) {
|
|
187
|
+
let index = start;
|
|
188
|
+
while (index < value.length && isJsonWhitespace(value.charCodeAt(index)))
|
|
189
|
+
index += 1;
|
|
190
|
+
return index;
|
|
191
|
+
}
|
|
192
|
+
// Called only after bounded JSON validation. Locate a credential property's whole
|
|
193
|
+
// value (including objects/arrays) without decoding or rewriting adjacent data.
|
|
194
|
+
function jsonValueEnd(value, start) {
|
|
195
|
+
if (value.charCodeAt(start) === 0x22) {
|
|
196
|
+
return decodeArtifactJsonStringToken(value, start).nextIndex;
|
|
197
|
+
}
|
|
198
|
+
if (value[start] === "{" || value[start] === "[") {
|
|
199
|
+
let depth = 0;
|
|
200
|
+
for (let index = start; index < value.length; index += 1) {
|
|
201
|
+
if (value[index] === '"') {
|
|
202
|
+
index = decodeArtifactJsonStringToken(value, index).nextIndex - 1;
|
|
203
|
+
}
|
|
204
|
+
else if (value[index] === "{" || value[index] === "[") {
|
|
205
|
+
depth += 1;
|
|
206
|
+
}
|
|
207
|
+
else if (value[index] === "}" || value[index] === "]") {
|
|
208
|
+
depth -= 1;
|
|
209
|
+
if (depth === 0)
|
|
210
|
+
return index + 1;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
throw new Error(artifactJsonMessage);
|
|
214
|
+
}
|
|
215
|
+
let index = start;
|
|
216
|
+
while (index < value.length
|
|
217
|
+
&& !isJsonWhitespace(value.charCodeAt(index))
|
|
218
|
+
&& value[index] !== "," && value[index] !== "}" && value[index] !== "]")
|
|
219
|
+
index += 1;
|
|
220
|
+
return index;
|
|
221
|
+
}
|
|
222
|
+
function redactContent(value, exactSecrets) {
|
|
223
|
+
return typeof value === "string" ? redactText(value, exactSecrets) : value;
|
|
224
|
+
}
|
|
225
|
+
function assertStructuralFieldsDoNotContainSecrets(fields, exactSecrets) {
|
|
226
|
+
for (const field of fields) {
|
|
227
|
+
if (field === undefined || field === null)
|
|
228
|
+
continue;
|
|
229
|
+
for (const secret of exactSecrets) {
|
|
230
|
+
if (secret.length > 0 && field.includes(secret)) {
|
|
231
|
+
throw new Error(structuralSecretMessage);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
function assertSidecarsDoNotContainSecrets(sidecars, exactSecrets) {
|
|
237
|
+
if (!sidecars || exactSecrets.length === 0)
|
|
238
|
+
return;
|
|
239
|
+
for (const sidecar of sidecars) {
|
|
240
|
+
const decoded = Buffer.from(sidecar.contentBase64, "base64");
|
|
241
|
+
for (const secret of exactSecrets) {
|
|
242
|
+
if (secret.length === 0)
|
|
243
|
+
continue;
|
|
244
|
+
if (sidecar.path.includes(secret)
|
|
245
|
+
|| sidecar.contentBase64.includes(secret)
|
|
246
|
+
|| sidecar.contentHash.includes(secret)
|
|
247
|
+
|| decoded.indexOf(Buffer.from(secret, "utf8")) >= 0) {
|
|
248
|
+
throw new Error(sidecarSecretMessage);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
assertSidecarJsonShape(decoded, sidecar.path, exactSecrets);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
function assertSerializedJsonDoesNotContainSecrets(value, exactSecrets, errorMessage) {
|
|
255
|
+
if (exactSecrets.length === 0)
|
|
256
|
+
return;
|
|
257
|
+
assertJsonStringDoesNotContainSecrets(value, exactSecrets, errorMessage);
|
|
258
|
+
inspectJsonStringTokens(value, exactSecrets, errorMessage);
|
|
259
|
+
}
|
|
260
|
+
function assertSidecarJsonShape(content, path, exactSecrets) {
|
|
261
|
+
const problem = sidecarJsonShapeProblem(content, path, decoded => assertJsonStringDoesNotContainSecrets(decoded, exactSecrets, sidecarSecretMessage));
|
|
262
|
+
if (problem === null)
|
|
263
|
+
return;
|
|
264
|
+
// A malformed file cannot be read token by token, so decode its escapes leniently first: a
|
|
265
|
+
// secret hidden behind JSON escapes keeps the secret error instead of the malformed one.
|
|
266
|
+
assertJsonStringDoesNotContainSecrets(decodeJsonEscapesLeniently(content.toString("utf8")), exactSecrets, sidecarSecretMessage);
|
|
267
|
+
// Still fail closed: the bytes cannot be redacted, so the result is rejected either way. The
|
|
268
|
+
// distinct code and message say the file is malformed, not that a secret was found.
|
|
269
|
+
throw new ForgeFailureError(malformedSidecarFailureCode, `runner result sidecar ${path} looks like JSON but is not valid JSON (${problem}); `
|
|
270
|
+
+ "Forge rejects sidecars it cannot fully inspect, so the result was not accepted.");
|
|
271
|
+
}
|
|
272
|
+
function inspectJsonStringTokens(value, exactSecrets, errorMessage) {
|
|
273
|
+
try {
|
|
274
|
+
inspectJsonText(value, decoded => assertJsonStringDoesNotContainSecrets(decoded, exactSecrets, errorMessage));
|
|
275
|
+
}
|
|
276
|
+
catch (error) {
|
|
277
|
+
if (error instanceof JsonShapeError)
|
|
278
|
+
throw new Error(errorMessage, { cause: error });
|
|
279
|
+
throw error;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
function decodeArtifactJsonStringToken(value, openingQuoteIndex) {
|
|
283
|
+
try {
|
|
284
|
+
return decodeJsonStringToken(value, openingQuoteIndex);
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
if (error instanceof JsonShapeError)
|
|
288
|
+
throw new Error(artifactJsonMessage, { cause: error });
|
|
289
|
+
throw error;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
function assertJsonStringDoesNotContainSecrets(value, exactSecrets, errorMessage) {
|
|
293
|
+
for (const secret of exactSecrets) {
|
|
294
|
+
if (secret.length > 0 && value.includes(secret)) {
|
|
295
|
+
throw new Error(errorMessage);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
23
298
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { HostRequirementsCheck } from "../runtime/host-runtime-requirements-check.js";
|
|
1
2
|
import type { HostRuntimeReadinessProbeRequest, HostRuntimeReadinessProbeResult, RunOnceDispatchPacket, RunOnceResultPacket, RunnerDispatchEvent } from "./session.types.js";
|
|
2
|
-
import type {
|
|
3
|
+
import type { RunnerHostDefaults } from "../runtime/runner-settings.js";
|
|
4
|
+
import type { HostCapacityLimits, HostRuntimeCapacitySnapshot, HostRuntimeReapOptions, HostRuntimeReapReport } from "../runtime/host-runtime-lease.js";
|
|
3
5
|
export interface SessionEventSink {
|
|
4
6
|
emit(event: RunnerDispatchEvent): Promise<void>;
|
|
5
7
|
}
|
|
@@ -9,4 +11,10 @@ export interface SessionService {
|
|
|
9
11
|
reapHostRuntime?(options: HostRuntimeReapOptions): Promise<HostRuntimeReapReport | null>;
|
|
10
12
|
runtimeCapacity?(): HostRuntimeCapacitySnapshot | null;
|
|
11
13
|
probeHostRuntime?(request: HostRuntimeReadinessProbeRequest, signal?: AbortSignal): Promise<HostRuntimeReadinessProbeResult>;
|
|
14
|
+
/** Decision 0013: host attempts recheck the project's requirements before starting. */
|
|
15
|
+
setHostRequirementsCheck?(check: HostRequirementsCheck | null): void;
|
|
16
|
+
/** Decision 0014: the host's max attempts and memory reserve defaults; null without host attempts. */
|
|
17
|
+
runnerLimitDefaults?(): RunnerHostDefaults | null;
|
|
18
|
+
/** Decision 0014: applies the effective max attempts and memory reserve to host attempt admission. */
|
|
19
|
+
applyRunnerLimits?(limits: HostCapacityLimits): void | Promise<void>;
|
|
12
20
|
}
|
|
@@ -1,16 +1,25 @@
|
|
|
1
|
+
import type { HostRequirementsCheck } from "../runtime/host-runtime-requirements-check.js";
|
|
1
2
|
import type { ProviderCliService } from "./provider-cli/provider-cli.base.js";
|
|
2
3
|
import type { SessionEventSink, SessionService } from "./session.base.js";
|
|
3
4
|
import type { HostRuntimeReadinessProbeRequest, HostRuntimeReadinessProbeResult, RunOnceDispatchPacket, RunOnceResultPacket } from "./session.types.js";
|
|
4
5
|
import type { WorktreeService } from "../worktree/worktree.base.js";
|
|
5
|
-
import { type HostRuntimeCapacitySnapshot, type HostRuntimeLeaseRuntime, type HostRuntimeReapOptions, type HostRuntimeReapReport } from "../runtime/host-runtime-lease.js";
|
|
6
|
+
import { type HostCapacityLimits, type HostRuntimeCapacitySnapshot, type HostRuntimeLeaseRuntime, type HostRuntimeReapOptions, type HostRuntimeReapReport } from "../runtime/host-runtime-lease.js";
|
|
7
|
+
import type { RunnerHostDefaults } from "../runtime/runner-settings.js";
|
|
8
|
+
import { type WorkspaceRuntimeFingerprintReader } from "./workspace-runtime-fingerprint.js";
|
|
6
9
|
export declare class BridgeSessionService implements SessionService {
|
|
7
10
|
private readonly worktrees;
|
|
8
11
|
private readonly providerCli;
|
|
9
12
|
private readonly hostRuntime?;
|
|
10
|
-
|
|
13
|
+
private readonly workspaceFingerprint;
|
|
14
|
+
constructor(worktrees?: WorktreeService, providerCli?: ProviderCliService, hostRuntime?: HostRuntimeLeaseRuntime | undefined, workspaceFingerprint?: WorkspaceRuntimeFingerprintReader);
|
|
15
|
+
setHostRequirementsCheck(check: HostRequirementsCheck | null): void;
|
|
16
|
+
runnerLimitDefaults(): RunnerHostDefaults | null;
|
|
17
|
+
applyRunnerLimits(limits: HostCapacityLimits): void;
|
|
11
18
|
updateLease(dispatchAttemptId: string, fencingToken: string, expiresAt: string): Promise<void>;
|
|
12
19
|
reapHostRuntime(options: HostRuntimeReapOptions): Promise<HostRuntimeReapReport | null>;
|
|
13
20
|
runtimeCapacity(): HostRuntimeCapacitySnapshot | null;
|
|
14
21
|
probeHostRuntime(request: HostRuntimeReadinessProbeRequest, signal?: AbortSignal): Promise<HostRuntimeReadinessProbeResult>;
|
|
15
22
|
runOnce(dispatch: RunOnceDispatchPacket, sink: SessionEventSink, signal?: AbortSignal): Promise<RunOnceResultPacket>;
|
|
23
|
+
/** Reports the provider's peak memory and releases the attempt's host runtime lease. */
|
|
24
|
+
private releaseHostRuntime;
|
|
16
25
|
}
|