@loucompanion/forge-bridge 0.1.4-dev.028808a841c8 → 0.1.4-dev.03584818ede5
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 +57 -2
- 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.base.d.ts +9 -0
- package/dist/bridge/bridge.service.d.ts +73 -2
- package/dist/bridge/bridge.service.js +312 -119
- package/dist/bridge/bridge.types.d.ts +16 -0
- package/dist/bridge/local-yield-flag.d.ts +6 -0
- package/dist/bridge/local-yield-flag.js +34 -0
- package/dist/bridge/runner-host-capabilities.d.ts +5 -0
- package/dist/bridge/runner-host-capabilities.js +17 -0
- package/dist/bridge/test-postgres-capability.d.ts +14 -0
- package/dist/bridge/test-postgres-capability.js +120 -0
- package/dist/cleanup/cleanup.service.d.ts +9 -0
- package/dist/cleanup/cleanup.service.js +72 -109
- package/dist/cleanup/cleanup.types.d.ts +4 -0
- package/dist/cleanup/forge-owned-paths.d.ts +9 -0
- package/dist/cleanup/forge-owned-paths.js +53 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +5 -0
- package/dist/cleanup/host-runtime-ledger.js +109 -0
- package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
- package/dist/cleanup/managed-branch-sweep.js +111 -0
- package/dist/cli/cli.help.js +18 -0
- package/dist/cli/cli.service.d.ts +16 -0
- package/dist/cli/cli.service.js +142 -16
- package/dist/cli/local-config.d.ts +4 -0
- package/dist/cli/local-config.js +26 -4
- package/dist/runtime/aspnet-runtime-prebuild.js +94 -6
- package/dist/runtime/host-facts.d.ts +2 -1
- package/dist/runtime/host-load-admission.d.ts +67 -0
- package/dist/runtime/host-load-admission.js +99 -0
- package/dist/runtime/host-load-child-environment.d.ts +27 -0
- package/dist/runtime/host-load-child-environment.js +76 -0
- package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
- package/dist/runtime/host-load-forge-cgroups.js +140 -0
- package/dist/runtime/host-load-governor-config.d.ts +52 -0
- package/dist/runtime/host-load-governor-config.js +83 -0
- package/dist/runtime/host-load-governor.d.ts +184 -0
- package/dist/runtime/host-load-governor.js +632 -0
- package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
- package/dist/runtime/host-load-ledger-lock.js +185 -0
- package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
- package/dist/runtime/host-load-runtime-settings.js +78 -0
- package/dist/runtime/host-load-sampler.d.ts +68 -2
- package/dist/runtime/host-load-sampler.js +135 -8
- package/dist/runtime/host-load-step-class.d.ts +70 -0
- package/dist/runtime/host-load-step-class.js +161 -0
- package/dist/runtime/host-load-step-reaper.d.ts +27 -0
- package/dist/runtime/host-load-step-reaper.js +95 -0
- package/dist/runtime/host-load-step-run.d.ts +73 -0
- package/dist/runtime/host-load-step-run.js +102 -0
- package/dist/runtime/host-load-test-slot.d.ts +43 -0
- package/dist/runtime/host-load-test-slot.js +81 -0
- package/dist/runtime/host-load-token-ledger.d.ts +200 -0
- package/dist/runtime/host-load-token-ledger.js +453 -0
- package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
- package/dist/runtime/host-load-windows-cpu.js +85 -0
- package/dist/runtime/host-pressure-stall.d.ts +21 -1
- package/dist/runtime/host-pressure-stall.js +48 -1
- package/dist/runtime/host-runtime-contract.d.ts +3 -0
- package/dist/runtime/host-runtime-contract.js +4 -1
- package/dist/runtime/host-runtime-lease.d.ts +74 -4
- package/dist/runtime/host-runtime-lease.js +281 -11
- package/dist/runtime/host-runtime-promotion.d.ts +23 -0
- package/dist/runtime/host-runtime-promotion.js +48 -0
- package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
- package/dist/runtime/host-runtime-requirements-check.js +29 -0
- package/dist/runtime/host-runtime-requirements.d.ts +36 -0
- package/dist/runtime/host-runtime-requirements.js +117 -0
- package/dist/runtime/playwright-host-runtime-adapter.d.ts +7 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
- package/dist/runtime/runner-settings.d.ts +100 -0
- package/dist/runtime/runner-settings.js +214 -0
- package/dist/sandbox/host-capacity-broker.d.ts +113 -0
- package/dist/sandbox/host-capacity-broker.js +334 -0
- package/dist/sandbox/runtime.d.ts +10 -1
- package/dist/sandbox/runtime.js +45 -2
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -0
- package/dist/session/architect-waits.d.ts +2 -0
- package/dist/session/architect-waits.js +138 -0
- package/dist/session/managed-attempt-tools.d.ts +2 -0
- package/dist/session/managed-attempt-tools.js +157 -39
- package/dist/session/managed-command-host-load.d.ts +47 -0
- package/dist/session/managed-command-host-load.js +83 -0
- package/dist/session/mcp-argument-coercion.d.ts +23 -0
- package/dist/session/mcp-argument-coercion.js +121 -0
- package/dist/session/phase-completion.artifacts.d.ts +7 -0
- package/dist/session/phase-completion.artifacts.js +94 -25
- package/dist/session/phase-completion.command-validation.d.ts +7 -0
- package/dist/session/phase-completion.command-validation.js +77 -0
- package/dist/session/phase-completion.d.ts +4 -0
- package/dist/session/phase-completion.helpers.js +13 -12
- package/dist/session/phase-completion.js +4 -0
- package/dist/session/phase-completion.prompts.js +6 -1
- package/dist/session/phase-completion.runtime.d.ts +5 -3
- package/dist/session/phase-completion.runtime.js +49 -19
- package/dist/session/phase-completion.schema-parts.d.ts +19 -0
- package/dist/session/phase-completion.schema-parts.js +188 -0
- package/dist/session/phase-completion.schemas.d.ts +3 -3
- package/dist/session/phase-completion.schemas.js +208 -231
- package/dist/session/phase-completion.validation.d.ts +2 -3
- package/dist/session/phase-completion.validation.js +49 -93
- package/dist/session/pre-publication-host-load.d.ts +27 -0
- package/dist/session/pre-publication-host-load.js +111 -0
- package/dist/session/pre-publication-pass.d.ts +61 -0
- package/dist/session/pre-publication-pass.js +148 -0
- package/dist/session/pre-publication-process.d.ts +3 -0
- package/dist/session/pre-publication-process.js +23 -11
- package/dist/session/pre-publication-step-execution.d.ts +11 -0
- package/dist/session/pre-publication-step-execution.js +49 -0
- package/dist/session/pre-publication-validation.d.ts +32 -20
- package/dist/session/pre-publication-validation.js +195 -158
- 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.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 +20 -22
- package/dist/session/provider-cli/provider-cli.process.js +51 -344
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +2 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +50 -10
- package/dist/session/provider-cli/provider-cli.runtime.js +7 -0
- package/dist/session/provider-cli/provider-cli.service.d.ts +4 -1
- package/dist/session/provider-cli/provider-cli.service.js +107 -153
- package/dist/session/provider-cli/provider-cli.types.d.ts +30 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
- package/dist/session/provider-cli/provider-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.d.ts +30 -0
- package/dist/session/sandbox-host-capacity-gate.js +238 -0
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.service.d.ts +9 -2
- package/dist/session/session.service.js +120 -5
- package/dist/session/session.types.d.ts +3 -0
- package/dist/session/session.types.js +4 -4
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -0
- package/dist/shared/process/host-process-supervisor.d.ts +1 -0
- package/dist/shared/process/host-process-supervisor.js +1 -1
- package/dist/shared/process/process-tree.d.ts +52 -0
- package/dist/shared/process/process-tree.js +144 -0
- package/dist/shared/process/process.d.ts +67 -0
- package/dist/shared/process/process.js +213 -11
- package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
- package/dist/shared/process/windows-app-execution-alias.js +45 -0
- package/dist/shared/process/windows-launch.d.ts +18 -0
- package/dist/shared/process/windows-launch.js +68 -0
- package/dist/shared/provider-capabilities.js +5 -6
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/dependency-warmer.d.ts +25 -0
- package/dist/worktree/dependency-warmer.js +46 -10
- package/dist/worktree/worktree.service.d.ts +10 -1
- package/dist/worktree/worktree.service.js +42 -2
- package/dist/worktree/worktree.types.d.ts +7 -0
- package/package.json +2 -2
|
@@ -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>;
|
|
@@ -50,9 +54,17 @@ export interface ProviderProcessHandlers {
|
|
|
50
54
|
* end-of-turn exit grace and the success ceiling.
|
|
51
55
|
*/
|
|
52
56
|
isToolCallInFlight?(): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Called before each provider generation (child process) starts, including every
|
|
59
|
+
* relaunch a recovery wrapper or supervisor makes with the same handlers. Per-generation
|
|
60
|
+
* state, such as tool calls in flight, must be reset here: a generation that exited mid
|
|
61
|
+
* call never reports that call's completion.
|
|
62
|
+
*/
|
|
63
|
+
onGenerationStart?(): void;
|
|
53
64
|
}
|
|
54
65
|
/** Recovery must wrap the attempt coordinator, never its raw OS runner. Each
|
|
55
|
-
* 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. */
|
|
56
68
|
export declare function recoveringProviderProcessRunner(inner: ProviderProcessRunner): ProviderProcessRunner;
|
|
57
69
|
/**
|
|
58
70
|
* Codex Desktop and an independently installed Codex CLI can briefly disagree
|
|
@@ -81,23 +93,18 @@ export declare class CodexResumeRecoveringProcessRunner implements ProviderProce
|
|
|
81
93
|
* arbitrary tool/command output and therefore cannot mint retry authority.
|
|
82
94
|
*/
|
|
83
95
|
export declare function isTransientCodexProviderNotFoundFailure(command: string, result: ProviderProcessRunResult): boolean;
|
|
84
|
-
interface ProviderChildEnvironmentOptions {
|
|
85
|
-
readonly parentEnv?: NodeJS.ProcessEnv;
|
|
86
|
-
readonly platform?: NodeJS.Platform;
|
|
87
|
-
readonly homeDir?: string;
|
|
88
|
-
}
|
|
89
|
-
export declare function buildProviderChildEnvironment(requestEnv?: Readonly<Record<string, string>>, options?: ProviderChildEnvironmentOptions): NodeJS.ProcessEnv;
|
|
90
96
|
export declare class StreamingProviderProcessRunner implements ProviderProcessRunner {
|
|
91
97
|
private readonly terminalExitGraceMs;
|
|
92
98
|
private readonly terminalSuccessCeilingMs;
|
|
93
99
|
private readonly terminalWorkPollMs;
|
|
94
|
-
|
|
100
|
+
private readonly outputPipeReleaseGraceMs;
|
|
101
|
+
constructor(terminalExitGraceMs?: number, terminalSuccessCeilingMs?: number, terminalWorkPollMs?: number, outputPipeReleaseGraceMs?: number);
|
|
95
102
|
run(request: ProviderProcessRunRequest, handlers?: ProviderProcessHandlers, signal?: AbortSignal): Promise<ProviderProcessRunResult>;
|
|
96
103
|
}
|
|
97
104
|
/**
|
|
98
105
|
* The typed failure for a provider run that ended without calling its required Forge
|
|
99
|
-
* completion tool. A run Forge stopped at the success ceiling
|
|
100
|
-
* 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.
|
|
101
108
|
*/
|
|
102
109
|
export declare function providerCompletionToolMissingFailure(message: string, result?: Pick<ProviderProcessRunResult, "terminalStopReason"> | null): ForgeFailureError;
|
|
103
110
|
/** Returns aggregate resident bytes for the exact supervised Unix process group. */
|
|
@@ -117,12 +124,3 @@ export declare function resolveClaudeNpmDirectLaunch(commandPath: string, args:
|
|
|
117
124
|
* wrapped by the Windows Job Object supervisor.
|
|
118
125
|
*/
|
|
119
126
|
export declare function resolvePackageManagerDirectLaunch(commandPath: string, args: readonly string[]): LaunchCommand | null;
|
|
120
|
-
/**
|
|
121
|
-
* Resolves Windows commands without spawning where.exe. Runtime launches can
|
|
122
|
-
* happen while the machine is under enough process pressure for where.exe to
|
|
123
|
-
* miss its timeout; returning the unresolved package-manager name in that case
|
|
124
|
-
* makes Node fall back to a shell shim that cannot survive Job Object wrapping.
|
|
125
|
-
*/
|
|
126
|
-
export declare function resolveWindowsCommandFromPath(command: string, pathValue?: string, pathExtValue?: string): string | null;
|
|
127
|
-
export declare function chooseWindowsCommandCandidate(candidates: readonly string[]): string | null;
|
|
128
|
-
export {};
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { execFile, execFileSync, spawn } from "node:child_process";
|
|
2
|
-
import { randomUUID } from "node:crypto";
|
|
3
2
|
import fs from "node:fs";
|
|
4
|
-
import os from "node:os";
|
|
5
3
|
import path from "node:path";
|
|
6
|
-
import readline from "node:readline";
|
|
7
4
|
import { promisify } from "node:util";
|
|
8
5
|
import { resolveCursorAgentDirectLaunch } from "../../shared/cursor-agent/cursor-agent.launch.js";
|
|
9
6
|
import { persistHostProcessSupervisorMetadata, resolveHostProcessSupervisedLaunch, terminateHostProcessTree, } from "../../shared/process/host-process-supervisor.js";
|
|
10
|
-
import { buildWindowsLaunchCommand } from "../../shared/process/windows-launch.js";
|
|
7
|
+
import { buildWindowsLaunchCommand, chooseWindowsCommandCandidate, resolveWindowsCommandFromPath } from "../../shared/process/windows-launch.js";
|
|
8
|
+
import { buildProviderChildEnvironment } from "./provider-cli.child-environment.js";
|
|
9
|
+
import { isCodexModelsCacheSchemaFailure, quarantineIncompatibleCodexModelsCache } from "./provider-cli.codex-models-cache.js";
|
|
11
10
|
import { assertHostDatabaseCapabilityBoundary } from "../../runtime/host-database-capability-boundary.js";
|
|
12
11
|
import { ForgeFailureError } from "../session.types.js";
|
|
13
|
-
import {
|
|
12
|
+
import { BackgroundWorkStopFailingRunner, ClaudeBackgroundTurnEndWatch, providerTurnEndedWithBackgroundWorkFailure } from "./claude-background-work.js";
|
|
13
|
+
import { hasNonterminalManagedCommand, isProviderTerminalFailure, isProviderTerminalSuccess, isProviderTurnActivity } from "./provider-in-flight-work.js";
|
|
14
|
+
import { OutputPipeRelease, readProcessLines, PROVIDER_OUTPUT_PIPE_RELEASE_GRACE_MS } from "./provider-output-pipes.js";
|
|
15
|
+
export { chooseWindowsCommandCandidate, resolveWindowsCommandFromPath } from "../../shared/process/windows-launch.js";
|
|
16
|
+
export { buildProviderChildEnvironment } from "./provider-cli.child-environment.js";
|
|
14
17
|
const execFileAsync = promisify(execFile);
|
|
15
18
|
// Provider processes can emit many gigabytes over a long-running session. The
|
|
16
19
|
// line handlers stream that output to Forge as it arrives; the completed result
|
|
@@ -23,11 +26,11 @@ const PROVIDER_TERMINAL_EXIT_GRACE_MS = 15_000;
|
|
|
23
26
|
const PROVIDER_TERMINAL_SUCCESS_CEILING_MS = 10 * 60_000;
|
|
24
27
|
// How often the end-of-turn timers re-check whether supervised work is still in flight.
|
|
25
28
|
const PROVIDER_TERMINAL_WORK_POLL_MS = 1_000;
|
|
26
|
-
const maximumRecoverableCodexModelsCacheBytes = 16 * 1024 * 1024;
|
|
27
29
|
/** Recovery must wrap the attempt coordinator, never its raw OS runner. Each
|
|
28
|
-
* relaunch needs a new fenced child generation and exclusive launch files.
|
|
30
|
+
* relaunch needs a new fenced child generation and exclusive launch files. The outer
|
|
31
|
+
* layer fails any run Forge stopped because its turn ended with background work live. */
|
|
29
32
|
export function recoveringProviderProcessRunner(inner) {
|
|
30
|
-
return new CodexResumeRecoveringProcessRunner(new CodexModelsCacheRecoveringProcessRunner(inner));
|
|
33
|
+
return new BackgroundWorkStopFailingRunner(new CodexResumeRecoveringProcessRunner(new CodexModelsCacheRecoveringProcessRunner(inner)));
|
|
31
34
|
}
|
|
32
35
|
/**
|
|
33
36
|
* Codex Desktop and an independently installed Codex CLI can briefly disagree
|
|
@@ -51,6 +54,7 @@ export class CodexModelsCacheRecoveringProcessRunner {
|
|
|
51
54
|
const recovered = await quarantineIncompatibleCodexModelsCache(request.env).catch(() => false);
|
|
52
55
|
if (!recovered || signal?.aborted)
|
|
53
56
|
return first;
|
|
57
|
+
handlers?.onGenerationStart?.();
|
|
54
58
|
return await this.inner.run(request, handlers, signal);
|
|
55
59
|
}
|
|
56
60
|
}
|
|
@@ -73,7 +77,10 @@ export class CodexResumeRecoveringProcessRunner {
|
|
|
73
77
|
return first;
|
|
74
78
|
}
|
|
75
79
|
const fallback = codexFreshTurnRequest(request);
|
|
76
|
-
|
|
80
|
+
if (!fallback)
|
|
81
|
+
return first;
|
|
82
|
+
handlers?.onGenerationStart?.();
|
|
83
|
+
return await this.inner.run(fallback, handlers, signal);
|
|
77
84
|
}
|
|
78
85
|
}
|
|
79
86
|
function isRecoverableCodexResumeFailure(command, result) {
|
|
@@ -111,224 +118,27 @@ function codexFreshTurnRequest(request) {
|
|
|
111
118
|
const cd = args.splice(cdIndex, 2);
|
|
112
119
|
args.splice(args.length - 1, 0, ...cd);
|
|
113
120
|
}
|
|
114
|
-
|
|
121
|
+
// The fallback starts a fresh thread, so it has no replayed turn to discount.
|
|
122
|
+
return { ...request, args, resumesProviderThread: false };
|
|
115
123
|
}
|
|
116
124
|
function isCodexCommand(command) {
|
|
117
125
|
return path.parse(command).name.toLowerCase() === "codex";
|
|
118
126
|
}
|
|
119
|
-
function isCodexModelsCacheSchemaFailure(result) {
|
|
120
|
-
const output = `${result.stderr}\n${result.stdout}`.toLowerCase();
|
|
121
|
-
return output.includes("base_instructions")
|
|
122
|
-
&& output.includes("missing field")
|
|
123
|
-
&& (output.includes("models_cache") || output.includes("models cache") || output.includes("model cache"));
|
|
124
|
-
}
|
|
125
|
-
async function quarantineIncompatibleCodexModelsCache(requestEnv) {
|
|
126
|
-
const configuredHome = readEnvironmentValue(requestEnv ?? {}, "CODEX_HOME")
|
|
127
|
-
?? readEnvironmentValue(process.env, "CODEX_HOME")
|
|
128
|
-
?? readEnvironmentValue(process.env, "FORGE_CODEX_HOME");
|
|
129
|
-
const codexHome = path.resolve(configuredHome ?? path.join(os.homedir(), ".codex"));
|
|
130
|
-
if (!path.isAbsolute(codexHome) || codexHome === path.parse(codexHome).root)
|
|
131
|
-
return false;
|
|
132
|
-
const cachePath = path.join(codexHome, "models_cache.json");
|
|
133
|
-
const cacheStat = await fs.promises.lstat(cachePath).catch(error => {
|
|
134
|
-
if (error.code === "ENOENT")
|
|
135
|
-
return null;
|
|
136
|
-
throw error;
|
|
137
|
-
});
|
|
138
|
-
if (!cacheStat
|
|
139
|
-
|| !cacheStat.isFile()
|
|
140
|
-
|| cacheStat.isSymbolicLink()
|
|
141
|
-
|| cacheStat.nlink !== 1
|
|
142
|
-
|| cacheStat.size <= 0
|
|
143
|
-
|| cacheStat.size > maximumRecoverableCodexModelsCacheBytes) {
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
|
-
const quarantinePath = path.join(codexHome, `models_cache.forge-incompatible-${Date.now()}-${randomUUID()}.json`);
|
|
147
|
-
await fs.promises.rename(cachePath, quarantinePath);
|
|
148
|
-
return true;
|
|
149
|
-
}
|
|
150
|
-
const allowedProviderParentEnvNames = [
|
|
151
|
-
"PATH",
|
|
152
|
-
"HOME",
|
|
153
|
-
"USERPROFILE",
|
|
154
|
-
"TMPDIR",
|
|
155
|
-
"TEMP",
|
|
156
|
-
"TMP",
|
|
157
|
-
"LANG",
|
|
158
|
-
"CLAUDE_CONFIG_DIR"
|
|
159
|
-
];
|
|
160
|
-
const windowsAllowedProviderParentEnvNames = [
|
|
161
|
-
"SystemRoot",
|
|
162
|
-
"SystemDrive",
|
|
163
|
-
"ComSpec",
|
|
164
|
-
"PATHEXT",
|
|
165
|
-
"APPDATA",
|
|
166
|
-
"LOCALAPPDATA",
|
|
167
|
-
"USERNAME",
|
|
168
|
-
"USERDOMAIN",
|
|
169
|
-
"HOMEDRIVE",
|
|
170
|
-
"HOMEPATH",
|
|
171
|
-
"ProgramData",
|
|
172
|
-
"ProgramFiles",
|
|
173
|
-
"ProgramFiles(x86)",
|
|
174
|
-
"ProgramW6432",
|
|
175
|
-
"DOTNET_ROOT",
|
|
176
|
-
"DOTNET_ROOT(x86)",
|
|
177
|
-
"DOTNET_CLI_HOME",
|
|
178
|
-
"NUGET_PACKAGES",
|
|
179
|
-
"NUGET_HTTP_CACHE_PATH",
|
|
180
|
-
"CLAUDE_CODE_GIT_BASH_PATH"
|
|
181
|
-
];
|
|
182
|
-
export function buildProviderChildEnvironment(requestEnv, options = {}) {
|
|
183
|
-
const parentEnv = options.parentEnv ?? process.env;
|
|
184
|
-
const platform = options.platform ?? process.platform;
|
|
185
|
-
const env = {};
|
|
186
|
-
for (const [key, value] of Object.entries(parentEnv)) {
|
|
187
|
-
if (typeof value === "string" && isAllowedProviderParentEnv(key, platform)) {
|
|
188
|
-
env[key] = value;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
if (requestEnv) {
|
|
192
|
-
for (const [key, value] of Object.entries(requestEnv)) {
|
|
193
|
-
const trimmedKey = key.trim();
|
|
194
|
-
if (trimmedKey.length > 0) {
|
|
195
|
-
env[trimmedKey] = value;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
if (platform === "win32") {
|
|
200
|
-
normalizeWindowsDotNetEnvironment(env, parentEnv, options.homeDir ?? os.homedir());
|
|
201
|
-
}
|
|
202
|
-
normalizeProviderBuildEnvironment(env);
|
|
203
|
-
return env;
|
|
204
|
-
}
|
|
205
|
-
function normalizeProviderBuildEnvironment(env) {
|
|
206
|
-
// Provider sessions are long lived and commonly run many dotnet builds. Persistent
|
|
207
|
-
// MSBuild and Roslyn compiler servers otherwise survive individual commands and can
|
|
208
|
-
// retain more memory than the active Forge lane. Keep those caches process-scoped by
|
|
209
|
-
// default on every runner OS; an explicitly supplied request value still wins.
|
|
210
|
-
setCanonicalProviderBuildEnvironmentValue(env, "DOTNET_CLI_USE_MSBUILD_SERVER", "0");
|
|
211
|
-
setCanonicalProviderBuildEnvironmentValue(env, "MSBUILDDISABLENODEREUSE", "1");
|
|
212
|
-
setCanonicalProviderBuildEnvironmentValue(env, "UseSharedCompilation", "false");
|
|
213
|
-
}
|
|
214
|
-
function setCanonicalProviderBuildEnvironmentValue(env, name, value) {
|
|
215
|
-
// The dotnet CLI uses case-sensitive environment lookup on POSIX, while MSBuild
|
|
216
|
-
// property names are case-insensitive on every OS. Collapse request aliases to
|
|
217
|
-
// one canonical key so the explicit value wins without producing ambiguity.
|
|
218
|
-
const exact = env[name];
|
|
219
|
-
const alias = Object.entries(env).find(([key, candidate]) => key !== name
|
|
220
|
-
&& key.toLowerCase() === name.toLowerCase()
|
|
221
|
-
&& typeof candidate === "string"
|
|
222
|
-
&& candidate.trim().length > 0)?.[1];
|
|
223
|
-
const resolved = typeof exact === "string" && exact.trim().length > 0
|
|
224
|
-
? exact
|
|
225
|
-
: alias ?? value;
|
|
226
|
-
for (const key of Object.keys(env)) {
|
|
227
|
-
if (key !== name && key.toLowerCase() === name.toLowerCase()) {
|
|
228
|
-
delete env[key];
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
env[name] = resolved;
|
|
232
|
-
}
|
|
233
|
-
function isAllowedProviderParentEnv(key, platform = process.platform) {
|
|
234
|
-
return isAllowedProviderParentEnvName(key, allowedProviderParentEnvNames)
|
|
235
|
-
|| key.toUpperCase().startsWith("LC_")
|
|
236
|
-
|| (platform === "win32" && isAllowedProviderParentEnvName(key, windowsAllowedProviderParentEnvNames));
|
|
237
|
-
}
|
|
238
|
-
function isAllowedProviderParentEnvName(key, allowedNames) {
|
|
239
|
-
return allowedNames.some((allowed) => allowed.toLowerCase() === key.toLowerCase());
|
|
240
|
-
}
|
|
241
|
-
function normalizeWindowsDotNetEnvironment(env, parentEnv, homeDir) {
|
|
242
|
-
const systemRoot = readEnvironmentValue(env, "SystemRoot") ?? readEnvironmentValue(parentEnv, "SystemRoot") ?? "C:\\Windows";
|
|
243
|
-
const systemDrive = path.win32.parse(systemRoot).root.replace(/\\$/, "") || "C:";
|
|
244
|
-
setEnvironmentValueIfMissing(env, "SystemRoot", systemRoot);
|
|
245
|
-
setEnvironmentValueIfMissing(env, "SystemDrive", readEnvironmentValue(parentEnv, "SystemDrive") ?? systemDrive);
|
|
246
|
-
setEnvironmentValueIfMissing(env, "ComSpec", readEnvironmentValue(parentEnv, "ComSpec") ?? path.win32.join(systemRoot, "System32", "cmd.exe"));
|
|
247
|
-
setEnvironmentValueIfMissing(env, "PATHEXT", readEnvironmentValue(parentEnv, "PATHEXT") ?? ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.CPL");
|
|
248
|
-
const resolvedSystemDrive = readEnvironmentValue(env, "SystemDrive") ?? systemDrive;
|
|
249
|
-
const defaultProgramFiles = path.win32.join(`${resolvedSystemDrive}\\`, "Program Files");
|
|
250
|
-
const defaultProgramFilesX86 = path.win32.join(`${resolvedSystemDrive}\\`, "Program Files (x86)");
|
|
251
|
-
const defaultProgramData = path.win32.join(`${resolvedSystemDrive}\\`, "ProgramData");
|
|
252
|
-
const programFiles = readEnvironmentValue(env, "ProgramFiles")
|
|
253
|
-
?? readEnvironmentValue(parentEnv, "ProgramFiles")
|
|
254
|
-
?? defaultProgramFiles;
|
|
255
|
-
setEnvironmentValueIfMissing(env, "ProgramFiles", programFiles);
|
|
256
|
-
setEnvironmentValueIfMissing(env, "ProgramW6432", readEnvironmentValue(parentEnv, "ProgramW6432") ?? defaultProgramFiles);
|
|
257
|
-
setEnvironmentValueIfMissing(env, "ProgramFiles(x86)", readEnvironmentValue(parentEnv, "ProgramFiles(x86)") ?? defaultProgramFilesX86);
|
|
258
|
-
setEnvironmentValueIfMissing(env, "ProgramData", readEnvironmentValue(parentEnv, "ProgramData") ?? defaultProgramData);
|
|
259
|
-
const userProfile = resolveWindowsUserProfile(env, parentEnv, homeDir);
|
|
260
|
-
if (userProfile) {
|
|
261
|
-
setEnvironmentValueIfMissing(env, "USERPROFILE", userProfile);
|
|
262
|
-
setEnvironmentValueIfMissing(env, "HOME", userProfile);
|
|
263
|
-
setEnvironmentValueIfMissing(env, "DOTNET_CLI_HOME", userProfile);
|
|
264
|
-
setEnvironmentValueIfMissing(env, "NUGET_PACKAGES", path.win32.join(userProfile, ".nuget", "packages"));
|
|
265
|
-
const parsed = path.win32.parse(userProfile);
|
|
266
|
-
if (parsed.root) {
|
|
267
|
-
setEnvironmentValueIfMissing(env, "HOMEDRIVE", parsed.root.replace(/\\$/, ""));
|
|
268
|
-
setEnvironmentValueIfMissing(env, "HOMEPATH", userProfile.slice(parsed.root.length - (parsed.root.endsWith("\\") ? 1 : 0)) || "\\");
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
const appData = readEnvironmentValue(env, "APPDATA")
|
|
272
|
-
?? readEnvironmentValue(parentEnv, "APPDATA")
|
|
273
|
-
?? (userProfile ? path.win32.join(userProfile, "AppData", "Roaming") : undefined);
|
|
274
|
-
const localAppData = readEnvironmentValue(env, "LOCALAPPDATA")
|
|
275
|
-
?? readEnvironmentValue(parentEnv, "LOCALAPPDATA")
|
|
276
|
-
?? (userProfile ? path.win32.join(userProfile, "AppData", "Local") : undefined);
|
|
277
|
-
if (appData) {
|
|
278
|
-
setEnvironmentValueIfMissing(env, "APPDATA", appData);
|
|
279
|
-
}
|
|
280
|
-
if (localAppData) {
|
|
281
|
-
setEnvironmentValueIfMissing(env, "LOCALAPPDATA", localAppData);
|
|
282
|
-
setEnvironmentValueIfMissing(env, "NUGET_HTTP_CACHE_PATH", path.win32.join(localAppData, "NuGet", "v3-cache"));
|
|
283
|
-
}
|
|
284
|
-
setEnvironmentValueIfMissing(env, "DOTNET_NOLOGO", "1");
|
|
285
|
-
setEnvironmentValueIfMissing(env, "DOTNET_CLI_TELEMETRY_OPTOUT", "1");
|
|
286
|
-
setEnvironmentValueIfMissing(env, "DOTNET_SKIP_FIRST_TIME_EXPERIENCE", "1");
|
|
287
|
-
setEnvironmentValueIfMissing(env, "NUGET_XMLDOC_MODE", "skip");
|
|
288
|
-
}
|
|
289
|
-
function resolveWindowsUserProfile(env, parentEnv, homeDir) {
|
|
290
|
-
const existing = readEnvironmentValue(env, "USERPROFILE") ?? readEnvironmentValue(parentEnv, "USERPROFILE");
|
|
291
|
-
if (existing) {
|
|
292
|
-
return existing;
|
|
293
|
-
}
|
|
294
|
-
const home = readEnvironmentValue(env, "HOME") ?? readEnvironmentValue(parentEnv, "HOME");
|
|
295
|
-
if (home && path.win32.isAbsolute(home)) {
|
|
296
|
-
return home;
|
|
297
|
-
}
|
|
298
|
-
const homeDrive = readEnvironmentValue(env, "HOMEDRIVE") ?? readEnvironmentValue(parentEnv, "HOMEDRIVE");
|
|
299
|
-
const homePath = readEnvironmentValue(env, "HOMEPATH") ?? readEnvironmentValue(parentEnv, "HOMEPATH");
|
|
300
|
-
if (homeDrive && homePath) {
|
|
301
|
-
return `${homeDrive}${homePath}`;
|
|
302
|
-
}
|
|
303
|
-
if (homeDir && path.win32.isAbsolute(homeDir)) {
|
|
304
|
-
return homeDir;
|
|
305
|
-
}
|
|
306
|
-
const systemDrive = readEnvironmentValue(env, "SystemDrive") ?? readEnvironmentValue(parentEnv, "SystemDrive") ?? "C:";
|
|
307
|
-
const username = readEnvironmentValue(env, "USERNAME") ?? readEnvironmentValue(parentEnv, "USERNAME");
|
|
308
|
-
return username ? path.win32.join(systemDrive, "Users", username) : undefined;
|
|
309
|
-
}
|
|
310
|
-
function readEnvironmentValue(env, name) {
|
|
311
|
-
const entry = Object.entries(env).find(([key]) => key.toLowerCase() === name.toLowerCase());
|
|
312
|
-
const value = entry?.[1];
|
|
313
|
-
return typeof value === "string" && value.trim().length > 0 ? value : undefined;
|
|
314
|
-
}
|
|
315
|
-
function setEnvironmentValueIfMissing(env, name, value) {
|
|
316
|
-
if (readEnvironmentValue(env, name)) {
|
|
317
|
-
return;
|
|
318
|
-
}
|
|
319
|
-
env[name] = value;
|
|
320
|
-
}
|
|
321
127
|
export class StreamingProviderProcessRunner {
|
|
322
128
|
terminalExitGraceMs;
|
|
323
129
|
terminalSuccessCeilingMs;
|
|
324
130
|
terminalWorkPollMs;
|
|
325
|
-
|
|
131
|
+
outputPipeReleaseGraceMs;
|
|
132
|
+
constructor(terminalExitGraceMs = PROVIDER_TERMINAL_EXIT_GRACE_MS, terminalSuccessCeilingMs = PROVIDER_TERMINAL_SUCCESS_CEILING_MS, terminalWorkPollMs = PROVIDER_TERMINAL_WORK_POLL_MS, outputPipeReleaseGraceMs = PROVIDER_OUTPUT_PIPE_RELEASE_GRACE_MS) {
|
|
326
133
|
this.terminalExitGraceMs = terminalExitGraceMs;
|
|
327
134
|
this.terminalSuccessCeilingMs = terminalSuccessCeilingMs;
|
|
328
135
|
this.terminalWorkPollMs = terminalWorkPollMs;
|
|
136
|
+
this.outputPipeReleaseGraceMs = outputPipeReleaseGraceMs;
|
|
329
137
|
}
|
|
330
138
|
async run(request, handlers = {}, signal) {
|
|
331
139
|
assertHostDatabaseCapabilityBoundary();
|
|
140
|
+
// Every child this runner launches is a new generation, including supervisor retries.
|
|
141
|
+
handlers.onGenerationStart?.();
|
|
332
142
|
const providerLaunch = await resolveProviderProcessLaunch(request.command, request.args);
|
|
333
143
|
const supervisedLaunch = resolveHostProcessSupervisedLaunch(request, providerLaunch.command, providerLaunch.args);
|
|
334
144
|
// An unsupervised Unix provider still gets a dedicated process group so a
|
|
@@ -372,11 +182,12 @@ export class StreamingProviderProcessRunner {
|
|
|
372
182
|
const childStderr = child.stderr;
|
|
373
183
|
if (!childStdout || !childStderr) {
|
|
374
184
|
const pipeError = new Error("Provider process stdout/stderr streams were not piped.");
|
|
375
|
-
void terminate().then(() => reject(pipeError), terminationError => reject(new AggregateError([pipeError, terminationError], "Provider launch failed and its process tree could not be proven stopped.")));
|
|
185
|
+
void terminate().then(() => reject(pipeError), terminationError => reject(new AggregateError([pipeError, terminationError], "host_process_supervisor_termination_failed: Provider launch failed and its process tree could not be proven stopped.")));
|
|
376
186
|
return;
|
|
377
187
|
}
|
|
378
188
|
const stdout = new BoundedOutputTail(PROVIDER_OUTPUT_CAPTURE_LIMIT_CHARS);
|
|
379
189
|
const stderr = new BoundedOutputTail(PROVIDER_OUTPUT_CAPTURE_LIMIT_CHARS);
|
|
190
|
+
const outputPipes = new OutputPipeRelease(child, this.outputPipeReleaseGraceMs, message => stderr.appendLine(message));
|
|
380
191
|
let settled = false;
|
|
381
192
|
let closed = false;
|
|
382
193
|
let cancellationRequested = false;
|
|
@@ -394,8 +205,10 @@ export class StreamingProviderProcessRunner {
|
|
|
394
205
|
let terminalWorkTickRunning = false;
|
|
395
206
|
let latestTurnFailed = false;
|
|
396
207
|
let readiness = null;
|
|
208
|
+
const backgroundTurnEnd = new ClaudeBackgroundTurnEndWatch(request.command, this.terminalExitGraceMs, () => finishAfterTerminalSuccess("turn_ended_with_background_work"));
|
|
397
209
|
const cleanup = () => {
|
|
398
210
|
stopTerminalWorkTimer();
|
|
211
|
+
backgroundTurnEnd.stop();
|
|
399
212
|
graceIdleMs = null;
|
|
400
213
|
ceilingIdleMs = null;
|
|
401
214
|
signal?.removeEventListener("abort", abort);
|
|
@@ -408,7 +221,7 @@ export class StreamingProviderProcessRunner {
|
|
|
408
221
|
cleanup();
|
|
409
222
|
// Do not release the caller's reservation/worktree/port ownership until
|
|
410
223
|
// descendant termination has completed (or failed with explicit proof).
|
|
411
|
-
void terminate().then(() => reject(error), terminationError => reject(new AggregateError([error, terminationError], "Provider process failed and its process tree could not be proven stopped.")));
|
|
224
|
+
void terminate().then(() => reject(error), terminationError => reject(new AggregateError([error, terminationError], "host_process_supervisor_termination_failed: Provider process failed and its process tree could not be proven stopped.")));
|
|
412
225
|
};
|
|
413
226
|
const abort = () => {
|
|
414
227
|
if (!closed)
|
|
@@ -419,12 +232,10 @@ export class StreamingProviderProcessRunner {
|
|
|
419
232
|
// termination; only a failed termination proof rejects the run.
|
|
420
233
|
void terminate().catch(fail);
|
|
421
234
|
};
|
|
422
|
-
if (signal?.aborted)
|
|
235
|
+
if (signal?.aborted)
|
|
423
236
|
abort();
|
|
424
|
-
|
|
425
|
-
else {
|
|
237
|
+
else
|
|
426
238
|
signal?.addEventListener("abort", abort, { once: true });
|
|
427
|
-
}
|
|
428
239
|
child.on("error", fail);
|
|
429
240
|
const startGrant = startGated ? child.stdio[3] : null;
|
|
430
241
|
if (startGated && !startGrant) {
|
|
@@ -507,16 +318,6 @@ export class StreamingProviderProcessRunner {
|
|
|
507
318
|
stopTerminalWorkTimer();
|
|
508
319
|
void terminate().catch(fail);
|
|
509
320
|
};
|
|
510
|
-
const workInFlight = async () => {
|
|
511
|
-
try {
|
|
512
|
-
if (handlers.isToolCallInFlight?.())
|
|
513
|
-
return true;
|
|
514
|
-
}
|
|
515
|
-
catch {
|
|
516
|
-
// A failing probe must not keep the provider open or stop it early on its own.
|
|
517
|
-
}
|
|
518
|
-
return await hasNonterminalManagedCommand(request.env?.FORGE_LOG_DIR).catch(() => false);
|
|
519
|
-
};
|
|
520
321
|
// The grace and the ceiling only count time in which no supervised work is in flight:
|
|
521
322
|
// a provider waiting on an MCP tool call or on a managed command it started is not
|
|
522
323
|
// finished, even when its turn has ended. The grace restarts once that work is done.
|
|
@@ -525,7 +326,7 @@ export class StreamingProviderProcessRunner {
|
|
|
525
326
|
return;
|
|
526
327
|
terminalWorkTickRunning = true;
|
|
527
328
|
try {
|
|
528
|
-
const inFlight = await
|
|
329
|
+
const inFlight = await providerWorkInFlight(handlers, request.env?.FORGE_LOG_DIR);
|
|
529
330
|
const now = performance.now();
|
|
530
331
|
const elapsed = Math.max(0, now - terminalWorkTickAt);
|
|
531
332
|
terminalWorkTickAt = now;
|
|
@@ -579,6 +380,7 @@ export class StreamingProviderProcessRunner {
|
|
|
579
380
|
if (request.captureOutput !== false)
|
|
580
381
|
stdout.appendLine(line);
|
|
581
382
|
const handled = handlers.onStdoutLine?.(line);
|
|
383
|
+
backgroundTurnEnd.consume(line);
|
|
582
384
|
if (!terminalTerminationStarted) {
|
|
583
385
|
if (isProviderTerminalSuccess(line)) {
|
|
584
386
|
latestTurnFailed = false;
|
|
@@ -595,11 +397,12 @@ export class StreamingProviderProcessRunner {
|
|
|
595
397
|
// the grace period restarts at its next terminal event.
|
|
596
398
|
graceIdleMs = null;
|
|
597
399
|
// A resumed session can replay a queued notification turn before the
|
|
598
|
-
// prompt's own turn.
|
|
599
|
-
// resumed agent is stopped mid-work
|
|
400
|
+
// prompt's own turn. The replayed turn must not consume the ceiling, or the
|
|
401
|
+
// resumed agent is stopped mid-work, but the prompt's turn still needs a
|
|
402
|
+
// watchdog: restart the ceiling from here instead of dropping it.
|
|
600
403
|
if (request.resumesProviderThread && terminalSuccessCount === 1 && !replayedTurnCeilingSkipped) {
|
|
601
404
|
replayedTurnCeilingSkipped = true;
|
|
602
|
-
ceilingIdleMs =
|
|
405
|
+
ceilingIdleMs = 0;
|
|
603
406
|
}
|
|
604
407
|
}
|
|
605
408
|
}
|
|
@@ -658,68 +461,36 @@ export class StreamingProviderProcessRunner {
|
|
|
658
461
|
...(memory ?? {}),
|
|
659
462
|
...(cancelledBeforeClose ? { cancelled: true } : {}),
|
|
660
463
|
...(terminalStopReason && !cancellationRequested ? { terminalStopReason } : {}),
|
|
464
|
+
...outputPipes.resultFields(),
|
|
661
465
|
});
|
|
662
466
|
}).catch(fail);
|
|
663
467
|
});
|
|
664
468
|
});
|
|
665
469
|
}
|
|
666
470
|
}
|
|
471
|
+
async function providerWorkInFlight(handlers, logDirectory) {
|
|
472
|
+
try {
|
|
473
|
+
if (handlers.isToolCallInFlight?.())
|
|
474
|
+
return true;
|
|
475
|
+
}
|
|
476
|
+
catch {
|
|
477
|
+
// A failing probe must not keep the provider open or stop it early on its own.
|
|
478
|
+
}
|
|
479
|
+
return await hasNonterminalManagedCommand(logDirectory).catch(() => false);
|
|
480
|
+
}
|
|
667
481
|
/**
|
|
668
482
|
* The typed failure for a provider run that ended without calling its required Forge
|
|
669
|
-
* completion tool. A run Forge stopped at the success ceiling
|
|
670
|
-
* is not mistaken for an agent that simply ended its turn.
|
|
483
|
+
* completion tool. A run Forge stopped at the success ceiling or for background work is
|
|
484
|
+
* reported as such, so it is not mistaken for an agent that simply ended its turn.
|
|
671
485
|
*/
|
|
672
486
|
export function providerCompletionToolMissingFailure(message, result) {
|
|
487
|
+
if (result?.terminalStopReason === "turn_ended_with_background_work")
|
|
488
|
+
return providerTurnEndedWithBackgroundWorkFailure(message);
|
|
673
489
|
if (result?.terminalStopReason === "success_ceiling") {
|
|
674
490
|
return new ForgeFailureError("provider_terminated_at_turn_ceiling", `${message} Forge stopped the provider at its post-turn success ceiling while it was still working.`);
|
|
675
491
|
}
|
|
676
492
|
return new ForgeFailureError("provider_completion_tool_missing", message);
|
|
677
493
|
}
|
|
678
|
-
/** A stream event that shows the provider is working on a turn: model output or a tool result. */
|
|
679
|
-
function isProviderTurnActivity(line) {
|
|
680
|
-
const trimmed = line.trim();
|
|
681
|
-
if (!trimmed.startsWith("{"))
|
|
682
|
-
return false;
|
|
683
|
-
try {
|
|
684
|
-
const event = JSON.parse(trimmed);
|
|
685
|
-
return event.type === "assistant"
|
|
686
|
-
|| event.type === "user"
|
|
687
|
-
|| (event.type === "system" && event.subtype === "init")
|
|
688
|
-
|| event.type === "turn.started"
|
|
689
|
-
|| event.type === "item.started";
|
|
690
|
-
}
|
|
691
|
-
catch {
|
|
692
|
-
return false;
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
function isProviderTerminalFailure(line) {
|
|
696
|
-
const trimmed = line.trim();
|
|
697
|
-
if (!trimmed.startsWith("{"))
|
|
698
|
-
return false;
|
|
699
|
-
try {
|
|
700
|
-
const event = JSON.parse(trimmed);
|
|
701
|
-
// The same events the output parsers report as provider errors.
|
|
702
|
-
return event.type === "turn.failed"
|
|
703
|
-
|| event.type === "error"
|
|
704
|
-
|| (event.type === "result" && (event.subtype !== "success" || event.is_error === true));
|
|
705
|
-
}
|
|
706
|
-
catch {
|
|
707
|
-
return false;
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
function isProviderTerminalSuccess(line) {
|
|
711
|
-
const trimmed = line.trim();
|
|
712
|
-
if (!trimmed.startsWith("{"))
|
|
713
|
-
return false;
|
|
714
|
-
try {
|
|
715
|
-
const event = JSON.parse(trimmed);
|
|
716
|
-
return event.type === "turn.completed"
|
|
717
|
-
|| (event.type === "result" && event.subtype === "success" && event.is_error !== true);
|
|
718
|
-
}
|
|
719
|
-
catch {
|
|
720
|
-
return false;
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
494
|
class HostProcessTreeMemoryObserver {
|
|
724
495
|
launch;
|
|
725
496
|
processGroupId;
|
|
@@ -1074,67 +845,3 @@ async function resolveWindowsCommand(command) {
|
|
|
1074
845
|
return null;
|
|
1075
846
|
}
|
|
1076
847
|
}
|
|
1077
|
-
/**
|
|
1078
|
-
* Resolves Windows commands without spawning where.exe. Runtime launches can
|
|
1079
|
-
* happen while the machine is under enough process pressure for where.exe to
|
|
1080
|
-
* miss its timeout; returning the unresolved package-manager name in that case
|
|
1081
|
-
* makes Node fall back to a shell shim that cannot survive Job Object wrapping.
|
|
1082
|
-
*/
|
|
1083
|
-
export function resolveWindowsCommandFromPath(command, pathValue = process.env.PATH ?? "", pathExtValue = process.env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD") {
|
|
1084
|
-
if (!command || path.isAbsolute(command) || command.includes("/") || command.includes("\\")) {
|
|
1085
|
-
return null;
|
|
1086
|
-
}
|
|
1087
|
-
const hasExtension = path.extname(command).length > 0;
|
|
1088
|
-
const extensions = hasExtension
|
|
1089
|
-
? [""]
|
|
1090
|
-
: [...new Set([
|
|
1091
|
-
"",
|
|
1092
|
-
".exe",
|
|
1093
|
-
".ps1",
|
|
1094
|
-
".cmd",
|
|
1095
|
-
".bat",
|
|
1096
|
-
...pathExtValue.split(";").map(value => value.trim().toLowerCase()).filter(Boolean),
|
|
1097
|
-
])];
|
|
1098
|
-
for (const rawDirectory of pathValue.split(path.delimiter)) {
|
|
1099
|
-
const directory = rawDirectory.trim().replace(/^"|"$/gu, "");
|
|
1100
|
-
if (!directory)
|
|
1101
|
-
continue;
|
|
1102
|
-
const candidates = [];
|
|
1103
|
-
for (const extension of extensions) {
|
|
1104
|
-
const candidate = path.join(directory, `${command}${extension}`);
|
|
1105
|
-
if (fs.existsSync(candidate))
|
|
1106
|
-
candidates.push(candidate);
|
|
1107
|
-
}
|
|
1108
|
-
const resolved = chooseWindowsCommandCandidate(candidates);
|
|
1109
|
-
if (resolved)
|
|
1110
|
-
return resolved;
|
|
1111
|
-
}
|
|
1112
|
-
return null;
|
|
1113
|
-
}
|
|
1114
|
-
export function chooseWindowsCommandCandidate(candidates) {
|
|
1115
|
-
const normalized = candidates
|
|
1116
|
-
.map((candidate) => candidate.trim())
|
|
1117
|
-
.filter((candidate) => candidate.length > 0);
|
|
1118
|
-
if (normalized.length === 0) {
|
|
1119
|
-
return null;
|
|
1120
|
-
}
|
|
1121
|
-
const preferredExtensions = [".exe", ".ps1", ".cmd", ".bat", ""];
|
|
1122
|
-
for (const extension of preferredExtensions) {
|
|
1123
|
-
const candidate = normalized.find((entry) => path.extname(entry).toLowerCase() === extension);
|
|
1124
|
-
if (candidate) {
|
|
1125
|
-
return candidate;
|
|
1126
|
-
}
|
|
1127
|
-
}
|
|
1128
|
-
return normalized[0];
|
|
1129
|
-
}
|
|
1130
|
-
async function readProcessLines(stream, onLine) {
|
|
1131
|
-
const reader = readline.createInterface({ input: stream });
|
|
1132
|
-
try {
|
|
1133
|
-
for await (const line of reader) {
|
|
1134
|
-
await onLine(line);
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1137
|
-
finally {
|
|
1138
|
-
reader.close();
|
|
1139
|
-
}
|
|
1140
|
-
}
|
|
@@ -34,6 +34,8 @@ export declare function codexSandboxModeForPlatform(platform?: NodeJS.Platform,
|
|
|
34
34
|
export declare function buildArchitectPrompt(dispatch: RunOnceDispatchPacket): string;
|
|
35
35
|
export declare function architectDependencyInstruction(dispatch: RunOnceDispatchPacket): string;
|
|
36
36
|
export declare function designerRefInstruction(dispatch: RunOnceDispatchPacket): string;
|
|
37
|
+
export declare function designerRefBuildInstruction(dispatch: RunOnceDispatchPacket): string;
|
|
38
|
+
export declare function designerRefQaInstruction(dispatch: RunOnceDispatchPacket): string;
|
|
37
39
|
export declare function architectRevisionInstruction(dispatch: RunOnceDispatchPacket): string;
|
|
38
40
|
/**
|
|
39
41
|
* Headless providers must not end a turn to wait: Forge stops the provider shortly after
|