@loucompanion/forge-bridge 0.1.4-dev.138b79c6feb3 → 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 +142 -1
- package/dist/bridge/bridge-chat-provider-command.d.ts +19 -0
- package/dist/bridge/bridge-chat-provider-command.js +132 -0
- package/dist/bridge/bridge-chat.types.d.ts +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 +87 -14
- package/dist/bridge/bridge.service.js +393 -337
- package/dist/bridge/bridge.types.d.ts +16 -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 +3 -0
- package/dist/bridge/runner-host-capabilities.js +13 -0
- package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
- package/dist/bridge/sandbox-resource-accounting.js +150 -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 +11 -1
- package/dist/cleanup/cleanup.service.js +80 -62
- package/dist/cleanup/cleanup.types.d.ts +2 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +2 -0
- package/dist/cleanup/host-runtime-ledger.js +30 -9
- package/dist/cli/cli.help.js +74 -12
- package/dist/cli/cli.service.d.ts +19 -10
- package/dist/cli/cli.service.js +142 -185
- 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 +104 -26
- 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 +2 -0
- package/dist/runtime/attempt-process-supervisor.js +12 -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-facts.d.ts +2 -1
- package/dist/runtime/host-load-admission.d.ts +18 -3
- package/dist/runtime/host-load-admission.js +19 -4
- package/dist/runtime/host-load-child-environment.d.ts +11 -6
- package/dist/runtime/host-load-child-environment.js +22 -11
- package/dist/runtime/host-load-governor-config.d.ts +19 -1
- package/dist/runtime/host-load-governor-config.js +37 -0
- package/dist/runtime/host-load-governor.d.ts +14 -0
- package/dist/runtime/host-load-governor.js +139 -26
- package/dist/runtime/host-load-ledger-lock.js +6 -4
- 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 +34 -4
- package/dist/runtime/host-load-sampler.js +73 -7
- package/dist/runtime/host-load-step-class.d.ts +3 -1
- package/dist/runtime/host-load-step-class.js +60 -5
- 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 +26 -0
- package/dist/runtime/host-load-token-ledger.js +93 -61
- 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-runtime-contract.d.ts +12 -0
- package/dist/runtime/host-runtime-contract.js +29 -1
- package/dist/runtime/host-runtime-lease.d.ts +32 -4
- package/dist/runtime/host-runtime-lease.js +109 -173
- 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 +36 -0
- package/dist/runtime/managed-command-teardown.js +5 -16
- package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
- package/dist/runtime/native-test-postgres-fallback.js +60 -8
- 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 +10 -2
- package/dist/sandbox/host-capacity-broker.js +27 -6
- 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.js +2 -6
- 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 +0 -7
- package/dist/session/managed-attempt-tools.js +58 -91
- package/dist/session/managed-build-coordinator.d.ts +16 -0
- package/dist/session/managed-build-coordinator.js +10 -0
- 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 +2 -0
- package/dist/session/managed-command-host-load.js +2 -1
- package/dist/session/phase-completion.artifacts.js +2 -1
- package/dist/session/phase-completion.d.ts +8 -0
- package/dist/session/phase-completion.js +1 -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.runtime.d.ts +0 -8
- package/dist/session/phase-completion.runtime.js +43 -197
- package/dist/session/phase-completion.schemas.js +25 -23
- package/dist/session/phase-completion.validation.js +3 -1
- 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.js +10 -10
- package/dist/session/pre-publication-step-execution.d.ts +2 -1
- package/dist/session/pre-publication-step-execution.js +6 -5
- package/dist/session/pre-publication-validation.d.ts +30 -14
- package/dist/session/pre-publication-validation.js +207 -134
- 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.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.process.d.ts +15 -36
- package/dist/session/provider-cli/provider-cli.process.js +39 -430
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +5 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +68 -31
- 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 +5 -5
- package/dist/session/provider-cli/provider-cli.service.js +70 -263
- 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 +4 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +45 -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 +2 -0
- package/dist/session/provider-cli/provider-output-state.js +6 -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/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 +22 -1
- package/dist/session/sandbox-host-capacity-gate.js +42 -14
- package/dist/session/session-redaction.js +31 -181
- package/dist/session/session.base.d.ts +6 -1
- package/dist/session/session.service.d.ts +6 -1
- package/dist/session/session.service.js +75 -64
- package/dist/session/session.types.js +3 -3
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -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 +13 -1
- package/dist/shared/process/host-process-supervisor.js +66 -14
- 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/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 +27 -5
- package/dist/worktree/worktree.service.js +110 -181
- package/dist/worktree/worktree.types.d.ts +31 -0
- package/package.json +2 -2
|
@@ -3,19 +3,18 @@ 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";
|
|
11
10
|
import { emptyToolInputHint, isEmptyToolInput } from "./mcp-argument-coercion.js";
|
|
12
|
-
import { ManagedBuildCoordinator } from "./managed-build-coordinator.js";
|
|
11
|
+
import { assertManagedBuildSparesSupervisedRuntimes, ManagedBuildCoordinator } from "./managed-build-coordinator.js";
|
|
13
12
|
import { attachManagedCommandProcess, ManagedCommandHostCapacity, } from "./managed-command-host-load.js";
|
|
14
13
|
import { HostCapacityLedgerUnavailableError } from "../runtime/host-load-ledger-lock.js";
|
|
15
14
|
import { isProcessTreeTerminationUnproven } from "../shared/process/process.js";
|
|
16
15
|
import { HostCapacityTokenFencedError } from "../runtime/host-load-token-ledger.js";
|
|
17
|
-
import {
|
|
18
|
-
import { managedBuildConfiguration, publishManagedBuildReceipt, verifyManagedBuildReceipt, } from "./managed-build-receipt.js";
|
|
16
|
+
import { withoutHostLoadGovernorVariables } from "../runtime/host-load-child-environment.js";
|
|
17
|
+
import { managedBuildConfiguration, persistJsonAtomically, publishManagedBuildReceipt, verifyManagedBuildReceipt, } from "./managed-build-receipt.js";
|
|
19
18
|
import { managedLongTierTimeoutMs, managedMaximumCommandTimeoutMs, managedVerificationTierTimeoutMs, } from "./managed-verification-timeouts.js";
|
|
20
19
|
import { resolveWindowsCommandFromPath, StreamingProviderProcessRunner } from "./provider-cli/provider-cli.process.js";
|
|
21
20
|
import { monotonicNowMs } from "../shared/time/monotonic.js";
|
|
@@ -38,8 +37,6 @@ const managedCommandRetryAfterMs = 60_000;
|
|
|
38
37
|
const managedCommandLaunchTimeoutMs = 60_000;
|
|
39
38
|
const managedCommandProgressPersistIntervalMs = 5_000;
|
|
40
39
|
const managedCommandReceiptPollIntervalMs = 1_000;
|
|
41
|
-
const managedCommandReceiptReplaceAttempts = 40;
|
|
42
|
-
const managedCommandReceiptReplaceRetryMs = 25;
|
|
43
40
|
const terminalManagedCommandStatuses = new Set([
|
|
44
41
|
"pass",
|
|
45
42
|
"fail",
|
|
@@ -295,6 +292,9 @@ async function launchManagedCommand(record, worktreePath, forceAsync, verificati
|
|
|
295
292
|
buildReceiptReuse,
|
|
296
293
|
controller: new AbortController(),
|
|
297
294
|
};
|
|
295
|
+
// A build aimed at the output a running supervised runtime executes from fails here, naming
|
|
296
|
+
// that runtime, instead of failing on its locked files after the build-slot and capacity waits.
|
|
297
|
+
await assertManagedBuildSparesSupervisedRuntimes(invocation);
|
|
298
298
|
if (forceAsync || timeoutMs > maximumSynchronousWaitMs) {
|
|
299
299
|
const started = managedCommandResult({
|
|
300
300
|
...invocation,
|
|
@@ -447,7 +447,7 @@ export function buildManagedVerificationCommand(profile, outputDirectory, shardC
|
|
|
447
447
|
export function preferredPowerShellExecutable(platform = process.platform, pathValue = process.env.PATH ?? "") {
|
|
448
448
|
if (platform !== "win32")
|
|
449
449
|
return "pwsh";
|
|
450
|
-
return resolveWindowsCommandFromPath("pwsh.exe", pathValue) ?? "powershell.exe";
|
|
450
|
+
return resolveWindowsCommandFromPath("pwsh.exe", pathValue, undefined, { skipAppExecutionAliases: true }) ?? "powershell.exe";
|
|
451
451
|
}
|
|
452
452
|
export function validatePlaywrightProjectName(project, availableProjects) {
|
|
453
453
|
if (!availableProjects.includes(project)) {
|
|
@@ -594,41 +594,48 @@ async function executeManagedCommand(invocation) {
|
|
|
594
594
|
return managedCommandPublicResult(receipt);
|
|
595
595
|
}
|
|
596
596
|
}
|
|
597
|
+
/** A command's environment and redaction list; a setup that throws releases the database it started. */
|
|
597
598
|
async function managedCommandProcessEnvironment(invocation) {
|
|
598
599
|
assertHostDatabaseCapabilityBoundary();
|
|
599
|
-
const
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
600
|
+
const database = invocation.verificationProfile ? await managedVerificationDatabase() : noManagedVerificationDatabase;
|
|
601
|
+
return await setUpWithManagedVerificationDatabase(database, () => {
|
|
602
|
+
const exactSecrets = [
|
|
603
|
+
...database.secrets,
|
|
604
|
+
// The attempt's brokered database login reaches managed commands; their output never shows it.
|
|
605
|
+
...attemptDatabaseCapabilitySecrets(process.env[attemptDatabaseCapabilityEnvironment]),
|
|
606
|
+
];
|
|
607
|
+
const environment = inheritedEnvironment({
|
|
608
|
+
FORGE_RUNTIME_MODE: "host",
|
|
609
|
+
FORGE_RESOURCE_LEASE_ID: requiredAttemptEnvironment("FORGE_RESOURCE_LEASE_ID"),
|
|
610
|
+
FORGE_DISPATCH_ATTEMPT_ID: requiredAttemptEnvironment("FORGE_DISPATCH_ATTEMPT_ID"),
|
|
611
|
+
// This nested command owns a distinct supervisor identity. A command-local
|
|
612
|
+
// fence avoids exposing the parent attempt's fencing capability to Codex's
|
|
613
|
+
// MCP subprocess configuration while preserving exact-tree cleanup proof.
|
|
614
|
+
FORGE_FENCING_TOKEN: randomUUID(),
|
|
615
|
+
FORGE_LOG_DIR: invocation.logDirectory,
|
|
616
|
+
FORGE_TEST_OUTPUT_DIR: requiredAttemptEnvironment("FORGE_TEST_OUTPUT_DIR"),
|
|
617
|
+
FORGE_PROCESS_SUPERVISOR_ID: `managed-${invocation.commandId.replaceAll("-", "")}`,
|
|
618
|
+
FORGE_PROCESS_SUPERVISOR_METADATA_PATH: invocation.metadataPath,
|
|
619
|
+
...(invocation.verificationProfile
|
|
620
|
+
? {
|
|
621
|
+
FORGE_MANAGED_VERIFICATION_PROFILE: invocation.verificationProfile,
|
|
622
|
+
// Managed verification executes mutable worktree scripts, SDK targets,
|
|
623
|
+
// and test assemblies. It uses an attempt-owned container, or the
|
|
624
|
+
// dedicated native test cluster while Docker is unavailable; it never
|
|
625
|
+
// receives a capability for a server that holds real data.
|
|
626
|
+
FORGE_MANAGED_VERIFICATION_DATABASE_MODE: "container_only",
|
|
627
|
+
...database.environment,
|
|
628
|
+
}
|
|
629
|
+
: {}),
|
|
630
|
+
});
|
|
631
|
+
return { environment, exactSecrets, release: database.release };
|
|
630
632
|
});
|
|
631
|
-
|
|
633
|
+
}
|
|
634
|
+
function clearManagedCommandTimers(...timers) {
|
|
635
|
+
// clearTimeout and clearInterval share one timer table.
|
|
636
|
+
for (const timer of timers)
|
|
637
|
+
if (timer)
|
|
638
|
+
clearTimeout(timer);
|
|
632
639
|
}
|
|
633
640
|
async function executeManagedCommandProcess(invocation) {
|
|
634
641
|
let prepared;
|
|
@@ -830,11 +837,9 @@ async function executeManagedCommandProcess(invocation) {
|
|
|
830
837
|
return managedCommandPublicResult(receipt);
|
|
831
838
|
}
|
|
832
839
|
finally {
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
if (progressHeartbeat)
|
|
837
|
-
clearInterval(progressHeartbeat);
|
|
840
|
+
clearManagedCommandTimers(launchTimer, timer, progressHeartbeat);
|
|
841
|
+
// An ephemeral verification cluster lives exactly as long as its command; one that would not stop is reaped later and named in the receipt.
|
|
842
|
+
await releaseManagedVerificationDatabase(prepared, async (message) => await annotateManagedCommandReceipt(invocation.receiptPath, { ephemeral_cluster_release_error: redactText(message, exactSecrets) }));
|
|
838
843
|
}
|
|
839
844
|
}
|
|
840
845
|
async function readManagedCommand(input) {
|
|
@@ -907,7 +912,7 @@ async function waitManagedCommand(input) {
|
|
|
907
912
|
const lastOutputAt = Date.parse(String(receipt.structuredContent.last_output_at));
|
|
908
913
|
const hostLoadWaitMs = receipt.structuredContent.host_load_wait_ms;
|
|
909
914
|
const progress = receipt.structuredContent.status === "waiting_for_host_capacity" && typeof hostLoadWaitMs === "number"
|
|
910
|
-
? ` It has waited ${Math.round(hostLoadWaitMs / 1000)}s for host capacity 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
|
+
? ` 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.`
|
|
911
916
|
: receipt.structuredContent.status === "running" && typeof elapsedMs === "number"
|
|
912
917
|
? ` It has run for ${Math.round(elapsedMs / 1000)}s`
|
|
913
918
|
+ (Number.isFinite(lastOutputAt) ? `, last output ${Math.max(0, Math.round((Date.now() - lastOutputAt) / 1000))}s ago` : ", with no output yet")
|
|
@@ -938,27 +943,7 @@ function managedCommandReceiptPath(logDirectory, commandId) {
|
|
|
938
943
|
return path.join(logDirectory, "managed-commands", `${commandId}.receipt.json`);
|
|
939
944
|
}
|
|
940
945
|
async function persistManagedCommandReceipt(receiptPath, receipt) {
|
|
941
|
-
|
|
942
|
-
await fs.writeFile(temporaryPath, `${JSON.stringify(receipt, null, 2)}\n`, { encoding: "utf8", mode: 0o600 });
|
|
943
|
-
try {
|
|
944
|
-
for (let attempt = 1;; attempt += 1) {
|
|
945
|
-
try {
|
|
946
|
-
await fs.rename(temporaryPath, receiptPath);
|
|
947
|
-
break;
|
|
948
|
-
}
|
|
949
|
-
catch (error) {
|
|
950
|
-
const code = error.code;
|
|
951
|
-
if (attempt >= managedCommandReceiptReplaceAttempts
|
|
952
|
-
|| (code !== "EPERM" && code !== "EBUSY" && code !== "EACCES")) {
|
|
953
|
-
throw error;
|
|
954
|
-
}
|
|
955
|
-
await delay(managedCommandReceiptReplaceRetryMs);
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
}
|
|
959
|
-
finally {
|
|
960
|
-
await fs.rm(temporaryPath, { force: true }).catch(() => undefined);
|
|
961
|
-
}
|
|
946
|
+
await persistJsonAtomically(receiptPath, receipt);
|
|
962
947
|
}
|
|
963
948
|
function managedCommandResult(values) {
|
|
964
949
|
// Governed commands count elapsed time from admission: queue time is host_load_wait_ms.
|
|
@@ -1033,7 +1018,7 @@ function managedCommandHostLoadReceipt(hostLoad) {
|
|
|
1033
1018
|
return {
|
|
1034
1019
|
host_load_step_class: hostLoad.stepClass,
|
|
1035
1020
|
host_load_wait_ms: waiting ? Math.max(0, Date.now() - hostLoad.waitStartedAt) : hostLoad.waitMs,
|
|
1036
|
-
...(waiting ? { host_load_wait_started_at: new Date(hostLoad.waitStartedAt).toISOString() } : {}),
|
|
1021
|
+
...(waiting ? { host_load_wait_started_at: new Date(hostLoad.waitStartedAt).toISOString(), host_load_wait_detail: hostLoad.waitDetail ?? null } : {}),
|
|
1037
1022
|
};
|
|
1038
1023
|
}
|
|
1039
1024
|
async function annotateManagedCommandReceipt(receiptPath, fields) {
|
|
@@ -1115,30 +1100,15 @@ async function containedWorkingDirectory(worktreePath, input) {
|
|
|
1115
1100
|
}
|
|
1116
1101
|
function inheritedEnvironment(overrides) {
|
|
1117
1102
|
const env = {};
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
continue;
|
|
1103
|
+
// A nested Forge process must not join the host ledger: it would queue behind the
|
|
1104
|
+
// token this command already holds. Every FORGE_HOST_LOAD_* variable is dropped,
|
|
1105
|
+
// the test slot count too (decision 0018).
|
|
1106
|
+
for (const [key, value] of Object.entries(withoutHostLoadGovernorVariables(process.env))) {
|
|
1123
1107
|
if (typeof value === "string" && !looksSensitiveEnvironmentName(key))
|
|
1124
1108
|
env[key] = value;
|
|
1125
1109
|
}
|
|
1126
1110
|
return { ...env, ...overrides };
|
|
1127
1111
|
}
|
|
1128
|
-
/**
|
|
1129
|
-
* Runner-authored verification normally uses its attempt-owned Testcontainers
|
|
1130
|
-
* database. Only when the Docker engine is unavailable does it switch to the
|
|
1131
|
-
* operator-provisioned native test cluster, which holds no real data.
|
|
1132
|
-
*/
|
|
1133
|
-
export async function managedVerificationDatabaseEnvironment(dockerAvailable = async () => (await new DockerEngineProbe().refresh(true)).available, readFallback = () => {
|
|
1134
|
-
const configPath = process.env[nativeTestPostgresFallbackConfigEnvironment]?.trim();
|
|
1135
|
-
return configPath ? readNativeTestPostgresFallback(configPath) : null;
|
|
1136
|
-
}) {
|
|
1137
|
-
const fallback = readFallback();
|
|
1138
|
-
if (!fallback || await dockerAvailable())
|
|
1139
|
-
return {};
|
|
1140
|
-
return nativeTestPostgresFallbackEnvironment(fallback);
|
|
1141
|
-
}
|
|
1142
1112
|
export function isBuildProducingManagedCommand(command, args) {
|
|
1143
1113
|
const executable = path.basename(command).toLowerCase();
|
|
1144
1114
|
if (executable === "dotnet" || executable === "dotnet.exe") {
|
|
@@ -1150,10 +1120,7 @@ export function isBuildProducingManagedCommand(command, args) {
|
|
|
1150
1120
|
if (["powershell", "powershell.exe", "pwsh", "pwsh.exe"].includes(executable)) {
|
|
1151
1121
|
const fileIndex = args.findIndex(argument => argument.toLowerCase() === "-file");
|
|
1152
1122
|
const script = fileIndex >= 0 ? path.basename(args[fileIndex + 1] ?? "").toLowerCase() : "";
|
|
1153
|
-
if (
|
|
1154
|
-
return !args.some(argument => argument.toLowerCase() === "-nobuild");
|
|
1155
|
-
}
|
|
1156
|
-
if (script === "run-dotnet-test-tier.ps1") {
|
|
1123
|
+
if (["run-dotnet-test-tier.ps1", "run-dotnet-test-tier-set.ps1", "run-dotnet-test-suite.ps1"].includes(script)) {
|
|
1157
1124
|
return !args.some(argument => argument.toLowerCase() === "-nobuild");
|
|
1158
1125
|
}
|
|
1159
1126
|
}
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
/** The managed command a build check needs: what it runs, where, and for which attempt. */
|
|
2
|
+
export interface ManagedBuildCandidate {
|
|
3
|
+
readonly command: string;
|
|
4
|
+
readonly args: readonly string[];
|
|
5
|
+
readonly cwd: string;
|
|
6
|
+
readonly worktreePath: string;
|
|
7
|
+
readonly logDirectory: string;
|
|
8
|
+
readonly buildProducing: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Refuses, before launch, a managed command that would build into the output one of the
|
|
12
|
+
* attempt's running supervised runtimes executes from. The build slot below orders builds
|
|
13
|
+
* against each other; a running runtime cannot wait its turn, so the collision fails fast
|
|
14
|
+
* with an error naming the runtime instead of a build stuck on its locked files.
|
|
15
|
+
*/
|
|
16
|
+
export declare function assertManagedBuildSparesSupervisedRuntimes(candidate: ManagedBuildCandidate): Promise<void>;
|
|
1
17
|
export declare class ManagedBuildCoordinator {
|
|
2
18
|
private readonly stateRoot;
|
|
3
19
|
constructor(stateRoot?: string);
|
|
@@ -3,10 +3,20 @@ import fs from "node:fs/promises";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { defaultWorktreeCoordinatorStateRoot } from "../worktree/worktree-paths.js";
|
|
5
5
|
import { monotonicNowMs } from "../shared/time/monotonic.js";
|
|
6
|
+
import { assertBuildSparesSupervisedRuntimes } from "../runtime/supervised-runtime-build-guard.js";
|
|
6
7
|
const heartbeatIntervalMs = 30_000;
|
|
7
8
|
const staleAfterMs = 2 * 60_000;
|
|
8
9
|
const acquisitionTimeoutMs = 2 * 60 * 60_000;
|
|
9
10
|
const pollIntervalMs = 100;
|
|
11
|
+
/**
|
|
12
|
+
* Refuses, before launch, a managed command that would build into the output one of the
|
|
13
|
+
* attempt's running supervised runtimes executes from. The build slot below orders builds
|
|
14
|
+
* against each other; a running runtime cannot wait its turn, so the collision fails fast
|
|
15
|
+
* with an error naming the runtime instead of a build stuck on its locked files.
|
|
16
|
+
*/
|
|
17
|
+
export async function assertManagedBuildSparesSupervisedRuntimes(candidate) {
|
|
18
|
+
await assertBuildSparesSupervisedRuntimes({ ...candidate, buildsWorktreeSolution: candidate.buildProducing });
|
|
19
|
+
}
|
|
10
20
|
export class ManagedBuildCoordinator {
|
|
11
21
|
stateRoot;
|
|
12
22
|
constructor(stateRoot = defaultWorktreeCoordinatorStateRoot()) {
|
|
@@ -19,3 +19,8 @@ export declare function verifyManagedBuildReceipt(options: {
|
|
|
19
19
|
readonly requiredCoverage: string;
|
|
20
20
|
}): Promise<ManagedBuildReceiptEvidence>;
|
|
21
21
|
export declare function managedBuildConfiguration(command: string, args: readonly string[]): string;
|
|
22
|
+
/**
|
|
23
|
+
* Writes a JSON receipt by replacing the whole file. Agents and Forge poll receipts, and on
|
|
24
|
+
* Windows a poll that has one open refuses the replace: that delays a write, never fails it.
|
|
25
|
+
*/
|
|
26
|
+
export declare function persistJsonAtomically(receiptPath: string, value: unknown): Promise<void>;
|
|
@@ -3,6 +3,7 @@ import { spawn } from "node:child_process";
|
|
|
3
3
|
import fs from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { defaultWorktreeCoordinatorStateRoot } from "../worktree/worktree-paths.js";
|
|
6
|
+
import { replaceFile } from "../shared/fs/replace-file.js";
|
|
6
7
|
const schemaVersion = 1;
|
|
7
8
|
const maximumRetainedReceipts = 8;
|
|
8
9
|
const maximumOutputManifestEntries = 20_000;
|
|
@@ -262,7 +263,7 @@ async function persistImmutableReceipt(receiptPath, receipt) {
|
|
|
262
263
|
const temporaryPath = `${receiptPath}.${randomUUID()}.tmp`;
|
|
263
264
|
await fs.writeFile(temporaryPath, `${JSON.stringify(receipt, null, 2)}\n`, { encoding: "utf8", mode: 0o600 });
|
|
264
265
|
try {
|
|
265
|
-
await
|
|
266
|
+
await replaceFile(temporaryPath, receiptPath).catch(async (error) => {
|
|
266
267
|
if (error.code !== "EEXIST")
|
|
267
268
|
throw error;
|
|
268
269
|
});
|
|
@@ -271,11 +272,15 @@ async function persistImmutableReceipt(receiptPath, receipt) {
|
|
|
271
272
|
await fs.rm(temporaryPath, { force: true }).catch(() => undefined);
|
|
272
273
|
}
|
|
273
274
|
}
|
|
274
|
-
|
|
275
|
+
/**
|
|
276
|
+
* Writes a JSON receipt by replacing the whole file. Agents and Forge poll receipts, and on
|
|
277
|
+
* Windows a poll that has one open refuses the replace: that delays a write, never fails it.
|
|
278
|
+
*/
|
|
279
|
+
export async function persistJsonAtomically(receiptPath, value) {
|
|
275
280
|
const temporaryPath = `${receiptPath}.${randomUUID()}.tmp`;
|
|
276
281
|
await fs.writeFile(temporaryPath, `${JSON.stringify(value, null, 2)}\n`, { encoding: "utf8", mode: 0o600 });
|
|
277
282
|
try {
|
|
278
|
-
await
|
|
283
|
+
await replaceFile(temporaryPath, receiptPath);
|
|
279
284
|
}
|
|
280
285
|
finally {
|
|
281
286
|
await fs.rm(temporaryPath, { force: true }).catch(() => undefined);
|
|
@@ -8,6 +8,8 @@ export interface ManagedCommandHostLoadFields {
|
|
|
8
8
|
readonly waitMs: number;
|
|
9
9
|
/** Set while the command is still queued: the receipt reports the wait so far. */
|
|
10
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;
|
|
11
13
|
/** When the command was admitted; elapsed_ms counts from here. */
|
|
12
14
|
readonly executionStartedAt?: number;
|
|
13
15
|
}
|
|
@@ -45,11 +45,12 @@ export class ManagedCommandHostCapacity {
|
|
|
45
45
|
signal,
|
|
46
46
|
// The receipt says host_capacity_token_fenced itself (termination_reason).
|
|
47
47
|
reportsOwnFence: true,
|
|
48
|
-
onWaiting:
|
|
48
|
+
onWaiting: decision => {
|
|
49
49
|
this.waitingWrite = this.persistWaiting({
|
|
50
50
|
stepClass: this.classification.stepClass,
|
|
51
51
|
waitMs: 0,
|
|
52
52
|
waitStartedAt: this.requestedAtMs ?? Date.now(),
|
|
53
|
+
waitDetail: decision.detail,
|
|
53
54
|
}).catch(() => undefined);
|
|
54
55
|
},
|
|
55
56
|
onReleaseFailed,
|
|
@@ -2,7 +2,7 @@ import crypto from "node:crypto";
|
|
|
2
2
|
import fs from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { redactSecrets } from "../shared/redaction/redaction.js";
|
|
5
|
-
import { ensureNoSymbolicLinkPathSegments, isPathUnderRoot, sha256File } from "./qa-sidecar-validation.js";
|
|
5
|
+
import { assertQaSidecarJsonShape, ensureNoSymbolicLinkPathSegments, isPathUnderRoot, sha256File } from "./qa-sidecar-validation.js";
|
|
6
6
|
import { assertClaimedChangedFilesMatchPublishableDiff } from "./publishable-worktree-changes.js";
|
|
7
7
|
import { coerceJsonStringArguments } from "./mcp-argument-coercion.js";
|
|
8
8
|
import { toolInputSchema } from "./phase-completion.schemas.js";
|
|
@@ -690,6 +690,7 @@ async function validateQaSidecarReferences(worktreePath, workItemId, sidecars, o
|
|
|
690
690
|
if (actualHash !== normalizeSha256ContentHash(contentHash)) {
|
|
691
691
|
throw new Error(`sidecars[${index}].content_hash does not match the referenced file.`);
|
|
692
692
|
}
|
|
693
|
+
await assertQaSidecarJsonShape(fullPath, sidecarPath, `sidecars[${index}]`);
|
|
693
694
|
const canonicalPath = path.relative(worktreePath, fullPath).split(path.sep).join("/");
|
|
694
695
|
const duplicateKey = canonicalPath.toLowerCase();
|
|
695
696
|
const existing = validatedByPath.get(duplicateKey);
|
|
@@ -4,6 +4,7 @@ export { isDebugCompletionPhase } from "./phase-completion.validation.js";
|
|
|
4
4
|
export { readCompletionArtifact, writeCompletionArtifact } from "./phase-completion.artifacts.js";
|
|
5
5
|
export * from "./phase-completion.prompts.js";
|
|
6
6
|
export * from "./phase-completion.runtime.js";
|
|
7
|
+
export * from "./phase-completion.mcp-args.js";
|
|
7
8
|
export type DevelopCompletionPhase = "implementation" | "self_review" | "validation";
|
|
8
9
|
export type DebugCompletionPhase = "debug_repro" | "debug_root_cause" | "debug_fix" | "debug_regression";
|
|
9
10
|
export type ArchitectCompletionPhase = "architect";
|
|
@@ -31,6 +32,12 @@ export interface CompletionToolRuntimeOptions {
|
|
|
31
32
|
readonly runtimeEnvironment?: Readonly<Record<string, string>>;
|
|
32
33
|
/** Host load governor variables; only the MCP server receives them. */
|
|
33
34
|
readonly hostLoadEnvironment?: Readonly<Record<string, string>>;
|
|
35
|
+
/**
|
|
36
|
+
* Serve only the managed-attempt tools (managed commands, verification, waits), never a
|
|
37
|
+
* completion tool. A pre-publication repair turn uses this: its phase's completion artifacts are
|
|
38
|
+
* already recorded and validated, and the repair prompt forbids rewriting them.
|
|
39
|
+
*/
|
|
40
|
+
readonly managedToolsOnly?: boolean;
|
|
34
41
|
}
|
|
35
42
|
export interface CompletionToolServerConfig {
|
|
36
43
|
readonly worktreePath: string;
|
|
@@ -46,6 +53,7 @@ export interface CompletionToolServerConfig {
|
|
|
46
53
|
readonly architectCycle?: boolean;
|
|
47
54
|
readonly draftCycle?: boolean;
|
|
48
55
|
readonly decomposeCycle?: boolean;
|
|
56
|
+
readonly managedToolsOnly?: boolean;
|
|
49
57
|
}
|
|
50
58
|
export interface CompletionToolCallResult {
|
|
51
59
|
readonly content: readonly {
|
|
@@ -4,6 +4,7 @@ export { isDebugCompletionPhase } from "./phase-completion.validation.js";
|
|
|
4
4
|
export { readCompletionArtifact, writeCompletionArtifact } from "./phase-completion.artifacts.js";
|
|
5
5
|
export * from "./phase-completion.prompts.js";
|
|
6
6
|
export * from "./phase-completion.runtime.js";
|
|
7
|
+
export * from "./phase-completion.mcp-args.js";
|
|
7
8
|
export const toolServerName = "forge";
|
|
8
9
|
export const completionRedactionSecretsEnv = "FORGE_COMPLETION_REDACTION_SECRETS";
|
|
9
10
|
export const completionPhaseOrder = ["implementation", "self_review", "validation"];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type CompletionToolServerConfig } from "./phase-completion.js";
|
|
2
|
+
export declare function buildCompletionToolServerArgs(config: CompletionToolServerConfig): readonly string[];
|
|
3
|
+
export declare function parseCompletionMcpArgs(argv: readonly string[]): {
|
|
4
|
+
readonly ok: true;
|
|
5
|
+
readonly config: CompletionToolServerConfig;
|
|
6
|
+
} | {
|
|
7
|
+
readonly ok: false;
|
|
8
|
+
readonly error: string;
|
|
9
|
+
};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { attemptDatabaseCapabilityEnvironment, attemptDatabaseCapabilitySecrets, } from "../runtime/attempt-database-broker.js";
|
|
3
|
+
import { completionRedactionSecretsEnv, } from "./phase-completion.js";
|
|
4
|
+
import { isDebugCompletionPhase, isDevelopCompletionPhase, normalizedOwnerType, parseCompletionRedactionSecrets, parseStrictCompletionPhase, } from "./phase-completion.validation.js";
|
|
5
|
+
// The `forge-bridge mcp` command line: the arguments the Bridge launches its completion-tool server
|
|
6
|
+
// with, and the parsing that server applies to them.
|
|
7
|
+
export function buildCompletionToolServerArgs(config) {
|
|
8
|
+
const args = [
|
|
9
|
+
"mcp",
|
|
10
|
+
"--worktree",
|
|
11
|
+
path.resolve(config.worktreePath),
|
|
12
|
+
"--work-item-id",
|
|
13
|
+
config.workItemId,
|
|
14
|
+
"--phase",
|
|
15
|
+
config.phase,
|
|
16
|
+
"--produced-by",
|
|
17
|
+
config.producedBy ?? "forge-completion-tool"
|
|
18
|
+
];
|
|
19
|
+
if (config.ownerType || config.ownerId) {
|
|
20
|
+
args.push("--owner-type", normalizedOwnerType(config.ownerType) ?? "work_item");
|
|
21
|
+
args.push("--owner-id", config.ownerId ?? config.workItemId);
|
|
22
|
+
}
|
|
23
|
+
if (config.developCycle) {
|
|
24
|
+
args.push("--develop-cycle");
|
|
25
|
+
}
|
|
26
|
+
if (config.qaCycle) {
|
|
27
|
+
args.push("--qa-cycle");
|
|
28
|
+
}
|
|
29
|
+
if (config.debugCycle) {
|
|
30
|
+
args.push("--debug-cycle");
|
|
31
|
+
}
|
|
32
|
+
if (config.architectCycle) {
|
|
33
|
+
args.push("--architect-cycle");
|
|
34
|
+
}
|
|
35
|
+
if (config.draftCycle) {
|
|
36
|
+
args.push("--draft-cycle");
|
|
37
|
+
}
|
|
38
|
+
if (config.decomposeCycle) {
|
|
39
|
+
args.push("--decompose-cycle");
|
|
40
|
+
}
|
|
41
|
+
if (config.managedToolsOnly) {
|
|
42
|
+
args.push("--managed-tools-only");
|
|
43
|
+
}
|
|
44
|
+
return args;
|
|
45
|
+
}
|
|
46
|
+
const completionMcpFlags = {
|
|
47
|
+
"--develop-cycle": "developCycle",
|
|
48
|
+
"--qa-cycle": "qaCycle",
|
|
49
|
+
"--debug-cycle": "debugCycle",
|
|
50
|
+
"--architect-cycle": "architectCycle",
|
|
51
|
+
"--draft-cycle": "draftCycle",
|
|
52
|
+
"--decompose-cycle": "decomposeCycle",
|
|
53
|
+
"--managed-tools-only": "managedToolsOnly",
|
|
54
|
+
};
|
|
55
|
+
const completionMcpValues = {
|
|
56
|
+
"--worktree": "worktreePath",
|
|
57
|
+
"--work-item-id": "workItemId",
|
|
58
|
+
"--owner-id": "ownerId",
|
|
59
|
+
"--produced-by": "producedBy",
|
|
60
|
+
};
|
|
61
|
+
export function parseCompletionMcpArgs(argv) {
|
|
62
|
+
let phase = "implementation";
|
|
63
|
+
let ownerType;
|
|
64
|
+
const values = {};
|
|
65
|
+
const flags = {
|
|
66
|
+
developCycle: false,
|
|
67
|
+
qaCycle: false,
|
|
68
|
+
debugCycle: false,
|
|
69
|
+
architectCycle: false,
|
|
70
|
+
draftCycle: false,
|
|
71
|
+
decomposeCycle: false,
|
|
72
|
+
managedToolsOnly: false,
|
|
73
|
+
};
|
|
74
|
+
for (let index = 1; index < argv.length; index += 1) {
|
|
75
|
+
const arg = argv[index];
|
|
76
|
+
if (Object.hasOwn(completionMcpFlags, arg)) {
|
|
77
|
+
flags[completionMcpFlags[arg]] = true;
|
|
78
|
+
}
|
|
79
|
+
else if (Object.hasOwn(completionMcpValues, arg)) {
|
|
80
|
+
values[completionMcpValues[arg]] = argv[++index];
|
|
81
|
+
}
|
|
82
|
+
else if (arg === "--owner-type") {
|
|
83
|
+
ownerType = normalizedOwnerType(argv[++index]);
|
|
84
|
+
if (!ownerType) {
|
|
85
|
+
return { ok: false, error: "mcp --owner-type must be work_item or story." };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else if (arg === "--phase") {
|
|
89
|
+
const rawPhase = argv[++index];
|
|
90
|
+
const parsedPhase = parseStrictCompletionPhase(rawPhase);
|
|
91
|
+
if (!parsedPhase) {
|
|
92
|
+
return { ok: false, error: "mcp --phase must be one of: implementation, self-review, validation, qa, architect, draft, decompose, ci-repair, comment-repair, debug-repro, debug-root-cause, debug-fix, debug-regression." };
|
|
93
|
+
}
|
|
94
|
+
phase = parsedPhase;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
return { ok: false, error: `Unknown mcp argument: ${arg}` };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const { worktreePath, workItemId, ownerId, producedBy } = values;
|
|
101
|
+
if (!worktreePath?.trim() || !workItemId?.trim()) {
|
|
102
|
+
return { ok: false, error: "mcp requires --worktree and --work-item-id." };
|
|
103
|
+
}
|
|
104
|
+
const { managedToolsOnly, ...cycles } = flags;
|
|
105
|
+
const config = {
|
|
106
|
+
worktreePath: path.resolve(worktreePath),
|
|
107
|
+
workItemId,
|
|
108
|
+
ownerType,
|
|
109
|
+
ownerId,
|
|
110
|
+
phase,
|
|
111
|
+
producedBy,
|
|
112
|
+
redactionSecrets: redactionSecretsFromEnvironment(),
|
|
113
|
+
...cycles,
|
|
114
|
+
...(managedToolsOnly ? { managedToolsOnly } : {})
|
|
115
|
+
};
|
|
116
|
+
const modeError = completionMcpModeError(config);
|
|
117
|
+
return modeError ? { ok: false, error: modeError } : { ok: true, config };
|
|
118
|
+
}
|
|
119
|
+
/** The secrets the server redacts from what it records: the Bridge's list and the attempt database capability. */
|
|
120
|
+
function redactionSecretsFromEnvironment() {
|
|
121
|
+
return [
|
|
122
|
+
...parseCompletionRedactionSecrets(process.env[completionRedactionSecretsEnv]),
|
|
123
|
+
...attemptDatabaseCapabilitySecrets(process.env[attemptDatabaseCapabilityEnvironment]),
|
|
124
|
+
];
|
|
125
|
+
}
|
|
126
|
+
/** Why the parsed cycle mode, phase and tool scope cannot run together, or null when they can. */
|
|
127
|
+
function completionMcpModeError(config) {
|
|
128
|
+
const { phase } = config;
|
|
129
|
+
const cycleModes = [config.developCycle, config.qaCycle, config.debugCycle, config.architectCycle, config.draftCycle, config.decomposeCycle]
|
|
130
|
+
.filter(Boolean).length;
|
|
131
|
+
if (cycleModes > 1) {
|
|
132
|
+
return "mcp accepts only one cycle mode.";
|
|
133
|
+
}
|
|
134
|
+
if (config.managedToolsOnly && cycleModes > 0) {
|
|
135
|
+
return "mcp --managed-tools-only serves no completion tools, so it accepts no cycle mode.";
|
|
136
|
+
}
|
|
137
|
+
if (config.developCycle && !isDevelopCompletionPhase(phase)) {
|
|
138
|
+
return "mcp --develop-cycle requires --phase implementation, self-review, or validation.";
|
|
139
|
+
}
|
|
140
|
+
if (config.qaCycle && phase !== "qa") {
|
|
141
|
+
return "mcp --qa-cycle requires --phase qa.";
|
|
142
|
+
}
|
|
143
|
+
if (config.debugCycle && !isDebugCompletionPhase(phase)) {
|
|
144
|
+
return "mcp --debug-cycle requires --phase debug-repro, debug-root-cause, debug-fix, or debug-regression.";
|
|
145
|
+
}
|
|
146
|
+
if (config.architectCycle && phase !== "architect") {
|
|
147
|
+
return "mcp --architect-cycle requires --phase architect.";
|
|
148
|
+
}
|
|
149
|
+
if (config.draftCycle && phase !== "draft") {
|
|
150
|
+
return "mcp --draft-cycle requires --phase draft.";
|
|
151
|
+
}
|
|
152
|
+
if (config.decomposeCycle && phase !== "decompose") {
|
|
153
|
+
return "mcp --decompose-cycle requires --phase decompose.";
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type CompletionToolCallResult, type CompletionToolRuntime, type CompletionToolRuntimeOptions, type CompletionToolServerConfig } from "./phase-completion.js";
|
|
2
2
|
import { type ManagedAttemptToolResult } from "./managed-attempt-tools.js";
|
|
3
3
|
export declare function prepareCompletionToolRuntime(options: CompletionToolRuntimeOptions): Promise<CompletionToolRuntime>;
|
|
4
|
-
export declare function buildCompletionToolServerArgs(config: CompletionToolServerConfig): readonly string[];
|
|
5
4
|
export declare function codexMcpConfigArgs(runtime: CompletionToolRuntime): readonly string[];
|
|
6
5
|
export declare function cursorMcpServerConfig(runtime: CompletionToolRuntime): unknown;
|
|
7
6
|
export declare function claudeMcpServerConfig(runtime: CompletionToolRuntime): unknown;
|
|
@@ -38,13 +37,6 @@ export declare function completionToolRuntimeEnvironment(runtimeEnvironment?: Re
|
|
|
38
37
|
*/
|
|
39
38
|
export declare function assertManagedQaRegressionEvidence(input: unknown, receipts: readonly Readonly<Record<string, unknown>>[]): void;
|
|
40
39
|
export declare function runCompletionMcpServer(config: CompletionToolServerConfig): Promise<void>;
|
|
41
|
-
export declare function parseCompletionMcpArgs(argv: readonly string[]): {
|
|
42
|
-
readonly ok: true;
|
|
43
|
-
readonly config: CompletionToolServerConfig;
|
|
44
|
-
} | {
|
|
45
|
-
readonly ok: false;
|
|
46
|
-
readonly error: string;
|
|
47
|
-
};
|
|
48
40
|
export declare function completionRedactionEnv(secrets: readonly string[]): Readonly<Record<string, string>>;
|
|
49
41
|
export declare function completionToolRejectedResult(toolName: string, error: unknown, input?: unknown): Readonly<Record<string, unknown>>;
|
|
50
42
|
/** The input schema a completion tool advertises; also the shape its arguments are coerced to. */
|