@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,218 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { GitClient } from "../shared/git/git.js";
|
|
5
|
+
import { hostRuntimeContractPath, loadHostRuntimeContract } from "./host-runtime-contract.js";
|
|
6
|
+
import { hostRuntimeContractFingerprint } from "./host-runtime-promotion.js";
|
|
7
|
+
import { readCanonicalSourceFile } from "./canonical-source-file.js";
|
|
8
|
+
import { assertCanonicalDirectory } from "./attempt-private-directory.js";
|
|
9
|
+
import { generatedOutputRootForPath } from "./generated-output-reset.js";
|
|
10
|
+
import { readPinnedSourceDirectory } from "./pinned-source-directory.js";
|
|
11
|
+
/** Bind evidence to the prepared source, including unstaged replacements, not just HEAD. */
|
|
12
|
+
export async function preparedRuntimeIdentity(worktreePath, signal, diagnostics) {
|
|
13
|
+
diagnostics?.entries.clear();
|
|
14
|
+
const root = await fs.realpath(worktreePath);
|
|
15
|
+
const rootIdentity = (await assertCanonicalDirectory(root));
|
|
16
|
+
const sourceKey = (target) => process.platform === "win32" ? target.toLowerCase() : target;
|
|
17
|
+
const expectedEntries = new Map();
|
|
18
|
+
const directories = new Map();
|
|
19
|
+
const containedRelative = (target) => {
|
|
20
|
+
const relative = path.relative(root, path.resolve(target));
|
|
21
|
+
if (relative.startsWith("..") || path.isAbsolute(relative)) {
|
|
22
|
+
throw new Error("host_runtime_source_invalid: source path escapes the worktree.");
|
|
23
|
+
}
|
|
24
|
+
return relative.replaceAll("\\", "/");
|
|
25
|
+
};
|
|
26
|
+
const directorySnapshot = async (target) => {
|
|
27
|
+
const resolved = path.resolve(target);
|
|
28
|
+
containedRelative(resolved);
|
|
29
|
+
const key = sourceKey(resolved);
|
|
30
|
+
let captured = directories.get(key);
|
|
31
|
+
if (!captured) {
|
|
32
|
+
captured = (async () => {
|
|
33
|
+
let identity;
|
|
34
|
+
if (key === sourceKey(root))
|
|
35
|
+
identity = rootIdentity;
|
|
36
|
+
else {
|
|
37
|
+
const parent = await expectedEntry(resolved);
|
|
38
|
+
if (!parent || parent.kind !== "directory") {
|
|
39
|
+
throw new Error("host_runtime_source_changed: discovery directory identity changed.");
|
|
40
|
+
}
|
|
41
|
+
identity = parent.identity;
|
|
42
|
+
}
|
|
43
|
+
const entries = await readPinnedSourceDirectory(resolved, identity);
|
|
44
|
+
for (const entry of entries)
|
|
45
|
+
expectedEntries.set(sourceKey(path.join(resolved, entry.name)), entry);
|
|
46
|
+
return { path: resolved, identity, entries };
|
|
47
|
+
})();
|
|
48
|
+
directories.set(key, captured);
|
|
49
|
+
}
|
|
50
|
+
return (await captured).entries.map(entry => ({
|
|
51
|
+
name: entry.name,
|
|
52
|
+
isDirectory: entry.kind === "directory",
|
|
53
|
+
isFile: entry.kind === "file",
|
|
54
|
+
}));
|
|
55
|
+
};
|
|
56
|
+
const expectedEntry = async (target) => {
|
|
57
|
+
const resolved = path.resolve(target);
|
|
58
|
+
containedRelative(resolved);
|
|
59
|
+
if (sourceKey(resolved) === sourceKey(root)) {
|
|
60
|
+
return { name: path.basename(root), kind: "directory", identity: rootIdentity, size: 0n };
|
|
61
|
+
}
|
|
62
|
+
const parentPath = path.dirname(resolved);
|
|
63
|
+
if (sourceKey(parentPath) !== sourceKey(root)) {
|
|
64
|
+
const parent = await expectedEntry(parentPath);
|
|
65
|
+
if (!parent)
|
|
66
|
+
return undefined;
|
|
67
|
+
if (parent.kind !== "directory") {
|
|
68
|
+
throw new Error("host_runtime_source_changed: discovery ancestor is not a directory.");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
await directorySnapshot(parentPath);
|
|
72
|
+
return expectedEntries.get(sourceKey(resolved));
|
|
73
|
+
};
|
|
74
|
+
// Pin the worktree before Git or discovery uses it. Every child directory is
|
|
75
|
+
// subsequently reached through an identity captured from its pinned parent.
|
|
76
|
+
await directorySnapshot(root);
|
|
77
|
+
const git = new GitClient();
|
|
78
|
+
const head = (await git.run(root, ["rev-parse", "HEAD"])).trim();
|
|
79
|
+
const inventory = async () => {
|
|
80
|
+
const included = (name) => name && (!name.startsWith(".forge/") || name === ".forge/forge.runtime.yml");
|
|
81
|
+
// ls-files --deleted loses a deletion once staged. HEAD-relative tombstones
|
|
82
|
+
// keep the same prepared source identity before and after git add -u.
|
|
83
|
+
const deleted = [...new Set((await git.run(root, ["ls-files", "-z", "--deleted"]))
|
|
84
|
+
.split("\0").concat((await git.run(root, ["diff", "--name-only", "--diff-filter=D", "-z", "HEAD", "--"]))
|
|
85
|
+
.split("\0")).filter(included))].sort();
|
|
86
|
+
const tracked = (await git.run(root, ["ls-files", "-z", "--cached"]))
|
|
87
|
+
.split("\0").filter(included);
|
|
88
|
+
const untracked = (await git.run(root, ["ls-files", "-z", "--others", "--exclude-standard"]))
|
|
89
|
+
.split("\0").filter(included);
|
|
90
|
+
const generatedRoots = [...new Set(untracked
|
|
91
|
+
.map(generatedOutputRootForPath)
|
|
92
|
+
.filter((candidate) => candidate !== null))];
|
|
93
|
+
const comparisonKey = (value) => process.platform === "win32" ? value.toLowerCase() : value;
|
|
94
|
+
const containedBy = (name, candidate) => {
|
|
95
|
+
const key = comparisonKey(name);
|
|
96
|
+
const rootKey = comparisonKey(candidate);
|
|
97
|
+
return key === rootKey || key.startsWith(`${rootKey}/`);
|
|
98
|
+
};
|
|
99
|
+
// resetGeneratedOutputs only quarantines a generated directory when Git
|
|
100
|
+
// confirms it contains no tracked files. Mirror that boundary here so the
|
|
101
|
+
// cleanup performed by runtime.start cannot invalidate its own foreground
|
|
102
|
+
// proof, while tracked or mixed-content directories remain source-bound.
|
|
103
|
+
const resettableRoots = generatedRoots.filter(candidate => !tracked.some(name => containedBy(name, candidate)));
|
|
104
|
+
const names = [...new Set(tracked.concat(untracked.filter(name => !resettableRoots.some(candidate => containedBy(name, candidate))), deleted, hostRuntimeContractPath).filter(included))].sort();
|
|
105
|
+
return { names, deleted };
|
|
106
|
+
};
|
|
107
|
+
const source = await inventory();
|
|
108
|
+
const { names } = source;
|
|
109
|
+
if (names.length > 100_000)
|
|
110
|
+
throw new Error("host_runtime_source_invalid: source inventory exceeds the file limit.");
|
|
111
|
+
const deleted = new Set(source.deleted);
|
|
112
|
+
const hash = createHash("sha256");
|
|
113
|
+
const snapshot = new Map();
|
|
114
|
+
const additional = new Map();
|
|
115
|
+
let discoveryCapture = Promise.resolve();
|
|
116
|
+
let bytes = 0;
|
|
117
|
+
for (const name of names) {
|
|
118
|
+
signal?.throwIfAborted();
|
|
119
|
+
const target = path.resolve(root, name);
|
|
120
|
+
const relative = path.relative(root, target);
|
|
121
|
+
if (relative.startsWith("..") || path.isAbsolute(relative)) {
|
|
122
|
+
throw new Error("host_runtime_source_invalid: source path escapes the worktree.");
|
|
123
|
+
}
|
|
124
|
+
hash.update(JSON.stringify(name));
|
|
125
|
+
try {
|
|
126
|
+
const expected = await expectedEntry(target);
|
|
127
|
+
if (!expected || expected.kind !== "file") {
|
|
128
|
+
throw Object.assign(new Error("host_runtime_source_changed: source inventory no longer names an ordinary file."), { code: "ENOENT" });
|
|
129
|
+
}
|
|
130
|
+
const sourceBytes = await readCanonicalSourceFile(target, 256 * 1024 * 1024 - bytes, expected.identity);
|
|
131
|
+
bytes += sourceBytes.length;
|
|
132
|
+
const digest = createHash("sha256").update(sourceBytes).digest();
|
|
133
|
+
hash.update(digest);
|
|
134
|
+
diagnostics?.entries.set(name, digest.toString("hex"));
|
|
135
|
+
snapshot.set(sourceKey(target), Promise.resolve(sourceBytes));
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
if (error.code !== "ENOENT" || (!deleted.has(name) && name !== hostRuntimeContractPath))
|
|
139
|
+
throw error;
|
|
140
|
+
const disposition = deleted.has(name) ? "deleted" : "absent";
|
|
141
|
+
hash.update(disposition);
|
|
142
|
+
diagnostics?.entries.set(name, disposition);
|
|
143
|
+
snapshot.set(sourceKey(target), Promise.resolve(null));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const contract = await loadHostRuntimeContract(root, target => {
|
|
147
|
+
const key = sourceKey(path.resolve(target));
|
|
148
|
+
const captured = snapshot.get(key);
|
|
149
|
+
if (captured)
|
|
150
|
+
return captured;
|
|
151
|
+
// Discovery also consumes ignored lockfiles and launch metadata. Capture
|
|
152
|
+
// those once, too; omission from Git's inventory must not change discovery.
|
|
153
|
+
const capture = discoveryCapture.then(async () => {
|
|
154
|
+
signal?.throwIfAborted();
|
|
155
|
+
const relative = path.relative(root, target).replaceAll("\\", "/");
|
|
156
|
+
if (relative.startsWith("..") || path.isAbsolute(relative)) {
|
|
157
|
+
throw new Error("host_runtime_source_invalid: discovery input escapes the worktree.");
|
|
158
|
+
}
|
|
159
|
+
let sourceBytes;
|
|
160
|
+
try {
|
|
161
|
+
const expected = await expectedEntry(target);
|
|
162
|
+
if (!expected)
|
|
163
|
+
sourceBytes = null;
|
|
164
|
+
else if (expected.kind !== "file") {
|
|
165
|
+
throw new Error("host_runtime_source_changed: discovery input is not an ordinary file.");
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
sourceBytes = await readCanonicalSourceFile(target, 256 * 1024 * 1024 - bytes, expected.identity);
|
|
169
|
+
}
|
|
170
|
+
if (sourceBytes !== null) {
|
|
171
|
+
bytes += sourceBytes.length;
|
|
172
|
+
if (bytes > 256 * 1024 * 1024)
|
|
173
|
+
throw new Error("host_runtime_source_invalid: discovery exceeds the byte limit.");
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
if (error.code !== "ENOENT")
|
|
178
|
+
throw error;
|
|
179
|
+
sourceBytes = null;
|
|
180
|
+
}
|
|
181
|
+
additional.set(relative, sourceBytes);
|
|
182
|
+
return sourceBytes;
|
|
183
|
+
});
|
|
184
|
+
// Discovery walks in parallel, but reads share one total byte budget.
|
|
185
|
+
discoveryCapture = capture.then(() => undefined, () => undefined);
|
|
186
|
+
snapshot.set(key, capture);
|
|
187
|
+
return capture;
|
|
188
|
+
}, directorySnapshot);
|
|
189
|
+
for (const [name, sourceBytes] of [...additional].sort(([left], [right]) => left.localeCompare(right))) {
|
|
190
|
+
hash.update(JSON.stringify(["runtime-discovery", name]));
|
|
191
|
+
const digest = sourceBytes === null
|
|
192
|
+
? null
|
|
193
|
+
: createHash("sha256").update(sourceBytes).digest();
|
|
194
|
+
hash.update(digest ?? "absent");
|
|
195
|
+
diagnostics?.entries.set(`runtime-discovery:${name}`, digest?.toString("hex") ?? "absent");
|
|
196
|
+
}
|
|
197
|
+
if (head !== (await git.run(root, ["rev-parse", "HEAD"])).trim()
|
|
198
|
+
|| JSON.stringify(source) !== JSON.stringify(await inventory())) {
|
|
199
|
+
throw new Error("host_runtime_source_changed: prepared source changed during verification.");
|
|
200
|
+
}
|
|
201
|
+
for (const captured of await Promise.all([...directories.values()])) {
|
|
202
|
+
const current = await readPinnedSourceDirectory(captured.path, captured.identity);
|
|
203
|
+
if (directoryInventory(current) !== directoryInventory(captured.entries)) {
|
|
204
|
+
throw new Error("host_runtime_source_changed: runtime discovery inventory changed during verification.");
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
inputCommitSha: head,
|
|
209
|
+
runtimeContractFingerprint: hostRuntimeContractFingerprint(contract),
|
|
210
|
+
sourceFingerprint: `sha256:${hash.digest("hex")}`,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function directoryInventory(entries) {
|
|
214
|
+
return JSON.stringify(entries.map(entry => ({
|
|
215
|
+
name: entry.name,
|
|
216
|
+
kind: entry.kind,
|
|
217
|
+
})));
|
|
218
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { RunOnceDispatchPacket } from "../session/session.types.js";
|
|
2
|
+
import type { HostRuntimeAdmissionCheckpointHandler, HostRuntimeLeaseRuntime } from "./host-runtime-lease.js";
|
|
3
|
+
import { HostParallelPromotionStore, type HostParallelProofIdentity } from "./host-runtime-promotion.js";
|
|
4
|
+
export interface PreparedRuntimePendingSnapshot {
|
|
5
|
+
readonly repoId: string;
|
|
6
|
+
readonly dispatchAttemptId: string;
|
|
7
|
+
readonly fencingToken: string;
|
|
8
|
+
readonly probeDispatchAttemptId?: string;
|
|
9
|
+
readonly probeFencingToken?: string;
|
|
10
|
+
}
|
|
11
|
+
/** Foreground barrier: prepare a wave, verify its exact runtimes, then release agents. */
|
|
12
|
+
export declare class PreparedRuntimeReadiness {
|
|
13
|
+
private readonly runtime;
|
|
14
|
+
private readonly store;
|
|
15
|
+
private readonly releasePreparation;
|
|
16
|
+
private readonly admissionExpired;
|
|
17
|
+
private readonly preparations;
|
|
18
|
+
private readonly draining;
|
|
19
|
+
constructor(runtime: HostRuntimeLeaseRuntime, store: HostParallelPromotionStore, releasePreparation: (id: string, fence: string) => Promise<unknown>, admissionExpired: () => Error);
|
|
20
|
+
acquire(dispatch: RunOnceDispatchPacket, signal?: AbortSignal): Promise<readonly string[]>;
|
|
21
|
+
has(id: string): boolean;
|
|
22
|
+
hasPending(): boolean;
|
|
23
|
+
pendingSnapshots(): readonly PreparedRuntimePendingSnapshot[];
|
|
24
|
+
verify(dispatch: RunOnceDispatchPacket, worktree: string, checkpoint?: HostRuntimeAdmissionCheckpointHandler): Promise<HostParallelProofIdentity | undefined>;
|
|
25
|
+
renew(id: string, fence: string, expiresAt: string): Promise<void>;
|
|
26
|
+
cancel(id: string, fence: string, reason?: Error): void;
|
|
27
|
+
private drain;
|
|
28
|
+
private scheduleDeadline;
|
|
29
|
+
private check;
|
|
30
|
+
}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { GitClient } from "../shared/git/git.js";
|
|
3
|
+
import { loadHostRuntimeContract } from "./host-runtime-contract.js";
|
|
4
|
+
import { configuredLaunchPortNames, hostRuntimeContractFingerprint, hostRuntimeParallelEligible } from "./host-runtime-promotion.js";
|
|
5
|
+
import { preparedRuntimeIdentity } from "./prepared-runtime-identity.js";
|
|
6
|
+
/** Foreground barrier: prepare a wave, verify its exact runtimes, then release agents. */
|
|
7
|
+
export class PreparedRuntimeReadiness {
|
|
8
|
+
runtime;
|
|
9
|
+
store;
|
|
10
|
+
releasePreparation;
|
|
11
|
+
admissionExpired;
|
|
12
|
+
preparations = new Map();
|
|
13
|
+
draining = new Set();
|
|
14
|
+
constructor(runtime, store, releasePreparation, admissionExpired) {
|
|
15
|
+
this.runtime = runtime;
|
|
16
|
+
this.store = store;
|
|
17
|
+
this.releasePreparation = releasePreparation;
|
|
18
|
+
this.admissionExpired = admissionExpired;
|
|
19
|
+
}
|
|
20
|
+
async acquire(dispatch, signal) {
|
|
21
|
+
const id = dispatch.sandbox.dispatchAttemptId;
|
|
22
|
+
if (this.preparations.has(id))
|
|
23
|
+
throw new Error("host_runtime_preparation_conflict: duplicate preparation.");
|
|
24
|
+
const controller = new AbortController();
|
|
25
|
+
const abort = () => this.cancel(id, dispatch.lease.fencingToken);
|
|
26
|
+
const entry = { dispatch, controller, phase: "preparing", expiresAt: dispatch.lease.expiresAt,
|
|
27
|
+
removeAbort: () => signal?.removeEventListener("abort", abort) };
|
|
28
|
+
this.preparations.set(id, entry);
|
|
29
|
+
this.scheduleDeadline(entry);
|
|
30
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
31
|
+
if (signal?.aborted)
|
|
32
|
+
abort();
|
|
33
|
+
try {
|
|
34
|
+
// Preparation consumes normal capacity, but no project-runtime claim.
|
|
35
|
+
return await this.runtime.acquire({ ...dispatch,
|
|
36
|
+
runtimeIntent: { ...dispatch.runtimeIntent, executionClass: "analysis_only", applicationRuntimeRequired: false },
|
|
37
|
+
}, controller.signal);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
const failure = controller.signal.aborted ? controller.signal.reason : error;
|
|
41
|
+
this.cancel(id, dispatch.lease.fencingToken);
|
|
42
|
+
throw failure;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
has(id) { return this.preparations.has(id); }
|
|
46
|
+
hasPending() { return this.preparations.size > 0; }
|
|
47
|
+
pendingSnapshots() {
|
|
48
|
+
return [...this.preparations.values()].map(entry => ({
|
|
49
|
+
repoId: entry.dispatch.repo.id,
|
|
50
|
+
dispatchAttemptId: entry.dispatch.sandbox.dispatchAttemptId,
|
|
51
|
+
fencingToken: entry.dispatch.lease.fencingToken,
|
|
52
|
+
...(entry.probe
|
|
53
|
+
? {
|
|
54
|
+
probeDispatchAttemptId: entry.probe.sandbox.dispatchAttemptId,
|
|
55
|
+
probeFencingToken: entry.probe.lease.fencingToken,
|
|
56
|
+
}
|
|
57
|
+
: {}),
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
async verify(dispatch, worktree, checkpoint) {
|
|
61
|
+
const id = dispatch.sandbox.dispatchAttemptId;
|
|
62
|
+
const entry = this.preparations.get(id);
|
|
63
|
+
if (!entry || entry.dispatch.lease.fencingToken !== dispatch.lease.fencingToken) {
|
|
64
|
+
throw new Error("host_runtime_preparation_missing: preparation ownership changed.");
|
|
65
|
+
}
|
|
66
|
+
// Release preparation headroom before waiting for peers; otherwise a one-slot
|
|
67
|
+
// host would deadlock while the rest of the wave tries to prepare.
|
|
68
|
+
await this.releasePreparation(id, dispatch.lease.fencingToken);
|
|
69
|
+
entry.controller.signal.throwIfAborted();
|
|
70
|
+
const completion = new Promise((resolve, reject) => {
|
|
71
|
+
entry.resolve = resolve;
|
|
72
|
+
entry.reject = reject;
|
|
73
|
+
});
|
|
74
|
+
entry.check = () => this.check(entry, worktree, checkpoint);
|
|
75
|
+
entry.phase = "queued";
|
|
76
|
+
void this.drain(dispatch.repo.id);
|
|
77
|
+
return await completion;
|
|
78
|
+
}
|
|
79
|
+
async renew(id, fence, expiresAt) {
|
|
80
|
+
const entry = this.preparations.get(id);
|
|
81
|
+
if (!entry || entry.dispatch.lease.fencingToken !== fence || Date.parse(expiresAt) <= Date.parse(entry.expiresAt))
|
|
82
|
+
return;
|
|
83
|
+
entry.expiresAt = expiresAt;
|
|
84
|
+
this.scheduleDeadline(entry);
|
|
85
|
+
if (entry.probe)
|
|
86
|
+
await this.runtime.updateLease(entry.probe.sandbox.dispatchAttemptId, entry.probe.lease.fencingToken, expiresAt);
|
|
87
|
+
}
|
|
88
|
+
cancel(id, fence, reason = new Error("host_runtime_preparation_cancelled: prepared readiness was cancelled.")) {
|
|
89
|
+
const entry = this.preparations.get(id);
|
|
90
|
+
if (!entry || entry.dispatch.lease.fencingToken !== fence)
|
|
91
|
+
return;
|
|
92
|
+
if (entry.deadline)
|
|
93
|
+
clearTimeout(entry.deadline);
|
|
94
|
+
entry.controller.abort(reason);
|
|
95
|
+
// Do not return to session teardown while a supervised probe still owns the worktree.
|
|
96
|
+
if (entry.phase === "checking")
|
|
97
|
+
return;
|
|
98
|
+
entry.reject?.(entry.controller.signal.reason);
|
|
99
|
+
entry.removeAbort();
|
|
100
|
+
this.preparations.delete(id);
|
|
101
|
+
void this.drain(entry.dispatch.repo.id);
|
|
102
|
+
}
|
|
103
|
+
async drain(repoId) {
|
|
104
|
+
if (this.draining.has(repoId))
|
|
105
|
+
return;
|
|
106
|
+
const entries = () => [...this.preparations.values()].filter(entry => entry.dispatch.repo.id === repoId);
|
|
107
|
+
if (entries().some(entry => entry.phase === "preparing"))
|
|
108
|
+
return;
|
|
109
|
+
this.draining.add(repoId);
|
|
110
|
+
const completed = [];
|
|
111
|
+
try {
|
|
112
|
+
for (const entry of entries()) {
|
|
113
|
+
if (entry.phase !== "queued")
|
|
114
|
+
continue;
|
|
115
|
+
entry.phase = "checking";
|
|
116
|
+
try {
|
|
117
|
+
completed.push({ entry, identity: await entry.check() });
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
completed.push({ entry, error });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// No provider from this wave can start while a sibling proof is running.
|
|
124
|
+
for (const result of completed) {
|
|
125
|
+
const { entry } = result;
|
|
126
|
+
this.preparations.delete(entry.dispatch.sandbox.dispatchAttemptId);
|
|
127
|
+
if (entry.deadline)
|
|
128
|
+
clearTimeout(entry.deadline);
|
|
129
|
+
entry.removeAbort();
|
|
130
|
+
if (entry.controller.signal.aborted)
|
|
131
|
+
entry.reject?.(entry.controller.signal.reason);
|
|
132
|
+
else if (result.error)
|
|
133
|
+
entry.reject?.(result.error);
|
|
134
|
+
else
|
|
135
|
+
entry.resolve?.(result.identity);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
finally {
|
|
139
|
+
this.draining.delete(repoId);
|
|
140
|
+
if (entries().some(entry => entry.phase === "queued"))
|
|
141
|
+
void this.drain(repoId);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
scheduleDeadline(entry) {
|
|
145
|
+
if (entry.deadline)
|
|
146
|
+
clearTimeout(entry.deadline);
|
|
147
|
+
const delay = Date.parse(entry.expiresAt) - Date.now();
|
|
148
|
+
entry.deadline = setTimeout(() => this.cancel(entry.dispatch.sandbox.dispatchAttemptId, entry.dispatch.lease.fencingToken, this.admissionExpired()), Number.isFinite(delay) ? Math.max(0, Math.min(delay, 2_147_483_647)) : 0);
|
|
149
|
+
entry.deadline.unref();
|
|
150
|
+
}
|
|
151
|
+
async check(entry, worktree, checkpoint) {
|
|
152
|
+
const { dispatch, controller } = entry;
|
|
153
|
+
if (!dispatch.runtimeIntent.applicationRuntimeRequired)
|
|
154
|
+
return undefined;
|
|
155
|
+
const contract = await loadHostRuntimeContract(worktree);
|
|
156
|
+
if (!hostRuntimeParallelEligible(contract))
|
|
157
|
+
return undefined;
|
|
158
|
+
const preparedDiagnostics = { entries: new Map() };
|
|
159
|
+
const identity = await preparedRuntimeIdentity(worktree, controller.signal, preparedDiagnostics);
|
|
160
|
+
if (hostRuntimeContractFingerprint(contract) !== identity.runtimeContractFingerprint) {
|
|
161
|
+
throw new Error("host_runtime_prepared_source_changed: runtime contract changed while capturing its source identity.");
|
|
162
|
+
}
|
|
163
|
+
if (await this.store.load(dispatch.repo.id, identity))
|
|
164
|
+
return identity;
|
|
165
|
+
await checkpoint?.({ code: "host_runtime_prepared_probe_started", expiresAt: entry.expiresAt,
|
|
166
|
+
message: `Verifying prepared runtime ${identity.inputCommitSha.slice(0, 12)} before agent admission; project-default readiness is not a substitute.` });
|
|
167
|
+
const probeId = randomUUID();
|
|
168
|
+
const probe = { ...dispatch,
|
|
169
|
+
cycleRun: { ...dispatch.cycleRun, phase: "prepared_readiness" },
|
|
170
|
+
lease: { ...dispatch.lease, id: probeId, fencingToken: randomUUID(), expiresAt: entry.expiresAt },
|
|
171
|
+
sandbox: { ...dispatch.sandbox, dispatchAttemptId: probeId, executionLeaseId: probeId,
|
|
172
|
+
inputCommitSha: identity.inputCommitSha },
|
|
173
|
+
};
|
|
174
|
+
entry.probe = probe;
|
|
175
|
+
const stopPreparedHeadMonitor = new AbortController();
|
|
176
|
+
const preparedHeadMonitor = monitorPreparedHead(worktree, identity.inputCommitSha, controller, stopPreparedHeadMonitor.signal);
|
|
177
|
+
let cleanupConfirmed;
|
|
178
|
+
let verifiedRuntimeContractFingerprint;
|
|
179
|
+
let verifiedPorts;
|
|
180
|
+
try {
|
|
181
|
+
controller.signal.throwIfAborted();
|
|
182
|
+
await this.runtime.acquire(probe, controller.signal);
|
|
183
|
+
const prepared = await this.runtime.start(probe, worktree, controller.signal);
|
|
184
|
+
if (hostRuntimeContractFingerprint(prepared.runtimeContract) !== identity.runtimeContractFingerprint) {
|
|
185
|
+
throw new Error("host_runtime_prepared_source_changed: probe loaded a different runtime contract; application was not started.");
|
|
186
|
+
}
|
|
187
|
+
const started = await this.runtime.startConfiguredProject(probeId, probe.lease.fencingToken, controller.signal, progress => checkpoint?.({ code: "host_runtime_prepared_probe_progress", expiresAt: entry.expiresAt,
|
|
188
|
+
message: progress.message }));
|
|
189
|
+
verifiedRuntimeContractFingerprint = hostRuntimeContractFingerprint(started.runtimeContract);
|
|
190
|
+
verifiedPorts = started.lease.resources.ports.map(port => port.name).sort();
|
|
191
|
+
}
|
|
192
|
+
finally {
|
|
193
|
+
stopPreparedHeadMonitor.abort();
|
|
194
|
+
await preparedHeadMonitor;
|
|
195
|
+
// A failed teardown must not publish reusable evidence.
|
|
196
|
+
cleanupConfirmed = Boolean(await this.runtime.release(probeId, probe.lease.fencingToken));
|
|
197
|
+
entry.probe = undefined;
|
|
198
|
+
}
|
|
199
|
+
if (!cleanupConfirmed) {
|
|
200
|
+
throw new Error("host_runtime_prepared_probe_cleanup_unconfirmed: matching probe teardown was not confirmed.");
|
|
201
|
+
}
|
|
202
|
+
// Probe-owned processes may create transient, untracked files while they
|
|
203
|
+
// are alive. Verify the prepared source only after matching teardown is
|
|
204
|
+
// confirmed: persistent source edits still fail closed, while files that
|
|
205
|
+
// belong to the probe lifecycle cannot create a false source-change loop.
|
|
206
|
+
const currentDiagnostics = { entries: new Map() };
|
|
207
|
+
const currentIdentity = await preparedRuntimeIdentity(worktree, controller.signal, currentDiagnostics);
|
|
208
|
+
const changed = [];
|
|
209
|
+
if (verifiedRuntimeContractFingerprint !== identity.runtimeContractFingerprint
|
|
210
|
+
|| currentIdentity.runtimeContractFingerprint !== identity.runtimeContractFingerprint) {
|
|
211
|
+
changed.push("runtime contract");
|
|
212
|
+
}
|
|
213
|
+
if (currentIdentity.inputCommitSha !== identity.inputCommitSha)
|
|
214
|
+
changed.push("HEAD");
|
|
215
|
+
if (currentIdentity.sourceFingerprint !== identity.sourceFingerprint) {
|
|
216
|
+
const paths = changedIdentityPaths(preparedDiagnostics.entries, currentDiagnostics.entries);
|
|
217
|
+
changed.push(paths.length > 0
|
|
218
|
+
? `source fingerprint (${paths.join(", ")})`
|
|
219
|
+
: "source fingerprint");
|
|
220
|
+
}
|
|
221
|
+
if (changed.length > 0) {
|
|
222
|
+
throw new Error(`host_runtime_prepared_source_changed: ${changed.join(", ")} changed during isolation verification.`);
|
|
223
|
+
}
|
|
224
|
+
if (JSON.stringify(verifiedPorts) !== JSON.stringify(configuredLaunchPortNames(contract))) {
|
|
225
|
+
throw new Error("host_runtime_prepared_probe_incomplete: assigned-port verification did not confirm every configured launch port.");
|
|
226
|
+
}
|
|
227
|
+
controller.signal.throwIfAborted();
|
|
228
|
+
await this.store.observe(dispatch.repo.id, contract, probeId, configuredLaunchPortNames(contract), identity.inputCommitSha, identity.sourceFingerprint);
|
|
229
|
+
await checkpoint?.({ code: "host_runtime_prepared_probe_completed", expiresAt: entry.expiresAt,
|
|
230
|
+
message: `Prepared runtime ${identity.inputCommitSha.slice(0, 12)} passed isolation verification; its source-bound proof is retained independently.` });
|
|
231
|
+
return identity;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const preparedHeadPollIntervalMs = 1_000;
|
|
235
|
+
async function monitorPreparedHead(worktree, expectedCommitSha, preparationController, stopSignal) {
|
|
236
|
+
const git = new GitClient();
|
|
237
|
+
while (!stopSignal.aborted && !preparationController.signal.aborted) {
|
|
238
|
+
try {
|
|
239
|
+
const currentCommitSha = (await git.run(worktree, ["rev-parse", "--verify", "HEAD^{commit}"]))
|
|
240
|
+
.trim()
|
|
241
|
+
.toLowerCase();
|
|
242
|
+
if (currentCommitSha !== expectedCommitSha.toLowerCase()) {
|
|
243
|
+
throw new Error("host_runtime_prepared_source_changed: HEAD changed during isolation verification; the obsolete probe was cancelled.");
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
if (!stopSignal.aborted && !preparationController.signal.aborted) {
|
|
248
|
+
const failure = error instanceof Error && error.message.startsWith("host_runtime_prepared_source_changed:")
|
|
249
|
+
? error
|
|
250
|
+
: new Error(`host_runtime_prepared_source_changed: HEAD could not be revalidated during isolation verification: ${errorMessage(error)}`);
|
|
251
|
+
preparationController.abort(failure);
|
|
252
|
+
}
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
await waitForPreparedHeadPoll(stopSignal);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
async function waitForPreparedHeadPoll(signal) {
|
|
259
|
+
if (signal.aborted)
|
|
260
|
+
return;
|
|
261
|
+
await new Promise(resolve => {
|
|
262
|
+
const complete = () => {
|
|
263
|
+
clearTimeout(timer);
|
|
264
|
+
signal.removeEventListener("abort", complete);
|
|
265
|
+
resolve();
|
|
266
|
+
};
|
|
267
|
+
const timer = setTimeout(complete, preparedHeadPollIntervalMs);
|
|
268
|
+
timer.unref();
|
|
269
|
+
signal.addEventListener("abort", complete, { once: true });
|
|
270
|
+
if (signal.aborted)
|
|
271
|
+
complete();
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
function errorMessage(error) {
|
|
275
|
+
return error instanceof Error ? error.message : String(error);
|
|
276
|
+
}
|
|
277
|
+
function changedIdentityPaths(before, after) {
|
|
278
|
+
const paths = new Set([...before.keys(), ...after.keys()]);
|
|
279
|
+
const changed = [...paths]
|
|
280
|
+
.filter(path => before.get(path) !== after.get(path))
|
|
281
|
+
.sort((left, right) => left.localeCompare(right));
|
|
282
|
+
if (changed.length <= 8)
|
|
283
|
+
return changed;
|
|
284
|
+
return [...changed.slice(0, 8), `+${changed.length - 8} more`];
|
|
285
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { type HostLoadGovernorMode } from "./host-load-governor-config.js";
|
|
2
|
+
export declare const runnerSettingKeys: readonly ["maxConcurrentAttempts", "cpuBudgetPercent", "yieldCpuBudgetPercent", "memoryReserveBytes", "maxHeavySteps", "yieldToForeground"];
|
|
3
|
+
export type RunnerSettingKey = typeof runnerSettingKeys[number];
|
|
4
|
+
/** The `ApplySettings` hub message. Null numeric fields mean "no server value": keep today's env/default behaviour. */
|
|
5
|
+
export interface RunnerSettingsDocument {
|
|
6
|
+
readonly runnerId: string | null;
|
|
7
|
+
readonly version: number;
|
|
8
|
+
readonly maxConcurrentAttempts: number | null;
|
|
9
|
+
readonly cpuBudgetPercent: number | null;
|
|
10
|
+
readonly yieldCpuBudgetPercent: number | null;
|
|
11
|
+
readonly memoryReserveBytes: number | null;
|
|
12
|
+
readonly maxHeavySteps: number | null;
|
|
13
|
+
readonly yieldToForeground: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface RunnerSettingsValues {
|
|
16
|
+
readonly maxConcurrentAttempts: number;
|
|
17
|
+
readonly cpuBudgetPercent: number;
|
|
18
|
+
readonly yieldCpuBudgetPercent: number;
|
|
19
|
+
readonly memoryReserveBytes: number;
|
|
20
|
+
/** Null: the governor's budget alone limits heavy steps (no count limit). */
|
|
21
|
+
readonly maxHeavySteps: number | null;
|
|
22
|
+
readonly yieldToForeground: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Where an effective value came from: the server's value as is, the bridge default,
|
|
26
|
+
* an env var that capped/floored the server value or supplied it, or the host's
|
|
27
|
+
* `forge-bridge yield on` flag.
|
|
28
|
+
*/
|
|
29
|
+
export type RunnerSettingSource = "server" | "default" | "host_env" | "host_local";
|
|
30
|
+
export interface RunnerSettingBound {
|
|
31
|
+
readonly key: RunnerSettingKey;
|
|
32
|
+
readonly envVar: string;
|
|
33
|
+
readonly value: number;
|
|
34
|
+
readonly kind: "ceiling" | "floor";
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Why a key was rejected. `invalid`: the server value is outside the contract, so
|
|
38
|
+
* the host default applies (version skew; it never holds placement). `apply_failed`:
|
|
39
|
+
* the host could not put the value in force, so the previous value stays in force
|
|
40
|
+
* and the server holds placement until a later apply succeeds. Clamping by an env
|
|
41
|
+
* bound is neither: it is a `bound` and a `host_env` source.
|
|
42
|
+
*/
|
|
43
|
+
export type RunnerSettingRejectionKind = "invalid" | "apply_failed";
|
|
44
|
+
export interface RunnerSettingRejection {
|
|
45
|
+
readonly key: RunnerSettingKey;
|
|
46
|
+
readonly reason: string;
|
|
47
|
+
readonly kind: RunnerSettingRejectionKind;
|
|
48
|
+
}
|
|
49
|
+
/** The `SettingsApplied` report; also carried in the capabilities `settings` block (schema 8). */
|
|
50
|
+
export interface RunnerSettingsReport {
|
|
51
|
+
/** The applied document version, or null before any ApplySettings was applied. */
|
|
52
|
+
readonly version: number | null;
|
|
53
|
+
/** FORGE_HOST_LOAD_GOVERNOR: CPU budget, yield budget and heavy steps only take effect when on. */
|
|
54
|
+
readonly governor: HostLoadGovernorMode;
|
|
55
|
+
readonly values: RunnerSettingsValues;
|
|
56
|
+
readonly sources: Readonly<Record<RunnerSettingKey, RunnerSettingSource>>;
|
|
57
|
+
readonly bounds: readonly RunnerSettingBound[];
|
|
58
|
+
readonly rejected: readonly RunnerSettingRejection[];
|
|
59
|
+
}
|
|
60
|
+
/** Today's bridge defaults for the keys whose default depends on the host. */
|
|
61
|
+
export interface RunnerHostDefaults {
|
|
62
|
+
/** floor(threads / 2) capped at 8 (at least 1). */
|
|
63
|
+
readonly maxConcurrentAttempts: number;
|
|
64
|
+
/** The adaptive reserve: 12.5% of RAM within 1–4 GiB, before FORGE_HOST_MEMORY_RESERVE_BYTES. */
|
|
65
|
+
readonly memoryReserveBytes: number;
|
|
66
|
+
}
|
|
67
|
+
export interface EffectiveRunnerSettings {
|
|
68
|
+
readonly report: RunnerSettingsReport;
|
|
69
|
+
/** Effective yield (server OR local flag). */
|
|
70
|
+
readonly yielding: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* The governor CPU budget in force, as a fraction of logical CPUs: the CPU budget,
|
|
73
|
+
* or min(yield budget, CPU budget) while yielding.
|
|
74
|
+
*/
|
|
75
|
+
readonly governorCpuBudgetFraction: number;
|
|
76
|
+
}
|
|
77
|
+
export declare const defaultCpuBudgetPercent = 80;
|
|
78
|
+
export declare const defaultYieldCpuBudgetPercent = 50;
|
|
79
|
+
/**
|
|
80
|
+
* Computes every effective value (decision 0014 precedence):
|
|
81
|
+
* - ceiling keys: server != null ? min(server, ceiling ?? +inf) : (ceiling ?? default);
|
|
82
|
+
* - memory reserve (floor): server != null ? max(server, floor ?? 0) : (floor ?? adaptive default);
|
|
83
|
+
* - yield: server OR the local `forge-bridge yield on` flag.
|
|
84
|
+
* With no document at all (and the local flag off) the values equal today's env/default behaviour.
|
|
85
|
+
*/
|
|
86
|
+
export declare function computeEffectiveRunnerSettings(document: RunnerSettingsDocument | null, environment: Readonly<Record<string, string | undefined>>, hostDefaults: RunnerHostDefaults, localYield: boolean): EffectiveRunnerSettings;
|
|
87
|
+
/**
|
|
88
|
+
* Parses the `ApplySettings` argument. Returns null when it has no usable version
|
|
89
|
+
* (the bridge then ignores it); malformed values become null so the host default applies.
|
|
90
|
+
*/
|
|
91
|
+
export declare function parseRunnerSettingsDocument(raw: unknown): RunnerSettingsDocument | null;
|
|
92
|
+
/**
|
|
93
|
+
* The report for what is actually in force after an apply in which the host
|
|
94
|
+
* failed to put some keys in force: each failed key keeps the value (and source)
|
|
95
|
+
* that was in force before, and its failure is reported as an `apply_failed`
|
|
96
|
+
* rejection, so the server never reads a desired value as applied.
|
|
97
|
+
*/
|
|
98
|
+
export declare function runnerSettingsInForce(report: RunnerSettingsReport, previous: RunnerSettingsReport, failures: readonly RunnerSettingRejection[]): RunnerSettingsReport;
|
|
99
|
+
/** True when two reports say the same thing (version included), so an unchanged recompute is not re-sent. */
|
|
100
|
+
export declare function sameRunnerSettingsReport(left: RunnerSettingsReport, right: RunnerSettingsReport): boolean;
|
|
101
|
+
/** The offer refusal message while the runner yields to foreground work. */
|
|
102
|
+
export declare function runnerYieldingMessage(report: RunnerSettingsReport): string;
|
|
103
|
+
/** One line describing the effective settings, for the bridge log. */
|
|
104
|
+
export declare function describeRunnerSettings(report: RunnerSettingsReport): string;
|