@loucompanion/forge-bridge 0.2.1-dev.4f11ffc822f9 → 0.2.1-dev.7171bf414613
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 +41 -3
- package/dist/bridge/bridge-state-io.d.ts +6 -2
- package/dist/bridge/bridge-state-io.js +22 -4
- package/dist/bridge/bridge.service.d.ts +10 -0
- package/dist/bridge/bridge.service.js +63 -101
- package/dist/bridge/bridge.types.d.ts +16 -0
- package/dist/bridge/bridge.types.js +2 -1
- package/dist/bridge/default-session-service.d.ts +13 -0
- package/dist/bridge/default-session-service.js +22 -0
- package/dist/bridge/dispatch-offer-policy.d.ts +22 -0
- package/dist/bridge/dispatch-offer-policy.js +58 -0
- package/dist/bridge/runner-host-capabilities.js +14 -1
- package/dist/bridge/windows-bash-resolution.d.ts +31 -0
- package/dist/bridge/windows-bash-resolution.js +153 -0
- package/dist/cleanup/cleanup-wip.js +3 -3
- package/dist/cleanup/forge-owned-paths.d.ts +2 -0
- package/dist/cleanup/forge-owned-paths.js +9 -0
- package/dist/cli/cli.help.js +1 -1
- package/dist/cli/cli.service.js +11 -43
- package/dist/cli/local-config.d.ts +12 -1
- package/dist/cli/local-config.js +35 -1
- package/dist/cli/provider-cli-advertising.d.ts +24 -0
- package/dist/cli/provider-cli-advertising.js +88 -0
- package/dist/runtime/host-load-admission.d.ts +5 -0
- package/dist/runtime/host-load-capacity.d.ts +198 -0
- package/dist/runtime/host-load-capacity.js +353 -0
- package/dist/runtime/host-load-child-environment.d.ts +13 -0
- package/dist/runtime/host-load-child-environment.js +35 -1
- package/dist/runtime/host-load-governor-config.d.ts +33 -3
- package/dist/runtime/host-load-governor-config.js +24 -3
- package/dist/runtime/host-load-governor.d.ts +89 -2
- package/dist/runtime/host-load-governor.js +217 -18
- package/dist/runtime/host-load-live-test-slots.d.ts +61 -0
- package/dist/runtime/host-load-live-test-slots.js +193 -0
- package/dist/runtime/host-load-sampler.d.ts +17 -0
- package/dist/runtime/host-load-sampler.js +24 -0
- package/dist/runtime/host-load-step-run.d.ts +37 -3
- package/dist/runtime/host-load-step-run.js +63 -7
- package/dist/runtime/host-load-test-slot.d.ts +3 -0
- package/dist/runtime/host-load-test-slot.js +26 -7
- package/dist/runtime/host-runtime-contract.js +6 -4
- package/dist/runtime/prepared-runtime-readiness.d.ts +12 -2
- package/dist/runtime/prepared-runtime-readiness.js +35 -11
- package/dist/sandbox/runtime.d.ts +1 -2
- package/dist/sandbox/runtime.js +8 -14
- package/dist/sandbox/sandbox-input.d.ts +22 -0
- package/dist/sandbox/sandbox-input.js +49 -0
- package/dist/sandbox/workspace.service.js +15 -2
- package/dist/session/managed-attempt-tools.js +6 -29
- package/dist/session/managed-build-receipt.d.ts +3 -1
- package/dist/session/managed-build-receipt.js +5 -2
- package/dist/session/managed-command-environment.d.ts +8 -0
- package/dist/session/managed-command-environment.js +28 -0
- package/dist/session/managed-command-host-load.d.ts +10 -5
- package/dist/session/managed-command-host-load.js +18 -14
- package/dist/session/phase-completion.artifact-bundle.d.ts +20 -0
- package/dist/session/phase-completion.artifact-bundle.js +167 -0
- package/dist/session/phase-completion.artifacts.d.ts +2 -17
- package/dist/session/phase-completion.artifacts.js +63 -165
- package/dist/session/phase-completion.d.ts +25 -2
- package/dist/session/phase-completion.helpers.js +5 -53
- package/dist/session/phase-completion.js +15 -32
- package/dist/session/phase-completion.mcp-args.js +69 -2
- package/dist/session/phase-completion.phase-aliases.d.ts +5 -0
- package/dist/session/phase-completion.phase-aliases.js +43 -0
- package/dist/session/phase-completion.pr-review-schema.d.ts +1 -0
- package/dist/session/phase-completion.pr-review-schema.js +75 -0
- package/dist/session/phase-completion.pr-review-threads.d.ts +34 -0
- package/dist/session/phase-completion.pr-review-threads.js +90 -0
- package/dist/session/phase-completion.pr-review-validation.d.ts +11 -0
- package/dist/session/phase-completion.pr-review-validation.js +215 -0
- package/dist/session/phase-completion.pr-review.d.ts +36 -0
- package/dist/session/phase-completion.pr-review.js +294 -0
- package/dist/session/phase-completion.prompts.d.ts +1 -1
- package/dist/session/phase-completion.prompts.js +14 -0
- package/dist/session/phase-completion.runtime.js +9 -3
- package/dist/session/phase-completion.schemas.js +12 -2
- package/dist/session/phase-completion.validation.d.ts +1 -0
- package/dist/session/phase-completion.validation.js +9 -1
- package/dist/session/pr-review-diff-base.d.ts +18 -0
- package/dist/session/pr-review-diff-base.js +45 -0
- package/dist/session/pr-review-placement.d.ts +50 -0
- package/dist/session/pr-review-placement.js +91 -0
- package/dist/session/pre-publication-change-set.d.ts +62 -0
- package/dist/session/pre-publication-change-set.js +166 -0
- package/dist/session/pre-publication-host-load.js +6 -5
- package/dist/session/pre-publication-process.js +3 -2
- package/dist/session/pre-publication-validation.d.ts +2 -1
- package/dist/session/pre-publication-validation.js +31 -36
- package/dist/session/provider-cli/dispatch-target-branch.d.ts +7 -0
- package/dist/session/provider-cli/dispatch-target-branch.js +8 -0
- package/dist/session/provider-cli/pr-review-credential-isolation.d.ts +83 -0
- package/dist/session/provider-cli/pr-review-credential-isolation.js +144 -0
- package/dist/session/provider-cli/pr-review-guardrails.d.ts +70 -0
- package/dist/session/provider-cli/pr-review-guardrails.js +360 -0
- package/dist/session/provider-cli/pr-review-prompt.d.ts +11 -0
- package/dist/session/provider-cli/pr-review-prompt.js +132 -0
- package/dist/session/provider-cli/pre-publication-repair.js +8 -3
- package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
- package/dist/session/provider-cli/provider-cli.deterministic.d.ts +1 -0
- package/dist/session/provider-cli/provider-cli.deterministic.js +5 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +6 -3
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +29 -10
- package/dist/session/provider-cli/provider-cli.pr-review.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.pr-review.js +213 -0
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +10 -3
- package/dist/session/provider-cli/provider-cli.prompts.js +123 -70
- package/dist/session/provider-cli/provider-cli.reapply-conflicts.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.reapply-conflicts.js +37 -0
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +14 -0
- package/dist/session/provider-cli/provider-cli.service-support.d.ts +37 -0
- package/dist/session/provider-cli/provider-cli.service-support.js +146 -0
- package/dist/session/provider-cli/provider-cli.service.d.ts +11 -17
- package/dist/session/provider-cli/provider-cli.service.js +33 -148
- package/dist/session/provider-cli/provider-cli.types.d.ts +7 -2
- package/dist/session/sandbox-host-capacity-gate.js +29 -7
- package/dist/session/session-host-project.d.ts +22 -0
- package/dist/session/session-host-project.js +98 -0
- package/dist/session/session.parse-helpers.d.ts +10 -0
- package/dist/session/session.parse-helpers.js +84 -0
- package/dist/session/session.runtime-refresh.d.ts +46 -0
- package/dist/session/session.runtime-refresh.js +116 -0
- package/dist/session/session.service.d.ts +2 -1
- package/dist/session/session.service.js +57 -158
- package/dist/session/session.types.d.ts +5 -0
- package/dist/session/session.types.js +8 -78
- package/dist/session/session.types.pr-review.d.ts +59 -0
- package/dist/session/session.types.pr-review.js +53 -0
- package/dist/shared/provider-capabilities.d.ts +2 -0
- package/dist/shared/provider-capabilities.js +9 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/artifact-injector.js +24 -0
- package/dist/worktree/wip-git.d.ts +25 -0
- package/dist/worktree/wip-git.js +64 -4
- package/dist/worktree/wip-refs.d.ts +23 -0
- package/dist/worktree/wip-refs.js +52 -2
- package/dist/worktree/wip-restore.d.ts +13 -0
- package/dist/worktree/wip-restore.js +159 -25
- package/dist/worktree/wip-snapshot.d.ts +5 -2
- package/dist/worktree/wip-snapshot.js +15 -13
- package/dist/worktree/worktree-origin-sync.d.ts +1 -0
- package/dist/worktree/worktree-origin-sync.js +1 -0
- package/dist/worktree/worktree-wip-events.d.ts +2 -0
- package/dist/worktree/worktree-wip-events.js +53 -3
- package/dist/worktree/worktree-wip.d.ts +7 -0
- package/dist/worktree/worktree-wip.js +17 -2
- package/dist/worktree/worktree.service.d.ts +23 -1
- package/dist/worktree/worktree.service.js +122 -15
- package/dist/worktree/worktree.types.d.ts +16 -0
- package/package.json +1 -1
|
@@ -5,6 +5,7 @@ import { promisify } from "node:util";
|
|
|
5
5
|
import { probeTestPostgresCapability } from "./test-postgres-capability.js";
|
|
6
6
|
import { appExecutionAliasWarning } from "../shared/process/windows-app-execution-alias.js";
|
|
7
7
|
import { buildProviderChildEnvironment } from "../session/provider-cli/provider-cli.process.js";
|
|
8
|
+
import { resolveBashExecutable } from "./windows-bash-resolution.js";
|
|
8
9
|
const execFileAsync = promisify(execFile);
|
|
9
10
|
export class ProcessRunnerHostCapabilityProbe {
|
|
10
11
|
warn;
|
|
@@ -23,7 +24,7 @@ export class ProcessRunnerHostCapabilityProbe {
|
|
|
23
24
|
probe("pnpm", ["--version"]),
|
|
24
25
|
probe("dotnet", ["--version"]),
|
|
25
26
|
probe("git", ["--version"]),
|
|
26
|
-
|
|
27
|
+
probeBash(this.warn),
|
|
27
28
|
probe("pwsh", ["-NoProfile", "-Command", "$PSVersionTable.PSVersion.ToString()"]),
|
|
28
29
|
process.platform === "win32"
|
|
29
30
|
? probe("powershell.exe", ["-NoProfile", "-Command", "$PSVersionTable.PSVersion.ToString()"])
|
|
@@ -62,6 +63,18 @@ async function probe(executable, args) {
|
|
|
62
63
|
return unavailable(executable);
|
|
63
64
|
}
|
|
64
65
|
}
|
|
66
|
+
// On Windows a bare "bash" can resolve to WSL's System32\bash.exe (see resolveBashExecutable), so
|
|
67
|
+
// the probe runs, and reports, the resolved absolute Git Bash path instead.
|
|
68
|
+
async function probeBash(warn) {
|
|
69
|
+
const resolution = await resolveBashExecutable({
|
|
70
|
+
platform: process.platform,
|
|
71
|
+
env: process.env,
|
|
72
|
+
gitExecPath: async () => (await execFileAsync("git", ["--exec-path"], { encoding: "utf8", timeout: 5_000 })).stdout,
|
|
73
|
+
});
|
|
74
|
+
if (resolution.warning)
|
|
75
|
+
warn(resolution.warning);
|
|
76
|
+
return resolution.executable ? probe(resolution.executable, ["--version"]) : unavailable("bash");
|
|
77
|
+
}
|
|
65
78
|
function unavailable(executable) {
|
|
66
79
|
return { available: false, executable, version: null };
|
|
67
80
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Environment variables that name the bash the bridge should use on Windows, in priority order. */
|
|
2
|
+
export declare const WINDOWS_BASH_OVERRIDE_VARIABLES: readonly ["FORGE_BRIDGE_BASH_PATH", "CLAUDE_CODE_GIT_BASH_PATH"];
|
|
3
|
+
export interface BashResolutionInput {
|
|
4
|
+
readonly platform: NodeJS.Platform;
|
|
5
|
+
readonly env: NodeJS.ProcessEnv;
|
|
6
|
+
/** Output of `git --exec-path`, or null when git is unavailable. Called only on Windows. */
|
|
7
|
+
readonly gitExecPath: () => Promise<string | null>;
|
|
8
|
+
readonly fileExists?: (candidate: string) => boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface BashResolution {
|
|
11
|
+
/** What to run: "bash" off Windows, an absolute bash.exe path on Windows, or null when none was found. */
|
|
12
|
+
readonly executable: string | null;
|
|
13
|
+
/** Why the result is not what the host may expect (an override was rejected, nothing was found). */
|
|
14
|
+
readonly warning?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Picks the bash the bridge runs. Off Windows this is plain `bash` from PATH, unchanged.
|
|
18
|
+
*
|
|
19
|
+
* On Windows a bare `bash` is not safe: libuv's executable search looks in the current directory
|
|
20
|
+
* before PATH (unless `NoDefaultCurrentDirectoryInExePath` is set), and a scheduled task with no
|
|
21
|
+
* working directory starts in `C:\Windows\System32`, so `bash` becomes WSL's `System32\bash.exe`
|
|
22
|
+
* even with Git Bash first on PATH. The bridge therefore resolves Git for Windows' bash.exe to an
|
|
23
|
+
* absolute path and never accepts the WSL launcher or a Store app-execution alias.
|
|
24
|
+
*/
|
|
25
|
+
export declare function resolveBashExecutable(input: BashResolutionInput): Promise<BashResolution>;
|
|
26
|
+
/** True for WSL's bash.exe launcher (System32, SysWOW64, Sysnative) and for Store app-execution aliases. */
|
|
27
|
+
export declare function isRejectedWindowsBash(candidate: string, env: NodeJS.ProcessEnv): boolean;
|
|
28
|
+
/** `git --exec-path` is `<root>/mingw64/libexec/git-core` (or clangarm64, mingw32) on Git for Windows. */
|
|
29
|
+
export declare function gitRootFromExecPath(execPath: string | null): string | null;
|
|
30
|
+
/** git.exe lives in `<root>\cmd`, `<root>\bin` or `<root>\mingw64\bin` on Git for Windows. */
|
|
31
|
+
export declare function gitRootFromGitExecutable(gitExecutable: string | null): string | null;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { isWindowsAppExecutionAliasPath } from "../shared/process/windows-launch.js";
|
|
4
|
+
/** Environment variables that name the bash the bridge should use on Windows, in priority order. */
|
|
5
|
+
export const WINDOWS_BASH_OVERRIDE_VARIABLES = ["FORGE_BRIDGE_BASH_PATH", "CLAUDE_CODE_GIT_BASH_PATH"];
|
|
6
|
+
/**
|
|
7
|
+
* Picks the bash the bridge runs. Off Windows this is plain `bash` from PATH, unchanged.
|
|
8
|
+
*
|
|
9
|
+
* On Windows a bare `bash` is not safe: libuv's executable search looks in the current directory
|
|
10
|
+
* before PATH (unless `NoDefaultCurrentDirectoryInExePath` is set), and a scheduled task with no
|
|
11
|
+
* working directory starts in `C:\Windows\System32`, so `bash` becomes WSL's `System32\bash.exe`
|
|
12
|
+
* even with Git Bash first on PATH. The bridge therefore resolves Git for Windows' bash.exe to an
|
|
13
|
+
* absolute path and never accepts the WSL launcher or a Store app-execution alias.
|
|
14
|
+
*/
|
|
15
|
+
export async function resolveBashExecutable(input) {
|
|
16
|
+
if (input.platform !== "win32")
|
|
17
|
+
return { executable: "bash" };
|
|
18
|
+
const fileExists = input.fileExists ?? defaultFileExists;
|
|
19
|
+
const env = input.env;
|
|
20
|
+
// Relative candidates (a "." PATH entry, a relative override) would put the cwd lookup back.
|
|
21
|
+
const accept = (candidate) => Boolean(candidate)
|
|
22
|
+
&& isAbsoluteWindowsPath(candidate)
|
|
23
|
+
&& !isRejectedWindowsBash(candidate, env)
|
|
24
|
+
&& fileExists(candidate);
|
|
25
|
+
for (const name of WINDOWS_BASH_OVERRIDE_VARIABLES) {
|
|
26
|
+
const raw = environmentValue(env, name)?.trim().replace(/^"|"$/gu, "");
|
|
27
|
+
if (!raw)
|
|
28
|
+
continue;
|
|
29
|
+
if (accept(raw))
|
|
30
|
+
return { executable: path.win32.normalize(raw) };
|
|
31
|
+
const reason = !isAbsoluteWindowsPath(raw)
|
|
32
|
+
? "is not an absolute path"
|
|
33
|
+
: isRejectedWindowsBash(raw, env)
|
|
34
|
+
? "points at the WSL launcher or a Store alias, not Git Bash"
|
|
35
|
+
: "does not exist";
|
|
36
|
+
return { executable: null, warning: `${name}=${raw} ${reason}; bash is reported unavailable.` };
|
|
37
|
+
}
|
|
38
|
+
const pathValue = environmentValue(env, "PATH") ?? "";
|
|
39
|
+
const gitRoots = [
|
|
40
|
+
gitRootFromExecPath(await input.gitExecPath().catch(() => null)),
|
|
41
|
+
gitRootFromGitExecutable(findOnWindowsPath(pathValue, "git.exe", fileExists)),
|
|
42
|
+
];
|
|
43
|
+
for (const root of gitRoots) {
|
|
44
|
+
if (!root)
|
|
45
|
+
continue;
|
|
46
|
+
for (const candidate of gitBashCandidates(root)) {
|
|
47
|
+
if (accept(candidate))
|
|
48
|
+
return { executable: candidate };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
for (const directory of windowsPathDirectories(pathValue)) {
|
|
52
|
+
const candidate = path.win32.join(directory, "bash.exe");
|
|
53
|
+
if (accept(candidate))
|
|
54
|
+
return { executable: candidate };
|
|
55
|
+
}
|
|
56
|
+
for (const root of standardGitRoots(env)) {
|
|
57
|
+
for (const candidate of gitBashCandidates(root)) {
|
|
58
|
+
if (accept(candidate))
|
|
59
|
+
return { executable: candidate };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
executable: null,
|
|
64
|
+
warning: "Git Bash (bash.exe from Git for Windows) was not found; bash is reported unavailable. "
|
|
65
|
+
+ "Install Git for Windows or set FORGE_BRIDGE_BASH_PATH to its bin\\bash.exe.",
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/** True for WSL's bash.exe launcher (System32, SysWOW64, Sysnative) and for Store app-execution aliases. */
|
|
69
|
+
export function isRejectedWindowsBash(candidate, env) {
|
|
70
|
+
if (isWindowsAppExecutionAliasPath(candidate))
|
|
71
|
+
return true;
|
|
72
|
+
const normalized = path.win32.normalize(candidate).toLowerCase();
|
|
73
|
+
if (path.win32.basename(normalized) !== "bash.exe" && path.win32.basename(normalized) !== "bash")
|
|
74
|
+
return false;
|
|
75
|
+
const directory = path.win32.dirname(normalized);
|
|
76
|
+
const systemRoot = (environmentValue(env, "SystemRoot") ?? environmentValue(env, "windir") ?? "C:\\Windows").toLowerCase();
|
|
77
|
+
const systemDirectories = ["system32", "syswow64", "sysnative"].map(name => path.win32.join(systemRoot, name));
|
|
78
|
+
return systemDirectories.includes(directory) || /\\windows\\(system32|syswow64|sysnative)$/u.test(directory);
|
|
79
|
+
}
|
|
80
|
+
/** `git --exec-path` is `<root>/mingw64/libexec/git-core` (or clangarm64, mingw32) on Git for Windows. */
|
|
81
|
+
export function gitRootFromExecPath(execPath) {
|
|
82
|
+
const trimmed = execPath?.trim();
|
|
83
|
+
if (!trimmed)
|
|
84
|
+
return null;
|
|
85
|
+
const normalized = path.win32.normalize(trimmed);
|
|
86
|
+
const libexec = normalized.toLowerCase().lastIndexOf("\\libexec");
|
|
87
|
+
if (libexec <= 0)
|
|
88
|
+
return null;
|
|
89
|
+
return path.win32.dirname(normalized.slice(0, libexec));
|
|
90
|
+
}
|
|
91
|
+
/** git.exe lives in `<root>\cmd`, `<root>\bin` or `<root>\mingw64\bin` on Git for Windows. */
|
|
92
|
+
export function gitRootFromGitExecutable(gitExecutable) {
|
|
93
|
+
if (!gitExecutable)
|
|
94
|
+
return null;
|
|
95
|
+
const directory = path.win32.dirname(path.win32.normalize(gitExecutable));
|
|
96
|
+
const leaf = path.win32.basename(directory).toLowerCase();
|
|
97
|
+
if (leaf === "cmd")
|
|
98
|
+
return path.win32.dirname(directory);
|
|
99
|
+
if (leaf === "bin") {
|
|
100
|
+
const parent = path.win32.dirname(directory);
|
|
101
|
+
return /^(mingw64|mingw32|clangarm64|usr)$/u.test(path.win32.basename(parent).toLowerCase())
|
|
102
|
+
? path.win32.dirname(parent)
|
|
103
|
+
: parent;
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
/** A drive-letter (`C:\...`) or UNC path; rooted-but-driveless (`\bin`) and relative paths are not. */
|
|
108
|
+
function isAbsoluteWindowsPath(candidate) {
|
|
109
|
+
return /^[a-z]:[\\/]/iu.test(candidate) || /^[\\/]{2}[^\\/]/u.test(candidate);
|
|
110
|
+
}
|
|
111
|
+
// path.win32 and ";" rather than the host's path module, so the Windows rules are testable anywhere.
|
|
112
|
+
function windowsPathDirectories(pathValue) {
|
|
113
|
+
return pathValue.split(";").map(entry => entry.trim().replace(/^"|"$/gu, "")).filter(Boolean);
|
|
114
|
+
}
|
|
115
|
+
function findOnWindowsPath(pathValue, fileName, fileExists) {
|
|
116
|
+
for (const directory of windowsPathDirectories(pathValue)) {
|
|
117
|
+
const candidate = path.win32.join(directory, fileName);
|
|
118
|
+
if (!isWindowsAppExecutionAliasPath(candidate) && fileExists(candidate))
|
|
119
|
+
return candidate;
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
function gitBashCandidates(root) {
|
|
124
|
+
return [path.win32.join(root, "bin", "bash.exe"), path.win32.join(root, "usr", "bin", "bash.exe")];
|
|
125
|
+
}
|
|
126
|
+
function standardGitRoots(env) {
|
|
127
|
+
const roots = [
|
|
128
|
+
environmentValue(env, "ProgramFiles"),
|
|
129
|
+
environmentValue(env, "ProgramW6432"),
|
|
130
|
+
environmentValue(env, "ProgramFiles(x86)"),
|
|
131
|
+
].filter((value) => Boolean(value)).map(value => path.win32.join(value, "Git"));
|
|
132
|
+
const localAppData = environmentValue(env, "LOCALAPPDATA");
|
|
133
|
+
if (localAppData)
|
|
134
|
+
roots.push(path.win32.join(localAppData, "Programs", "Git"));
|
|
135
|
+
roots.push("C:\\Program Files\\Git");
|
|
136
|
+
const seen = new Set();
|
|
137
|
+
return roots.filter(root => !seen.has(root.toLowerCase()) && Boolean(seen.add(root.toLowerCase())));
|
|
138
|
+
}
|
|
139
|
+
/** Windows environment keys are case-insensitive ("Path"), but a copied env object is not. */
|
|
140
|
+
function environmentValue(env, name) {
|
|
141
|
+
if (env[name] !== undefined)
|
|
142
|
+
return env[name];
|
|
143
|
+
const key = Object.keys(env).find(candidate => candidate.toLowerCase() === name.toLowerCase());
|
|
144
|
+
return key === undefined ? undefined : env[key];
|
|
145
|
+
}
|
|
146
|
+
function defaultFileExists(candidate) {
|
|
147
|
+
try {
|
|
148
|
+
return fs.statSync(candidate).isFile();
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { preserveWorktreeWip } from "../worktree/wip-snapshot.js";
|
|
3
|
-
import { isRuntimeReadinessName } from "./forge-owned-paths.js";
|
|
3
|
+
import { isPrReviewWorktreeKey, isRuntimeReadinessName } from "./forge-owned-paths.js";
|
|
4
4
|
import { isForgeManagedWorkBranch } from "./managed-branch-sweep.js";
|
|
5
5
|
// Cleanup removes stale Forge worktrees: folders whose Git registration is gone (or prunable) and
|
|
6
6
|
// that no lease owns. Such a folder can still hold a session's uncommitted work (the #558 loss:
|
|
@@ -10,8 +10,8 @@ const releaseSuffix = /\.forge-release-[0-9a-f-]{36}$/u;
|
|
|
10
10
|
/** Saves a stale candidate's uncommitted work. Never throws: a failure means "keep the folder". */
|
|
11
11
|
export async function saveStaleWorktreeWork(git, repoPath, worktreeRoot, candidate) {
|
|
12
12
|
const branchName = candidateBranch(worktreeRoot, candidate);
|
|
13
|
-
// A readiness probe never runs an agent: there is no work of anyone's in
|
|
14
|
-
if (isRuntimeReadinessName(branchName))
|
|
13
|
+
// A readiness probe never runs an agent, and a review only reads: there is no work of anyone's in either.
|
|
14
|
+
if (isRuntimeReadinessName(branchName) || isPrReviewWorktreeKey(branchName))
|
|
15
15
|
return { status: "exempt" };
|
|
16
16
|
try {
|
|
17
17
|
const result = await snapshotCandidate(git, repoPath, candidate, branchName);
|
|
@@ -6,4 +6,6 @@ export declare function isForgeOwnedWorktreePath(relativePath: string, separator
|
|
|
6
6
|
export declare function isForgeWorktreeContainer(relativePath: string, separator?: PathSeparator): boolean;
|
|
7
7
|
/** True for a readiness probe's exact folder or branch name: runtime-readiness-<UUID>. */
|
|
8
8
|
export declare function isRuntimeReadinessName(name: string): boolean;
|
|
9
|
+
/** True for a Forge PR review's worktree key, pr-review/<12 hex>-<12 hex>: nothing in it is anyone's work. */
|
|
10
|
+
export declare function isPrReviewWorktreeKey(name: string): boolean;
|
|
9
11
|
export {};
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
// <kind>/<12 hex> a work item (story, task, bug, feature, work_order) or
|
|
5
5
|
// its Architect phase (architect)
|
|
6
6
|
// decompose/<feature|work_order>/<12 hex> a decompose session
|
|
7
|
+
// pr-review/<12 hex>-<12 hex> a Forge PR review of one head (work item, head SHA); it is
|
|
8
|
+
// detached and review-only, so it holds nothing to save
|
|
7
9
|
// runtime-readiness-<UUID> a runtime readiness probe (session.service.ts)
|
|
8
10
|
// draft-<32 hex> a drafting session (DraftingService on the server)
|
|
9
11
|
// A release that couldn't finish deleting can leave `<one of those>.forge-release-<UUID>` beside it.
|
|
@@ -16,10 +18,12 @@ const releaseSuffix = `(?:\\.forge-release-${uuid})?`;
|
|
|
16
18
|
const forgeOwnedWorktreePathPattern = new RegExp("^(?:"
|
|
17
19
|
+ `(?:story|task|bug|feature|work_order|architect)/${hex12}`
|
|
18
20
|
+ `|decompose/(?:feature|work_order)/${hex12}`
|
|
21
|
+
+ `|pr-review/${hex12}-${hex12}`
|
|
19
22
|
+ `|runtime-readiness-${uuid}`
|
|
20
23
|
+ "|draft-[0-9a-f]{32}"
|
|
21
24
|
+ `)${releaseSuffix}$`);
|
|
22
25
|
const runtimeReadinessNamePattern = new RegExp(`^runtime-readiness-${uuid}$`);
|
|
26
|
+
const prReviewWorktreeKeyPattern = new RegExp(`^pr-review/${hex12}-${hex12}$`);
|
|
23
27
|
// Folders that only group Forge's worktrees; cleanup may look inside them but never removes them.
|
|
24
28
|
const forgeWorktreeContainers = new Set([
|
|
25
29
|
"story",
|
|
@@ -31,6 +35,7 @@ const forgeWorktreeContainers = new Set([
|
|
|
31
35
|
"decompose",
|
|
32
36
|
"decompose/feature",
|
|
33
37
|
"decompose/work_order",
|
|
38
|
+
"pr-review",
|
|
34
39
|
]);
|
|
35
40
|
// Split only on the separators the filesystem itself uses. On POSIX a backslash is an ordinary
|
|
36
41
|
// filename character, so a folder a person named `story\0123456789ab` must not read as Forge's
|
|
@@ -51,3 +56,7 @@ export function isForgeWorktreeContainer(relativePath, separator = path.sep) {
|
|
|
51
56
|
export function isRuntimeReadinessName(name) {
|
|
52
57
|
return runtimeReadinessNamePattern.test(name);
|
|
53
58
|
}
|
|
59
|
+
/** True for a Forge PR review's worktree key, pr-review/<12 hex>-<12 hex>: nothing in it is anyone's work. */
|
|
60
|
+
export function isPrReviewWorktreeKey(name) {
|
|
61
|
+
return prReviewWorktreeKeyPattern.test(name);
|
|
62
|
+
}
|
package/dist/cli/cli.help.js
CHANGED
|
@@ -256,7 +256,7 @@ export function commandHelpText(command) {
|
|
|
256
256
|
"Internal MCP server used by provider CLIs to report Forge phase artifacts.",
|
|
257
257
|
"",
|
|
258
258
|
"Usage:",
|
|
259
|
-
" forge-bridge mcp --worktree <path> --work-item-id <id> --phase <phase> # includes ci-repair",
|
|
259
|
+
" forge-bridge mcp --worktree <path> --work-item-id <id> --phase <phase> # includes ci-repair, comment-repair, pr-review",
|
|
260
260
|
"",
|
|
261
261
|
].join("\n");
|
|
262
262
|
case "version":
|
package/dist/cli/cli.service.js
CHANGED
|
@@ -3,13 +3,12 @@ import os from "node:os";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { createInterface } from "node:readline/promises";
|
|
5
5
|
import { configureDotNetToolchain } from "../shared/process/dotnet-toolchain.js";
|
|
6
|
-
import { supportsDraftImageAttachmentsFor } from "../shared/provider-capabilities.js";
|
|
7
6
|
import { redactText } from "../shared/redaction/redaction.js";
|
|
8
7
|
import { BridgeRevokedError, bridgeRevokedExitCode, defaultBridgeServiceConfig, ForgeBridgeService, } from "../bridge/bridge.service.js";
|
|
9
8
|
import { forgeBridgeVersion } from "../version.js";
|
|
10
9
|
import { ManagedWorktreeCleanupService } from "../cleanup/cleanup.service.js";
|
|
11
|
-
import { addRepoMapping, applyLocalConfigDefaults, providerStatusesFor, readLocalConfigSync, removeRepoMapping, resolveLocalConfigPath, resolveLocalYieldFlagPath, setSandboxPolicy, setServerUrl, writeLocalConfig } from "./local-config.js";
|
|
12
|
-
import { BridgeSessionService } from "../session/session.service.js";
|
|
10
|
+
import { addRepoMapping, applyLocalConfigDefaults, pairDerivedCapabilities, providerStatusesFor, readLocalConfigSync, removeRepoMapping, resolveLocalConfigPath, resolveLocalYieldFlagPath, setSandboxPolicy, setServerUrl, writeLocalConfig } from "./local-config.js";
|
|
11
|
+
import { BridgeSessionService, runOnceWithReviewPlacement } from "../session/session.service.js";
|
|
13
12
|
import { redactRunnerDispatchEvent, redactRunOnceResultPacket } from "../session/session-redaction.js";
|
|
14
13
|
import { validateDockerfilePolicy, validateSandboxContract } from "../sandbox/contract.js";
|
|
15
14
|
import { DockerPreflight } from "../sandbox/preflight.js";
|
|
@@ -19,7 +18,7 @@ import { parseCompletionMcpArgs, runCompletionMcpServer } from "../session/phase
|
|
|
19
18
|
import { failureFactsFromError, failureResult, parseRunOnceDispatchPacket } from "../session/session.types.js";
|
|
20
19
|
import { commandHelpText, helpText } from "./cli.help.js";
|
|
21
20
|
import { readLocalYieldFlag, writeLocalYieldFlag } from "../bridge/local-yield-flag.js";
|
|
22
|
-
import {
|
|
21
|
+
import { detectKnownCliProviders, knownProviderCandidates, withDetectedCliProviders } from "./provider-cli-advertising.js";
|
|
23
22
|
import { idleSummaryLine, parseStatusArgs, runIdleStatusCommand } from "./idle-status.js";
|
|
24
23
|
export { claudeDefaultModels, parseCodexModelCatalog, parseCursorModelList } from "./provider-cli-detection.js";
|
|
25
24
|
const apiKeySecretGrantEnv = "FORGE_API_KEY_SECRET_GRANT";
|
|
@@ -61,7 +60,9 @@ export class ForgeBridgeCliService {
|
|
|
61
60
|
return 2;
|
|
62
61
|
}
|
|
63
62
|
if (args.command === "connect") {
|
|
64
|
-
|
|
63
|
+
// Probe every known provider CLI, not only the configured ones, so a CLI installed after
|
|
64
|
+
// pairing gets advertised.
|
|
65
|
+
const config = await withDetectedCliProviders(args.config, knownProviderCandidates(args.config.cliProviders));
|
|
65
66
|
const missing = [
|
|
66
67
|
["server", config.serverUrl],
|
|
67
68
|
["runner id", config.runnerId],
|
|
@@ -243,7 +244,7 @@ export class ForgeBridgeCliService {
|
|
|
243
244
|
const dispatchJson = await fs.readFile(args.dispatchPath, "utf8");
|
|
244
245
|
const dispatch = attachEnvSecretGrant(parseRunOnceDispatchPacket(JSON.parse(dispatchJson)));
|
|
245
246
|
redactionSecrets = exactSecrets(dispatch);
|
|
246
|
-
const result = await this.sessions.runOnce(
|
|
247
|
+
const result = await runOnceWithReviewPlacement(dispatch, (packet) => this.sessions.runOnce(packet, {
|
|
247
248
|
emit: async (event) => {
|
|
248
249
|
const line = {
|
|
249
250
|
type: "runner_event",
|
|
@@ -251,7 +252,7 @@ export class ForgeBridgeCliService {
|
|
|
251
252
|
};
|
|
252
253
|
io.stdout.write(`${JSON.stringify(line)}\n`);
|
|
253
254
|
}
|
|
254
|
-
});
|
|
255
|
+
}));
|
|
255
256
|
await writeJsonAtomic(args.resultPath, redactRunOnceResultPacket(result, redactionSecrets));
|
|
256
257
|
return result.exitCode;
|
|
257
258
|
}
|
|
@@ -956,7 +957,7 @@ function pairedConfig(current, args, claim) {
|
|
|
956
957
|
supportsRunnerAuthoredPhaseArtifacts: current.supportsRunnerAuthoredPhaseArtifacts ?? true,
|
|
957
958
|
supportsDraftRunOnce: current.supportsDraftRunOnce ?? true,
|
|
958
959
|
supportsDraftAttachments: current.supportsDraftAttachments ?? true,
|
|
959
|
-
|
|
960
|
+
...pairDerivedCapabilities(current, args.cliProviders),
|
|
960
961
|
repoMappings: current.repoMappings ?? []
|
|
961
962
|
};
|
|
962
963
|
}
|
|
@@ -1056,7 +1057,7 @@ async function runStatus(args, io) {
|
|
|
1056
1057
|
return args.idle ? await runIdleStatusCommand(args.idle, io) : await writeStatus(args.config, args.checkUpdates, io);
|
|
1057
1058
|
}
|
|
1058
1059
|
async function writeStatus(config, checkUpdates, io) {
|
|
1059
|
-
const detected = await
|
|
1060
|
+
const detected = await detectKnownCliProviders(config.cliProviders);
|
|
1060
1061
|
const repos = config.repoMappings.filter((mapping) => mapping.localPath?.trim());
|
|
1061
1062
|
io.stdout.write(`Forge bridge ${config.version}\n`);
|
|
1062
1063
|
io.stdout.write(`Config: ${resolveLocalConfigPath()}\n`);
|
|
@@ -1128,32 +1129,8 @@ async function cleanupRepos(config, mode, force, cleanup, io) {
|
|
|
1128
1129
|
}
|
|
1129
1130
|
return failures === 0 ? 0 : 1;
|
|
1130
1131
|
}
|
|
1131
|
-
async function withDetectedCliProviders(config, candidates = config.cliProviders) {
|
|
1132
|
-
const detected = await detectCliProviders(uniqueProviders(candidates));
|
|
1133
|
-
const found = detected.filter((result) => result.found);
|
|
1134
|
-
if (found.length === 0) {
|
|
1135
|
-
return config;
|
|
1136
|
-
}
|
|
1137
|
-
const cliProviders = uniqueProviders([...config.cliProviders, ...found.map((result) => result.provider)]);
|
|
1138
|
-
const providerStatuses = { ...config.providerStatuses };
|
|
1139
|
-
for (const result of found) {
|
|
1140
|
-
const existing = providerStatuses[result.provider];
|
|
1141
|
-
providerStatuses[result.provider] = {
|
|
1142
|
-
signedIn: existing?.signedIn ?? true,
|
|
1143
|
-
version: result.version || existing?.version || "",
|
|
1144
|
-
models: result.models.length > 0
|
|
1145
|
-
? result.models
|
|
1146
|
-
: existing?.models ?? providerStatusesFor([result.provider])[result.provider]?.models ?? []
|
|
1147
|
-
};
|
|
1148
|
-
}
|
|
1149
|
-
return {
|
|
1150
|
-
...config,
|
|
1151
|
-
cliProviders,
|
|
1152
|
-
providerStatuses
|
|
1153
|
-
};
|
|
1154
|
-
}
|
|
1155
1132
|
async function withDetectedPairCliProviders(args) {
|
|
1156
|
-
const configured =
|
|
1133
|
+
const configured = knownProviderCandidates(args.cliProviders);
|
|
1157
1134
|
const detectedConfig = await withDetectedCliProviders({
|
|
1158
1135
|
...defaultBridgeServiceConfig({
|
|
1159
1136
|
serverUrl: args.serverUrl,
|
|
@@ -1169,12 +1146,3 @@ async function withDetectedPairCliProviders(args) {
|
|
|
1169
1146
|
cliProviders: detectedConfig.cliProviders
|
|
1170
1147
|
};
|
|
1171
1148
|
}
|
|
1172
|
-
function configuredProviderCandidates(providers) {
|
|
1173
|
-
return uniqueProviders([...providers, "codex", "cursor", "claude"]);
|
|
1174
|
-
}
|
|
1175
|
-
function uniqueProviders(providers) {
|
|
1176
|
-
return providers
|
|
1177
|
-
.map((provider) => provider.trim())
|
|
1178
|
-
.filter((provider) => provider.length > 0)
|
|
1179
|
-
.filter((provider, index, all) => all.findIndex((candidate) => candidate.toLowerCase() === provider.toLowerCase()) === index);
|
|
1180
|
-
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type BridgeProviderStatus, type BridgeRepoMapping, type BridgeServiceConfig, type DerivedCapabilityField } from "../bridge/bridge.types.js";
|
|
2
2
|
export interface BridgeLocalConfig {
|
|
3
3
|
readonly schemaVersion: 1 | 2;
|
|
4
4
|
readonly serverUrl?: string;
|
|
@@ -10,6 +10,8 @@ export interface BridgeLocalConfig {
|
|
|
10
10
|
readonly dockerEnabled?: boolean;
|
|
11
11
|
readonly dockerDesktopRecoveryEnabled?: boolean;
|
|
12
12
|
readonly allowOpenPublicSandbox?: boolean;
|
|
13
|
+
/** Run Forge PR reviews on this host when they are not placed in the Docker sandbox. Default false. */
|
|
14
|
+
readonly allowUnsandboxedPrReview?: boolean;
|
|
13
15
|
readonly cliProviders?: readonly string[];
|
|
14
16
|
readonly providerStatuses?: Readonly<Record<string, BridgeProviderStatus>>;
|
|
15
17
|
readonly projectLabels?: readonly string[];
|
|
@@ -22,6 +24,13 @@ export interface BridgeLocalConfig {
|
|
|
22
24
|
readonly supportsDraftRunOnce?: boolean;
|
|
23
25
|
readonly supportsDraftAttachments?: boolean;
|
|
24
26
|
readonly supportsDraftImageAttachments?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The capability fields in this file that `pair` derived from cliProviders rather than the user
|
|
29
|
+
* setting them. `connect` may re-derive these when it detects a new provider CLI; any other
|
|
30
|
+
* field present here is the user's choice and is kept. Files written before this marker
|
|
31
|
+
* existed don't have it (see `capabilitySourcesFor`).
|
|
32
|
+
*/
|
|
33
|
+
readonly derivedCapabilities?: readonly DerivedCapabilityField[];
|
|
25
34
|
}
|
|
26
35
|
export interface LocalRepoMapping extends BridgeRepoMapping {
|
|
27
36
|
readonly label: string;
|
|
@@ -46,3 +55,5 @@ export declare function removeRepoMapping(label: string): Promise<{
|
|
|
46
55
|
export declare function setServerUrl(serverUrl: string): Promise<BridgeLocalConfig>;
|
|
47
56
|
export declare function setSandboxPolicy(dockerEnabled: boolean, allowOpenPublicSandbox: boolean): Promise<BridgeLocalConfig>;
|
|
48
57
|
export declare function providerStatusesFor(providers: readonly string[]): Readonly<Record<string, BridgeProviderStatus>>;
|
|
58
|
+
/** The capability fields `pair` derives, and marks as derived, when it writes bridge.json. */
|
|
59
|
+
export declare function pairDerivedCapabilities(current: BridgeLocalConfig, cliProviders: readonly string[]): Pick<BridgeLocalConfig, "supportsDraftImageAttachments" | "derivedCapabilities">;
|
package/dist/cli/local-config.js
CHANGED
|
@@ -2,6 +2,8 @@ import fs from "node:fs/promises";
|
|
|
2
2
|
import fsSync from "node:fs";
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
|
+
import { derivedCapabilityFields, } from "../bridge/bridge.types.js";
|
|
6
|
+
import { supportsDraftImageAttachmentsFor } from "../shared/provider-capabilities.js";
|
|
5
7
|
import { localYieldFlagPathFor } from "../bridge/local-yield-flag.js";
|
|
6
8
|
import { bridgeStatePathFor } from "../bridge/bridge-state-file.js";
|
|
7
9
|
export function resolveLocalConfigPath() {
|
|
@@ -72,6 +74,8 @@ export function applyLocalConfigDefaults(config, local) {
|
|
|
72
74
|
allowOpenPublicSandbox: process.env.FORGE_ALLOW_OPEN_PUBLIC_SANDBOX === undefined
|
|
73
75
|
? local.allowOpenPublicSandbox ?? config.allowOpenPublicSandbox
|
|
74
76
|
: config.allowOpenPublicSandbox,
|
|
77
|
+
// Only an explicit true in bridge.json opts in; there is no environment override.
|
|
78
|
+
allowUnsandboxedPrReview: local.allowUnsandboxedPrReview === true,
|
|
75
79
|
cliProviders,
|
|
76
80
|
providerStatuses: normalizeProviderStatuses(local.providerStatuses) ?? providerStatusesFor(cliProviders),
|
|
77
81
|
projectLabels: local.projectLabels ?? config.projectLabels,
|
|
@@ -84,6 +88,7 @@ export function applyLocalConfigDefaults(config, local) {
|
|
|
84
88
|
supportsDraftRunOnce: local.supportsDraftRunOnce ?? config.supportsDraftRunOnce,
|
|
85
89
|
supportsDraftAttachments: local.supportsDraftAttachments ?? config.supportsDraftAttachments,
|
|
86
90
|
supportsDraftImageAttachments: local.supportsDraftImageAttachments ?? config.supportsDraftImageAttachments,
|
|
91
|
+
capabilitySources: capabilitySourcesFor(local),
|
|
87
92
|
localYieldFlagPath: resolveLocalYieldFlagPath(),
|
|
88
93
|
bridgeStatePath: resolveBridgeStatePath()
|
|
89
94
|
};
|
|
@@ -159,6 +164,7 @@ function normalizeLocalConfig(config) {
|
|
|
159
164
|
dockerEnabled: config.dockerEnabled,
|
|
160
165
|
dockerDesktopRecoveryEnabled: config.dockerDesktopRecoveryEnabled,
|
|
161
166
|
allowOpenPublicSandbox: config.allowOpenPublicSandbox,
|
|
167
|
+
allowUnsandboxedPrReview: config.allowUnsandboxedPrReview === true ? true : undefined,
|
|
162
168
|
cliProviders: cleanList(config.cliProviders),
|
|
163
169
|
providerStatuses: normalizeProviderStatuses(config.providerStatuses),
|
|
164
170
|
projectLabels: cleanList(config.projectLabels),
|
|
@@ -170,9 +176,37 @@ function normalizeLocalConfig(config) {
|
|
|
170
176
|
supportsRunnerAuthoredPhaseArtifacts: config.supportsRunnerAuthoredPhaseArtifacts,
|
|
171
177
|
supportsDraftRunOnce: config.supportsDraftRunOnce,
|
|
172
178
|
supportsDraftAttachments: config.supportsDraftAttachments,
|
|
173
|
-
supportsDraftImageAttachments: config.supportsDraftImageAttachments
|
|
179
|
+
supportsDraftImageAttachments: config.supportsDraftImageAttachments,
|
|
180
|
+
derivedCapabilities: Array.isArray(config.derivedCapabilities)
|
|
181
|
+
? derivedCapabilityFields.filter((field) => config.derivedCapabilities.includes(field))
|
|
182
|
+
: undefined
|
|
174
183
|
};
|
|
175
184
|
}
|
|
185
|
+
/** The capability fields `pair` derives, and marks as derived, when it writes bridge.json. */
|
|
186
|
+
export function pairDerivedCapabilities(current, cliProviders) {
|
|
187
|
+
return {
|
|
188
|
+
supportsDraftImageAttachments: supportsDraftImageAttachmentsFor(cliProviders),
|
|
189
|
+
derivedCapabilities: derivedCapabilityFields.filter((field) => field === "supportsDraftImageAttachments" || current.derivedCapabilities?.includes(field)),
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Where each derived capability's value comes from. A field bridge.json doesn't set comes from the
|
|
194
|
+
* defaults, so it is derived. A field it sets is derived when the file's marker lists it, and the
|
|
195
|
+
* user's choice when the marker doesn't. Without a marker (a file written before it existed) the
|
|
196
|
+
* source is unknown and gets no entry.
|
|
197
|
+
*/
|
|
198
|
+
function capabilitySourcesFor(local) {
|
|
199
|
+
const sources = {};
|
|
200
|
+
for (const field of derivedCapabilityFields) {
|
|
201
|
+
if (local[field] === undefined || local.derivedCapabilities?.includes(field)) {
|
|
202
|
+
sources[field] = "derived";
|
|
203
|
+
}
|
|
204
|
+
else if (local.derivedCapabilities !== undefined) {
|
|
205
|
+
sources[field] = "explicit";
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return sources;
|
|
209
|
+
}
|
|
176
210
|
function emptyConfig() {
|
|
177
211
|
return {
|
|
178
212
|
schemaVersion: 2,
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { BridgeServiceConfig } from "../bridge/bridge.types.js";
|
|
2
|
+
import { type CliProviderDetection } from "./provider-cli-detection.js";
|
|
3
|
+
/** Every provider CLI the bridge knows how to detect. */
|
|
4
|
+
export declare const knownCliProviders: readonly string[];
|
|
5
|
+
/** The configured providers followed by every known provider, without duplicates. */
|
|
6
|
+
export declare function knownProviderCandidates(providers: readonly string[]): string[];
|
|
7
|
+
/** Probes the configured providers and every known provider, for `forge-bridge status`. */
|
|
8
|
+
export declare function detectKnownCliProviders(configured: readonly string[]): Promise<CliProviderDetection[]>;
|
|
9
|
+
/**
|
|
10
|
+
* Probes `candidates` and adds the ones found to the advertised providers, with their detected
|
|
11
|
+
* version and models.
|
|
12
|
+
*
|
|
13
|
+
* A configured provider that is no longer found stays advertised with its saved status: the probe
|
|
14
|
+
* can miss a CLI that still works (a PATH the bridge's shell doesn't see, a cold-start timeout),
|
|
15
|
+
* and dropping it would take a working runner away. Detection only ever adds providers.
|
|
16
|
+
*
|
|
17
|
+
* Capabilities derived from the provider list (image attachments, default sandbox profiles) are
|
|
18
|
+
* re-derived for the added providers; see `withRederivedCapabilities`.
|
|
19
|
+
*
|
|
20
|
+
* Advertising a provider doesn't mean the bridge will launch it: a provider whose user
|
|
21
|
+
* configuration Forge can't shut out (cursor) is still refused at launch
|
|
22
|
+
* (`provider-user-config-isolation.ts`).
|
|
23
|
+
*/
|
|
24
|
+
export declare function withDetectedCliProviders(config: BridgeServiceConfig, candidates?: readonly string[]): Promise<BridgeServiceConfig>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { defaultSandboxProfiles, supportsDraftImageAttachmentsFor } from "../shared/provider-capabilities.js";
|
|
2
|
+
import { providerStatusesFor } from "./local-config.js";
|
|
3
|
+
import { detectCliProviders } from "./provider-cli-detection.js";
|
|
4
|
+
// Which provider CLIs `forge-bridge connect` and `pair` advertise to Forge. Split out of
|
|
5
|
+
// cli.service.ts (file-size inventory plan).
|
|
6
|
+
/** Every provider CLI the bridge knows how to detect. */
|
|
7
|
+
export const knownCliProviders = Object.freeze(["codex", "cursor", "claude"]);
|
|
8
|
+
/** The configured providers followed by every known provider, without duplicates. */
|
|
9
|
+
export function knownProviderCandidates(providers) {
|
|
10
|
+
return uniqueProviders([...providers, ...knownCliProviders]);
|
|
11
|
+
}
|
|
12
|
+
/** Probes the configured providers and every known provider, for `forge-bridge status`. */
|
|
13
|
+
export async function detectKnownCliProviders(configured) {
|
|
14
|
+
return await detectCliProviders(knownProviderCandidates(configured));
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Probes `candidates` and adds the ones found to the advertised providers, with their detected
|
|
18
|
+
* version and models.
|
|
19
|
+
*
|
|
20
|
+
* A configured provider that is no longer found stays advertised with its saved status: the probe
|
|
21
|
+
* can miss a CLI that still works (a PATH the bridge's shell doesn't see, a cold-start timeout),
|
|
22
|
+
* and dropping it would take a working runner away. Detection only ever adds providers.
|
|
23
|
+
*
|
|
24
|
+
* Capabilities derived from the provider list (image attachments, default sandbox profiles) are
|
|
25
|
+
* re-derived for the added providers; see `withRederivedCapabilities`.
|
|
26
|
+
*
|
|
27
|
+
* Advertising a provider doesn't mean the bridge will launch it: a provider whose user
|
|
28
|
+
* configuration Forge can't shut out (cursor) is still refused at launch
|
|
29
|
+
* (`provider-user-config-isolation.ts`).
|
|
30
|
+
*/
|
|
31
|
+
export async function withDetectedCliProviders(config, candidates = config.cliProviders) {
|
|
32
|
+
const detected = await detectCliProviders(uniqueProviders(candidates));
|
|
33
|
+
const found = detected.filter((result) => result.found);
|
|
34
|
+
if (found.length === 0) {
|
|
35
|
+
return config;
|
|
36
|
+
}
|
|
37
|
+
const cliProviders = uniqueProviders([...config.cliProviders, ...found.map((result) => result.provider)]);
|
|
38
|
+
const providerStatuses = { ...config.providerStatuses };
|
|
39
|
+
for (const result of found) {
|
|
40
|
+
const existing = providerStatuses[result.provider];
|
|
41
|
+
providerStatuses[result.provider] = {
|
|
42
|
+
signedIn: existing?.signedIn ?? true,
|
|
43
|
+
version: result.version || existing?.version || "",
|
|
44
|
+
models: result.models.length > 0
|
|
45
|
+
? result.models
|
|
46
|
+
: existing?.models ?? providerStatusesFor([result.provider])[result.provider]?.models ?? []
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return withRederivedCapabilities(config, {
|
|
50
|
+
...config,
|
|
51
|
+
cliProviders,
|
|
52
|
+
providerStatuses
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Re-derives the capabilities that `pair` and the config defaults compute from the provider
|
|
57
|
+
* list, so a provider detected at connect gets them (codex's image attachments and sandbox).
|
|
58
|
+
* A field changes only when the added providers change what the list derives, so detection
|
|
59
|
+
* never turns a capability off. Then, by the field's source (`capabilitySources`):
|
|
60
|
+
* - derived: re-derived from the merged list;
|
|
61
|
+
* - explicit (the user set it in bridge.json): kept;
|
|
62
|
+
* - unknown (a bridge.json written before the marker): re-derived only while it still equals
|
|
63
|
+
* what the configured providers derive, since a value that differs must be the user's.
|
|
64
|
+
*/
|
|
65
|
+
function withRederivedCapabilities(before, after) {
|
|
66
|
+
const sources = before.capabilitySources ?? {};
|
|
67
|
+
return {
|
|
68
|
+
...after,
|
|
69
|
+
supportsDraftImageAttachments: rederive(sources.supportsDraftImageAttachments, before.supportsDraftImageAttachments, supportsDraftImageAttachmentsFor(before.cliProviders), supportsDraftImageAttachmentsFor(after.cliProviders), (left, right) => left === right),
|
|
70
|
+
sandboxProfiles: rederive(sources.sandboxProfiles, before.sandboxProfiles, defaultSandboxProfiles(before.cliProviders), defaultSandboxProfiles(after.cliProviders), sameList),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function rederive(source, current, fromConfigured, fromMerged, same) {
|
|
74
|
+
if (same(fromConfigured, fromMerged) || source === "explicit")
|
|
75
|
+
return current;
|
|
76
|
+
if (source === undefined && !same(current, fromConfigured))
|
|
77
|
+
return current;
|
|
78
|
+
return fromMerged;
|
|
79
|
+
}
|
|
80
|
+
function sameList(left, right) {
|
|
81
|
+
return left.length === right.length && left.every((value, index) => value.toLowerCase() === right[index]?.toLowerCase());
|
|
82
|
+
}
|
|
83
|
+
function uniqueProviders(providers) {
|
|
84
|
+
return providers
|
|
85
|
+
.map((provider) => provider.trim())
|
|
86
|
+
.filter((provider) => provider.length > 0)
|
|
87
|
+
.filter((provider, index, all) => all.findIndex((candidate) => candidate.toLowerCase() === provider.toLowerCase()) === index);
|
|
88
|
+
}
|
|
@@ -55,6 +55,11 @@ export interface HostLoadAdmissionDecision {
|
|
|
55
55
|
readonly reservedCpuCores: number;
|
|
56
56
|
readonly reservedMemoryBytes: number;
|
|
57
57
|
readonly detail: string;
|
|
58
|
+
/**
|
|
59
|
+
* Set on a host test slot wait whose holders are all healthy (owner alive, lease renewed, not retained):
|
|
60
|
+
* the queue is moving, so the wait does not count toward the stalled-wait limit.
|
|
61
|
+
*/
|
|
62
|
+
readonly progressing?: boolean;
|
|
58
63
|
}
|
|
59
64
|
/**
|
|
60
65
|
* Decision 0013 admission rule. A step is admitted when the reserved cost of
|