@loucompanion/forge-bridge 0.1.4-dev.04a1e5b9e484 → 0.1.4-dev.176dfdaf5020
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +145 -4
- package/dist/bridge/bridge-chat-provider-command.d.ts +19 -0
- package/dist/bridge/bridge-chat-provider-command.js +132 -0
- package/dist/bridge/bridge-chat.types.d.ts +10 -0
- package/dist/bridge/bridge-chat.types.js +16 -1
- package/dist/bridge/bridge-state-file.d.ts +161 -0
- package/dist/bridge/bridge-state-file.js +376 -0
- package/dist/bridge/bridge-state-io.d.ts +11 -0
- package/dist/bridge/bridge-state-io.js +50 -0
- package/dist/bridge/bridge-state-lock.d.ts +11 -0
- package/dist/bridge/bridge-state-lock.js +102 -0
- package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
- package/dist/bridge/bridge-state-unpublished.js +111 -0
- package/dist/bridge/bridge.base.d.ts +9 -0
- package/dist/bridge/bridge.service.d.ts +101 -15
- package/dist/bridge/bridge.service.js +472 -345
- package/dist/bridge/bridge.types.d.ts +27 -0
- package/dist/bridge/dispatch-result-outbox.d.ts +11 -1
- package/dist/bridge/dispatch-result-outbox.js +31 -6
- package/dist/bridge/in-flight-registry.d.ts +62 -0
- package/dist/bridge/in-flight-registry.js +207 -0
- package/dist/bridge/local-yield-flag.d.ts +6 -0
- package/dist/bridge/local-yield-flag.js +34 -0
- package/dist/bridge/readiness-result-outbox.d.ts +5 -1
- package/dist/bridge/readiness-result-outbox.js +20 -0
- package/dist/bridge/runner-host-capabilities.d.ts +5 -0
- package/dist/bridge/runner-host-capabilities.js +17 -0
- package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
- package/dist/bridge/sandbox-resource-accounting.js +150 -0
- package/dist/bridge/test-postgres-capability.d.ts +14 -0
- package/dist/bridge/test-postgres-capability.js +120 -0
- package/dist/cleanup/cleanup-wip.d.ts +12 -0
- package/dist/cleanup/cleanup-wip.js +66 -0
- package/dist/cleanup/cleanup.service.d.ts +20 -1
- package/dist/cleanup/cleanup.service.js +150 -169
- package/dist/cleanup/cleanup.types.d.ts +6 -0
- package/dist/cleanup/forge-owned-paths.d.ts +9 -0
- package/dist/cleanup/forge-owned-paths.js +53 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +7 -0
- package/dist/cleanup/host-runtime-ledger.js +130 -0
- package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
- package/dist/cleanup/managed-branch-sweep.js +111 -0
- package/dist/cli/cli.help.js +76 -14
- package/dist/cli/cli.service.d.ts +19 -10
- package/dist/cli/cli.service.js +152 -187
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +6 -0
- package/dist/cli/local-config.js +32 -4
- package/dist/cli/provider-cli-detection.d.ts +10 -0
- package/dist/cli/provider-cli-detection.js +160 -0
- package/dist/runtime/aspnet-runtime-prebuild.d.ts +20 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +184 -18
- package/dist/runtime/attempt-database-broker.d.ts +1 -1
- package/dist/runtime/attempt-node-runtime-launcher.js +9 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +21 -0
- package/dist/runtime/attempt-process-supervisor.js +62 -6
- package/dist/runtime/docker-engine-probe.d.ts +5 -0
- package/dist/runtime/docker-engine-probe.js +7 -0
- package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
- package/dist/runtime/dotnet-build-outputs.js +402 -0
- package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
- package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
- package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
- package/dist/runtime/ephemeral-test-postgres.js +303 -0
- package/dist/runtime/host-database-capability-boundary.d.ts +1 -1
- package/dist/runtime/host-database-capability-boundary.js +1 -0
- package/dist/runtime/host-facts.d.ts +36 -0
- package/dist/runtime/host-facts.js +95 -0
- package/dist/runtime/host-load-admission.d.ts +67 -0
- package/dist/runtime/host-load-admission.js +99 -0
- package/dist/runtime/host-load-child-environment.d.ts +27 -0
- package/dist/runtime/host-load-child-environment.js +76 -0
- package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
- package/dist/runtime/host-load-forge-cgroups.js +140 -0
- package/dist/runtime/host-load-governor-config.d.ts +52 -0
- package/dist/runtime/host-load-governor-config.js +83 -0
- package/dist/runtime/host-load-governor.d.ts +186 -0
- package/dist/runtime/host-load-governor.js +632 -0
- package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
- package/dist/runtime/host-load-ledger-lock.js +187 -0
- package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
- package/dist/runtime/host-load-runtime-settings.js +80 -0
- package/dist/runtime/host-load-sampler.d.ts +156 -0
- package/dist/runtime/host-load-sampler.js +298 -0
- package/dist/runtime/host-load-step-class.d.ts +70 -0
- package/dist/runtime/host-load-step-class.js +161 -0
- package/dist/runtime/host-load-step-reaper.d.ts +27 -0
- package/dist/runtime/host-load-step-reaper.js +95 -0
- package/dist/runtime/host-load-step-run.d.ts +73 -0
- package/dist/runtime/host-load-step-run.js +102 -0
- package/dist/runtime/host-load-test-slot.d.ts +43 -0
- package/dist/runtime/host-load-test-slot.js +81 -0
- package/dist/runtime/host-load-token-ledger.d.ts +200 -0
- package/dist/runtime/host-load-token-ledger.js +453 -0
- package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
- package/dist/runtime/host-load-windows-cpu.js +85 -0
- package/dist/runtime/host-pressure-stall.d.ts +61 -0
- package/dist/runtime/host-pressure-stall.js +168 -0
- package/dist/runtime/host-runtime-contract.d.ts +16 -0
- package/dist/runtime/host-runtime-contract.js +35 -2
- package/dist/runtime/host-runtime-lease.d.ts +77 -5
- package/dist/runtime/host-runtime-lease.js +328 -136
- package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
- package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
- package/dist/runtime/host-runtime-promotion.d.ts +23 -0
- package/dist/runtime/host-runtime-promotion.js +48 -0
- package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
- package/dist/runtime/host-runtime-requirements-check.js +29 -0
- package/dist/runtime/host-runtime-requirements.d.ts +36 -0
- package/dist/runtime/host-runtime-requirements.js +117 -0
- package/dist/runtime/managed-command-teardown.d.ts +62 -0
- package/dist/runtime/managed-command-teardown.js +596 -0
- package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
- package/dist/runtime/native-test-postgres-fallback.js +60 -8
- package/dist/runtime/playwright-browser-cache.d.ts +39 -0
- package/dist/runtime/playwright-browser-cache.js +227 -0
- package/dist/runtime/playwright-host-runtime-adapter.d.ts +18 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +61 -55
- package/dist/runtime/runner-settings.d.ts +104 -0
- package/dist/runtime/runner-settings.js +236 -0
- package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
- package/dist/runtime/supervised-runtime-build-guard.js +112 -0
- package/dist/sandbox/host-capacity-broker.d.ts +115 -0
- package/dist/sandbox/host-capacity-broker.js +336 -0
- package/dist/sandbox/managed-branch.d.ts +13 -0
- package/dist/sandbox/managed-branch.js +90 -0
- package/dist/sandbox/provider-auth/codex.js +11 -11
- package/dist/sandbox/runtime.d.ts +10 -1
- package/dist/sandbox/runtime.js +47 -8
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -0
- package/dist/session/architect-waits.d.ts +2 -0
- package/dist/session/architect-waits.js +138 -0
- package/dist/session/managed-attempt-tools.d.ts +27 -7
- package/dist/session/managed-attempt-tools.js +406 -123
- package/dist/session/managed-build-coordinator.d.ts +17 -1
- package/dist/session/managed-build-coordinator.js +14 -1
- package/dist/session/managed-build-receipt.d.ts +5 -0
- package/dist/session/managed-build-receipt.js +8 -3
- package/dist/session/managed-command-host-load.d.ts +47 -0
- package/dist/session/managed-command-host-load.js +83 -0
- package/dist/session/mcp-argument-coercion.d.ts +23 -0
- package/dist/session/mcp-argument-coercion.js +121 -0
- package/dist/session/phase-completion.artifacts.d.ts +7 -0
- package/dist/session/phase-completion.artifacts.js +100 -26
- package/dist/session/phase-completion.command-validation.d.ts +7 -0
- package/dist/session/phase-completion.command-validation.js +77 -0
- package/dist/session/phase-completion.d.ts +12 -0
- package/dist/session/phase-completion.helpers.js +13 -12
- package/dist/session/phase-completion.js +5 -0
- package/dist/session/phase-completion.mcp-args.d.ts +9 -0
- package/dist/session/phase-completion.mcp-args.js +156 -0
- package/dist/session/phase-completion.prompts.js +6 -1
- package/dist/session/phase-completion.runtime.d.ts +5 -11
- package/dist/session/phase-completion.runtime.js +111 -230
- package/dist/session/phase-completion.schema-parts.d.ts +19 -0
- package/dist/session/phase-completion.schema-parts.js +188 -0
- package/dist/session/phase-completion.schemas.d.ts +3 -3
- package/dist/session/phase-completion.schemas.js +208 -231
- package/dist/session/phase-completion.validation.d.ts +2 -3
- package/dist/session/phase-completion.validation.js +49 -93
- package/dist/session/pre-publication-host-load.d.ts +27 -0
- package/dist/session/pre-publication-host-load.js +111 -0
- package/dist/session/pre-publication-native-postgres.d.ts +30 -0
- package/dist/session/pre-publication-native-postgres.js +111 -0
- package/dist/session/pre-publication-pass.d.ts +61 -0
- package/dist/session/pre-publication-pass.js +148 -0
- package/dist/session/pre-publication-process.d.ts +23 -0
- package/dist/session/pre-publication-process.js +109 -0
- package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
- package/dist/session/pre-publication-skipped-tests.js +109 -0
- package/dist/session/pre-publication-step-execution.d.ts +12 -0
- package/dist/session/pre-publication-step-execution.js +50 -0
- package/dist/session/pre-publication-validation.d.ts +37 -21
- package/dist/session/pre-publication-validation.js +228 -219
- package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
- package/dist/session/provider-cli/claude-background-work.js +181 -0
- package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
- package/dist/session/provider-cli/host-build-lock.js +30 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
- package/dist/session/provider-cli/pre-publication-repair.js +276 -0
- package/dist/session/provider-cli/provider-cli.artifacts.d.ts +2 -1
- package/dist/session/provider-cli/provider-cli.artifacts.js +21 -15
- package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +75 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +46 -31
- package/dist/session/provider-cli/provider-cli.process.js +286 -403
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +87 -32
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +8 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +29 -1
- package/dist/session/provider-cli/provider-cli.service.d.ts +7 -1
- package/dist/session/provider-cli/provider-cli.service.js +207 -192
- package/dist/session/provider-cli/provider-cli.types.d.ts +30 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +10 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +92 -0
- package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
- package/dist/session/provider-cli/provider-output-pipes.js +67 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +8 -0
- package/dist/session/provider-cli/provider-output-state.js +15 -0
- package/dist/session/provider-cli/provider-usage.d.ts +2 -1
- package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
- package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
- package/dist/session/publishable-worktree-changes.d.ts +54 -0
- package/dist/session/publishable-worktree-changes.js +193 -0
- package/dist/session/qa-sidecar-validation.d.ts +6 -0
- package/dist/session/qa-sidecar-validation.js +28 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +51 -0
- package/dist/session/sandbox-host-capacity-gate.js +257 -0
- package/dist/session/session-redaction.js +31 -181
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.service.d.ts +11 -2
- package/dist/session/session.service.js +189 -69
- package/dist/session/session.types.d.ts +3 -0
- package/dist/session/session.types.js +15 -3
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -0
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -0
- package/dist/shared/fs/file-identity.d.ts +10 -0
- package/dist/shared/fs/file-identity.js +15 -0
- package/dist/shared/fs/replace-file.d.ts +7 -0
- package/dist/shared/fs/replace-file.js +33 -0
- package/dist/shared/process/host-process-recovery.d.ts +14 -3
- package/dist/shared/process/host-process-recovery.js +23 -3
- package/dist/shared/process/host-process-supervisor.d.ts +14 -1
- package/dist/shared/process/host-process-supervisor.js +67 -15
- package/dist/shared/process/process-tree.d.ts +52 -0
- package/dist/shared/process/process-tree.js +144 -0
- package/dist/shared/process/process.d.ts +67 -0
- package/dist/shared/process/process.js +213 -11
- package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
- package/dist/shared/process/windows-app-execution-alias.js +45 -0
- package/dist/shared/process/windows-launch.d.ts +18 -0
- package/dist/shared/process/windows-launch.js +68 -0
- package/dist/shared/provider-capabilities.js +14 -7
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/dependency-warmer.d.ts +25 -0
- package/dist/worktree/dependency-warmer.js +120 -10
- package/dist/worktree/orphan-relink.d.ts +19 -0
- package/dist/worktree/orphan-relink.js +106 -0
- package/dist/worktree/wip-git.d.ts +33 -0
- package/dist/worktree/wip-git.js +122 -0
- package/dist/worktree/wip-refs.d.ts +62 -0
- package/dist/worktree/wip-refs.js +119 -0
- package/dist/worktree/wip-restore.d.ts +38 -0
- package/dist/worktree/wip-restore.js +190 -0
- package/dist/worktree/wip-snapshot.d.ts +50 -0
- package/dist/worktree/wip-snapshot.js +268 -0
- package/dist/worktree/worktree-inputs.d.ts +8 -0
- package/dist/worktree/worktree-inputs.js +134 -0
- package/dist/worktree/worktree-origin-sync.d.ts +34 -0
- package/dist/worktree/worktree-origin-sync.js +127 -0
- package/dist/worktree/worktree-wip-events.d.ts +18 -0
- package/dist/worktree/worktree-wip-events.js +98 -0
- package/dist/worktree/worktree-wip.d.ts +50 -0
- package/dist/worktree/worktree-wip.js +185 -0
- package/dist/worktree/worktree.base.d.ts +7 -1
- package/dist/worktree/worktree.service.d.ts +36 -5
- package/dist/worktree/worktree.service.js +124 -155
- package/dist/worktree/worktree.types.d.ts +38 -0
- package/package.json +2 -2
|
@@ -1,5 +1,21 @@
|
|
|
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);
|
|
4
|
-
withBuildSlot<T>(worktreePath: string, action: (queueWaitMs: number) => Promise<T>, onWaiting?: () => Promise<void
|
|
20
|
+
withBuildSlot<T>(worktreePath: string, action: (queueWaitMs: number) => Promise<T>, onWaiting?: () => Promise<void>, signal?: AbortSignal): Promise<T>;
|
|
5
21
|
}
|
|
@@ -3,16 +3,26 @@ 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()) {
|
|
13
23
|
this.stateRoot = stateRoot;
|
|
14
24
|
}
|
|
15
|
-
async withBuildSlot(worktreePath, action, onWaiting) {
|
|
25
|
+
async withBuildSlot(worktreePath, action, onWaiting, signal) {
|
|
16
26
|
const resolved = path.resolve(worktreePath);
|
|
17
27
|
const key = createHash("sha256").update(resolved.toLowerCase()).digest("hex");
|
|
18
28
|
const root = path.join(this.stateRoot, "managed-build-locks");
|
|
@@ -22,6 +32,9 @@ export class ManagedBuildCoordinator {
|
|
|
22
32
|
let waitingReported = false;
|
|
23
33
|
await fs.mkdir(root, { recursive: true, mode: 0o700 });
|
|
24
34
|
while (true) {
|
|
35
|
+
if (signal?.aborted) {
|
|
36
|
+
throw signal.reason instanceof Error ? signal.reason : new Error("managed_build_slot_cancelled: the build-slot wait was cancelled.");
|
|
37
|
+
}
|
|
25
38
|
try {
|
|
26
39
|
const handle = await fs.open(target, "wx", 0o600);
|
|
27
40
|
try {
|
|
@@ -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);
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP clients sometimes send a structured tool argument as its JSON text, for
|
|
3
|
+
* example `sidecars: "[{...}]"` instead of `sidecars: [{...}]`. At the tool-call
|
|
4
|
+
* boundary, before any validation, this replaces such a string with its parsed
|
|
5
|
+
* value, but only where the tool's declared input schema says the value is an
|
|
6
|
+
* array or an object and the string parses to exactly that kind of value.
|
|
7
|
+
*
|
|
8
|
+
* Nothing else is coerced: a string field that happens to contain JSON stays a
|
|
9
|
+
* string, an undeclared field is left alone, and a malformed string is passed
|
|
10
|
+
* through unchanged so the validator reports it.
|
|
11
|
+
*/
|
|
12
|
+
export declare function coerceJsonStringArguments(value: unknown, schema: unknown): unknown;
|
|
13
|
+
type StructuredKind = "array" | "object";
|
|
14
|
+
/**
|
|
15
|
+
* Explains why a value is not the expected array or object, for validator
|
|
16
|
+
* messages. A string gets an explicit instruction because that is the usual
|
|
17
|
+
* client mistake; the hint never echoes the value itself.
|
|
18
|
+
*/
|
|
19
|
+
export declare function structuredTypeHint(value: unknown, expected: StructuredKind): string;
|
|
20
|
+
/** True when a tool call arrived with no usable arguments at all. */
|
|
21
|
+
export declare function isEmptyToolInput(input: unknown): boolean;
|
|
22
|
+
export declare const emptyToolInputHint: string;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP clients sometimes send a structured tool argument as its JSON text, for
|
|
3
|
+
* example `sidecars: "[{...}]"` instead of `sidecars: [{...}]`. At the tool-call
|
|
4
|
+
* boundary, before any validation, this replaces such a string with its parsed
|
|
5
|
+
* value, but only where the tool's declared input schema says the value is an
|
|
6
|
+
* array or an object and the string parses to exactly that kind of value.
|
|
7
|
+
*
|
|
8
|
+
* Nothing else is coerced: a string field that happens to contain JSON stays a
|
|
9
|
+
* string, an undeclared field is left alone, and a malformed string is passed
|
|
10
|
+
* through unchanged so the validator reports it.
|
|
11
|
+
*/
|
|
12
|
+
export function coerceJsonStringArguments(value, schema) {
|
|
13
|
+
const node = schemaNode(schema);
|
|
14
|
+
if (!node)
|
|
15
|
+
return value;
|
|
16
|
+
const expected = structuredKind(node);
|
|
17
|
+
let current = value;
|
|
18
|
+
if (typeof current === "string" && expected) {
|
|
19
|
+
const parsed = parseStructured(current, expected);
|
|
20
|
+
if (parsed !== undefined)
|
|
21
|
+
current = parsed;
|
|
22
|
+
}
|
|
23
|
+
if (Array.isArray(current)) {
|
|
24
|
+
const items = schemaNode(node.items);
|
|
25
|
+
if (!items || !acceptsKind(node, "array"))
|
|
26
|
+
return current;
|
|
27
|
+
let changed = current !== value;
|
|
28
|
+
const next = current.map((entry) => {
|
|
29
|
+
const coerced = coerceJsonStringArguments(entry, items);
|
|
30
|
+
if (coerced !== entry)
|
|
31
|
+
changed = true;
|
|
32
|
+
return coerced;
|
|
33
|
+
});
|
|
34
|
+
return changed ? next : current;
|
|
35
|
+
}
|
|
36
|
+
if (isPlainRecord(current)) {
|
|
37
|
+
const properties = schemaNode(node.properties);
|
|
38
|
+
if (!properties || !acceptsKind(node, "object"))
|
|
39
|
+
return current;
|
|
40
|
+
let next = current !== value ? { ...current } : null;
|
|
41
|
+
for (const [key, propertySchema] of Object.entries(properties)) {
|
|
42
|
+
if (!Object.prototype.hasOwnProperty.call(current, key))
|
|
43
|
+
continue;
|
|
44
|
+
const original = current[key];
|
|
45
|
+
const coerced = coerceJsonStringArguments(original, propertySchema);
|
|
46
|
+
if (coerced !== original) {
|
|
47
|
+
next ??= { ...current };
|
|
48
|
+
next[key] = coerced;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return next ?? current;
|
|
52
|
+
}
|
|
53
|
+
return current;
|
|
54
|
+
}
|
|
55
|
+
function structuredKind(node) {
|
|
56
|
+
const type = node.type;
|
|
57
|
+
if (type === "array" || type === "object")
|
|
58
|
+
return type;
|
|
59
|
+
if (Array.isArray(type)) {
|
|
60
|
+
// A schema that also admits a string must keep the string as sent.
|
|
61
|
+
if (type.includes("string"))
|
|
62
|
+
return null;
|
|
63
|
+
if (type.includes("array") && !type.includes("object"))
|
|
64
|
+
return "array";
|
|
65
|
+
if (type.includes("object") && !type.includes("array"))
|
|
66
|
+
return "object";
|
|
67
|
+
}
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
function acceptsKind(node, kind) {
|
|
71
|
+
const type = node.type;
|
|
72
|
+
if (type === undefined)
|
|
73
|
+
return true;
|
|
74
|
+
return type === kind || (Array.isArray(type) && type.includes(kind));
|
|
75
|
+
}
|
|
76
|
+
function parseStructured(text, expected) {
|
|
77
|
+
const trimmed = text.trim();
|
|
78
|
+
if (!trimmed.startsWith(expected === "array" ? "[" : "{"))
|
|
79
|
+
return undefined;
|
|
80
|
+
try {
|
|
81
|
+
const parsed = JSON.parse(trimmed);
|
|
82
|
+
if (expected === "array" ? Array.isArray(parsed) : isPlainRecord(parsed))
|
|
83
|
+
return parsed;
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
// Leave malformed JSON text in place; the validator reports it with a hint.
|
|
87
|
+
}
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
function schemaNode(value) {
|
|
91
|
+
return isPlainRecord(value) ? value : null;
|
|
92
|
+
}
|
|
93
|
+
function isPlainRecord(value) {
|
|
94
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Explains why a value is not the expected array or object, for validator
|
|
98
|
+
* messages. A string gets an explicit instruction because that is the usual
|
|
99
|
+
* client mistake; the hint never echoes the value itself.
|
|
100
|
+
*/
|
|
101
|
+
export function structuredTypeHint(value, expected) {
|
|
102
|
+
if (value === undefined || value === null) {
|
|
103
|
+
return " (it was omitted)";
|
|
104
|
+
}
|
|
105
|
+
if (typeof value === "string") {
|
|
106
|
+
return expected === "array"
|
|
107
|
+
? " (received a string; pass a JSON array value, not a quoted string)"
|
|
108
|
+
: " (received a string; pass a JSON object value, not a quoted string)";
|
|
109
|
+
}
|
|
110
|
+
if (Array.isArray(value))
|
|
111
|
+
return " (received an array)";
|
|
112
|
+
return typeof value === "object" ? " (received an object)" : ` (received a ${typeof value})`;
|
|
113
|
+
}
|
|
114
|
+
/** True when a tool call arrived with no usable arguments at all. */
|
|
115
|
+
export function isEmptyToolInput(input) {
|
|
116
|
+
return input === undefined
|
|
117
|
+
|| input === null
|
|
118
|
+
|| (isPlainRecord(input) && Object.keys(input).length === 0);
|
|
119
|
+
}
|
|
120
|
+
export const emptyToolInputHint = "No arguments were received: the call arrived as an empty object. "
|
|
121
|
+
+ "If the call was large it was probably cut off before it was sent; resend it with every required field.";
|
|
@@ -2,6 +2,13 @@ import { type CompletionArtifactReference, type CompletionPhase, type Completion
|
|
|
2
2
|
import type { RunnerDispatchArtifact } from "./session.types.js";
|
|
3
3
|
export declare function writeDecomposeGateCompletionArtifact(config: CompletionToolServerConfig, gate: DecomposeCompletionGate, toolName: string, input: unknown): Promise<CompletionArtifactReference>;
|
|
4
4
|
export declare function writeDraftGateCompletionArtifact(config: CompletionToolServerConfig, gate: DraftCompletionGate, toolName: string, input: unknown): Promise<CompletionArtifactReference>;
|
|
5
|
+
/**
|
|
6
|
+
* Judges a Decompose gate call before anything is written and returns its status. The gate's
|
|
7
|
+
* input schema advertises exactly these rules (see the completion tool schema contract test).
|
|
8
|
+
*/
|
|
9
|
+
export declare function validateDecomposeGatePayload(gate: DecomposeCompletionGate, payload: Record<string, unknown>): string;
|
|
10
|
+
/** Judges a Draft gate call before anything is written and returns its status. */
|
|
11
|
+
export declare function validateDraftGatePayload(gate: DraftCompletionGate, payload: Record<string, unknown>): string;
|
|
5
12
|
export declare function writeCompletionArtifact(config: CompletionToolServerConfig, toolName: string, input: unknown): Promise<CompletionArtifactReference>;
|
|
6
13
|
export declare function writeArchitectCompletionArtifact(config: CompletionToolServerConfig, payload: Record<string, unknown>, status: string, producedBy: string): Promise<CompletionArtifactReference>;
|
|
7
14
|
export declare function writeQaGateCompletionArtifact(config: CompletionToolServerConfig, gate: QaCompletionGate, input: unknown): Promise<CompletionArtifactReference>;
|
|
@@ -2,16 +2,15 @@ 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";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
5
|
+
import { assertQaSidecarJsonShape, ensureNoSymbolicLinkPathSegments, isPathUnderRoot, sha256File } from "./qa-sidecar-validation.js";
|
|
6
|
+
import { assertClaimedChangedFilesMatchPublishableDiff } from "./publishable-worktree-changes.js";
|
|
7
|
+
import { coerceJsonStringArguments } from "./mcp-argument-coercion.js";
|
|
8
|
+
import { toolInputSchema } from "./phase-completion.schemas.js";
|
|
9
|
+
import { artifactRootFor, artifactRootForOwner, completionArtifactJsonPath, completionArtifactReportPath, decomposeGateFileNames, draftGateFileNames, phaseFiles, qaGateFileNames, decomposeStatuses, draftStatuses } from "./phase-completion.js";
|
|
10
|
+
import { artifactOwnerFields, artifactReferenceOwnerFields, artifactOwnerRelativeRoot, defaultQaChecklist, fallbackReport, isNodeError, jsonText, normalizeArtifactPayload, normalizeCompletionStatus, normalizeQaGateArtifactPayload, normalizeQaGateStatus, normalizedString, optionalString, numberOrDefault, parseJsonObject, parseOptionalJsonObject, phaseFromToolName, qaArray, qaArtifactRelativePath, qaArtifactRelativePathForOwner, qaEvidenceSource, qaObjectArray, qaPolicyWarnings, qaEvidenceGates, qaStringArray, readOptionalFile, reportMarkdown, requireField, requiredRecord, requiredString, qaGateFromToolName, sha256, stableStringify, validateOptionalWorkItemId, validatePayloadShape, validateQaGatePayloadShape, validateQaScopeRecord, writeFileAtomic, asRecord } from "./phase-completion.validation.js";
|
|
8
11
|
export async function writeDecomposeGateCompletionArtifact(config, gate, toolName, input) {
|
|
9
12
|
const payload = asRecord(input, "Decompose completion payload");
|
|
10
|
-
const status =
|
|
11
|
-
if (gate === "decompose_proposal") {
|
|
12
|
-
const proposalJson = asRecord(payload["proposal_json"] ?? payload["decomposition_json"], "proposal_json");
|
|
13
|
-
validateDecomposeProposalJson(proposalJson);
|
|
14
|
-
}
|
|
13
|
+
const status = validateDecomposeGatePayload(gate, payload);
|
|
15
14
|
const redactedPayload = redactSecrets({ ...payload, status, phase: "decompose", gate, tool_name: toolName }, config.redactionSecrets ?? []);
|
|
16
15
|
assertStructuralFieldsUnchanged(payload, redactedPayload);
|
|
17
16
|
if (gate === "decompose_proposal") {
|
|
@@ -44,11 +43,7 @@ ${optionalString(redactedPayload, "summary") ?? "Decompose gate recorded."}
|
|
|
44
43
|
}
|
|
45
44
|
export async function writeDraftGateCompletionArtifact(config, gate, toolName, input) {
|
|
46
45
|
const payload = asRecord(input, "Draft completion payload");
|
|
47
|
-
const status =
|
|
48
|
-
if (gate === "draft_proposal") {
|
|
49
|
-
const draftJson = asRecord(payload["draft_json"], "draft_json");
|
|
50
|
-
validateDraftProposalJson(draftJson);
|
|
51
|
-
}
|
|
46
|
+
const status = validateDraftGatePayload(gate, payload);
|
|
52
47
|
const redactedPayload = redactSecrets({ ...payload, status, phase: "draft", gate, tool_name: toolName }, config.redactionSecrets ?? []);
|
|
53
48
|
assertStructuralFieldsUnchanged(payload, redactedPayload);
|
|
54
49
|
if (gate === "draft_proposal") {
|
|
@@ -76,9 +71,48 @@ export async function writeDraftGateCompletionArtifact(config, gate, toolName, i
|
|
|
76
71
|
producedBy: config.producedBy ?? "forge-completion-tool"
|
|
77
72
|
};
|
|
78
73
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Judges a Decompose gate call before anything is written and returns its status. The gate's
|
|
76
|
+
* input schema advertises exactly these rules (see the completion tool schema contract test).
|
|
77
|
+
*/
|
|
78
|
+
export function validateDecomposeGatePayload(gate, payload) {
|
|
79
|
+
const status = gateStatus(payload, decomposeStatuses);
|
|
80
|
+
if (gate === "decompose_proposal") {
|
|
81
|
+
validateDecomposeProposalJson(asRecord(payload["proposal_json"] ?? payload["decomposition_json"], "proposal_json"));
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
// An earlier Decompose gate's evidence is its summary, and a missing status means pass, so an
|
|
85
|
+
// empty call would otherwise record a pass and move to the next gate.
|
|
86
|
+
requireField(payload, "summary");
|
|
87
|
+
}
|
|
88
|
+
return status;
|
|
89
|
+
}
|
|
90
|
+
/** Judges a Draft gate call before anything is written and returns its status. */
|
|
91
|
+
export function validateDraftGatePayload(gate, payload) {
|
|
92
|
+
const status = gateStatus(payload, draftStatuses);
|
|
93
|
+
if (gate === "draft_proposal") {
|
|
94
|
+
validateDraftProposalJson(asRecord(payload["draft_json"], "draft_json"));
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
// An earlier Draft gate's only evidence is its summary, and a missing status means pass, so an
|
|
98
|
+
// empty call would otherwise record a pass and move to the next gate.
|
|
99
|
+
requireField(payload, "summary");
|
|
100
|
+
}
|
|
101
|
+
return status;
|
|
102
|
+
}
|
|
103
|
+
// Only an omitted status defaults to pass. A status that is present must be one of the advertised
|
|
104
|
+
// values: a typo such as "pas", a blank string or a non-string is rejected rather than advancing
|
|
105
|
+
// the gate as a pass.
|
|
106
|
+
function gateStatus(payload, allowed) {
|
|
107
|
+
const value = payload["status"];
|
|
108
|
+
if (value === undefined || value === null) {
|
|
109
|
+
return "pass";
|
|
110
|
+
}
|
|
111
|
+
const normalized = typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
112
|
+
if (!allowed.includes(normalized)) {
|
|
113
|
+
throw new Error(`status must be one of ${allowed.join(", ")}; received ${typeof value === "string" ? `'${value}'` : JSON.stringify(value)}.`);
|
|
114
|
+
}
|
|
115
|
+
return normalized;
|
|
82
116
|
}
|
|
83
117
|
function validateDraftProposalJson(draftJson) {
|
|
84
118
|
if (draftJson.suggested_qa_scope !== undefined && draftJson.suggested_qa_scope !== null) {
|
|
@@ -158,6 +192,9 @@ export async function writeCompletionArtifact(config, toolName, input) {
|
|
|
158
192
|
}
|
|
159
193
|
validatePayloadShape(phase, validationPayload);
|
|
160
194
|
validateOptionalWorkItemId(validationPayload, config.workItemId);
|
|
195
|
+
if (phase === "comment_repair" && status === "pass") {
|
|
196
|
+
await assertClaimedChangedFilesMatchPublishableDiff(config.worktreePath, validationPayload, toolName);
|
|
197
|
+
}
|
|
161
198
|
const redactedPayload = redactSecrets(validationPayload, config.redactionSecrets ?? []);
|
|
162
199
|
assertStructuralFieldsUnchanged(validationPayload, redactedPayload);
|
|
163
200
|
validatePostRedaction(() => {
|
|
@@ -216,8 +253,10 @@ export async function writeArchitectCompletionArtifact(config, payload, status,
|
|
|
216
253
|
const qaPlanPath = path.join(artifactRoot, "qa.plan.json");
|
|
217
254
|
const verdictPath = path.join(artifactRoot, "architect.verdict.json");
|
|
218
255
|
const reportPath = path.join(artifactRoot, "architect.report.md");
|
|
219
|
-
|
|
220
|
-
|
|
256
|
+
// A needs_revision or blocked verdict has no plan to approve; its schema lets
|
|
257
|
+
// the agent omit both plans, and the bundle still carries a file for each.
|
|
258
|
+
const implementationPlan = architectPlanRecord(payload, "implementation_plan", status);
|
|
259
|
+
const qaPlan = architectPlanRecord(payload, "qa_plan", status);
|
|
221
260
|
const report = optionalString(payload, "report") ?? optionalString(payload, "report_markdown") ?? reportMarkdown(payload, "architect", status, producedBy, "pending");
|
|
222
261
|
const artifactWithoutHash = normalizeArtifactPayload(payload, {
|
|
223
262
|
phase: "architect",
|
|
@@ -250,13 +289,21 @@ export async function writeArchitectCompletionArtifact(config, payload, status,
|
|
|
250
289
|
producedBy
|
|
251
290
|
};
|
|
252
291
|
}
|
|
292
|
+
function architectPlanRecord(payload, key, status) {
|
|
293
|
+
if (status !== "pass" && (payload[key] === undefined || payload[key] === null)) {
|
|
294
|
+
return {};
|
|
295
|
+
}
|
|
296
|
+
return requiredRecord(payload, key);
|
|
297
|
+
}
|
|
253
298
|
export async function writeQaGateCompletionArtifact(config, gate, input) {
|
|
254
299
|
const payload = asRecord(input, "QA gate completion payload");
|
|
255
300
|
const status = normalizeQaGateStatus(requiredString(payload, "status"));
|
|
256
301
|
validateQaGatePayloadShape(gate, payload, status);
|
|
257
302
|
validateOptionalWorkItemId(payload, config.workItemId);
|
|
258
303
|
const ownerFields = artifactOwnerFields(config);
|
|
259
|
-
|
|
304
|
+
// Every evidence gate's sidecars are merged into the final verdict, which checks each file,
|
|
305
|
+
// so each gate checks its references (exists, under qa/, size and hash match) when it is called.
|
|
306
|
+
const validatedSidecars = qaEvidenceGates.has(gate)
|
|
260
307
|
? await validateQaSidecarReferences(config.worktreePath, config.workItemId, qaArray(payload, "sidecars", qaEvidenceSource(payload)), ownerFields.owner_type, ownerFields.owner_id)
|
|
261
308
|
: null;
|
|
262
309
|
const redactedPayload = redactSecrets({
|
|
@@ -269,7 +316,7 @@ export async function writeQaGateCompletionArtifact(config, gate, input) {
|
|
|
269
316
|
validateQaGatePayloadShape(gate, redactedPayload, status);
|
|
270
317
|
validateOptionalWorkItemId(redactedPayload, config.workItemId);
|
|
271
318
|
});
|
|
272
|
-
if (gate
|
|
319
|
+
if (qaEvidenceGates.has(gate)) {
|
|
273
320
|
await validateQaSidecarReferences(config.worktreePath, config.workItemId, qaArray(redactedPayload, "sidecars", qaEvidenceSource(redactedPayload)), ownerFields.owner_type, ownerFields.owner_id).catch((error) => {
|
|
274
321
|
throw postRedactionValidationError(error);
|
|
275
322
|
});
|
|
@@ -425,12 +472,12 @@ export async function writeQaCompletionArtifact(config, payload, status, produce
|
|
|
425
472
|
};
|
|
426
473
|
}
|
|
427
474
|
async function synthesizeQaCycleVerdictPayload(config, payload, status) {
|
|
428
|
-
const qaPlan = await
|
|
429
|
-
const qaRegression = await
|
|
430
|
-
const qaApi = await
|
|
431
|
-
const qaManualWeb = await
|
|
432
|
-
const qaBugRepro = await
|
|
433
|
-
const qaFindings = await
|
|
475
|
+
const qaPlan = await readInheritedQaGateArtifact(config, "qa_plan");
|
|
476
|
+
const qaRegression = await readInheritedQaGateArtifact(config, "qa_regression");
|
|
477
|
+
const qaApi = await readInheritedQaGateArtifact(config, "qa_api");
|
|
478
|
+
const qaManualWeb = await readInheritedQaGateArtifact(config, "qa_manual_web");
|
|
479
|
+
const qaBugRepro = await readInheritedQaGateArtifact(config, "qa_bug_repro");
|
|
480
|
+
const qaFindings = await readInheritedQaGateArtifact(config, "qa_findings");
|
|
434
481
|
const evidenceGates = [qaRegression, qaApi, qaManualWeb, qaBugRepro];
|
|
435
482
|
const payloadEvidence = qaEvidenceSource(payload);
|
|
436
483
|
const merged = { ...payload };
|
|
@@ -478,6 +525,32 @@ async function synthesizeQaCycleVerdictPayload(config, payload, status) {
|
|
|
478
525
|
merged.candidate_bugs = mergeQaObjectArraysById(qaObjectArray(payload, "candidate_bugs"), qaObjectArray(qaFindings, "candidate_bugs"));
|
|
479
526
|
return merged;
|
|
480
527
|
}
|
|
528
|
+
/**
|
|
529
|
+
* Reads an earlier gate's artifact for the verdict merge. Gates recorded before
|
|
530
|
+
* argument coercion existed may hold a JSON-string array, so the same schema
|
|
531
|
+
* coercion is applied here, and any remaining shape error names the gate file
|
|
532
|
+
* instead of looking like a fault in the verdict payload.
|
|
533
|
+
*/
|
|
534
|
+
async function readInheritedQaGateArtifact(config, gate) {
|
|
535
|
+
const artifact = coerceJsonStringArguments(await readQaGateArtifact(config, gate), toolInputSchema("qa", gate));
|
|
536
|
+
// Gates accept sidecars inside the evidence wrapper too; promote them so the verdict inherits
|
|
537
|
+
// them. A top-level value still takes precedence.
|
|
538
|
+
if (artifact.sidecars === undefined || artifact.sidecars === null) {
|
|
539
|
+
const nestedSidecars = qaEvidenceSource(artifact).sidecars;
|
|
540
|
+
if (nestedSidecars !== undefined && nestedSidecars !== null) {
|
|
541
|
+
artifact.sidecars = nestedSidecars;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
for (const key of ["commands", "browser_checks", "sidecars", "checklist", "acceptance_criteria", "findings", "candidate_bugs"]) {
|
|
545
|
+
try {
|
|
546
|
+
qaArray(artifact, key);
|
|
547
|
+
}
|
|
548
|
+
catch (error) {
|
|
549
|
+
throw new Error(`${qaGateFileNames[gate]} recorded by ${gate} has an invalid ${key}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
return artifact;
|
|
553
|
+
}
|
|
481
554
|
export async function readQaGateArtifact(config, gate) {
|
|
482
555
|
const ownerFields = artifactOwnerFields(config);
|
|
483
556
|
const artifactRoot = ownerFields.owner_type && ownerFields.owner_id
|
|
@@ -617,6 +690,7 @@ async function validateQaSidecarReferences(worktreePath, workItemId, sidecars, o
|
|
|
617
690
|
if (actualHash !== normalizeSha256ContentHash(contentHash)) {
|
|
618
691
|
throw new Error(`sidecars[${index}].content_hash does not match the referenced file.`);
|
|
619
692
|
}
|
|
693
|
+
await assertQaSidecarJsonShape(fullPath, sidecarPath, `sidecars[${index}]`);
|
|
620
694
|
const canonicalPath = path.relative(worktreePath, fullPath).split(path.sep).join("/");
|
|
621
695
|
const duplicateKey = canonicalPath.toLowerCase();
|
|
622
696
|
const existing = validatedByPath.get(duplicateKey);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function validateQaGatePassingCommands(commands: readonly unknown[], options?: {
|
|
2
|
+
readonly allowClassifiedNonBlockingFailures?: boolean;
|
|
3
|
+
/** Payload field that holds these command records, for error messages. */
|
|
4
|
+
readonly label?: string;
|
|
5
|
+
/** Why a passing result is required, for error messages. */
|
|
6
|
+
readonly context?: string;
|
|
7
|
+
}): void;
|