@loucompanion/forge-bridge 0.1.4-dev.494233aa2e50 → 0.1.4-dev.4e7855579f82
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 +144 -3
- 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 +89 -14
- package/dist/bridge/bridge.service.js +423 -342
- package/dist/bridge/bridge.types.d.ts +21 -0
- 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.service.d.ts +9 -0
- package/dist/cleanup/cleanup.service.js +72 -109
- package/dist/cleanup/cleanup.types.d.ts +4 -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 +5 -0
- package/dist/cleanup/host-runtime-ledger.js +109 -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 +74 -12
- 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 +5 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +138 -6
- package/dist/runtime/attempt-database-broker.d.ts +1 -1
- package/dist/runtime/docker-engine-probe.d.ts +5 -0
- package/dist/runtime/docker-engine-probe.js +7 -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-facts.d.ts +2 -1
- 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 +184 -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 +185 -0
- package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
- package/dist/runtime/host-load-runtime-settings.js +78 -0
- package/dist/runtime/host-load-sampler.d.ts +75 -2
- package/dist/runtime/host-load-sampler.js +142 -8
- 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 +21 -1
- package/dist/runtime/host-pressure-stall.js +48 -1
- package/dist/runtime/host-runtime-contract.d.ts +15 -0
- package/dist/runtime/host-runtime-contract.js +33 -2
- package/dist/runtime/host-runtime-lease.d.ts +74 -4
- package/dist/runtime/host-runtime-lease.js +285 -55
- 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/native-test-postgres-fallback.d.ts +51 -7
- package/dist/runtime/native-test-postgres-fallback.js +60 -8
- package/dist/runtime/playwright-host-runtime-adapter.d.ts +7 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
- package/dist/runtime/runner-settings.d.ts +104 -0
- package/dist/runtime/runner-settings.js +236 -0
- package/dist/sandbox/host-capacity-broker.d.ts +113 -0
- package/dist/sandbox/host-capacity-broker.js +334 -0
- package/dist/sandbox/runtime.d.ts +10 -1
- package/dist/sandbox/runtime.js +45 -2
- 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 +2 -7
- package/dist/session/managed-attempt-tools.js +200 -92
- 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 +96 -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 +91 -215
- 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 +3 -0
- package/dist/session/pre-publication-process.js +23 -11
- 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 +221 -182
- 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 +20 -7
- 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 +41 -31
- package/dist/session/provider-cli/provider-cli.process.js +139 -438
- 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 +146 -182
- 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-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 +10 -1
- package/dist/session/publishable-worktree-changes.js +21 -5
- 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 +30 -0
- package/dist/session/sandbox-host-capacity-gate.js +238 -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 +9 -2
- package/dist/session/session.service.js +120 -5
- package/dist/session/session.types.d.ts +3 -0
- package/dist/session/session.types.js +13 -4
- 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/process/host-process-supervisor.d.ts +1 -0
- package/dist/shared/process/host-process-supervisor.js +1 -1
- 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 +46 -10
- package/dist/worktree/worktree.service.d.ts +10 -1
- package/dist/worktree/worktree.service.js +42 -2
- package/dist/worktree/worktree.types.d.ts +7 -0
- package/package.json +2 -2
|
@@ -3,12 +3,17 @@ import fs from "node:fs/promises";
|
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { resetGeneratedOutputs } from "../runtime/generated-output-reset.js";
|
|
6
|
-
import { DockerEngineProbe } from "../runtime/docker-engine-probe.js";
|
|
7
6
|
import { attemptDatabaseCapabilityEnvironment, attemptDatabaseCapabilitySecrets, } from "../runtime/attempt-database-broker.js";
|
|
8
7
|
import { assertHostDatabaseCapabilityBoundary } from "../runtime/host-database-capability-boundary.js";
|
|
9
|
-
import {
|
|
8
|
+
import { managedVerificationDatabase, noManagedVerificationDatabase, releaseManagedVerificationDatabase, setUpWithManagedVerificationDatabase } from "../runtime/ephemeral-test-postgres-grant.js";
|
|
10
9
|
import { redactText } from "../shared/redaction/redaction.js";
|
|
10
|
+
import { emptyToolInputHint, isEmptyToolInput } from "./mcp-argument-coercion.js";
|
|
11
11
|
import { ManagedBuildCoordinator } from "./managed-build-coordinator.js";
|
|
12
|
+
import { attachManagedCommandProcess, ManagedCommandHostCapacity, } from "./managed-command-host-load.js";
|
|
13
|
+
import { HostCapacityLedgerUnavailableError } from "../runtime/host-load-ledger-lock.js";
|
|
14
|
+
import { isProcessTreeTerminationUnproven } from "../shared/process/process.js";
|
|
15
|
+
import { HostCapacityTokenFencedError } from "../runtime/host-load-token-ledger.js";
|
|
16
|
+
import { withoutHostLoadGovernorVariables } from "../runtime/host-load-child-environment.js";
|
|
12
17
|
import { managedBuildConfiguration, publishManagedBuildReceipt, verifyManagedBuildReceipt, } from "./managed-build-receipt.js";
|
|
13
18
|
import { managedLongTierTimeoutMs, managedMaximumCommandTimeoutMs, managedVerificationTierTimeoutMs, } from "./managed-verification-timeouts.js";
|
|
14
19
|
import { resolveWindowsCommandFromPath, StreamingProviderProcessRunner } from "./provider-cli/provider-cli.process.js";
|
|
@@ -143,11 +148,17 @@ export function isManagedAttemptTool(name) {
|
|
|
143
148
|
|| startManagedVerificationNames.has(name)
|
|
144
149
|
|| resetGeneratedOutputNames.has(name);
|
|
145
150
|
}
|
|
151
|
+
const managedVerificationProfiles = ["dotnet_unit", "dotnet_contract", "dotnet_api_component", "dotnet_orchestration", "dotnet_infrastructure", "dotnet_solution", "dotnet_affected"];
|
|
152
|
+
const managedVerificationProfileHint = `Use one of: ${managedVerificationProfiles.join(", ")}. These are .NET test profiles only; run client, bridge, or Playwright e2e checks with forge.start_managed_command.`;
|
|
153
|
+
/** The input schema a managed-attempt tool advertises; also the shape its arguments are coerced to. */
|
|
154
|
+
export function managedAttemptToolInputSchema(name) {
|
|
155
|
+
return managedAttemptToolDefinition(name).inputSchema;
|
|
156
|
+
}
|
|
146
157
|
export function managedAttemptToolDefinition(name) {
|
|
147
158
|
if (startManagedVerificationNames.has(name)) {
|
|
148
159
|
return {
|
|
149
160
|
name,
|
|
150
|
-
description: "Start a canonical Forge verification profile with runner-owned cwd, arguments, attempt output, timeout, and process supervision. Prefer this over reconstructing broad .NET commands. Continue independent work, then use forge.wait_managed_command for a transport-safe terminal receipt.",
|
|
161
|
+
description: "Start a canonical Forge .NET verification profile with runner-owned cwd, arguments, attempt output, timeout, and process supervision. Prefer this over reconstructing broad .NET commands. Continue independent work, then use forge.wait_managed_command for a transport-safe terminal receipt. To run every shard of a tier in one call, set run_all_shards: true with shard_count 2 or more and without no_build.",
|
|
151
162
|
inputSchema: {
|
|
152
163
|
type: "object",
|
|
153
164
|
additionalProperties: false,
|
|
@@ -155,13 +166,14 @@ export function managedAttemptToolDefinition(name) {
|
|
|
155
166
|
properties: {
|
|
156
167
|
profile: {
|
|
157
168
|
type: "string",
|
|
158
|
-
enum: [
|
|
169
|
+
enum: [...managedVerificationProfiles],
|
|
170
|
+
description: "Required .NET test profile. dotnet_affected selects its own tests and owns its build: it takes no shard or no_build options. dotnet_solution takes no shard options. Client, bridge, and e2e checks are not profiles; use forge.start_managed_command for them.",
|
|
159
171
|
},
|
|
160
|
-
shard_count: { type: "integer", minimum: 1, maximum: 32, default: 1 },
|
|
161
|
-
shard_index: { type: "integer", minimum: 0, maximum: 31, default: 0 },
|
|
162
|
-
run_all_shards: { type: "boolean", default: false },
|
|
172
|
+
shard_count: { type: "integer", minimum: 1, maximum: 32, default: 1, description: "Number of shards to split the tier into. Must be at least 2 when run_all_shards is true." },
|
|
173
|
+
shard_index: { type: "integer", minimum: 0, maximum: 31, default: 0, description: "Which single shard to run; must be less than shard_count, and 0 when run_all_shards is true." },
|
|
174
|
+
run_all_shards: { type: "boolean", default: false, description: "Run every shard of the tier after one shared build. Requires shard_count of at least 2 and shard_index 0, cannot be combined with no_build, and is not supported for dotnet_solution or dotnet_affected." },
|
|
163
175
|
max_parallelism: { type: "integer", minimum: 1, maximum: 4, default: 2 },
|
|
164
|
-
no_build: { type: "boolean", default: false },
|
|
176
|
+
no_build: { type: "boolean", default: false, description: "Reuse the verified build from an earlier managed build instead of building. Not allowed with run_all_shards or dotnet_affected." },
|
|
165
177
|
timeout_ms: { type: "integer", minimum: 1000, maximum: 7200000 },
|
|
166
178
|
},
|
|
167
179
|
},
|
|
@@ -178,8 +190,8 @@ export function managedAttemptToolDefinition(name) {
|
|
|
178
190
|
additionalProperties: false,
|
|
179
191
|
required: ["command", "args"],
|
|
180
192
|
properties: {
|
|
181
|
-
command: { type: "string", minLength: 1 },
|
|
182
|
-
args: { type: "array", items: { type: "string" } },
|
|
193
|
+
command: { type: "string", minLength: 1, description: "Required executable only, for example pnpm, node, npm, or dotnet. Not a shell command line: shell syntax such as cd, &&, or pipes is not interpreted." },
|
|
194
|
+
args: { type: "array", items: { type: "string" }, description: "Required argument list, each argument its own string, for example [\"--dir\", \"client\", \"lint\"]. Send [] when there are none. Use cwd instead of cd." },
|
|
183
195
|
cwd: { type: "string", description: "Worktree-relative directory; defaults to the worktree root." },
|
|
184
196
|
timeout_ms: { type: "integer", minimum: 1000, maximum: 7200000, default: 2700000 },
|
|
185
197
|
},
|
|
@@ -342,13 +354,13 @@ async function startManagedVerification(input, worktreePath) {
|
|
|
342
354
|
const runAllShards = optionalBoolean(record.run_all_shards, "run_all_shards", false);
|
|
343
355
|
const maxParallelism = optionalBoundedInteger(record.max_parallelism, "max_parallelism", 1, 4, 2);
|
|
344
356
|
if (runAllShards && shardCount < 2) {
|
|
345
|
-
throw new Error("managed_verification_invalid: run_all_shards requires shard_count of at least 2.");
|
|
357
|
+
throw new Error("managed_verification_invalid: run_all_shards requires shard_count of at least 2. Set shard_count to 2 or more to run every shard, or omit run_all_shards to run a single shard.");
|
|
346
358
|
}
|
|
347
359
|
if (runAllShards && shardIndex !== 0) {
|
|
348
360
|
throw new Error("managed_verification_invalid: shard_index must be 0 when run_all_shards is enabled.");
|
|
349
361
|
}
|
|
350
362
|
if (runAllShards && noBuild) {
|
|
351
|
-
throw new Error("managed_verification_invalid: run_all_shards owns the single prerequisite build and cannot be combined with no_build.");
|
|
363
|
+
throw new Error("managed_verification_invalid: run_all_shards owns the single prerequisite build and cannot be combined with no_build. Omit no_build when run_all_shards is true.");
|
|
352
364
|
}
|
|
353
365
|
const outputDirectory = requiredAttemptEnvironment("FORGE_TEST_OUTPUT_DIR");
|
|
354
366
|
const profileCommand = buildManagedVerificationCommand(profile, outputDirectory, shardCount, shardIndex, noBuild, runAllShards, maxParallelism);
|
|
@@ -405,7 +417,7 @@ export function buildManagedVerificationCommand(profile, outputDirectory, shardC
|
|
|
405
417
|
};
|
|
406
418
|
const tier = tiers[profile];
|
|
407
419
|
if (!tier)
|
|
408
|
-
throw new Error(`managed_verification_invalid: unsupported profile ${profile}
|
|
420
|
+
throw new Error(`managed_verification_invalid: unsupported profile ${profile}. ${managedVerificationProfileHint}`);
|
|
409
421
|
const command = preferredPowerShellExecutable();
|
|
410
422
|
if (runAllShards) {
|
|
411
423
|
return {
|
|
@@ -434,7 +446,7 @@ export function buildManagedVerificationCommand(profile, outputDirectory, shardC
|
|
|
434
446
|
export function preferredPowerShellExecutable(platform = process.platform, pathValue = process.env.PATH ?? "") {
|
|
435
447
|
if (platform !== "win32")
|
|
436
448
|
return "pwsh";
|
|
437
|
-
return resolveWindowsCommandFromPath("pwsh.exe", pathValue) ?? "powershell.exe";
|
|
449
|
+
return resolveWindowsCommandFromPath("pwsh.exe", pathValue, undefined, { skipAppExecutionAliases: true }) ?? "powershell.exe";
|
|
438
450
|
}
|
|
439
451
|
export function validatePlaywrightProjectName(project, availableProjects) {
|
|
440
452
|
if (!availableProjects.includes(project)) {
|
|
@@ -488,15 +500,66 @@ function optionValue(args, name) {
|
|
|
488
500
|
const index = args.indexOf(name);
|
|
489
501
|
return index >= 0 ? args[index + 1]?.trim() || null : null;
|
|
490
502
|
}
|
|
503
|
+
function hostCapacityLossReason(reason) {
|
|
504
|
+
if (reason instanceof HostCapacityTokenFencedError)
|
|
505
|
+
return "host_capacity_token_fenced";
|
|
506
|
+
if (reason instanceof HostCapacityLedgerUnavailableError)
|
|
507
|
+
return "host_capacity_ledger_unavailable";
|
|
508
|
+
return null;
|
|
509
|
+
}
|
|
491
510
|
async function executeManagedCommand(invocation) {
|
|
492
|
-
if (!invocation.buildProducing)
|
|
493
|
-
return await executeManagedCommandProcess(invocation);
|
|
494
511
|
let processStarted = false;
|
|
512
|
+
// The per-worktree build slot is taken first: holding a host token while
|
|
513
|
+
// queued behind this worktree's own build would waste host capacity.
|
|
514
|
+
const hostCapacity = new ManagedCommandHostCapacity({ ...invocation, label: invocation.verificationProfile ?? invocation.commandId }, async (hostLoad) => await persistManagedCommandReceipt(invocation.receiptPath, managedCommandResult({
|
|
515
|
+
...invocation,
|
|
516
|
+
hostLoad,
|
|
517
|
+
timedOut: false,
|
|
518
|
+
status: "waiting_for_host_capacity",
|
|
519
|
+
exitCode: null,
|
|
520
|
+
stdout: "",
|
|
521
|
+
stderr: "",
|
|
522
|
+
launchRequested: false,
|
|
523
|
+
}).structuredContent));
|
|
524
|
+
const launch = async (buildQueueWaitMs) => await hostCapacity.run(invocation.controller.signal, async (hostLoad, control) => {
|
|
525
|
+
processStarted = true;
|
|
526
|
+
// A reclaimed token means this command's capacity is gone: it stops. A fence that
|
|
527
|
+
// landed between admission and here stops it too (a listener added now never fires).
|
|
528
|
+
const stopOnFence = () => invocation.controller.abort(control.fenced.reason);
|
|
529
|
+
if (control.fenced?.aborted)
|
|
530
|
+
stopOnFence();
|
|
531
|
+
else
|
|
532
|
+
control.fenced?.addEventListener("abort", stopOnFence, { once: true });
|
|
533
|
+
try {
|
|
534
|
+
return await executeManagedCommandProcess({
|
|
535
|
+
...invocation,
|
|
536
|
+
buildQueueWaitMs,
|
|
537
|
+
hostLoad,
|
|
538
|
+
// Recording the tree is part of holding the token: if it fails (the token was
|
|
539
|
+
// fenced meanwhile, or the ledger refused), the command stops instead of
|
|
540
|
+
// running on without a reservation the host can account for.
|
|
541
|
+
// Checked against the tree recorded on the token at launch (null: the governor's own).
|
|
542
|
+
holdHostCapacityUntilStopped: reason => control.holdUntilStopped?.(null, reason),
|
|
543
|
+
onProcessStarted: async () => await attachManagedCommandProcess(control, invocation.metadataPath)
|
|
544
|
+
.catch((error) => {
|
|
545
|
+
invocation.controller.abort(error instanceof HostCapacityTokenFencedError || error instanceof HostCapacityLedgerUnavailableError
|
|
546
|
+
? error
|
|
547
|
+
: new HostCapacityLedgerUnavailableError(`the managed command's process tree could not be recorded on its host load token: ${error instanceof Error ? error.message : String(error)}`, { cause: error }));
|
|
548
|
+
}),
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
finally {
|
|
552
|
+
control.fenced?.removeEventListener("abort", stopOnFence);
|
|
553
|
+
}
|
|
554
|
+
},
|
|
555
|
+
// A fenced release is already the receipt's termination reason; only a ledger fault is noted.
|
|
556
|
+
async (error) => error instanceof HostCapacityTokenFencedError ? undefined : await annotateManagedCommandReceipt(invocation.receiptPath, {
|
|
557
|
+
host_capacity_release_error: redactText(error instanceof Error ? error.message : String(error), []),
|
|
558
|
+
}));
|
|
495
559
|
try {
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
}, async () => {
|
|
560
|
+
if (!invocation.buildProducing)
|
|
561
|
+
return await launch();
|
|
562
|
+
return await new ManagedBuildCoordinator().withBuildSlot(invocation.worktreePath, launch, async () => {
|
|
500
563
|
const waiting = managedCommandResult({
|
|
501
564
|
...invocation,
|
|
502
565
|
timedOut: false,
|
|
@@ -512,11 +575,12 @@ async function executeManagedCommand(invocation) {
|
|
|
512
575
|
catch (error) {
|
|
513
576
|
if (processStarted)
|
|
514
577
|
throw error;
|
|
515
|
-
// The command never started (its build-slot wait failed or was
|
|
516
|
-
// must still become terminal, or a waiting agent sees it queued forever.
|
|
578
|
+
// The command never started (its build-slot or host-capacity wait failed or was
|
|
579
|
+
// stopped). Its receipt must still become terminal, or a waiting agent sees it queued forever.
|
|
517
580
|
const ownerExited = ownerExitStoppedCommands.has(invocation.commandId);
|
|
518
581
|
const receipt = managedCommandResult({
|
|
519
582
|
...invocation,
|
|
583
|
+
hostLoad: await hostCapacity.unadmittedFields(error),
|
|
520
584
|
timedOut: false,
|
|
521
585
|
status: "runner_error",
|
|
522
586
|
exitCode: null,
|
|
@@ -529,41 +593,48 @@ async function executeManagedCommand(invocation) {
|
|
|
529
593
|
return managedCommandPublicResult(receipt);
|
|
530
594
|
}
|
|
531
595
|
}
|
|
596
|
+
/** A command's environment and redaction list; a setup that throws releases the database it started. */
|
|
532
597
|
async function managedCommandProcessEnvironment(invocation) {
|
|
533
598
|
assertHostDatabaseCapabilityBoundary();
|
|
534
|
-
const
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
599
|
+
const database = invocation.verificationProfile ? await managedVerificationDatabase() : noManagedVerificationDatabase;
|
|
600
|
+
return await setUpWithManagedVerificationDatabase(database, () => {
|
|
601
|
+
const exactSecrets = [
|
|
602
|
+
...database.secrets,
|
|
603
|
+
// The attempt's brokered database login reaches managed commands; their output never shows it.
|
|
604
|
+
...attemptDatabaseCapabilitySecrets(process.env[attemptDatabaseCapabilityEnvironment]),
|
|
605
|
+
];
|
|
606
|
+
const environment = inheritedEnvironment({
|
|
607
|
+
FORGE_RUNTIME_MODE: "host",
|
|
608
|
+
FORGE_RESOURCE_LEASE_ID: requiredAttemptEnvironment("FORGE_RESOURCE_LEASE_ID"),
|
|
609
|
+
FORGE_DISPATCH_ATTEMPT_ID: requiredAttemptEnvironment("FORGE_DISPATCH_ATTEMPT_ID"),
|
|
610
|
+
// This nested command owns a distinct supervisor identity. A command-local
|
|
611
|
+
// fence avoids exposing the parent attempt's fencing capability to Codex's
|
|
612
|
+
// MCP subprocess configuration while preserving exact-tree cleanup proof.
|
|
613
|
+
FORGE_FENCING_TOKEN: randomUUID(),
|
|
614
|
+
FORGE_LOG_DIR: invocation.logDirectory,
|
|
615
|
+
FORGE_TEST_OUTPUT_DIR: requiredAttemptEnvironment("FORGE_TEST_OUTPUT_DIR"),
|
|
616
|
+
FORGE_PROCESS_SUPERVISOR_ID: `managed-${invocation.commandId.replaceAll("-", "")}`,
|
|
617
|
+
FORGE_PROCESS_SUPERVISOR_METADATA_PATH: invocation.metadataPath,
|
|
618
|
+
...(invocation.verificationProfile
|
|
619
|
+
? {
|
|
620
|
+
FORGE_MANAGED_VERIFICATION_PROFILE: invocation.verificationProfile,
|
|
621
|
+
// Managed verification executes mutable worktree scripts, SDK targets,
|
|
622
|
+
// and test assemblies. It uses an attempt-owned container, or the
|
|
623
|
+
// dedicated native test cluster while Docker is unavailable; it never
|
|
624
|
+
// receives a capability for a server that holds real data.
|
|
625
|
+
FORGE_MANAGED_VERIFICATION_DATABASE_MODE: "container_only",
|
|
626
|
+
...database.environment,
|
|
627
|
+
}
|
|
628
|
+
: {}),
|
|
629
|
+
});
|
|
630
|
+
return { environment, exactSecrets, release: database.release };
|
|
565
631
|
});
|
|
566
|
-
|
|
632
|
+
}
|
|
633
|
+
function clearManagedCommandTimers(...timers) {
|
|
634
|
+
// clearTimeout and clearInterval share one timer table.
|
|
635
|
+
for (const timer of timers)
|
|
636
|
+
if (timer)
|
|
637
|
+
clearTimeout(timer);
|
|
567
638
|
}
|
|
568
639
|
async function executeManagedCommandProcess(invocation) {
|
|
569
640
|
let prepared;
|
|
@@ -642,6 +713,8 @@ async function executeManagedCommandProcess(invocation) {
|
|
|
642
713
|
}, {
|
|
643
714
|
onStarted: async () => {
|
|
644
715
|
clearTimeout(launchTimer);
|
|
716
|
+
// onProcessStarted stops the command itself when its token cannot be held.
|
|
717
|
+
await invocation.onProcessStarted?.();
|
|
645
718
|
const running = managedCommandResult({
|
|
646
719
|
...invocation,
|
|
647
720
|
timedOut: false,
|
|
@@ -688,13 +761,17 @@ async function executeManagedCommandProcess(invocation) {
|
|
|
688
761
|
// Only a stop that interrupted the process relabels it. A command that exited on its own
|
|
689
762
|
// just before its owner asked for the stop keeps its real result.
|
|
690
763
|
const ownerExited = !timedOut && result.cancelled === true && ownerExitStoppedCommands.has(invocation.commandId);
|
|
691
|
-
|
|
692
|
-
|
|
764
|
+
const hostCapacityLoss = !timedOut && !ownerExited && result.cancelled === true
|
|
765
|
+
? hostCapacityLossReason(controller.signal.reason)
|
|
766
|
+
: null;
|
|
767
|
+
const fenced = hostCapacityLoss !== null;
|
|
768
|
+
if (ownerExited || fenced) {
|
|
769
|
+
stderr = appendBounded(stderr, ownerExited ? managedCommandOwnerExitMessage : controller.signal.reason.message);
|
|
693
770
|
outputRevision += 1;
|
|
694
771
|
lastOutputAt = Date.now();
|
|
695
772
|
lastOutputStream = "stderr";
|
|
696
773
|
}
|
|
697
|
-
const status = timedOut ? "timed_out" : ownerExited ? "runner_error" : result.exitCode === 0 ? "pass" : "fail";
|
|
774
|
+
const status = timedOut ? "timed_out" : ownerExited || fenced ? "runner_error" : result.exitCode === 0 ? "pass" : "fail";
|
|
698
775
|
const receiptCoverage = managedBuildReceiptCoverage(invocation);
|
|
699
776
|
const buildReceipt = status === "pass" && receiptCoverage
|
|
700
777
|
? await publishManagedBuildReceipt({
|
|
@@ -717,9 +794,9 @@ async function executeManagedCommandProcess(invocation) {
|
|
|
717
794
|
lastOutputStream,
|
|
718
795
|
buildReceipt,
|
|
719
796
|
buildReceiptReused: invocation.buildReceiptReuse !== undefined,
|
|
720
|
-
terminationReason: ownerExited ? "owner_exited" : undefined,
|
|
797
|
+
terminationReason: ownerExited ? "owner_exited" : hostCapacityLoss ?? undefined,
|
|
721
798
|
// The runner resolves only after the stopped tree is proven gone.
|
|
722
|
-
processTreeTerminated: ownerExited ? true : undefined,
|
|
799
|
+
processTreeTerminated: ownerExited || fenced ? true : undefined,
|
|
723
800
|
});
|
|
724
801
|
await persistManagedCommandReceipt(invocation.receiptPath, receipt.structuredContent);
|
|
725
802
|
return managedCommandPublicResult(receipt);
|
|
@@ -745,19 +822,23 @@ async function executeManagedCommandProcess(invocation) {
|
|
|
745
822
|
outputRevision,
|
|
746
823
|
lastOutputAt,
|
|
747
824
|
lastOutputStream,
|
|
748
|
-
|
|
825
|
+
// A host capacity loss before launch (a fence that landed while it was admitted) is named too.
|
|
826
|
+
terminationReason: ownerExited ? "owner_exited" : hostCapacityLossReason(controller.signal.reason) ?? undefined,
|
|
749
827
|
// The runner rejected, so its tree was not proven stopped; teardown still stops it.
|
|
750
828
|
processTreeTerminated: false,
|
|
751
829
|
});
|
|
752
830
|
await persistManagedCommandReceipt(invocation.receiptPath, receipt.structuredContent);
|
|
831
|
+
// The runner stops the tree before it rejects; only a failed termination proof means
|
|
832
|
+
// part of it may still run. Its token is then kept, never returned with this receipt.
|
|
833
|
+
if (isProcessTreeTerminationUnproven(error)) {
|
|
834
|
+
invocation.holdHostCapacityUntilStopped?.(error instanceof Error ? error : new Error(String(error)));
|
|
835
|
+
}
|
|
753
836
|
return managedCommandPublicResult(receipt);
|
|
754
837
|
}
|
|
755
838
|
finally {
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
if (progressHeartbeat)
|
|
760
|
-
clearInterval(progressHeartbeat);
|
|
839
|
+
clearManagedCommandTimers(launchTimer, timer, progressHeartbeat);
|
|
840
|
+
// An ephemeral verification cluster lives exactly as long as its command; one that would not stop is reaped later and named in the receipt.
|
|
841
|
+
await releaseManagedVerificationDatabase(prepared, async (message) => await annotateManagedCommandReceipt(invocation.receiptPath, { ephemeral_cluster_release_error: redactText(message, exactSecrets) }));
|
|
761
842
|
}
|
|
762
843
|
}
|
|
763
844
|
async function readManagedCommand(input) {
|
|
@@ -773,6 +854,11 @@ async function readManagedCommand(input) {
|
|
|
773
854
|
}
|
|
774
855
|
throw error;
|
|
775
856
|
}
|
|
857
|
+
// A queued receipt is written once; its wait so far is computed when it is read.
|
|
858
|
+
const hostLoadWaitStartedAt = Date.parse(String(receipt.host_load_wait_started_at));
|
|
859
|
+
if (receipt.status === "waiting_for_host_capacity" && Number.isFinite(hostLoadWaitStartedAt)) {
|
|
860
|
+
receipt = { ...receipt, host_load_wait_ms: Math.max(0, Date.now() - hostLoadWaitStartedAt) };
|
|
861
|
+
}
|
|
776
862
|
const status = typeof receipt.status === "string" ? receipt.status : "unknown";
|
|
777
863
|
const stdout = typeof receipt.stdout === "string" ? receipt.stdout : "";
|
|
778
864
|
const stderr = typeof receipt.stderr === "string" ? receipt.stderr : "";
|
|
@@ -823,15 +909,18 @@ async function waitManagedCommand(input) {
|
|
|
823
909
|
const elapsedMs = receipt.structuredContent.elapsed_ms;
|
|
824
910
|
const timeoutMs = receipt.structuredContent.timeout_ms;
|
|
825
911
|
const lastOutputAt = Date.parse(String(receipt.structuredContent.last_output_at));
|
|
826
|
-
const
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
912
|
+
const hostLoadWaitMs = receipt.structuredContent.host_load_wait_ms;
|
|
913
|
+
const progress = receipt.structuredContent.status === "waiting_for_host_capacity" && typeof hostLoadWaitMs === "number"
|
|
914
|
+
? ` It has waited ${Math.round(hostLoadWaitMs / 1000)}s for host capacity${typeof receipt.structuredContent.host_load_wait_detail === "string" ? ` (${receipt.structuredContent.host_load_wait_detail})` : ""} and has not started yet; its timeout starts only once it is admitted, so queue time never counts against it. Keep waiting; a queued command is not a blocker.`
|
|
915
|
+
: receipt.structuredContent.status === "running" && typeof elapsedMs === "number"
|
|
916
|
+
? ` It has run for ${Math.round(elapsedMs / 1000)}s`
|
|
917
|
+
+ (Number.isFinite(lastOutputAt) ? `, last output ${Math.max(0, Math.round((Date.now() - lastOutputAt) / 1000))}s ago` : ", with no output yet")
|
|
918
|
+
+ `. Forge refreshes this receipt every ${managedCommandProgressPersistIntervalMs / 1000}s, so a rising elapsed time means the command is still alive even when it is quiet.`
|
|
919
|
+
// Agents otherwise abandon long verification tiers and record a blocker that is not one.
|
|
920
|
+
+ (typeof timeoutMs === "number"
|
|
921
|
+
? ` Forge itself ends it at its ${Math.round(timeoutMs / 60_000)}-minute limit if it hangs, so keep waiting; a running command is not a blocker.`
|
|
922
|
+
: "")
|
|
923
|
+
: "";
|
|
835
924
|
return {
|
|
836
925
|
...receipt,
|
|
837
926
|
content: [{
|
|
@@ -876,7 +965,9 @@ async function persistManagedCommandReceipt(receiptPath, receipt) {
|
|
|
876
965
|
}
|
|
877
966
|
}
|
|
878
967
|
function managedCommandResult(values) {
|
|
879
|
-
|
|
968
|
+
// Governed commands count elapsed time from admission: queue time is host_load_wait_ms.
|
|
969
|
+
const hostLoad = values.hostLoad;
|
|
970
|
+
const elapsedMs = Date.now() - (hostLoad ? hostLoad.executionStartedAt ?? Date.now() : values.startedAt);
|
|
880
971
|
const isTerminal = terminalManagedCommandStatuses.has(values.status);
|
|
881
972
|
const diagnostics = isTerminal
|
|
882
973
|
? managedCommandDiagnostics(values.stdout, values.stderr)
|
|
@@ -921,6 +1012,7 @@ function managedCommandResult(values) {
|
|
|
921
1012
|
build_coordination: values.buildProducing ? "per_worktree_exclusive" : null,
|
|
922
1013
|
build_queue_wait_ms: values.buildQueueWaitMs ?? 0,
|
|
923
1014
|
build_receipt_reused: values.buildReceiptReused ?? false,
|
|
1015
|
+
...(hostLoad ? managedCommandHostLoadReceipt(hostLoad) : {}),
|
|
924
1016
|
build_receipt: values.buildReceipt ? {
|
|
925
1017
|
fingerprint: values.buildReceipt.fingerprint,
|
|
926
1018
|
receipt_path: values.buildReceipt.receiptPath,
|
|
@@ -940,6 +1032,18 @@ function managedCommandResult(values) {
|
|
|
940
1032
|
isError: isTerminal && values.status !== "pass",
|
|
941
1033
|
};
|
|
942
1034
|
}
|
|
1035
|
+
function managedCommandHostLoadReceipt(hostLoad) {
|
|
1036
|
+
const waiting = hostLoad.waitStartedAt !== undefined;
|
|
1037
|
+
return {
|
|
1038
|
+
host_load_step_class: hostLoad.stepClass,
|
|
1039
|
+
host_load_wait_ms: waiting ? Math.max(0, Date.now() - hostLoad.waitStartedAt) : hostLoad.waitMs,
|
|
1040
|
+
...(waiting ? { host_load_wait_started_at: new Date(hostLoad.waitStartedAt).toISOString(), host_load_wait_detail: hostLoad.waitDetail ?? null } : {}),
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1043
|
+
async function annotateManagedCommandReceipt(receiptPath, fields) {
|
|
1044
|
+
const receipt = JSON.parse(await fs.readFile(receiptPath, "utf8"));
|
|
1045
|
+
await persistManagedCommandReceipt(receiptPath, { ...receipt, ...fields });
|
|
1046
|
+
}
|
|
943
1047
|
/** This server's birth identity, so a reissued PID is never mistaken for a live owner. */
|
|
944
1048
|
function managedCommandOwnerIdentity() {
|
|
945
1049
|
// Windows identity capture starts PowerShell; the PID check alone is used there.
|
|
@@ -1015,26 +1119,15 @@ async function containedWorkingDirectory(worktreePath, input) {
|
|
|
1015
1119
|
}
|
|
1016
1120
|
function inheritedEnvironment(overrides) {
|
|
1017
1121
|
const env = {};
|
|
1018
|
-
|
|
1122
|
+
// A nested Forge process must not join the host ledger: it would queue behind the
|
|
1123
|
+
// token this command already holds. Every FORGE_HOST_LOAD_* variable is dropped,
|
|
1124
|
+
// the test slot count too (decision 0018).
|
|
1125
|
+
for (const [key, value] of Object.entries(withoutHostLoadGovernorVariables(process.env))) {
|
|
1019
1126
|
if (typeof value === "string" && !looksSensitiveEnvironmentName(key))
|
|
1020
1127
|
env[key] = value;
|
|
1021
1128
|
}
|
|
1022
1129
|
return { ...env, ...overrides };
|
|
1023
1130
|
}
|
|
1024
|
-
/**
|
|
1025
|
-
* Runner-authored verification normally uses its attempt-owned Testcontainers
|
|
1026
|
-
* database. Only when the Docker engine is unavailable does it switch to the
|
|
1027
|
-
* operator-provisioned native test cluster, which holds no real data.
|
|
1028
|
-
*/
|
|
1029
|
-
export async function managedVerificationDatabaseEnvironment(dockerAvailable = async () => (await new DockerEngineProbe().refresh(true)).available, readFallback = () => {
|
|
1030
|
-
const configPath = process.env[nativeTestPostgresFallbackConfigEnvironment]?.trim();
|
|
1031
|
-
return configPath ? readNativeTestPostgresFallback(configPath) : null;
|
|
1032
|
-
}) {
|
|
1033
|
-
const fallback = readFallback();
|
|
1034
|
-
if (!fallback || await dockerAvailable())
|
|
1035
|
-
return {};
|
|
1036
|
-
return nativeTestPostgresFallbackEnvironment(fallback);
|
|
1037
|
-
}
|
|
1038
1131
|
export function isBuildProducingManagedCommand(command, args) {
|
|
1039
1132
|
const executable = path.basename(command).toLowerCase();
|
|
1040
1133
|
if (executable === "dotnet" || executable === "dotnet.exe") {
|
|
@@ -1104,8 +1197,17 @@ function asRecord(value) {
|
|
|
1104
1197
|
throw new Error("managed_command_invalid: input must be an object.");
|
|
1105
1198
|
return value;
|
|
1106
1199
|
}
|
|
1200
|
+
const requiredInputExamples = {
|
|
1201
|
+
command: "Send the executable as command and each argument as its own string in args, for example {\"command\": \"pnpm\", \"args\": [\"--dir\", \"client\", \"lint\"]}.",
|
|
1202
|
+
profile: managedVerificationProfileHint,
|
|
1203
|
+
command_id: "Send the command_id returned by forge.start_managed_command or forge.start_managed_verification.",
|
|
1204
|
+
};
|
|
1107
1205
|
function requiredInputString(record, name) {
|
|
1108
|
-
|
|
1206
|
+
const value = record[name];
|
|
1207
|
+
if (typeof value === "string" && value.trim())
|
|
1208
|
+
return value.trim();
|
|
1209
|
+
const hints = [requiredInputExamples[name], isEmptyToolInput(record) ? emptyToolInputHint : undefined].filter(Boolean);
|
|
1210
|
+
throw new Error(`managed_command_invalid: ${name} is required.${hints.length > 0 ? ` ${hints.join(" ")}` : ""}`);
|
|
1109
1211
|
}
|
|
1110
1212
|
function validatedCommandId(record) {
|
|
1111
1213
|
const commandId = requiredInputString(record, "command_id");
|
|
@@ -1122,7 +1224,13 @@ function requiredStandaloneString(value, name) {
|
|
|
1122
1224
|
function requiredStringArray(record, name) {
|
|
1123
1225
|
const value = record[name];
|
|
1124
1226
|
if (!Array.isArray(value) || value.some(entry => typeof entry !== "string")) {
|
|
1125
|
-
|
|
1227
|
+
const shellLine = typeof record.command === "string" && /\s/u.test(record.command.trim());
|
|
1228
|
+
const hint = typeof value === "string"
|
|
1229
|
+
? " (received a string). Put each argument in its own string, for example [\"--dir\", \"client\", \"test\"]."
|
|
1230
|
+
: value === undefined
|
|
1231
|
+
? ` (it was omitted). Send [] when there are no arguments.${shellLine ? " command holds only the executable, so move its arguments into args; shell syntax such as cd, &&, or pipes is not interpreted, so set cwd instead of cd." : ""}`
|
|
1232
|
+
: " Every argument must be a string.";
|
|
1233
|
+
throw new Error(`managed_command_invalid: ${name} must be a string array${hint}`);
|
|
1126
1234
|
}
|
|
1127
1235
|
return value;
|
|
1128
1236
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type HostLoadStepGate } from "../runtime/host-load-governor.js";
|
|
2
|
+
import { type HostLoadStepClassification, type ManagedCommandStepInput } from "../runtime/host-load-step-class.js";
|
|
3
|
+
import { type HostLoadStepControl } from "../runtime/host-load-step-run.js";
|
|
4
|
+
/** Host-load facts a managed command receipt carries; absent while the governor is off. */
|
|
5
|
+
export interface ManagedCommandHostLoadFields {
|
|
6
|
+
readonly stepClass: string;
|
|
7
|
+
/** Queue time before admission; never part of elapsed_ms. */
|
|
8
|
+
readonly waitMs: number;
|
|
9
|
+
/** Set while the command is still queued: the receipt reports the wait so far. */
|
|
10
|
+
readonly waitStartedAt?: number;
|
|
11
|
+
/** Why it waits, for example for the host test slot and who holds it (decision 0018). */
|
|
12
|
+
readonly waitDetail?: string;
|
|
13
|
+
/** When the command was admitted; elapsed_ms counts from here. */
|
|
14
|
+
readonly executionStartedAt?: number;
|
|
15
|
+
}
|
|
16
|
+
/** This MCP server's governor, built once from the environment the bridge handed it. */
|
|
17
|
+
export declare function managedCommandHostLoadGate(): HostLoadStepGate | undefined;
|
|
18
|
+
/** Test support: installs a gate (undefined disables it; null rebuilds from the environment). */
|
|
19
|
+
export declare function setManagedCommandHostLoadGateForTesting(value: HostLoadStepGate | undefined | null): void;
|
|
20
|
+
/**
|
|
21
|
+
* Admits one managed command. The waiting receipt is written while the command
|
|
22
|
+
* is queued and always lands before the launch receipts, so a stale "waiting"
|
|
23
|
+
* write can never replace a later status.
|
|
24
|
+
*/
|
|
25
|
+
export declare class ManagedCommandHostCapacity {
|
|
26
|
+
private readonly persistWaiting;
|
|
27
|
+
private readonly gateFor;
|
|
28
|
+
readonly classification: HostLoadStepClassification;
|
|
29
|
+
private readonly label;
|
|
30
|
+
private requestedAtMs;
|
|
31
|
+
private waitingWrite;
|
|
32
|
+
constructor(input: ManagedCommandStepInput & {
|
|
33
|
+
readonly label: string;
|
|
34
|
+
}, persistWaiting: (fields: ManagedCommandHostLoadFields) => Promise<void>, gateFor?: () => HostLoadStepGate | undefined);
|
|
35
|
+
/** Runs `launch` once admitted; `fields` is undefined with the governor off. */
|
|
36
|
+
run<T>(signal: AbortSignal, launch: (fields: ManagedCommandHostLoadFields | undefined, control: HostLoadStepControl) => Promise<T>, onReleaseFailed?: (error: unknown) => Promise<void>): Promise<T>;
|
|
37
|
+
/**
|
|
38
|
+
* Host-load facts for a command that was never admitted (it timed out in
|
|
39
|
+
* the queue or was stopped while waiting), once its waiting receipt landed.
|
|
40
|
+
*/
|
|
41
|
+
unadmittedFields(error: unknown): Promise<ManagedCommandHostLoadFields | undefined>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The managed command's process tree as its supervisor recorded it, for its
|
|
45
|
+
* host load token: a reclaim then stops exactly this tree before reuse.
|
|
46
|
+
*/
|
|
47
|
+
export declare function attachManagedCommandProcess(control: HostLoadStepControl, metadataPath: string): Promise<void>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { hostLoadGovernorFromChildEnvironment } from "../runtime/host-load-child-environment.js";
|
|
2
|
+
import { HostCapacityTimeoutError } from "../runtime/host-load-governor.js";
|
|
3
|
+
import { classifyManagedCommand } from "../runtime/host-load-step-class.js";
|
|
4
|
+
import { attachSupervisedStepProcess, runHostGovernedStep } from "../runtime/host-load-step-run.js";
|
|
5
|
+
let gate = null;
|
|
6
|
+
/** This MCP server's governor, built once from the environment the bridge handed it. */
|
|
7
|
+
export function managedCommandHostLoadGate() {
|
|
8
|
+
if (gate === null)
|
|
9
|
+
gate = hostLoadGovernorFromChildEnvironment();
|
|
10
|
+
return gate;
|
|
11
|
+
}
|
|
12
|
+
/** Test support: installs a gate (undefined disables it; null rebuilds from the environment). */
|
|
13
|
+
export function setManagedCommandHostLoadGateForTesting(value) {
|
|
14
|
+
gate = value;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Admits one managed command. The waiting receipt is written while the command
|
|
18
|
+
* is queued and always lands before the launch receipts, so a stale "waiting"
|
|
19
|
+
* write can never replace a later status.
|
|
20
|
+
*/
|
|
21
|
+
export class ManagedCommandHostCapacity {
|
|
22
|
+
persistWaiting;
|
|
23
|
+
gateFor;
|
|
24
|
+
classification;
|
|
25
|
+
label;
|
|
26
|
+
requestedAtMs = null;
|
|
27
|
+
waitingWrite = Promise.resolve();
|
|
28
|
+
constructor(input, persistWaiting, gateFor = managedCommandHostLoadGate) {
|
|
29
|
+
this.persistWaiting = persistWaiting;
|
|
30
|
+
this.gateFor = gateFor;
|
|
31
|
+
this.classification = classifyManagedCommand(input);
|
|
32
|
+
this.label = input.label;
|
|
33
|
+
}
|
|
34
|
+
/** Runs `launch` once admitted; `fields` is undefined with the governor off. */
|
|
35
|
+
async run(signal, launch, onReleaseFailed) {
|
|
36
|
+
const current = this.gateFor();
|
|
37
|
+
if (current?.enabled)
|
|
38
|
+
this.requestedAtMs = Date.now();
|
|
39
|
+
return await runHostGovernedStep(current, {
|
|
40
|
+
classification: this.classification,
|
|
41
|
+
label: this.label,
|
|
42
|
+
dispatchAttemptId: process.env.FORGE_DISPATCH_ATTEMPT_ID?.trim() || null,
|
|
43
|
+
// An agent waits on its managed commands; readiness probes never start one.
|
|
44
|
+
priority: "foreground",
|
|
45
|
+
signal,
|
|
46
|
+
// The receipt says host_capacity_token_fenced itself (termination_reason).
|
|
47
|
+
reportsOwnFence: true,
|
|
48
|
+
onWaiting: decision => {
|
|
49
|
+
this.waitingWrite = this.persistWaiting({
|
|
50
|
+
stepClass: this.classification.stepClass,
|
|
51
|
+
waitMs: 0,
|
|
52
|
+
waitStartedAt: this.requestedAtMs ?? Date.now(),
|
|
53
|
+
waitDetail: decision.detail,
|
|
54
|
+
}).catch(() => undefined);
|
|
55
|
+
},
|
|
56
|
+
onReleaseFailed,
|
|
57
|
+
}, async (waitMs, control) => {
|
|
58
|
+
await this.waitingWrite;
|
|
59
|
+
// The launch timer and timeout_ms start inside `launch`, after admission.
|
|
60
|
+
return await launch(waitMs === null
|
|
61
|
+
? undefined
|
|
62
|
+
: { stepClass: this.classification.stepClass, waitMs, executionStartedAt: Date.now() }, control);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Host-load facts for a command that was never admitted (it timed out in
|
|
67
|
+
* the queue or was stopped while waiting), once its waiting receipt landed.
|
|
68
|
+
*/
|
|
69
|
+
async unadmittedFields(error) {
|
|
70
|
+
await this.waitingWrite;
|
|
71
|
+
if (this.requestedAtMs === null)
|
|
72
|
+
return undefined;
|
|
73
|
+
const waitMs = error instanceof HostCapacityTimeoutError ? error.waitMs : Date.now() - this.requestedAtMs;
|
|
74
|
+
return { stepClass: this.classification.stepClass, waitMs: Math.round(waitMs), executionStartedAt: Date.now() };
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The managed command's process tree as its supervisor recorded it, for its
|
|
79
|
+
* host load token: a reclaim then stops exactly this tree before reuse.
|
|
80
|
+
*/
|
|
81
|
+
export async function attachManagedCommandProcess(control, metadataPath) {
|
|
82
|
+
await attachSupervisedStepProcess(control, metadataPath);
|
|
83
|
+
}
|