@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,333 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import net from "node:net";
|
|
3
|
+
export class HostPortCollisionError extends Error {
|
|
4
|
+
constructor(message = "host_port_collision: the launched process did not own its assigned loopback port.") {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "HostPortCollisionError";
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Owns runner-local loopback ports for supervised host attempts.
|
|
11
|
+
*
|
|
12
|
+
* A reservation keeps a real listening socket open until an adapter is ready to
|
|
13
|
+
* launch. The adapter then performs a narrow handoff and must prove that the
|
|
14
|
+
* supervised child owns the assigned endpoint before the reservation is active.
|
|
15
|
+
*/
|
|
16
|
+
export class HostPortBroker {
|
|
17
|
+
hostIp;
|
|
18
|
+
minimumPort;
|
|
19
|
+
maximumPort;
|
|
20
|
+
maximumLaunchAttempts;
|
|
21
|
+
reservations = new Map();
|
|
22
|
+
claimedPorts = new Map();
|
|
23
|
+
nextPort;
|
|
24
|
+
launchGate = Promise.resolve();
|
|
25
|
+
constructor(options = {}) {
|
|
26
|
+
this.hostIp = options.hostIp ?? "127.0.0.1";
|
|
27
|
+
const hasMinimum = options.minimumPort !== undefined;
|
|
28
|
+
const hasMaximum = options.maximumPort !== undefined;
|
|
29
|
+
if (hasMinimum !== hasMaximum) {
|
|
30
|
+
throw new Error("host_port_broker_invalid: minimumPort and maximumPort must be configured together.");
|
|
31
|
+
}
|
|
32
|
+
this.minimumPort = hasMinimum ? validPort(options.minimumPort, "minimumPort") : null;
|
|
33
|
+
this.maximumPort = hasMaximum ? validPort(options.maximumPort, "maximumPort") : null;
|
|
34
|
+
if (this.minimumPort !== null && this.maximumPort !== null && this.minimumPort > this.maximumPort) {
|
|
35
|
+
throw new Error("host_port_broker_invalid: minimumPort cannot exceed maximumPort.");
|
|
36
|
+
}
|
|
37
|
+
this.maximumLaunchAttempts = options.maximumLaunchAttempts ?? 3;
|
|
38
|
+
if (!Number.isSafeInteger(this.maximumLaunchAttempts) || this.maximumLaunchAttempts < 1 || this.maximumLaunchAttempts > 10) {
|
|
39
|
+
throw new Error("host_port_broker_invalid: maximumLaunchAttempts must be between 1 and 10.");
|
|
40
|
+
}
|
|
41
|
+
this.nextPort = this.minimumPort;
|
|
42
|
+
}
|
|
43
|
+
async reserve(owner, request, signal) {
|
|
44
|
+
validateOwner(owner);
|
|
45
|
+
validateRequest(request);
|
|
46
|
+
if (signal?.aborted)
|
|
47
|
+
throw cancellationError(signal);
|
|
48
|
+
const { server, port } = await this.listen(signal, new Set());
|
|
49
|
+
const now = new Date().toISOString();
|
|
50
|
+
const reservation = {
|
|
51
|
+
schemaVersion: 1,
|
|
52
|
+
reservationId: randomUUID(),
|
|
53
|
+
...owner,
|
|
54
|
+
name: request.name,
|
|
55
|
+
protocol: "tcp",
|
|
56
|
+
hostIp: this.hostIp,
|
|
57
|
+
hostPort: port,
|
|
58
|
+
targetPort: request.targetPort ?? port,
|
|
59
|
+
state: "reserved",
|
|
60
|
+
reservedAt: now,
|
|
61
|
+
handedOffAt: null,
|
|
62
|
+
activatedAt: null,
|
|
63
|
+
};
|
|
64
|
+
this.reservations.set(reservation.reservationId, { reservation, server });
|
|
65
|
+
this.claimedPorts.set(port, reservation.reservationId);
|
|
66
|
+
return reservation;
|
|
67
|
+
}
|
|
68
|
+
async handoff(reservationId, owner) {
|
|
69
|
+
const held = this.owned(reservationId, owner);
|
|
70
|
+
if (!held || held.reservation.state !== "reserved")
|
|
71
|
+
return null;
|
|
72
|
+
await closeServer(held.server);
|
|
73
|
+
held.server = null;
|
|
74
|
+
held.reservation = {
|
|
75
|
+
...held.reservation,
|
|
76
|
+
state: "handed_off",
|
|
77
|
+
handedOffAt: new Date().toISOString(),
|
|
78
|
+
};
|
|
79
|
+
return held.reservation;
|
|
80
|
+
}
|
|
81
|
+
activate(reservationId, owner) {
|
|
82
|
+
const held = this.owned(reservationId, owner);
|
|
83
|
+
if (!held || held.reservation.state !== "handed_off")
|
|
84
|
+
return null;
|
|
85
|
+
held.reservation = {
|
|
86
|
+
...held.reservation,
|
|
87
|
+
state: "active",
|
|
88
|
+
activatedAt: new Date().toISOString(),
|
|
89
|
+
};
|
|
90
|
+
return held.reservation;
|
|
91
|
+
}
|
|
92
|
+
async release(reservationId, owner) {
|
|
93
|
+
const held = this.owned(reservationId, owner);
|
|
94
|
+
if (!held)
|
|
95
|
+
return false;
|
|
96
|
+
await closeServer(held.server);
|
|
97
|
+
this.reservations.delete(reservationId);
|
|
98
|
+
if (this.claimedPorts.get(held.reservation.hostPort) === reservationId) {
|
|
99
|
+
this.claimedPorts.delete(held.reservation.hostPort);
|
|
100
|
+
}
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
snapshot() {
|
|
104
|
+
return [...this.reservations.values()]
|
|
105
|
+
.map(entry => entry.reservation)
|
|
106
|
+
.sort((left, right) => left.hostPort - right.hostPort);
|
|
107
|
+
}
|
|
108
|
+
diagnostics() {
|
|
109
|
+
return {
|
|
110
|
+
hostIp: this.hostIp,
|
|
111
|
+
pool: this.minimumPort === null || this.maximumPort === null
|
|
112
|
+
? null
|
|
113
|
+
: { minimumPort: this.minimumPort, maximumPort: this.maximumPort },
|
|
114
|
+
reservations: this.snapshot().map(({ fencingToken: _fencingToken, ...reservation }) => reservation),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
async launchWithRetry(owner, request, lifecycle, signal) {
|
|
118
|
+
const rejectedPorts = new Set();
|
|
119
|
+
let lastCollision = null;
|
|
120
|
+
for (let attempt = 1; attempt <= this.maximumLaunchAttempts; attempt += 1) {
|
|
121
|
+
if (signal?.aborted)
|
|
122
|
+
throw cancellationError(signal);
|
|
123
|
+
const reservation = await this.reserveExcluding(owner, request, rejectedPorts, signal);
|
|
124
|
+
try {
|
|
125
|
+
return await this.withLaunchGate(async () => {
|
|
126
|
+
let value;
|
|
127
|
+
try {
|
|
128
|
+
if (signal?.aborted)
|
|
129
|
+
throw cancellationError(signal);
|
|
130
|
+
const handedOff = await this.handoff(reservation.reservationId, owner);
|
|
131
|
+
if (!handedOff)
|
|
132
|
+
throw new Error("host_port_broker_state: reservation handoff failed.");
|
|
133
|
+
value = await lifecycle.launch(handedOff, signal);
|
|
134
|
+
if (!await lifecycle.verifyOwnership(value, handedOff, signal)) {
|
|
135
|
+
throw new HostPortCollisionError();
|
|
136
|
+
}
|
|
137
|
+
const active = this.activate(reservation.reservationId, owner);
|
|
138
|
+
if (!active)
|
|
139
|
+
throw new Error("host_port_broker_state: reservation activation failed.");
|
|
140
|
+
return { reservation: active, value };
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
if (value !== undefined)
|
|
144
|
+
await lifecycle.stop(value).catch(() => undefined);
|
|
145
|
+
rejectedPorts.add(reservation.hostPort);
|
|
146
|
+
await this.release(reservation.reservationId, owner);
|
|
147
|
+
throw error;
|
|
148
|
+
}
|
|
149
|
+
}, signal);
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
if (this.reservations.has(reservation.reservationId)) {
|
|
153
|
+
rejectedPorts.add(reservation.hostPort);
|
|
154
|
+
await this.release(reservation.reservationId, owner);
|
|
155
|
+
}
|
|
156
|
+
if (!(error instanceof HostPortCollisionError))
|
|
157
|
+
throw error;
|
|
158
|
+
lastCollision = error;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
throw lastCollision ?? new HostPortCollisionError("host_port_collision: launch retry budget exhausted.");
|
|
162
|
+
}
|
|
163
|
+
async reserveExcluding(owner, request, excludedPorts, signal) {
|
|
164
|
+
validateOwner(owner);
|
|
165
|
+
validateRequest(request);
|
|
166
|
+
const { server, port } = await this.listen(signal, excludedPorts);
|
|
167
|
+
const now = new Date().toISOString();
|
|
168
|
+
const reservation = {
|
|
169
|
+
schemaVersion: 1,
|
|
170
|
+
reservationId: randomUUID(),
|
|
171
|
+
...owner,
|
|
172
|
+
name: request.name,
|
|
173
|
+
protocol: "tcp",
|
|
174
|
+
hostIp: this.hostIp,
|
|
175
|
+
hostPort: port,
|
|
176
|
+
targetPort: request.targetPort ?? port,
|
|
177
|
+
state: "reserved",
|
|
178
|
+
reservedAt: now,
|
|
179
|
+
handedOffAt: null,
|
|
180
|
+
activatedAt: null,
|
|
181
|
+
};
|
|
182
|
+
this.reservations.set(reservation.reservationId, { reservation, server });
|
|
183
|
+
this.claimedPorts.set(port, reservation.reservationId);
|
|
184
|
+
return reservation;
|
|
185
|
+
}
|
|
186
|
+
async listen(signal, excludedPorts) {
|
|
187
|
+
if (this.minimumPort === null || this.maximumPort === null) {
|
|
188
|
+
for (let attempt = 0; attempt < 16; attempt += 1) {
|
|
189
|
+
const result = await listenOn(this.hostIp, 0, signal);
|
|
190
|
+
if (!this.claimedPorts.has(result.port) && !excludedPorts.has(result.port))
|
|
191
|
+
return result;
|
|
192
|
+
await closeServer(result.server);
|
|
193
|
+
}
|
|
194
|
+
throw new Error("host_port_broker_exhausted: could not reserve a unique ephemeral loopback port.");
|
|
195
|
+
}
|
|
196
|
+
const poolSize = this.maximumPort - this.minimumPort + 1;
|
|
197
|
+
for (let attempt = 0; attempt < poolSize; attempt += 1) {
|
|
198
|
+
const port = this.nextPort ?? this.minimumPort;
|
|
199
|
+
this.nextPort = port >= this.maximumPort ? this.minimumPort : port + 1;
|
|
200
|
+
if (this.claimedPorts.has(port) || excludedPorts.has(port))
|
|
201
|
+
continue;
|
|
202
|
+
try {
|
|
203
|
+
return await listenOn(this.hostIp, port, signal);
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
if (isAddressInUse(error))
|
|
207
|
+
continue;
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
throw new Error("host_port_broker_exhausted: no loopback ports are available in the configured pool.");
|
|
212
|
+
}
|
|
213
|
+
owned(reservationId, owner) {
|
|
214
|
+
const held = this.reservations.get(reservationId);
|
|
215
|
+
if (!held)
|
|
216
|
+
return null;
|
|
217
|
+
return sameOwner(held.reservation, owner) ? held : null;
|
|
218
|
+
}
|
|
219
|
+
async withLaunchGate(action, signal) {
|
|
220
|
+
const predecessor = this.launchGate;
|
|
221
|
+
let release = () => undefined;
|
|
222
|
+
const turn = new Promise(resolve => { release = resolve; });
|
|
223
|
+
this.launchGate = predecessor.then(() => turn, () => turn);
|
|
224
|
+
try {
|
|
225
|
+
await waitForTurn(predecessor, signal);
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
void predecessor.finally(release);
|
|
229
|
+
throw error;
|
|
230
|
+
}
|
|
231
|
+
try {
|
|
232
|
+
return await action();
|
|
233
|
+
}
|
|
234
|
+
finally {
|
|
235
|
+
release();
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function listenOn(host, port, signal) {
|
|
240
|
+
if (signal?.aborted)
|
|
241
|
+
return Promise.reject(cancellationError(signal));
|
|
242
|
+
return new Promise((resolve, reject) => {
|
|
243
|
+
const server = net.createServer(socket => socket.destroy());
|
|
244
|
+
const abort = () => {
|
|
245
|
+
server.close();
|
|
246
|
+
reject(cancellationError(signal));
|
|
247
|
+
};
|
|
248
|
+
const error = (cause) => {
|
|
249
|
+
signal?.removeEventListener("abort", abort);
|
|
250
|
+
reject(cause);
|
|
251
|
+
};
|
|
252
|
+
server.once("error", error);
|
|
253
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
254
|
+
server.listen({ host, port, exclusive: true }, () => {
|
|
255
|
+
signal?.removeEventListener("abort", abort);
|
|
256
|
+
server.removeListener("error", error);
|
|
257
|
+
const address = server.address();
|
|
258
|
+
if (!address || typeof address === "string") {
|
|
259
|
+
void closeServer(server).then(() => reject(new Error("host_port_broker_invalid: listener address was unavailable.")));
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
resolve({ server, port: address.port });
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
function closeServer(server) {
|
|
267
|
+
if (!server?.listening)
|
|
268
|
+
return Promise.resolve();
|
|
269
|
+
return new Promise((resolve, reject) => server.close(error => error ? reject(error) : resolve()));
|
|
270
|
+
}
|
|
271
|
+
function validateOwner(owner) {
|
|
272
|
+
if (![owner.dispatchAttemptId, owner.executionLeaseId, owner.fencingToken].every(isUuid)
|
|
273
|
+
|| !boundedText(owner.processSupervisorId, 255)) {
|
|
274
|
+
throw new Error("host_port_broker_invalid: owner identity or fence is invalid.");
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
function validateRequest(request) {
|
|
278
|
+
if (!/^[a-z][a-z0-9_-]{0,63}$/u.test(request.name)
|
|
279
|
+
|| (request.protocol !== undefined && request.protocol !== "tcp")) {
|
|
280
|
+
throw new Error("host_port_broker_invalid: only named TCP loopback reservations are supported.");
|
|
281
|
+
}
|
|
282
|
+
if (request.targetPort !== undefined)
|
|
283
|
+
validPort(request.targetPort, "targetPort");
|
|
284
|
+
}
|
|
285
|
+
function validPort(value, label) {
|
|
286
|
+
if (!Number.isSafeInteger(value) || Number(value) < 1 || Number(value) > 65535) {
|
|
287
|
+
throw new Error(`host_port_broker_invalid: ${label} must be a valid TCP port.`);
|
|
288
|
+
}
|
|
289
|
+
return Number(value);
|
|
290
|
+
}
|
|
291
|
+
function sameOwner(left, right) {
|
|
292
|
+
return left.dispatchAttemptId === right.dispatchAttemptId
|
|
293
|
+
&& left.executionLeaseId === right.executionLeaseId
|
|
294
|
+
&& left.fencingToken === right.fencingToken
|
|
295
|
+
&& left.processSupervisorId === right.processSupervisorId;
|
|
296
|
+
}
|
|
297
|
+
function isAddressInUse(error) {
|
|
298
|
+
return error instanceof Error && "code" in error && error.code === "EADDRINUSE";
|
|
299
|
+
}
|
|
300
|
+
function isUuid(value) {
|
|
301
|
+
return typeof value === "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu.test(value);
|
|
302
|
+
}
|
|
303
|
+
function boundedText(value, maximumLength) {
|
|
304
|
+
return typeof value === "string"
|
|
305
|
+
&& value.length > 0
|
|
306
|
+
&& value.length <= maximumLength
|
|
307
|
+
&& Array.from(value).every(character => {
|
|
308
|
+
const codePoint = character.codePointAt(0) ?? 0;
|
|
309
|
+
return codePoint > 31 && codePoint !== 127;
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
function cancellationError(signal) {
|
|
313
|
+
return new Error(String(signal?.reason ?? "Host port reservation cancelled."));
|
|
314
|
+
}
|
|
315
|
+
function waitForTurn(predecessor, signal) {
|
|
316
|
+
if (!signal)
|
|
317
|
+
return predecessor;
|
|
318
|
+
if (signal.aborted)
|
|
319
|
+
return Promise.reject(cancellationError(signal));
|
|
320
|
+
return new Promise((resolve, reject) => {
|
|
321
|
+
const abort = () => {
|
|
322
|
+
reject(cancellationError(signal));
|
|
323
|
+
};
|
|
324
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
325
|
+
void predecessor.then(() => {
|
|
326
|
+
signal.removeEventListener("abort", abort);
|
|
327
|
+
resolve();
|
|
328
|
+
}, error => {
|
|
329
|
+
signal.removeEventListener("abort", abort);
|
|
330
|
+
reject(error);
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export interface PressureStallAverages {
|
|
2
|
+
/** Percent of wall time stalled over the last 10 seconds (0-100). */
|
|
3
|
+
readonly avg10: number;
|
|
4
|
+
readonly avg60: number;
|
|
5
|
+
readonly avg300: number;
|
|
6
|
+
}
|
|
7
|
+
export interface PressureStallResource {
|
|
8
|
+
readonly some: PressureStallAverages | null;
|
|
9
|
+
readonly full: PressureStallAverages | null;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Parses one PSI file. Returns null when the content has no well-formed
|
|
13
|
+
* `some`/`full` line, so callers can report PSI as unavailable instead of
|
|
14
|
+
* publishing zeros for a file they could not interpret.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parsePressureStall(content: string): PressureStallResource | null;
|
|
17
|
+
/** Reads `usage_usec` from a cgroup v2 `cpu.stat` file. */
|
|
18
|
+
export declare function parseCgroupCpuUsageUsec(content: string): number | null;
|
|
19
|
+
/** Reads anonymous (RSS-like, excludes page cache) bytes from cgroup v2 `memory.stat`. */
|
|
20
|
+
export declare function parseCgroupMemoryAnonBytes(content: string): number | null;
|
|
21
|
+
/** Reads a single non-negative integer file such as cgroup v2 `memory.current`. */
|
|
22
|
+
export declare function parseNonNegativeInteger(content: string): number | null;
|
|
23
|
+
/** Reads `MemAvailable` (bytes) from /proc/meminfo. */
|
|
24
|
+
export declare function parseMemAvailableBytes(content: string): number | null;
|
|
25
|
+
/**
|
|
26
|
+
* Resolves the unified (cgroup v2) hierarchy path from /proc/self/cgroup.
|
|
27
|
+
* Returns null on pure cgroup v1 hosts (no `0::` entry) and for the root cgroup.
|
|
28
|
+
*/
|
|
29
|
+
export declare function parseUnifiedCgroupPath(content: string): string | null;
|
|
30
|
+
/**
|
|
31
|
+
* This process's cgroup v2 path from `/proc/self/cgroup`, including the root
|
|
32
|
+
* `/` (a container's own cgroup under a cgroup namespace); null for cgroup v1
|
|
33
|
+
* or a malformed entry. `parseUnifiedCgroupPath` excludes the root, because the
|
|
34
|
+
* root is never the bridge's own unit; memory limits apply there all the same.
|
|
35
|
+
*/
|
|
36
|
+
export declare function parseUnifiedCgroupMembership(content: string): string | null;
|
|
37
|
+
/** The leaf cgroup name, e.g. `forge-bridge.service`. */
|
|
38
|
+
export declare function cgroupLeafName(cgroupPath: string): string | null;
|
|
39
|
+
/**
|
|
40
|
+
* Whether the bridge's cgroup is dedicated to it, so its usage can later be
|
|
41
|
+
* subtracted from system pressure as "Forge's own load". Only a systemd
|
|
42
|
+
* `.service` qualifies by default, or exactly the unit an operator names via
|
|
43
|
+
* FORGE_BRIDGE_CGROUP_UNIT. A `.scope` is rejected: a bridge started from a
|
|
44
|
+
* terminal, SSH session or desktop app shares `session-N.scope` /
|
|
45
|
+
* `app-*.scope` with unrelated work (possibly the owner's game).
|
|
46
|
+
* Container cgroups (e.g. `docker-<id>.scope`) are not treated as dedicated yet.
|
|
47
|
+
*/
|
|
48
|
+
export declare function isDedicatedBridgeUnit(unit: string, configuredUnit: string | null | undefined): boolean;
|
|
49
|
+
/** Aggregate host CPU time from /proc/stat, in clock ticks, plus the online CPU count. */
|
|
50
|
+
export interface ProcStatCpuTotals {
|
|
51
|
+
readonly busyTicks: number;
|
|
52
|
+
readonly totalTicks: number;
|
|
53
|
+
readonly cpuCount: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Reads the aggregate `cpu` line of /proc/stat. Busy time is user + nice +
|
|
57
|
+
* system + irq + softirq + steal (guest time is already inside user/nice);
|
|
58
|
+
* idle and iowait are not busy. Both counters are additive CPU time, so a
|
|
59
|
+
* cgroup's `cpu.stat` usage over the same window can be subtracted from them.
|
|
60
|
+
*/
|
|
61
|
+
export declare function parseProcStatCpuTotals(content: string): ProcStatCpuTotals | null;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// Linux Pressure Stall Information (PSI) parsing shared by the host load sampler.
|
|
2
|
+
// Format (system-wide /proc/pressure/<resource> and cgroup v2 <resource>.pressure):
|
|
3
|
+
// some avg10=0.12 avg60=0.34 avg300=0.56 total=123456
|
|
4
|
+
// full avg10=0.00 avg60=0.00 avg300=0.00 total=0
|
|
5
|
+
const pressureLinePattern = /^(some|full)\s+(.*)$/u;
|
|
6
|
+
/**
|
|
7
|
+
* Parses one PSI file. Returns null when the content has no well-formed
|
|
8
|
+
* `some`/`full` line, so callers can report PSI as unavailable instead of
|
|
9
|
+
* publishing zeros for a file they could not interpret.
|
|
10
|
+
*/
|
|
11
|
+
export function parsePressureStall(content) {
|
|
12
|
+
let some = null;
|
|
13
|
+
let full = null;
|
|
14
|
+
for (const rawLine of content.split(/\r?\n/u)) {
|
|
15
|
+
const match = pressureLinePattern.exec(rawLine.trim());
|
|
16
|
+
if (!match)
|
|
17
|
+
continue;
|
|
18
|
+
const averages = parseAverages(match[2]);
|
|
19
|
+
if (!averages)
|
|
20
|
+
continue;
|
|
21
|
+
if (match[1] === "some")
|
|
22
|
+
some = averages;
|
|
23
|
+
else
|
|
24
|
+
full = averages;
|
|
25
|
+
}
|
|
26
|
+
return some || full ? { some, full } : null;
|
|
27
|
+
}
|
|
28
|
+
const pressureFieldPattern = /^(avg10|avg60|avg300|total)=(\d+(?:\.\d+)?)$/u;
|
|
29
|
+
/** A PSI line must carry exactly avg10, avg60, avg300 and an integer total; anything else is malformed. */
|
|
30
|
+
function parseAverages(fields) {
|
|
31
|
+
const values = new Map();
|
|
32
|
+
for (const field of fields.trim().split(/\s+/u)) {
|
|
33
|
+
const match = pressureFieldPattern.exec(field);
|
|
34
|
+
if (!match || values.has(match[1]))
|
|
35
|
+
return null;
|
|
36
|
+
values.set(match[1], Number(match[2]));
|
|
37
|
+
}
|
|
38
|
+
const avg10 = values.get("avg10");
|
|
39
|
+
const avg60 = values.get("avg60");
|
|
40
|
+
const avg300 = values.get("avg300");
|
|
41
|
+
const total = values.get("total");
|
|
42
|
+
if (avg10 === undefined || avg60 === undefined || avg300 === undefined
|
|
43
|
+
|| total === undefined || !Number.isSafeInteger(total))
|
|
44
|
+
return null;
|
|
45
|
+
return { avg10: clampPercent(avg10), avg60: clampPercent(avg60), avg300: clampPercent(avg300) };
|
|
46
|
+
}
|
|
47
|
+
function clampPercent(value) {
|
|
48
|
+
return Math.min(100, Math.max(0, value));
|
|
49
|
+
}
|
|
50
|
+
/** Reads `usage_usec` from a cgroup v2 `cpu.stat` file. */
|
|
51
|
+
export function parseCgroupCpuUsageUsec(content) {
|
|
52
|
+
const match = /^usage_usec\s+(\d+)\s*$/mu.exec(content);
|
|
53
|
+
if (!match)
|
|
54
|
+
return null;
|
|
55
|
+
const value = Number(match[1]);
|
|
56
|
+
return Number.isSafeInteger(value) ? value : null;
|
|
57
|
+
}
|
|
58
|
+
/** Reads anonymous (RSS-like, excludes page cache) bytes from cgroup v2 `memory.stat`. */
|
|
59
|
+
export function parseCgroupMemoryAnonBytes(content) {
|
|
60
|
+
const match = /^anon\s+(\d+)\s*$/mu.exec(content);
|
|
61
|
+
if (!match)
|
|
62
|
+
return null;
|
|
63
|
+
const value = Number(match[1]);
|
|
64
|
+
return Number.isSafeInteger(value) ? value : null;
|
|
65
|
+
}
|
|
66
|
+
/** Reads a single non-negative integer file such as cgroup v2 `memory.current`. */
|
|
67
|
+
export function parseNonNegativeInteger(content) {
|
|
68
|
+
const trimmed = content.trim();
|
|
69
|
+
if (!/^\d+$/u.test(trimmed))
|
|
70
|
+
return null;
|
|
71
|
+
const value = Number(trimmed);
|
|
72
|
+
return Number.isSafeInteger(value) ? value : null;
|
|
73
|
+
}
|
|
74
|
+
/** Reads `MemAvailable` (bytes) from /proc/meminfo. */
|
|
75
|
+
export function parseMemAvailableBytes(content) {
|
|
76
|
+
const match = /^MemAvailable:\s+(\d+)\s*kB\s*$/mu.exec(content);
|
|
77
|
+
if (!match)
|
|
78
|
+
return null;
|
|
79
|
+
const value = Number(match[1]) * 1024;
|
|
80
|
+
return Number.isSafeInteger(value) ? value : null;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Resolves the unified (cgroup v2) hierarchy path from /proc/self/cgroup.
|
|
84
|
+
* Returns null on pure cgroup v1 hosts (no `0::` entry) and for the root cgroup.
|
|
85
|
+
*/
|
|
86
|
+
export function parseUnifiedCgroupPath(content) {
|
|
87
|
+
for (const rawLine of content.split(/\r?\n/u)) {
|
|
88
|
+
const line = rawLine.trim();
|
|
89
|
+
if (!line.startsWith("0::"))
|
|
90
|
+
continue;
|
|
91
|
+
const cgroupPath = line.slice(3).trim();
|
|
92
|
+
if (!cgroupPath.startsWith("/") || cgroupPath === "/")
|
|
93
|
+
return null;
|
|
94
|
+
if (cgroupPath.split("/").some(segment => segment === ".."))
|
|
95
|
+
return null;
|
|
96
|
+
return cgroupPath;
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* This process's cgroup v2 path from `/proc/self/cgroup`, including the root
|
|
102
|
+
* `/` (a container's own cgroup under a cgroup namespace); null for cgroup v1
|
|
103
|
+
* or a malformed entry. `parseUnifiedCgroupPath` excludes the root, because the
|
|
104
|
+
* root is never the bridge's own unit; memory limits apply there all the same.
|
|
105
|
+
*/
|
|
106
|
+
export function parseUnifiedCgroupMembership(content) {
|
|
107
|
+
for (const rawLine of content.split(/\r?\n/u)) {
|
|
108
|
+
const line = rawLine.trim();
|
|
109
|
+
if (!line.startsWith("0::"))
|
|
110
|
+
continue;
|
|
111
|
+
const cgroupPath = line.slice(3).trim();
|
|
112
|
+
if (!cgroupPath.startsWith("/"))
|
|
113
|
+
return null;
|
|
114
|
+
if (cgroupPath.split("/").some(segment => segment === ".."))
|
|
115
|
+
return null;
|
|
116
|
+
return cgroupPath;
|
|
117
|
+
}
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
/** The leaf cgroup name, e.g. `forge-bridge.service`. */
|
|
121
|
+
export function cgroupLeafName(cgroupPath) {
|
|
122
|
+
return cgroupPath.split("/").filter(Boolean).at(-1) ?? null;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Whether the bridge's cgroup is dedicated to it, so its usage can later be
|
|
126
|
+
* subtracted from system pressure as "Forge's own load". Only a systemd
|
|
127
|
+
* `.service` qualifies by default, or exactly the unit an operator names via
|
|
128
|
+
* FORGE_BRIDGE_CGROUP_UNIT. A `.scope` is rejected: a bridge started from a
|
|
129
|
+
* terminal, SSH session or desktop app shares `session-N.scope` /
|
|
130
|
+
* `app-*.scope` with unrelated work (possibly the owner's game).
|
|
131
|
+
* Container cgroups (e.g. `docker-<id>.scope`) are not treated as dedicated yet.
|
|
132
|
+
*/
|
|
133
|
+
export function isDedicatedBridgeUnit(unit, configuredUnit) {
|
|
134
|
+
const configured = configuredUnit?.trim();
|
|
135
|
+
if (configured)
|
|
136
|
+
return unit === configured;
|
|
137
|
+
// `app-*` services are desktop-launched apps (XDG naming); `user@N` is the whole user manager.
|
|
138
|
+
return /^[^@\s]+(@[^\s]+)?\.service$/u.test(unit)
|
|
139
|
+
&& !/^app-/u.test(unit)
|
|
140
|
+
&& !/^user@\d+\.service$/u.test(unit);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Reads the aggregate `cpu` line of /proc/stat. Busy time is user + nice +
|
|
144
|
+
* system + irq + softirq + steal (guest time is already inside user/nice);
|
|
145
|
+
* idle and iowait are not busy. Both counters are additive CPU time, so a
|
|
146
|
+
* cgroup's `cpu.stat` usage over the same window can be subtracted from them.
|
|
147
|
+
*/
|
|
148
|
+
export function parseProcStatCpuTotals(content) {
|
|
149
|
+
let aggregate = null;
|
|
150
|
+
let cpuCount = 0;
|
|
151
|
+
for (const rawLine of content.split(/\r?\n/u)) {
|
|
152
|
+
const fields = rawLine.trim().split(/\s+/u);
|
|
153
|
+
if (fields[0] === "cpu") {
|
|
154
|
+
const values = fields.slice(1, 9).map(Number);
|
|
155
|
+
if (values.length < 8 || values.some(value => !Number.isSafeInteger(value) || value < 0))
|
|
156
|
+
return null;
|
|
157
|
+
aggregate = values;
|
|
158
|
+
}
|
|
159
|
+
else if (/^cpu\d+$/u.test(fields[0] ?? "")) {
|
|
160
|
+
cpuCount += 1;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (!aggregate || cpuCount === 0)
|
|
164
|
+
return null;
|
|
165
|
+
const [user, nice, system, idle, iowait, irq, softirq, steal] = aggregate;
|
|
166
|
+
const busyTicks = user + nice + system + irq + softirq + steal;
|
|
167
|
+
return { busyTicks, totalTicks: busyTicks + idle + iowait, cpuCount };
|
|
168
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { type HostRuntimeRequirements } from "./host-runtime-requirements.js";
|
|
2
|
+
export declare const hostRuntimeContractPath = ".forge/forge.runtime.yml";
|
|
3
|
+
export declare const hostRuntimeTestPostgresAdminEnvironment = "FORGE_TEST_POSTGRES_ADMIN_CONNECTION_STRING";
|
|
4
|
+
export declare const hostRuntimeLegacyTestPostgresEnvironment = "FORGE_TEST_POSTGRES_CONNECTION_STRING";
|
|
5
|
+
export declare const hostRuntimeTestPostgresProvisionerEnvironment = "FORGE_TEST_POSTGRES_PROVISIONER_CONNECTION_STRING";
|
|
6
|
+
export type RequestedHostConcurrency = "serial" | "parallel" | "disabled";
|
|
7
|
+
export type HostRuntimePortAdapter = "node" | "vite" | "next" | "aspnetcore";
|
|
8
|
+
export interface HostRuntimeLaunchConfig {
|
|
9
|
+
readonly command: string;
|
|
10
|
+
readonly args: readonly string[];
|
|
11
|
+
readonly workingDirectory: string;
|
|
12
|
+
readonly environment?: Readonly<Record<string, string>>;
|
|
13
|
+
}
|
|
14
|
+
export interface HostRuntimePortConfig {
|
|
15
|
+
readonly name: string;
|
|
16
|
+
readonly adapter: HostRuntimePortAdapter | null;
|
|
17
|
+
readonly launch: HostRuntimeLaunchConfig | null;
|
|
18
|
+
readonly env: string;
|
|
19
|
+
readonly baseUrlEnv: string | null;
|
|
20
|
+
readonly format: string | null;
|
|
21
|
+
}
|
|
22
|
+
export interface HostRuntimePlaywrightConfig {
|
|
23
|
+
readonly config: string;
|
|
24
|
+
readonly baseUrlPort: string;
|
|
25
|
+
readonly workers: number;
|
|
26
|
+
}
|
|
27
|
+
export interface HostRuntimeContract {
|
|
28
|
+
readonly schemaVersion: 1;
|
|
29
|
+
readonly runtime: {
|
|
30
|
+
readonly hostConcurrency: RequestedHostConcurrency;
|
|
31
|
+
readonly ports: readonly HostRuntimePortConfig[];
|
|
32
|
+
readonly playwright: HostRuntimePlaywrightConfig | null;
|
|
33
|
+
readonly browserProfile: "isolated";
|
|
34
|
+
readonly singletonResources: readonly string[];
|
|
35
|
+
};
|
|
36
|
+
/** Decision 0013 placement requirements; absent or null when the contract declares none. */
|
|
37
|
+
readonly requires?: HostRuntimeRequirements | null;
|
|
38
|
+
}
|
|
39
|
+
export interface LoadedHostRuntimeContract {
|
|
40
|
+
readonly contract: HostRuntimeContract;
|
|
41
|
+
readonly source: "default" | "project" | "derived";
|
|
42
|
+
readonly discovery?: HostRuntimeDiscovery | null;
|
|
43
|
+
}
|
|
44
|
+
export interface HostRuntimeDiscovery {
|
|
45
|
+
readonly status: "derived" | "ambiguous" | "unsupported";
|
|
46
|
+
readonly reasonCode: string;
|
|
47
|
+
readonly summary: string;
|
|
48
|
+
readonly candidateFingerprint?: string | null;
|
|
49
|
+
}
|
|
50
|
+
/** Returns retained bytes (or retained absence) for one canonical discovery input. */
|
|
51
|
+
export type HostRuntimeSourceSnapshot = (target: string) => Promise<Buffer | null>;
|
|
52
|
+
export interface HostRuntimeDirectoryEntry {
|
|
53
|
+
readonly name: string;
|
|
54
|
+
readonly isDirectory: boolean;
|
|
55
|
+
readonly isFile: boolean;
|
|
56
|
+
}
|
|
57
|
+
/** Returns one identity-bound directory inventory for runtime discovery. */
|
|
58
|
+
export type HostRuntimeDirectorySnapshot = (target: string) => Promise<readonly HostRuntimeDirectoryEntry[]>;
|
|
59
|
+
export declare function loadHostRuntimeContract(worktreePath: string, snapshot?: HostRuntimeSourceSnapshot, directorySnapshot?: HostRuntimeDirectorySnapshot): Promise<LoadedHostRuntimeContract>;
|
|
60
|
+
/** A managed attempt's own API master key: 32 random bytes, base64-encoded, as Security:MasterKey expects. */
|
|
61
|
+
export declare function newAttemptApiMasterKey(): string;
|
|
62
|
+
/**
|
|
63
|
+
* The environment a managed attempt's ASP.NET API launches with. When neither the launch profile
|
|
64
|
+
* nor the runtime contract configures Security__MasterKey or Security__MasterKeyFile, the API gets
|
|
65
|
+
* the attempt's own key. Otherwise ASP.NET Development falls back to the host user's dotnet
|
|
66
|
+
* user-secrets: the host's own key where they exist, and a failed secret write wherever they do not.
|
|
67
|
+
* The caller keeps one key for the attempt's whole life, so a restart against the same attempt
|
|
68
|
+
* database can still decrypt what was stored before it. The key is a secret: it is for the API
|
|
69
|
+
* process only, never for the environment handed to checks or providers.
|
|
70
|
+
*/
|
|
71
|
+
export declare function withAttemptApiMasterKey(port: HostRuntimePortConfig, environment: Readonly<Record<string, string>>, attemptMasterKey: string): Readonly<Record<string, string>>;
|
|
72
|
+
export declare function defaultHostRuntimeContract(): HostRuntimeContract;
|
|
73
|
+
export declare function validateHostRuntimeContract(source: string): HostRuntimeContract;
|
|
74
|
+
export declare function hostPortEnvironment(config: HostRuntimePortConfig, hostIp: "127.0.0.1", hostPort: number): Readonly<Record<string, string>>;
|