@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
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { attemptDatabaseCapabilityEnvironment, attemptDatabaseCapabilitySecrets, } from "../runtime/attempt-database-broker.js";
|
|
5
4
|
import { completionPhaseFromDispatch, completionPhaseOrder, completionRedactionSecretsEnv, completionToolNamesForDebugGate, completionToolNamesForDecomposeGate, completionToolNamesForDraftGate, completionToolNamesForPhase, completionToolNamesForQaGate, debugCompletionPhaseOrder, decomposeCompletionGateOrder, draftCompletionGateOrder, qaCompletionGateOrder, toolServerName, usesArchitectCycleCompletion, usesDebugCycleCompletion, usesDevelopCycleCompletion, usesQaCycleCompletion } from "./phase-completion.js";
|
|
6
|
-
import { CompletionPayloadValidationError, asDebugCompletionPhase, asJsonRpcMessage, asMutableRecord, asRecord, artifactOwnerRelativeRoot, decomposeGateFromToolName, draftGateFromToolName, errorMessage, forgeBridgeCliBinPath, isDebugCompletionPhase, isDecomposeDispatch,
|
|
5
|
+
import { CompletionPayloadValidationError, asDebugCompletionPhase, asJsonRpcMessage, asMutableRecord, asRecord, artifactOwnerRelativeRoot, decomposeGateFromToolName, draftGateFromToolName, errorMessage, forgeBridgeCliBinPath, isDebugCompletionPhase, isDecomposeDispatch, normalizedOwnerType, phaseFromToolName, qaGateFromToolName, requiredString, rpcError, tomlString, tomlStringArray, writeJsonRpc } from "./phase-completion.validation.js";
|
|
7
6
|
import { completionPromptForDebugCycle, completionPromptForDecomposeCycle, completionPromptForDevelopCycle, completionPromptForDraftCycle, completionPromptForPhase, completionPromptForQaCycle, completionToolNextInstruction, completionToolNextInstructionForDebugGate, completionToolNextInstructionForDecomposeGate, completionToolNextInstructionForDraftGate, completionToolNextInstructionForQaGate, nextDebugPhaseAfter, nextPhaseAfter } from "./phase-completion.prompts.js";
|
|
8
7
|
import { configuredNativeTestPostgresFallbackPath, nativeTestPostgresFallbackConfigEnvironment, } from "../runtime/native-test-postgres-fallback.js";
|
|
9
8
|
import { isHostLoadChildEnvironmentName } from "../runtime/host-load-child-environment.js";
|
|
9
|
+
import { isProviderUserConfigIsolated, providerUserConfigIsolationUnsupported } from "./provider-cli/provider-user-config-isolation.js";
|
|
10
10
|
import { toolDescription, toolInputSchema } from "./phase-completion.schemas.js";
|
|
11
11
|
import { coerceJsonStringArguments, emptyToolInputHint, isEmptyToolInput } from "./mcp-argument-coercion.js";
|
|
12
12
|
import { writeCompletionArtifact, writeDecomposeGateCompletionArtifact, writeDraftGateCompletionArtifact } from "./phase-completion.artifacts.js";
|
|
13
|
+
import { buildCompletionToolServerArgs } from "./phase-completion.mcp-args.js";
|
|
13
14
|
import { callManagedAttemptTool, isManagedAttemptTool, managedAttemptToolDefinition, managedAttemptToolInputSchema, managedAttemptToolNames, runWithOwnerShutdown, } from "./managed-attempt-tools.js";
|
|
14
15
|
export async function prepareCompletionToolRuntime(options) {
|
|
15
16
|
const phase = options.phase ?? completionPhaseFromDispatch(options.dispatch);
|
|
@@ -17,6 +18,8 @@ export async function prepareCompletionToolRuntime(options) {
|
|
|
17
18
|
const workItemId = options.dispatch.workItem.id;
|
|
18
19
|
const ownerType = normalizedOwnerType(options.dispatch.cycleRun.ownerType) ?? "work_item";
|
|
19
20
|
const ownerId = options.dispatch.cycleRun.ownerId ?? workItemId;
|
|
21
|
+
// A managed-tools-only server records no completion artifact, so it takes no cycle mode.
|
|
22
|
+
const cycles = !options.managedToolsOnly;
|
|
20
23
|
const mcpArgs = buildCompletionToolServerArgs({
|
|
21
24
|
worktreePath,
|
|
22
25
|
workItemId,
|
|
@@ -24,15 +27,17 @@ export async function prepareCompletionToolRuntime(options) {
|
|
|
24
27
|
ownerId,
|
|
25
28
|
phase,
|
|
26
29
|
producedBy: `${options.dispatch.execution.provider}-cli`,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
managedToolsOnly: options.managedToolsOnly,
|
|
31
|
+
developCycle: cycles && usesDevelopCycleCompletion(options.dispatch),
|
|
32
|
+
qaCycle: cycles && usesQaCycleCompletion(options.dispatch),
|
|
33
|
+
debugCycle: cycles && usesDebugCycleCompletion(options.dispatch),
|
|
34
|
+
architectCycle: cycles && usesArchitectCycleCompletion(options.dispatch),
|
|
35
|
+
draftCycle: cycles
|
|
36
|
+
&& (phase === "draft"
|
|
37
|
+
|| options.dispatch.execution.lane.trim().toLowerCase() === "draft"
|
|
38
|
+
|| options.dispatch.cycleRun.kind.trim().toLowerCase() === "draft")
|
|
34
39
|
&& !isDecomposeDispatch(options.dispatch),
|
|
35
|
-
decomposeCycle: isDecomposeDispatch(options.dispatch)
|
|
40
|
+
decomposeCycle: cycles && isDecomposeDispatch(options.dispatch)
|
|
36
41
|
});
|
|
37
42
|
const runtime = {
|
|
38
43
|
serverName: toolServerName,
|
|
@@ -42,50 +47,16 @@ export async function prepareCompletionToolRuntime(options) {
|
|
|
42
47
|
cleanup: async () => undefined
|
|
43
48
|
};
|
|
44
49
|
const provider = options.dispatch.execution.provider.trim().toLowerCase();
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
// Provider phases refuse these at entry (admitUserConfigIsolatedProvider, provider-cli.runtime.ts);
|
|
51
|
+
// this guards any other caller before the Claude MCP config is written.
|
|
52
|
+
if (!isProviderUserConfigIsolated(provider)) {
|
|
53
|
+
throw providerUserConfigIsolationUnsupported(options.dispatch.execution.provider);
|
|
47
54
|
}
|
|
48
55
|
if (provider === "claude") {
|
|
49
56
|
return await prepareClaudeCompletionToolRuntime(runtime);
|
|
50
57
|
}
|
|
51
58
|
return runtime;
|
|
52
59
|
}
|
|
53
|
-
export function buildCompletionToolServerArgs(config) {
|
|
54
|
-
const args = [
|
|
55
|
-
"mcp",
|
|
56
|
-
"--worktree",
|
|
57
|
-
path.resolve(config.worktreePath),
|
|
58
|
-
"--work-item-id",
|
|
59
|
-
config.workItemId,
|
|
60
|
-
"--phase",
|
|
61
|
-
config.phase,
|
|
62
|
-
"--produced-by",
|
|
63
|
-
config.producedBy ?? "forge-completion-tool"
|
|
64
|
-
];
|
|
65
|
-
if (config.ownerType || config.ownerId) {
|
|
66
|
-
args.push("--owner-type", normalizedOwnerType(config.ownerType) ?? "work_item");
|
|
67
|
-
args.push("--owner-id", config.ownerId ?? config.workItemId);
|
|
68
|
-
}
|
|
69
|
-
if (config.developCycle) {
|
|
70
|
-
args.push("--develop-cycle");
|
|
71
|
-
}
|
|
72
|
-
if (config.qaCycle) {
|
|
73
|
-
args.push("--qa-cycle");
|
|
74
|
-
}
|
|
75
|
-
if (config.debugCycle) {
|
|
76
|
-
args.push("--debug-cycle");
|
|
77
|
-
}
|
|
78
|
-
if (config.architectCycle) {
|
|
79
|
-
args.push("--architect-cycle");
|
|
80
|
-
}
|
|
81
|
-
if (config.draftCycle) {
|
|
82
|
-
args.push("--draft-cycle");
|
|
83
|
-
}
|
|
84
|
-
if (config.decomposeCycle) {
|
|
85
|
-
args.push("--decompose-cycle");
|
|
86
|
-
}
|
|
87
|
-
return args;
|
|
88
|
-
}
|
|
89
60
|
export function codexMcpConfigArgs(runtime) {
|
|
90
61
|
const prefix = `mcp_servers.${runtime.serverName}`;
|
|
91
62
|
const args = [
|
|
@@ -133,6 +104,10 @@ export function completionToolNamesForServer(config) {
|
|
|
133
104
|
? completionToolNamesForPhase("architect")
|
|
134
105
|
: completionToolNamesForPhase(config.phase);
|
|
135
106
|
}
|
|
107
|
+
const managedToolsOnlyInstructions = "Forge serves only its managed-attempt tools in this turn: "
|
|
108
|
+
+ "forge.start_managed_verification, forge.start_managed_command, forge.wait_managed_command, forge.get_managed_command, "
|
|
109
|
+
+ "forge.run_managed_command and forge.reset_generated_outputs. No completion tool is available; the phase's completion "
|
|
110
|
+
+ "artifacts are already recorded and must stay as they are.";
|
|
136
111
|
export class CompletionToolServerSession {
|
|
137
112
|
config;
|
|
138
113
|
currentPhase;
|
|
@@ -146,20 +121,24 @@ export class CompletionToolServerSession {
|
|
|
146
121
|
this.currentPhase = config.phase;
|
|
147
122
|
}
|
|
148
123
|
get instructions() {
|
|
149
|
-
return this.config.
|
|
150
|
-
?
|
|
151
|
-
: this.config.
|
|
152
|
-
?
|
|
153
|
-
: this.config.
|
|
154
|
-
?
|
|
155
|
-
: this.config.
|
|
156
|
-
?
|
|
157
|
-
: this.config.
|
|
158
|
-
?
|
|
159
|
-
:
|
|
124
|
+
return this.config.managedToolsOnly
|
|
125
|
+
? managedToolsOnlyInstructions
|
|
126
|
+
: this.config.decomposeCycle
|
|
127
|
+
? completionPromptForDecomposeCycle(this.currentDecomposeGate)
|
|
128
|
+
: this.config.draftCycle
|
|
129
|
+
? completionPromptForDraftCycle(this.currentDraftGate)
|
|
130
|
+
: this.config.debugCycle
|
|
131
|
+
? completionPromptForDebugCycle(asDebugCompletionPhase(this.currentPhase))
|
|
132
|
+
: this.config.qaCycle
|
|
133
|
+
? completionPromptForQaCycle(this.currentQaGate, artifactOwnerRelativeRoot(this.config.ownerType, this.config.ownerId, this.config.workItemId))
|
|
134
|
+
: this.config.developCycle
|
|
135
|
+
? completionPromptForDevelopCycle(this.currentPhase)
|
|
136
|
+
: completionPromptForPhase(this.currentPhase, artifactOwnerRelativeRoot(this.config.ownerType, this.config.ownerId, this.config.workItemId));
|
|
160
137
|
}
|
|
161
138
|
toolDefinitions() {
|
|
162
|
-
const completionTools =
|
|
139
|
+
const completionTools = this.config.managedToolsOnly
|
|
140
|
+
? []
|
|
141
|
+
: completionToolNamesForServer(this.config).map(toolDefinition);
|
|
163
142
|
return managedAttemptToolsAvailable()
|
|
164
143
|
? [...completionTools, ...managedAttemptToolNames.map(managedAttemptToolDefinition)]
|
|
165
144
|
: completionTools;
|
|
@@ -176,6 +155,9 @@ export class CompletionToolServerSession {
|
|
|
176
155
|
}
|
|
177
156
|
return result;
|
|
178
157
|
}
|
|
158
|
+
if (this.config.managedToolsOnly) {
|
|
159
|
+
throw new Error(`${toolName} is not available in this turn: Forge serves only its managed-attempt tools during a pre-publication repair turn, and the phase's completion artifacts are already recorded. Fix the failing checks and stop; Bridge reruns validation.`);
|
|
160
|
+
}
|
|
179
161
|
const requestedPhase = phaseFromToolName(toolName);
|
|
180
162
|
// Clients sometimes send a declared array/object argument as its JSON text.
|
|
181
163
|
const input = coerceJsonStringArguments(rawInput, completionToolInputSchema(toolName));
|
|
@@ -491,7 +473,7 @@ export function completionToolRuntimeEnvironment(runtimeEnvironment, nativeTestP
|
|
|
491
473
|
env[name] = value.trim();
|
|
492
474
|
}
|
|
493
475
|
// Managed verification reads the operator's native test cluster only through
|
|
494
|
-
// this explicit path
|
|
476
|
+
// this explicit path; the file's `use` decides whether Docker comes first.
|
|
495
477
|
if (runtimeEnvironment && nativeTestPostgresFallbackPath) {
|
|
496
478
|
env[nativeTestPostgresFallbackConfigEnvironment] = nativeTestPostgresFallbackPath;
|
|
497
479
|
}
|
|
@@ -599,148 +581,12 @@ export async function runCompletionMcpServer(config) {
|
|
|
599
581
|
}
|
|
600
582
|
});
|
|
601
583
|
}
|
|
602
|
-
export function parseCompletionMcpArgs(argv) {
|
|
603
|
-
let worktreePath = null;
|
|
604
|
-
let workItemId = null;
|
|
605
|
-
let phase = "implementation";
|
|
606
|
-
let ownerType;
|
|
607
|
-
let ownerId;
|
|
608
|
-
let producedBy;
|
|
609
|
-
let developCycle = false;
|
|
610
|
-
let qaCycle = false;
|
|
611
|
-
let debugCycle = false;
|
|
612
|
-
let architectCycle = false;
|
|
613
|
-
let draftCycle = false;
|
|
614
|
-
let decomposeCycle = false;
|
|
615
|
-
for (let index = 1; index < argv.length; index += 1) {
|
|
616
|
-
const arg = argv[index];
|
|
617
|
-
if (arg === "--worktree") {
|
|
618
|
-
worktreePath = argv[++index] ?? null;
|
|
619
|
-
}
|
|
620
|
-
else if (arg === "--work-item-id") {
|
|
621
|
-
workItemId = argv[++index] ?? null;
|
|
622
|
-
}
|
|
623
|
-
else if (arg === "--owner-type") {
|
|
624
|
-
ownerType = normalizedOwnerType(argv[++index]);
|
|
625
|
-
if (!ownerType) {
|
|
626
|
-
return { ok: false, error: "mcp --owner-type must be work_item or story." };
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
else if (arg === "--owner-id") {
|
|
630
|
-
ownerId = argv[++index] ?? undefined;
|
|
631
|
-
}
|
|
632
|
-
else if (arg === "--phase") {
|
|
633
|
-
const rawPhase = argv[++index];
|
|
634
|
-
const parsedPhase = parseStrictCompletionPhase(rawPhase);
|
|
635
|
-
if (!parsedPhase) {
|
|
636
|
-
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." };
|
|
637
|
-
}
|
|
638
|
-
phase = parsedPhase;
|
|
639
|
-
}
|
|
640
|
-
else if (arg === "--produced-by") {
|
|
641
|
-
producedBy = argv[++index] ?? undefined;
|
|
642
|
-
}
|
|
643
|
-
else if (arg === "--develop-cycle") {
|
|
644
|
-
developCycle = true;
|
|
645
|
-
}
|
|
646
|
-
else if (arg === "--qa-cycle") {
|
|
647
|
-
qaCycle = true;
|
|
648
|
-
}
|
|
649
|
-
else if (arg === "--debug-cycle") {
|
|
650
|
-
debugCycle = true;
|
|
651
|
-
}
|
|
652
|
-
else if (arg === "--architect-cycle") {
|
|
653
|
-
architectCycle = true;
|
|
654
|
-
}
|
|
655
|
-
else if (arg === "--draft-cycle") {
|
|
656
|
-
draftCycle = true;
|
|
657
|
-
}
|
|
658
|
-
else if (arg === "--decompose-cycle") {
|
|
659
|
-
decomposeCycle = true;
|
|
660
|
-
}
|
|
661
|
-
else {
|
|
662
|
-
return { ok: false, error: `Unknown mcp argument: ${arg}` };
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
if (!worktreePath?.trim() || !workItemId?.trim()) {
|
|
666
|
-
return { ok: false, error: "mcp requires --worktree and --work-item-id." };
|
|
667
|
-
}
|
|
668
|
-
if ([developCycle, qaCycle, debugCycle, architectCycle, draftCycle, decomposeCycle].filter(Boolean).length > 1) {
|
|
669
|
-
return { ok: false, error: "mcp accepts only one cycle mode." };
|
|
670
|
-
}
|
|
671
|
-
if (developCycle && !isDevelopCompletionPhase(phase)) {
|
|
672
|
-
return { ok: false, error: "mcp --develop-cycle requires --phase implementation, self-review, or validation." };
|
|
673
|
-
}
|
|
674
|
-
if (qaCycle && phase !== "qa") {
|
|
675
|
-
return { ok: false, error: "mcp --qa-cycle requires --phase qa." };
|
|
676
|
-
}
|
|
677
|
-
if (debugCycle && !isDebugCompletionPhase(phase)) {
|
|
678
|
-
return { ok: false, error: "mcp --debug-cycle requires --phase debug-repro, debug-root-cause, debug-fix, or debug-regression." };
|
|
679
|
-
}
|
|
680
|
-
if (architectCycle && phase !== "architect") {
|
|
681
|
-
return { ok: false, error: "mcp --architect-cycle requires --phase architect." };
|
|
682
|
-
}
|
|
683
|
-
if (draftCycle && phase !== "draft") {
|
|
684
|
-
return { ok: false, error: "mcp --draft-cycle requires --phase draft." };
|
|
685
|
-
}
|
|
686
|
-
if (decomposeCycle && phase !== "decompose") {
|
|
687
|
-
return { ok: false, error: "mcp --decompose-cycle requires --phase decompose." };
|
|
688
|
-
}
|
|
689
|
-
return {
|
|
690
|
-
ok: true,
|
|
691
|
-
config: {
|
|
692
|
-
worktreePath: path.resolve(worktreePath),
|
|
693
|
-
workItemId,
|
|
694
|
-
ownerType,
|
|
695
|
-
ownerId,
|
|
696
|
-
phase,
|
|
697
|
-
producedBy,
|
|
698
|
-
redactionSecrets: [
|
|
699
|
-
...parseCompletionRedactionSecrets(process.env[completionRedactionSecretsEnv]),
|
|
700
|
-
...attemptDatabaseCapabilitySecrets(process.env[attemptDatabaseCapabilityEnvironment]),
|
|
701
|
-
],
|
|
702
|
-
developCycle,
|
|
703
|
-
qaCycle,
|
|
704
|
-
debugCycle,
|
|
705
|
-
architectCycle,
|
|
706
|
-
draftCycle,
|
|
707
|
-
decomposeCycle
|
|
708
|
-
}
|
|
709
|
-
};
|
|
710
|
-
}
|
|
711
584
|
export function completionRedactionEnv(secrets) {
|
|
712
585
|
const filtered = secrets.filter((secret) => secret.length > 0);
|
|
713
586
|
return filtered.length > 0
|
|
714
587
|
? { [completionRedactionSecretsEnv]: JSON.stringify(filtered) }
|
|
715
588
|
: {};
|
|
716
589
|
}
|
|
717
|
-
async function prepareCursorCompletionToolRuntime(worktreePath, runtime) {
|
|
718
|
-
const cursorDir = path.join(worktreePath, ".cursor");
|
|
719
|
-
const configPath = path.join(cursorDir, "mcp.json");
|
|
720
|
-
const original = await fs.readFile(configPath, "utf8").then((content) => ({ existed: true, content }), () => ({ existed: false, content: "" }));
|
|
721
|
-
const existing = original.existed ? parseOptionalJsonObject(original.content, configPath) : {};
|
|
722
|
-
const servers = asMutableRecord(existing.mcpServers);
|
|
723
|
-
servers[runtime.serverName] = cursorMcpServerConfig(runtime);
|
|
724
|
-
const next = {
|
|
725
|
-
...existing,
|
|
726
|
-
mcpServers: servers
|
|
727
|
-
};
|
|
728
|
-
await fs.mkdir(cursorDir, { recursive: true });
|
|
729
|
-
await writeFileAtomic(configPath, `${JSON.stringify(next, null, 2)}\n`);
|
|
730
|
-
return {
|
|
731
|
-
...runtime,
|
|
732
|
-
cursorMcpConfigPath: configPath,
|
|
733
|
-
cleanup: async () => {
|
|
734
|
-
if (original.existed) {
|
|
735
|
-
await writeFileAtomic(configPath, original.content);
|
|
736
|
-
}
|
|
737
|
-
else {
|
|
738
|
-
await fs.rm(configPath, { force: true });
|
|
739
|
-
await fs.rmdir(cursorDir).catch(() => undefined);
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
};
|
|
743
|
-
}
|
|
744
590
|
/**
|
|
745
591
|
* Claude Code takes MCP servers from `--mcp-config <file>`. The file lives in an attempt-owned
|
|
746
592
|
* temp directory (never the worktree) because its env block can carry redaction secrets, and
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { decomposeGateFileNames, decomposeStatuses, draftStatuses, isDebugCompletionPhase, phaseFiles, qaBlockerReasons, qaGateFileNames } from "./phase-completion.js";
|
|
2
2
|
import { browserCheckSchema, qaSidecarsSchema, qaEvidenceWrapperSchema, qaGateEvidenceWrapperSchema, findingEvidenceSchema, objectToolSchema, evidenceObjectSchema, qaScopeSchema, commandEvidenceSchema, resolvedFindingSchema, acceptanceCriteriaSchema, reviewSectionSchema, reviewSectionProperties } from "./phase-completion.schema-parts.js";
|
|
3
|
+
import { architectNonPassProperties } from "./architect-waits.js";
|
|
3
4
|
export function toolDescription(phase, qaGate = null, decomposeGate = null, draftGate = null) {
|
|
4
5
|
if (qaGate) {
|
|
5
6
|
return qaGate === "qa_verdict"
|
|
@@ -499,17 +500,8 @@ export function toolInputSchema(phase, qaGate = null, decomposeGate = null, draf
|
|
|
499
500
|
report_markdown: { type: "string", description: "Human-readable Architect report. Use report as an alias only when the client cannot send report_markdown." },
|
|
500
501
|
report: { type: "string", description: "Alias for report_markdown." },
|
|
501
502
|
blockers: baseProperties.blockers,
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
description: "Required for needs_revision when blockers are not used.",
|
|
505
|
-
items: { type: "string" }
|
|
506
|
-
},
|
|
507
|
-
revision_reasons: {
|
|
508
|
-
type: "array",
|
|
509
|
-
description: "Concrete reasons that prevent pass status.",
|
|
510
|
-
items: { type: "string" }
|
|
511
|
-
}
|
|
512
|
-
}, ["status", "summary"], "For status pass, include implementation_plan and qa_plan at the top level of the MCP tool arguments, as JSON objects rather than quoted strings. implementation_plan.phases must be a top-level array inside implementation_plan, not nested under another object. For needs_revision or blocked, implementation_plan and qa_plan may be omitted; include blockers, revision_questions, or revision_reasons instead.");
|
|
503
|
+
...architectNonPassProperties()
|
|
504
|
+
}, ["status", "summary"], "For status pass, include implementation_plan and qa_plan at the top level of the MCP tool arguments, as JSON objects rather than quoted strings. implementation_plan.phases must be a top-level array inside implementation_plan, not nested under another object. For needs_revision or blocked, implementation_plan and qa_plan may be omitted; include blockers, revision_questions, or revision_reasons instead. When blocked because another Story or pull request must merge first, also list it in waits_on; when the owner must choose, also set owner_decision.");
|
|
513
505
|
}
|
|
514
506
|
return objectToolSchema({
|
|
515
507
|
...baseProperties,
|
|
@@ -536,6 +528,27 @@ export function toolInputSchema(phase, qaGate = null, decomposeGate = null, draf
|
|
|
536
528
|
ready_for_dev_test: { type: "boolean", default: true, description: "Required for pass and must be true." }
|
|
537
529
|
}, ["status", "summary"], "For status pass, commands must include at least one passing deterministic command, acceptance criteria entries must use status: satisfied plus evidence, and ready_for_dev_test must be true.");
|
|
538
530
|
}
|
|
531
|
+
// Feature-to-Story candidate fields: schedule order, handoff to dependents, and whether the Story
|
|
532
|
+
// needs a design reference before Forge builds it.
|
|
533
|
+
const storyCandidateScheduleProperties = {
|
|
534
|
+
scheduleIndex: { type: "number", description: "Feature-to-Story total schedule order for dependency-safe execution." },
|
|
535
|
+
schedule_index: { type: "number", description: "Snake_case alias for scheduleIndex." },
|
|
536
|
+
waveIndex: { type: "number", description: "Feature-to-Story parallel wave number." },
|
|
537
|
+
wave_index: { type: "number", description: "Snake_case alias for waveIndex." },
|
|
538
|
+
featureScheduleIndex: { type: "number", description: "Optional ordering within the Feature." },
|
|
539
|
+
feature_schedule_index: { type: "number", description: "Snake_case alias for featureScheduleIndex." },
|
|
540
|
+
expectedOutput: { type: "string", description: "Durable output this Story should produce for dependents." },
|
|
541
|
+
expected_output: { type: "string", description: "Snake_case alias for expectedOutput." },
|
|
542
|
+
handoffSummary: { type: "string", description: "How dependent Stories should consume this Story output." },
|
|
543
|
+
handoff_summary: { type: "string", description: "Snake_case alias for handoffSummary." },
|
|
544
|
+
dependencyReason: { type: "string", description: "Why this Story depends on its dependsOn predecessors." },
|
|
545
|
+
dependency_reason: { type: "string", description: "Snake_case alias for dependencyReason." },
|
|
546
|
+
requiresDesign: {
|
|
547
|
+
type: "boolean",
|
|
548
|
+
description: "Feature-to-Story only. True when the Story adds or changes user-visible UI; Forge holds it until a design reference is attached. False for non-visual Stories."
|
|
549
|
+
},
|
|
550
|
+
requires_design: { type: "boolean", description: "Snake_case alias for requiresDesign." }
|
|
551
|
+
};
|
|
539
552
|
function decomposeGateToolInputSchema(gate, phaseProperties) {
|
|
540
553
|
// Advertise every status the Decompose writer accepts, so the schema and the runtime agree.
|
|
541
554
|
const baseProperties = {
|
|
@@ -572,18 +585,7 @@ function decomposeGateToolInputSchema(gate, phaseProperties) {
|
|
|
572
585
|
acceptanceCriteria: { type: "string" },
|
|
573
586
|
planningPacket: { type: "string" },
|
|
574
587
|
sortOrder: { type: "number" },
|
|
575
|
-
|
|
576
|
-
schedule_index: { type: "number", description: "Snake_case alias for scheduleIndex." },
|
|
577
|
-
waveIndex: { type: "number", description: "Feature-to-Story parallel wave number." },
|
|
578
|
-
wave_index: { type: "number", description: "Snake_case alias for waveIndex." },
|
|
579
|
-
featureScheduleIndex: { type: "number", description: "Optional ordering within the Feature." },
|
|
580
|
-
feature_schedule_index: { type: "number", description: "Snake_case alias for featureScheduleIndex." },
|
|
581
|
-
expectedOutput: { type: "string", description: "Durable output this Story should produce for dependents." },
|
|
582
|
-
expected_output: { type: "string", description: "Snake_case alias for expectedOutput." },
|
|
583
|
-
handoffSummary: { type: "string", description: "How dependent Stories should consume this Story output." },
|
|
584
|
-
handoff_summary: { type: "string", description: "Snake_case alias for handoffSummary." },
|
|
585
|
-
dependencyReason: { type: "string", description: "Why this Story depends on its dependsOn predecessors." },
|
|
586
|
-
dependency_reason: { type: "string", description: "Snake_case alias for dependencyReason." },
|
|
588
|
+
...storyCandidateScheduleProperties,
|
|
587
589
|
points: { type: "number" },
|
|
588
590
|
dependsOn: { type: "array", items: { type: "string" } },
|
|
589
591
|
estimatedQaScope: qaScopeSchema("Work Order-to-Feature planning QA estimate. This is not dispatch-authoritative QA scope."),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { qaBlockerReasons, qaCandidateBugActions, qaFindingScopes, qaFindingSeverities, qaGateToolNames, qaScopeAuthorities, qaScopeCapabilities, qaScopeConfidence, qaScopeEvidence, qaScopeFields, qaScopeSources, qaScopeSurfaces } from "./phase-completion.js";
|
|
2
2
|
import { structuredTypeHint } from "./mcp-argument-coercion.js";
|
|
3
|
+
import { validateArchitectWaits } from "./architect-waits.js";
|
|
3
4
|
import { validateQaGatePassingCommands } from "./phase-completion.command-validation.js";
|
|
4
5
|
export { validateQaGatePassingCommands } from "./phase-completion.command-validation.js";
|
|
5
6
|
export const qaEvidenceGates = new Set(["qa_regression", "qa_api", "qa_manual_web", "qa_bug_repro"]);
|
|
@@ -353,6 +354,7 @@ export function validateQaGatePayloadShape(gate, payload, status) {
|
|
|
353
354
|
}
|
|
354
355
|
}
|
|
355
356
|
export function validateArchitectPayloadShape(payload, status) {
|
|
357
|
+
validateArchitectWaits(payload, status);
|
|
356
358
|
if (status !== "pass") {
|
|
357
359
|
requireArchitectNonPassEvidence(payload);
|
|
358
360
|
return;
|
|
@@ -706,7 +708,7 @@ export function hasArchitectDependencyCycle(edges) {
|
|
|
706
708
|
return false;
|
|
707
709
|
}
|
|
708
710
|
export function requireArchitectNonPassEvidence(payload) {
|
|
709
|
-
const evidenceKeys = ["blockers", "revision_questions", "revision_reasons", "known_gaps", "findings", "remaining_risks", "failures"];
|
|
711
|
+
const evidenceKeys = ["blockers", "revision_questions", "revision_reasons", "waits_on", "owner_decision", "known_gaps", "findings", "remaining_risks", "failures"];
|
|
710
712
|
const hasEvidence = evidenceKeys.some((key) => {
|
|
711
713
|
const value = payload[key];
|
|
712
714
|
if (typeof value === "string") {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { DockerEngineProbe } from "../runtime/docker-engine-probe.js";
|
|
2
|
+
import { startEphemeralTestPostgresGrant } from "../runtime/ephemeral-test-postgres-grant.js";
|
|
3
|
+
import { type NativeTestPostgresFallback, type NativeTestPostgresGrant } from "../runtime/native-test-postgres-fallback.js";
|
|
4
|
+
import type { RunnerDispatchEvent } from "./session.types.js";
|
|
5
|
+
/**
|
|
6
|
+
* A provisioned native test cluster whose file prefers it serves this check's shared
|
|
7
|
+
* test server without waiting on Docker (owner policy 2026-11-16: native PostgreSQL
|
|
8
|
+
* first). Docker is still probed, never recovered, so the fixtures know whether
|
|
9
|
+
* pinned-engine tests can start their own containers. An unreadable file leaves the
|
|
10
|
+
* check on Docker.
|
|
11
|
+
*/
|
|
12
|
+
export declare function preferredNativeTestPostgres(checkId: string, requiredPrerequisite: string | undefined, readCluster: () => NativeTestPostgresFallback | null, dockerEngineProbe: DockerEngineProbe | undefined, emit?: (event: RunnerDispatchEvent) => Promise<void>, startEphemeral?: typeof startEphemeralTestPostgresGrant): Promise<NativeTestPostgresGrant | undefined>;
|
|
13
|
+
/** Whether this check already has its isolated PostgreSQL without Docker. */
|
|
14
|
+
export declare function isolatedPostgresProvided(checkId: string, environment?: Readonly<Record<string, string>>, postgresAdminConnection?: NativeTestPostgresGrant): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The grant, when it makes its check Docker-free. A native_preferred grant still lets
|
|
17
|
+
* pinned-engine tests start Docker containers, so a Docker loss during its check stays
|
|
18
|
+
* retryable infrastructure; only a native_fallback grant (Docker was already down) does not.
|
|
19
|
+
*/
|
|
20
|
+
export declare function dockerFreeGrant(grant: NativeTestPostgresGrant | undefined): NativeTestPostgresGrant | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Releases a check's ephemeral cluster once the check has ended. A cluster that would not stop
|
|
23
|
+
* is left disowned for the next start's reap and does not change the check's own result.
|
|
24
|
+
*/
|
|
25
|
+
export declare function releaseCheckPostgres(checkId: string, grant: NativeTestPostgresGrant | undefined, emit?: (event: RunnerDispatchEvent) => Promise<void>): Promise<void>;
|
|
26
|
+
/** The native cluster grant for a check while Docker stays down, or null when it cannot use one. */
|
|
27
|
+
export declare function dockerUnavailableNativeTestPostgres(checkId: string, requiredPrerequisite: string | undefined, readCluster: () => NativeTestPostgresFallback | null): NativeTestPostgresGrant | null;
|
|
28
|
+
export type { NativeTestPostgresFallback, NativeTestPostgresGrant };
|
|
29
|
+
/** Starts a check's ephemeral cluster; injectable so tests need no PostgreSQL install. */
|
|
30
|
+
export type StartEphemeralTestPostgresGrant = typeof startEphemeralTestPostgresGrant;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { attemptDatabaseCapabilityEnvironment } from "../runtime/attempt-database-broker.js";
|
|
3
|
+
import { startEphemeralTestPostgresGrant } from "../runtime/ephemeral-test-postgres-grant.js";
|
|
4
|
+
import { nativeTestPostgresFallbackDatabaseMode, nativeTestPostgresGrant, } from "../runtime/native-test-postgres-fallback.js";
|
|
5
|
+
import { validationEvent } from "./pre-publication-pass.js";
|
|
6
|
+
import { supportsNativeTestPostgresFallback } from "./pre-publication-step-execution.js";
|
|
7
|
+
// Which PostgreSQL a pre-publication check's isolated_postgres prerequisite is met by,
|
|
8
|
+
// before the validator falls back to waiting for Docker.
|
|
9
|
+
/**
|
|
10
|
+
* A provisioned native test cluster whose file prefers it serves this check's shared
|
|
11
|
+
* test server without waiting on Docker (owner policy 2026-11-16: native PostgreSQL
|
|
12
|
+
* first). Docker is still probed, never recovered, so the fixtures know whether
|
|
13
|
+
* pinned-engine tests can start their own containers. An unreadable file leaves the
|
|
14
|
+
* check on Docker.
|
|
15
|
+
*/
|
|
16
|
+
export async function preferredNativeTestPostgres(checkId, requiredPrerequisite, readCluster, dockerEngineProbe, emit, startEphemeral = startEphemeralTestPostgresGrant) {
|
|
17
|
+
if (requiredPrerequisite !== "isolated_postgres" || !supportsNativeTestPostgresFallback(checkId))
|
|
18
|
+
return undefined;
|
|
19
|
+
let configured;
|
|
20
|
+
try {
|
|
21
|
+
configured = readCluster();
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
await emit?.(validationEvent("prepublication_prerequisite_native_invalid", checkId, `The native PostgreSQL test cluster configuration was refused, so '${checkId}' uses Docker: ${error instanceof Error ? error.message : String(error)}`));
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
if (configured?.use === "ephemeral") {
|
|
28
|
+
return await ephemeralNativeTestPostgres(checkId, configured, dockerEngineProbe, emit, startEphemeral);
|
|
29
|
+
}
|
|
30
|
+
if (configured?.use !== "preferred")
|
|
31
|
+
return undefined;
|
|
32
|
+
const dockerAvailable = dockerEngineProbe ? (await dockerEngineProbe.probeWithoutRecovery()).available : false;
|
|
33
|
+
const grant = nativeTestPostgresGrant(configured, dockerAvailable);
|
|
34
|
+
if (!grant)
|
|
35
|
+
return undefined;
|
|
36
|
+
await emit?.(validationEvent("prepublication_prerequisite_native_preferred", checkId, `Pre-publication check '${checkId}' is using the dedicated native PostgreSQL test cluster at ${grant.endpoint} with per-run owned databases${dockerAvailable
|
|
37
|
+
? "; tests that need a pinned engine container still start one in Docker."
|
|
38
|
+
: ". Docker is unavailable, so tests that need a pinned engine container are skipped."}`));
|
|
39
|
+
return grant;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A throwaway cluster of the check's own, whose superuser it holds (owner policy 2026-11-17).
|
|
43
|
+
* If it cannot start, the check falls back to Docker, and to the provisioned cluster only while
|
|
44
|
+
* Docker is down.
|
|
45
|
+
*/
|
|
46
|
+
async function ephemeralNativeTestPostgres(checkId, configured, dockerEngineProbe, emit, startEphemeral) {
|
|
47
|
+
const dockerAvailable = dockerEngineProbe ? (await dockerEngineProbe.probeWithoutRecovery()).available : false;
|
|
48
|
+
let grant;
|
|
49
|
+
try {
|
|
50
|
+
grant = await startEphemeral(configured, dockerAvailable);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
await emit?.(validationEvent("prepublication_prerequisite_ephemeral_unavailable", checkId, `An ephemeral PostgreSQL test cluster could not start for '${checkId}', so it uses Docker: ${error instanceof Error ? error.message : String(error)}`));
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
await emit?.(validationEvent("prepublication_prerequisite_native_ephemeral", checkId, `Pre-publication check '${checkId}' is using its own ephemeral PostgreSQL test cluster at ${grant.endpoint}, deleted when the check ends${dockerAvailable
|
|
58
|
+
? "; tests that need a pinned engine container still start one in Docker."
|
|
59
|
+
: ". Docker is unavailable, so tests that need a pinned engine container are skipped."}`));
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
// The caller releases only a grant it receives, so a failed emit releases it here.
|
|
63
|
+
await grant.release?.().catch(() => undefined);
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
return grant;
|
|
67
|
+
}
|
|
68
|
+
function environmentValue(environment, name) {
|
|
69
|
+
return Object.prototype.hasOwnProperty.call(environment ?? {}, name)
|
|
70
|
+
? environment?.[name]?.trim() ?? ""
|
|
71
|
+
: process.env[name]?.trim() ?? "";
|
|
72
|
+
}
|
|
73
|
+
/** Whether this check already has its isolated PostgreSQL without Docker. */
|
|
74
|
+
export function isolatedPostgresProvided(checkId, environment, postgresAdminConnection) {
|
|
75
|
+
if (checkId === "playwright-e2e") {
|
|
76
|
+
const attemptId = environmentValue(environment, "FORGE_DISPATCH_ATTEMPT_ID");
|
|
77
|
+
return (environmentValue(environment, "FORGE_E2E_OWNERSHIP_MODE") === "attempt"
|
|
78
|
+
|| /^[0-9a-f-]{36}$/iu.test(attemptId))
|
|
79
|
+
&& /^forge_attempt_[0-9a-f]{32}$/u.test(environmentValue(environment, "FORGE_ATTEMPT_DATABASE_SCHEMA"))
|
|
80
|
+
&& path.isAbsolute(environmentValue(environment, "FORGE_ATTEMPT_DATABASE_READINESS_PATH"))
|
|
81
|
+
// The attempt owns a database only once the Bridge's broker has issued it one.
|
|
82
|
+
&& environmentValue(environment, attemptDatabaseCapabilityEnvironment).length > 0;
|
|
83
|
+
}
|
|
84
|
+
return Boolean(postgresAdminConnection);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The grant, when it makes its check Docker-free. A native_preferred grant still lets
|
|
88
|
+
* pinned-engine tests start Docker containers, so a Docker loss during its check stays
|
|
89
|
+
* retryable infrastructure; only a native_fallback grant (Docker was already down) does not.
|
|
90
|
+
*/
|
|
91
|
+
export function dockerFreeGrant(grant) {
|
|
92
|
+
return grant?.mode === nativeTestPostgresFallbackDatabaseMode ? grant : undefined;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Releases a check's ephemeral cluster once the check has ended. A cluster that would not stop
|
|
96
|
+
* is left disowned for the next start's reap and does not change the check's own result.
|
|
97
|
+
*/
|
|
98
|
+
export async function releaseCheckPostgres(checkId, grant, emit) {
|
|
99
|
+
try {
|
|
100
|
+
await grant?.release?.();
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
await emit?.(validationEvent("prepublication_ephemeral_release_failed", checkId, `The ephemeral PostgreSQL test cluster for '${checkId}' could not be released and will be reaped later: ${error instanceof Error ? error.message : String(error)}`)).catch(() => undefined);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/** The native cluster grant for a check while Docker stays down, or null when it cannot use one. */
|
|
107
|
+
export function dockerUnavailableNativeTestPostgres(checkId, requiredPrerequisite, readCluster) {
|
|
108
|
+
return requiredPrerequisite === "isolated_postgres" && supportsNativeTestPostgresFallback(checkId)
|
|
109
|
+
? nativeTestPostgresGrant(readCluster(), false)
|
|
110
|
+
: null;
|
|
111
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { ValidationStep } from "./pre-publication-step-execution.js";
|
|
2
|
+
import { ForgeFailureError, type RunnerDispatchEvent } from "./session.types.js";
|
|
3
|
+
/** The check id a failed restart of the attempt's runtime stack before the pass is reported under. */
|
|
4
|
+
export declare const runtimeRestartCheckId = "host-runtime-restart";
|
|
5
|
+
/** One check that failed in a pass: the step that failed and its clipped diagnostics. */
|
|
6
|
+
export interface PrePublicationCheckFailure {
|
|
7
|
+
readonly checkId: string;
|
|
8
|
+
readonly exitCode: number;
|
|
9
|
+
readonly command: string;
|
|
10
|
+
readonly args: readonly string[];
|
|
11
|
+
readonly detail: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A failed validation pass. The single-check fields name the first failure, as they always have;
|
|
15
|
+
* `failures` lists every check that failed in the pass, in the order the checks ran.
|
|
16
|
+
*/
|
|
17
|
+
export declare class PrePublicationValidationError extends ForgeFailureError {
|
|
18
|
+
readonly checkId: string;
|
|
19
|
+
readonly exitCode: number;
|
|
20
|
+
readonly command: string;
|
|
21
|
+
readonly args: readonly string[];
|
|
22
|
+
readonly detail: string;
|
|
23
|
+
readonly code = "prepublication_validation_failed";
|
|
24
|
+
readonly failures: readonly PrePublicationCheckFailure[];
|
|
25
|
+
constructor(checkId: string, exitCode: number, command: string, args: readonly string[], detail: string, additionalFailures?: readonly PrePublicationCheckFailure[]);
|
|
26
|
+
/** Every failed check's id, first failure first. */
|
|
27
|
+
get checkIds(): readonly string[];
|
|
28
|
+
}
|
|
29
|
+
export declare class PrePublicationPass {
|
|
30
|
+
private readonly runtimeRestartFailure?;
|
|
31
|
+
private readonly failures;
|
|
32
|
+
/** The check whose .NET build failed to compile in this pass, if any. */
|
|
33
|
+
private dotnetCompileFailedIn;
|
|
34
|
+
/** A failed runtime restart before the pass is its first failure. */
|
|
35
|
+
constructor(runtimeRestartFailure?: PrePublicationValidationError | undefined);
|
|
36
|
+
record(failure: PrePublicationCheckFailure, failedStep?: ValidationStep): void;
|
|
37
|
+
/** The failed checks that keep this check from running meaningfully in this pass. */
|
|
38
|
+
blockers(checkId: string): readonly string[];
|
|
39
|
+
/**
|
|
40
|
+
* Whether an error ends the pass with the failures it already found. Only a classified retryable
|
|
41
|
+
* failure (a resource hold, lost infrastructure, a supervisor that did not start) does, once the
|
|
42
|
+
* pass has found a failure: the repair turn can fix those failures now, and the next pass meets
|
|
43
|
+
* the condition again. Any other error, or cancellation, still ends the attempt as it did.
|
|
44
|
+
*/
|
|
45
|
+
stopsAt(error: unknown, signal?: AbortSignal): error is ForgeFailureError;
|
|
46
|
+
stoppedEvent(checkId: string, error: ForgeFailureError): RunnerDispatchEvent;
|
|
47
|
+
/** Throws every failure the pass found as one validation failure. */
|
|
48
|
+
throwIfFailed(): void;
|
|
49
|
+
}
|
|
50
|
+
export declare function skippedCheckEvent(checkId: string, blockedBy: readonly string[]): RunnerDispatchEvent;
|
|
51
|
+
/** The tests a check's steps skipped, so a check that passed with skips says so with each reason. */
|
|
52
|
+
export declare class SkippedTestTally {
|
|
53
|
+
private readonly worktreePath;
|
|
54
|
+
private readonly environment?;
|
|
55
|
+
private summary;
|
|
56
|
+
constructor(worktreePath: string, environment?: Readonly<Record<string, string>> | undefined);
|
|
57
|
+
/** The invocation's own arguments: a managed attempt may direct results to its test-output root. */
|
|
58
|
+
add(args: readonly string[], stepStartedMs: number): Promise<void>;
|
|
59
|
+
passedEvent(checkId: string, secrets: readonly string[]): RunnerDispatchEvent;
|
|
60
|
+
}
|
|
61
|
+
export declare function validationEvent(eventType: string, checkId: string, content: string, detail?: Readonly<Record<string, unknown>>): RunnerDispatchEvent;
|