@loucompanion/forge-bridge 0.1.3-dev.f66395c3ac21 → 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 +306 -1
- 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 +18 -1
- package/dist/bridge/bridge.service.d.ts +216 -4
- package/dist/bridge/bridge.service.js +2574 -90
- package/dist/bridge/bridge.types.d.ts +245 -2
- 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 +33 -2
- package/dist/cleanup/cleanup.service.js +477 -3
- package/dist/cleanup/cleanup.types.d.ts +16 -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/index.d.ts +1 -1
- package/dist/cleanup/index.js +1 -1
- package/dist/cleanup/internals.d.ts +2 -2
- package/dist/cleanup/internals.js +1 -1
- package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
- package/dist/cleanup/managed-branch-sweep.js +111 -0
- package/dist/cli/cli.help.d.ts +2 -0
- package/dist/cli/cli.help.js +279 -0
- package/dist/cli/cli.service.d.ts +69 -12
- package/dist/cli/cli.service.js +557 -382
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +13 -0
- package/dist/cli/local-config.js +82 -6
- 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 +18 -0
- package/dist/runtime/attempt-node-runtime-launcher.js +140 -0
- 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-registry.d.ts +20 -0
- package/dist/runtime/attempt-process-supervisor-registry.js +64 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +121 -0
- package/dist/runtime/attempt-process-supervisor.js +471 -0
- 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 +20 -0
- package/dist/runtime/generated-output-reset.js +157 -0
- 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 +51 -0
- package/dist/runtime/host-listener-inspector.js +385 -0
- 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-port-broker.d.ts +76 -0
- package/dist/runtime/host-port-broker.js +333 -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 +74 -0
- package/dist/runtime/host-runtime-contract.js +846 -0
- package/dist/runtime/host-runtime-lease.d.ts +287 -0
- package/dist/runtime/host-runtime-lease.js +2763 -0
- package/dist/runtime/host-runtime-promotion.d.ts +55 -0
- package/dist/runtime/host-runtime-promotion.js +254 -0
- 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 +54 -0
- package/dist/runtime/node-host-runtime-adapter.js +286 -0
- 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 +39 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +274 -0
- 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.d.ts +67 -0
- package/dist/runtime/runtime-isolation-lease.js +161 -0
- package/dist/runtime/workspace-resource-estimator.d.ts +17 -0
- package/dist/runtime/workspace-resource-estimator.js +174 -0
- package/dist/sandbox/command-runner.d.ts +4 -0
- package/dist/sandbox/command-runner.js +47 -0
- package/dist/sandbox/contract.d.ts +5 -0
- package/dist/sandbox/contract.js +276 -0
- package/dist/sandbox/event-budget.d.ts +11 -0
- package/dist/sandbox/event-budget.js +27 -0
- package/dist/sandbox/host-capacity-broker.d.ts +115 -0
- package/dist/sandbox/host-capacity-broker.js +336 -0
- package/dist/sandbox/image-policy.d.ts +35 -0
- package/dist/sandbox/image-policy.js +247 -0
- package/dist/sandbox/index.d.ts +5 -0
- package/dist/sandbox/index.js +5 -0
- package/dist/sandbox/lease-watchdog.d.ts +18 -0
- package/dist/sandbox/lease-watchdog.js +67 -0
- package/dist/sandbox/managed-branch.d.ts +13 -0
- package/dist/sandbox/managed-branch.js +36 -0
- package/dist/sandbox/preflight.d.ts +84 -0
- package/dist/sandbox/preflight.js +521 -0
- package/dist/sandbox/process.d.ts +20 -0
- package/dist/sandbox/process.js +209 -0
- package/dist/sandbox/provider-auth/codex.d.ts +26 -0
- package/dist/sandbox/provider-auth/codex.js +212 -0
- package/dist/sandbox/repository-lock.d.ts +6 -0
- package/dist/sandbox/repository-lock.js +129 -0
- package/dist/sandbox/runtime.d.ts +311 -0
- package/dist/sandbox/runtime.js +2407 -0
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -0
- package/dist/sandbox/sandbox.types.d.ts +93 -0
- package/dist/sandbox/sandbox.types.js +1 -0
- package/dist/sandbox/smoke.d.ts +76 -0
- package/dist/sandbox/smoke.js +380 -0
- package/dist/sandbox/worker-supervisor.d.ts +13 -0
- package/dist/sandbox/worker-supervisor.js +36 -0
- package/dist/sandbox/worker.d.ts +1 -0
- package/dist/sandbox/worker.js +225 -0
- package/dist/sandbox/workspace.service.d.ts +13 -0
- package/dist/sandbox/workspace.service.js +74 -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 +48 -0
- package/dist/session/managed-attempt-tools.js +1299 -0
- 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 +34 -0
- package/dist/session/phase-completion.artifacts.js +903 -0
- 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 +65 -42
- package/dist/session/phase-completion.helpers.d.ts +117 -0
- package/dist/session/phase-completion.helpers.js +708 -0
- package/dist/session/phase-completion.js +130 -3007
- 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.d.ts +14 -0
- package/dist/session/phase-completion.prompts.js +238 -0
- package/dist/session/phase-completion.runtime.d.ts +43 -0
- package/dist/session/phase-completion.runtime.js +721 -0
- 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 -0
- package/dist/session/phase-completion.schemas.js +836 -0
- package/dist/session/phase-completion.validation.d.ts +37 -0
- package/dist/session/phase-completion.validation.js +874 -0
- 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 +16 -0
- package/dist/session/provider-cli/ci-repair-readiness.js +110 -0
- 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 +96 -0
- package/dist/session/provider-cli/provider-cli.artifacts.js +818 -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-payloads.d.ts +12 -0
- package/dist/session/provider-cli/provider-cli.deterministic-payloads.js +279 -0
- package/dist/session/provider-cli/provider-cli.deterministic.d.ts +14 -0
- package/dist/session/provider-cli/provider-cli.deterministic.js +407 -0
- 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 +114 -0
- package/dist/session/provider-cli/provider-cli.process.js +757 -0
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +62 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +770 -0
- package/dist/session/provider-cli/provider-cli.qa-sidecars.d.ts +11 -0
- package/dist/session/provider-cli/provider-cli.qa-sidecars.js +66 -0
- 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 +30 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +120 -0
- package/dist/session/provider-cli/provider-cli.service.d.ts +53 -53
- package/dist/session/provider-cli/provider-cli.service.js +1299 -2523
- package/dist/session/provider-cli/provider-cli.types.d.ts +38 -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 +40 -0
- package/dist/session/provider-cli/provider-output-state.js +832 -0
- 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.d.ts +3 -0
- package/dist/session/session-redaction.js +298 -0
- package/dist/session/session.base.d.ts +14 -1
- package/dist/session/session.service.d.ts +17 -2
- package/dist/session/session.service.js +708 -60
- package/dist/session/session.types.d.ts +327 -3
- package/dist/session/session.types.js +951 -10
- 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 +21 -1
- 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 +23 -0
- package/dist/shared/process/host-process-recovery.js +99 -0
- package/dist/shared/process/host-process-supervisor.d.ts +72 -0
- package/dist/shared/process/host-process-supervisor.js +383 -0
- 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 +70 -0
- package/dist/shared/process/process.js +224 -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 +26 -0
- package/dist/shared/process/windows-launch.js +109 -0
- package/dist/shared/provider-capabilities.d.ts +4 -0
- package/dist/shared/provider-capabilities.js +95 -0
- package/dist/shared/redaction/redaction.d.ts +1 -0
- package/dist/shared/redaction/redaction.js +47 -4
- 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/artifact-injector.d.ts +3 -2
- package/dist/worktree/artifact-injector.js +82 -10
- package/dist/worktree/dependency-warmer.d.ts +78 -1
- package/dist/worktree/dependency-warmer.js +731 -13
- package/dist/worktree/index.d.ts +2 -1
- package/dist/worktree/index.js +1 -0
- package/dist/worktree/prior-phase-artifact-hydrator.d.ts +2 -0
- package/dist/worktree/prior-phase-artifact-hydrator.js +136 -0
- 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-paths.d.ts +4 -0
- package/dist/worktree/worktree-paths.js +30 -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 +10 -1
- package/dist/worktree/worktree.service.d.ts +30 -4
- package/dist/worktree/worktree.service.js +379 -54
- package/dist/worktree/worktree.types.d.ts +38 -1
- package/package.json +12 -7
- package/runtime/windows-job-supervisor.ps1 +722 -0
- package/runtime/windows-listener-owner.ps1 +33 -0
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { hostLoadStepCostForClass } from "../runtime/host-load-step-class.js";
|
|
2
|
+
import { takesHostTestSlot } from "../runtime/host-load-test-slot.js";
|
|
3
|
+
import { ForgeFailureError } from "../session/session.types.js";
|
|
4
|
+
// Host side of Docker-sandbox admission (decision 0013). The validator inside a
|
|
5
|
+
// container cannot reach the host ledger, so it asks the bridge over the
|
|
6
|
+
// channels the sandbox already has: a request line on the worker's stdout
|
|
7
|
+
// (which the bridge parses anyway) and a response file the bridge writes with
|
|
8
|
+
// `docker exec`. The bridge's own governor holds the token, renews it, and
|
|
9
|
+
// returns it when the sandbox releases it or exits, so Docker steps share the
|
|
10
|
+
// host budget.
|
|
11
|
+
//
|
|
12
|
+
// Replies are unforgeable from inside the sandbox. They live on their own tmpfs
|
|
13
|
+
// owned by root with mode 0755, mounted only for brokered workers, and are
|
|
14
|
+
// written by `docker exec --user 0`. The workload runs as uid 10001 with every
|
|
15
|
+
// capability dropped and no-new-privileges, so it can neither write there nor
|
|
16
|
+
// create any root-owned file anywhere, and a mount point cannot be renamed
|
|
17
|
+
// away. The validator accepts only a regular, root-owned, single-link reply
|
|
18
|
+
// that no one else can write (sandbox-host-capacity-gate.ts).
|
|
19
|
+
export const sandboxHostCapacityBrokerEnvironment = "FORGE_HOST_LOAD_BROKER";
|
|
20
|
+
export const sandboxHostCapacityBrokerProtocol = "stdout-v1";
|
|
21
|
+
export const sandboxHostCapacityLineType = "forge_host_capacity";
|
|
22
|
+
export const sandboxHostCapacityResponseRoot = "/run/forge/host-capacity";
|
|
23
|
+
/** Owner of authentic replies inside the container: root, via `docker exec --user 0`. */
|
|
24
|
+
export const sandboxHostCapacityResponseOwnerUid = 0;
|
|
25
|
+
export const sandboxHostCapacityMaxWaitEnvironment = "FORGE_HOST_LOAD_BROKER_MAX_WAIT_MS";
|
|
26
|
+
const requestIdPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u;
|
|
27
|
+
const stepClassPattern = /^[a-z0-9][a-z0-9._-]{0,63}$/u;
|
|
28
|
+
/** A sandbox validates one step at a time; a small bound stops a runaway from hoarding tokens. */
|
|
29
|
+
const defaultMaximumOutstanding = 2;
|
|
30
|
+
/** A validation run sends two lines per step; this leaves room for reruns and caps docker exec churn. */
|
|
31
|
+
const defaultBurst = 40;
|
|
32
|
+
const defaultRefillPerSecond = 2;
|
|
33
|
+
function codeOf(error) {
|
|
34
|
+
const code = error?.code;
|
|
35
|
+
return typeof code === "string" ? code : null;
|
|
36
|
+
}
|
|
37
|
+
function hasCode(error, code) {
|
|
38
|
+
return codeOf(error) === code;
|
|
39
|
+
}
|
|
40
|
+
/** Parses one stdout line; null when it is not a well-formed broker request. */
|
|
41
|
+
export function parseSandboxHostCapacityRequest(line) {
|
|
42
|
+
const trimmed = line.trim();
|
|
43
|
+
if (!trimmed.startsWith("{") || !trimmed.includes(sandboxHostCapacityLineType) || trimmed.length > 4096)
|
|
44
|
+
return null;
|
|
45
|
+
let value;
|
|
46
|
+
try {
|
|
47
|
+
value = JSON.parse(trimmed);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
if (!value || value.type !== sandboxHostCapacityLineType || value.version !== 1)
|
|
53
|
+
return null;
|
|
54
|
+
if (value.action !== "acquire" && value.action !== "release" && value.action !== "retain")
|
|
55
|
+
return null;
|
|
56
|
+
if (typeof value.requestId !== "string" || !requestIdPattern.test(value.requestId))
|
|
57
|
+
return null;
|
|
58
|
+
const claimed = typeof value.stepClass === "string" && stepClassPattern.test(value.stepClass) ? value.stepClass : "generic";
|
|
59
|
+
// A sandbox brokers only validation steps; it cannot claim a class that skips the host test slot.
|
|
60
|
+
const stepClass = takesHostTestSlot(claimed) ? claimed : "generic";
|
|
61
|
+
// Diagnostics only, but never control characters or markup from the sandbox.
|
|
62
|
+
const label = typeof value.label === "string" ? value.label.replace(/[^\w .:/@+-]/gu, "_").slice(0, 128) : "";
|
|
63
|
+
return { action: value.action, requestId: value.requestId, stepClass, label };
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* One sandbox's brokered tokens. The sandbox never chooses the cost or the
|
|
67
|
+
* attempt. Replies for one request go out one at a time, newest state only,
|
|
68
|
+
* each with a rising sequence the container-side writer uses to refuse an
|
|
69
|
+
* older reply; a failed delivery is retried until a newer state replaces it
|
|
70
|
+
* or the broker closes. A sandbox that floods requests or exceeds its
|
|
71
|
+
* outstanding limit stops the broker and fails its attempt.
|
|
72
|
+
*/
|
|
73
|
+
export class SandboxHostCapacityBroker {
|
|
74
|
+
gate;
|
|
75
|
+
dispatchAttemptId;
|
|
76
|
+
priority;
|
|
77
|
+
deliver;
|
|
78
|
+
options;
|
|
79
|
+
tokens = new Map();
|
|
80
|
+
deliveries = new Map();
|
|
81
|
+
work = new Set();
|
|
82
|
+
maximumOutstanding;
|
|
83
|
+
burst;
|
|
84
|
+
refillPerSecond;
|
|
85
|
+
retryMs;
|
|
86
|
+
now;
|
|
87
|
+
sequence = 0;
|
|
88
|
+
allowance;
|
|
89
|
+
allowanceAtMs;
|
|
90
|
+
closed = false;
|
|
91
|
+
abuse = null;
|
|
92
|
+
constructor(gate, dispatchAttemptId, priority, deliver, options = {}) {
|
|
93
|
+
this.gate = gate;
|
|
94
|
+
this.dispatchAttemptId = dispatchAttemptId;
|
|
95
|
+
this.priority = priority;
|
|
96
|
+
this.deliver = deliver;
|
|
97
|
+
this.options = options;
|
|
98
|
+
this.maximumOutstanding = options.maximumOutstanding ?? defaultMaximumOutstanding;
|
|
99
|
+
this.burst = options.burst ?? defaultBurst;
|
|
100
|
+
this.refillPerSecond = options.refillPerSecond ?? defaultRefillPerSecond;
|
|
101
|
+
this.retryMs = options.retryMs ?? 250;
|
|
102
|
+
this.now = options.now ?? Date.now;
|
|
103
|
+
this.allowance = this.burst;
|
|
104
|
+
this.allowanceAtMs = this.now();
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* True when the line was a broker request; such a line is never a runner
|
|
108
|
+
* event. Throws sandbox_host_capacity_abuse once the sandbox breaks its
|
|
109
|
+
* limits: its tokens are returned and the attempt fails with that reason.
|
|
110
|
+
*/
|
|
111
|
+
handleLine(line) {
|
|
112
|
+
if (this.abuse)
|
|
113
|
+
throw this.abuse;
|
|
114
|
+
const request = parseSandboxHostCapacityRequest(line);
|
|
115
|
+
if (!request)
|
|
116
|
+
return false;
|
|
117
|
+
if (!this.takeAllowance()) {
|
|
118
|
+
this.stop(`more than ${this.burst} host capacity requests in a burst (sustained limit ${this.refillPerSecond}/s)`);
|
|
119
|
+
}
|
|
120
|
+
if (request.action === "acquire" && !this.tokens.has(request.requestId) && this.tokens.size >= this.maximumOutstanding) {
|
|
121
|
+
this.stop(`more than ${this.maximumOutstanding} host capacity requests outstanding at once`);
|
|
122
|
+
}
|
|
123
|
+
this.track(request.action === "acquire" ? this.acquire(request)
|
|
124
|
+
: request.action === "retain" ? Promise.resolve(this.retain(request.requestId)) : this.release(request.requestId));
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
/** The sandbox exited: cancel its waits and return every token it holds. */
|
|
128
|
+
async close() {
|
|
129
|
+
this.closed = true;
|
|
130
|
+
await Promise.allSettled([...this.tokens.keys()].map(requestId => this.release(requestId)));
|
|
131
|
+
await Promise.allSettled([...this.work]);
|
|
132
|
+
}
|
|
133
|
+
/** Requests waiting or admitted, for diagnostics and tests. */
|
|
134
|
+
outstanding() {
|
|
135
|
+
return this.tokens.size;
|
|
136
|
+
}
|
|
137
|
+
stop(reason) {
|
|
138
|
+
this.abuse = new ForgeFailureError("sandbox_host_capacity_abuse", `sandbox_host_capacity_abuse: the sandbox sent ${reason}; Forge returned its host capacity and stopped the attempt.`, "sandbox");
|
|
139
|
+
void this.close();
|
|
140
|
+
throw this.abuse;
|
|
141
|
+
}
|
|
142
|
+
takeAllowance() {
|
|
143
|
+
const nowMs = this.now();
|
|
144
|
+
this.allowance = Math.min(this.burst, this.allowance + ((nowMs - this.allowanceAtMs) / 1000) * this.refillPerSecond);
|
|
145
|
+
this.allowanceAtMs = nowMs;
|
|
146
|
+
if (this.allowance < 1)
|
|
147
|
+
return false;
|
|
148
|
+
this.allowance -= 1;
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
track(task) {
|
|
152
|
+
const tracked = task.catch(() => undefined);
|
|
153
|
+
this.work.add(tracked);
|
|
154
|
+
void tracked.finally(() => this.work.delete(tracked));
|
|
155
|
+
}
|
|
156
|
+
async acquire(request) {
|
|
157
|
+
if (this.closed || this.tokens.has(request.requestId))
|
|
158
|
+
return;
|
|
159
|
+
const entry = { controller: new AbortController(), admission: null, released: false, retained: false };
|
|
160
|
+
this.tokens.set(request.requestId, entry);
|
|
161
|
+
let admission;
|
|
162
|
+
try {
|
|
163
|
+
admission = await this.gate.acquire({
|
|
164
|
+
stepClass: request.stepClass,
|
|
165
|
+
label: `sandbox ${request.label || request.stepClass}`,
|
|
166
|
+
// The host decides the cost from the class; the sandbox cannot claim a cheaper one.
|
|
167
|
+
cost: hostLoadStepCostForClass(request.stepClass),
|
|
168
|
+
dispatchAttemptId: this.dispatchAttemptId,
|
|
169
|
+
priority: this.priority,
|
|
170
|
+
}, {
|
|
171
|
+
signal: entry.controller.signal,
|
|
172
|
+
// Sequenced when called, so it can never overtake the admission that follows.
|
|
173
|
+
onWaiting: decision => this.respond({
|
|
174
|
+
requestId: request.requestId, status: "waiting", reason: decision.reason, detail: decision.detail,
|
|
175
|
+
}),
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
this.tokens.delete(request.requestId);
|
|
180
|
+
if (entry.released)
|
|
181
|
+
return;
|
|
182
|
+
const failure = error;
|
|
183
|
+
void this.respond({
|
|
184
|
+
requestId: request.requestId,
|
|
185
|
+
status: "failed",
|
|
186
|
+
code: typeof failure.code === "string" ? failure.code : "host_capacity_broker_failed",
|
|
187
|
+
message: typeof failure.message === "string" ? failure.message : String(error),
|
|
188
|
+
...(typeof failure.waitMs === "number" ? { waitMs: Math.round(failure.waitMs) } : {}),
|
|
189
|
+
});
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (entry.released) {
|
|
193
|
+
await admission.release().catch(() => undefined);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
entry.admission = admission;
|
|
197
|
+
// A reclaim after a bridge crash then stops the sandbox before reusing its capacity.
|
|
198
|
+
// Without a known process (lookup failed) the token has no tree and, on a crash,
|
|
199
|
+
// stays degraded with its cost; a failed recording is terminal, not ignored.
|
|
200
|
+
let attachFailure = null;
|
|
201
|
+
if (!admission.fenced.aborted) {
|
|
202
|
+
const stepProcess = await this.options.stepProcess?.().catch(() => null);
|
|
203
|
+
if (stepProcess)
|
|
204
|
+
attachFailure = await admission.attachProcess(stepProcess).then(() => null, (error) => error);
|
|
205
|
+
}
|
|
206
|
+
if (entry.released)
|
|
207
|
+
return;
|
|
208
|
+
if (admission.fenced.aborted || attachFailure !== null) {
|
|
209
|
+
// Lost before the sandbox was told it may start: it never runs this step, so
|
|
210
|
+
// it gets a terminal answer instead of "admitted", and the token goes back now.
|
|
211
|
+
const reason = admission.fenced.aborted ? admission.fenced.reason : attachFailure;
|
|
212
|
+
const fenced = admission.fenced.aborted || hasCode(reason, "host_capacity_token_fenced");
|
|
213
|
+
entry.released = true;
|
|
214
|
+
this.tokens.delete(request.requestId);
|
|
215
|
+
void this.respond({
|
|
216
|
+
requestId: request.requestId,
|
|
217
|
+
status: fenced ? "fenced" : "failed",
|
|
218
|
+
code: fenced ? "host_capacity_token_fenced" : codeOf(reason) ?? "host_capacity_broker_failed",
|
|
219
|
+
message: reason instanceof Error ? reason.message : String(reason),
|
|
220
|
+
});
|
|
221
|
+
await admission.release().catch(() => undefined);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
// Registered synchronously after the check above, so no fence can slip between them.
|
|
225
|
+
admission.fenced.addEventListener("abort", () => {
|
|
226
|
+
// Retention stops the step's reservation on purpose; the sandbox already knows.
|
|
227
|
+
if (entry.retained)
|
|
228
|
+
return;
|
|
229
|
+
void this.respond({
|
|
230
|
+
requestId: request.requestId,
|
|
231
|
+
status: "fenced",
|
|
232
|
+
code: "host_capacity_token_fenced",
|
|
233
|
+
message: admission.fenced.reason instanceof Error ? admission.fenced.reason.message : "host_capacity_token_fenced",
|
|
234
|
+
});
|
|
235
|
+
}, { once: true });
|
|
236
|
+
void this.respond({
|
|
237
|
+
requestId: request.requestId, status: "admitted", waitMs: Math.round(admission.waitMs), reason: admission.decision.reason,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* The sandbox's step ended but part of its tree may still run: the host token is
|
|
242
|
+
* kept, marked retained (so the attempt's own next step does not wait for it),
|
|
243
|
+
* until the sandbox releases the request or exits.
|
|
244
|
+
*/
|
|
245
|
+
retain(requestId) {
|
|
246
|
+
const entry = this.tokens.get(requestId);
|
|
247
|
+
if (!entry?.admission || entry.released || entry.retained)
|
|
248
|
+
return;
|
|
249
|
+
entry.retained = true;
|
|
250
|
+
entry.admission.retainUntilStopped(async () => entry.released, new Error("The sandbox step's processes could not be proven stopped; its host capacity is kept until the sandbox releases it."));
|
|
251
|
+
}
|
|
252
|
+
async release(requestId) {
|
|
253
|
+
const entry = this.tokens.get(requestId);
|
|
254
|
+
if (!entry || entry.released)
|
|
255
|
+
return;
|
|
256
|
+
entry.released = true;
|
|
257
|
+
this.tokens.delete(requestId);
|
|
258
|
+
this.deliveries.delete(requestId);
|
|
259
|
+
entry.controller.abort(new Error("The sandbox released its host capacity request."));
|
|
260
|
+
await entry.admission?.release().catch(() => undefined);
|
|
261
|
+
}
|
|
262
|
+
/** Queues the newest state for a request; at most one delivery per request is in flight. */
|
|
263
|
+
respond(response) {
|
|
264
|
+
// A container that already exited cannot read the answer; the token is released on close.
|
|
265
|
+
if (this.closed)
|
|
266
|
+
return Promise.resolve();
|
|
267
|
+
this.sequence += 1;
|
|
268
|
+
const state = this.deliveries.get(response.requestId) ?? { latest: null, delivering: false };
|
|
269
|
+
this.deliveries.set(response.requestId, state);
|
|
270
|
+
state.latest = { ...response, sequence: this.sequence };
|
|
271
|
+
if (state.delivering)
|
|
272
|
+
return Promise.resolve();
|
|
273
|
+
state.delivering = true;
|
|
274
|
+
const pump = this.pump(response.requestId, state);
|
|
275
|
+
this.track(pump);
|
|
276
|
+
return pump;
|
|
277
|
+
}
|
|
278
|
+
async pump(requestId, state) {
|
|
279
|
+
// The reply chain for one request; ends when its newest state landed or the broker closed.
|
|
280
|
+
let delayMs = this.retryMs;
|
|
281
|
+
try {
|
|
282
|
+
while (state.latest && !this.closed) {
|
|
283
|
+
const next = state.latest;
|
|
284
|
+
try {
|
|
285
|
+
await this.deliver(next);
|
|
286
|
+
if (state.latest === next)
|
|
287
|
+
state.latest = null;
|
|
288
|
+
delayMs = this.retryMs;
|
|
289
|
+
}
|
|
290
|
+
catch {
|
|
291
|
+
// Redeliver the newest state (this one, unless a newer one arrived meanwhile).
|
|
292
|
+
await new Promise(resolve => setTimeout(resolve, delayMs));
|
|
293
|
+
delayMs = Math.min(delayMs * 2, 4_000);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
finally {
|
|
298
|
+
state.delivering = false;
|
|
299
|
+
if (!this.tokens.has(requestId) && this.deliveries.get(requestId) === state)
|
|
300
|
+
this.deliveries.delete(requestId);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Adds the broker variables to a worker `docker create` command, just before
|
|
306
|
+
* its image: the protocol, and the host's maximum queue wait so the
|
|
307
|
+
* container's own fail-safe never fires before the host answers.
|
|
308
|
+
*/
|
|
309
|
+
export function withSandboxHostCapacityBroker(createArgs, image, maxWaitMs) {
|
|
310
|
+
const imageIndex = createArgs.lastIndexOf(image);
|
|
311
|
+
if (imageIndex < 0)
|
|
312
|
+
throw new Error("sandbox_host_capacity_broker_invalid: the worker image is missing from its create command.");
|
|
313
|
+
const args = [...createArgs];
|
|
314
|
+
args.splice(imageIndex, 0,
|
|
315
|
+
// Root-owned and not writable by the sandbox user: only the bridge's replies land here.
|
|
316
|
+
"--tmpfs", `${sandboxHostCapacityResponseRoot}:rw,nosuid,nodev,noexec,size=4m,uid=0,gid=0,mode=0755`, "--env", `${sandboxHostCapacityBrokerEnvironment}=${sandboxHostCapacityBrokerProtocol}`, "--env", `${sandboxHostCapacityMaxWaitEnvironment}=${Math.round(maxWaitMs)}`);
|
|
317
|
+
return args;
|
|
318
|
+
}
|
|
319
|
+
/** `docker exec` arguments that write one reply into the container as root. */
|
|
320
|
+
export function sandboxHostCapacityDeliveryExecArgs(container) {
|
|
321
|
+
return ["exec", "--interactive", "--user", "0", container, "node", "-e", sandboxHostCapacityResponseScript];
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* The `node -e` script that writes one response file inside the container, run
|
|
325
|
+
* as root. It keeps the newest reply: one with a lower or equal sequence than
|
|
326
|
+
* the file already holds is dropped, so a late delivery can never replace a
|
|
327
|
+
* newer state. Replies are world-readable but owned by the writer (root, via
|
|
328
|
+
* `docker exec --user 0`). The directory must already be owned by that same uid
|
|
329
|
+
* and writable by no one else, i.e. the root-owned reply mount; it is never
|
|
330
|
+
* created here, where it could turn out to be the sandbox's own directory. A
|
|
331
|
+
* runtime without POSIX user ids (Windows) cannot prove that, so the script
|
|
332
|
+
* writes nothing there (exit 3), as for any directory it cannot trust.
|
|
333
|
+
*/
|
|
334
|
+
export const sandboxHostCapacityResponseScript = "let s='';process.stdin.setEncoding('utf8');process.stdin.on('data',c=>s+=c);process.stdin.on('end',()=>{const f=require('fs'),r=JSON.parse(s),d='"
|
|
335
|
+
+ sandboxHostCapacityResponseRoot
|
|
336
|
+
+ "';if(!/^[0-9a-f-]{36}$/.test(r.requestId)||!Number.isSafeInteger(r.sequence))process.exit(2);if(typeof process.getuid!=='function')process.exit(3);const st=f.lstatSync(d);if(!st.isDirectory()||st.uid!==process.getuid()||(st.mode&0o022))process.exit(3);const p=d+'/'+r.requestId+'.json',t=p+'.'+process.pid+'.tmp';let o=-1;try{o=JSON.parse(f.readFileSync(p,'utf8')).sequence}catch{}if(Number.isSafeInteger(o)&&o>=r.sequence)return;f.writeFileSync(t,s,{mode:0o644,flag:'wx'});f.renameSync(t,p)})";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type SandboxProcessRequest, type SandboxProcessResult } from "./process.js";
|
|
2
|
+
export type SandboxImageLayer = "project" | "tooling" | "agent";
|
|
3
|
+
export interface SandboxImagePolicyRequest {
|
|
4
|
+
readonly key: string;
|
|
5
|
+
readonly project: string;
|
|
6
|
+
readonly executionPolicy: string;
|
|
7
|
+
readonly stateRoot: string;
|
|
8
|
+
readonly builderVersion: string;
|
|
9
|
+
readonly contextDigest: string;
|
|
10
|
+
readonly contractDigest: string;
|
|
11
|
+
readonly toolingImage: string;
|
|
12
|
+
readonly upstreamImages: readonly string[];
|
|
13
|
+
readonly codexVersion: string;
|
|
14
|
+
readonly images: Readonly<Record<SandboxImageLayer, string>>;
|
|
15
|
+
readonly imageScanTargets?: Readonly<Partial<Record<SandboxImageLayer, string>>>;
|
|
16
|
+
readonly environment?: NodeJS.ProcessEnv;
|
|
17
|
+
readonly signal?: AbortSignal;
|
|
18
|
+
readonly runCommand?: (command: SandboxProcessRequest) => Promise<SandboxProcessResult>;
|
|
19
|
+
}
|
|
20
|
+
export interface SandboxImagePolicyResult {
|
|
21
|
+
readonly status: "passed" | "warning";
|
|
22
|
+
readonly policyDigest: string;
|
|
23
|
+
readonly root: string;
|
|
24
|
+
}
|
|
25
|
+
export declare function evaluateSandboxImagePolicy(request: SandboxImagePolicyRequest): Promise<SandboxImagePolicyResult>;
|
|
26
|
+
export interface SandboxImageSignatureRequest {
|
|
27
|
+
readonly image: string;
|
|
28
|
+
readonly executionPolicy: string;
|
|
29
|
+
readonly environment?: NodeJS.ProcessEnv;
|
|
30
|
+
readonly signal?: AbortSignal;
|
|
31
|
+
readonly runCommand?: (command: SandboxProcessRequest) => Promise<SandboxProcessResult>;
|
|
32
|
+
}
|
|
33
|
+
export declare function verifySandboxImageSignature(request: SandboxImageSignatureRequest): Promise<"passed" | "warning">;
|
|
34
|
+
export declare function hasSandboxImagePolicyRecord(stateRoot: string, key: string, expectedDigest: string, requirePassed?: boolean): Promise<boolean>;
|
|
35
|
+
export declare function sandboxImagePolicyConfigurationDigest(environment?: NodeJS.ProcessEnv): Promise<string>;
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { createHash, createPrivateKey, createPublicKey, sign, verify } from "node:crypto";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { runSandboxProcess } from "./process.js";
|
|
5
|
+
export async function evaluateSandboxImagePolicy(request) {
|
|
6
|
+
const environment = request.environment ?? process.env;
|
|
7
|
+
const required = request.executionPolicy === "sandbox_required";
|
|
8
|
+
const enforced = environment.FORGE_SANDBOX_IMAGE_POLICY_ENFORCED === "true";
|
|
9
|
+
const sbomExecutable = environment.FORGE_SANDBOX_SBOM_EXECUTABLE?.trim();
|
|
10
|
+
const vulnerabilityExecutable = environment.FORGE_SANDBOX_VULNERABILITY_EXECUTABLE?.trim();
|
|
11
|
+
const signingKeyPath = environment.FORGE_SANDBOX_PROVENANCE_SIGNING_KEY?.trim();
|
|
12
|
+
const signatureExecutable = environment.FORGE_SANDBOX_SIGNATURE_EXECUTABLE?.trim();
|
|
13
|
+
const signaturePublicKey = environment.FORGE_SANDBOX_SIGNATURE_PUBLIC_KEY?.trim();
|
|
14
|
+
if (required && (!enforced || !sbomExecutable || !vulnerabilityExecutable || !signingKeyPath || !signatureExecutable || !signaturePublicKey)) {
|
|
15
|
+
throw new Error("sandbox_build_policy_failed: sandbox_required needs enforced SBOM, vulnerability, provenance-signing, and upstream-signature configuration.");
|
|
16
|
+
}
|
|
17
|
+
const root = path.join(request.stateRoot, "attestations", request.key);
|
|
18
|
+
await fs.mkdir(root, { recursive: true, mode: 0o700 });
|
|
19
|
+
const artifacts = {};
|
|
20
|
+
let status = "passed";
|
|
21
|
+
const privateKey = signingKeyPath ? await readSigningKey(signingKeyPath) : null;
|
|
22
|
+
const runCommand = request.runCommand ?? runSandboxProcess;
|
|
23
|
+
const upstreamSignatures = {};
|
|
24
|
+
for (const image of [...new Set([request.toolingImage, ...request.upstreamImages])]) {
|
|
25
|
+
const signatureStatus = await verifySandboxImageSignature({
|
|
26
|
+
image,
|
|
27
|
+
executionPolicy: request.executionPolicy,
|
|
28
|
+
environment,
|
|
29
|
+
signal: request.signal,
|
|
30
|
+
runCommand
|
|
31
|
+
});
|
|
32
|
+
upstreamSignatures[image] = signatureStatus;
|
|
33
|
+
if (signatureStatus === "warning")
|
|
34
|
+
status = "warning";
|
|
35
|
+
}
|
|
36
|
+
for (const [layer, imageDigest] of Object.entries(request.images)) {
|
|
37
|
+
const scanTarget = request.imageScanTargets?.[layer] ?? imageDigest;
|
|
38
|
+
const provenance = {
|
|
39
|
+
schemaVersion: 1,
|
|
40
|
+
predicateType: "https://slsa.dev/provenance/v1",
|
|
41
|
+
subject: [{ name: `forge/${layer}`, digest: { sha256: imageDigest.slice("sha256:".length) } }],
|
|
42
|
+
builder: { id: `forge-bridge/${request.builderVersion}` },
|
|
43
|
+
buildType: "https://forge.dev/buildkit/project-agent-overlay/v1",
|
|
44
|
+
invocation: { parameters: { key: request.key, project: request.project, layer } },
|
|
45
|
+
materials: [
|
|
46
|
+
{ uri: "forge:tracked-context", digest: { sha256: request.contextDigest } },
|
|
47
|
+
{ uri: "forge:sandbox-contract", digest: { sha256: request.contractDigest.replace(/^sha256:/u, "") } },
|
|
48
|
+
{ uri: request.toolingImage },
|
|
49
|
+
{ uri: `pkg:npm/@openai/codex@${request.codexVersion}` }
|
|
50
|
+
]
|
|
51
|
+
};
|
|
52
|
+
const provenanceBytes = Buffer.from(`${canonicalJson(provenance)}\n`, "utf8");
|
|
53
|
+
const provenanceName = `${layer}.provenance.json`;
|
|
54
|
+
await writeRestricted(path.join(root, provenanceName), provenanceBytes);
|
|
55
|
+
let signatureDigest = null;
|
|
56
|
+
if (privateKey) {
|
|
57
|
+
const signature = sign("sha256", provenanceBytes, privateKey);
|
|
58
|
+
if (!verify("sha256", provenanceBytes, createPublicKey(privateKey), signature)) {
|
|
59
|
+
throw new Error("sandbox_build_policy_failed: generated provenance signature did not verify.");
|
|
60
|
+
}
|
|
61
|
+
await writeRestricted(path.join(root, `${provenanceName}.sig`), signature);
|
|
62
|
+
signatureDigest = sha256(signature);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
status = "warning";
|
|
66
|
+
}
|
|
67
|
+
let sbomDigest = null;
|
|
68
|
+
if (sbomExecutable) {
|
|
69
|
+
const sbom = await runCommand({
|
|
70
|
+
command: sbomExecutable,
|
|
71
|
+
args: [scanTarget, "-o", "spdx-json"],
|
|
72
|
+
timeoutMs: 10 * 60_000,
|
|
73
|
+
maxOutputBytes: 32 * 1024 * 1024,
|
|
74
|
+
signal: request.signal
|
|
75
|
+
});
|
|
76
|
+
if (sbom.exitCode !== 0 || sbom.truncated || !validJsonObject(sbom.stdout)) {
|
|
77
|
+
throw new Error(`sandbox_build_policy_failed: SPDX SBOM generation failed for ${layer}.`);
|
|
78
|
+
}
|
|
79
|
+
const bytes = Buffer.from(sbom.stdout, "utf8");
|
|
80
|
+
await writeRestricted(path.join(root, `${layer}.sbom.spdx.json`), bytes);
|
|
81
|
+
sbomDigest = sha256(bytes);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
status = "warning";
|
|
85
|
+
}
|
|
86
|
+
let vulnerabilityDigest = null;
|
|
87
|
+
if (vulnerabilityExecutable) {
|
|
88
|
+
const scan = await runCommand({
|
|
89
|
+
command: vulnerabilityExecutable,
|
|
90
|
+
args: ["image", "--scanners", "vuln", "--format", "json", "--severity", "HIGH,CRITICAL", "--exit-code", "1", "--no-progress", scanTarget],
|
|
91
|
+
timeoutMs: 15 * 60_000,
|
|
92
|
+
maxOutputBytes: 32 * 1024 * 1024,
|
|
93
|
+
signal: request.signal
|
|
94
|
+
});
|
|
95
|
+
const bytes = Buffer.from(scan.stdout || scan.stderr, "utf8");
|
|
96
|
+
await writeRestricted(path.join(root, `${layer}.vulnerabilities.json`), bytes);
|
|
97
|
+
vulnerabilityDigest = sha256(bytes);
|
|
98
|
+
if (scan.exitCode !== 0 || scan.truncated) {
|
|
99
|
+
throw new Error(`sandbox_build_policy_failed: ${layer} violates the HIGH/CRITICAL vulnerability policy.`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
status = "warning";
|
|
104
|
+
}
|
|
105
|
+
artifacts[layer] = {
|
|
106
|
+
imageDigest,
|
|
107
|
+
scanTarget,
|
|
108
|
+
provenanceSha256: sha256(provenanceBytes),
|
|
109
|
+
provenanceSignatureSha256: signatureDigest,
|
|
110
|
+
sbomSha256: sbomDigest,
|
|
111
|
+
vulnerabilityReportSha256: vulnerabilityDigest
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
const policyRecord = {
|
|
115
|
+
schemaVersion: 1,
|
|
116
|
+
key: request.key,
|
|
117
|
+
project: request.project,
|
|
118
|
+
status,
|
|
119
|
+
enforced,
|
|
120
|
+
generatedAt: new Date().toISOString(),
|
|
121
|
+
upstreamSignatures,
|
|
122
|
+
artifacts
|
|
123
|
+
};
|
|
124
|
+
const recordBytes = Buffer.from(`${canonicalJson(policyRecord)}\n`, "utf8");
|
|
125
|
+
const policyDigest = sha256(recordBytes);
|
|
126
|
+
await writeRestricted(path.join(root, "policy.json"), recordBytes);
|
|
127
|
+
return { status, policyDigest, root };
|
|
128
|
+
}
|
|
129
|
+
export async function verifySandboxImageSignature(request) {
|
|
130
|
+
const required = request.executionPolicy === "sandbox_required";
|
|
131
|
+
if (!/@sha256:[a-f0-9]{64}$/iu.test(request.image)) {
|
|
132
|
+
if (required)
|
|
133
|
+
throw new Error(`sandbox_image_signature_failed: image '${request.image}' is not digest-pinned.`);
|
|
134
|
+
return "warning";
|
|
135
|
+
}
|
|
136
|
+
const environment = request.environment ?? process.env;
|
|
137
|
+
const executable = environment.FORGE_SANDBOX_SIGNATURE_EXECUTABLE?.trim();
|
|
138
|
+
const publicKeyPath = environment.FORGE_SANDBOX_SIGNATURE_PUBLIC_KEY?.trim();
|
|
139
|
+
if (!executable || !publicKeyPath) {
|
|
140
|
+
if (required)
|
|
141
|
+
throw new Error("sandbox_image_signature_failed: sandbox_required needs an image signature verifier and public key.");
|
|
142
|
+
return "warning";
|
|
143
|
+
}
|
|
144
|
+
await readBoundedRegularFile(publicKeyPath, "image signature public key", "sandbox_image_signature_failed");
|
|
145
|
+
const runCommand = request.runCommand ?? runSandboxProcess;
|
|
146
|
+
const result = await runCommand({
|
|
147
|
+
command: executable,
|
|
148
|
+
args: ["verify", "--key", publicKeyPath, request.image],
|
|
149
|
+
timeoutMs: 5 * 60_000,
|
|
150
|
+
maxOutputBytes: 4 * 1024 * 1024,
|
|
151
|
+
terminateOnOutputLimit: true,
|
|
152
|
+
signal: request.signal
|
|
153
|
+
});
|
|
154
|
+
if (result.exitCode !== 0 || result.truncated || !validSignatureResult(result.stdout)) {
|
|
155
|
+
throw new Error(`sandbox_image_signature_failed: signature verification failed for '${request.image}'.`);
|
|
156
|
+
}
|
|
157
|
+
return "passed";
|
|
158
|
+
}
|
|
159
|
+
export async function hasSandboxImagePolicyRecord(stateRoot, key, expectedDigest, requirePassed = false) {
|
|
160
|
+
const target = path.join(stateRoot, "attestations", key, "policy.json");
|
|
161
|
+
const stat = await fs.lstat(target).catch(() => null);
|
|
162
|
+
if (!stat || !stat.isFile() || stat.isSymbolicLink() || stat.size > 1024 * 1024)
|
|
163
|
+
return false;
|
|
164
|
+
const bytes = await fs.readFile(target);
|
|
165
|
+
if (sha256(bytes) !== expectedDigest)
|
|
166
|
+
return false;
|
|
167
|
+
if (!requirePassed)
|
|
168
|
+
return true;
|
|
169
|
+
try {
|
|
170
|
+
const record = JSON.parse(bytes.toString("utf8"));
|
|
171
|
+
return record.status === "passed" && record.enforced === true;
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
export async function sandboxImagePolicyConfigurationDigest(environment = process.env) {
|
|
178
|
+
const signingKeyPath = environment.FORGE_SANDBOX_PROVENANCE_SIGNING_KEY?.trim() ?? "";
|
|
179
|
+
const signaturePublicKeyPath = environment.FORGE_SANDBOX_SIGNATURE_PUBLIC_KEY?.trim() ?? "";
|
|
180
|
+
const fields = [
|
|
181
|
+
environment.FORGE_SANDBOX_IMAGE_POLICY_ENFORCED ?? "",
|
|
182
|
+
environment.FORGE_SANDBOX_SBOM_EXECUTABLE?.trim() ?? "",
|
|
183
|
+
environment.FORGE_SANDBOX_VULNERABILITY_EXECUTABLE?.trim() ?? "",
|
|
184
|
+
environment.FORGE_SANDBOX_SIGNATURE_EXECUTABLE?.trim() ?? "",
|
|
185
|
+
await policyFileFingerprint(signingKeyPath),
|
|
186
|
+
await policyFileFingerprint(signaturePublicKeyPath)
|
|
187
|
+
];
|
|
188
|
+
return sha256(Buffer.from(fields.join("\0"), "utf8"));
|
|
189
|
+
}
|
|
190
|
+
async function readSigningKey(target) {
|
|
191
|
+
const bytes = await readBoundedRegularFile(target, "provenance signing key");
|
|
192
|
+
try {
|
|
193
|
+
return createPrivateKey(bytes);
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
throw new Error("sandbox_build_policy_failed: provenance signing key is invalid.", { cause: error });
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
async function readBoundedRegularFile(target, label, failureCode = "sandbox_build_policy_failed") {
|
|
200
|
+
const stat = await fs.lstat(target).catch(() => null);
|
|
201
|
+
if (!stat || !stat.isFile() || stat.isSymbolicLink() || stat.size === 0 || stat.size > 64 * 1024) {
|
|
202
|
+
throw new Error(`${failureCode}: ${label} must be a bounded regular file.`);
|
|
203
|
+
}
|
|
204
|
+
return await fs.readFile(target);
|
|
205
|
+
}
|
|
206
|
+
async function policyFileFingerprint(target) {
|
|
207
|
+
if (!target)
|
|
208
|
+
return "not-configured";
|
|
209
|
+
const stat = await fs.lstat(target).catch(() => null);
|
|
210
|
+
if (!stat || !stat.isFile() || stat.isSymbolicLink() || stat.size === 0 || stat.size > 64 * 1024)
|
|
211
|
+
return "invalid";
|
|
212
|
+
return sha256(await fs.readFile(target));
|
|
213
|
+
}
|
|
214
|
+
async function writeRestricted(target, bytes) {
|
|
215
|
+
const temporary = `${target}.${process.pid}.${Date.now()}.tmp`;
|
|
216
|
+
await fs.writeFile(temporary, bytes, { mode: 0o600, flag: "wx" });
|
|
217
|
+
await fs.rename(temporary, target);
|
|
218
|
+
}
|
|
219
|
+
function validJsonObject(value) {
|
|
220
|
+
try {
|
|
221
|
+
const parsed = JSON.parse(value);
|
|
222
|
+
return Boolean(parsed && typeof parsed === "object" && !Array.isArray(parsed));
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function validSignatureResult(value) {
|
|
229
|
+
try {
|
|
230
|
+
const parsed = JSON.parse(value);
|
|
231
|
+
return Array.isArray(parsed) && parsed.length > 0 && parsed.every(entry => Boolean(entry && typeof entry === "object" && !Array.isArray(entry)));
|
|
232
|
+
}
|
|
233
|
+
catch {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function sha256(value) {
|
|
238
|
+
return createHash("sha256").update(value).digest("hex");
|
|
239
|
+
}
|
|
240
|
+
function canonicalJson(value) {
|
|
241
|
+
if (Array.isArray(value))
|
|
242
|
+
return `[${value.map(canonicalJson).join(",")}]`;
|
|
243
|
+
if (value && typeof value === "object") {
|
|
244
|
+
return `{${Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, child]) => `${JSON.stringify(key)}:${canonicalJson(child)}`).join(",")}}`;
|
|
245
|
+
}
|
|
246
|
+
return JSON.stringify(value);
|
|
247
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface SignedLeaseUpdate {
|
|
2
|
+
readonly schemaVersion: 1;
|
|
3
|
+
readonly dispatchAttemptId: string;
|
|
4
|
+
readonly fencingToken: string;
|
|
5
|
+
readonly expiresAt: string;
|
|
6
|
+
readonly mac: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function createLeaseUpdate(dispatchAttemptId: string, fencingToken: string, expiresAt: string, controlKey: string): SignedLeaseUpdate;
|
|
9
|
+
export declare class MonotonicLeaseDeadline {
|
|
10
|
+
readonly dispatchAttemptId: string;
|
|
11
|
+
readonly fencingToken: string;
|
|
12
|
+
private readonly controlKey;
|
|
13
|
+
private expiresAtMs;
|
|
14
|
+
private deadlineMs;
|
|
15
|
+
constructor(dispatchAttemptId: string, fencingToken: string, initialExpiresAt: string, controlKey: string, wallNowMs?: number, monotonicNowMs?: number);
|
|
16
|
+
apply(update: unknown, wallNowMs?: number, monotonicNowMs?: number): boolean;
|
|
17
|
+
expired(monotonicNowMs?: number): boolean;
|
|
18
|
+
}
|