@loucompanion/forge-bridge 0.1.4-dev.04a1e5b9e484 → 0.1.4-dev.176dfdaf5020
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 +145 -4
- 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 +10 -0
- package/dist/bridge/bridge-chat.types.js +16 -1
- 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 +9 -0
- package/dist/bridge/bridge.service.d.ts +101 -15
- package/dist/bridge/bridge.service.js +472 -345
- package/dist/bridge/bridge.types.d.ts +27 -0
- package/dist/bridge/dispatch-result-outbox.d.ts +11 -1
- package/dist/bridge/dispatch-result-outbox.js +31 -6
- package/dist/bridge/in-flight-registry.d.ts +62 -0
- package/dist/bridge/in-flight-registry.js +207 -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 +5 -1
- package/dist/bridge/readiness-result-outbox.js +20 -0
- package/dist/bridge/runner-host-capabilities.d.ts +5 -0
- package/dist/bridge/runner-host-capabilities.js +17 -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 +20 -1
- package/dist/cleanup/cleanup.service.js +150 -169
- 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 +76 -14
- package/dist/cli/cli.service.d.ts +19 -10
- package/dist/cli/cli.service.js +152 -187
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +6 -0
- package/dist/cli/local-config.js +32 -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 +20 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +184 -18
- package/dist/runtime/attempt-database-broker.d.ts +1 -1
- package/dist/runtime/attempt-node-runtime-launcher.js +9 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +21 -0
- package/dist/runtime/attempt-process-supervisor.js +62 -6
- package/dist/runtime/docker-engine-probe.d.ts +5 -0
- package/dist/runtime/docker-engine-probe.js +7 -0
- package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
- package/dist/runtime/dotnet-build-outputs.js +402 -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/host-database-capability-boundary.d.ts +1 -1
- package/dist/runtime/host-database-capability-boundary.js +1 -0
- package/dist/runtime/host-facts.d.ts +36 -0
- package/dist/runtime/host-facts.js +95 -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-pressure-stall.d.ts +61 -0
- package/dist/runtime/host-pressure-stall.js +168 -0
- package/dist/runtime/host-runtime-contract.d.ts +16 -0
- package/dist/runtime/host-runtime-contract.js +35 -2
- package/dist/runtime/host-runtime-lease.d.ts +77 -5
- package/dist/runtime/host-runtime-lease.js +328 -136
- package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
- package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
- package/dist/runtime/host-runtime-promotion.d.ts +23 -0
- package/dist/runtime/host-runtime-promotion.js +48 -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/native-test-postgres-fallback.d.ts +51 -7
- package/dist/runtime/native-test-postgres-fallback.js +60 -8
- 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 +18 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +61 -55
- package/dist/runtime/runner-settings.d.ts +104 -0
- package/dist/runtime/runner-settings.js +236 -0
- package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
- package/dist/runtime/supervised-runtime-build-guard.js +112 -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 +90 -0
- package/dist/sandbox/provider-auth/codex.js +11 -11
- package/dist/sandbox/runtime.d.ts +10 -1
- package/dist/sandbox/runtime.js +47 -8
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -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 +27 -7
- package/dist/session/managed-attempt-tools.js +406 -123
- package/dist/session/managed-build-coordinator.d.ts +17 -1
- package/dist/session/managed-build-coordinator.js +14 -1
- package/dist/session/managed-build-receipt.d.ts +5 -0
- package/dist/session/managed-build-receipt.js +8 -3
- package/dist/session/managed-command-host-load.d.ts +47 -0
- package/dist/session/managed-command-host-load.js +83 -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 +7 -0
- package/dist/session/phase-completion.artifacts.js +100 -26
- 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 +12 -0
- package/dist/session/phase-completion.helpers.js +13 -12
- package/dist/session/phase-completion.js +5 -0
- 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 +6 -1
- package/dist/session/phase-completion.runtime.d.ts +5 -11
- package/dist/session/phase-completion.runtime.js +111 -230
- 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 +208 -231
- package/dist/session/phase-completion.validation.d.ts +2 -3
- package/dist/session/phase-completion.validation.js +49 -93
- 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 +37 -21
- package/dist/session/pre-publication-validation.js +228 -219
- 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 +2 -1
- package/dist/session/provider-cli/provider-cli.artifacts.js +21 -15
- 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.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 +46 -31
- package/dist/session/provider-cli/provider-cli.process.js +286 -403
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +87 -32
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +8 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +29 -1
- package/dist/session/provider-cli/provider-cli.service.d.ts +7 -1
- package/dist/session/provider-cli/provider-cli.service.js +207 -192
- package/dist/session/provider-cli/provider-cli.types.d.ts +30 -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 +8 -0
- package/dist/session/provider-cli/provider-output-state.js +15 -0
- package/dist/session/provider-cli/provider-usage.d.ts +2 -1
- 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 +31 -181
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.service.d.ts +11 -2
- package/dist/session/session.service.js +189 -69
- package/dist/session/session.types.d.ts +3 -0
- package/dist/session/session.types.js +15 -3
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -0
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -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/process/host-process-recovery.d.ts +14 -3
- package/dist/shared/process/host-process-recovery.js +23 -3
- package/dist/shared/process/host-process-supervisor.d.ts +14 -1
- package/dist/shared/process/host-process-supervisor.js +67 -15
- 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 +67 -0
- package/dist/shared/process/process.js +213 -11
- 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.js +14 -7
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/dependency-warmer.d.ts +25 -0
- package/dist/worktree/dependency-warmer.js +120 -10
- package/dist/worktree/orphan-relink.d.ts +19 -0
- package/dist/worktree/orphan-relink.js +106 -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-inputs.d.ts +8 -0
- package/dist/worktree/worktree-inputs.js +134 -0
- package/dist/worktree/worktree-origin-sync.d.ts +34 -0
- package/dist/worktree/worktree-origin-sync.js +127 -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 +50 -0
- package/dist/worktree/worktree-wip.js +185 -0
- package/dist/worktree/worktree.base.d.ts +7 -1
- package/dist/worktree/worktree.service.d.ts +36 -5
- package/dist/worktree/worktree.service.js +124 -155
- package/dist/worktree/worktree.types.d.ts +38 -0
- package/package.json +2 -2
package/dist/sandbox/runtime.js
CHANGED
|
@@ -5,9 +5,16 @@ import { fileURLToPath } from "node:url";
|
|
|
5
5
|
import { createFailureEnvelope, ForgeFailureError, failureFactsForCode, failurePolicyForCode, failureResult, parseRunOnceResultPacket, } from "../session/session.types.js";
|
|
6
6
|
import { dockerfileUpstreamImages, validateDockerfilePolicy, validateSandboxContract } from "./contract.js";
|
|
7
7
|
import { requireSandboxProcess, runSandboxProcess } from "./process.js";
|
|
8
|
+
import { advanceCheckedOutBranch } from "./managed-branch.js";
|
|
8
9
|
import { createLeaseUpdate } from "./lease-watchdog.js";
|
|
9
10
|
import { evaluateSandboxImagePolicy, hasSandboxImagePolicyRecord, sandboxImagePolicyConfigurationDigest, verifySandboxImageSignature } from "./image-policy.js";
|
|
10
11
|
import { SandboxEventBudget } from "./event-budget.js";
|
|
12
|
+
import { SandboxHostCapacityBroker, sandboxHostCapacityDeliveryExecArgs, withSandboxHostCapacityBroker, } from "./host-capacity-broker.js";
|
|
13
|
+
import { defaultHostLoadGovernorConfig } from "../runtime/host-load-governor-config.js";
|
|
14
|
+
import { captureHostProcessIdentity } from "../shared/process/host-process-supervisor.js";
|
|
15
|
+
import { FileForgeCgroupRegistry } from "../runtime/host-load-forge-cgroups.js";
|
|
16
|
+
import { trackSandboxCgroups } from "./sandbox-cgroups.js";
|
|
17
|
+
import { runtimeAdmissionPriority } from "../runtime/host-runtime-lease.js";
|
|
11
18
|
import { RepositoryCoordinatorLock } from "./repository-lock.js";
|
|
12
19
|
import { redactText } from "../shared/redaction/redaction.js";
|
|
13
20
|
import { createRuntimeIsolationLease, renewRuntimeIsolationLease, transitionRuntimeIsolationLease, validRuntimeIsolationLease, withRuntimeIsolationResources, } from "../runtime/runtime-isolation-lease.js";
|
|
@@ -18,14 +25,21 @@ const bridgeRuntimeDigestLabel = "dev.forge.bridge-runtime-digest";
|
|
|
18
25
|
export class DockerSandboxRuntime {
|
|
19
26
|
config;
|
|
20
27
|
publicationGrantRedeemer;
|
|
28
|
+
hostLoadGate;
|
|
21
29
|
active = new Map();
|
|
22
30
|
degraded = new Set();
|
|
23
31
|
builds = new Map();
|
|
24
32
|
verifiedCatalogImages = new Set();
|
|
25
33
|
buildTail = Promise.resolve();
|
|
26
|
-
|
|
34
|
+
/** Shared with every sampler on the state root, so sandbox CPU is never external load. */
|
|
35
|
+
forgeCgroups;
|
|
36
|
+
constructor(config, publicationGrantRedeemer,
|
|
37
|
+
/** The host load governor; with it on, the sandbox's validation steps are brokered through it (decision 0013). */
|
|
38
|
+
hostLoadGate) {
|
|
27
39
|
this.config = config;
|
|
28
40
|
this.publicationGrantRedeemer = publicationGrantRedeemer;
|
|
41
|
+
this.hostLoadGate = hostLoadGate;
|
|
42
|
+
this.forgeCgroups = new FileForgeCgroupRegistry(config.sandboxStateRoot);
|
|
29
43
|
}
|
|
30
44
|
async runOnce(dispatch, sink, signal) {
|
|
31
45
|
if (!dispatch.sandbox || dispatch.sandbox.executionMode !== "docker" || dispatch.sandbox.runtime !== "docker") {
|
|
@@ -153,7 +167,11 @@ export class DockerSandboxRuntime {
|
|
|
153
167
|
await this.initializeEgressPolicy(builtImage.helperImageDigest, runtimeDispatch, resources, labels, runtimeSignal);
|
|
154
168
|
const egressProxy = await this.startEgressProxy(runtimeDispatch, resources, labels, securityOptions, sink, runtimeSignal);
|
|
155
169
|
const serviceContainers = await this.startServices(validated, runtimeDispatch.sandbox.executionPolicy, resources, labels, securityOptions, sink, runtimeSignal);
|
|
156
|
-
const
|
|
170
|
+
const brokered = this.hostLoadGate?.enabled === true;
|
|
171
|
+
const workerArgs = workerCreateArgs(runtimeDispatch, validated, resources, labels, imageDigest, securityOptions);
|
|
172
|
+
const createArgs = brokered
|
|
173
|
+
? withSandboxHostCapacityBroker(workerArgs, imageDigest, this.hostLoadGate.maxWaitMs ?? defaultHostLoadGovernorConfig.maxWaitMs)
|
|
174
|
+
: workerArgs;
|
|
157
175
|
const createdContainer = await this.docker(createArgs, 60_000, runtimeSignal);
|
|
158
176
|
const containerId = dockerObjectId(createdContainer.stdout, "container");
|
|
159
177
|
await this.docker(["cp", prepared.bundlePath, `${containerId}:/control/input/repo.bundle`], 60_000, runtimeSignal);
|
|
@@ -183,6 +201,16 @@ export class DockerSandboxRuntime {
|
|
|
183
201
|
runtimeLease: active.runtimeLease,
|
|
184
202
|
}));
|
|
185
203
|
const eventBudget = new SandboxEventBudget();
|
|
204
|
+
const hostCapacity = brokered
|
|
205
|
+
? new SandboxHostCapacityBroker(this.hostLoadGate, runtimeDispatch.sandbox.dispatchAttemptId, runtimeAdmissionPriority(runtimeDispatch), async (response) => void await requireSandboxProcess({
|
|
206
|
+
command: this.config.dockerExecutable,
|
|
207
|
+
// As root, into the root-owned reply mount the sandbox user cannot write.
|
|
208
|
+
args: this.dockerArgs(sandboxHostCapacityDeliveryExecArgs(containerId)),
|
|
209
|
+
input: `${JSON.stringify(response)}\n`,
|
|
210
|
+
timeoutMs: 10_000,
|
|
211
|
+
maxOutputBytes: 16 * 1024,
|
|
212
|
+
}), { stepProcess: async () => await this.containerInitProcess(containerId) })
|
|
213
|
+
: null;
|
|
186
214
|
const startPromise = runSandboxProcess({
|
|
187
215
|
command: this.config.dockerExecutable,
|
|
188
216
|
args: this.dockerArgs(["start", "--attach", "--interactive", containerId]),
|
|
@@ -198,6 +226,8 @@ export class DockerSandboxRuntime {
|
|
|
198
226
|
signal: runtimeSignal,
|
|
199
227
|
onStdoutLine: async (line) => {
|
|
200
228
|
eventBudget.accept(line);
|
|
229
|
+
if (hostCapacity?.handleLine(line))
|
|
230
|
+
return;
|
|
201
231
|
const streamedEvent = parseSandboxEventLine(line);
|
|
202
232
|
if (streamedEvent) {
|
|
203
233
|
if (streamedEvent.eventType === "provider_cli_started")
|
|
@@ -207,7 +237,14 @@ export class DockerSandboxRuntime {
|
|
|
207
237
|
}
|
|
208
238
|
});
|
|
209
239
|
const memorySampler = this.startPeakMemorySampler(runtimeContainers);
|
|
240
|
+
// The sandbox's CPU is Forge's own work, not external load, for the governor.
|
|
241
|
+
const untrackCgroups = brokered
|
|
242
|
+
? trackSandboxCgroups(this.forgeCgroups, runtimeDispatch.sandbox.dispatchAttemptId, runtimeContainers.map(container => container.id), async (ids) => (await this.docker(["inspect", "--format", "{{.State.Pid}}", ...ids], 10_000)).stdout)
|
|
243
|
+
: null;
|
|
210
244
|
const start = await startPromise.finally(async () => {
|
|
245
|
+
// The worker exited: its queued and admitted host load tokens go back to the budget.
|
|
246
|
+
untrackCgroups?.();
|
|
247
|
+
await hostCapacity?.close();
|
|
211
248
|
const telemetry = await memorySampler.stop();
|
|
212
249
|
if (!telemetry)
|
|
213
250
|
return;
|
|
@@ -1105,6 +1142,13 @@ export class DockerSandboxRuntime {
|
|
|
1105
1142
|
docker(args, timeoutMs, signal, maxOutputBytes = 1024 * 1024) {
|
|
1106
1143
|
return requireSandboxProcess({ command: this.config.dockerExecutable, args: this.dockerArgs(args), timeoutMs, maxOutputBytes, signal });
|
|
1107
1144
|
}
|
|
1145
|
+
/** The container's init process: stopping it stops every process in the sandbox. */
|
|
1146
|
+
async containerInitProcess(containerId) {
|
|
1147
|
+
const pid = Number((await this.docker(["inspect", "--format", "{{.State.Pid}}", containerId], 10_000)).stdout.trim());
|
|
1148
|
+
return Number.isSafeInteger(pid) && pid > 1
|
|
1149
|
+
? { rootPid: pid, rootIdentity: captureHostProcessIdentity(pid), processGroup: false }
|
|
1150
|
+
: null;
|
|
1151
|
+
}
|
|
1108
1152
|
dockerArgs(args) { return this.config.dockerContext ? ["--context", this.config.dockerContext, ...args] : [...args]; }
|
|
1109
1153
|
}
|
|
1110
1154
|
class HostGit {
|
|
@@ -1233,12 +1277,7 @@ class HostGit {
|
|
|
1233
1277
|
await this.git(["update-ref", branchRef, imported, managedBranchUpdateExpectedValue(current, expected, imported)], 30_000);
|
|
1234
1278
|
return;
|
|
1235
1279
|
}
|
|
1236
|
-
|
|
1237
|
-
const status = (await requireSandboxProcess({ command: "git", args: ["-C", checkedOut.path, "status", "--porcelain=v1", "--untracked-files=no"], timeoutMs: 30_000, maxOutputBytes: 4 * 1024 * 1024 })).stdout;
|
|
1238
|
-
if (head !== expected || status.trim())
|
|
1239
|
-
throw trustedSandboxFailure("sandbox_output_conflict", "managed worktree changed after sandbox input was captured.");
|
|
1240
|
-
await this.git(["update-ref", branchRef, imported, expected], 30_000);
|
|
1241
|
-
await requireSandboxProcess({ command: "git", args: ["-C", checkedOut.path, "reset", "--hard"], timeoutMs: 2 * 60_000, maxOutputBytes: 4 * 1024 * 1024 });
|
|
1280
|
+
await advanceCheckedOutBranch({ repoPath: this.repoPath, worktreePath: checkedOut.path, branchRef, expected, imported });
|
|
1242
1281
|
}
|
|
1243
1282
|
async resolveFirst(refs) {
|
|
1244
1283
|
for (const ref of refs) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ForgeCgroupWriter } from "../runtime/host-load-forge-cgroups.js";
|
|
2
|
+
export type DockerInspectPids = (containerIds: readonly string[]) => Promise<string>;
|
|
3
|
+
/** Cgroup paths of the given containers' init processes; containers not yet running are skipped. */
|
|
4
|
+
export declare function sandboxContainerCgroupPaths(inspectPids: DockerInspectPids, containerIds: readonly string[], procRoot?: string): Promise<readonly string[]>;
|
|
5
|
+
/**
|
|
6
|
+
* Registers a sandbox's container cgroups once its containers are running,
|
|
7
|
+
* retrying briefly while the agent container starts. Returns a function that
|
|
8
|
+
* stops the retries and removes the registration.
|
|
9
|
+
*/
|
|
10
|
+
export declare function trackSandboxCgroups(registry: ForgeCgroupWriter, owner: string, containerIds: readonly string[], inspectPids: DockerInspectPids, options?: {
|
|
11
|
+
readonly attempts?: number;
|
|
12
|
+
readonly intervalMs?: number;
|
|
13
|
+
readonly procRoot?: string;
|
|
14
|
+
}): () => void;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import { parseUnifiedCgroupPath } from "../runtime/host-pressure-stall.js";
|
|
3
|
+
/** Cgroup paths of the given containers' init processes; containers not yet running are skipped. */
|
|
4
|
+
export async function sandboxContainerCgroupPaths(inspectPids, containerIds, procRoot = "/proc") {
|
|
5
|
+
const output = await inspectPids(containerIds);
|
|
6
|
+
const paths = [];
|
|
7
|
+
for (const line of output.split(/\r?\n/u)) {
|
|
8
|
+
const pid = Number(line.trim());
|
|
9
|
+
if (!Number.isSafeInteger(pid) || pid <= 1)
|
|
10
|
+
continue;
|
|
11
|
+
const membership = await fs.readFile(`${procRoot}/${pid}/cgroup`, "utf8").catch(() => null);
|
|
12
|
+
const cgroupPath = membership ? parseUnifiedCgroupPath(membership) : null;
|
|
13
|
+
if (cgroupPath)
|
|
14
|
+
paths.push(cgroupPath);
|
|
15
|
+
}
|
|
16
|
+
return paths;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Registers a sandbox's container cgroups once its containers are running,
|
|
20
|
+
* retrying briefly while the agent container starts. Returns a function that
|
|
21
|
+
* stops the retries and removes the registration.
|
|
22
|
+
*/
|
|
23
|
+
export function trackSandboxCgroups(registry, owner, containerIds, inspectPids, options = {}) {
|
|
24
|
+
let stopped = false;
|
|
25
|
+
void (async () => {
|
|
26
|
+
for (let attempt = 0; attempt < (options.attempts ?? 10) && !stopped; attempt += 1) {
|
|
27
|
+
await new Promise(resolve => setTimeout(resolve, options.intervalMs ?? 1_000));
|
|
28
|
+
if (stopped)
|
|
29
|
+
return;
|
|
30
|
+
const paths = await sandboxContainerCgroupPaths(inspectPids, containerIds, options.procRoot).catch(() => []);
|
|
31
|
+
if (stopped)
|
|
32
|
+
return;
|
|
33
|
+
registry.set(owner, paths);
|
|
34
|
+
if (paths.length >= containerIds.length)
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
})();
|
|
38
|
+
return () => {
|
|
39
|
+
stopped = true;
|
|
40
|
+
registry.delete(owner);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// Decision 0022: a blocked Architect verdict may say what it waits on (a sibling Story, a pull
|
|
2
|
+
// request, or something outside Forge) and which choice it needs from the owner. Forge records
|
|
3
|
+
// Story and pull request waits as dependency edges and re-plans the Story when they merge.
|
|
4
|
+
const architectWaitKinds = ["story", "pull_request", "external"];
|
|
5
|
+
const architectWaitUntil = ["merged"];
|
|
6
|
+
const storyIdPattern = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|[0-9a-f]{8,32})$/i;
|
|
7
|
+
// Architect tool properties for non-pass verdicts: revision prose plus the structured waits.
|
|
8
|
+
export function architectNonPassProperties() {
|
|
9
|
+
return {
|
|
10
|
+
revision_questions: {
|
|
11
|
+
type: "array",
|
|
12
|
+
description: "Required for needs_revision when blockers are not used.",
|
|
13
|
+
items: { type: "string" }
|
|
14
|
+
},
|
|
15
|
+
revision_reasons: {
|
|
16
|
+
type: "array",
|
|
17
|
+
description: "Concrete reasons that prevent pass status.",
|
|
18
|
+
items: { type: "string" }
|
|
19
|
+
},
|
|
20
|
+
waits_on: {
|
|
21
|
+
type: "array",
|
|
22
|
+
description: "Only with status blocked. What must merge before this Story can be planned: a sibling Story (kind story, story_id as the full id or its first 8+ hex digits), a pull request (kind pull_request, pr_number), or something outside Forge (kind external). Forge records Story and sibling pull request waits and plans the Story again when they merge; external waits hold for the owner.",
|
|
23
|
+
items: {
|
|
24
|
+
type: "object",
|
|
25
|
+
additionalProperties: false,
|
|
26
|
+
required: ["kind", "until", "reason"],
|
|
27
|
+
properties: {
|
|
28
|
+
kind: { type: "string", enum: [...architectWaitKinds] },
|
|
29
|
+
story_id: { type: "string", description: "Required for kind story." },
|
|
30
|
+
pr_number: { type: "integer", minimum: 1, description: "Required for kind pull_request." },
|
|
31
|
+
until: { type: "string", enum: [...architectWaitUntil] },
|
|
32
|
+
reason: { type: "string", description: "What this Story needs from the blocker." }
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
owner_decision: {
|
|
37
|
+
type: "object",
|
|
38
|
+
description: "Only with status blocked. A choice only the owner can make before the Story can be planned. Forge holds the Story for the owner and never picks an option.",
|
|
39
|
+
additionalProperties: false,
|
|
40
|
+
required: ["question", "options"],
|
|
41
|
+
properties: {
|
|
42
|
+
question: { type: "string" },
|
|
43
|
+
options: {
|
|
44
|
+
type: "array",
|
|
45
|
+
minItems: 2,
|
|
46
|
+
items: {
|
|
47
|
+
type: "object",
|
|
48
|
+
additionalProperties: false,
|
|
49
|
+
required: ["label", "summary"],
|
|
50
|
+
properties: {
|
|
51
|
+
label: { type: "string" },
|
|
52
|
+
summary: { type: "string" }
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
recommended: { type: "string", description: "Label of the recommended option." }
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
// An explicit null is absent, as the API reads it.
|
|
62
|
+
function isPresent(value) {
|
|
63
|
+
return value !== undefined && value !== null;
|
|
64
|
+
}
|
|
65
|
+
function hasArchitectWaitDeclarations(payload) {
|
|
66
|
+
return isPresent(payload.waits_on) || isPresent(payload.owner_decision);
|
|
67
|
+
}
|
|
68
|
+
// Throws an actionable error for a malformed waits_on or owner_decision. Absent (or null) fields are valid.
|
|
69
|
+
export function validateArchitectWaits(payload, status) {
|
|
70
|
+
if (!hasArchitectWaitDeclarations(payload)) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (status !== "blocked") {
|
|
74
|
+
throw new Error("waits_on/owner_decision: allowed only with status blocked; correction: remove them, or return status blocked when the plan cannot pass until they are resolved.");
|
|
75
|
+
}
|
|
76
|
+
if (isPresent(payload.waits_on)) {
|
|
77
|
+
validateWaitsOn(payload.waits_on);
|
|
78
|
+
}
|
|
79
|
+
if (isPresent(payload.owner_decision)) {
|
|
80
|
+
validateOwnerDecision(payload.owner_decision);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function validateWaitsOn(value) {
|
|
84
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
85
|
+
throw new Error("waits_on: expected a non-empty array; correction: list each Story, pull request or external dependency, or omit waits_on.");
|
|
86
|
+
}
|
|
87
|
+
value.forEach((entry, index) => validateWait(entry, `waits_on[${index}]`));
|
|
88
|
+
}
|
|
89
|
+
function validateWait(entry, label) {
|
|
90
|
+
const wait = requireRecord(entry, label);
|
|
91
|
+
const kind = wait.kind;
|
|
92
|
+
if (typeof kind !== "string" || !architectWaitKinds.includes(kind)) {
|
|
93
|
+
throw new Error(`${label}.kind: expected one of story, pull_request, external.`);
|
|
94
|
+
}
|
|
95
|
+
if (wait.until !== "merged") {
|
|
96
|
+
throw new Error(`${label}.until: expected "merged".`);
|
|
97
|
+
}
|
|
98
|
+
requireText(wait.reason, `${label}.reason`);
|
|
99
|
+
if (kind === "story") {
|
|
100
|
+
const storyId = requireText(wait.story_id, `${label}.story_id`);
|
|
101
|
+
if (!storyIdPattern.test(storyId)) {
|
|
102
|
+
throw new Error(`${label}.story_id: expected the Story's full id or its first 8+ hex digits; got '${storyId}'.`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (kind === "pull_request" && !(typeof wait.pr_number === "number" && Number.isInteger(wait.pr_number) && wait.pr_number > 0)) {
|
|
106
|
+
throw new Error(`${label}.pr_number: expected a positive integer pull request number.`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function validateOwnerDecision(value) {
|
|
110
|
+
const decision = requireRecord(value, "owner_decision");
|
|
111
|
+
requireText(decision.question, "owner_decision.question");
|
|
112
|
+
if (!Array.isArray(decision.options) || decision.options.length < 2) {
|
|
113
|
+
throw new Error("owner_decision.options: expected at least two options, each with a distinct label and a summary.");
|
|
114
|
+
}
|
|
115
|
+
const labels = decision.options.map((option, index) => {
|
|
116
|
+
const record = requireRecord(option, `owner_decision.options[${index}]`);
|
|
117
|
+
requireText(record.summary, `owner_decision.options[${index}].summary`);
|
|
118
|
+
return requireText(record.label, `owner_decision.options[${index}].label`);
|
|
119
|
+
});
|
|
120
|
+
if (new Set(labels).size !== labels.length) {
|
|
121
|
+
throw new Error("owner_decision.options: expected at least two options, each with a distinct label and a summary.");
|
|
122
|
+
}
|
|
123
|
+
if (isPresent(decision.recommended) && !labels.includes(requireText(decision.recommended, "owner_decision.recommended"))) {
|
|
124
|
+
throw new Error("owner_decision.recommended: expected the label of one of the options.");
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function requireRecord(value, label) {
|
|
128
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
129
|
+
throw new Error(`${label}: expected an object.`);
|
|
130
|
+
}
|
|
131
|
+
return value;
|
|
132
|
+
}
|
|
133
|
+
function requireText(value, label) {
|
|
134
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
135
|
+
throw new Error(`${label}: expected a non-empty string.`);
|
|
136
|
+
}
|
|
137
|
+
return value.trim();
|
|
138
|
+
}
|
|
@@ -1,6 +1,31 @@
|
|
|
1
|
-
import { type NativeTestPostgresFallback } from "../runtime/native-test-postgres-fallback.js";
|
|
2
1
|
export declare const managedAttemptToolNames: readonly ["forge.run_managed_command", "run_managed_command", "forge.start_managed_command", "start_managed_command", "forge.get_managed_command", "get_managed_command", "forge.wait_managed_command", "wait_managed_command", "forge.start_managed_verification", "start_managed_verification", "forge.reset_generated_outputs", "reset_generated_outputs"];
|
|
2
|
+
/**
|
|
3
|
+
* Stops every managed command this MCP server started, proves each process tree stopped,
|
|
4
|
+
* and writes their terminal receipts. Called when the provider closes the MCP connection
|
|
5
|
+
* or the server is signalled: once this server exits nothing could supervise them.
|
|
6
|
+
*/
|
|
7
|
+
export declare function stopManagedCommandsForOwnerExit(): Promise<void>;
|
|
8
|
+
/** Test support: lets one test process act as a fresh MCP server after a simulated exit. */
|
|
9
|
+
export declare function resetManagedCommandOwnerShutdownForTesting(): void;
|
|
10
|
+
declare const ownerShutdownSignals: readonly ["SIGTERM", "SIGHUP", "SIGINT"];
|
|
11
|
+
export interface OwnerShutdownSignalTarget {
|
|
12
|
+
once(signal: (typeof ownerShutdownSignals)[number], listener: () => void): unknown;
|
|
13
|
+
removeListener(signal: (typeof ownerShutdownSignals)[number], listener: () => void): unknown;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Makes a termination signal stop this server's managed commands before it exits, so none
|
|
17
|
+
* outlives its only supervisor. Returns a function that removes the handlers.
|
|
18
|
+
*/
|
|
19
|
+
export declare function installOwnerShutdownHandlers(target?: OwnerShutdownSignalTarget, exit?: (code: number) => void): () => void;
|
|
20
|
+
/**
|
|
21
|
+
* Runs an MCP server body, then stops every managed command it started before returning.
|
|
22
|
+
* The signal handlers stay installed until that stop completes: a signal during the body
|
|
23
|
+
* or the stop exits only after the same stop finishes, never by Node's default exit.
|
|
24
|
+
*/
|
|
25
|
+
export declare function runWithOwnerShutdown<T>(body: () => Promise<T>, target?: OwnerShutdownSignalTarget, exit?: (code: number) => void): Promise<T>;
|
|
3
26
|
export declare function isManagedAttemptTool(name: string): boolean;
|
|
27
|
+
/** The input schema a managed-attempt tool advertises; also the shape its arguments are coerced to. */
|
|
28
|
+
export declare function managedAttemptToolInputSchema(name: string): unknown;
|
|
4
29
|
export declare function managedAttemptToolDefinition(name: string): unknown;
|
|
5
30
|
export interface ManagedAttemptToolResult {
|
|
6
31
|
readonly content: readonly {
|
|
@@ -19,10 +44,5 @@ export declare function buildManagedVerificationCommand(profile: string, outputD
|
|
|
19
44
|
export declare function preferredPowerShellExecutable(platform?: NodeJS.Platform, pathValue?: string): string;
|
|
20
45
|
export declare function validatePlaywrightProjectName(project: string, availableProjects: readonly string[]): void;
|
|
21
46
|
export declare function playwrightProjectNamesFromConfigSource(source: string): readonly string[];
|
|
22
|
-
/**
|
|
23
|
-
* Runner-authored verification normally uses its attempt-owned Testcontainers
|
|
24
|
-
* database. Only when the Docker engine is unavailable does it switch to the
|
|
25
|
-
* operator-provisioned native test cluster, which holds no real data.
|
|
26
|
-
*/
|
|
27
|
-
export declare function managedVerificationDatabaseEnvironment(dockerAvailable?: () => Promise<boolean>, readFallback?: () => NativeTestPostgresFallback | null): Promise<Readonly<Record<string, string>>>;
|
|
28
47
|
export declare function isBuildProducingManagedCommand(command: string, args: readonly string[]): boolean;
|
|
48
|
+
export {};
|