@loucompanion/forge-bridge 0.1.4-dev.a690038a6849 → 0.1.4-dev.a7b2e9125fed
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/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 +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 +75 -2
- package/dist/runtime/host-load-sampler.js +142 -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/native-test-postgres-fallback.d.ts +51 -7
- package/dist/runtime/native-test-postgres-fallback.js +60 -8
- 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 -7
- package/dist/session/managed-attempt-tools.js +200 -92
- 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 +96 -26
- package/dist/session/phase-completion.command-validation.d.ts +7 -0
- package/dist/session/phase-completion.command-validation.js +77 -0
- package/dist/session/phase-completion.d.ts +12 -0
- package/dist/session/phase-completion.helpers.js +13 -12
- package/dist/session/phase-completion.js +5 -0
- package/dist/session/phase-completion.mcp-args.d.ts +9 -0
- package/dist/session/phase-completion.mcp-args.js +156 -0
- package/dist/session/phase-completion.prompts.js +6 -1
- package/dist/session/phase-completion.runtime.d.ts +5 -11
- package/dist/session/phase-completion.runtime.js +86 -186
- package/dist/session/phase-completion.schema-parts.d.ts +19 -0
- package/dist/session/phase-completion.schema-parts.js +188 -0
- package/dist/session/phase-completion.schemas.d.ts +3 -3
- package/dist/session/phase-completion.schemas.js +208 -231
- package/dist/session/phase-completion.validation.d.ts +2 -3
- package/dist/session/phase-completion.validation.js +49 -93
- package/dist/session/pre-publication-host-load.d.ts +27 -0
- package/dist/session/pre-publication-host-load.js +111 -0
- package/dist/session/pre-publication-native-postgres.d.ts +30 -0
- package/dist/session/pre-publication-native-postgres.js +111 -0
- package/dist/session/pre-publication-pass.d.ts +61 -0
- package/dist/session/pre-publication-pass.js +148 -0
- package/dist/session/pre-publication-process.d.ts +3 -0
- package/dist/session/pre-publication-process.js +23 -11
- package/dist/session/pre-publication-step-execution.d.ts +12 -0
- package/dist/session/pre-publication-step-execution.js +50 -0
- package/dist/session/pre-publication-validation.d.ts +37 -21
- package/dist/session/pre-publication-validation.js +221 -182
- 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 +56 -0
- package/dist/session/provider-cli/pre-publication-repair.js +276 -0
- package/dist/session/provider-cli/provider-cli.artifacts.js +15 -3
- 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.merge-integrity.d.ts +89 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +22 -36
- package/dist/session/provider-cli/provider-cli.process.js +54 -437
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +5 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +65 -10
- package/dist/session/provider-cli/provider-cli.runtime.js +7 -0
- package/dist/session/provider-cli/provider-cli.service.d.ts +7 -1
- package/dist/session/provider-cli/provider-cli.service.js +106 -167
- package/dist/session/provider-cli/provider-cli.types.d.ts +30 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +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/publishable-worktree-changes.d.ts +10 -1
- package/dist/session/publishable-worktree-changes.js +21 -5
- package/dist/session/qa-sidecar-validation.d.ts +6 -0
- package/dist/session/qa-sidecar-validation.js +28 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +30 -0
- package/dist/session/sandbox-host-capacity-gate.js +238 -0
- package/dist/session/session-redaction.js +31 -181
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.service.d.ts +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 +8 -5
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -0
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -0
- package/dist/shared/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,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { randomUUID } from "node:crypto";
|
|
1
|
+
import { execFileSync, spawn } from "node:child_process";
|
|
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
|
-
import { promisify } from "node:util";
|
|
8
|
-
import { resolveCursorAgentDirectLaunch } from "../../shared/cursor-agent/cursor-agent.launch.js";
|
|
9
4
|
import { persistHostProcessSupervisorMetadata, resolveHostProcessSupervisedLaunch, terminateHostProcessTree, } from "../../shared/process/host-process-supervisor.js";
|
|
10
|
-
import {
|
|
5
|
+
import { buildProviderChildEnvironment } from "./provider-cli.child-environment.js";
|
|
6
|
+
import { resolveWindowsProviderLaunch } from "./provider-cli.windows-launch.js";
|
|
7
|
+
import { isCodexModelsCacheSchemaFailure, quarantineIncompatibleCodexModelsCache } from "./provider-cli.codex-models-cache.js";
|
|
11
8
|
import { assertHostDatabaseCapabilityBoundary } from "../../runtime/host-database-capability-boundary.js";
|
|
12
9
|
import { ForgeFailureError } from "../session.types.js";
|
|
13
|
-
import {
|
|
14
|
-
|
|
10
|
+
import { BackgroundWorkStopFailingRunner, ClaudeBackgroundTurnEndWatch, providerTurnEndedWithBackgroundWorkFailure } from "./claude-background-work.js";
|
|
11
|
+
import { hasNonterminalManagedCommand, isProviderTerminalFailure, isProviderTerminalSuccess, isProviderTurnActivity } from "./provider-in-flight-work.js";
|
|
12
|
+
import { OutputPipeRelease, readProcessLines, PROVIDER_OUTPUT_PIPE_RELEASE_GRACE_MS } from "./provider-output-pipes.js";
|
|
13
|
+
export { chooseWindowsCommandCandidate, resolveWindowsCommandFromPath } from "../../shared/process/windows-launch.js";
|
|
14
|
+
export { buildProviderChildEnvironment } from "./provider-cli.child-environment.js";
|
|
15
15
|
// Provider processes can emit many gigabytes over a long-running session. The
|
|
16
16
|
// line handlers stream that output to Forge as it arrives; the completed result
|
|
17
17
|
// only needs a bounded diagnostic tail for failure classification.
|
|
@@ -23,11 +23,12 @@ const PROVIDER_TERMINAL_EXIT_GRACE_MS = 15_000;
|
|
|
23
23
|
const PROVIDER_TERMINAL_SUCCESS_CEILING_MS = 10 * 60_000;
|
|
24
24
|
// How often the end-of-turn timers re-check whether supervised work is still in flight.
|
|
25
25
|
const PROVIDER_TERMINAL_WORK_POLL_MS = 1_000;
|
|
26
|
-
|
|
26
|
+
export { resolveClaudeNpmDirectLaunch, resolveCodexNpmDirectLaunch, resolvePackageManagerDirectLaunch } from "./provider-cli.windows-launch.js";
|
|
27
27
|
/** Recovery must wrap the attempt coordinator, never its raw OS runner. Each
|
|
28
|
-
* relaunch needs a new fenced child generation and exclusive launch files.
|
|
28
|
+
* relaunch needs a new fenced child generation and exclusive launch files. The outer
|
|
29
|
+
* layer fails any run Forge stopped because its turn ended with background work live. */
|
|
29
30
|
export function recoveringProviderProcessRunner(inner) {
|
|
30
|
-
return new CodexResumeRecoveringProcessRunner(new CodexModelsCacheRecoveringProcessRunner(inner));
|
|
31
|
+
return new BackgroundWorkStopFailingRunner(new CodexResumeRecoveringProcessRunner(new CodexModelsCacheRecoveringProcessRunner(inner)));
|
|
31
32
|
}
|
|
32
33
|
/**
|
|
33
34
|
* Codex Desktop and an independently installed Codex CLI can briefly disagree
|
|
@@ -51,6 +52,7 @@ export class CodexModelsCacheRecoveringProcessRunner {
|
|
|
51
52
|
const recovered = await quarantineIncompatibleCodexModelsCache(request.env).catch(() => false);
|
|
52
53
|
if (!recovered || signal?.aborted)
|
|
53
54
|
return first;
|
|
55
|
+
handlers?.onGenerationStart?.();
|
|
54
56
|
return await this.inner.run(request, handlers, signal);
|
|
55
57
|
}
|
|
56
58
|
}
|
|
@@ -73,7 +75,10 @@ export class CodexResumeRecoveringProcessRunner {
|
|
|
73
75
|
return first;
|
|
74
76
|
}
|
|
75
77
|
const fallback = codexFreshTurnRequest(request);
|
|
76
|
-
|
|
78
|
+
if (!fallback)
|
|
79
|
+
return first;
|
|
80
|
+
handlers?.onGenerationStart?.();
|
|
81
|
+
return await this.inner.run(fallback, handlers, signal);
|
|
77
82
|
}
|
|
78
83
|
}
|
|
79
84
|
function isRecoverableCodexResumeFailure(command, result) {
|
|
@@ -111,224 +116,27 @@ function codexFreshTurnRequest(request) {
|
|
|
111
116
|
const cd = args.splice(cdIndex, 2);
|
|
112
117
|
args.splice(args.length - 1, 0, ...cd);
|
|
113
118
|
}
|
|
114
|
-
|
|
119
|
+
// The fallback starts a fresh thread, so it has no replayed turn to discount.
|
|
120
|
+
return { ...request, args, resumesProviderThread: false };
|
|
115
121
|
}
|
|
116
122
|
function isCodexCommand(command) {
|
|
117
123
|
return path.parse(command).name.toLowerCase() === "codex";
|
|
118
124
|
}
|
|
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
125
|
export class StreamingProviderProcessRunner {
|
|
322
126
|
terminalExitGraceMs;
|
|
323
127
|
terminalSuccessCeilingMs;
|
|
324
128
|
terminalWorkPollMs;
|
|
325
|
-
|
|
129
|
+
outputPipeReleaseGraceMs;
|
|
130
|
+
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
131
|
this.terminalExitGraceMs = terminalExitGraceMs;
|
|
327
132
|
this.terminalSuccessCeilingMs = terminalSuccessCeilingMs;
|
|
328
133
|
this.terminalWorkPollMs = terminalWorkPollMs;
|
|
134
|
+
this.outputPipeReleaseGraceMs = outputPipeReleaseGraceMs;
|
|
329
135
|
}
|
|
330
136
|
async run(request, handlers = {}, signal) {
|
|
331
137
|
assertHostDatabaseCapabilityBoundary();
|
|
138
|
+
// Every child this runner launches is a new generation, including supervisor retries.
|
|
139
|
+
handlers.onGenerationStart?.();
|
|
332
140
|
const providerLaunch = await resolveProviderProcessLaunch(request.command, request.args);
|
|
333
141
|
const supervisedLaunch = resolveHostProcessSupervisedLaunch(request, providerLaunch.command, providerLaunch.args);
|
|
334
142
|
// An unsupervised Unix provider still gets a dedicated process group so a
|
|
@@ -372,11 +180,12 @@ export class StreamingProviderProcessRunner {
|
|
|
372
180
|
const childStderr = child.stderr;
|
|
373
181
|
if (!childStdout || !childStderr) {
|
|
374
182
|
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.")));
|
|
183
|
+
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
184
|
return;
|
|
377
185
|
}
|
|
378
186
|
const stdout = new BoundedOutputTail(PROVIDER_OUTPUT_CAPTURE_LIMIT_CHARS);
|
|
379
187
|
const stderr = new BoundedOutputTail(PROVIDER_OUTPUT_CAPTURE_LIMIT_CHARS);
|
|
188
|
+
const outputPipes = new OutputPipeRelease(child, this.outputPipeReleaseGraceMs, message => stderr.appendLine(message));
|
|
380
189
|
let settled = false;
|
|
381
190
|
let closed = false;
|
|
382
191
|
let cancellationRequested = false;
|
|
@@ -394,8 +203,10 @@ export class StreamingProviderProcessRunner {
|
|
|
394
203
|
let terminalWorkTickRunning = false;
|
|
395
204
|
let latestTurnFailed = false;
|
|
396
205
|
let readiness = null;
|
|
206
|
+
const backgroundTurnEnd = new ClaudeBackgroundTurnEndWatch(request.command, this.terminalExitGraceMs, () => finishAfterTerminalSuccess("turn_ended_with_background_work"));
|
|
397
207
|
const cleanup = () => {
|
|
398
208
|
stopTerminalWorkTimer();
|
|
209
|
+
backgroundTurnEnd.stop();
|
|
399
210
|
graceIdleMs = null;
|
|
400
211
|
ceilingIdleMs = null;
|
|
401
212
|
signal?.removeEventListener("abort", abort);
|
|
@@ -408,7 +219,7 @@ export class StreamingProviderProcessRunner {
|
|
|
408
219
|
cleanup();
|
|
409
220
|
// Do not release the caller's reservation/worktree/port ownership until
|
|
410
221
|
// 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.")));
|
|
222
|
+
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
223
|
};
|
|
413
224
|
const abort = () => {
|
|
414
225
|
if (!closed)
|
|
@@ -419,12 +230,10 @@ export class StreamingProviderProcessRunner {
|
|
|
419
230
|
// termination; only a failed termination proof rejects the run.
|
|
420
231
|
void terminate().catch(fail);
|
|
421
232
|
};
|
|
422
|
-
if (signal?.aborted)
|
|
233
|
+
if (signal?.aborted)
|
|
423
234
|
abort();
|
|
424
|
-
|
|
425
|
-
else {
|
|
235
|
+
else
|
|
426
236
|
signal?.addEventListener("abort", abort, { once: true });
|
|
427
|
-
}
|
|
428
237
|
child.on("error", fail);
|
|
429
238
|
const startGrant = startGated ? child.stdio[3] : null;
|
|
430
239
|
if (startGated && !startGrant) {
|
|
@@ -507,16 +316,6 @@ export class StreamingProviderProcessRunner {
|
|
|
507
316
|
stopTerminalWorkTimer();
|
|
508
317
|
void terminate().catch(fail);
|
|
509
318
|
};
|
|
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
319
|
// The grace and the ceiling only count time in which no supervised work is in flight:
|
|
521
320
|
// a provider waiting on an MCP tool call or on a managed command it started is not
|
|
522
321
|
// finished, even when its turn has ended. The grace restarts once that work is done.
|
|
@@ -525,7 +324,7 @@ export class StreamingProviderProcessRunner {
|
|
|
525
324
|
return;
|
|
526
325
|
terminalWorkTickRunning = true;
|
|
527
326
|
try {
|
|
528
|
-
const inFlight = await
|
|
327
|
+
const inFlight = await providerWorkInFlight(handlers, request.env?.FORGE_LOG_DIR);
|
|
529
328
|
const now = performance.now();
|
|
530
329
|
const elapsed = Math.max(0, now - terminalWorkTickAt);
|
|
531
330
|
terminalWorkTickAt = now;
|
|
@@ -579,6 +378,7 @@ export class StreamingProviderProcessRunner {
|
|
|
579
378
|
if (request.captureOutput !== false)
|
|
580
379
|
stdout.appendLine(line);
|
|
581
380
|
const handled = handlers.onStdoutLine?.(line);
|
|
381
|
+
backgroundTurnEnd.consume(line);
|
|
582
382
|
if (!terminalTerminationStarted) {
|
|
583
383
|
if (isProviderTerminalSuccess(line)) {
|
|
584
384
|
latestTurnFailed = false;
|
|
@@ -595,11 +395,12 @@ export class StreamingProviderProcessRunner {
|
|
|
595
395
|
// the grace period restarts at its next terminal event.
|
|
596
396
|
graceIdleMs = null;
|
|
597
397
|
// A resumed session can replay a queued notification turn before the
|
|
598
|
-
// prompt's own turn.
|
|
599
|
-
// resumed agent is stopped mid-work
|
|
398
|
+
// prompt's own turn. The replayed turn must not consume the ceiling, or the
|
|
399
|
+
// resumed agent is stopped mid-work, but the prompt's turn still needs a
|
|
400
|
+
// watchdog: restart the ceiling from here instead of dropping it.
|
|
600
401
|
if (request.resumesProviderThread && terminalSuccessCount === 1 && !replayedTurnCeilingSkipped) {
|
|
601
402
|
replayedTurnCeilingSkipped = true;
|
|
602
|
-
ceilingIdleMs =
|
|
403
|
+
ceilingIdleMs = 0;
|
|
603
404
|
}
|
|
604
405
|
}
|
|
605
406
|
}
|
|
@@ -658,68 +459,36 @@ export class StreamingProviderProcessRunner {
|
|
|
658
459
|
...(memory ?? {}),
|
|
659
460
|
...(cancelledBeforeClose ? { cancelled: true } : {}),
|
|
660
461
|
...(terminalStopReason && !cancellationRequested ? { terminalStopReason } : {}),
|
|
462
|
+
...outputPipes.resultFields(),
|
|
661
463
|
});
|
|
662
464
|
}).catch(fail);
|
|
663
465
|
});
|
|
664
466
|
});
|
|
665
467
|
}
|
|
666
468
|
}
|
|
469
|
+
async function providerWorkInFlight(handlers, logDirectory) {
|
|
470
|
+
try {
|
|
471
|
+
if (handlers.isToolCallInFlight?.())
|
|
472
|
+
return true;
|
|
473
|
+
}
|
|
474
|
+
catch {
|
|
475
|
+
// A failing probe must not keep the provider open or stop it early on its own.
|
|
476
|
+
}
|
|
477
|
+
return await hasNonterminalManagedCommand(logDirectory).catch(() => false);
|
|
478
|
+
}
|
|
667
479
|
/**
|
|
668
480
|
* 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.
|
|
481
|
+
* completion tool. A run Forge stopped at the success ceiling or for background work is
|
|
482
|
+
* reported as such, so it is not mistaken for an agent that simply ended its turn.
|
|
671
483
|
*/
|
|
672
484
|
export function providerCompletionToolMissingFailure(message, result) {
|
|
485
|
+
if (result?.terminalStopReason === "turn_ended_with_background_work")
|
|
486
|
+
return providerTurnEndedWithBackgroundWorkFailure(message);
|
|
673
487
|
if (result?.terminalStopReason === "success_ceiling") {
|
|
674
488
|
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
489
|
}
|
|
676
490
|
return new ForgeFailureError("provider_completion_tool_missing", message);
|
|
677
491
|
}
|
|
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
492
|
class HostProcessTreeMemoryObserver {
|
|
724
493
|
launch;
|
|
725
494
|
processGroupId;
|
|
@@ -877,18 +646,7 @@ async function resolveProviderProcessLaunch(command, args) {
|
|
|
877
646
|
if (process.platform !== "win32") {
|
|
878
647
|
return { command, args };
|
|
879
648
|
}
|
|
880
|
-
|
|
881
|
-
if (cursorDirect) {
|
|
882
|
-
return cursorDirect;
|
|
883
|
-
}
|
|
884
|
-
const resolved = await resolveWindowsCommand(command);
|
|
885
|
-
if (!resolved) {
|
|
886
|
-
return { command, args };
|
|
887
|
-
}
|
|
888
|
-
return resolveCodexNpmDirectLaunch(resolved, args)
|
|
889
|
-
?? resolveClaudeNpmDirectLaunch(resolved, args)
|
|
890
|
-
?? resolvePackageManagerDirectLaunch(resolved, args)
|
|
891
|
-
?? buildWindowsLaunchCommand(resolved, args);
|
|
649
|
+
return await resolveWindowsProviderLaunch(command, args);
|
|
892
650
|
}
|
|
893
651
|
const UNIX_PROVIDER_START_GATE_SHELL = "/bin/sh";
|
|
894
652
|
const UNIX_PROVIDER_START_GATE_NAME = "forge-provider-start-gate";
|
|
@@ -997,144 +755,3 @@ async function waitForWindowsProviderReady(launch, signal, isClosed) {
|
|
|
997
755
|
await new Promise(resolve => setTimeout(resolve, 25));
|
|
998
756
|
}
|
|
999
757
|
}
|
|
1000
|
-
export function resolveCodexNpmDirectLaunch(commandPath, args) {
|
|
1001
|
-
const extension = path.extname(commandPath).toLowerCase();
|
|
1002
|
-
if ((extension !== ".cmd" && extension !== ".ps1")
|
|
1003
|
-
|| path.basename(commandPath, extension).toLowerCase() !== "codex") {
|
|
1004
|
-
return null;
|
|
1005
|
-
}
|
|
1006
|
-
const entryPoint = path.join(path.dirname(commandPath), "node_modules", "@openai", "codex", "bin", "codex.js");
|
|
1007
|
-
return fs.existsSync(entryPoint)
|
|
1008
|
-
? { command: process.execPath, args: [entryPoint, ...args] }
|
|
1009
|
-
: null;
|
|
1010
|
-
}
|
|
1011
|
-
/**
|
|
1012
|
-
* npm installs of Claude Code (`npm i -g @anthropic-ai/claude-code`) put a `claude.cmd` shim on
|
|
1013
|
-
* PATH; launch its cli.js directly for the same Job Object reasons as Codex. The native installer
|
|
1014
|
-
* ships `claude.exe`, which is preferred by PATH resolution and needs no rewrite.
|
|
1015
|
-
*/
|
|
1016
|
-
export function resolveClaudeNpmDirectLaunch(commandPath, args) {
|
|
1017
|
-
const extension = path.extname(commandPath).toLowerCase();
|
|
1018
|
-
if ((extension !== ".cmd" && extension !== ".ps1")
|
|
1019
|
-
|| path.basename(commandPath, extension).toLowerCase() !== "claude") {
|
|
1020
|
-
return null;
|
|
1021
|
-
}
|
|
1022
|
-
const entryPoint = path.join(path.dirname(commandPath), "node_modules", "@anthropic-ai", "claude-code", "cli.js");
|
|
1023
|
-
return fs.existsSync(entryPoint)
|
|
1024
|
-
? { command: process.execPath, args: [entryPoint, ...args] }
|
|
1025
|
-
: null;
|
|
1026
|
-
}
|
|
1027
|
-
/**
|
|
1028
|
-
* Avoids cmd.exe's nested-quote handling for package-manager shims. That
|
|
1029
|
-
* quoting loses executable paths containing spaces after the command is
|
|
1030
|
-
* wrapped by the Windows Job Object supervisor.
|
|
1031
|
-
*/
|
|
1032
|
-
export function resolvePackageManagerDirectLaunch(commandPath, args) {
|
|
1033
|
-
const extension = path.extname(commandPath).toLowerCase();
|
|
1034
|
-
if (extension !== ".cmd" && extension !== ".ps1")
|
|
1035
|
-
return null;
|
|
1036
|
-
const packageManager = path.basename(commandPath, extension).toLowerCase();
|
|
1037
|
-
if (!["corepack", "npm", "npx", "pnpm", "pnpx", "yarn", "yarnpkg"].includes(packageManager))
|
|
1038
|
-
return null;
|
|
1039
|
-
const root = path.dirname(commandPath);
|
|
1040
|
-
const candidates = [
|
|
1041
|
-
path.join(root, "node_modules", "corepack", "dist", packageManager === "corepack" ? "corepack.js" : `${packageManager}.js`),
|
|
1042
|
-
...(packageManager === "npm" || packageManager === "npx"
|
|
1043
|
-
? [path.join(root, "node_modules", "npm", "bin", `${packageManager}-cli.js`)]
|
|
1044
|
-
: []),
|
|
1045
|
-
...(packageManager === "pnpm" || packageManager === "pnpx"
|
|
1046
|
-
? [path.join(root, "node_modules", "pnpm", "bin", `${packageManager}.cjs`)]
|
|
1047
|
-
: []),
|
|
1048
|
-
...(packageManager === "yarn" || packageManager === "yarnpkg"
|
|
1049
|
-
? [path.join(root, "node_modules", "yarn", "bin", "yarn.js")]
|
|
1050
|
-
: []),
|
|
1051
|
-
];
|
|
1052
|
-
const entryPoint = candidates.find(candidate => fs.existsSync(candidate));
|
|
1053
|
-
if (!entryPoint)
|
|
1054
|
-
return null;
|
|
1055
|
-
const adjacentNode = path.join(root, "node.exe");
|
|
1056
|
-
return {
|
|
1057
|
-
command: fs.existsSync(adjacentNode) ? adjacentNode : process.execPath,
|
|
1058
|
-
args: [entryPoint, ...args],
|
|
1059
|
-
};
|
|
1060
|
-
}
|
|
1061
|
-
async function resolveWindowsCommand(command) {
|
|
1062
|
-
if (path.isAbsolute(command)) {
|
|
1063
|
-
return command;
|
|
1064
|
-
}
|
|
1065
|
-
const resolvedFromPath = resolveWindowsCommandFromPath(command);
|
|
1066
|
-
if (resolvedFromPath) {
|
|
1067
|
-
return resolvedFromPath;
|
|
1068
|
-
}
|
|
1069
|
-
try {
|
|
1070
|
-
const result = await execFileAsync("where.exe", [command], { timeout: 2000 });
|
|
1071
|
-
return chooseWindowsCommandCandidate(result.stdout.split(/\r?\n/));
|
|
1072
|
-
}
|
|
1073
|
-
catch {
|
|
1074
|
-
return null;
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
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
|
-
}
|
|
@@ -29,11 +29,16 @@ export declare function buildProviderCliCommand(dispatch: RunOnceDispatchPacket,
|
|
|
29
29
|
* Values the provider does not accept are dropped rather than failing the attempt; Forge validates on save.
|
|
30
30
|
*/
|
|
31
31
|
export declare function providerEffort(provider: string, effort: string | null | undefined): string | null;
|
|
32
|
+
/** Whether the provider reads its prompt from stdin rather than the command line. */
|
|
33
|
+
export declare function shouldPipePromptToStdin(provider: string, prompt: string, force?: boolean): boolean;
|
|
34
|
+
export declare function usesManagedWindowsHost(dispatch: RunOnceDispatchPacket): boolean;
|
|
32
35
|
export declare function buildProviderCliPrompt(dispatch: RunOnceDispatchPacket, prompt: string, runtimeEnvironment?: Readonly<Record<string, string>>): string;
|
|
33
36
|
export declare function codexSandboxModeForPlatform(platform?: NodeJS.Platform, executionMode?: string): "workspace-write" | "danger-full-access";
|
|
34
37
|
export declare function buildArchitectPrompt(dispatch: RunOnceDispatchPacket): string;
|
|
35
38
|
export declare function architectDependencyInstruction(dispatch: RunOnceDispatchPacket): string;
|
|
36
39
|
export declare function designerRefInstruction(dispatch: RunOnceDispatchPacket): string;
|
|
40
|
+
export declare function designerRefBuildInstruction(dispatch: RunOnceDispatchPacket): string;
|
|
41
|
+
export declare function designerRefQaInstruction(dispatch: RunOnceDispatchPacket): string;
|
|
37
42
|
export declare function architectRevisionInstruction(dispatch: RunOnceDispatchPacket): string;
|
|
38
43
|
/**
|
|
39
44
|
* Headless providers must not end a turn to wait: Forge stops the provider shortly after
|