@loucompanion/forge-bridge 0.1.4-dev.b33004c2b0ea → 0.1.4-dev.bb5355d0d83f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -0
- package/dist/bridge/bridge-chat-provider-command.d.ts +16 -0
- package/dist/bridge/bridge-chat-provider-command.js +137 -0
- package/dist/bridge/bridge-chat.types.d.ts +10 -0
- package/dist/bridge/bridge-chat.types.js +16 -1
- package/dist/bridge/bridge.service.d.ts +1 -1
- package/dist/bridge/bridge.service.js +4 -110
- package/dist/bridge/runner-host-capabilities.d.ts +3 -0
- package/dist/bridge/runner-host-capabilities.js +13 -0
- package/dist/runtime/attempt-database-broker.d.ts +1 -1
- package/dist/runtime/docker-engine-probe.d.ts +5 -0
- package/dist/runtime/docker-engine-probe.js +7 -0
- package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
- package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
- package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
- package/dist/runtime/ephemeral-test-postgres.js +303 -0
- package/dist/runtime/host-facts.d.ts +2 -1
- package/dist/runtime/host-load-admission.d.ts +9 -2
- package/dist/runtime/host-load-child-environment.d.ts +11 -6
- package/dist/runtime/host-load-child-environment.js +19 -10
- package/dist/runtime/host-load-governor-config.d.ts +10 -1
- package/dist/runtime/host-load-governor-config.js +7 -0
- package/dist/runtime/host-load-governor.d.ts +10 -0
- package/dist/runtime/host-load-governor.js +125 -34
- package/dist/runtime/host-load-sampler.d.ts +34 -4
- package/dist/runtime/host-load-sampler.js +73 -7
- package/dist/runtime/host-load-step-class.d.ts +3 -1
- package/dist/runtime/host-load-step-class.js +60 -5
- package/dist/runtime/host-load-test-slot.d.ts +43 -0
- package/dist/runtime/host-load-test-slot.js +81 -0
- package/dist/runtime/host-load-token-ledger.d.ts +26 -0
- package/dist/runtime/host-load-token-ledger.js +93 -61
- package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
- package/dist/runtime/host-load-windows-cpu.js +85 -0
- package/dist/runtime/host-runtime-lease.d.ts +1 -1
- package/dist/runtime/host-runtime-lease.js +1 -1
- package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
- package/dist/runtime/native-test-postgres-fallback.js +60 -8
- package/dist/sandbox/host-capacity-broker.d.ts +7 -1
- package/dist/sandbox/host-capacity-broker.js +23 -4
- package/dist/session/architect-waits.d.ts +2 -0
- package/dist/session/architect-waits.js +138 -0
- package/dist/session/managed-attempt-tools.d.ts +0 -7
- package/dist/session/managed-attempt-tools.js +51 -62
- package/dist/session/managed-command-host-load.d.ts +2 -0
- package/dist/session/managed-command-host-load.js +2 -1
- package/dist/session/phase-completion.runtime.js +1 -1
- package/dist/session/phase-completion.schemas.js +25 -23
- package/dist/session/phase-completion.validation.js +3 -1
- package/dist/session/pre-publication-native-postgres.d.ts +30 -0
- package/dist/session/pre-publication-native-postgres.js +111 -0
- package/dist/session/pre-publication-pass.d.ts +2 -1
- package/dist/session/pre-publication-pass.js +8 -5
- package/dist/session/pre-publication-step-execution.d.ts +2 -1
- package/dist/session/pre-publication-step-execution.js +6 -5
- package/dist/session/pre-publication-validation.d.ts +9 -3
- package/dist/session/pre-publication-validation.js +62 -34
- package/dist/session/provider-cli/claude-background-work.d.ts +66 -0
- package/dist/session/provider-cli/claude-background-work.js +180 -0
- package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +73 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +13 -22
- package/dist/session/provider-cli/provider-cli.process.js +36 -337
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +2 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +45 -8
- package/dist/session/provider-cli/provider-cli.runtime.js +7 -0
- package/dist/session/provider-cli/provider-cli.service.js +2 -8
- package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +4 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +45 -0
- package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
- package/dist/session/provider-cli/provider-output-pipes.js +67 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +2 -0
- package/dist/session/provider-cli/provider-output-state.js +6 -0
- package/dist/session/sandbox-host-capacity-gate.js +12 -3
- package/dist/session/session.types.js +1 -1
- package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
- package/dist/shared/process/windows-app-execution-alias.js +45 -0
- package/dist/shared/process/windows-launch.d.ts +18 -0
- package/dist/shared/process/windows-launch.js +68 -0
- package/dist/shared/provider-capabilities.js +5 -6
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Windows environment a provider child (and every tool it runs, such as dotnet and pwsh)
|
|
3
|
+
* gets from the Bridge. Provider children start from an allowlist, not the Bridge's whole
|
|
4
|
+
* environment, so each variable Windows tools expect must be listed here or defaulted below.
|
|
5
|
+
*/
|
|
6
|
+
export declare const windowsAllowedProviderParentEnvNames: readonly ["SystemRoot", "SystemDrive", "ComSpec", "PATHEXT", "APPDATA", "LOCALAPPDATA", "USERNAME", "USERDOMAIN", "HOMEDRIVE", "HOMEPATH", "ProgramData", "ProgramFiles", "ProgramFiles(x86)", "ProgramW6432", "PROCESSOR_ARCHITECTURE", "PROCESSOR_IDENTIFIER", "NUMBER_OF_PROCESSORS", "ALLUSERSPROFILE", "PUBLIC", "CommonProgramFiles", "CommonProgramFiles(x86)", "CommonProgramW6432", "OS", "windir", "DOTNET_ROOT", "DOTNET_ROOT(x86)", "DOTNET_CLI_HOME", "NUGET_PACKAGES", "NUGET_HTTP_CACHE_PATH", "CLAUDE_CODE_GIT_BASH_PATH"];
|
|
7
|
+
/** Fills in the Windows system, machine, profile and .NET variables a provider child needs. */
|
|
8
|
+
export declare function normalizeWindowsProviderEnvironment(env: NodeJS.ProcessEnv, parentEnv: NodeJS.ProcessEnv, homeDir: string, arch: string): void;
|
|
9
|
+
/** A case-insensitive, non-blank environment lookup (Windows variable names ignore case). */
|
|
10
|
+
export declare function readEnvironmentValue(env: NodeJS.ProcessEnv, name: string): string | undefined;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
/**
|
|
3
|
+
* The Windows environment a provider child (and every tool it runs, such as dotnet and pwsh)
|
|
4
|
+
* gets from the Bridge. Provider children start from an allowlist, not the Bridge's whole
|
|
5
|
+
* environment, so each variable Windows tools expect must be listed here or defaulted below.
|
|
6
|
+
*/
|
|
7
|
+
export const windowsAllowedProviderParentEnvNames = [
|
|
8
|
+
"SystemRoot",
|
|
9
|
+
"SystemDrive",
|
|
10
|
+
"ComSpec",
|
|
11
|
+
"PATHEXT",
|
|
12
|
+
"APPDATA",
|
|
13
|
+
"LOCALAPPDATA",
|
|
14
|
+
"USERNAME",
|
|
15
|
+
"USERDOMAIN",
|
|
16
|
+
"HOMEDRIVE",
|
|
17
|
+
"HOMEPATH",
|
|
18
|
+
"ProgramData",
|
|
19
|
+
"ProgramFiles",
|
|
20
|
+
"ProgramFiles(x86)",
|
|
21
|
+
"ProgramW6432",
|
|
22
|
+
// The .NET SDK reads these during startup (the MSI workload installer behind
|
|
23
|
+
// `dotnet --info` and `dotnet workload` throws on a missing PROCESSOR_ARCHITECTURE),
|
|
24
|
+
// and other Windows tools expect the standard machine variables too.
|
|
25
|
+
"PROCESSOR_ARCHITECTURE",
|
|
26
|
+
"PROCESSOR_IDENTIFIER",
|
|
27
|
+
"NUMBER_OF_PROCESSORS",
|
|
28
|
+
"ALLUSERSPROFILE",
|
|
29
|
+
"PUBLIC",
|
|
30
|
+
"CommonProgramFiles",
|
|
31
|
+
"CommonProgramFiles(x86)",
|
|
32
|
+
"CommonProgramW6432",
|
|
33
|
+
"OS",
|
|
34
|
+
"windir",
|
|
35
|
+
"DOTNET_ROOT",
|
|
36
|
+
"DOTNET_ROOT(x86)",
|
|
37
|
+
"DOTNET_CLI_HOME",
|
|
38
|
+
"NUGET_PACKAGES",
|
|
39
|
+
"NUGET_HTTP_CACHE_PATH",
|
|
40
|
+
"CLAUDE_CODE_GIT_BASH_PATH"
|
|
41
|
+
];
|
|
42
|
+
/** Fills in the Windows system, machine, profile and .NET variables a provider child needs. */
|
|
43
|
+
export function normalizeWindowsProviderEnvironment(env, parentEnv, homeDir, arch) {
|
|
44
|
+
const systemRoot = normalizeWindowsSystemEnvironment(env, parentEnv);
|
|
45
|
+
normalizeWindowsProgramFolders(env, parentEnv);
|
|
46
|
+
normalizeWindowsMachineEnvironment(env, parentEnv, systemRoot, arch);
|
|
47
|
+
normalizeWindowsProfileEnvironment(env, parentEnv, homeDir);
|
|
48
|
+
setEnvironmentValueIfMissing(env, "DOTNET_NOLOGO", "1");
|
|
49
|
+
setEnvironmentValueIfMissing(env, "DOTNET_CLI_TELEMETRY_OPTOUT", "1");
|
|
50
|
+
setEnvironmentValueIfMissing(env, "DOTNET_SKIP_FIRST_TIME_EXPERIENCE", "1");
|
|
51
|
+
setEnvironmentValueIfMissing(env, "NUGET_XMLDOC_MODE", "skip");
|
|
52
|
+
}
|
|
53
|
+
function normalizeWindowsSystemEnvironment(env, parentEnv) {
|
|
54
|
+
const systemRoot = readEnvironmentValue(env, "SystemRoot") ?? readEnvironmentValue(parentEnv, "SystemRoot") ?? "C:\\Windows";
|
|
55
|
+
const systemDrive = path.win32.parse(systemRoot).root.replace(/\\$/, "") || "C:";
|
|
56
|
+
setEnvironmentValueIfMissing(env, "SystemRoot", systemRoot);
|
|
57
|
+
setEnvironmentValueIfMissing(env, "SystemDrive", readEnvironmentValue(parentEnv, "SystemDrive") ?? systemDrive);
|
|
58
|
+
setEnvironmentValueIfMissing(env, "ComSpec", readEnvironmentValue(parentEnv, "ComSpec") ?? path.win32.join(systemRoot, "System32", "cmd.exe"));
|
|
59
|
+
setEnvironmentValueIfMissing(env, "PATHEXT", readEnvironmentValue(parentEnv, "PATHEXT") ?? ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.CPL");
|
|
60
|
+
return systemRoot;
|
|
61
|
+
}
|
|
62
|
+
function normalizeWindowsProgramFolders(env, parentEnv) {
|
|
63
|
+
const systemDriveRoot = `${readEnvironmentValue(env, "SystemDrive") ?? "C:"}\\`;
|
|
64
|
+
const defaultProgramFiles = path.win32.join(systemDriveRoot, "Program Files");
|
|
65
|
+
const defaultProgramData = path.win32.join(systemDriveRoot, "ProgramData");
|
|
66
|
+
const programFiles = readEnvironmentValue(env, "ProgramFiles")
|
|
67
|
+
?? readEnvironmentValue(parentEnv, "ProgramFiles")
|
|
68
|
+
?? defaultProgramFiles;
|
|
69
|
+
setEnvironmentValueIfMissing(env, "ProgramFiles", programFiles);
|
|
70
|
+
setEnvironmentValueIfMissing(env, "ProgramW6432", readEnvironmentValue(parentEnv, "ProgramW6432") ?? defaultProgramFiles);
|
|
71
|
+
setEnvironmentValueIfMissing(env, "ProgramFiles(x86)", readEnvironmentValue(parentEnv, "ProgramFiles(x86)") ?? path.win32.join(systemDriveRoot, "Program Files (x86)"));
|
|
72
|
+
setEnvironmentValueIfMissing(env, "ProgramData", readEnvironmentValue(parentEnv, "ProgramData") ?? defaultProgramData);
|
|
73
|
+
setEnvironmentValueIfMissing(env, "ALLUSERSPROFILE", readEnvironmentValue(parentEnv, "ALLUSERSPROFILE") ?? readEnvironmentValue(env, "ProgramData") ?? defaultProgramData);
|
|
74
|
+
}
|
|
75
|
+
function normalizeWindowsMachineEnvironment(env, parentEnv, systemRoot, arch) {
|
|
76
|
+
setEnvironmentValueIfMissing(env, "windir", readEnvironmentValue(parentEnv, "windir") ?? systemRoot);
|
|
77
|
+
setEnvironmentValueIfMissing(env, "OS", readEnvironmentValue(parentEnv, "OS") ?? "Windows_NT");
|
|
78
|
+
const processorArchitecture = readEnvironmentValue(parentEnv, "PROCESSOR_ARCHITECTURE") ?? windowsProcessorArchitecture(arch);
|
|
79
|
+
if (processorArchitecture) {
|
|
80
|
+
setEnvironmentValueIfMissing(env, "PROCESSOR_ARCHITECTURE", processorArchitecture);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** The PROCESSOR_ARCHITECTURE value Windows sets for a native process of this architecture. */
|
|
84
|
+
function windowsProcessorArchitecture(arch) {
|
|
85
|
+
switch (arch) {
|
|
86
|
+
case "x64": return "AMD64";
|
|
87
|
+
case "arm64": return "ARM64";
|
|
88
|
+
case "ia32": return "x86";
|
|
89
|
+
default: return undefined;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function normalizeWindowsProfileEnvironment(env, parentEnv, homeDir) {
|
|
93
|
+
const userProfile = resolveWindowsUserProfile(env, parentEnv, homeDir);
|
|
94
|
+
if (userProfile) {
|
|
95
|
+
setEnvironmentValueIfMissing(env, "USERPROFILE", userProfile);
|
|
96
|
+
setEnvironmentValueIfMissing(env, "HOME", userProfile);
|
|
97
|
+
setEnvironmentValueIfMissing(env, "DOTNET_CLI_HOME", userProfile);
|
|
98
|
+
setEnvironmentValueIfMissing(env, "NUGET_PACKAGES", path.win32.join(userProfile, ".nuget", "packages"));
|
|
99
|
+
const parsed = path.win32.parse(userProfile);
|
|
100
|
+
if (parsed.root) {
|
|
101
|
+
setEnvironmentValueIfMissing(env, "HOMEDRIVE", parsed.root.replace(/\\$/, ""));
|
|
102
|
+
setEnvironmentValueIfMissing(env, "HOMEPATH", userProfile.slice(parsed.root.length - (parsed.root.endsWith("\\") ? 1 : 0)) || "\\");
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const appData = readEnvironmentValue(env, "APPDATA")
|
|
106
|
+
?? readEnvironmentValue(parentEnv, "APPDATA")
|
|
107
|
+
?? (userProfile ? path.win32.join(userProfile, "AppData", "Roaming") : undefined);
|
|
108
|
+
const localAppData = readEnvironmentValue(env, "LOCALAPPDATA")
|
|
109
|
+
?? readEnvironmentValue(parentEnv, "LOCALAPPDATA")
|
|
110
|
+
?? (userProfile ? path.win32.join(userProfile, "AppData", "Local") : undefined);
|
|
111
|
+
if (appData) {
|
|
112
|
+
setEnvironmentValueIfMissing(env, "APPDATA", appData);
|
|
113
|
+
}
|
|
114
|
+
if (localAppData) {
|
|
115
|
+
setEnvironmentValueIfMissing(env, "LOCALAPPDATA", localAppData);
|
|
116
|
+
setEnvironmentValueIfMissing(env, "NUGET_HTTP_CACHE_PATH", path.win32.join(localAppData, "NuGet", "v3-cache"));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function resolveWindowsUserProfile(env, parentEnv, homeDir) {
|
|
120
|
+
const existing = readEnvironmentValue(env, "USERPROFILE") ?? readEnvironmentValue(parentEnv, "USERPROFILE");
|
|
121
|
+
if (existing) {
|
|
122
|
+
return existing;
|
|
123
|
+
}
|
|
124
|
+
const home = readEnvironmentValue(env, "HOME") ?? readEnvironmentValue(parentEnv, "HOME");
|
|
125
|
+
if (home && path.win32.isAbsolute(home)) {
|
|
126
|
+
return home;
|
|
127
|
+
}
|
|
128
|
+
const homeDrive = readEnvironmentValue(env, "HOMEDRIVE") ?? readEnvironmentValue(parentEnv, "HOMEDRIVE");
|
|
129
|
+
const homePath = readEnvironmentValue(env, "HOMEPATH") ?? readEnvironmentValue(parentEnv, "HOMEPATH");
|
|
130
|
+
if (homeDrive && homePath) {
|
|
131
|
+
return `${homeDrive}${homePath}`;
|
|
132
|
+
}
|
|
133
|
+
if (homeDir && path.win32.isAbsolute(homeDir)) {
|
|
134
|
+
return homeDir;
|
|
135
|
+
}
|
|
136
|
+
const systemDrive = readEnvironmentValue(env, "SystemDrive") ?? readEnvironmentValue(parentEnv, "SystemDrive") ?? "C:";
|
|
137
|
+
const username = readEnvironmentValue(env, "USERNAME") ?? readEnvironmentValue(parentEnv, "USERNAME");
|
|
138
|
+
return username ? path.win32.join(systemDrive, "Users", username) : undefined;
|
|
139
|
+
}
|
|
140
|
+
/** A case-insensitive, non-blank environment lookup (Windows variable names ignore case). */
|
|
141
|
+
export function readEnvironmentValue(env, name) {
|
|
142
|
+
const entry = Object.entries(env).find(([key]) => key.toLowerCase() === name.toLowerCase());
|
|
143
|
+
const value = entry?.[1];
|
|
144
|
+
return typeof value === "string" && value.trim().length > 0 ? value : undefined;
|
|
145
|
+
}
|
|
146
|
+
function setEnvironmentValueIfMissing(env, name, value) {
|
|
147
|
+
if (readEnvironmentValue(env, name)) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
env[name] = value;
|
|
151
|
+
}
|
|
@@ -4,3 +4,7 @@
|
|
|
4
4
|
* Unreadable or stale receipts do not count.
|
|
5
5
|
*/
|
|
6
6
|
export declare function hasNonterminalManagedCommand(logDirectory: string | undefined, nowMs?: number): Promise<boolean>;
|
|
7
|
+
/** A stream event that shows the provider is working on a turn: model output or a tool result. */
|
|
8
|
+
export declare function isProviderTurnActivity(line: string): boolean;
|
|
9
|
+
export declare function isProviderTerminalFailure(line: string): boolean;
|
|
10
|
+
export declare function isProviderTerminalSuccess(line: string): boolean;
|
|
@@ -45,3 +45,48 @@ async function receiptHoldsProvider(receiptPath, nowMs) {
|
|
|
45
45
|
return false;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
+
/** A stream event that shows the provider is working on a turn: model output or a tool result. */
|
|
49
|
+
export function isProviderTurnActivity(line) {
|
|
50
|
+
const trimmed = line.trim();
|
|
51
|
+
if (!trimmed.startsWith("{"))
|
|
52
|
+
return false;
|
|
53
|
+
try {
|
|
54
|
+
const event = JSON.parse(trimmed);
|
|
55
|
+
return event.type === "assistant"
|
|
56
|
+
|| event.type === "user"
|
|
57
|
+
|| (event.type === "system" && event.subtype === "init")
|
|
58
|
+
|| event.type === "turn.started"
|
|
59
|
+
|| event.type === "item.started";
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export function isProviderTerminalFailure(line) {
|
|
66
|
+
const trimmed = line.trim();
|
|
67
|
+
if (!trimmed.startsWith("{"))
|
|
68
|
+
return false;
|
|
69
|
+
try {
|
|
70
|
+
const event = JSON.parse(trimmed);
|
|
71
|
+
// The same events the output parsers report as provider errors.
|
|
72
|
+
return event.type === "turn.failed"
|
|
73
|
+
|| event.type === "error"
|
|
74
|
+
|| (event.type === "result" && (event.subtype !== "success" || event.is_error === true));
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
export function isProviderTerminalSuccess(line) {
|
|
81
|
+
const trimmed = line.trim();
|
|
82
|
+
if (!trimmed.startsWith("{"))
|
|
83
|
+
return false;
|
|
84
|
+
try {
|
|
85
|
+
const event = JSON.parse(trimmed);
|
|
86
|
+
return event.type === "turn.completed"
|
|
87
|
+
|| (event.type === "result" && event.subtype === "success" && event.is_error !== true);
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ChildProcess } from "node:child_process";
|
|
2
|
+
/**
|
|
3
|
+
* How long Forge keeps waiting, once the provider's root process has exited, for its output
|
|
4
|
+
* pipes to reach end-of-file. Node reports a child's "close" only after every copy of its
|
|
5
|
+
* stdout and stderr write ends is closed, and a descendant that escaped the provider's
|
|
6
|
+
* supervision can hold an inherited copy for as long as it runs: on Windows, a process that a
|
|
7
|
+
* Microsoft Store app-execution alias (`...\WindowsApps\pwsh.exe`) created outside the provider's
|
|
8
|
+
* Job Object; elsewhere, one that left the provider's process group. Output the root wrote
|
|
9
|
+
* before it exited drains within this grace. After it, Forge closes its read ends, so the run
|
|
10
|
+
* settles on the root's exit instead of on that descendant's.
|
|
11
|
+
*/
|
|
12
|
+
export declare const PROVIDER_OUTPUT_PIPE_RELEASE_GRACE_MS = 5000;
|
|
13
|
+
export interface OutputPipeReleaseFields {
|
|
14
|
+
/** Present when Forge closed the provider's output pipes because they outlived its root process. */
|
|
15
|
+
readonly outputPipesReleasedAfterExit?: true;
|
|
16
|
+
}
|
|
17
|
+
/** Closes a child's output pipes a bounded grace after the child exits, unless they close first. */
|
|
18
|
+
export declare class OutputPipeRelease {
|
|
19
|
+
private readonly child;
|
|
20
|
+
private readonly graceMs;
|
|
21
|
+
private readonly onRelease;
|
|
22
|
+
private timer;
|
|
23
|
+
private released;
|
|
24
|
+
constructor(child: ChildProcess, graceMs: number, onRelease: (message: string) => void);
|
|
25
|
+
resultFields(): OutputPipeReleaseFields;
|
|
26
|
+
stop(): void;
|
|
27
|
+
private arm;
|
|
28
|
+
private release;
|
|
29
|
+
}
|
|
30
|
+
export declare function readProcessLines(stream: NodeJS.ReadableStream, onLine: (line: string) => Promise<void> | void): Promise<void>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import readline from "node:readline";
|
|
2
|
+
/**
|
|
3
|
+
* How long Forge keeps waiting, once the provider's root process has exited, for its output
|
|
4
|
+
* pipes to reach end-of-file. Node reports a child's "close" only after every copy of its
|
|
5
|
+
* stdout and stderr write ends is closed, and a descendant that escaped the provider's
|
|
6
|
+
* supervision can hold an inherited copy for as long as it runs: on Windows, a process that a
|
|
7
|
+
* Microsoft Store app-execution alias (`...\WindowsApps\pwsh.exe`) created outside the provider's
|
|
8
|
+
* Job Object; elsewhere, one that left the provider's process group. Output the root wrote
|
|
9
|
+
* before it exited drains within this grace. After it, Forge closes its read ends, so the run
|
|
10
|
+
* settles on the root's exit instead of on that descendant's.
|
|
11
|
+
*/
|
|
12
|
+
export const PROVIDER_OUTPUT_PIPE_RELEASE_GRACE_MS = 5_000;
|
|
13
|
+
/** Closes a child's output pipes a bounded grace after the child exits, unless they close first. */
|
|
14
|
+
export class OutputPipeRelease {
|
|
15
|
+
child;
|
|
16
|
+
graceMs;
|
|
17
|
+
onRelease;
|
|
18
|
+
timer = null;
|
|
19
|
+
released = false;
|
|
20
|
+
constructor(child, graceMs, onRelease) {
|
|
21
|
+
this.child = child;
|
|
22
|
+
this.graceMs = graceMs;
|
|
23
|
+
this.onRelease = onRelease;
|
|
24
|
+
child.once("exit", () => this.arm());
|
|
25
|
+
child.once("close", () => this.stop());
|
|
26
|
+
}
|
|
27
|
+
resultFields() {
|
|
28
|
+
return this.released ? { outputPipesReleasedAfterExit: true } : {};
|
|
29
|
+
}
|
|
30
|
+
stop() {
|
|
31
|
+
if (!this.timer)
|
|
32
|
+
return;
|
|
33
|
+
clearTimeout(this.timer);
|
|
34
|
+
this.timer = null;
|
|
35
|
+
}
|
|
36
|
+
arm() {
|
|
37
|
+
if (this.timer || this.released)
|
|
38
|
+
return;
|
|
39
|
+
this.timer = setTimeout(() => this.release(), Math.max(0, this.graceMs));
|
|
40
|
+
}
|
|
41
|
+
release() {
|
|
42
|
+
this.timer = null;
|
|
43
|
+
// fd 0 is the child's input; Node's "close" waits only for the others.
|
|
44
|
+
const open = this.child.stdio.slice(1).filter(stream => stream && !stream.destroyed);
|
|
45
|
+
if (open.length === 0)
|
|
46
|
+
return;
|
|
47
|
+
this.released = true;
|
|
48
|
+
this.onRelease(`forge-bridge: the provider's output pipes were still open ${this.graceMs} ms after its process exited, `
|
|
49
|
+
+ "so a descendant outside its supervision still holds them. Forge closed them to settle the run.");
|
|
50
|
+
for (const stream of open)
|
|
51
|
+
stream?.destroy();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export async function readProcessLines(stream, onLine) {
|
|
55
|
+
const reader = readline.createInterface({ input: stream });
|
|
56
|
+
// readline finishes on "end" only. A stream OutputPipeRelease destroys closes without one;
|
|
57
|
+
// closing the reader then still delivers every line already read.
|
|
58
|
+
stream.once("close", () => reader.close());
|
|
59
|
+
try {
|
|
60
|
+
for await (const line of reader) {
|
|
61
|
+
await onLine(line);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
reader.close();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { RunnerDispatchEvent } from "../session.types.js";
|
|
2
2
|
import { type ProviderUsage } from "./provider-usage.js";
|
|
3
3
|
export declare function messageFromError(error: unknown): string;
|
|
4
|
+
/** Keeps the end of `value`, where a process's failure detail is, within `maximumLength`. */
|
|
5
|
+
export declare function clipTail(value: string, maximumLength: number): string;
|
|
4
6
|
export declare function clip(value: string, maxLength: number): string;
|
|
5
7
|
export interface ProviderOutputState {
|
|
6
8
|
readonly sessionLabel: string | null;
|
|
@@ -2,6 +2,12 @@ import { addUsage, emptyUsage, readUsageNumber } from "./provider-usage.js";
|
|
|
2
2
|
export function messageFromError(error) {
|
|
3
3
|
return error instanceof Error ? error.message : String(error);
|
|
4
4
|
}
|
|
5
|
+
/** Keeps the end of `value`, where a process's failure detail is, within `maximumLength`. */
|
|
6
|
+
export function clipTail(value, maximumLength) {
|
|
7
|
+
if (value.length <= maximumLength)
|
|
8
|
+
return value;
|
|
9
|
+
return `...${value.slice(-(maximumLength - 3))}`;
|
|
10
|
+
}
|
|
5
11
|
export function clip(value, maxLength) {
|
|
6
12
|
if (maxLength <= 0) {
|
|
7
13
|
return "";
|
|
@@ -107,6 +107,8 @@ export class SandboxBrokeredHostLoadGate {
|
|
|
107
107
|
holding = true;
|
|
108
108
|
if (!fenced.signal.aborted)
|
|
109
109
|
fenced.abort(reason);
|
|
110
|
+
// The bridge marks the host token retained, so this attempt's next step does not wait for it.
|
|
111
|
+
this.send("retain", requestId, request);
|
|
110
112
|
if (!stillGone)
|
|
111
113
|
return;
|
|
112
114
|
let checking = false;
|
|
@@ -177,9 +179,10 @@ function responseError(request, response) {
|
|
|
177
179
|
return new ForgeFailureError(response.code ?? "host_capacity_broker_failed", message, "bridge");
|
|
178
180
|
}
|
|
179
181
|
/**
|
|
180
|
-
* The bridge's reply, or null while there is none
|
|
181
|
-
*
|
|
182
|
-
* bridge's: the sandbox user can
|
|
182
|
+
* The bridge's reply, or null while there is none (or the one opened was just
|
|
183
|
+
* replaced by a newer reply). Only a regular file with a single link, owned by the
|
|
184
|
+
* trusted uid and writable by no one else, is the bridge's: the sandbox user can
|
|
185
|
+
* create none of those (see host-capacity-broker.ts).
|
|
183
186
|
* Anything else fails closed with sandbox_host_capacity_reply_untrusted.
|
|
184
187
|
*/
|
|
185
188
|
async function readResponse(responsePath, requestId, trustedOwnerUid) {
|
|
@@ -195,6 +198,12 @@ async function readResponse(responsePath, requestId, trustedOwnerUid) {
|
|
|
195
198
|
let content;
|
|
196
199
|
try {
|
|
197
200
|
const stat = await handle.stat();
|
|
201
|
+
// No link left: the bridge renamed a newer reply over this one after it was opened
|
|
202
|
+
// (waiting -> admitted, admitted -> fenced). It is not a forgery, and nothing is read
|
|
203
|
+
// from it; the next poll opens the newer reply. Only the bridge can replace a reply,
|
|
204
|
+
// since the directory is root-owned and not writable by the sandbox user.
|
|
205
|
+
if (stat.isFile() && stat.nlink === 0)
|
|
206
|
+
return null;
|
|
198
207
|
if (!stat.isFile() || stat.nlink !== 1)
|
|
199
208
|
throw untrustedReply(responsePath, "it is not a regular file with a single link");
|
|
200
209
|
if (stat.uid !== trustedOwnerUid)
|
|
@@ -525,7 +525,7 @@ function unvalidatedFailureFactsForCode(code, source) {
|
|
|
525
525
|
if (code === "provider_completion_tool_missing") {
|
|
526
526
|
return facts(code, "provider", "agent", source, "non_retryable", "inspect_failure");
|
|
527
527
|
}
|
|
528
|
-
if (
|
|
528
|
+
if (["provider_terminated_at_turn_ceiling", "provider_turn_ended_with_background_work"].includes(code)) {
|
|
529
529
|
return facts(code, "provider", "agent", source, "retryable", "retry_with_policy");
|
|
530
530
|
}
|
|
531
531
|
if (code === "provider_context_window_exhausted") {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tools an agent commonly starts by bare name. When one of them resolves to a Microsoft Store
|
|
3
|
+
* app-execution alias (`%LOCALAPPDATA%\Microsoft\WindowsApps\pwsh.exe` and the like), Windows
|
|
4
|
+
* creates the process it starts outside the provider's Job Object: it survives the job, keeps the
|
|
5
|
+
* pipe handles it inherited, and holds the attempt's output open until it exits on its own.
|
|
6
|
+
*/
|
|
7
|
+
export declare const APP_EXECUTION_ALIAS_SENSITIVE_TOOLS: readonly ["pwsh", "node", "dotnet"];
|
|
8
|
+
export interface AppExecutionAliasFinding {
|
|
9
|
+
readonly tool: string;
|
|
10
|
+
/** The alias the tool's bare name resolves to. */
|
|
11
|
+
readonly aliasPath: string;
|
|
12
|
+
/** The first regular install later on PATH, or null when the alias is the only one. */
|
|
13
|
+
readonly nextInstallPath: string | null;
|
|
14
|
+
}
|
|
15
|
+
/** The sensitive tools whose bare name resolves, on this PATH, to an app-execution alias. */
|
|
16
|
+
export declare function findAppExecutionAliasTools(pathValue: string, pathExtValue?: string, tools?: readonly string[]): AppExecutionAliasFinding[];
|
|
17
|
+
export declare function describeAppExecutionAliasFindings(findings: readonly AppExecutionAliasFinding[]): string | null;
|
|
18
|
+
/** Reads PATH and PATHEXT from an environment whose key case is not normalized (Windows: "Path"). */
|
|
19
|
+
export declare function appExecutionAliasWarning(env: Readonly<Record<string, string | undefined>>, platform?: NodeJS.Platform): string | null;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { isWindowsAppExecutionAliasPath, resolveWindowsCommandFromPath } from "./windows-launch.js";
|
|
2
|
+
/**
|
|
3
|
+
* Tools an agent commonly starts by bare name. When one of them resolves to a Microsoft Store
|
|
4
|
+
* app-execution alias (`%LOCALAPPDATA%\Microsoft\WindowsApps\pwsh.exe` and the like), Windows
|
|
5
|
+
* creates the process it starts outside the provider's Job Object: it survives the job, keeps the
|
|
6
|
+
* pipe handles it inherited, and holds the attempt's output open until it exits on its own.
|
|
7
|
+
*/
|
|
8
|
+
export const APP_EXECUTION_ALIAS_SENSITIVE_TOOLS = ["pwsh", "node", "dotnet"];
|
|
9
|
+
/** The sensitive tools whose bare name resolves, on this PATH, to an app-execution alias. */
|
|
10
|
+
export function findAppExecutionAliasTools(pathValue, pathExtValue, tools = APP_EXECUTION_ALIAS_SENSITIVE_TOOLS) {
|
|
11
|
+
const findings = [];
|
|
12
|
+
for (const tool of tools) {
|
|
13
|
+
const aliasPath = resolveWindowsCommandFromPath(tool, pathValue, pathExtValue);
|
|
14
|
+
if (!aliasPath || !isWindowsAppExecutionAliasPath(aliasPath))
|
|
15
|
+
continue;
|
|
16
|
+
const nextInstallPath = resolveWindowsCommandFromPath(tool, pathValue, pathExtValue, { skipAppExecutionAliases: true });
|
|
17
|
+
findings.push({ tool, aliasPath, nextInstallPath });
|
|
18
|
+
}
|
|
19
|
+
return findings;
|
|
20
|
+
}
|
|
21
|
+
export function describeAppExecutionAliasFindings(findings) {
|
|
22
|
+
if (findings.length === 0)
|
|
23
|
+
return null;
|
|
24
|
+
const tools = findings.map(finding => `${finding.tool} -> ${finding.aliasPath}${finding.nextInstallPath
|
|
25
|
+
? ` (a regular install later on PATH: ${finding.nextInstallPath})`
|
|
26
|
+
: " (no regular install on PATH)"}`);
|
|
27
|
+
return "Host readiness warning: on the provider PATH, "
|
|
28
|
+
+ `${tools.join("; ")} resolve${findings.length === 1 ? "s" : ""} to a Microsoft Store app-execution alias under WindowsApps. `
|
|
29
|
+
+ "A process started through an alias is created outside the provider's Windows Job Object, survives it, "
|
|
30
|
+
+ "and can hold the attempt's output pipes open until it exits. Install the tool normally "
|
|
31
|
+
+ "(for PowerShell, the MSI under C:\\Program Files\\PowerShell\\7) and put it ahead of WindowsApps on PATH.";
|
|
32
|
+
}
|
|
33
|
+
/** Reads PATH and PATHEXT from an environment whose key case is not normalized (Windows: "Path"). */
|
|
34
|
+
export function appExecutionAliasWarning(env, platform = process.platform) {
|
|
35
|
+
if (platform !== "win32")
|
|
36
|
+
return null;
|
|
37
|
+
const pathValue = environmentValue(env, "PATH");
|
|
38
|
+
if (!pathValue)
|
|
39
|
+
return null;
|
|
40
|
+
return describeAppExecutionAliasFindings(findAppExecutionAliasTools(pathValue, environmentValue(env, "PATHEXT")));
|
|
41
|
+
}
|
|
42
|
+
function environmentValue(env, name) {
|
|
43
|
+
const key = Object.keys(env).find(candidate => candidate.toUpperCase() === name);
|
|
44
|
+
return key === undefined ? undefined : env[key];
|
|
45
|
+
}
|
|
@@ -6,3 +6,21 @@ export declare function buildWindowsCmdLaunch(command: string, args: readonly st
|
|
|
6
6
|
export declare function buildWindowsLaunchCommand(commandPath: string, args: readonly string[]): LaunchCommand;
|
|
7
7
|
export declare function windowsCommandLine(command: string, args: readonly string[]): string;
|
|
8
8
|
export declare function quoteWindowsCommandLineArg(value: string): string;
|
|
9
|
+
export interface WindowsCommandPathOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Skip candidates under a `WindowsApps` directory. Those are Microsoft Store app-execution
|
|
12
|
+
* aliases: the process they start is created outside the caller's Job Object, so it survives the
|
|
13
|
+
* job and keeps any inherited pipe open. Resolve the next real install on PATH instead.
|
|
14
|
+
*/
|
|
15
|
+
readonly skipAppExecutionAliases?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Resolves Windows commands without spawning where.exe. Runtime launches can
|
|
19
|
+
* happen while the machine is under enough process pressure for where.exe to
|
|
20
|
+
* miss its timeout; returning the unresolved package-manager name in that case
|
|
21
|
+
* makes Node fall back to a shell shim that cannot survive Job Object wrapping.
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolveWindowsCommandFromPath(command: string, pathValue?: string, pathExtValue?: string, options?: WindowsCommandPathOptions): string | null;
|
|
24
|
+
export declare function chooseWindowsCommandCandidate(candidates: readonly string[]): string | null;
|
|
25
|
+
/** True for a path inside a `WindowsApps` directory, where Store app-execution aliases live. */
|
|
26
|
+
export declare function isWindowsAppExecutionAliasPath(candidate: string): boolean;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
1
2
|
import path from "node:path";
|
|
2
3
|
export function buildWindowsCmdLaunch(command, args, comSpec = process.env.ComSpec) {
|
|
3
4
|
const resolvedComSpec = comSpec?.trim();
|
|
@@ -39,3 +40,70 @@ function powershellExecutable() {
|
|
|
39
40
|
? path.join(systemRoot, "System32", "WindowsPowerShell", "v1.0", "powershell.exe")
|
|
40
41
|
: "powershell.exe";
|
|
41
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Resolves Windows commands without spawning where.exe. Runtime launches can
|
|
45
|
+
* happen while the machine is under enough process pressure for where.exe to
|
|
46
|
+
* miss its timeout; returning the unresolved package-manager name in that case
|
|
47
|
+
* makes Node fall back to a shell shim that cannot survive Job Object wrapping.
|
|
48
|
+
*/
|
|
49
|
+
export function resolveWindowsCommandFromPath(command, pathValue = process.env.PATH ?? "", pathExtValue = process.env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD", options = {}) {
|
|
50
|
+
if (!command || path.isAbsolute(command) || command.includes("/") || command.includes("\\")) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const hasExtension = path.extname(command).length > 0;
|
|
54
|
+
const extensions = hasExtension
|
|
55
|
+
? [""]
|
|
56
|
+
: [...new Set([
|
|
57
|
+
"",
|
|
58
|
+
".exe",
|
|
59
|
+
".ps1",
|
|
60
|
+
".cmd",
|
|
61
|
+
".bat",
|
|
62
|
+
...pathExtValue.split(";").map(value => value.trim().toLowerCase()).filter(Boolean),
|
|
63
|
+
])];
|
|
64
|
+
for (const rawDirectory of pathValue.split(path.delimiter)) {
|
|
65
|
+
const directory = rawDirectory.trim().replace(/^"|"$/gu, "");
|
|
66
|
+
if (!directory)
|
|
67
|
+
continue;
|
|
68
|
+
const candidates = [];
|
|
69
|
+
for (const extension of extensions) {
|
|
70
|
+
const candidate = path.join(directory, `${command}${extension}`);
|
|
71
|
+
if (options.skipAppExecutionAliases && isWindowsAppExecutionAliasPath(candidate))
|
|
72
|
+
continue;
|
|
73
|
+
if (pathEntryExists(candidate))
|
|
74
|
+
candidates.push(candidate);
|
|
75
|
+
}
|
|
76
|
+
const resolved = chooseWindowsCommandCandidate(candidates);
|
|
77
|
+
if (resolved)
|
|
78
|
+
return resolved;
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
export function chooseWindowsCommandCandidate(candidates) {
|
|
83
|
+
const normalized = candidates
|
|
84
|
+
.map((candidate) => candidate.trim())
|
|
85
|
+
.filter((candidate) => candidate.length > 0);
|
|
86
|
+
if (normalized.length === 0) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
const preferredExtensions = [".exe", ".ps1", ".cmd", ".bat", ""];
|
|
90
|
+
for (const extension of preferredExtensions) {
|
|
91
|
+
const candidate = normalized.find((entry) => path.extname(entry).toLowerCase() === extension);
|
|
92
|
+
if (candidate) {
|
|
93
|
+
return candidate;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return normalized[0];
|
|
97
|
+
}
|
|
98
|
+
/** True for a path inside a `WindowsApps` directory, where Store app-execution aliases live. */
|
|
99
|
+
export function isWindowsAppExecutionAliasPath(candidate) {
|
|
100
|
+
return candidate.split(/[\\/]+/u).some(segment => segment.toLowerCase() === "windowsapps");
|
|
101
|
+
}
|
|
102
|
+
// An app-execution alias is a reparse point that stat() may not open, so an
|
|
103
|
+
// alias is also accepted when only lstat() can see it.
|
|
104
|
+
function pathEntryExists(candidate) {
|
|
105
|
+
if (fs.existsSync(candidate))
|
|
106
|
+
return true;
|
|
107
|
+
return isWindowsAppExecutionAliasPath(candidate)
|
|
108
|
+
&& fs.lstatSync(candidate, { throwIfNoEntry: false }) !== undefined;
|
|
109
|
+
}
|
|
@@ -40,8 +40,12 @@ function chatProviderEntries(cliProviders, providerStatuses) {
|
|
|
40
40
|
const providerKind = provider.trim().toLowerCase();
|
|
41
41
|
if (providerKind.length === 0)
|
|
42
42
|
continue;
|
|
43
|
-
statuses.set(providerKind, {
|
|
43
|
+
statuses.set(providerKind, { status });
|
|
44
44
|
}
|
|
45
|
+
// Only configured CLI providers can run a Bridge Chat turn. A status entry for a
|
|
46
|
+
// provider that is not in cliProviders (for example a leftover entry in
|
|
47
|
+
// bridge.json for a CLI that is no longer installed) annotates nothing and must
|
|
48
|
+
// not be advertised as a chat provider.
|
|
45
49
|
const providers = new Map();
|
|
46
50
|
for (const provider of cliProviders) {
|
|
47
51
|
const providerKind = provider.trim().toLowerCase();
|
|
@@ -52,11 +56,6 @@ function chatProviderEntries(cliProviders, providerStatuses) {
|
|
|
52
56
|
status: statuses.get(providerKind)?.status,
|
|
53
57
|
});
|
|
54
58
|
}
|
|
55
|
-
for (const [providerKind, entry] of statuses) {
|
|
56
|
-
if (!providers.has(providerKind)) {
|
|
57
|
-
providers.set(providerKind, entry);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
59
|
return [...providers.values()].sort((left, right) => compareStable(left.providerKind, right.providerKind));
|
|
61
60
|
}
|
|
62
61
|
function sortedUniqueStrings(values, lower) {
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const forgeBridgeVersion = "0.1.4-dev.
|
|
1
|
+
export declare const forgeBridgeVersion = "0.1.4-dev.bb5355d0d83f";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const forgeBridgeVersion = "0.1.4-dev.
|
|
1
|
+
export const forgeBridgeVersion = "0.1.4-dev.bb5355d0d83f";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loucompanion/forge-bridge",
|
|
3
|
-
"version": "0.1.4-dev.
|
|
3
|
+
"version": "0.1.4-dev.bb5355d0d83f",
|
|
4
4
|
"description": "Forge runner bridge CLI for connecting local developer machines to Forge dispatch.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|