@loucompanion/forge-bridge 0.1.3-dev.fbe15023cdfe → 0.1.4-dev.0098fdb4e213
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +232 -5
- package/dist/bridge/bridge-chat-provider-command.d.ts +19 -0
- package/dist/bridge/bridge-chat-provider-command.js +132 -0
- package/dist/bridge/bridge-chat.types.d.ts +121 -0
- package/dist/bridge/bridge-chat.types.js +416 -0
- package/dist/bridge/bridge-state-file.d.ts +161 -0
- package/dist/bridge/bridge-state-file.js +376 -0
- package/dist/bridge/bridge-state-io.d.ts +11 -0
- package/dist/bridge/bridge-state-io.js +50 -0
- package/dist/bridge/bridge-state-lock.d.ts +11 -0
- package/dist/bridge/bridge-state-lock.js +102 -0
- package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
- package/dist/bridge/bridge-state-unpublished.js +111 -0
- package/dist/bridge/bridge.base.d.ts +13 -1
- package/dist/bridge/bridge.service.d.ts +169 -14
- package/dist/bridge/bridge.service.js +1868 -330
- package/dist/bridge/bridge.types.d.ts +73 -1
- package/dist/bridge/dispatch-result-outbox.d.ts +35 -0
- package/dist/bridge/dispatch-result-outbox.js +87 -0
- package/dist/bridge/dispatch-result-worker.d.ts +2 -0
- package/dist/bridge/dispatch-result-worker.js +122 -0
- package/dist/bridge/in-flight-registry.d.ts +62 -0
- package/dist/bridge/in-flight-registry.js +207 -0
- package/dist/bridge/internals.d.ts +2 -0
- package/dist/bridge/internals.js +1 -0
- package/dist/bridge/local-yield-flag.d.ts +6 -0
- package/dist/bridge/local-yield-flag.js +34 -0
- package/dist/bridge/readiness-result-outbox.d.ts +25 -0
- package/dist/bridge/readiness-result-outbox.js +74 -0
- package/dist/bridge/readiness-result-worker.d.ts +2 -0
- package/dist/bridge/readiness-result-worker.js +121 -0
- package/dist/bridge/runner-host-capabilities.d.ts +20 -0
- package/dist/bridge/runner-host-capabilities.js +110 -0
- package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
- package/dist/bridge/sandbox-resource-accounting.js +150 -0
- package/dist/bridge/test-postgres-capability.d.ts +14 -0
- package/dist/bridge/test-postgres-capability.js +120 -0
- package/dist/cleanup/cleanup-wip.d.ts +12 -0
- package/dist/cleanup/cleanup-wip.js +66 -0
- package/dist/cleanup/cleanup.service.d.ts +21 -1
- package/dist/cleanup/cleanup.service.js +185 -143
- package/dist/cleanup/cleanup.types.d.ts +6 -0
- package/dist/cleanup/forge-owned-paths.d.ts +9 -0
- package/dist/cleanup/forge-owned-paths.js +53 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +7 -0
- package/dist/cleanup/host-runtime-ledger.js +130 -0
- package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
- package/dist/cleanup/managed-branch-sweep.js +111 -0
- package/dist/cli/cli.help.js +78 -16
- package/dist/cli/cli.service.d.ts +32 -15
- package/dist/cli/cli.service.js +206 -182
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +7 -0
- package/dist/cli/local-config.js +36 -4
- package/dist/cli/provider-cli-detection.d.ts +10 -0
- package/dist/cli/provider-cli-detection.js +160 -0
- package/dist/runtime/aspnet-runtime-prebuild.d.ts +41 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +474 -0
- package/dist/runtime/attempt-database-broker.d.ts +89 -0
- package/dist/runtime/attempt-database-broker.js +390 -0
- package/dist/runtime/attempt-node-runtime-launcher.d.ts +2 -1
- package/dist/runtime/attempt-node-runtime-launcher.js +57 -18
- package/dist/runtime/attempt-path-operation.d.ts +21 -0
- package/dist/runtime/attempt-path-operation.js +94 -0
- package/dist/runtime/attempt-private-directory.d.ts +6 -0
- package/dist/runtime/attempt-private-directory.js +54 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +35 -0
- package/dist/runtime/attempt-process-supervisor.js +144 -23
- package/dist/runtime/canonical-source-file.d.ts +3 -0
- package/dist/runtime/canonical-source-file.js +54 -0
- package/dist/runtime/docker-engine-probe.d.ts +95 -0
- package/dist/runtime/docker-engine-probe.js +340 -0
- package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
- package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
- package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
- package/dist/runtime/ephemeral-test-postgres.js +303 -0
- package/dist/runtime/generated-output-reset.d.ts +10 -0
- package/dist/runtime/generated-output-reset.js +62 -8
- package/dist/runtime/host-database-capability-boundary.d.ts +16 -0
- package/dist/runtime/host-database-capability-boundary.js +63 -0
- package/dist/runtime/host-diagnostics.d.ts +11 -0
- package/dist/runtime/host-diagnostics.js +192 -0
- package/dist/runtime/host-execution-root.d.ts +4 -0
- package/dist/runtime/host-execution-root.js +39 -0
- package/dist/runtime/host-facts.d.ts +36 -0
- package/dist/runtime/host-facts.js +95 -0
- package/dist/runtime/host-listener-inspector.d.ts +8 -1
- package/dist/runtime/host-listener-inspector.js +121 -60
- package/dist/runtime/host-load-admission.d.ts +67 -0
- package/dist/runtime/host-load-admission.js +99 -0
- package/dist/runtime/host-load-child-environment.d.ts +27 -0
- package/dist/runtime/host-load-child-environment.js +76 -0
- package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
- package/dist/runtime/host-load-forge-cgroups.js +140 -0
- package/dist/runtime/host-load-governor-config.d.ts +52 -0
- package/dist/runtime/host-load-governor-config.js +83 -0
- package/dist/runtime/host-load-governor.d.ts +186 -0
- package/dist/runtime/host-load-governor.js +632 -0
- package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
- package/dist/runtime/host-load-ledger-lock.js +187 -0
- package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
- package/dist/runtime/host-load-runtime-settings.js +80 -0
- package/dist/runtime/host-load-sampler.d.ts +156 -0
- package/dist/runtime/host-load-sampler.js +298 -0
- package/dist/runtime/host-load-step-class.d.ts +70 -0
- package/dist/runtime/host-load-step-class.js +161 -0
- package/dist/runtime/host-load-step-reaper.d.ts +27 -0
- package/dist/runtime/host-load-step-reaper.js +95 -0
- package/dist/runtime/host-load-step-run.d.ts +73 -0
- package/dist/runtime/host-load-step-run.js +102 -0
- package/dist/runtime/host-load-test-slot.d.ts +43 -0
- package/dist/runtime/host-load-test-slot.js +81 -0
- package/dist/runtime/host-load-token-ledger.d.ts +200 -0
- package/dist/runtime/host-load-token-ledger.js +453 -0
- package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
- package/dist/runtime/host-load-windows-cpu.js +85 -0
- package/dist/runtime/host-pressure-stall.d.ts +61 -0
- package/dist/runtime/host-pressure-stall.js +168 -0
- package/dist/runtime/host-runtime-contract.d.ts +28 -1
- package/dist/runtime/host-runtime-contract.js +203 -57
- package/dist/runtime/host-runtime-lease.d.ts +163 -9
- package/dist/runtime/host-runtime-lease.js +1427 -124
- package/dist/runtime/host-runtime-promotion.d.ts +35 -3
- package/dist/runtime/host-runtime-promotion.js +107 -12
- package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
- package/dist/runtime/host-runtime-requirements-check.js +29 -0
- package/dist/runtime/host-runtime-requirements.d.ts +36 -0
- package/dist/runtime/host-runtime-requirements.js +117 -0
- package/dist/runtime/managed-command-teardown.d.ts +62 -0
- package/dist/runtime/managed-command-teardown.js +596 -0
- package/dist/runtime/memory-capacity.d.ts +70 -0
- package/dist/runtime/memory-capacity.js +123 -0
- package/dist/runtime/native-test-postgres-fallback.d.ts +69 -0
- package/dist/runtime/native-test-postgres-fallback.js +143 -0
- package/dist/runtime/node-host-runtime-adapter.d.ts +3 -0
- package/dist/runtime/node-host-runtime-adapter.js +29 -11
- package/dist/runtime/pinned-directory-process.d.ts +9 -0
- package/dist/runtime/pinned-directory-process.js +61 -0
- package/dist/runtime/pinned-source-directory.d.ts +17 -0
- package/dist/runtime/pinned-source-directory.js +94 -0
- package/dist/runtime/playwright-browser-cache.d.ts +39 -0
- package/dist/runtime/playwright-browser-cache.js +227 -0
- package/dist/runtime/playwright-host-runtime-adapter.d.ts +19 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +113 -59
- package/dist/runtime/prepared-runtime-identity.d.ts +6 -0
- package/dist/runtime/prepared-runtime-identity.js +218 -0
- package/dist/runtime/prepared-runtime-readiness.d.ts +30 -0
- package/dist/runtime/prepared-runtime-readiness.js +285 -0
- package/dist/runtime/runner-settings.d.ts +104 -0
- package/dist/runtime/runner-settings.js +236 -0
- package/dist/runtime/runtime-isolation-lease.js +4 -1
- package/dist/runtime/workspace-resource-estimator.d.ts +17 -0
- package/dist/runtime/workspace-resource-estimator.js +174 -0
- package/dist/sandbox/host-capacity-broker.d.ts +115 -0
- package/dist/sandbox/host-capacity-broker.js +336 -0
- package/dist/sandbox/managed-branch.d.ts +13 -0
- package/dist/sandbox/managed-branch.js +36 -0
- package/dist/sandbox/preflight.d.ts +31 -1
- package/dist/sandbox/preflight.js +237 -51
- package/dist/sandbox/provider-auth/codex.js +11 -11
- package/dist/sandbox/repository-lock.d.ts +2 -1
- package/dist/sandbox/repository-lock.js +19 -9
- package/dist/sandbox/runtime.d.ts +16 -2
- package/dist/sandbox/runtime.js +183 -114
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -0
- package/dist/sandbox/sandbox.types.d.ts +7 -0
- package/dist/sandbox/workspace.service.js +2 -0
- package/dist/session/architect-waits.d.ts +2 -0
- package/dist/session/architect-waits.js +138 -0
- package/dist/session/managed-attempt-tools.d.ts +37 -1
- package/dist/session/managed-attempt-tools.js +822 -84
- package/dist/session/managed-build-coordinator.d.ts +5 -0
- package/dist/session/managed-build-coordinator.js +109 -0
- package/dist/session/managed-build-receipt.d.ts +26 -0
- package/dist/session/managed-build-receipt.js +342 -0
- package/dist/session/managed-command-host-load.d.ts +47 -0
- package/dist/session/managed-command-host-load.js +83 -0
- package/dist/session/managed-verification-timeouts.d.ts +8 -0
- package/dist/session/managed-verification-timeouts.js +17 -0
- package/dist/session/mcp-argument-coercion.d.ts +23 -0
- package/dist/session/mcp-argument-coercion.js +121 -0
- package/dist/session/phase-completion.artifacts.d.ts +24 -0
- package/dist/session/phase-completion.artifacts.js +321 -45
- package/dist/session/phase-completion.command-validation.d.ts +7 -0
- package/dist/session/phase-completion.command-validation.js +77 -0
- package/dist/session/phase-completion.d.ts +23 -1
- package/dist/session/phase-completion.helpers.d.ts +5 -0
- package/dist/session/phase-completion.helpers.js +43 -19
- package/dist/session/phase-completion.js +19 -3
- package/dist/session/phase-completion.mcp-args.d.ts +9 -0
- package/dist/session/phase-completion.mcp-args.js +156 -0
- package/dist/session/phase-completion.prompts.js +22 -18
- package/dist/session/phase-completion.runtime.d.ts +6 -10
- package/dist/session/phase-completion.runtime.js +214 -224
- package/dist/session/phase-completion.schema-parts.d.ts +19 -0
- package/dist/session/phase-completion.schema-parts.js +188 -0
- package/dist/session/phase-completion.schemas.d.ts +3 -3
- package/dist/session/phase-completion.schemas.js +250 -226
- package/dist/session/phase-completion.validation.d.ts +3 -3
- package/dist/session/phase-completion.validation.js +135 -89
- package/dist/session/pre-publication-host-load.d.ts +27 -0
- package/dist/session/pre-publication-host-load.js +111 -0
- package/dist/session/pre-publication-native-postgres.d.ts +30 -0
- package/dist/session/pre-publication-native-postgres.js +111 -0
- package/dist/session/pre-publication-pass.d.ts +61 -0
- package/dist/session/pre-publication-pass.js +148 -0
- package/dist/session/pre-publication-process.d.ts +23 -0
- package/dist/session/pre-publication-process.js +109 -0
- package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
- package/dist/session/pre-publication-skipped-tests.js +109 -0
- package/dist/session/pre-publication-step-execution.d.ts +12 -0
- package/dist/session/pre-publication-step-execution.js +50 -0
- package/dist/session/pre-publication-validation.d.ts +91 -0
- package/dist/session/pre-publication-validation.js +670 -0
- package/dist/session/provider-cli/bridge-cli.conformance-fixtures.d.ts +72 -0
- package/dist/session/provider-cli/bridge-cli.conformance-fixtures.js +462 -0
- package/dist/session/provider-cli/ci-repair-readiness.d.ts +8 -0
- package/dist/session/provider-cli/ci-repair-readiness.js +23 -3
- package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
- package/dist/session/provider-cli/claude-background-work.js +181 -0
- package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
- package/dist/session/provider-cli/host-build-lock.js +30 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
- package/dist/session/provider-cli/pre-publication-repair.js +276 -0
- package/dist/session/provider-cli/provider-cli.artifacts.d.ts +6 -3
- package/dist/session/provider-cli/provider-cli.artifacts.js +62 -22
- package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +75 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
- package/dist/session/provider-cli/provider-cli.deterministic.js +34 -2
- package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +85 -19
- package/dist/session/provider-cli/provider-cli.process.js +566 -283
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +15 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +211 -36
- package/dist/session/provider-cli/provider-cli.repair-epoch.d.ts +6 -0
- package/dist/session/provider-cli/provider-cli.repair-epoch.js +11 -0
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +22 -1
- package/dist/session/provider-cli/provider-cli.runtime.js +83 -4
- package/dist/session/provider-cli/provider-cli.service.d.ts +36 -5
- package/dist/session/provider-cli/provider-cli.service.js +818 -99
- package/dist/session/provider-cli/provider-cli.types.d.ts +32 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +10 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +92 -0
- package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
- package/dist/session/provider-cli/provider-output-pipes.js +67 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +18 -0
- package/dist/session/provider-cli/provider-output-state.js +376 -17
- package/dist/session/provider-cli/provider-usage.d.ts +9 -1
- package/dist/session/provider-cli/provider-usage.js +28 -5
- package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
- package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
- package/dist/session/publishable-worktree-changes.d.ts +54 -0
- package/dist/session/publishable-worktree-changes.js +193 -0
- package/dist/session/qa-sidecar-validation.d.ts +6 -0
- package/dist/session/qa-sidecar-validation.js +28 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +51 -0
- package/dist/session/sandbox-host-capacity-gate.js +257 -0
- package/dist/session/session-redaction.js +284 -9
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.service.d.ts +11 -2
- package/dist/session/session.service.js +301 -58
- package/dist/session/session.types.d.ts +150 -2
- package/dist/session/session.types.js +599 -7
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -0
- package/dist/session/unreferenced-exports.d.ts +12 -0
- package/dist/session/unreferenced-exports.js +59 -0
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -0
- package/dist/shared/format/format-bytes.d.ts +1 -0
- package/dist/shared/format/format-bytes.js +9 -0
- package/dist/shared/fs/file-identity.d.ts +10 -0
- package/dist/shared/fs/file-identity.js +15 -0
- package/dist/shared/fs/replace-file.d.ts +7 -0
- package/dist/shared/fs/replace-file.js +33 -0
- package/dist/shared/git/git.js +2 -1
- package/dist/shared/path/path.d.ts +1 -0
- package/dist/shared/path/path.js +18 -0
- package/dist/shared/process/dotnet-toolchain.d.ts +17 -0
- package/dist/shared/process/dotnet-toolchain.js +307 -0
- package/dist/shared/process/host-process-recovery.d.ts +14 -3
- package/dist/shared/process/host-process-recovery.js +26 -5
- package/dist/shared/process/host-process-supervisor.d.ts +16 -1
- package/dist/shared/process/host-process-supervisor.js +124 -23
- package/dist/shared/process/process-tree.d.ts +52 -0
- package/dist/shared/process/process-tree.js +144 -0
- package/dist/shared/process/process.d.ts +69 -0
- package/dist/shared/process/process.js +223 -16
- package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
- package/dist/shared/process/windows-app-execution-alias.js +45 -0
- package/dist/shared/process/windows-launch.d.ts +18 -0
- package/dist/shared/process/windows-launch.js +68 -0
- package/dist/shared/provider-capabilities.d.ts +3 -0
- package/dist/shared/provider-capabilities.js +92 -0
- package/dist/shared/redaction/redaction.d.ts +1 -0
- package/dist/shared/redaction/redaction.js +39 -3
- package/dist/shared/time/monotonic.d.ts +1 -0
- package/dist/shared/time/monotonic.js +8 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/dependency-warmer.d.ts +66 -9
- package/dist/worktree/dependency-warmer.js +609 -24
- package/dist/worktree/index.d.ts +1 -1
- package/dist/worktree/story-qa-reference-hydrator.d.ts +4 -0
- package/dist/worktree/story-qa-reference-hydrator.js +253 -0
- package/dist/worktree/wip-git.d.ts +33 -0
- package/dist/worktree/wip-git.js +122 -0
- package/dist/worktree/wip-refs.d.ts +62 -0
- package/dist/worktree/wip-refs.js +119 -0
- package/dist/worktree/wip-restore.d.ts +38 -0
- package/dist/worktree/wip-restore.js +190 -0
- package/dist/worktree/wip-snapshot.d.ts +50 -0
- package/dist/worktree/wip-snapshot.js +268 -0
- package/dist/worktree/worktree-wip-events.d.ts +18 -0
- package/dist/worktree/worktree-wip-events.js +98 -0
- package/dist/worktree/worktree-wip.d.ts +49 -0
- package/dist/worktree/worktree-wip.js +182 -0
- package/dist/worktree/worktree.base.d.ts +7 -1
- package/dist/worktree/worktree.service.d.ts +22 -2
- package/dist/worktree/worktree.service.js +302 -25
- package/dist/worktree/worktree.types.d.ts +36 -1
- package/package.json +8 -6
- package/runtime/windows-job-supervisor.ps1 +380 -14
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { formatBytes } from "../shared/format/format-bytes.js";
|
|
2
|
+
import { parseHostLoadGovernorMode } from "./host-load-governor-config.js";
|
|
3
|
+
// Decision 0014 §3 "Precedence" and §6 "Bridge hub": the server pushes a runner
|
|
4
|
+
// settings document (`ApplySettings`) and is the source of truth. Host env vars
|
|
5
|
+
// are one-sided safety bounds only: a ceiling on capacity, a floor on reserves.
|
|
6
|
+
// The bridge reports the effective values, their sources and every env bound it
|
|
7
|
+
// saw back to the server (`SettingsApplied`), so a host bound is never silent.
|
|
8
|
+
// Nothing here is persisted to bridge.json (0014 agent constraint).
|
|
9
|
+
export const runnerSettingKeys = [
|
|
10
|
+
"maxConcurrentAttempts",
|
|
11
|
+
"cpuBudgetPercent",
|
|
12
|
+
"yieldCpuBudgetPercent",
|
|
13
|
+
"memoryReserveBytes",
|
|
14
|
+
"maxHeavySteps",
|
|
15
|
+
"yieldToForeground",
|
|
16
|
+
];
|
|
17
|
+
export const defaultCpuBudgetPercent = 80;
|
|
18
|
+
export const defaultYieldCpuBudgetPercent = 50;
|
|
19
|
+
const MiB = 1024 ** 2;
|
|
20
|
+
const GiB = 1024 ** 3;
|
|
21
|
+
/** The server's ranges (contract); a value outside them is rejected, not clamped, so it is never silent. */
|
|
22
|
+
const serverRanges = {
|
|
23
|
+
maxConcurrentAttempts: { min: 1, max: 32 },
|
|
24
|
+
cpuBudgetPercent: { min: 10, max: 100 },
|
|
25
|
+
yieldCpuBudgetPercent: { min: 10, max: 100 },
|
|
26
|
+
memoryReserveBytes: { min: 512 * MiB, max: 128 * GiB },
|
|
27
|
+
maxHeavySteps: { min: 1, max: 64 },
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Computes every effective value (decision 0014 precedence):
|
|
31
|
+
* - ceiling keys: server != null ? min(server, ceiling ?? +inf) : (ceiling ?? default);
|
|
32
|
+
* - memory reserve (floor): server != null ? max(server, floor ?? 0) : (floor ?? adaptive default);
|
|
33
|
+
* - yield: server OR the local `forge-bridge yield on` flag.
|
|
34
|
+
* With no document at all (and the local flag off) the values equal today's env/default behaviour.
|
|
35
|
+
*/
|
|
36
|
+
export function computeEffectiveRunnerSettings(document, environment, hostDefaults, localYield) {
|
|
37
|
+
const rejected = [];
|
|
38
|
+
const server = (key) => {
|
|
39
|
+
const value = document?.[key] ?? null;
|
|
40
|
+
if (value === null)
|
|
41
|
+
return null;
|
|
42
|
+
const range = serverRanges[key];
|
|
43
|
+
if (typeof value !== "number" || !Number.isFinite(value) || !Number.isInteger(value)) {
|
|
44
|
+
rejected.push({ key, reason: `${String(value)} is not a whole number; the host default applies.`, kind: "invalid" });
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
if (value < range.min || value > range.max) {
|
|
48
|
+
rejected.push({ key, reason: `${value} is outside ${range.min}-${range.max}; the host default applies.`, kind: "invalid" });
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
return value;
|
|
52
|
+
};
|
|
53
|
+
const attemptsCeiling = integerEnv(environment, "FORGE_HOST_MAX_CONCURRENT_ATTEMPTS", 1, 32);
|
|
54
|
+
const cpuCeilings = cpuBudgetCeilings(environment);
|
|
55
|
+
const reserveFloor = integerEnv(environment, "FORGE_HOST_MEMORY_RESERVE_BYTES", 512 * MiB, 128 * GiB);
|
|
56
|
+
const heavyStepsCeiling = integerEnv(environment, "FORGE_HOST_MAX_HEAVY_STEPS", 1, 64);
|
|
57
|
+
const attempts = ceilingValue(server("maxConcurrentAttempts"), lowest(attemptsCeiling), hostDefaults.maxConcurrentAttempts);
|
|
58
|
+
const cpu = ceilingValue(server("cpuBudgetPercent"), lowest(...cpuCeilings), defaultCpuBudgetPercent);
|
|
59
|
+
// The yield budget's ceilings are the CPU budget's. Without a server value they
|
|
60
|
+
// cap its default rather than replace it: a host allowing 90% CPU must not raise
|
|
61
|
+
// the 50% yield default, which no env var sets today.
|
|
62
|
+
const serverYieldCpu = server("yieldCpuBudgetPercent");
|
|
63
|
+
const yieldCpu = ceilingValue(serverYieldCpu ?? defaultYieldCpuBudgetPercent, lowest(...cpuCeilings), defaultYieldCpuBudgetPercent);
|
|
64
|
+
const yieldCpuSource = serverYieldCpu === null && yieldCpu.source === "server" ? "default" : yieldCpu.source;
|
|
65
|
+
const reserve = floorValue(server("memoryReserveBytes"), reserveFloor?.value ?? null, hostDefaults.memoryReserveBytes);
|
|
66
|
+
const heavySteps = ceilingValue(server("maxHeavySteps"), lowest(heavyStepsCeiling), null);
|
|
67
|
+
const serverYield = document?.yieldToForeground === true;
|
|
68
|
+
const yielding = serverYield || localYield;
|
|
69
|
+
// The host's own switch wins the label: turning the server toggle off would not stop it.
|
|
70
|
+
const yieldSource = localYield ? "host_local" : serverYield ? "server" : "default";
|
|
71
|
+
const bounds = [];
|
|
72
|
+
const addCeilings = (key, set) => {
|
|
73
|
+
for (const bound of set)
|
|
74
|
+
if (bound)
|
|
75
|
+
bounds.push({ key, envVar: bound.envVar, value: bound.value, kind: "ceiling" });
|
|
76
|
+
};
|
|
77
|
+
addCeilings("maxConcurrentAttempts", [attemptsCeiling]);
|
|
78
|
+
addCeilings("cpuBudgetPercent", cpuCeilings);
|
|
79
|
+
addCeilings("yieldCpuBudgetPercent", cpuCeilings);
|
|
80
|
+
if (reserveFloor)
|
|
81
|
+
bounds.push({ key: "memoryReserveBytes", envVar: reserveFloor.envVar, value: reserveFloor.value, kind: "floor" });
|
|
82
|
+
addCeilings("maxHeavySteps", [heavyStepsCeiling]);
|
|
83
|
+
const values = {
|
|
84
|
+
maxConcurrentAttempts: attempts.value,
|
|
85
|
+
cpuBudgetPercent: cpu.value,
|
|
86
|
+
yieldCpuBudgetPercent: yieldCpu.value,
|
|
87
|
+
memoryReserveBytes: reserve.value,
|
|
88
|
+
maxHeavySteps: heavySteps.value,
|
|
89
|
+
yieldToForeground: yielding,
|
|
90
|
+
};
|
|
91
|
+
const budgetPercent = yielding ? Math.min(values.yieldCpuBudgetPercent, values.cpuBudgetPercent) : values.cpuBudgetPercent;
|
|
92
|
+
return {
|
|
93
|
+
report: {
|
|
94
|
+
version: null,
|
|
95
|
+
governor: parseHostLoadGovernorMode(environment.FORGE_HOST_LOAD_GOVERNOR),
|
|
96
|
+
values,
|
|
97
|
+
sources: {
|
|
98
|
+
maxConcurrentAttempts: attempts.source,
|
|
99
|
+
cpuBudgetPercent: cpu.source,
|
|
100
|
+
yieldCpuBudgetPercent: yieldCpuSource,
|
|
101
|
+
memoryReserveBytes: reserve.source,
|
|
102
|
+
maxHeavySteps: heavySteps.source,
|
|
103
|
+
yieldToForeground: yieldSource,
|
|
104
|
+
},
|
|
105
|
+
bounds,
|
|
106
|
+
rejected,
|
|
107
|
+
},
|
|
108
|
+
yielding,
|
|
109
|
+
governorCpuBudgetFraction: budgetPercent / 100,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Parses the `ApplySettings` argument. Returns null when it has no usable version
|
|
114
|
+
* (the bridge then ignores it); malformed values become null so the host default applies.
|
|
115
|
+
*/
|
|
116
|
+
export function parseRunnerSettingsDocument(raw) {
|
|
117
|
+
if (!raw || typeof raw !== "object")
|
|
118
|
+
return null;
|
|
119
|
+
const record = raw;
|
|
120
|
+
const version = record.version;
|
|
121
|
+
if (typeof version !== "number" || !Number.isSafeInteger(version) || version < 0)
|
|
122
|
+
return null;
|
|
123
|
+
const numeric = (key) => {
|
|
124
|
+
const value = record[key];
|
|
125
|
+
// Kept as-is (even out of range) so computeEffectiveRunnerSettings can report it as rejected.
|
|
126
|
+
return typeof value === "number" ? value : null;
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
runnerId: typeof record.runnerId === "string" ? record.runnerId : null,
|
|
130
|
+
version,
|
|
131
|
+
maxConcurrentAttempts: numeric("maxConcurrentAttempts"),
|
|
132
|
+
cpuBudgetPercent: numeric("cpuBudgetPercent"),
|
|
133
|
+
yieldCpuBudgetPercent: numeric("yieldCpuBudgetPercent"),
|
|
134
|
+
memoryReserveBytes: numeric("memoryReserveBytes"),
|
|
135
|
+
maxHeavySteps: numeric("maxHeavySteps"),
|
|
136
|
+
yieldToForeground: record.yieldToForeground === true,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The report for what is actually in force after an apply in which the host
|
|
141
|
+
* failed to put some keys in force: each failed key keeps the value (and source)
|
|
142
|
+
* that was in force before, and its failure is reported as an `apply_failed`
|
|
143
|
+
* rejection, so the server never reads a desired value as applied.
|
|
144
|
+
*/
|
|
145
|
+
export function runnerSettingsInForce(report, previous, failures) {
|
|
146
|
+
if (failures.length === 0)
|
|
147
|
+
return report;
|
|
148
|
+
const values = { ...report.values };
|
|
149
|
+
const sources = { ...report.sources };
|
|
150
|
+
for (const failure of failures) {
|
|
151
|
+
keepPrevious(values, previous.values, failure.key);
|
|
152
|
+
sources[failure.key] = previous.sources[failure.key];
|
|
153
|
+
}
|
|
154
|
+
return { ...report, values, sources, rejected: [...report.rejected, ...failures] };
|
|
155
|
+
}
|
|
156
|
+
function keepPrevious(target, previous, key) {
|
|
157
|
+
target[key] = previous[key];
|
|
158
|
+
}
|
|
159
|
+
/** True when two reports say the same thing (version included), so an unchanged recompute is not re-sent. */
|
|
160
|
+
export function sameRunnerSettingsReport(left, right) {
|
|
161
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
162
|
+
}
|
|
163
|
+
function ceilingValue(server, ceiling, fallback) {
|
|
164
|
+
if (server !== null) {
|
|
165
|
+
return ceiling && ceiling.value < server
|
|
166
|
+
? { value: ceiling.value, source: "host_env" }
|
|
167
|
+
: { value: server, source: "server" };
|
|
168
|
+
}
|
|
169
|
+
return ceiling ? { value: ceiling.value, source: "host_env" } : { value: fallback, source: "default" };
|
|
170
|
+
}
|
|
171
|
+
function floorValue(server, floor, fallback) {
|
|
172
|
+
if (server !== null) {
|
|
173
|
+
return floor !== null && floor > server
|
|
174
|
+
? { value: floor, source: "host_env" }
|
|
175
|
+
: { value: server, source: "server" };
|
|
176
|
+
}
|
|
177
|
+
return floor !== null ? { value: floor, source: "host_env" } : { value: fallback, source: "default" };
|
|
178
|
+
}
|
|
179
|
+
function lowest(...bounds) {
|
|
180
|
+
let result = null;
|
|
181
|
+
for (const bound of bounds) {
|
|
182
|
+
if (bound && (result === null || bound.value < result.value))
|
|
183
|
+
result = bound;
|
|
184
|
+
}
|
|
185
|
+
return result;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Both CPU ceilings: the new FORGE_HOST_CPU_BUDGET_PERCENT (10–100) and the
|
|
189
|
+
* existing FORGE_HOST_LOAD_CPU_BUDGET_FRACTION (0.05–1, the governor's own
|
|
190
|
+
* parse), reported as a percent.
|
|
191
|
+
*/
|
|
192
|
+
function cpuBudgetCeilings(environment) {
|
|
193
|
+
const percent = numberEnv(environment, "FORGE_HOST_CPU_BUDGET_PERCENT", 10, 100);
|
|
194
|
+
const fraction = numberEnv(environment, "FORGE_HOST_LOAD_CPU_BUDGET_FRACTION", 0.05, 1);
|
|
195
|
+
return [
|
|
196
|
+
percent,
|
|
197
|
+
fraction ? { envVar: fraction.envVar, value: Math.round(fraction.value * 10_000) / 100 } : null,
|
|
198
|
+
];
|
|
199
|
+
}
|
|
200
|
+
/** Matches the lease manager's parse (parseInt, clamped); an unparsable value counts as unset. */
|
|
201
|
+
function integerEnv(environment, envVar, minimum, maximum) {
|
|
202
|
+
const raw = environment[envVar];
|
|
203
|
+
if (raw === undefined || raw.trim() === "")
|
|
204
|
+
return null;
|
|
205
|
+
const parsed = Number.parseInt(raw, 10);
|
|
206
|
+
return Number.isFinite(parsed) ? { envVar, value: Math.max(minimum, Math.min(maximum, parsed)) } : null;
|
|
207
|
+
}
|
|
208
|
+
/** Matches the governor config's parse (Number, clamped); an unparsable value counts as unset. */
|
|
209
|
+
function numberEnv(environment, envVar, minimum, maximum) {
|
|
210
|
+
const raw = environment[envVar];
|
|
211
|
+
if (raw === undefined || raw.trim() === "")
|
|
212
|
+
return null;
|
|
213
|
+
const parsed = Number(raw);
|
|
214
|
+
return Number.isFinite(parsed) ? { envVar, value: Math.min(maximum, Math.max(minimum, parsed)) } : null;
|
|
215
|
+
}
|
|
216
|
+
/** The offer refusal message while the runner yields to foreground work. */
|
|
217
|
+
export function runnerYieldingMessage(report) {
|
|
218
|
+
const where = report.sources.yieldToForeground === "host_local" ? "on this host (forge-bridge yield on)" : "in Forge";
|
|
219
|
+
return `runner_yielding: this runner is yielding to foreground work (turned on ${where}); it takes no new attempts until yield is off. Running attempts continue.`;
|
|
220
|
+
}
|
|
221
|
+
/** One line describing the effective settings, for the bridge log. */
|
|
222
|
+
export function describeRunnerSettings(report) {
|
|
223
|
+
const { values } = report;
|
|
224
|
+
const parts = [
|
|
225
|
+
`max attempts ${values.maxConcurrentAttempts}`,
|
|
226
|
+
`CPU budget ${values.cpuBudgetPercent}%`,
|
|
227
|
+
`yield budget ${values.yieldCpuBudgetPercent}%`,
|
|
228
|
+
`memory reserve ${formatBytes(values.memoryReserveBytes)}`,
|
|
229
|
+
`heavy steps ${values.maxHeavySteps ?? "budget only"}`,
|
|
230
|
+
`yield ${values.yieldToForeground ? "on" : "off"}`,
|
|
231
|
+
];
|
|
232
|
+
const capped = report.bounds
|
|
233
|
+
.filter(bound => report.sources[bound.key] === "host_env")
|
|
234
|
+
.map(bound => `${bound.envVar}=${bound.value}`);
|
|
235
|
+
return `${parts.join(", ")}${capped.length > 0 ? `; host bounds in force: ${[...new Set(capped)].join(", ")}` : ""}`;
|
|
236
|
+
}
|
|
@@ -57,7 +57,10 @@ export function transitionRuntimeIsolationLease(lease, nextState, occurredAt = n
|
|
|
57
57
|
return transitioned;
|
|
58
58
|
}
|
|
59
59
|
export function renewRuntimeIsolationLease(lease, fencingToken, expiresAt) {
|
|
60
|
-
if (lease.fencingToken !== fencingToken
|
|
60
|
+
if (lease.fencingToken !== fencingToken
|
|
61
|
+
|| lease.state === "releasing"
|
|
62
|
+
|| lease.state === "released"
|
|
63
|
+
|| !validTimestamp(expiresAt))
|
|
61
64
|
return null;
|
|
62
65
|
const renewed = { ...lease, expiresAt };
|
|
63
66
|
return validRuntimeIsolationLease(renewed) ? renewed : null;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const minimumWorkspaceEstimateBytes: number;
|
|
2
|
+
export declare const architectMinimumWorkspaceEstimateBytes: number;
|
|
3
|
+
export interface RepositoryWorkspaceFootprint {
|
|
4
|
+
readonly sourceBytes: number;
|
|
5
|
+
readonly hasNode: boolean;
|
|
6
|
+
readonly hasDotNet: boolean;
|
|
7
|
+
readonly hasBrowser: boolean;
|
|
8
|
+
readonly serviceCount: number;
|
|
9
|
+
}
|
|
10
|
+
export interface WorkspaceEstimateHints {
|
|
11
|
+
readonly role?: string | null;
|
|
12
|
+
readonly serviceCount?: number;
|
|
13
|
+
readonly browser?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function estimateWorkspaceBytesFromRepo(repoPath: string, hints?: WorkspaceEstimateHints): Promise<number>;
|
|
16
|
+
export declare function calculateWorkspaceBytes(footprint: RepositoryWorkspaceFootprint, role?: string | null): number;
|
|
17
|
+
export declare function measureRepositoryWorkspace(repoPath: string): Promise<RepositoryWorkspaceFootprint>;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import readline from "node:readline";
|
|
5
|
+
const GiB = 1024 ** 3;
|
|
6
|
+
const alignmentBytes = 512 * 1024 ** 2;
|
|
7
|
+
export const minimumWorkspaceEstimateBytes = 2 * GiB;
|
|
8
|
+
export const architectMinimumWorkspaceEstimateBytes = GiB;
|
|
9
|
+
const maximumBytes = 100 * GiB;
|
|
10
|
+
const footprintCacheLifetimeMs = 5 * 60_000;
|
|
11
|
+
const excludedDirectories = new Set([
|
|
12
|
+
".git",
|
|
13
|
+
".artifacts",
|
|
14
|
+
".forge-worktrees",
|
|
15
|
+
".local",
|
|
16
|
+
".next",
|
|
17
|
+
".nuget",
|
|
18
|
+
".pnpm-store",
|
|
19
|
+
".tmp",
|
|
20
|
+
".turbo",
|
|
21
|
+
"artifacts",
|
|
22
|
+
"bin",
|
|
23
|
+
"build",
|
|
24
|
+
"coverage",
|
|
25
|
+
"dist",
|
|
26
|
+
"node_modules",
|
|
27
|
+
"obj",
|
|
28
|
+
"testresults",
|
|
29
|
+
]);
|
|
30
|
+
const footprintCache = new Map();
|
|
31
|
+
export async function estimateWorkspaceBytesFromRepo(repoPath, hints = {}) {
|
|
32
|
+
const cacheKey = path.resolve(repoPath);
|
|
33
|
+
const cached = footprintCache.get(cacheKey);
|
|
34
|
+
const footprint = cached && Date.now() - cached.measuredAt < footprintCacheLifetimeMs
|
|
35
|
+
? cached.footprint
|
|
36
|
+
: await measureRepositoryWorkspace(cacheKey);
|
|
37
|
+
if (!cached || cached.footprint !== footprint) {
|
|
38
|
+
footprintCache.set(cacheKey, { measuredAt: Date.now(), footprint });
|
|
39
|
+
}
|
|
40
|
+
return calculateWorkspaceBytes({
|
|
41
|
+
...footprint,
|
|
42
|
+
hasBrowser: footprint.hasBrowser || hints.browser === true,
|
|
43
|
+
serviceCount: Math.max(footprint.serviceCount, Math.max(0, hints.serviceCount ?? 0)),
|
|
44
|
+
}, hints.role);
|
|
45
|
+
}
|
|
46
|
+
export function calculateWorkspaceBytes(footprint, role) {
|
|
47
|
+
const normalizedRole = role?.trim().toLowerCase() ?? "";
|
|
48
|
+
if (normalizedRole === "architect") {
|
|
49
|
+
// Architect owns a checkout and planning artifacts, not dependencies,
|
|
50
|
+
// build outputs, browser state, services, or application runtime output.
|
|
51
|
+
const estimate = architectMinimumWorkspaceEstimateBytes
|
|
52
|
+
+ Math.max(0, footprint.sourceBytes) * 2;
|
|
53
|
+
return Math.min(maximumBytes, Math.max(architectMinimumWorkspaceEstimateBytes, alignUp(estimate, alignmentBytes)));
|
|
54
|
+
}
|
|
55
|
+
let estimate = 2 * GiB + Math.max(0, footprint.sourceBytes) * 3;
|
|
56
|
+
if (footprint.hasNode)
|
|
57
|
+
estimate += 3 * GiB;
|
|
58
|
+
if (footprint.hasDotNet)
|
|
59
|
+
estimate += 2 * GiB;
|
|
60
|
+
if (footprint.hasBrowser)
|
|
61
|
+
estimate += 1536 * 1024 ** 2;
|
|
62
|
+
estimate += Math.max(0, footprint.serviceCount) * GiB;
|
|
63
|
+
if (["qa", "ci_repair", "pr_fix"].includes(normalizedRole)) {
|
|
64
|
+
estimate += GiB;
|
|
65
|
+
}
|
|
66
|
+
return Math.min(maximumBytes, Math.max(minimumWorkspaceEstimateBytes, alignUp(estimate, alignmentBytes)));
|
|
67
|
+
}
|
|
68
|
+
export async function measureRepositoryWorkspace(repoPath) {
|
|
69
|
+
return await measureGitWorkspace(repoPath) ?? await measureFilesystemFallback(repoPath);
|
|
70
|
+
}
|
|
71
|
+
async function measureGitWorkspace(repoPath) {
|
|
72
|
+
let sourceBytes = 0;
|
|
73
|
+
let hasNode = false;
|
|
74
|
+
let hasDotNet = false;
|
|
75
|
+
let hasBrowser = false;
|
|
76
|
+
let serviceCount = 0;
|
|
77
|
+
const child = spawn("git", ["-c", "core.quotepath=false", "ls-files", "--cached", "--others", "--exclude-standard"], {
|
|
78
|
+
cwd: repoPath,
|
|
79
|
+
env: { ...process.env, GIT_OPTIONAL_LOCKS: "0" },
|
|
80
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
81
|
+
windowsHide: true,
|
|
82
|
+
});
|
|
83
|
+
const closed = new Promise((resolve) => {
|
|
84
|
+
child.once("close", resolve);
|
|
85
|
+
child.once("error", () => resolve(null));
|
|
86
|
+
});
|
|
87
|
+
try {
|
|
88
|
+
const lines = readline.createInterface({ input: child.stdout, crlfDelay: Infinity });
|
|
89
|
+
for await (const relativePath of lines) {
|
|
90
|
+
if (!relativePath.trim())
|
|
91
|
+
continue;
|
|
92
|
+
const file = await inspectWorkspaceFile(path.join(repoPath, relativePath));
|
|
93
|
+
if (!file)
|
|
94
|
+
continue;
|
|
95
|
+
sourceBytes += file.bytes;
|
|
96
|
+
hasNode ||= file.hasNode;
|
|
97
|
+
hasDotNet ||= file.hasDotNet;
|
|
98
|
+
hasBrowser ||= file.hasBrowser;
|
|
99
|
+
serviceCount = Math.max(serviceCount, file.serviceCount);
|
|
100
|
+
}
|
|
101
|
+
return await closed === 0 ? { sourceBytes, hasNode, hasDotNet, hasBrowser, serviceCount } : null;
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
child.kill();
|
|
105
|
+
await closed;
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async function measureFilesystemFallback(repoPath) {
|
|
110
|
+
let sourceBytes = 0;
|
|
111
|
+
let hasNode = false;
|
|
112
|
+
let hasDotNet = false;
|
|
113
|
+
let hasBrowser = false;
|
|
114
|
+
let serviceCount = 0;
|
|
115
|
+
const pending = [path.resolve(repoPath)];
|
|
116
|
+
while (pending.length > 0) {
|
|
117
|
+
const current = pending.pop();
|
|
118
|
+
const entries = await fs.readdir(current, { withFileTypes: true }).catch(() => []);
|
|
119
|
+
for (const entry of entries) {
|
|
120
|
+
const entryPath = path.join(current, entry.name);
|
|
121
|
+
if (entry.isDirectory()) {
|
|
122
|
+
if (!excludedDirectories.has(entry.name.toLowerCase()))
|
|
123
|
+
pending.push(entryPath);
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (!entry.isFile())
|
|
127
|
+
continue;
|
|
128
|
+
const file = await inspectWorkspaceFile(entryPath);
|
|
129
|
+
if (!file)
|
|
130
|
+
continue;
|
|
131
|
+
sourceBytes += file.bytes;
|
|
132
|
+
hasNode ||= file.hasNode;
|
|
133
|
+
hasDotNet ||= file.hasDotNet;
|
|
134
|
+
hasBrowser ||= file.hasBrowser;
|
|
135
|
+
serviceCount = Math.max(serviceCount, file.serviceCount);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return { sourceBytes, hasNode, hasDotNet, hasBrowser, serviceCount };
|
|
139
|
+
}
|
|
140
|
+
async function inspectWorkspaceFile(filePath) {
|
|
141
|
+
const stat = await fs.stat(filePath).catch(() => null);
|
|
142
|
+
if (!stat?.isFile())
|
|
143
|
+
return null;
|
|
144
|
+
const name = path.basename(filePath).toLowerCase();
|
|
145
|
+
const sandbox = name === "forge.sandbox.yml" || name === "forge.sandbox.yaml";
|
|
146
|
+
return {
|
|
147
|
+
bytes: stat.size,
|
|
148
|
+
hasNode: ["package.json", "pnpm-lock.yaml", "package-lock.json", "yarn.lock"].includes(name),
|
|
149
|
+
hasDotNet: name.endsWith(".sln") || name.endsWith(".csproj") || name.endsWith(".fsproj"),
|
|
150
|
+
hasBrowser: name.startsWith("playwright.config"),
|
|
151
|
+
serviceCount: sandbox
|
|
152
|
+
? countSandboxServices(await fs.readFile(filePath, "utf8").catch(() => ""))
|
|
153
|
+
: 0,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function countSandboxServices(yaml) {
|
|
157
|
+
let inServices = false;
|
|
158
|
+
let count = 0;
|
|
159
|
+
for (const rawLine of yaml.split(/\r?\n/gu)) {
|
|
160
|
+
const line = rawLine.trim();
|
|
161
|
+
if (!line || line.startsWith("#"))
|
|
162
|
+
continue;
|
|
163
|
+
if (!/^\s/u.test(rawLine)) {
|
|
164
|
+
inServices = line.toLowerCase() === "services:";
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
if (inServices && line.startsWith("-"))
|
|
168
|
+
count += 1;
|
|
169
|
+
}
|
|
170
|
+
return count;
|
|
171
|
+
}
|
|
172
|
+
function alignUp(value, alignment) {
|
|
173
|
+
return Math.ceil(value / alignment) * alignment;
|
|
174
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { HostLoadStepGate } from "../runtime/host-load-governor.js";
|
|
2
|
+
import type { HostLoadStepProcess } from "../runtime/host-load-step-reaper.js";
|
|
3
|
+
import type { HostLoadTokenPriority } from "../runtime/host-load-token-ledger.js";
|
|
4
|
+
export declare const sandboxHostCapacityBrokerEnvironment = "FORGE_HOST_LOAD_BROKER";
|
|
5
|
+
export declare const sandboxHostCapacityBrokerProtocol = "stdout-v1";
|
|
6
|
+
export declare const sandboxHostCapacityLineType = "forge_host_capacity";
|
|
7
|
+
export declare const sandboxHostCapacityResponseRoot = "/run/forge/host-capacity";
|
|
8
|
+
/** Owner of authentic replies inside the container: root, via `docker exec --user 0`. */
|
|
9
|
+
export declare const sandboxHostCapacityResponseOwnerUid = 0;
|
|
10
|
+
export declare const sandboxHostCapacityMaxWaitEnvironment = "FORGE_HOST_LOAD_BROKER_MAX_WAIT_MS";
|
|
11
|
+
export interface SandboxHostCapacityRequest {
|
|
12
|
+
readonly action: "acquire" | "release" | "retain";
|
|
13
|
+
readonly requestId: string;
|
|
14
|
+
readonly stepClass: string;
|
|
15
|
+
readonly label: string;
|
|
16
|
+
}
|
|
17
|
+
export interface SandboxHostCapacityResponse {
|
|
18
|
+
readonly requestId: string;
|
|
19
|
+
/** Rises with every reply the broker sends; the container keeps only the newest. */
|
|
20
|
+
readonly sequence: number;
|
|
21
|
+
readonly status: "waiting" | "admitted" | "failed" | "fenced";
|
|
22
|
+
readonly waitMs?: number;
|
|
23
|
+
readonly reason?: string;
|
|
24
|
+
readonly detail?: string;
|
|
25
|
+
readonly code?: string;
|
|
26
|
+
readonly message?: string;
|
|
27
|
+
}
|
|
28
|
+
export type SandboxHostCapacityDelivery = (response: SandboxHostCapacityResponse) => Promise<void>;
|
|
29
|
+
/** Parses one stdout line; null when it is not a well-formed broker request. */
|
|
30
|
+
export declare function parseSandboxHostCapacityRequest(line: string): SandboxHostCapacityRequest | null;
|
|
31
|
+
export interface SandboxHostCapacityBrokerOptions {
|
|
32
|
+
/** Requests (acquire or release) one sandbox may hold or start at once. */
|
|
33
|
+
readonly maximumOutstanding?: number;
|
|
34
|
+
/** Request lines allowed in a burst, and their sustained rate. */
|
|
35
|
+
readonly burst?: number;
|
|
36
|
+
readonly refillPerSecond?: number;
|
|
37
|
+
/** The sandbox's process tree (its container's init), recorded on each brokered token. */
|
|
38
|
+
readonly stepProcess?: () => Promise<HostLoadStepProcess | null>;
|
|
39
|
+
/** Delay before retrying a failed delivery; doubles up to a few seconds. */
|
|
40
|
+
readonly retryMs?: number;
|
|
41
|
+
readonly now?: () => number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* One sandbox's brokered tokens. The sandbox never chooses the cost or the
|
|
45
|
+
* attempt. Replies for one request go out one at a time, newest state only,
|
|
46
|
+
* each with a rising sequence the container-side writer uses to refuse an
|
|
47
|
+
* older reply; a failed delivery is retried until a newer state replaces it
|
|
48
|
+
* or the broker closes. A sandbox that floods requests or exceeds its
|
|
49
|
+
* outstanding limit stops the broker and fails its attempt.
|
|
50
|
+
*/
|
|
51
|
+
export declare class SandboxHostCapacityBroker {
|
|
52
|
+
private readonly gate;
|
|
53
|
+
private readonly dispatchAttemptId;
|
|
54
|
+
private readonly priority;
|
|
55
|
+
private readonly deliver;
|
|
56
|
+
private readonly options;
|
|
57
|
+
private readonly tokens;
|
|
58
|
+
private readonly deliveries;
|
|
59
|
+
private readonly work;
|
|
60
|
+
private readonly maximumOutstanding;
|
|
61
|
+
private readonly burst;
|
|
62
|
+
private readonly refillPerSecond;
|
|
63
|
+
private readonly retryMs;
|
|
64
|
+
private readonly now;
|
|
65
|
+
private sequence;
|
|
66
|
+
private allowance;
|
|
67
|
+
private allowanceAtMs;
|
|
68
|
+
private closed;
|
|
69
|
+
private abuse;
|
|
70
|
+
constructor(gate: HostLoadStepGate, dispatchAttemptId: string, priority: HostLoadTokenPriority, deliver: SandboxHostCapacityDelivery, options?: SandboxHostCapacityBrokerOptions);
|
|
71
|
+
/**
|
|
72
|
+
* True when the line was a broker request; such a line is never a runner
|
|
73
|
+
* event. Throws sandbox_host_capacity_abuse once the sandbox breaks its
|
|
74
|
+
* limits: its tokens are returned and the attempt fails with that reason.
|
|
75
|
+
*/
|
|
76
|
+
handleLine(line: string): boolean;
|
|
77
|
+
/** The sandbox exited: cancel its waits and return every token it holds. */
|
|
78
|
+
close(): Promise<void>;
|
|
79
|
+
/** Requests waiting or admitted, for diagnostics and tests. */
|
|
80
|
+
outstanding(): number;
|
|
81
|
+
private stop;
|
|
82
|
+
private takeAllowance;
|
|
83
|
+
private track;
|
|
84
|
+
private acquire;
|
|
85
|
+
/**
|
|
86
|
+
* The sandbox's step ended but part of its tree may still run: the host token is
|
|
87
|
+
* kept, marked retained (so the attempt's own next step does not wait for it),
|
|
88
|
+
* until the sandbox releases the request or exits.
|
|
89
|
+
*/
|
|
90
|
+
private retain;
|
|
91
|
+
private release;
|
|
92
|
+
/** Queues the newest state for a request; at most one delivery per request is in flight. */
|
|
93
|
+
private respond;
|
|
94
|
+
private pump;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Adds the broker variables to a worker `docker create` command, just before
|
|
98
|
+
* its image: the protocol, and the host's maximum queue wait so the
|
|
99
|
+
* container's own fail-safe never fires before the host answers.
|
|
100
|
+
*/
|
|
101
|
+
export declare function withSandboxHostCapacityBroker(createArgs: readonly string[], image: string, maxWaitMs: number): string[];
|
|
102
|
+
/** `docker exec` arguments that write one reply into the container as root. */
|
|
103
|
+
export declare function sandboxHostCapacityDeliveryExecArgs(container: string): string[];
|
|
104
|
+
/**
|
|
105
|
+
* The `node -e` script that writes one response file inside the container, run
|
|
106
|
+
* as root. It keeps the newest reply: one with a lower or equal sequence than
|
|
107
|
+
* the file already holds is dropped, so a late delivery can never replace a
|
|
108
|
+
* newer state. Replies are world-readable but owned by the writer (root, via
|
|
109
|
+
* `docker exec --user 0`). The directory must already be owned by that same uid
|
|
110
|
+
* and writable by no one else, i.e. the root-owned reply mount; it is never
|
|
111
|
+
* created here, where it could turn out to be the sandbox's own directory. A
|
|
112
|
+
* runtime without POSIX user ids (Windows) cannot prove that, so the script
|
|
113
|
+
* writes nothing there (exit 3), as for any directory it cannot trust.
|
|
114
|
+
*/
|
|
115
|
+
export declare const sandboxHostCapacityResponseScript: string;
|