@loucompanion/forge-bridge 0.1.4-dev.b33004c2b0ea → 0.1.4-dev.bb5355d0d83f
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 +13 -0
- package/dist/bridge/bridge-chat-provider-command.d.ts +16 -0
- package/dist/bridge/bridge-chat-provider-command.js +137 -0
- package/dist/bridge/bridge-chat.types.d.ts +10 -0
- package/dist/bridge/bridge-chat.types.js +16 -1
- package/dist/bridge/bridge.service.d.ts +1 -1
- package/dist/bridge/bridge.service.js +4 -110
- package/dist/bridge/runner-host-capabilities.d.ts +3 -0
- package/dist/bridge/runner-host-capabilities.js +13 -0
- package/dist/runtime/attempt-database-broker.d.ts +1 -1
- package/dist/runtime/docker-engine-probe.d.ts +5 -0
- package/dist/runtime/docker-engine-probe.js +7 -0
- package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
- package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
- package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
- package/dist/runtime/ephemeral-test-postgres.js +303 -0
- package/dist/runtime/host-facts.d.ts +2 -1
- package/dist/runtime/host-load-admission.d.ts +9 -2
- package/dist/runtime/host-load-child-environment.d.ts +11 -6
- package/dist/runtime/host-load-child-environment.js +19 -10
- package/dist/runtime/host-load-governor-config.d.ts +10 -1
- package/dist/runtime/host-load-governor-config.js +7 -0
- package/dist/runtime/host-load-governor.d.ts +10 -0
- package/dist/runtime/host-load-governor.js +125 -34
- 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-lease.d.ts +1 -1
- package/dist/runtime/host-runtime-lease.js +1 -1
- package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
- package/dist/runtime/native-test-postgres-fallback.js +60 -8
- package/dist/sandbox/host-capacity-broker.d.ts +7 -1
- package/dist/sandbox/host-capacity-broker.js +23 -4
- 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 +51 -62
- 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.runtime.js +1 -1
- 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 +2 -1
- package/dist/session/pre-publication-pass.js +8 -5
- 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 +9 -3
- package/dist/session/pre-publication-validation.js +62 -34
- 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/provider-cli.child-environment.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +73 -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 +13 -22
- package/dist/session/provider-cli/provider-cli.process.js +36 -337
- 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.js +2 -8
- 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-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/sandbox-host-capacity-gate.js +12 -3
- package/dist/session/session.types.js +1 -1
- 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 +5 -6
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { ForgeFailureError } from "../session.types.js";
|
|
2
|
+
import type { ProviderProcessHandlers, ProviderProcessRunner, ProviderProcessRunRequest, ProviderProcessRunResult } from "./provider-cli.process.js";
|
|
3
|
+
/**
|
|
4
|
+
* Removes the `run_in_background` parameter from Bash, PowerShell and the Agent tool, runs
|
|
5
|
+
* forked subagents and forked skills in the foreground, and stops Claude Code from moving long
|
|
6
|
+
* shell commands, subagents and MCP calls to the background on its own. Cron disables the
|
|
7
|
+
* session-scoped scheduled tasks (`CronCreate`, `/loop`). Applied last, so a project's runtime
|
|
8
|
+
* environment cannot turn them back on.
|
|
9
|
+
*/
|
|
10
|
+
export declare const claudeHeadlessEnvironment: Readonly<Record<string, string>>;
|
|
11
|
+
/**
|
|
12
|
+
* Tools whose only purpose is work that reports after the turn. `CLAUDE_CODE_DISABLE_BACKGROUND_TASKS`
|
|
13
|
+
* leaves Monitor running in the background, so it is removed here, together with self-paced
|
|
14
|
+
* wakeups, workflows (which run their agents in the background), cloud routines, cron
|
|
15
|
+
* (also disabled by environment), SendMessage, which resumes an earlier subagent in the
|
|
16
|
+
* background, and agent teams, whose teammates run alongside the turn. Foreground subagents
|
|
17
|
+
* stay available: they block the turn until they finish.
|
|
18
|
+
*/
|
|
19
|
+
export declare const claudeHeadlessDisallowedTools: readonly string[];
|
|
20
|
+
/**
|
|
21
|
+
* The Claude Code arguments that apply the restrictions: the tool deny list, and the environment
|
|
22
|
+
* again as flag settings, which outrank a user's or repository's settings `env` block.
|
|
23
|
+
*/
|
|
24
|
+
export declare function claudeHeadlessToolArgs(): readonly string[];
|
|
25
|
+
/**
|
|
26
|
+
* The provider ended its turn while background work it started (a background subagent or
|
|
27
|
+
* shell, a Monitor watch, a wakeup) was still live. Claude Code withholds the turn's terminal
|
|
28
|
+
* result for such work, and nothing started in the background reports to Forge, so Forge stops
|
|
29
|
+
* the provider at once instead of waiting for an idle watchdog. Retryable: the harness, not the
|
|
30
|
+
* task, ended the run.
|
|
31
|
+
*/
|
|
32
|
+
export declare function providerTurnEndedWithBackgroundWorkFailure(message: string): ForgeFailureError;
|
|
33
|
+
/**
|
|
34
|
+
* Fails every provider run Forge stopped because its turn ended with background work still live,
|
|
35
|
+
* whether or not the turn recorded a completion first: the stop cut that work short, so nothing
|
|
36
|
+
* may validate, commit or publish the worktree it left behind.
|
|
37
|
+
*/
|
|
38
|
+
export declare class BackgroundWorkStopFailingRunner implements ProviderProcessRunner {
|
|
39
|
+
private readonly inner;
|
|
40
|
+
constructor(inner: ProviderProcessRunner);
|
|
41
|
+
run(request: ProviderProcessRunRequest, handlers?: ProviderProcessHandlers, signal?: AbortSignal): Promise<ProviderProcessRunResult>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Recognizes a main-conversation turn that ended while background tasks it started were still
|
|
45
|
+
* live, the case in which Claude Code withholds the turn's `result`. The turn end is Claude
|
|
46
|
+
* Code's `post_turn_summary` event; the live set is the documented `background_tasks_changed`
|
|
47
|
+
* event (Claude Code's own `ambient` tasks and `awaited` ones do not count). After `graceMs`
|
|
48
|
+
* without the result or new main-conversation activity, it calls `onTurnEndedWithBackgroundWork`
|
|
49
|
+
* once, so the runner can stop the provider instead of waiting on work no one will collect.
|
|
50
|
+
*/
|
|
51
|
+
export declare class ClaudeBackgroundTurnEndWatch {
|
|
52
|
+
private readonly graceMs;
|
|
53
|
+
private readonly onTurnEndedWithBackgroundWork;
|
|
54
|
+
private liveBackgroundTasks;
|
|
55
|
+
private terminalSinceMainActivity;
|
|
56
|
+
private mainTurnEnded;
|
|
57
|
+
private timer;
|
|
58
|
+
private stopped;
|
|
59
|
+
private readonly enabled;
|
|
60
|
+
/** Watches only Claude Code, by its executable `command`; other output is left alone. */
|
|
61
|
+
constructor(command: string, graceMs: number, onTurnEndedWithBackgroundWork: () => void);
|
|
62
|
+
consume(line: string): void;
|
|
63
|
+
stop(): void;
|
|
64
|
+
private armIfTurnEndedWithBackgroundWork;
|
|
65
|
+
private cancel;
|
|
66
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless Claude Code runs must not start work that outlives the turn.
|
|
3
|
+
*
|
|
4
|
+
* Forge runs `claude -p` and treats the turn's terminal `result` event as the end of the run.
|
|
5
|
+
* When background work is still live at the end of a turn (a background subagent or shell, a
|
|
6
|
+
* Monitor watch, a scheduled wakeup), Claude Code withholds that `result` and keeps the process
|
|
7
|
+
* open for the work, so Forge sees a silent provider instead of a finished one. The launch
|
|
8
|
+
* restrictions below remove the ways to start such work; `ClaudeBackgroundTurnEndWatch` is the
|
|
9
|
+
* backstop for anything that still gets through.
|
|
10
|
+
*/
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
import { ForgeFailureError } from "../session.types.js";
|
|
13
|
+
/**
|
|
14
|
+
* Removes the `run_in_background` parameter from Bash, PowerShell and the Agent tool, runs
|
|
15
|
+
* forked subagents and forked skills in the foreground, and stops Claude Code from moving long
|
|
16
|
+
* shell commands, subagents and MCP calls to the background on its own. Cron disables the
|
|
17
|
+
* session-scoped scheduled tasks (`CronCreate`, `/loop`). Applied last, so a project's runtime
|
|
18
|
+
* environment cannot turn them back on.
|
|
19
|
+
*/
|
|
20
|
+
export const claudeHeadlessEnvironment = Object.freeze({
|
|
21
|
+
CLAUDE_CODE_DISABLE_BACKGROUND_TASKS: "1",
|
|
22
|
+
CLAUDE_CODE_DISABLE_CRON: "1",
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* Tools whose only purpose is work that reports after the turn. `CLAUDE_CODE_DISABLE_BACKGROUND_TASKS`
|
|
26
|
+
* leaves Monitor running in the background, so it is removed here, together with self-paced
|
|
27
|
+
* wakeups, workflows (which run their agents in the background), cloud routines, cron
|
|
28
|
+
* (also disabled by environment), SendMessage, which resumes an earlier subagent in the
|
|
29
|
+
* background, and agent teams, whose teammates run alongside the turn. Foreground subagents
|
|
30
|
+
* stay available: they block the turn until they finish.
|
|
31
|
+
*/
|
|
32
|
+
export const claudeHeadlessDisallowedTools = Object.freeze([
|
|
33
|
+
"Monitor",
|
|
34
|
+
"ScheduleWakeup",
|
|
35
|
+
"Workflow",
|
|
36
|
+
"RemoteTrigger",
|
|
37
|
+
"CronCreate",
|
|
38
|
+
"SendMessage",
|
|
39
|
+
"TeamCreate",
|
|
40
|
+
]);
|
|
41
|
+
/**
|
|
42
|
+
* The Claude Code arguments that apply the restrictions: the tool deny list, and the environment
|
|
43
|
+
* again as flag settings, which outrank a user's or repository's settings `env` block.
|
|
44
|
+
*/
|
|
45
|
+
export function claudeHeadlessToolArgs() {
|
|
46
|
+
return [
|
|
47
|
+
"--disallowedTools", claudeHeadlessDisallowedTools.join(","),
|
|
48
|
+
"--settings", JSON.stringify({ env: claudeHeadlessEnvironment }),
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The provider ended its turn while background work it started (a background subagent or
|
|
53
|
+
* shell, a Monitor watch, a wakeup) was still live. Claude Code withholds the turn's terminal
|
|
54
|
+
* result for such work, and nothing started in the background reports to Forge, so Forge stops
|
|
55
|
+
* the provider at once instead of waiting for an idle watchdog. Retryable: the harness, not the
|
|
56
|
+
* task, ended the run.
|
|
57
|
+
*/
|
|
58
|
+
export function providerTurnEndedWithBackgroundWorkFailure(message) {
|
|
59
|
+
return new ForgeFailureError("provider_turn_ended_with_background_work", `${message} The provider ended its turn while background work it started was still running, so it never delivered a terminal result; Forge stopped it instead of waiting.`);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Fails every provider run Forge stopped because its turn ended with background work still live,
|
|
63
|
+
* whether or not the turn recorded a completion first: the stop cut that work short, so nothing
|
|
64
|
+
* may validate, commit or publish the worktree it left behind.
|
|
65
|
+
*/
|
|
66
|
+
export class BackgroundWorkStopFailingRunner {
|
|
67
|
+
inner;
|
|
68
|
+
constructor(inner) {
|
|
69
|
+
this.inner = inner;
|
|
70
|
+
}
|
|
71
|
+
async run(request, handlers, signal) {
|
|
72
|
+
const result = await this.inner.run(request, handlers, signal);
|
|
73
|
+
if (result.terminalStopReason === "turn_ended_with_background_work") {
|
|
74
|
+
throw providerTurnEndedWithBackgroundWorkFailure("The provider turn did not finish.");
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Recognizes a main-conversation turn that ended while background tasks it started were still
|
|
81
|
+
* live, the case in which Claude Code withholds the turn's `result`. The turn end is Claude
|
|
82
|
+
* Code's `post_turn_summary` event; the live set is the documented `background_tasks_changed`
|
|
83
|
+
* event (Claude Code's own `ambient` tasks and `awaited` ones do not count). After `graceMs`
|
|
84
|
+
* without the result or new main-conversation activity, it calls `onTurnEndedWithBackgroundWork`
|
|
85
|
+
* once, so the runner can stop the provider instead of waiting on work no one will collect.
|
|
86
|
+
*/
|
|
87
|
+
export class ClaudeBackgroundTurnEndWatch {
|
|
88
|
+
graceMs;
|
|
89
|
+
onTurnEndedWithBackgroundWork;
|
|
90
|
+
liveBackgroundTasks = 0;
|
|
91
|
+
terminalSinceMainActivity = false;
|
|
92
|
+
mainTurnEnded = false;
|
|
93
|
+
timer = null;
|
|
94
|
+
stopped = false;
|
|
95
|
+
enabled;
|
|
96
|
+
/** Watches only Claude Code, by its executable `command`; other output is left alone. */
|
|
97
|
+
constructor(command, graceMs, onTurnEndedWithBackgroundWork) {
|
|
98
|
+
this.graceMs = graceMs;
|
|
99
|
+
this.onTurnEndedWithBackgroundWork = onTurnEndedWithBackgroundWork;
|
|
100
|
+
this.enabled = path.parse(command).name.toLowerCase() === "claude";
|
|
101
|
+
}
|
|
102
|
+
consume(line) {
|
|
103
|
+
if (!this.enabled || this.stopped)
|
|
104
|
+
return;
|
|
105
|
+
const event = parseStreamEvent(line);
|
|
106
|
+
if (!event)
|
|
107
|
+
return;
|
|
108
|
+
if (isTerminalEvent(event)) {
|
|
109
|
+
this.terminalSinceMainActivity = true;
|
|
110
|
+
this.cancel();
|
|
111
|
+
}
|
|
112
|
+
else if (event.type === "system" && event.subtype === "background_tasks_changed") {
|
|
113
|
+
this.liveBackgroundTasks = liveBackgroundTaskCount(event.tasks);
|
|
114
|
+
// The work settled: Claude Code now delivers the result or starts a turn for it, and a
|
|
115
|
+
// follow-up turn can think for a while before its first event.
|
|
116
|
+
if (this.liveBackgroundTasks === 0)
|
|
117
|
+
this.cancel();
|
|
118
|
+
// A task can be reported just after the turn summary, as the turn ends.
|
|
119
|
+
else if (this.mainTurnEnded)
|
|
120
|
+
this.armIfTurnEndedWithBackgroundWork();
|
|
121
|
+
}
|
|
122
|
+
else if (event.type === "system" && event.subtype === "post_turn_summary") {
|
|
123
|
+
this.mainTurnEnded = true;
|
|
124
|
+
this.armIfTurnEndedWithBackgroundWork();
|
|
125
|
+
}
|
|
126
|
+
else if ((event.type === "assistant" || event.type === "user") && !event.parent_tool_use_id) {
|
|
127
|
+
// The main conversation is working again (a new turn, or a turn that is still going).
|
|
128
|
+
this.terminalSinceMainActivity = false;
|
|
129
|
+
this.mainTurnEnded = false;
|
|
130
|
+
this.cancel();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
stop() {
|
|
134
|
+
this.stopped = true;
|
|
135
|
+
this.cancel();
|
|
136
|
+
}
|
|
137
|
+
armIfTurnEndedWithBackgroundWork() {
|
|
138
|
+
if (this.timer || this.terminalSinceMainActivity || this.liveBackgroundTasks === 0)
|
|
139
|
+
return;
|
|
140
|
+
this.timer = setTimeout(() => {
|
|
141
|
+
this.timer = null;
|
|
142
|
+
this.stopped = true;
|
|
143
|
+
this.onTurnEndedWithBackgroundWork();
|
|
144
|
+
}, this.graceMs);
|
|
145
|
+
this.timer.unref?.();
|
|
146
|
+
}
|
|
147
|
+
cancel() {
|
|
148
|
+
if (!this.timer)
|
|
149
|
+
return;
|
|
150
|
+
clearTimeout(this.timer);
|
|
151
|
+
this.timer = null;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function parseStreamEvent(line) {
|
|
155
|
+
const trimmed = line.trim();
|
|
156
|
+
if (!trimmed.startsWith("{"))
|
|
157
|
+
return null;
|
|
158
|
+
try {
|
|
159
|
+
const parsed = JSON.parse(trimmed);
|
|
160
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function isTerminalEvent(event) {
|
|
167
|
+
return event.type === "result" || event.type === "error";
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Tasks that keep the turn's result back: not Claude Code's own `ambient` tasks, and not
|
|
171
|
+
* `awaited` ones, which a still-running tool call of the turn waits for.
|
|
172
|
+
*/
|
|
173
|
+
function liveBackgroundTaskCount(tasks) {
|
|
174
|
+
if (!Array.isArray(tasks))
|
|
175
|
+
return 0;
|
|
176
|
+
return tasks.filter(task => {
|
|
177
|
+
const entry = task && typeof task === "object" ? task : {};
|
|
178
|
+
return entry.ambient !== true && entry.awaited !== true;
|
|
179
|
+
}).length;
|
|
180
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface ProviderChildEnvironmentOptions {
|
|
2
|
+
readonly parentEnv?: NodeJS.ProcessEnv;
|
|
3
|
+
readonly platform?: NodeJS.Platform;
|
|
4
|
+
readonly homeDir?: string;
|
|
5
|
+
readonly arch?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function buildProviderChildEnvironment(requestEnv?: Readonly<Record<string, string>>, options?: ProviderChildEnvironmentOptions): NodeJS.ProcessEnv;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
import { normalizeWindowsProviderEnvironment, windowsAllowedProviderParentEnvNames } from "./provider-cli.windows-environment.js";
|
|
3
|
+
// The environment a provider child process starts with: an allowlist of the Bridge's own
|
|
4
|
+
// variables, the request's values, the Windows defaults, then the .NET build-server settings.
|
|
5
|
+
const allowedProviderParentEnvNames = [
|
|
6
|
+
"PATH",
|
|
7
|
+
"HOME",
|
|
8
|
+
"USERPROFILE",
|
|
9
|
+
"TMPDIR",
|
|
10
|
+
"TEMP",
|
|
11
|
+
"TMP",
|
|
12
|
+
"LANG",
|
|
13
|
+
"CLAUDE_CONFIG_DIR"
|
|
14
|
+
];
|
|
15
|
+
export function buildProviderChildEnvironment(requestEnv, options = {}) {
|
|
16
|
+
const parentEnv = options.parentEnv ?? process.env;
|
|
17
|
+
const platform = options.platform ?? process.platform;
|
|
18
|
+
const env = {};
|
|
19
|
+
for (const [key, value] of Object.entries(parentEnv)) {
|
|
20
|
+
if (typeof value === "string" && isAllowedProviderParentEnv(key, platform)) {
|
|
21
|
+
env[key] = value;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (requestEnv) {
|
|
25
|
+
for (const [key, value] of Object.entries(requestEnv)) {
|
|
26
|
+
const trimmedKey = key.trim();
|
|
27
|
+
if (trimmedKey.length > 0) {
|
|
28
|
+
env[trimmedKey] = value;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (platform === "win32") {
|
|
33
|
+
normalizeWindowsProviderEnvironment(env, parentEnv, options.homeDir ?? os.homedir(), options.arch ?? os.arch());
|
|
34
|
+
}
|
|
35
|
+
normalizeProviderBuildEnvironment(env);
|
|
36
|
+
return env;
|
|
37
|
+
}
|
|
38
|
+
function normalizeProviderBuildEnvironment(env) {
|
|
39
|
+
// Provider sessions are long lived and commonly run many dotnet builds. Persistent
|
|
40
|
+
// MSBuild and Roslyn compiler servers otherwise survive individual commands and can
|
|
41
|
+
// retain more memory than the active Forge lane. Keep those caches process-scoped by
|
|
42
|
+
// default on every runner OS; an explicitly supplied request value still wins.
|
|
43
|
+
setCanonicalProviderBuildEnvironmentValue(env, "DOTNET_CLI_USE_MSBUILD_SERVER", "0");
|
|
44
|
+
setCanonicalProviderBuildEnvironmentValue(env, "MSBUILDDISABLENODEREUSE", "1");
|
|
45
|
+
setCanonicalProviderBuildEnvironmentValue(env, "UseSharedCompilation", "false");
|
|
46
|
+
}
|
|
47
|
+
function setCanonicalProviderBuildEnvironmentValue(env, name, value) {
|
|
48
|
+
// The dotnet CLI uses case-sensitive environment lookup on POSIX, while MSBuild
|
|
49
|
+
// property names are case-insensitive on every OS. Collapse request aliases to
|
|
50
|
+
// one canonical key so the explicit value wins without producing ambiguity.
|
|
51
|
+
const exact = env[name];
|
|
52
|
+
const alias = Object.entries(env).find(([key, candidate]) => key !== name
|
|
53
|
+
&& key.toLowerCase() === name.toLowerCase()
|
|
54
|
+
&& typeof candidate === "string"
|
|
55
|
+
&& candidate.trim().length > 0)?.[1];
|
|
56
|
+
const resolved = typeof exact === "string" && exact.trim().length > 0
|
|
57
|
+
? exact
|
|
58
|
+
: alias ?? value;
|
|
59
|
+
for (const key of Object.keys(env)) {
|
|
60
|
+
if (key !== name && key.toLowerCase() === name.toLowerCase()) {
|
|
61
|
+
delete env[key];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
env[name] = resolved;
|
|
65
|
+
}
|
|
66
|
+
function isAllowedProviderParentEnv(key, platform = process.platform) {
|
|
67
|
+
return isAllowedProviderParentEnvName(key, allowedProviderParentEnvNames)
|
|
68
|
+
|| key.toUpperCase().startsWith("LC_")
|
|
69
|
+
|| (platform === "win32" && isAllowedProviderParentEnvName(key, windowsAllowedProviderParentEnvNames));
|
|
70
|
+
}
|
|
71
|
+
function isAllowedProviderParentEnvName(key, allowedNames) {
|
|
72
|
+
return allowedNames.some((allowed) => allowed.toLowerCase() === key.toLowerCase());
|
|
73
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ProviderProcessRunResult } from "./provider-cli.process.js";
|
|
2
|
+
export declare function isCodexModelsCacheSchemaFailure(result: ProviderProcessRunResult): boolean;
|
|
3
|
+
export declare function quarantineIncompatibleCodexModelsCache(requestEnv?: Readonly<Record<string, string>>): Promise<boolean>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { readEnvironmentValue } from "./provider-cli.windows-environment.js";
|
|
6
|
+
const maximumRecoverableCodexModelsCacheBytes = 16 * 1024 * 1024;
|
|
7
|
+
export function isCodexModelsCacheSchemaFailure(result) {
|
|
8
|
+
const output = `${result.stderr}\n${result.stdout}`.toLowerCase();
|
|
9
|
+
return output.includes("base_instructions")
|
|
10
|
+
&& output.includes("missing field")
|
|
11
|
+
&& (output.includes("models_cache") || output.includes("models cache") || output.includes("model cache"));
|
|
12
|
+
}
|
|
13
|
+
export async function quarantineIncompatibleCodexModelsCache(requestEnv) {
|
|
14
|
+
const configuredHome = readEnvironmentValue(requestEnv ?? {}, "CODEX_HOME")
|
|
15
|
+
?? readEnvironmentValue(process.env, "CODEX_HOME")
|
|
16
|
+
?? readEnvironmentValue(process.env, "FORGE_CODEX_HOME");
|
|
17
|
+
const codexHome = path.resolve(configuredHome ?? path.join(os.homedir(), ".codex"));
|
|
18
|
+
if (!path.isAbsolute(codexHome) || codexHome === path.parse(codexHome).root)
|
|
19
|
+
return false;
|
|
20
|
+
const cachePath = path.join(codexHome, "models_cache.json");
|
|
21
|
+
const cacheStat = await fs.promises.lstat(cachePath).catch(error => {
|
|
22
|
+
if (error.code === "ENOENT")
|
|
23
|
+
return null;
|
|
24
|
+
throw error;
|
|
25
|
+
});
|
|
26
|
+
if (!cacheStat
|
|
27
|
+
|| !cacheStat.isFile()
|
|
28
|
+
|| cacheStat.isSymbolicLink()
|
|
29
|
+
|| cacheStat.nlink !== 1
|
|
30
|
+
|| cacheStat.size <= 0
|
|
31
|
+
|| cacheStat.size > maximumRecoverableCodexModelsCacheBytes) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
const quarantinePath = path.join(codexHome, `models_cache.forge-incompatible-${Date.now()}-${randomUUID()}.json`);
|
|
35
|
+
await fs.promises.rename(cachePath, quarantinePath);
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type LaunchCommand } from "../../shared/process/windows-launch.js";
|
|
2
2
|
import { ForgeFailureError } from "../session.types.js";
|
|
3
|
+
export { chooseWindowsCommandCandidate, resolveWindowsCommandFromPath } from "../../shared/process/windows-launch.js";
|
|
4
|
+
export { buildProviderChildEnvironment, type ProviderChildEnvironmentOptions } from "./provider-cli.child-environment.js";
|
|
3
5
|
export declare const PROVIDER_OUTPUT_CAPTURE_LIMIT_CHARS: number;
|
|
4
6
|
export type ProviderCliCommand = LaunchCommand;
|
|
5
7
|
export interface ProviderProcessRunRequest {
|
|
@@ -22,8 +24,8 @@ export interface ProviderProcessRunRequest {
|
|
|
22
24
|
*/
|
|
23
25
|
readonly resumesProviderThread?: boolean;
|
|
24
26
|
}
|
|
25
|
-
/** Why Forge stopped a provider
|
|
26
|
-
export type ProviderTerminalStopReason = "turn_exit_grace" | "success_ceiling";
|
|
27
|
+
/** Why Forge stopped a provider still resident after its turn (or its background work, for Claude). */
|
|
28
|
+
export type ProviderTerminalStopReason = "turn_exit_grace" | "success_ceiling" | "turn_ended_with_background_work";
|
|
27
29
|
export interface ProviderProcessRunResult {
|
|
28
30
|
readonly exitCode: number;
|
|
29
31
|
readonly stdout: string;
|
|
@@ -34,8 +36,10 @@ export interface ProviderProcessRunResult {
|
|
|
34
36
|
readonly memoryObservedAt?: string;
|
|
35
37
|
/** Present when the caller's cancellation stopped the process before it exited on its own. */
|
|
36
38
|
readonly cancelled?: true;
|
|
37
|
-
/** Present when Forge stopped a provider that stayed resident after
|
|
39
|
+
/** Present when Forge stopped a provider that stayed resident after its turn ended. */
|
|
38
40
|
readonly terminalStopReason?: ProviderTerminalStopReason;
|
|
41
|
+
/** Present when Forge closed output pipes a descendant still held after the provider exited. */
|
|
42
|
+
readonly outputPipesReleasedAfterExit?: true;
|
|
39
43
|
}
|
|
40
44
|
export interface ProviderProcessRunner {
|
|
41
45
|
run(request: ProviderProcessRunRequest, handlers?: ProviderProcessHandlers, signal?: AbortSignal): Promise<ProviderProcessRunResult>;
|
|
@@ -59,7 +63,8 @@ export interface ProviderProcessHandlers {
|
|
|
59
63
|
onGenerationStart?(): void;
|
|
60
64
|
}
|
|
61
65
|
/** Recovery must wrap the attempt coordinator, never its raw OS runner. Each
|
|
62
|
-
* relaunch needs a new fenced child generation and exclusive launch files.
|
|
66
|
+
* relaunch needs a new fenced child generation and exclusive launch files. The outer
|
|
67
|
+
* layer fails any run Forge stopped because its turn ended with background work live. */
|
|
63
68
|
export declare function recoveringProviderProcessRunner(inner: ProviderProcessRunner): ProviderProcessRunner;
|
|
64
69
|
/**
|
|
65
70
|
* Codex Desktop and an independently installed Codex CLI can briefly disagree
|
|
@@ -88,23 +93,18 @@ export declare class CodexResumeRecoveringProcessRunner implements ProviderProce
|
|
|
88
93
|
* arbitrary tool/command output and therefore cannot mint retry authority.
|
|
89
94
|
*/
|
|
90
95
|
export declare function isTransientCodexProviderNotFoundFailure(command: string, result: ProviderProcessRunResult): boolean;
|
|
91
|
-
interface ProviderChildEnvironmentOptions {
|
|
92
|
-
readonly parentEnv?: NodeJS.ProcessEnv;
|
|
93
|
-
readonly platform?: NodeJS.Platform;
|
|
94
|
-
readonly homeDir?: string;
|
|
95
|
-
}
|
|
96
|
-
export declare function buildProviderChildEnvironment(requestEnv?: Readonly<Record<string, string>>, options?: ProviderChildEnvironmentOptions): NodeJS.ProcessEnv;
|
|
97
96
|
export declare class StreamingProviderProcessRunner implements ProviderProcessRunner {
|
|
98
97
|
private readonly terminalExitGraceMs;
|
|
99
98
|
private readonly terminalSuccessCeilingMs;
|
|
100
99
|
private readonly terminalWorkPollMs;
|
|
101
|
-
|
|
100
|
+
private readonly outputPipeReleaseGraceMs;
|
|
101
|
+
constructor(terminalExitGraceMs?: number, terminalSuccessCeilingMs?: number, terminalWorkPollMs?: number, outputPipeReleaseGraceMs?: number);
|
|
102
102
|
run(request: ProviderProcessRunRequest, handlers?: ProviderProcessHandlers, signal?: AbortSignal): Promise<ProviderProcessRunResult>;
|
|
103
103
|
}
|
|
104
104
|
/**
|
|
105
105
|
* The typed failure for a provider run that ended without calling its required Forge
|
|
106
|
-
* completion tool. A run Forge stopped at the success ceiling
|
|
107
|
-
* is not mistaken for an agent that simply ended its turn.
|
|
106
|
+
* completion tool. A run Forge stopped at the success ceiling or for background work is
|
|
107
|
+
* reported as such, so it is not mistaken for an agent that simply ended its turn.
|
|
108
108
|
*/
|
|
109
109
|
export declare function providerCompletionToolMissingFailure(message: string, result?: Pick<ProviderProcessRunResult, "terminalStopReason"> | null): ForgeFailureError;
|
|
110
110
|
/** Returns aggregate resident bytes for the exact supervised Unix process group. */
|
|
@@ -124,12 +124,3 @@ export declare function resolveClaudeNpmDirectLaunch(commandPath: string, args:
|
|
|
124
124
|
* wrapped by the Windows Job Object supervisor.
|
|
125
125
|
*/
|
|
126
126
|
export declare function resolvePackageManagerDirectLaunch(commandPath: string, args: readonly string[]): LaunchCommand | null;
|
|
127
|
-
/**
|
|
128
|
-
* Resolves Windows commands without spawning where.exe. Runtime launches can
|
|
129
|
-
* happen while the machine is under enough process pressure for where.exe to
|
|
130
|
-
* miss its timeout; returning the unresolved package-manager name in that case
|
|
131
|
-
* makes Node fall back to a shell shim that cannot survive Job Object wrapping.
|
|
132
|
-
*/
|
|
133
|
-
export declare function resolveWindowsCommandFromPath(command: string, pathValue?: string, pathExtValue?: string): string | null;
|
|
134
|
-
export declare function chooseWindowsCommandCandidate(candidates: readonly string[]): string | null;
|
|
135
|
-
export {};
|