@loucompanion/forge-bridge 0.1.4-dev.138b79c6feb3 → 0.1.4-dev.176dfdaf5020
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +142 -1
- package/dist/bridge/bridge-chat-provider-command.d.ts +19 -0
- package/dist/bridge/bridge-chat-provider-command.js +132 -0
- package/dist/bridge/bridge-chat.types.d.ts +10 -0
- package/dist/bridge/bridge-chat.types.js +16 -1
- package/dist/bridge/bridge-state-file.d.ts +161 -0
- package/dist/bridge/bridge-state-file.js +376 -0
- package/dist/bridge/bridge-state-io.d.ts +11 -0
- package/dist/bridge/bridge-state-io.js +50 -0
- package/dist/bridge/bridge-state-lock.d.ts +11 -0
- package/dist/bridge/bridge-state-lock.js +102 -0
- package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
- package/dist/bridge/bridge-state-unpublished.js +111 -0
- package/dist/bridge/bridge.base.d.ts +9 -0
- package/dist/bridge/bridge.service.d.ts +87 -14
- package/dist/bridge/bridge.service.js +393 -337
- package/dist/bridge/bridge.types.d.ts +16 -0
- package/dist/bridge/in-flight-registry.d.ts +62 -0
- package/dist/bridge/in-flight-registry.js +207 -0
- package/dist/bridge/local-yield-flag.d.ts +6 -0
- package/dist/bridge/local-yield-flag.js +34 -0
- package/dist/bridge/readiness-result-outbox.d.ts +5 -1
- package/dist/bridge/readiness-result-outbox.js +20 -0
- package/dist/bridge/runner-host-capabilities.d.ts +3 -0
- package/dist/bridge/runner-host-capabilities.js +13 -0
- package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
- package/dist/bridge/sandbox-resource-accounting.js +150 -0
- package/dist/cleanup/cleanup-wip.d.ts +12 -0
- package/dist/cleanup/cleanup-wip.js +66 -0
- package/dist/cleanup/cleanup.service.d.ts +11 -1
- package/dist/cleanup/cleanup.service.js +80 -62
- package/dist/cleanup/cleanup.types.d.ts +2 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +2 -0
- package/dist/cleanup/host-runtime-ledger.js +30 -9
- package/dist/cli/cli.help.js +74 -12
- package/dist/cli/cli.service.d.ts +19 -10
- package/dist/cli/cli.service.js +142 -185
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +6 -0
- package/dist/cli/local-config.js +32 -4
- package/dist/cli/provider-cli-detection.d.ts +10 -0
- package/dist/cli/provider-cli-detection.js +160 -0
- package/dist/runtime/aspnet-runtime-prebuild.d.ts +20 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +104 -26
- package/dist/runtime/attempt-database-broker.d.ts +1 -1
- package/dist/runtime/attempt-node-runtime-launcher.js +9 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +2 -0
- package/dist/runtime/attempt-process-supervisor.js +12 -6
- package/dist/runtime/docker-engine-probe.d.ts +5 -0
- package/dist/runtime/docker-engine-probe.js +7 -0
- package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
- package/dist/runtime/dotnet-build-outputs.js +402 -0
- package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
- package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
- package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
- package/dist/runtime/ephemeral-test-postgres.js +303 -0
- package/dist/runtime/host-facts.d.ts +2 -1
- package/dist/runtime/host-load-admission.d.ts +18 -3
- package/dist/runtime/host-load-admission.js +19 -4
- package/dist/runtime/host-load-child-environment.d.ts +11 -6
- package/dist/runtime/host-load-child-environment.js +22 -11
- package/dist/runtime/host-load-governor-config.d.ts +19 -1
- package/dist/runtime/host-load-governor-config.js +37 -0
- package/dist/runtime/host-load-governor.d.ts +14 -0
- package/dist/runtime/host-load-governor.js +139 -26
- package/dist/runtime/host-load-ledger-lock.js +6 -4
- package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
- package/dist/runtime/host-load-runtime-settings.js +80 -0
- package/dist/runtime/host-load-sampler.d.ts +34 -4
- package/dist/runtime/host-load-sampler.js +73 -7
- package/dist/runtime/host-load-step-class.d.ts +3 -1
- package/dist/runtime/host-load-step-class.js +60 -5
- package/dist/runtime/host-load-test-slot.d.ts +43 -0
- package/dist/runtime/host-load-test-slot.js +81 -0
- package/dist/runtime/host-load-token-ledger.d.ts +26 -0
- package/dist/runtime/host-load-token-ledger.js +93 -61
- package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
- package/dist/runtime/host-load-windows-cpu.js +85 -0
- package/dist/runtime/host-runtime-contract.d.ts +12 -0
- package/dist/runtime/host-runtime-contract.js +29 -1
- package/dist/runtime/host-runtime-lease.d.ts +32 -4
- package/dist/runtime/host-runtime-lease.js +109 -173
- package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
- package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
- package/dist/runtime/host-runtime-promotion.d.ts +23 -0
- package/dist/runtime/host-runtime-promotion.js +36 -0
- package/dist/runtime/managed-command-teardown.js +5 -16
- package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
- package/dist/runtime/native-test-postgres-fallback.js +60 -8
- package/dist/runtime/runner-settings.d.ts +104 -0
- package/dist/runtime/runner-settings.js +236 -0
- package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
- package/dist/runtime/supervised-runtime-build-guard.js +112 -0
- package/dist/sandbox/host-capacity-broker.d.ts +10 -2
- package/dist/sandbox/host-capacity-broker.js +27 -6
- package/dist/sandbox/managed-branch.d.ts +13 -0
- package/dist/sandbox/managed-branch.js +90 -0
- package/dist/sandbox/provider-auth/codex.js +11 -11
- package/dist/sandbox/runtime.js +2 -6
- package/dist/session/architect-waits.d.ts +2 -0
- package/dist/session/architect-waits.js +138 -0
- package/dist/session/managed-attempt-tools.d.ts +0 -7
- package/dist/session/managed-attempt-tools.js +58 -91
- package/dist/session/managed-build-coordinator.d.ts +16 -0
- package/dist/session/managed-build-coordinator.js +10 -0
- package/dist/session/managed-build-receipt.d.ts +5 -0
- package/dist/session/managed-build-receipt.js +8 -3
- package/dist/session/managed-command-host-load.d.ts +2 -0
- package/dist/session/managed-command-host-load.js +2 -1
- package/dist/session/phase-completion.artifacts.js +2 -1
- package/dist/session/phase-completion.d.ts +8 -0
- package/dist/session/phase-completion.js +1 -0
- package/dist/session/phase-completion.mcp-args.d.ts +9 -0
- package/dist/session/phase-completion.mcp-args.js +156 -0
- package/dist/session/phase-completion.runtime.d.ts +0 -8
- package/dist/session/phase-completion.runtime.js +43 -197
- package/dist/session/phase-completion.schemas.js +25 -23
- package/dist/session/phase-completion.validation.js +3 -1
- package/dist/session/pre-publication-native-postgres.d.ts +30 -0
- package/dist/session/pre-publication-native-postgres.js +111 -0
- package/dist/session/pre-publication-pass.d.ts +61 -0
- package/dist/session/pre-publication-pass.js +148 -0
- package/dist/session/pre-publication-process.js +10 -10
- package/dist/session/pre-publication-step-execution.d.ts +2 -1
- package/dist/session/pre-publication-step-execution.js +6 -5
- package/dist/session/pre-publication-validation.d.ts +30 -14
- package/dist/session/pre-publication-validation.js +207 -134
- package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
- package/dist/session/provider-cli/claude-background-work.js +181 -0
- package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
- package/dist/session/provider-cli/host-build-lock.js +30 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
- package/dist/session/provider-cli/pre-publication-repair.js +276 -0
- package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +75 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +15 -36
- package/dist/session/provider-cli/provider-cli.process.js +39 -430
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +5 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +68 -31
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +8 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +29 -1
- package/dist/session/provider-cli/provider-cli.service.d.ts +5 -5
- package/dist/session/provider-cli/provider-cli.service.js +70 -263
- package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +4 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +45 -0
- package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
- package/dist/session/provider-cli/provider-output-pipes.js +67 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +2 -0
- package/dist/session/provider-cli/provider-output-state.js +6 -0
- package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
- package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
- package/dist/session/qa-sidecar-validation.d.ts +6 -0
- package/dist/session/qa-sidecar-validation.js +28 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +22 -1
- package/dist/session/sandbox-host-capacity-gate.js +42 -14
- package/dist/session/session-redaction.js +31 -181
- package/dist/session/session.base.d.ts +6 -1
- package/dist/session/session.service.d.ts +6 -1
- package/dist/session/session.service.js +75 -64
- package/dist/session/session.types.js +3 -3
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -0
- package/dist/shared/fs/file-identity.d.ts +10 -0
- package/dist/shared/fs/file-identity.js +15 -0
- package/dist/shared/fs/replace-file.d.ts +7 -0
- package/dist/shared/fs/replace-file.js +33 -0
- package/dist/shared/process/host-process-recovery.d.ts +14 -3
- package/dist/shared/process/host-process-recovery.js +23 -3
- package/dist/shared/process/host-process-supervisor.d.ts +13 -1
- package/dist/shared/process/host-process-supervisor.js +66 -14
- package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
- package/dist/shared/process/windows-app-execution-alias.js +45 -0
- package/dist/shared/process/windows-launch.d.ts +18 -0
- package/dist/shared/process/windows-launch.js +68 -0
- package/dist/shared/provider-capabilities.js +14 -7
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/orphan-relink.d.ts +19 -0
- package/dist/worktree/orphan-relink.js +106 -0
- package/dist/worktree/wip-git.d.ts +33 -0
- package/dist/worktree/wip-git.js +122 -0
- package/dist/worktree/wip-refs.d.ts +62 -0
- package/dist/worktree/wip-refs.js +119 -0
- package/dist/worktree/wip-restore.d.ts +38 -0
- package/dist/worktree/wip-restore.js +190 -0
- package/dist/worktree/wip-snapshot.d.ts +50 -0
- package/dist/worktree/wip-snapshot.js +268 -0
- package/dist/worktree/worktree-inputs.d.ts +8 -0
- package/dist/worktree/worktree-inputs.js +134 -0
- package/dist/worktree/worktree-origin-sync.d.ts +34 -0
- package/dist/worktree/worktree-origin-sync.js +127 -0
- package/dist/worktree/worktree-wip-events.d.ts +18 -0
- package/dist/worktree/worktree-wip-events.js +98 -0
- package/dist/worktree/worktree-wip.d.ts +50 -0
- package/dist/worktree/worktree-wip.js +185 -0
- package/dist/worktree/worktree.base.d.ts +7 -1
- package/dist/worktree/worktree.service.d.ts +27 -5
- package/dist/worktree/worktree.service.js +110 -181
- package/dist/worktree/worktree.types.d.ts +31 -0
- package/package.json +2 -2
|
@@ -1,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
|
|
@@ -121,216 +122,16 @@ function codexFreshTurnRequest(request) {
|
|
|
121
122
|
function isCodexCommand(command) {
|
|
122
123
|
return path.parse(command).name.toLowerCase() === "codex";
|
|
123
124
|
}
|
|
124
|
-
function isCodexModelsCacheSchemaFailure(result) {
|
|
125
|
-
const output = `${result.stderr}\n${result.stdout}`.toLowerCase();
|
|
126
|
-
return output.includes("base_instructions")
|
|
127
|
-
&& output.includes("missing field")
|
|
128
|
-
&& (output.includes("models_cache") || output.includes("models cache") || output.includes("model cache"));
|
|
129
|
-
}
|
|
130
|
-
async function quarantineIncompatibleCodexModelsCache(requestEnv) {
|
|
131
|
-
const configuredHome = readEnvironmentValue(requestEnv ?? {}, "CODEX_HOME")
|
|
132
|
-
?? readEnvironmentValue(process.env, "CODEX_HOME")
|
|
133
|
-
?? readEnvironmentValue(process.env, "FORGE_CODEX_HOME");
|
|
134
|
-
const codexHome = path.resolve(configuredHome ?? path.join(os.homedir(), ".codex"));
|
|
135
|
-
if (!path.isAbsolute(codexHome) || codexHome === path.parse(codexHome).root)
|
|
136
|
-
return false;
|
|
137
|
-
const cachePath = path.join(codexHome, "models_cache.json");
|
|
138
|
-
const cacheStat = await fs.promises.lstat(cachePath).catch(error => {
|
|
139
|
-
if (error.code === "ENOENT")
|
|
140
|
-
return null;
|
|
141
|
-
throw error;
|
|
142
|
-
});
|
|
143
|
-
if (!cacheStat
|
|
144
|
-
|| !cacheStat.isFile()
|
|
145
|
-
|| cacheStat.isSymbolicLink()
|
|
146
|
-
|| cacheStat.nlink !== 1
|
|
147
|
-
|| cacheStat.size <= 0
|
|
148
|
-
|| cacheStat.size > maximumRecoverableCodexModelsCacheBytes) {
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
const quarantinePath = path.join(codexHome, `models_cache.forge-incompatible-${Date.now()}-${randomUUID()}.json`);
|
|
152
|
-
await fs.promises.rename(cachePath, quarantinePath);
|
|
153
|
-
return true;
|
|
154
|
-
}
|
|
155
|
-
const allowedProviderParentEnvNames = [
|
|
156
|
-
"PATH",
|
|
157
|
-
"HOME",
|
|
158
|
-
"USERPROFILE",
|
|
159
|
-
"TMPDIR",
|
|
160
|
-
"TEMP",
|
|
161
|
-
"TMP",
|
|
162
|
-
"LANG",
|
|
163
|
-
"CLAUDE_CONFIG_DIR"
|
|
164
|
-
];
|
|
165
|
-
const windowsAllowedProviderParentEnvNames = [
|
|
166
|
-
"SystemRoot",
|
|
167
|
-
"SystemDrive",
|
|
168
|
-
"ComSpec",
|
|
169
|
-
"PATHEXT",
|
|
170
|
-
"APPDATA",
|
|
171
|
-
"LOCALAPPDATA",
|
|
172
|
-
"USERNAME",
|
|
173
|
-
"USERDOMAIN",
|
|
174
|
-
"HOMEDRIVE",
|
|
175
|
-
"HOMEPATH",
|
|
176
|
-
"ProgramData",
|
|
177
|
-
"ProgramFiles",
|
|
178
|
-
"ProgramFiles(x86)",
|
|
179
|
-
"ProgramW6432",
|
|
180
|
-
"DOTNET_ROOT",
|
|
181
|
-
"DOTNET_ROOT(x86)",
|
|
182
|
-
"DOTNET_CLI_HOME",
|
|
183
|
-
"NUGET_PACKAGES",
|
|
184
|
-
"NUGET_HTTP_CACHE_PATH",
|
|
185
|
-
"CLAUDE_CODE_GIT_BASH_PATH"
|
|
186
|
-
];
|
|
187
|
-
export function buildProviderChildEnvironment(requestEnv, options = {}) {
|
|
188
|
-
const parentEnv = options.parentEnv ?? process.env;
|
|
189
|
-
const platform = options.platform ?? process.platform;
|
|
190
|
-
const env = {};
|
|
191
|
-
for (const [key, value] of Object.entries(parentEnv)) {
|
|
192
|
-
if (typeof value === "string" && isAllowedProviderParentEnv(key, platform)) {
|
|
193
|
-
env[key] = value;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
if (requestEnv) {
|
|
197
|
-
for (const [key, value] of Object.entries(requestEnv)) {
|
|
198
|
-
const trimmedKey = key.trim();
|
|
199
|
-
if (trimmedKey.length > 0) {
|
|
200
|
-
env[trimmedKey] = value;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
if (platform === "win32") {
|
|
205
|
-
normalizeWindowsDotNetEnvironment(env, parentEnv, options.homeDir ?? os.homedir());
|
|
206
|
-
}
|
|
207
|
-
normalizeProviderBuildEnvironment(env);
|
|
208
|
-
return env;
|
|
209
|
-
}
|
|
210
|
-
function normalizeProviderBuildEnvironment(env) {
|
|
211
|
-
// Provider sessions are long lived and commonly run many dotnet builds. Persistent
|
|
212
|
-
// MSBuild and Roslyn compiler servers otherwise survive individual commands and can
|
|
213
|
-
// retain more memory than the active Forge lane. Keep those caches process-scoped by
|
|
214
|
-
// default on every runner OS; an explicitly supplied request value still wins.
|
|
215
|
-
setCanonicalProviderBuildEnvironmentValue(env, "DOTNET_CLI_USE_MSBUILD_SERVER", "0");
|
|
216
|
-
setCanonicalProviderBuildEnvironmentValue(env, "MSBUILDDISABLENODEREUSE", "1");
|
|
217
|
-
setCanonicalProviderBuildEnvironmentValue(env, "UseSharedCompilation", "false");
|
|
218
|
-
}
|
|
219
|
-
function setCanonicalProviderBuildEnvironmentValue(env, name, value) {
|
|
220
|
-
// The dotnet CLI uses case-sensitive environment lookup on POSIX, while MSBuild
|
|
221
|
-
// property names are case-insensitive on every OS. Collapse request aliases to
|
|
222
|
-
// one canonical key so the explicit value wins without producing ambiguity.
|
|
223
|
-
const exact = env[name];
|
|
224
|
-
const alias = Object.entries(env).find(([key, candidate]) => key !== name
|
|
225
|
-
&& key.toLowerCase() === name.toLowerCase()
|
|
226
|
-
&& typeof candidate === "string"
|
|
227
|
-
&& candidate.trim().length > 0)?.[1];
|
|
228
|
-
const resolved = typeof exact === "string" && exact.trim().length > 0
|
|
229
|
-
? exact
|
|
230
|
-
: alias ?? value;
|
|
231
|
-
for (const key of Object.keys(env)) {
|
|
232
|
-
if (key !== name && key.toLowerCase() === name.toLowerCase()) {
|
|
233
|
-
delete env[key];
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
env[name] = resolved;
|
|
237
|
-
}
|
|
238
|
-
function isAllowedProviderParentEnv(key, platform = process.platform) {
|
|
239
|
-
return isAllowedProviderParentEnvName(key, allowedProviderParentEnvNames)
|
|
240
|
-
|| key.toUpperCase().startsWith("LC_")
|
|
241
|
-
|| (platform === "win32" && isAllowedProviderParentEnvName(key, windowsAllowedProviderParentEnvNames));
|
|
242
|
-
}
|
|
243
|
-
function isAllowedProviderParentEnvName(key, allowedNames) {
|
|
244
|
-
return allowedNames.some((allowed) => allowed.toLowerCase() === key.toLowerCase());
|
|
245
|
-
}
|
|
246
|
-
function normalizeWindowsDotNetEnvironment(env, parentEnv, homeDir) {
|
|
247
|
-
const systemRoot = readEnvironmentValue(env, "SystemRoot") ?? readEnvironmentValue(parentEnv, "SystemRoot") ?? "C:\\Windows";
|
|
248
|
-
const systemDrive = path.win32.parse(systemRoot).root.replace(/\\$/, "") || "C:";
|
|
249
|
-
setEnvironmentValueIfMissing(env, "SystemRoot", systemRoot);
|
|
250
|
-
setEnvironmentValueIfMissing(env, "SystemDrive", readEnvironmentValue(parentEnv, "SystemDrive") ?? systemDrive);
|
|
251
|
-
setEnvironmentValueIfMissing(env, "ComSpec", readEnvironmentValue(parentEnv, "ComSpec") ?? path.win32.join(systemRoot, "System32", "cmd.exe"));
|
|
252
|
-
setEnvironmentValueIfMissing(env, "PATHEXT", readEnvironmentValue(parentEnv, "PATHEXT") ?? ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.CPL");
|
|
253
|
-
const resolvedSystemDrive = readEnvironmentValue(env, "SystemDrive") ?? systemDrive;
|
|
254
|
-
const defaultProgramFiles = path.win32.join(`${resolvedSystemDrive}\\`, "Program Files");
|
|
255
|
-
const defaultProgramFilesX86 = path.win32.join(`${resolvedSystemDrive}\\`, "Program Files (x86)");
|
|
256
|
-
const defaultProgramData = path.win32.join(`${resolvedSystemDrive}\\`, "ProgramData");
|
|
257
|
-
const programFiles = readEnvironmentValue(env, "ProgramFiles")
|
|
258
|
-
?? readEnvironmentValue(parentEnv, "ProgramFiles")
|
|
259
|
-
?? defaultProgramFiles;
|
|
260
|
-
setEnvironmentValueIfMissing(env, "ProgramFiles", programFiles);
|
|
261
|
-
setEnvironmentValueIfMissing(env, "ProgramW6432", readEnvironmentValue(parentEnv, "ProgramW6432") ?? defaultProgramFiles);
|
|
262
|
-
setEnvironmentValueIfMissing(env, "ProgramFiles(x86)", readEnvironmentValue(parentEnv, "ProgramFiles(x86)") ?? defaultProgramFilesX86);
|
|
263
|
-
setEnvironmentValueIfMissing(env, "ProgramData", readEnvironmentValue(parentEnv, "ProgramData") ?? defaultProgramData);
|
|
264
|
-
const userProfile = resolveWindowsUserProfile(env, parentEnv, homeDir);
|
|
265
|
-
if (userProfile) {
|
|
266
|
-
setEnvironmentValueIfMissing(env, "USERPROFILE", userProfile);
|
|
267
|
-
setEnvironmentValueIfMissing(env, "HOME", userProfile);
|
|
268
|
-
setEnvironmentValueIfMissing(env, "DOTNET_CLI_HOME", userProfile);
|
|
269
|
-
setEnvironmentValueIfMissing(env, "NUGET_PACKAGES", path.win32.join(userProfile, ".nuget", "packages"));
|
|
270
|
-
const parsed = path.win32.parse(userProfile);
|
|
271
|
-
if (parsed.root) {
|
|
272
|
-
setEnvironmentValueIfMissing(env, "HOMEDRIVE", parsed.root.replace(/\\$/, ""));
|
|
273
|
-
setEnvironmentValueIfMissing(env, "HOMEPATH", userProfile.slice(parsed.root.length - (parsed.root.endsWith("\\") ? 1 : 0)) || "\\");
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
const appData = readEnvironmentValue(env, "APPDATA")
|
|
277
|
-
?? readEnvironmentValue(parentEnv, "APPDATA")
|
|
278
|
-
?? (userProfile ? path.win32.join(userProfile, "AppData", "Roaming") : undefined);
|
|
279
|
-
const localAppData = readEnvironmentValue(env, "LOCALAPPDATA")
|
|
280
|
-
?? readEnvironmentValue(parentEnv, "LOCALAPPDATA")
|
|
281
|
-
?? (userProfile ? path.win32.join(userProfile, "AppData", "Local") : undefined);
|
|
282
|
-
if (appData) {
|
|
283
|
-
setEnvironmentValueIfMissing(env, "APPDATA", appData);
|
|
284
|
-
}
|
|
285
|
-
if (localAppData) {
|
|
286
|
-
setEnvironmentValueIfMissing(env, "LOCALAPPDATA", localAppData);
|
|
287
|
-
setEnvironmentValueIfMissing(env, "NUGET_HTTP_CACHE_PATH", path.win32.join(localAppData, "NuGet", "v3-cache"));
|
|
288
|
-
}
|
|
289
|
-
setEnvironmentValueIfMissing(env, "DOTNET_NOLOGO", "1");
|
|
290
|
-
setEnvironmentValueIfMissing(env, "DOTNET_CLI_TELEMETRY_OPTOUT", "1");
|
|
291
|
-
setEnvironmentValueIfMissing(env, "DOTNET_SKIP_FIRST_TIME_EXPERIENCE", "1");
|
|
292
|
-
setEnvironmentValueIfMissing(env, "NUGET_XMLDOC_MODE", "skip");
|
|
293
|
-
}
|
|
294
|
-
function resolveWindowsUserProfile(env, parentEnv, homeDir) {
|
|
295
|
-
const existing = readEnvironmentValue(env, "USERPROFILE") ?? readEnvironmentValue(parentEnv, "USERPROFILE");
|
|
296
|
-
if (existing) {
|
|
297
|
-
return existing;
|
|
298
|
-
}
|
|
299
|
-
const home = readEnvironmentValue(env, "HOME") ?? readEnvironmentValue(parentEnv, "HOME");
|
|
300
|
-
if (home && path.win32.isAbsolute(home)) {
|
|
301
|
-
return home;
|
|
302
|
-
}
|
|
303
|
-
const homeDrive = readEnvironmentValue(env, "HOMEDRIVE") ?? readEnvironmentValue(parentEnv, "HOMEDRIVE");
|
|
304
|
-
const homePath = readEnvironmentValue(env, "HOMEPATH") ?? readEnvironmentValue(parentEnv, "HOMEPATH");
|
|
305
|
-
if (homeDrive && homePath) {
|
|
306
|
-
return `${homeDrive}${homePath}`;
|
|
307
|
-
}
|
|
308
|
-
if (homeDir && path.win32.isAbsolute(homeDir)) {
|
|
309
|
-
return homeDir;
|
|
310
|
-
}
|
|
311
|
-
const systemDrive = readEnvironmentValue(env, "SystemDrive") ?? readEnvironmentValue(parentEnv, "SystemDrive") ?? "C:";
|
|
312
|
-
const username = readEnvironmentValue(env, "USERNAME") ?? readEnvironmentValue(parentEnv, "USERNAME");
|
|
313
|
-
return username ? path.win32.join(systemDrive, "Users", username) : undefined;
|
|
314
|
-
}
|
|
315
|
-
function readEnvironmentValue(env, name) {
|
|
316
|
-
const entry = Object.entries(env).find(([key]) => key.toLowerCase() === name.toLowerCase());
|
|
317
|
-
const value = entry?.[1];
|
|
318
|
-
return typeof value === "string" && value.trim().length > 0 ? value : undefined;
|
|
319
|
-
}
|
|
320
|
-
function setEnvironmentValueIfMissing(env, name, value) {
|
|
321
|
-
if (readEnvironmentValue(env, name)) {
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
env[name] = value;
|
|
325
|
-
}
|
|
326
125
|
export class StreamingProviderProcessRunner {
|
|
327
126
|
terminalExitGraceMs;
|
|
328
127
|
terminalSuccessCeilingMs;
|
|
329
128
|
terminalWorkPollMs;
|
|
330
|
-
|
|
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) {
|
|
331
131
|
this.terminalExitGraceMs = terminalExitGraceMs;
|
|
332
132
|
this.terminalSuccessCeilingMs = terminalSuccessCeilingMs;
|
|
333
133
|
this.terminalWorkPollMs = terminalWorkPollMs;
|
|
134
|
+
this.outputPipeReleaseGraceMs = outputPipeReleaseGraceMs;
|
|
334
135
|
}
|
|
335
136
|
async run(request, handlers = {}, signal) {
|
|
336
137
|
assertHostDatabaseCapabilityBoundary();
|
|
@@ -384,6 +185,7 @@ export class StreamingProviderProcessRunner {
|
|
|
384
185
|
}
|
|
385
186
|
const stdout = new BoundedOutputTail(PROVIDER_OUTPUT_CAPTURE_LIMIT_CHARS);
|
|
386
187
|
const stderr = new BoundedOutputTail(PROVIDER_OUTPUT_CAPTURE_LIMIT_CHARS);
|
|
188
|
+
const outputPipes = new OutputPipeRelease(child, this.outputPipeReleaseGraceMs, message => stderr.appendLine(message));
|
|
387
189
|
let settled = false;
|
|
388
190
|
let closed = false;
|
|
389
191
|
let cancellationRequested = false;
|
|
@@ -401,8 +203,10 @@ export class StreamingProviderProcessRunner {
|
|
|
401
203
|
let terminalWorkTickRunning = false;
|
|
402
204
|
let latestTurnFailed = false;
|
|
403
205
|
let readiness = null;
|
|
206
|
+
const backgroundTurnEnd = new ClaudeBackgroundTurnEndWatch(request.command, this.terminalExitGraceMs, () => finishAfterTerminalSuccess("turn_ended_with_background_work"));
|
|
404
207
|
const cleanup = () => {
|
|
405
208
|
stopTerminalWorkTimer();
|
|
209
|
+
backgroundTurnEnd.stop();
|
|
406
210
|
graceIdleMs = null;
|
|
407
211
|
ceilingIdleMs = null;
|
|
408
212
|
signal?.removeEventListener("abort", abort);
|
|
@@ -426,12 +230,10 @@ export class StreamingProviderProcessRunner {
|
|
|
426
230
|
// termination; only a failed termination proof rejects the run.
|
|
427
231
|
void terminate().catch(fail);
|
|
428
232
|
};
|
|
429
|
-
if (signal?.aborted)
|
|
233
|
+
if (signal?.aborted)
|
|
430
234
|
abort();
|
|
431
|
-
|
|
432
|
-
else {
|
|
235
|
+
else
|
|
433
236
|
signal?.addEventListener("abort", abort, { once: true });
|
|
434
|
-
}
|
|
435
237
|
child.on("error", fail);
|
|
436
238
|
const startGrant = startGated ? child.stdio[3] : null;
|
|
437
239
|
if (startGated && !startGrant) {
|
|
@@ -514,16 +316,6 @@ export class StreamingProviderProcessRunner {
|
|
|
514
316
|
stopTerminalWorkTimer();
|
|
515
317
|
void terminate().catch(fail);
|
|
516
318
|
};
|
|
517
|
-
const workInFlight = async () => {
|
|
518
|
-
try {
|
|
519
|
-
if (handlers.isToolCallInFlight?.())
|
|
520
|
-
return true;
|
|
521
|
-
}
|
|
522
|
-
catch {
|
|
523
|
-
// A failing probe must not keep the provider open or stop it early on its own.
|
|
524
|
-
}
|
|
525
|
-
return await hasNonterminalManagedCommand(request.env?.FORGE_LOG_DIR).catch(() => false);
|
|
526
|
-
};
|
|
527
319
|
// The grace and the ceiling only count time in which no supervised work is in flight:
|
|
528
320
|
// a provider waiting on an MCP tool call or on a managed command it started is not
|
|
529
321
|
// finished, even when its turn has ended. The grace restarts once that work is done.
|
|
@@ -532,7 +324,7 @@ export class StreamingProviderProcessRunner {
|
|
|
532
324
|
return;
|
|
533
325
|
terminalWorkTickRunning = true;
|
|
534
326
|
try {
|
|
535
|
-
const inFlight = await
|
|
327
|
+
const inFlight = await providerWorkInFlight(handlers, request.env?.FORGE_LOG_DIR);
|
|
536
328
|
const now = performance.now();
|
|
537
329
|
const elapsed = Math.max(0, now - terminalWorkTickAt);
|
|
538
330
|
terminalWorkTickAt = now;
|
|
@@ -586,6 +378,7 @@ export class StreamingProviderProcessRunner {
|
|
|
586
378
|
if (request.captureOutput !== false)
|
|
587
379
|
stdout.appendLine(line);
|
|
588
380
|
const handled = handlers.onStdoutLine?.(line);
|
|
381
|
+
backgroundTurnEnd.consume(line);
|
|
589
382
|
if (!terminalTerminationStarted) {
|
|
590
383
|
if (isProviderTerminalSuccess(line)) {
|
|
591
384
|
latestTurnFailed = false;
|
|
@@ -666,68 +459,36 @@ export class StreamingProviderProcessRunner {
|
|
|
666
459
|
...(memory ?? {}),
|
|
667
460
|
...(cancelledBeforeClose ? { cancelled: true } : {}),
|
|
668
461
|
...(terminalStopReason && !cancellationRequested ? { terminalStopReason } : {}),
|
|
462
|
+
...outputPipes.resultFields(),
|
|
669
463
|
});
|
|
670
464
|
}).catch(fail);
|
|
671
465
|
});
|
|
672
466
|
});
|
|
673
467
|
}
|
|
674
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
|
+
}
|
|
675
479
|
/**
|
|
676
480
|
* The typed failure for a provider run that ended without calling its required Forge
|
|
677
|
-
* completion tool. A run Forge stopped at the success ceiling
|
|
678
|
-
* 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.
|
|
679
483
|
*/
|
|
680
484
|
export function providerCompletionToolMissingFailure(message, result) {
|
|
485
|
+
if (result?.terminalStopReason === "turn_ended_with_background_work")
|
|
486
|
+
return providerTurnEndedWithBackgroundWorkFailure(message);
|
|
681
487
|
if (result?.terminalStopReason === "success_ceiling") {
|
|
682
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.`);
|
|
683
489
|
}
|
|
684
490
|
return new ForgeFailureError("provider_completion_tool_missing", message);
|
|
685
491
|
}
|
|
686
|
-
/** A stream event that shows the provider is working on a turn: model output or a tool result. */
|
|
687
|
-
function isProviderTurnActivity(line) {
|
|
688
|
-
const trimmed = line.trim();
|
|
689
|
-
if (!trimmed.startsWith("{"))
|
|
690
|
-
return false;
|
|
691
|
-
try {
|
|
692
|
-
const event = JSON.parse(trimmed);
|
|
693
|
-
return event.type === "assistant"
|
|
694
|
-
|| event.type === "user"
|
|
695
|
-
|| (event.type === "system" && event.subtype === "init")
|
|
696
|
-
|| event.type === "turn.started"
|
|
697
|
-
|| event.type === "item.started";
|
|
698
|
-
}
|
|
699
|
-
catch {
|
|
700
|
-
return false;
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
function isProviderTerminalFailure(line) {
|
|
704
|
-
const trimmed = line.trim();
|
|
705
|
-
if (!trimmed.startsWith("{"))
|
|
706
|
-
return false;
|
|
707
|
-
try {
|
|
708
|
-
const event = JSON.parse(trimmed);
|
|
709
|
-
// The same events the output parsers report as provider errors.
|
|
710
|
-
return event.type === "turn.failed"
|
|
711
|
-
|| event.type === "error"
|
|
712
|
-
|| (event.type === "result" && (event.subtype !== "success" || event.is_error === true));
|
|
713
|
-
}
|
|
714
|
-
catch {
|
|
715
|
-
return false;
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
function isProviderTerminalSuccess(line) {
|
|
719
|
-
const trimmed = line.trim();
|
|
720
|
-
if (!trimmed.startsWith("{"))
|
|
721
|
-
return false;
|
|
722
|
-
try {
|
|
723
|
-
const event = JSON.parse(trimmed);
|
|
724
|
-
return event.type === "turn.completed"
|
|
725
|
-
|| (event.type === "result" && event.subtype === "success" && event.is_error !== true);
|
|
726
|
-
}
|
|
727
|
-
catch {
|
|
728
|
-
return false;
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
492
|
class HostProcessTreeMemoryObserver {
|
|
732
493
|
launch;
|
|
733
494
|
processGroupId;
|
|
@@ -885,18 +646,7 @@ async function resolveProviderProcessLaunch(command, args) {
|
|
|
885
646
|
if (process.platform !== "win32") {
|
|
886
647
|
return { command, args };
|
|
887
648
|
}
|
|
888
|
-
|
|
889
|
-
if (cursorDirect) {
|
|
890
|
-
return cursorDirect;
|
|
891
|
-
}
|
|
892
|
-
const resolved = await resolveWindowsCommand(command);
|
|
893
|
-
if (!resolved) {
|
|
894
|
-
return { command, args };
|
|
895
|
-
}
|
|
896
|
-
return resolveCodexNpmDirectLaunch(resolved, args)
|
|
897
|
-
?? resolveClaudeNpmDirectLaunch(resolved, args)
|
|
898
|
-
?? resolvePackageManagerDirectLaunch(resolved, args)
|
|
899
|
-
?? buildWindowsLaunchCommand(resolved, args);
|
|
649
|
+
return await resolveWindowsProviderLaunch(command, args);
|
|
900
650
|
}
|
|
901
651
|
const UNIX_PROVIDER_START_GATE_SHELL = "/bin/sh";
|
|
902
652
|
const UNIX_PROVIDER_START_GATE_NAME = "forge-provider-start-gate";
|
|
@@ -1005,144 +755,3 @@ async function waitForWindowsProviderReady(launch, signal, isClosed) {
|
|
|
1005
755
|
await new Promise(resolve => setTimeout(resolve, 25));
|
|
1006
756
|
}
|
|
1007
757
|
}
|
|
1008
|
-
export function resolveCodexNpmDirectLaunch(commandPath, args) {
|
|
1009
|
-
const extension = path.extname(commandPath).toLowerCase();
|
|
1010
|
-
if ((extension !== ".cmd" && extension !== ".ps1")
|
|
1011
|
-
|| path.basename(commandPath, extension).toLowerCase() !== "codex") {
|
|
1012
|
-
return null;
|
|
1013
|
-
}
|
|
1014
|
-
const entryPoint = path.join(path.dirname(commandPath), "node_modules", "@openai", "codex", "bin", "codex.js");
|
|
1015
|
-
return fs.existsSync(entryPoint)
|
|
1016
|
-
? { command: process.execPath, args: [entryPoint, ...args] }
|
|
1017
|
-
: null;
|
|
1018
|
-
}
|
|
1019
|
-
/**
|
|
1020
|
-
* npm installs of Claude Code (`npm i -g @anthropic-ai/claude-code`) put a `claude.cmd` shim on
|
|
1021
|
-
* PATH; launch its cli.js directly for the same Job Object reasons as Codex. The native installer
|
|
1022
|
-
* ships `claude.exe`, which is preferred by PATH resolution and needs no rewrite.
|
|
1023
|
-
*/
|
|
1024
|
-
export function resolveClaudeNpmDirectLaunch(commandPath, args) {
|
|
1025
|
-
const extension = path.extname(commandPath).toLowerCase();
|
|
1026
|
-
if ((extension !== ".cmd" && extension !== ".ps1")
|
|
1027
|
-
|| path.basename(commandPath, extension).toLowerCase() !== "claude") {
|
|
1028
|
-
return null;
|
|
1029
|
-
}
|
|
1030
|
-
const entryPoint = path.join(path.dirname(commandPath), "node_modules", "@anthropic-ai", "claude-code", "cli.js");
|
|
1031
|
-
return fs.existsSync(entryPoint)
|
|
1032
|
-
? { command: process.execPath, args: [entryPoint, ...args] }
|
|
1033
|
-
: null;
|
|
1034
|
-
}
|
|
1035
|
-
/**
|
|
1036
|
-
* Avoids cmd.exe's nested-quote handling for package-manager shims. That
|
|
1037
|
-
* quoting loses executable paths containing spaces after the command is
|
|
1038
|
-
* wrapped by the Windows Job Object supervisor.
|
|
1039
|
-
*/
|
|
1040
|
-
export function resolvePackageManagerDirectLaunch(commandPath, args) {
|
|
1041
|
-
const extension = path.extname(commandPath).toLowerCase();
|
|
1042
|
-
if (extension !== ".cmd" && extension !== ".ps1")
|
|
1043
|
-
return null;
|
|
1044
|
-
const packageManager = path.basename(commandPath, extension).toLowerCase();
|
|
1045
|
-
if (!["corepack", "npm", "npx", "pnpm", "pnpx", "yarn", "yarnpkg"].includes(packageManager))
|
|
1046
|
-
return null;
|
|
1047
|
-
const root = path.dirname(commandPath);
|
|
1048
|
-
const candidates = [
|
|
1049
|
-
path.join(root, "node_modules", "corepack", "dist", packageManager === "corepack" ? "corepack.js" : `${packageManager}.js`),
|
|
1050
|
-
...(packageManager === "npm" || packageManager === "npx"
|
|
1051
|
-
? [path.join(root, "node_modules", "npm", "bin", `${packageManager}-cli.js`)]
|
|
1052
|
-
: []),
|
|
1053
|
-
...(packageManager === "pnpm" || packageManager === "pnpx"
|
|
1054
|
-
? [path.join(root, "node_modules", "pnpm", "bin", `${packageManager}.cjs`)]
|
|
1055
|
-
: []),
|
|
1056
|
-
...(packageManager === "yarn" || packageManager === "yarnpkg"
|
|
1057
|
-
? [path.join(root, "node_modules", "yarn", "bin", "yarn.js")]
|
|
1058
|
-
: []),
|
|
1059
|
-
];
|
|
1060
|
-
const entryPoint = candidates.find(candidate => fs.existsSync(candidate));
|
|
1061
|
-
if (!entryPoint)
|
|
1062
|
-
return null;
|
|
1063
|
-
const adjacentNode = path.join(root, "node.exe");
|
|
1064
|
-
return {
|
|
1065
|
-
command: fs.existsSync(adjacentNode) ? adjacentNode : process.execPath,
|
|
1066
|
-
args: [entryPoint, ...args],
|
|
1067
|
-
};
|
|
1068
|
-
}
|
|
1069
|
-
async function resolveWindowsCommand(command) {
|
|
1070
|
-
if (path.isAbsolute(command)) {
|
|
1071
|
-
return command;
|
|
1072
|
-
}
|
|
1073
|
-
const resolvedFromPath = resolveWindowsCommandFromPath(command);
|
|
1074
|
-
if (resolvedFromPath) {
|
|
1075
|
-
return resolvedFromPath;
|
|
1076
|
-
}
|
|
1077
|
-
try {
|
|
1078
|
-
const result = await execFileAsync("where.exe", [command], { timeout: 2000 });
|
|
1079
|
-
return chooseWindowsCommandCandidate(result.stdout.split(/\r?\n/));
|
|
1080
|
-
}
|
|
1081
|
-
catch {
|
|
1082
|
-
return null;
|
|
1083
|
-
}
|
|
1084
|
-
}
|
|
1085
|
-
/**
|
|
1086
|
-
* Resolves Windows commands without spawning where.exe. Runtime launches can
|
|
1087
|
-
* happen while the machine is under enough process pressure for where.exe to
|
|
1088
|
-
* miss its timeout; returning the unresolved package-manager name in that case
|
|
1089
|
-
* makes Node fall back to a shell shim that cannot survive Job Object wrapping.
|
|
1090
|
-
*/
|
|
1091
|
-
export function resolveWindowsCommandFromPath(command, pathValue = process.env.PATH ?? "", pathExtValue = process.env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD") {
|
|
1092
|
-
if (!command || path.isAbsolute(command) || command.includes("/") || command.includes("\\")) {
|
|
1093
|
-
return null;
|
|
1094
|
-
}
|
|
1095
|
-
const hasExtension = path.extname(command).length > 0;
|
|
1096
|
-
const extensions = hasExtension
|
|
1097
|
-
? [""]
|
|
1098
|
-
: [...new Set([
|
|
1099
|
-
"",
|
|
1100
|
-
".exe",
|
|
1101
|
-
".ps1",
|
|
1102
|
-
".cmd",
|
|
1103
|
-
".bat",
|
|
1104
|
-
...pathExtValue.split(";").map(value => value.trim().toLowerCase()).filter(Boolean),
|
|
1105
|
-
])];
|
|
1106
|
-
for (const rawDirectory of pathValue.split(path.delimiter)) {
|
|
1107
|
-
const directory = rawDirectory.trim().replace(/^"|"$/gu, "");
|
|
1108
|
-
if (!directory)
|
|
1109
|
-
continue;
|
|
1110
|
-
const candidates = [];
|
|
1111
|
-
for (const extension of extensions) {
|
|
1112
|
-
const candidate = path.join(directory, `${command}${extension}`);
|
|
1113
|
-
if (fs.existsSync(candidate))
|
|
1114
|
-
candidates.push(candidate);
|
|
1115
|
-
}
|
|
1116
|
-
const resolved = chooseWindowsCommandCandidate(candidates);
|
|
1117
|
-
if (resolved)
|
|
1118
|
-
return resolved;
|
|
1119
|
-
}
|
|
1120
|
-
return null;
|
|
1121
|
-
}
|
|
1122
|
-
export function chooseWindowsCommandCandidate(candidates) {
|
|
1123
|
-
const normalized = candidates
|
|
1124
|
-
.map((candidate) => candidate.trim())
|
|
1125
|
-
.filter((candidate) => candidate.length > 0);
|
|
1126
|
-
if (normalized.length === 0) {
|
|
1127
|
-
return null;
|
|
1128
|
-
}
|
|
1129
|
-
const preferredExtensions = [".exe", ".ps1", ".cmd", ".bat", ""];
|
|
1130
|
-
for (const extension of preferredExtensions) {
|
|
1131
|
-
const candidate = normalized.find((entry) => path.extname(entry).toLowerCase() === extension);
|
|
1132
|
-
if (candidate) {
|
|
1133
|
-
return candidate;
|
|
1134
|
-
}
|
|
1135
|
-
}
|
|
1136
|
-
return normalized[0];
|
|
1137
|
-
}
|
|
1138
|
-
async function readProcessLines(stream, onLine) {
|
|
1139
|
-
const reader = readline.createInterface({ input: stream });
|
|
1140
|
-
try {
|
|
1141
|
-
for await (const line of reader) {
|
|
1142
|
-
await onLine(line);
|
|
1143
|
-
}
|
|
1144
|
-
}
|
|
1145
|
-
finally {
|
|
1146
|
-
reader.close();
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
@@ -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
|