@loucompanion/forge-bridge 0.1.4-dev.acacfdecaad2 → 0.1.4-dev.b1c678efffd2
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 +9 -0
- package/dist/bridge/bridge-chat-provider-command.d.ts +16 -0
- package/dist/bridge/bridge-chat-provider-command.js +125 -0
- package/dist/bridge/bridge.service.d.ts +1 -1
- package/dist/bridge/bridge.service.js +4 -110
- package/dist/runtime/host-runtime-lease.d.ts +1 -1
- package/dist/runtime/host-runtime-lease.js +8 -7
- package/dist/runtime/host-runtime-promotion.d.ts +23 -0
- package/dist/runtime/host-runtime-promotion.js +36 -0
- package/dist/session/phase-completion.schemas.js +22 -12
- package/dist/session/pre-publication-pass.d.ts +60 -0
- package/dist/session/pre-publication-pass.js +145 -0
- package/dist/session/pre-publication-validation.d.ts +21 -11
- package/dist/session/pre-publication-validation.js +149 -104
- package/dist/session/provider-cli/claude-background-work.d.ts +66 -0
- package/dist/session/provider-cli/claude-background-work.js +180 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +40 -0
- package/dist/session/provider-cli/pre-publication-repair.js +243 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +7 -6
- package/dist/session/provider-cli/provider-cli.process.js +14 -54
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +2 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +45 -8
- package/dist/session/provider-cli/provider-cli.runtime.js +7 -0
- package/dist/session/provider-cli/provider-cli.service.d.ts +4 -7
- package/dist/session/provider-cli/provider-cli.service.js +66 -243
- 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-state.d.ts +2 -0
- package/dist/session/provider-cli/provider-output-state.js +6 -0
- package/dist/session/session.types.js +1 -1
- package/dist/shared/provider-capabilities.js +5 -6
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -162,6 +162,15 @@ While yielding, the bridge takes no new attempts and heavy steps of running atte
|
|
|
162
162
|
budget. Yield is on when this local flag or the runner's Yield toggle in Forge is on. The flag is stored
|
|
163
163
|
in `bridge.yield.json` next to `bridge.json`, and a running bridge notices it within one heartbeat.
|
|
164
164
|
|
|
165
|
+
## Pre-publication repair
|
|
166
|
+
|
|
167
|
+
Before Forge commits and pushes an agent's work, the bridge runs the CI parity checks in
|
|
168
|
+
`.forge/validation/ci-parity.v1.json`. A failed check does not stop the pass: the other checks still
|
|
169
|
+
run, except those that need what failed (the OpenAPI export and E2E after a .NET compile failure, E2E
|
|
170
|
+
after a failed runtime restart). The provider thread then gets one in-place repair turn that lists
|
|
171
|
+
every failed check. A Work Order holds after `FORGE_PREPUBLICATION_REPAIR_TURNS` repair turns (a whole
|
|
172
|
+
number from 1, capped at 10; default 4) if validation still fails.
|
|
173
|
+
|
|
165
174
|
## Docker sandbox runners
|
|
166
175
|
|
|
167
176
|
Protocol-v2 bridges preflight Docker before advertising the `docker` sandbox runtime. Validate a repository contract and the local runner before enabling a project's `sandbox_required` policy:
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ProviderCliCommand, ProviderProcessRunResult } from "../session/provider-cli/provider-cli.process.js";
|
|
2
|
+
import type { ChatTurnDispatchPacket } from "./bridge-chat.types.js";
|
|
3
|
+
/** The turn-scoped handoff metadata file the bridge writes into the chat workspace. */
|
|
4
|
+
export declare const chatTurnMetadataFileName = "forge-chat-metadata.json";
|
|
5
|
+
/**
|
|
6
|
+
* Fails a Bridge Chat turn Forge stopped because it ended with background work still live: the
|
|
7
|
+
* turn never delivered its answer, so it must not be reported as one.
|
|
8
|
+
*/
|
|
9
|
+
export declare function assertChatTurnFinished(result: Pick<ProviderProcessRunResult, "terminalStopReason">): void;
|
|
10
|
+
export interface ChatProviderCommandPlan {
|
|
11
|
+
readonly command: ProviderCliCommand;
|
|
12
|
+
readonly stdin?: string;
|
|
13
|
+
/** Provider environment, such as the headless background-work restrictions for Claude. */
|
|
14
|
+
readonly env?: Readonly<Record<string, string>>;
|
|
15
|
+
}
|
|
16
|
+
export declare function buildChatProviderCommand(packet: ChatTurnDispatchPacket, cwd: string): ChatProviderCommandPlan;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds the provider command for a Bridge Chat turn: the CLI invocation for the turn's provider
|
|
3
|
+
* and the prompt that carries the conversation, its context references and its bounded handoff
|
|
4
|
+
* metadata.
|
|
5
|
+
*/
|
|
6
|
+
import { claudeHeadlessEnvironment, claudeHeadlessToolArgs, providerTurnEndedWithBackgroundWorkFailure } from "../session/provider-cli/claude-background-work.js";
|
|
7
|
+
import { codexSandboxModeForPlatform } from "../session/provider-cli/provider-cli.prompts.js";
|
|
8
|
+
/** The turn-scoped handoff metadata file the bridge writes into the chat workspace. */
|
|
9
|
+
export const chatTurnMetadataFileName = "forge-chat-metadata.json";
|
|
10
|
+
/**
|
|
11
|
+
* Fails a Bridge Chat turn Forge stopped because it ended with background work still live: the
|
|
12
|
+
* turn never delivered its answer, so it must not be reported as one.
|
|
13
|
+
*/
|
|
14
|
+
export function assertChatTurnFinished(result) {
|
|
15
|
+
if (result.terminalStopReason === "turn_ended_with_background_work") {
|
|
16
|
+
throw providerTurnEndedWithBackgroundWorkFailure("The Bridge Chat turn did not finish.");
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function buildChatProviderCommand(packet, cwd) {
|
|
20
|
+
const provider = packet.providerKind.trim().toLowerCase();
|
|
21
|
+
const model = packet.model.trim();
|
|
22
|
+
const prompt = buildChatPrompt(packet);
|
|
23
|
+
const resumeThreadId = packet.providerThreadId?.trim() || null;
|
|
24
|
+
if (provider === "codex") {
|
|
25
|
+
const args = ["-s", codexSandboxModeForPlatform(process.platform, "host"), "-a", "never", "exec"];
|
|
26
|
+
if (resumeThreadId) {
|
|
27
|
+
args.push("--cd", cwd, "resume");
|
|
28
|
+
}
|
|
29
|
+
args.push("--model", model, "--json");
|
|
30
|
+
if (!resumeThreadId) {
|
|
31
|
+
args.push("--cd", cwd);
|
|
32
|
+
}
|
|
33
|
+
args.push("--skip-git-repo-check");
|
|
34
|
+
if (resumeThreadId) {
|
|
35
|
+
args.push(resumeThreadId);
|
|
36
|
+
}
|
|
37
|
+
args.push("-");
|
|
38
|
+
return { command: { command: "codex", args }, stdin: prompt };
|
|
39
|
+
}
|
|
40
|
+
if (provider === "cursor") {
|
|
41
|
+
const args = ["--print", "--output-format", "stream-json", "--model", model, "--workspace", cwd];
|
|
42
|
+
if (resumeThreadId) {
|
|
43
|
+
args.push("--resume", resumeThreadId);
|
|
44
|
+
}
|
|
45
|
+
args.push("--yolo", "--approve-mcps", "--trust", prompt);
|
|
46
|
+
return { command: { command: "cursor-agent", args } };
|
|
47
|
+
}
|
|
48
|
+
if (provider === "claude") {
|
|
49
|
+
const args = ["-p", "--output-format", "stream-json", "--verbose", "--model", model, "--permission-mode", "bypassPermissions", ...claudeHeadlessToolArgs()];
|
|
50
|
+
if (resumeThreadId) {
|
|
51
|
+
args.push("--resume", resumeThreadId);
|
|
52
|
+
}
|
|
53
|
+
return { command: { command: "claude", args }, stdin: prompt, env: claudeHeadlessEnvironment };
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
command: {
|
|
57
|
+
command: provider,
|
|
58
|
+
args: ["--model", model, prompt],
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function buildChatPrompt(packet) {
|
|
63
|
+
const messages = packet.messages
|
|
64
|
+
.map((message, index) => {
|
|
65
|
+
const role = message.role.trim() || `message-${index + 1}`;
|
|
66
|
+
return `[${role}]\n${message.content}`;
|
|
67
|
+
})
|
|
68
|
+
.join("\n\n");
|
|
69
|
+
const contextRefs = packet.contextRefs.length === 0
|
|
70
|
+
? ""
|
|
71
|
+
: `\n\n# Context References\n\n${packet.contextRefs.map((ref, index) => {
|
|
72
|
+
const title = ref.title?.trim() ? `\nTitle: ${ref.title.trim()}` : "";
|
|
73
|
+
const summary = ref.summary?.trim() ? `\nSummary: ${ref.summary.trim()}` : "";
|
|
74
|
+
return `${index + 1}. ${ref.kind}:${ref.refId}${title}${summary}`;
|
|
75
|
+
}).join("\n\n")}`;
|
|
76
|
+
const continuation = packet.providerThreadId
|
|
77
|
+
? "\n\nContinue the existing provider thread identified by the bridge; do not restart the conversation context."
|
|
78
|
+
: "";
|
|
79
|
+
const boundedMetadata = buildChatBoundedMetadataPrompt(packet);
|
|
80
|
+
return `You are handling a Forge Bridge Chat turn.
|
|
81
|
+
|
|
82
|
+
Conversation ID: ${packet.conversationId}
|
|
83
|
+
Turn ID: ${packet.turnId}
|
|
84
|
+
Provider: ${packet.providerKind}
|
|
85
|
+
Model: ${packet.model}${continuation}${boundedMetadata}
|
|
86
|
+
|
|
87
|
+
# Conversation
|
|
88
|
+
|
|
89
|
+
${messages}${contextRefs}
|
|
90
|
+
`;
|
|
91
|
+
}
|
|
92
|
+
function buildChatBoundedMetadataPrompt(packet) {
|
|
93
|
+
if (packet.attachmentHandoffs.length === 0 && packet.actionBrokerGrants.length === 0) {
|
|
94
|
+
return "";
|
|
95
|
+
}
|
|
96
|
+
const sections = [
|
|
97
|
+
`\n\n# Bounded Handoff Metadata\n\nMetadata file: ${chatTurnMetadataFileName}\n\nThe metadata file is turn-scoped and cleaned up by the bridge when the turn ends. It contains opaque handles only; attachment content, raw paths, and grant nonces are not included.`,
|
|
98
|
+
];
|
|
99
|
+
if (packet.attachmentHandoffs.length > 0) {
|
|
100
|
+
sections.push(`Attachment handoffs:\n${packet.attachmentHandoffs.map((handoff, index) => [
|
|
101
|
+
`${index + 1}. turnId: ${handoff.turnId}`,
|
|
102
|
+
` attachmentId: ${handoff.attachmentId}`,
|
|
103
|
+
` tempFileToken: ${handoff.tempFileToken}`,
|
|
104
|
+
` mimeType: ${handoff.mimeType}`,
|
|
105
|
+
` sizeBytes: ${handoff.sizeBytes}`,
|
|
106
|
+
` sha256: ${handoff.sha256}`,
|
|
107
|
+
` fileNameDisplay: ${handoff.fileNameDisplay}`,
|
|
108
|
+
` expiresAt: ${handoff.expiresAt}`,
|
|
109
|
+
` status: ${handoff.status}`,
|
|
110
|
+
].join("\n")).join("\n\n")}`);
|
|
111
|
+
}
|
|
112
|
+
if (packet.actionBrokerGrants.length > 0) {
|
|
113
|
+
sections.push(`Action-broker grants:\n${packet.actionBrokerGrants.map((grant, index) => [
|
|
114
|
+
`${index + 1}. grantId: ${grant.grantId}`,
|
|
115
|
+
` turnId: ${grant.turnId}`,
|
|
116
|
+
` leaseId: ${grant.leaseId}`,
|
|
117
|
+
` fencingToken: ${grant.fencingToken}`,
|
|
118
|
+
` allowedScopes: ${grant.allowedScopes.join(", ")}`,
|
|
119
|
+
` expiresAt: ${grant.expiresAt}`,
|
|
120
|
+
` redactionStatus: ${grant.redactionStatus}`,
|
|
121
|
+
" nonce: held by bridge",
|
|
122
|
+
].join("\n")).join("\n\n")}`);
|
|
123
|
+
}
|
|
124
|
+
return sections.join("\n\n");
|
|
125
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SessionService } from "../session/session.base.js";
|
|
2
|
-
import type
|
|
2
|
+
import { type ProviderProcessRunner } from "../session/provider-cli/provider-cli.service.js";
|
|
3
3
|
import { type RunnerSettingsReport } from "../runtime/runner-settings.js";
|
|
4
4
|
import { DockerEngineProbe, type DockerEngineCapabilitySnapshot } from "../runtime/docker-engine-probe.js";
|
|
5
5
|
import { type DispatchSandboxResourceRequest, type RunOnceDispatchPacket, type RunOnceResultPacket } from "../session/session.types.js";
|
|
@@ -8,8 +8,8 @@ import { defaultForgeBridgeConfig } from "../config.js";
|
|
|
8
8
|
import { bridgeChatCapabilityFor, supportsDraftImageAttachmentsFor } from "../shared/provider-capabilities.js";
|
|
9
9
|
import { redactText } from "../shared/redaction/redaction.js";
|
|
10
10
|
import { BridgeSessionService } from "../session/session.service.js";
|
|
11
|
-
import { ProcessBackedProviderCliService, RoutingProviderCliService, StreamingProviderProcessRunner, } from "../session/provider-cli/provider-cli.service.js";
|
|
12
|
-
import {
|
|
11
|
+
import { formatProviderCliCommandForCheckpoint, ProcessBackedProviderCliService, RoutingProviderCliService, StreamingProviderProcessRunner, } from "../session/provider-cli/provider-cli.service.js";
|
|
12
|
+
import { assertChatTurnFinished, buildChatProviderCommand, chatTurnMetadataFileName } from "./bridge-chat-provider-command.js";
|
|
13
13
|
import { clip, createProviderOutputState } from "../session/provider-cli/provider-output-state.js";
|
|
14
14
|
import { redactRunnerDispatchEvent, redactRunOnceResultPacket } from "../session/session-redaction.js";
|
|
15
15
|
import { PrePublicationValidator } from "../session/pre-publication-validation.js";
|
|
@@ -681,6 +681,7 @@ export class ForgeBridgeService {
|
|
|
681
681
|
env: {
|
|
682
682
|
FORGE_BRIDGE_CHAT_RUN_ID: packet.chatRunId,
|
|
683
683
|
FORGE_BRIDGE_CHAT_TURN_ID: packet.turnId,
|
|
684
|
+
...plan.env,
|
|
684
685
|
},
|
|
685
686
|
stdin: plan.stdin,
|
|
686
687
|
}, {
|
|
@@ -707,6 +708,7 @@ export class ForgeBridgeService {
|
|
|
707
708
|
content: "Bridge Chat provider process exited.",
|
|
708
709
|
}).catch(() => undefined);
|
|
709
710
|
}
|
|
711
|
+
assertChatTurnFinished(result);
|
|
710
712
|
return { command: plan.command, output, result };
|
|
711
713
|
}
|
|
712
714
|
async sendChatProviderEvent(packet, active, event, providerThreadId) {
|
|
@@ -2690,7 +2692,6 @@ const defaultChatTurnLeaseMs = 60 * 60 * 1000;
|
|
|
2690
2692
|
const maxChatEventContentChars = 4000;
|
|
2691
2693
|
const maxChatTerminalTextChars = 120_000;
|
|
2692
2694
|
const maxChatExactSecretChars = 8 * 1024;
|
|
2693
|
-
const chatTurnMetadataFileName = "forge-chat-metadata.json";
|
|
2694
2695
|
async function materializeChatTurnMetadata(packet, workspacePath) {
|
|
2695
2696
|
if (packet.attachmentHandoffs.length === 0 && packet.actionBrokerGrants.length === 0) {
|
|
2696
2697
|
return;
|
|
@@ -2750,113 +2751,6 @@ async function cleanupChatTurnWorkspace(workspacePath, redactionSecrets) {
|
|
|
2750
2751
|
};
|
|
2751
2752
|
}
|
|
2752
2753
|
}
|
|
2753
|
-
function buildChatProviderCommand(packet, cwd) {
|
|
2754
|
-
const provider = packet.providerKind.trim().toLowerCase();
|
|
2755
|
-
const model = packet.model.trim();
|
|
2756
|
-
const prompt = buildChatPrompt(packet);
|
|
2757
|
-
const resumeThreadId = packet.providerThreadId?.trim() || null;
|
|
2758
|
-
if (provider === "codex") {
|
|
2759
|
-
const args = ["-s", codexSandboxModeForPlatform(process.platform, "host"), "-a", "never", "exec"];
|
|
2760
|
-
if (resumeThreadId) {
|
|
2761
|
-
args.push("--cd", cwd, "resume");
|
|
2762
|
-
}
|
|
2763
|
-
args.push("--model", model, "--json");
|
|
2764
|
-
if (!resumeThreadId) {
|
|
2765
|
-
args.push("--cd", cwd);
|
|
2766
|
-
}
|
|
2767
|
-
args.push("--skip-git-repo-check");
|
|
2768
|
-
if (resumeThreadId) {
|
|
2769
|
-
args.push(resumeThreadId);
|
|
2770
|
-
}
|
|
2771
|
-
args.push("-");
|
|
2772
|
-
return { command: { command: "codex", args }, stdin: prompt };
|
|
2773
|
-
}
|
|
2774
|
-
if (provider === "cursor") {
|
|
2775
|
-
const args = ["--print", "--output-format", "stream-json", "--model", model, "--workspace", cwd];
|
|
2776
|
-
if (resumeThreadId) {
|
|
2777
|
-
args.push("--resume", resumeThreadId);
|
|
2778
|
-
}
|
|
2779
|
-
args.push("--yolo", "--approve-mcps", "--trust", prompt);
|
|
2780
|
-
return { command: { command: "cursor-agent", args } };
|
|
2781
|
-
}
|
|
2782
|
-
if (provider === "claude") {
|
|
2783
|
-
const args = ["-p", "--output-format", "stream-json", "--verbose", "--model", model, "--permission-mode", "bypassPermissions"];
|
|
2784
|
-
if (resumeThreadId) {
|
|
2785
|
-
args.push("--resume", resumeThreadId);
|
|
2786
|
-
}
|
|
2787
|
-
return { command: { command: "claude", args }, stdin: prompt };
|
|
2788
|
-
}
|
|
2789
|
-
return {
|
|
2790
|
-
command: {
|
|
2791
|
-
command: provider,
|
|
2792
|
-
args: ["--model", model, prompt],
|
|
2793
|
-
},
|
|
2794
|
-
};
|
|
2795
|
-
}
|
|
2796
|
-
function buildChatPrompt(packet) {
|
|
2797
|
-
const messages = packet.messages
|
|
2798
|
-
.map((message, index) => {
|
|
2799
|
-
const role = message.role.trim() || `message-${index + 1}`;
|
|
2800
|
-
return `[${role}]\n${message.content}`;
|
|
2801
|
-
})
|
|
2802
|
-
.join("\n\n");
|
|
2803
|
-
const contextRefs = packet.contextRefs.length === 0
|
|
2804
|
-
? ""
|
|
2805
|
-
: `\n\n# Context References\n\n${packet.contextRefs.map((ref, index) => {
|
|
2806
|
-
const title = ref.title?.trim() ? `\nTitle: ${ref.title.trim()}` : "";
|
|
2807
|
-
const summary = ref.summary?.trim() ? `\nSummary: ${ref.summary.trim()}` : "";
|
|
2808
|
-
return `${index + 1}. ${ref.kind}:${ref.refId}${title}${summary}`;
|
|
2809
|
-
}).join("\n\n")}`;
|
|
2810
|
-
const continuation = packet.providerThreadId
|
|
2811
|
-
? "\n\nContinue the existing provider thread identified by the bridge; do not restart the conversation context."
|
|
2812
|
-
: "";
|
|
2813
|
-
const boundedMetadata = buildChatBoundedMetadataPrompt(packet);
|
|
2814
|
-
return `You are handling a Forge Bridge Chat turn.
|
|
2815
|
-
|
|
2816
|
-
Conversation ID: ${packet.conversationId}
|
|
2817
|
-
Turn ID: ${packet.turnId}
|
|
2818
|
-
Provider: ${packet.providerKind}
|
|
2819
|
-
Model: ${packet.model}${continuation}${boundedMetadata}
|
|
2820
|
-
|
|
2821
|
-
# Conversation
|
|
2822
|
-
|
|
2823
|
-
${messages}${contextRefs}
|
|
2824
|
-
`;
|
|
2825
|
-
}
|
|
2826
|
-
function buildChatBoundedMetadataPrompt(packet) {
|
|
2827
|
-
if (packet.attachmentHandoffs.length === 0 && packet.actionBrokerGrants.length === 0) {
|
|
2828
|
-
return "";
|
|
2829
|
-
}
|
|
2830
|
-
const sections = [
|
|
2831
|
-
`\n\n# Bounded Handoff Metadata\n\nMetadata file: ${chatTurnMetadataFileName}\n\nThe metadata file is turn-scoped and cleaned up by the bridge when the turn ends. It contains opaque handles only; attachment content, raw paths, and grant nonces are not included.`,
|
|
2832
|
-
];
|
|
2833
|
-
if (packet.attachmentHandoffs.length > 0) {
|
|
2834
|
-
sections.push(`Attachment handoffs:\n${packet.attachmentHandoffs.map((handoff, index) => [
|
|
2835
|
-
`${index + 1}. turnId: ${handoff.turnId}`,
|
|
2836
|
-
` attachmentId: ${handoff.attachmentId}`,
|
|
2837
|
-
` tempFileToken: ${handoff.tempFileToken}`,
|
|
2838
|
-
` mimeType: ${handoff.mimeType}`,
|
|
2839
|
-
` sizeBytes: ${handoff.sizeBytes}`,
|
|
2840
|
-
` sha256: ${handoff.sha256}`,
|
|
2841
|
-
` fileNameDisplay: ${handoff.fileNameDisplay}`,
|
|
2842
|
-
` expiresAt: ${handoff.expiresAt}`,
|
|
2843
|
-
` status: ${handoff.status}`,
|
|
2844
|
-
].join("\n")).join("\n\n")}`);
|
|
2845
|
-
}
|
|
2846
|
-
if (packet.actionBrokerGrants.length > 0) {
|
|
2847
|
-
sections.push(`Action-broker grants:\n${packet.actionBrokerGrants.map((grant, index) => [
|
|
2848
|
-
`${index + 1}. grantId: ${grant.grantId}`,
|
|
2849
|
-
` turnId: ${grant.turnId}`,
|
|
2850
|
-
` leaseId: ${grant.leaseId}`,
|
|
2851
|
-
` fencingToken: ${grant.fencingToken}`,
|
|
2852
|
-
` allowedScopes: ${grant.allowedScopes.join(", ")}`,
|
|
2853
|
-
` expiresAt: ${grant.expiresAt}`,
|
|
2854
|
-
` redactionStatus: ${grant.redactionStatus}`,
|
|
2855
|
-
" nonce: held by bridge",
|
|
2856
|
-
].join("\n")).join("\n\n")}`);
|
|
2857
|
-
}
|
|
2858
|
-
return sections.join("\n\n");
|
|
2859
|
-
}
|
|
2860
2754
|
function chatProviderExitFailure(command, result, redactionSecrets) {
|
|
2861
2755
|
const commandText = redactText(formatProviderCliCommandForCheckpoint(command), redactionSecrets);
|
|
2862
2756
|
const stderr = clip(redactText(result.stderr.trim(), redactionSecrets), 1000);
|
|
@@ -29,7 +29,7 @@ export interface HostRuntimeAdmissionCheckpoint {
|
|
|
29
29
|
}
|
|
30
30
|
export type HostRuntimeAdmissionCheckpointHandler = (checkpoint: HostRuntimeAdmissionCheckpoint) => void | Promise<void>;
|
|
31
31
|
export interface HostRuntimeProjectCheckpoint {
|
|
32
|
-
readonly code: "host_runtime_build_started" | "host_runtime_build_waiting_for_host_capacity" | "host_runtime_build_cached" | "host_runtime_build_completed" | "host_runtime_database_provisioned";
|
|
32
|
+
readonly code: "host_runtime_build_started" | "host_runtime_build_waiting_for_host_capacity" | "host_runtime_build_cached" | "host_runtime_build_completed" | "host_runtime_database_provisioned" | "host_runtime_contract_readmitted";
|
|
33
33
|
readonly message: string;
|
|
34
34
|
readonly data?: Readonly<Record<string, unknown>>;
|
|
35
35
|
}
|
|
@@ -23,7 +23,7 @@ import { AttemptNodeRuntimeLauncher } from "./attempt-node-runtime-launcher.js";
|
|
|
23
23
|
import { HostListenerInspector } from "./host-listener-inspector.js";
|
|
24
24
|
import { RecoveryStabilizedMemory, buildMemoryAdmissionDiagnostics, resolveAdaptiveMemoryReserveBytes, } from "./memory-capacity.js";
|
|
25
25
|
import { PlaywrightHostRuntimeAdapter } from "./playwright-host-runtime-adapter.js";
|
|
26
|
-
import { HostParallelPromotionStore, configuredLaunchPortNames, hostRuntimeContractFingerprint, hostRuntimeParallelEligible, } from "./host-runtime-promotion.js";
|
|
26
|
+
import { HostParallelPromotionStore, configuredLaunchPortNames, hostRuntimeContractFingerprint, hostRuntimeParallelEligible, readmitHostRuntimeContract, } from "./host-runtime-promotion.js";
|
|
27
27
|
import { ExactHostProcessRecovery, } from "../shared/process/host-process-recovery.js";
|
|
28
28
|
import { resetGeneratedOutputs } from "./generated-output-reset.js";
|
|
29
29
|
import { assertCanonicalDirectory, createCanonicalDirectory } from "./attempt-private-directory.js";
|
|
@@ -1418,12 +1418,13 @@ export class HostRuntimeLeaseManager {
|
|
|
1418
1418
|
}
|
|
1419
1419
|
}
|
|
1420
1420
|
async runConfiguredProjectRestart(active, dispatchAttemptId, fencingToken, signal, onProjectCheckpoint) {
|
|
1421
|
-
// The relaunch
|
|
1422
|
-
//
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1421
|
+
// The relaunch keeps the admission granted at start. A workspace contract that changed only its
|
|
1422
|
+
// launch environment is adopted; any other change throws host_runtime_contract_changed.
|
|
1423
|
+
const readmitted = readmitHostRuntimeContract(active, await loadHostRuntimeContract(active.lease.worktreePath));
|
|
1424
|
+
active.runtimeContract = readmitted.runtimeContract;
|
|
1425
|
+
active.runtimeContractFingerprint = readmitted.runtimeContractFingerprint;
|
|
1426
|
+
if (readmitted.changed) {
|
|
1427
|
+
await onProjectCheckpoint?.({ code: "host_runtime_contract_readmitted", message: "The workspace's runtime contract changed only its launch environment; the restart runs it under the admission granted at start." });
|
|
1427
1428
|
}
|
|
1428
1429
|
const portNames = active.executionClass === "analysis_only" ? [] : configuredLaunchPortNames(active.runtimeContract);
|
|
1429
1430
|
const pendingPort = portNames.find(name => active.pendingAdapterLaunches.has(name));
|
|
@@ -28,5 +28,28 @@ export declare class HostParallelPromotionStore {
|
|
|
28
28
|
private recordPath;
|
|
29
29
|
}
|
|
30
30
|
export declare function hostRuntimeContractFingerprint(runtimeContract: LoadedHostRuntimeContract): string;
|
|
31
|
+
export interface ReadmittedHostRuntimeContract {
|
|
32
|
+
readonly runtimeContract: LoadedHostRuntimeContract;
|
|
33
|
+
readonly runtimeContractFingerprint: string;
|
|
34
|
+
readonly changed: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Decides whether a restart may run the workspace's current runtime contract under the admission
|
|
38
|
+
* granted at start. A restart relaunches from the workspace in any case, so a contract whose only
|
|
39
|
+
* change is the values its ports launch with (launch environment, or discovery inputs that leave
|
|
40
|
+
* the contract itself unchanged) is adopted. This is how a conflict repair survives its own merge:
|
|
41
|
+
* merging the target branch can rename a variable in a derived launch profile, or change a
|
|
42
|
+
* manifest or project file, without changing anything admission granted. Every other part of the
|
|
43
|
+
* contract is admission: source, concurrency, ports (names, adapters, environment names, URL
|
|
44
|
+
* formats, and the command, arguments and working directory that launch them), Playwright, browser
|
|
45
|
+
* profile, singleton resources and declared requirements. Changing any of those throws the
|
|
46
|
+
* retryable host_runtime_contract_changed, so only a fresh attempt runs that contract. An attempt
|
|
47
|
+
* admitted to run in parallel keeps that admission, as it does when a merge changes only source;
|
|
48
|
+
* a restart never promotes, so the adopted contract earns no parallel-safety proof of its own here.
|
|
49
|
+
*/
|
|
50
|
+
export declare function readmitHostRuntimeContract(admitted: {
|
|
51
|
+
readonly runtimeContract: LoadedHostRuntimeContract;
|
|
52
|
+
readonly runtimeContractFingerprint: string;
|
|
53
|
+
}, current: LoadedHostRuntimeContract): ReadmittedHostRuntimeContract;
|
|
31
54
|
export declare function hostRuntimeParallelEligible(runtimeContract: LoadedHostRuntimeContract): boolean;
|
|
32
55
|
export declare function configuredLaunchPortNames(runtimeContract: LoadedHostRuntimeContract): readonly string[];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
2
|
import fs from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
import { ForgeFailureError } from "../session/session.types.js";
|
|
4
5
|
/** Persists only observed, contract-bound host parallel-safety evidence. */
|
|
5
6
|
export class HostParallelPromotionStore {
|
|
6
7
|
stateRoot;
|
|
@@ -154,6 +155,41 @@ export function hostRuntimeContractFingerprint(runtimeContract) {
|
|
|
154
155
|
});
|
|
155
156
|
return `sha256:${createHash("sha256").update(canonical).digest("hex")}`;
|
|
156
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Decides whether a restart may run the workspace's current runtime contract under the admission
|
|
160
|
+
* granted at start. A restart relaunches from the workspace in any case, so a contract whose only
|
|
161
|
+
* change is the values its ports launch with (launch environment, or discovery inputs that leave
|
|
162
|
+
* the contract itself unchanged) is adopted. This is how a conflict repair survives its own merge:
|
|
163
|
+
* merging the target branch can rename a variable in a derived launch profile, or change a
|
|
164
|
+
* manifest or project file, without changing anything admission granted. Every other part of the
|
|
165
|
+
* contract is admission: source, concurrency, ports (names, adapters, environment names, URL
|
|
166
|
+
* formats, and the command, arguments and working directory that launch them), Playwright, browser
|
|
167
|
+
* profile, singleton resources and declared requirements. Changing any of those throws the
|
|
168
|
+
* retryable host_runtime_contract_changed, so only a fresh attempt runs that contract. An attempt
|
|
169
|
+
* admitted to run in parallel keeps that admission, as it does when a merge changes only source;
|
|
170
|
+
* a restart never promotes, so the adopted contract earns no parallel-safety proof of its own here.
|
|
171
|
+
*/
|
|
172
|
+
export function readmitHostRuntimeContract(admitted, current) {
|
|
173
|
+
const runtimeContractFingerprint = hostRuntimeContractFingerprint(current);
|
|
174
|
+
// The fingerprint leaves out the source of a project or default contract, but parallel
|
|
175
|
+
// eligibility depends on it, so an unchanged fingerprint alone does not prove the same admission.
|
|
176
|
+
if (runtimeContractFingerprint === admitted.runtimeContractFingerprint && current.source === admitted.runtimeContract.source) {
|
|
177
|
+
return { runtimeContract: admitted.runtimeContract, runtimeContractFingerprint, changed: false };
|
|
178
|
+
}
|
|
179
|
+
if (hostRuntimeAdmissionShape(current) !== hostRuntimeAdmissionShape(admitted.runtimeContract)) {
|
|
180
|
+
throw new ForgeFailureError("host_runtime_contract_changed", "host_runtime_contract_changed: the workspace's runtime contract changed after this attempt's runtime was admitted; a fresh attempt is needed to run it.");
|
|
181
|
+
}
|
|
182
|
+
return { runtimeContract: current, runtimeContractFingerprint, changed: true };
|
|
183
|
+
}
|
|
184
|
+
function hostRuntimeAdmissionShape(runtimeContract) {
|
|
185
|
+
const runtime = runtimeContract.contract.runtime;
|
|
186
|
+
return JSON.stringify({
|
|
187
|
+
source: runtimeContract.source,
|
|
188
|
+
schemaVersion: runtimeContract.contract.schemaVersion,
|
|
189
|
+
runtime: { ...runtime, ports: runtime.ports.map(port => ({ ...port, launch: port.launch && { ...port.launch, environment: undefined } })) },
|
|
190
|
+
...requirementsFingerprintPart(runtimeContract.contract.requires),
|
|
191
|
+
});
|
|
192
|
+
}
|
|
157
193
|
// Cost hints are estimates, not placement constraints: they never change the fingerprint.
|
|
158
194
|
function requirementsFingerprintPart(requires) {
|
|
159
195
|
if (!requires)
|
|
@@ -536,6 +536,27 @@ export function toolInputSchema(phase, qaGate = null, decomposeGate = null, draf
|
|
|
536
536
|
ready_for_dev_test: { type: "boolean", default: true, description: "Required for pass and must be true." }
|
|
537
537
|
}, ["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
538
|
}
|
|
539
|
+
// Feature-to-Story candidate fields: schedule order, handoff to dependents, and whether the Story
|
|
540
|
+
// needs a design reference before Forge builds it.
|
|
541
|
+
const storyCandidateScheduleProperties = {
|
|
542
|
+
scheduleIndex: { type: "number", description: "Feature-to-Story total schedule order for dependency-safe execution." },
|
|
543
|
+
schedule_index: { type: "number", description: "Snake_case alias for scheduleIndex." },
|
|
544
|
+
waveIndex: { type: "number", description: "Feature-to-Story parallel wave number." },
|
|
545
|
+
wave_index: { type: "number", description: "Snake_case alias for waveIndex." },
|
|
546
|
+
featureScheduleIndex: { type: "number", description: "Optional ordering within the Feature." },
|
|
547
|
+
feature_schedule_index: { type: "number", description: "Snake_case alias for featureScheduleIndex." },
|
|
548
|
+
expectedOutput: { type: "string", description: "Durable output this Story should produce for dependents." },
|
|
549
|
+
expected_output: { type: "string", description: "Snake_case alias for expectedOutput." },
|
|
550
|
+
handoffSummary: { type: "string", description: "How dependent Stories should consume this Story output." },
|
|
551
|
+
handoff_summary: { type: "string", description: "Snake_case alias for handoffSummary." },
|
|
552
|
+
dependencyReason: { type: "string", description: "Why this Story depends on its dependsOn predecessors." },
|
|
553
|
+
dependency_reason: { type: "string", description: "Snake_case alias for dependencyReason." },
|
|
554
|
+
requiresDesign: {
|
|
555
|
+
type: "boolean",
|
|
556
|
+
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."
|
|
557
|
+
},
|
|
558
|
+
requires_design: { type: "boolean", description: "Snake_case alias for requiresDesign." }
|
|
559
|
+
};
|
|
539
560
|
function decomposeGateToolInputSchema(gate, phaseProperties) {
|
|
540
561
|
// Advertise every status the Decompose writer accepts, so the schema and the runtime agree.
|
|
541
562
|
const baseProperties = {
|
|
@@ -572,18 +593,7 @@ function decomposeGateToolInputSchema(gate, phaseProperties) {
|
|
|
572
593
|
acceptanceCriteria: { type: "string" },
|
|
573
594
|
planningPacket: { type: "string" },
|
|
574
595
|
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." },
|
|
596
|
+
...storyCandidateScheduleProperties,
|
|
587
597
|
points: { type: "number" },
|
|
588
598
|
dependsOn: { type: "array", items: { type: "string" } },
|
|
589
599
|
estimatedQaScope: qaScopeSchema("Work Order-to-Feature planning QA estimate. This is not dispatch-authoritative QA scope."),
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
private dotnetCompileFailed;
|
|
33
|
+
/** A failed runtime restart before the pass is its first failure. */
|
|
34
|
+
constructor(runtimeRestartFailure?: PrePublicationValidationError | undefined);
|
|
35
|
+
record(failure: PrePublicationCheckFailure, failedStep?: ValidationStep): void;
|
|
36
|
+
/** The failed checks that keep this check from running meaningfully in this pass. */
|
|
37
|
+
blockers(checkId: string): readonly string[];
|
|
38
|
+
/**
|
|
39
|
+
* Whether an error ends the pass with the failures it already found. Only a classified retryable
|
|
40
|
+
* failure (a resource hold, lost infrastructure, a supervisor that did not start) does, once the
|
|
41
|
+
* pass has found a failure: the repair turn can fix those failures now, and the next pass meets
|
|
42
|
+
* the condition again. Any other error, or cancellation, still ends the attempt as it did.
|
|
43
|
+
*/
|
|
44
|
+
stopsAt(error: unknown, signal?: AbortSignal): error is ForgeFailureError;
|
|
45
|
+
stoppedEvent(checkId: string, error: ForgeFailureError): RunnerDispatchEvent;
|
|
46
|
+
/** Throws every failure the pass found as one validation failure. */
|
|
47
|
+
throwIfFailed(): void;
|
|
48
|
+
}
|
|
49
|
+
export declare function skippedCheckEvent(checkId: string, blockedBy: readonly string[]): RunnerDispatchEvent;
|
|
50
|
+
/** The tests a check's steps skipped, so a check that passed with skips says so with each reason. */
|
|
51
|
+
export declare class SkippedTestTally {
|
|
52
|
+
private readonly worktreePath;
|
|
53
|
+
private readonly environment?;
|
|
54
|
+
private summary;
|
|
55
|
+
constructor(worktreePath: string, environment?: Readonly<Record<string, string>> | undefined);
|
|
56
|
+
/** The invocation's own arguments: a managed attempt may direct results to its test-output root. */
|
|
57
|
+
add(args: readonly string[], stepStartedMs: number): Promise<void>;
|
|
58
|
+
passedEvent(checkId: string, secrets: readonly string[]): RunnerDispatchEvent;
|
|
59
|
+
}
|
|
60
|
+
export declare function validationEvent(eventType: string, checkId: string, content: string, detail?: Readonly<Record<string, unknown>>): RunnerDispatchEvent;
|