@loucompanion/forge-bridge 0.1.4-dev.c1ae24134918 → 0.1.4-dev.cabe9c22da46
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 +394 -338
- 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.service.d.ts +9 -0
- package/dist/cleanup/cleanup.service.js +76 -115
- package/dist/cleanup/cleanup.types.d.ts +4 -0
- package/dist/cleanup/forge-owned-paths.d.ts +9 -0
- package/dist/cleanup/forge-owned-paths.js +53 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +5 -0
- package/dist/cleanup/host-runtime-ledger.js +109 -0
- package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
- package/dist/cleanup/managed-branch-sweep.js +111 -0
- package/dist/cli/cli.help.js +74 -12
- package/dist/cli/cli.service.d.ts +19 -10
- package/dist/cli/cli.service.js +149 -186
- 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 +5 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +140 -7
- 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 +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 +12 -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 +59 -3
- package/dist/runtime/host-runtime-lease.js +209 -58
- 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/playwright-host-runtime-adapter.d.ts +7 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
- package/dist/runtime/runner-settings.d.ts +104 -0
- package/dist/runtime/runner-settings.js +236 -0
- package/dist/sandbox/host-capacity-broker.d.ts +10 -2
- package/dist/sandbox/host-capacity-broker.js +27 -6
- package/dist/sandbox/provider-auth/codex.js +11 -11
- package/dist/session/architect-waits.d.ts +2 -0
- package/dist/session/architect-waits.js +138 -0
- package/dist/session/managed-attempt-tools.d.ts +2 -7
- package/dist/session/managed-attempt-tools.js +89 -99
- 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/mcp-argument-coercion.d.ts +23 -0
- package/dist/session/mcp-argument-coercion.js +121 -0
- package/dist/session/phase-completion.artifacts.d.ts +7 -0
- package/dist/session/phase-completion.artifacts.js +96 -26
- package/dist/session/phase-completion.command-validation.d.ts +7 -0
- package/dist/session/phase-completion.command-validation.js +77 -0
- package/dist/session/phase-completion.d.ts +10 -0
- package/dist/session/phase-completion.helpers.js +13 -12
- package/dist/session/phase-completion.js +5 -0
- package/dist/session/phase-completion.mcp-args.d.ts +9 -0
- package/dist/session/phase-completion.mcp-args.js +156 -0
- package/dist/session/phase-completion.prompts.js +6 -1
- package/dist/session/phase-completion.runtime.d.ts +4 -10
- package/dist/session/phase-completion.runtime.js +77 -209
- package/dist/session/phase-completion.schema-parts.d.ts +19 -0
- package/dist/session/phase-completion.schema-parts.js +188 -0
- package/dist/session/phase-completion.schemas.d.ts +3 -3
- package/dist/session/phase-completion.schemas.js +208 -231
- package/dist/session/phase-completion.validation.d.ts +2 -3
- package/dist/session/phase-completion.validation.js +49 -93
- package/dist/session/pre-publication-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 +72 -32
- 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 +7 -1
- package/dist/session/provider-cli/provider-cli.service.js +78 -171
- package/dist/session/provider-cli/provider-cli.types.d.ts +26 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +4 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +45 -0
- package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
- package/dist/session/provider-cli/provider-output-pipes.js +67 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +2 -0
- package/dist/session/provider-cli/provider-output-state.js +6 -0
- package/dist/session/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 +7 -2
- package/dist/session/session.service.js +100 -2
- package/dist/session/session.types.js +4 -4
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -0
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -0
- package/dist/shared/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/worktree.service.d.ts +5 -1
- package/dist/worktree/worktree.service.js +29 -1
- package/package.json +2 -2
package/dist/cli/cli.help.js
CHANGED
|
@@ -15,12 +15,13 @@ export function helpText() {
|
|
|
15
15
|
" Hint: commands suffixed with * have detailed help. Run <command> --help for details.",
|
|
16
16
|
" connect * Start the runner bridge and wait for Forge dispatches",
|
|
17
17
|
" pair * Pair this machine with Forge and save runner credentials",
|
|
18
|
-
" status * Show config, runner identity, repos, provider CLIs, and
|
|
18
|
+
" status * Show config, runner identity, repos, provider CLIs, updates, and idle state",
|
|
19
19
|
" server * Show or change the saved Forge server URL",
|
|
20
20
|
" add-repo * Map a Forge repo label/name to a local checkout path",
|
|
21
21
|
" remove-repo * Remove a saved repo mapping",
|
|
22
22
|
" cleanup * Prune managed bridge worktrees",
|
|
23
23
|
" sandbox * Initialize, diagnose, smoke-test, or reap Docker sandboxes",
|
|
24
|
+
" yield * Yield this machine to foreground work: no new attempts",
|
|
24
25
|
" version * Print the installed bridge package version",
|
|
25
26
|
" help * Display help for command",
|
|
26
27
|
" run-once * Internal: run one dispatch packet from JSON",
|
|
@@ -31,6 +32,7 @@ export function helpText() {
|
|
|
31
32
|
" forge-bridge pair 1234-5678 --server https://forge.example.ts.net:8443 --repo-root \"%USERPROFILE%\\ForgeRepos\"",
|
|
32
33
|
" forge-bridge connect",
|
|
33
34
|
" forge-bridge status --check-updates",
|
|
35
|
+
" forge-bridge status --idle --require-yield --wait 600",
|
|
34
36
|
" forge-bridge server set http://localhost:5208",
|
|
35
37
|
" forge-bridge add-repo Forge D:\\Programming\\repos\\Forge",
|
|
36
38
|
" forge-bridge cleanup --stale",
|
|
@@ -39,12 +41,61 @@ export function helpText() {
|
|
|
39
41
|
" If Forge says the bridge is old: npm install -g @loucompanion/forge-bridge@next",
|
|
40
42
|
" If connect shows 502/500: leave it open; it reconnects with backoff while dev restarts.",
|
|
41
43
|
" If a provider is missing: run forge-bridge status --check-updates and verify CLI login.",
|
|
44
|
+
" Before restarting or updating the bridge: forge-bridge help status (yield on, wait for idle, restart, yield off).",
|
|
42
45
|
"",
|
|
43
46
|
"Docs:",
|
|
44
47
|
" https://github.com/coleman399/Forge/tree/develop/tools/forge-bridge#readme",
|
|
45
48
|
"",
|
|
46
49
|
].join("\n");
|
|
47
50
|
}
|
|
51
|
+
// The status help, kept out of commandHelpText so that function stays within its length ceiling.
|
|
52
|
+
const statusHelpLines = [
|
|
53
|
+
"Forge Bridge — status",
|
|
54
|
+
"Show saved configuration, paired runner identity, repo mappings, detected provider CLIs, and optional update info.",
|
|
55
|
+
"",
|
|
56
|
+
"Usage:",
|
|
57
|
+
" forge-bridge status [--check-updates]",
|
|
58
|
+
" forge-bridge status --idle [--require-yield] [--json] [--wait <seconds>]",
|
|
59
|
+
"",
|
|
60
|
+
"--idle reports whether the running `forge-bridge connect` can be restarted without killing work.",
|
|
61
|
+
"The bridge publishes its in-flight work to bridge.state.json next to bridge.json: accepted offers,",
|
|
62
|
+
"dispatches in admission, worktree and dependency preparation, prepared-runtime probes, running",
|
|
63
|
+
"attempts and their teardown, chat turns, readiness probes and result delivery.",
|
|
64
|
+
"",
|
|
65
|
+
"Options:",
|
|
66
|
+
" --idle Check the running bridge's published idle state.",
|
|
67
|
+
" --require-yield Count idle only once Forge has acknowledged this bridge's yield (with --idle).",
|
|
68
|
+
" --json Print the result as JSON (with --idle).",
|
|
69
|
+
" --wait <seconds> Keep checking until idle, the bridge process has exited, or time is up (with --idle).",
|
|
70
|
+
" --wait 0 checks once, like no --wait.",
|
|
71
|
+
"",
|
|
72
|
+
"Exit codes with --idle:",
|
|
73
|
+
" 0 idle: a live bridge reported a fresh heartbeat with nothing in flight",
|
|
74
|
+
" 1 busy: work is in flight; restarting now would kill it",
|
|
75
|
+
" 2 usage error",
|
|
76
|
+
" 3 stale or unknown: old heartbeat, unreadable or missing state file, two bridges on one",
|
|
77
|
+
" config, or the bridge is shutting down; idle cannot be confirmed (a bridge older than",
|
|
78
|
+
" this check writes no file)",
|
|
79
|
+
" 4 not running: the recorded bridge process has exited; there is nothing to interrupt",
|
|
80
|
+
" 5 not yielding (with --require-yield): idle, but Forge has not acknowledged yield yet",
|
|
81
|
+
"",
|
|
82
|
+
"Yield stops new attempts (Offers) and defers readiness probes. It does not stop a Bridge Chat",
|
|
83
|
+
"turn on a chat lease already bound to this runner, or a legacy Dispatch (protocol-1 bridges",
|
|
84
|
+
"only); those run and count as busy.",
|
|
85
|
+
"",
|
|
86
|
+
"Restart or update procedure:",
|
|
87
|
+
" forge-bridge yield on # no new attempts; running work finishes",
|
|
88
|
+
" forge-bridge status --idle --require-yield --wait 3600 # exit 0 only once idle and yielding",
|
|
89
|
+
" (stop forge-bridge connect, update it, start it again)",
|
|
90
|
+
" forge-bridge yield off # after the new bridge connects, or after a failed wait",
|
|
91
|
+
"Run these as the same user and with the same FORGE_BRIDGE_CONFIG as the bridge, so they",
|
|
92
|
+
"read and write the bridge's own files.",
|
|
93
|
+
"",
|
|
94
|
+
"Examples:",
|
|
95
|
+
" forge-bridge status --check-updates",
|
|
96
|
+
" forge-bridge status --idle --json",
|
|
97
|
+
"",
|
|
98
|
+
];
|
|
48
99
|
export function commandHelpText(command) {
|
|
49
100
|
switch (command) {
|
|
50
101
|
case "pair":
|
|
@@ -91,17 +142,7 @@ export function commandHelpText(command) {
|
|
|
91
142
|
"",
|
|
92
143
|
].join("\n");
|
|
93
144
|
case "status":
|
|
94
|
-
return
|
|
95
|
-
"Forge Bridge — status",
|
|
96
|
-
"Show saved configuration, paired runner identity, repo mappings, detected provider CLIs, and optional update info.",
|
|
97
|
-
"",
|
|
98
|
-
"Usage:",
|
|
99
|
-
" forge-bridge status [--check-updates]",
|
|
100
|
-
"",
|
|
101
|
-
"Example:",
|
|
102
|
-
" forge-bridge status --check-updates",
|
|
103
|
-
"",
|
|
104
|
-
].join("\n");
|
|
145
|
+
return statusHelpLines.join("\n");
|
|
105
146
|
case "server":
|
|
106
147
|
return [
|
|
107
148
|
"Forge Bridge — server",
|
|
@@ -179,6 +220,27 @@ export function commandHelpText(command) {
|
|
|
179
220
|
"Stop the connected bridge first so the Docker ownership lock can be acquired.",
|
|
180
221
|
"",
|
|
181
222
|
].join("\n");
|
|
223
|
+
case "yield":
|
|
224
|
+
return [
|
|
225
|
+
"Forge Bridge — yield",
|
|
226
|
+
"Yield this machine to foreground work (for example while you are gaming).",
|
|
227
|
+
"",
|
|
228
|
+
"Usage:",
|
|
229
|
+
" forge-bridge yield on",
|
|
230
|
+
" forge-bridge yield off",
|
|
231
|
+
" forge-bridge yield status",
|
|
232
|
+
"",
|
|
233
|
+
"While yielding, the bridge takes no new attempts; running attempts finish, and",
|
|
234
|
+
"their heavy steps run under the yield CPU budget. A running bridge notices the",
|
|
235
|
+
"change within one heartbeat, without a restart, and reports it to Forge.",
|
|
236
|
+
"The flag is saved in its own file next to bridge.json. Yield is also on when the",
|
|
237
|
+
"runner's Yield toggle in Forge is on: either side turns it on.",
|
|
238
|
+
"",
|
|
239
|
+
"To restart or update the bridge safely, yield first, wait until",
|
|
240
|
+
"`forge-bridge status --idle --require-yield --wait <seconds>` exits 0, restart, then run",
|
|
241
|
+
"`forge-bridge yield off` once the new bridge has connected. See `forge-bridge help status`.",
|
|
242
|
+
"",
|
|
243
|
+
].join("\n");
|
|
182
244
|
case "run-once":
|
|
183
245
|
return [
|
|
184
246
|
"Forge Bridge — run-once",
|
|
@@ -5,6 +5,8 @@ import type { CleanupMode } from "../cleanup/cleanup.types.js";
|
|
|
5
5
|
import type { CleanupService } from "../cleanup/cleanup.base.js";
|
|
6
6
|
import type { SessionService } from "../session/session.base.js";
|
|
7
7
|
import type { CliIo, CliService } from "./cli.base.js";
|
|
8
|
+
import { type StatusArgs } from "./idle-status.js";
|
|
9
|
+
export { claudeDefaultModels, parseCodexModelCatalog, parseCursorModelList } from "./provider-cli-detection.js";
|
|
8
10
|
type DotNetToolchainConfigurator = (repoRoots: readonly string[], options?: {
|
|
9
11
|
readonly cloneFolders?: readonly string[];
|
|
10
12
|
}) => Promise<DotNetToolchainSelection | null>;
|
|
@@ -17,6 +19,7 @@ export declare class ForgeBridgeCliService implements CliService {
|
|
|
17
19
|
constructor(sessions?: SessionService, bridgeFactory?: (config: BridgeServiceConfig) => BridgeService, pairRunner?: PairRunnerClient, cleanupFactory?: CleanupServiceFactory, dotNetToolchainConfigurator?: DotNetToolchainConfigurator);
|
|
18
20
|
run(argv: readonly string[], io?: CliIo): Promise<number>;
|
|
19
21
|
}
|
|
22
|
+
type YieldAction = "on" | "off" | "status";
|
|
20
23
|
export declare function parseArgs(argv: readonly string[]): {
|
|
21
24
|
readonly ok: true;
|
|
22
25
|
readonly command: "run-once";
|
|
@@ -46,12 +49,7 @@ export declare function parseArgs(argv: readonly string[]): {
|
|
|
46
49
|
readonly ok: true;
|
|
47
50
|
readonly command: "server-set";
|
|
48
51
|
readonly serverUrl: string;
|
|
49
|
-
} | {
|
|
50
|
-
readonly ok: true;
|
|
51
|
-
readonly command: "status";
|
|
52
|
-
readonly config: BridgeServiceConfig;
|
|
53
|
-
readonly checkUpdates: boolean;
|
|
54
|
-
} | {
|
|
52
|
+
} | StatusArgs | {
|
|
55
53
|
readonly ok: true;
|
|
56
54
|
readonly command: "cleanup";
|
|
57
55
|
readonly config: BridgeServiceConfig;
|
|
@@ -86,6 +84,10 @@ export declare function parseArgs(argv: readonly string[]): {
|
|
|
86
84
|
} | {
|
|
87
85
|
readonly ok: true;
|
|
88
86
|
readonly command: "sandbox-status";
|
|
87
|
+
} | {
|
|
88
|
+
readonly ok: true;
|
|
89
|
+
readonly command: "yield";
|
|
90
|
+
readonly action: YieldAction;
|
|
89
91
|
} | {
|
|
90
92
|
readonly ok: false;
|
|
91
93
|
readonly error: string;
|
|
@@ -104,15 +106,22 @@ interface PairArgs {
|
|
|
104
106
|
readonly repoRoot?: string;
|
|
105
107
|
readonly cleanupWorktrees: boolean;
|
|
106
108
|
readonly cliProviders: readonly string[];
|
|
109
|
+
/** True when `--cli-provider` named the providers, which then win over the Connect dialog's choice. */
|
|
110
|
+
readonly cliProvidersFromFlag?: boolean;
|
|
107
111
|
readonly projectLabels: readonly string[];
|
|
108
112
|
}
|
|
113
|
+
/** Decision 0014 §5: what the Connect dialog's pairing intent set for this host, echoed by the claim. */
|
|
114
|
+
export interface PairRunnerHost {
|
|
115
|
+
readonly name?: string;
|
|
116
|
+
readonly repoRoot?: string;
|
|
117
|
+
readonly cliProviders?: readonly string[];
|
|
118
|
+
}
|
|
109
119
|
interface PairRunnerClaim {
|
|
110
120
|
readonly runnerId: string;
|
|
111
121
|
readonly deviceToken: string;
|
|
122
|
+
readonly host?: PairRunnerHost;
|
|
112
123
|
}
|
|
113
124
|
type PairRunnerClient = (args: PairArgs) => Promise<PairRunnerClaim>;
|
|
114
|
-
|
|
115
|
-
export declare function
|
|
116
|
-
export declare function parseCursorModelList(raw: string): string[];
|
|
125
|
+
/** Expands `~` in a repo folder chosen in Forge and rejects one shaped for another OS. */
|
|
126
|
+
export declare function resolveHostRepoRoot(value: string, platform?: NodeJS.Platform, home?: string): string | undefined;
|
|
117
127
|
type CleanupServiceFactory = (stateRoot: string) => CleanupService;
|
|
118
|
-
export {};
|
package/dist/cli/cli.service.js
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
|
-
import { execFile } from "node:child_process";
|
|
3
2
|
import os from "node:os";
|
|
4
3
|
import path from "node:path";
|
|
5
4
|
import { createInterface } from "node:readline/promises";
|
|
6
|
-
import { promisify } from "node:util";
|
|
7
|
-
import { resolveCursorAgentDirectLaunch } from "../shared/cursor-agent/cursor-agent.launch.js";
|
|
8
|
-
import { buildWindowsCmdLaunch } from "../shared/process/windows-launch.js";
|
|
9
5
|
import { configureDotNetToolchain } from "../shared/process/dotnet-toolchain.js";
|
|
10
6
|
import { supportsDraftImageAttachmentsFor } from "../shared/provider-capabilities.js";
|
|
11
7
|
import { redactText } from "../shared/redaction/redaction.js";
|
|
12
|
-
import { defaultBridgeServiceConfig, ForgeBridgeService } from "../bridge/bridge.service.js";
|
|
8
|
+
import { BridgeRevokedError, bridgeRevokedExitCode, defaultBridgeServiceConfig, ForgeBridgeService, } from "../bridge/bridge.service.js";
|
|
13
9
|
import { forgeBridgeVersion } from "../version.js";
|
|
14
10
|
import { ManagedWorktreeCleanupService } from "../cleanup/cleanup.service.js";
|
|
15
|
-
import { addRepoMapping, applyLocalConfigDefaults, providerStatusesFor, readLocalConfigSync, removeRepoMapping, resolveLocalConfigPath, setSandboxPolicy, setServerUrl, writeLocalConfig } from "./local-config.js";
|
|
11
|
+
import { addRepoMapping, applyLocalConfigDefaults, providerStatusesFor, readLocalConfigSync, removeRepoMapping, resolveLocalConfigPath, resolveLocalYieldFlagPath, setSandboxPolicy, setServerUrl, writeLocalConfig } from "./local-config.js";
|
|
16
12
|
import { BridgeSessionService } from "../session/session.service.js";
|
|
17
13
|
import { redactRunnerDispatchEvent, redactRunOnceResultPacket } from "../session/session-redaction.js";
|
|
18
14
|
import { validateDockerfilePolicy, validateSandboxContract } from "../sandbox/contract.js";
|
|
@@ -22,8 +18,11 @@ import { DockerSandboxSmoke } from "../sandbox/smoke.js";
|
|
|
22
18
|
import { parseCompletionMcpArgs, runCompletionMcpServer } from "../session/phase-completion.js";
|
|
23
19
|
import { failureFactsFromError, failureResult, parseRunOnceDispatchPacket } from "../session/session.types.js";
|
|
24
20
|
import { commandHelpText, helpText } from "./cli.help.js";
|
|
21
|
+
import { readLocalYieldFlag, writeLocalYieldFlag } from "../bridge/local-yield-flag.js";
|
|
22
|
+
import { detectCliProviders } from "./provider-cli-detection.js";
|
|
23
|
+
import { idleSummaryLine, parseStatusArgs, runIdleStatusCommand } from "./idle-status.js";
|
|
24
|
+
export { claudeDefaultModels, parseCodexModelCatalog, parseCursorModelList } from "./provider-cli-detection.js";
|
|
25
25
|
const apiKeySecretGrantEnv = "FORGE_API_KEY_SECRET_GRANT";
|
|
26
|
-
const execFileAsync = promisify(execFile);
|
|
27
26
|
export class ForgeBridgeCliService {
|
|
28
27
|
sessions;
|
|
29
28
|
bridgeFactory;
|
|
@@ -91,11 +90,22 @@ export class ForgeBridgeCliService {
|
|
|
91
90
|
if (config.cleanupWorktrees && config.repoMappings.some(mapping => mapping.localPath?.trim())) {
|
|
92
91
|
io.stdout.write("Cleaning stale managed worktrees before accepting dispatches.\n");
|
|
93
92
|
await cleanupRepos(config, "stale", true, this.cleanupFactory(config.sandboxStateRoot), io);
|
|
93
|
+
// Forge branches on this device whose work has merged since the bridge last ran.
|
|
94
|
+
await cleanupRepos(config, "merged", true, this.cleanupFactory(config.sandboxStateRoot), io);
|
|
94
95
|
}
|
|
95
96
|
io.stdout.write(connectStartupText(config));
|
|
96
97
|
await this.bridgeFactory(config).run(controller.signal);
|
|
97
98
|
return 0;
|
|
98
99
|
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
if (error instanceof BridgeRevokedError) {
|
|
102
|
+
// Decision 0014: removed from Forge. Exit with a distinct code so a supervisor can
|
|
103
|
+
// tell "pair again" apart from a crash.
|
|
104
|
+
io.stderr.write(`${error.message}\n`);
|
|
105
|
+
return bridgeRevokedExitCode;
|
|
106
|
+
}
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
99
109
|
finally {
|
|
100
110
|
process.off("SIGINT", stop);
|
|
101
111
|
process.off("SIGTERM", stop);
|
|
@@ -119,13 +129,22 @@ export class ForgeBridgeCliService {
|
|
|
119
129
|
const current = readLocalConfigSync();
|
|
120
130
|
io.stdout.write(`Pairing with server: ${args.serverUrl}\n`);
|
|
121
131
|
const code = await resolvePairingCode(args.code);
|
|
122
|
-
const
|
|
123
|
-
await
|
|
124
|
-
const pairArgs = await withDetectedPairCliProviders({ ...args, code, repoRoot });
|
|
132
|
+
const provisionalRoot = path.resolve(args.repoRoot ?? current.defaultRepoRoot ?? path.join(os.homedir(), "ForgeRepos"));
|
|
133
|
+
const pairArgs = await withDetectedPairCliProviders({ ...args, code, repoRoot: provisionalRoot });
|
|
125
134
|
const claim = await this.pairRunner(pairArgs);
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
135
|
+
// The code is spent now: save the credentials before anything else can fail or prompt.
|
|
136
|
+
const applied = applyPairHost(pairArgs, claim.host, args.repoRoot !== undefined, io);
|
|
137
|
+
await writeLocalConfig(pairedConfig(current, applied.args, claim));
|
|
138
|
+
let repoRoot = applied.args.repoRoot;
|
|
139
|
+
if (!args.repoRoot && !applied.repoRootFromHost) {
|
|
140
|
+
const answered = await promptPairRepoRoot(repoRoot);
|
|
141
|
+
if (answered !== repoRoot) {
|
|
142
|
+
repoRoot = answered;
|
|
143
|
+
await writeLocalConfig(pairedConfig(current, { ...applied.args, repoRoot }, claim));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
await fs.mkdir(repoRoot, { recursive: true });
|
|
147
|
+
io.stdout.write(`Paired runner ${claim.runnerId}${applied.args.name ? ` (${applied.args.name})` : ""}.\n`);
|
|
129
148
|
io.stdout.write(`Repo folder: ${repoRoot}\n`);
|
|
130
149
|
io.stdout.write(`Config: ${resolveLocalConfigPath()}\n`);
|
|
131
150
|
io.stdout.write("Start the bridge with: forge-bridge connect\n");
|
|
@@ -174,8 +193,7 @@ export class ForgeBridgeCliService {
|
|
|
174
193
|
}
|
|
175
194
|
}
|
|
176
195
|
if (args.command === "status") {
|
|
177
|
-
await
|
|
178
|
-
return 0;
|
|
196
|
+
return await runStatus(args, io);
|
|
179
197
|
}
|
|
180
198
|
if (args.command === "cleanup") {
|
|
181
199
|
return await cleanupRepos(args.config, args.mode, args.force, this.cleanupFactory(args.config.sandboxStateRoot), io);
|
|
@@ -208,6 +226,9 @@ export class ForgeBridgeCliService {
|
|
|
208
226
|
writeSandboxPolicyStatus(readLocalConfigSync(), io);
|
|
209
227
|
return 0;
|
|
210
228
|
}
|
|
229
|
+
if (args.command === "yield") {
|
|
230
|
+
return await runYieldCommand(args.action, io);
|
|
231
|
+
}
|
|
211
232
|
if (args.command === "mcp") {
|
|
212
233
|
const parsed = parseCompletionMcpArgs(args.argv);
|
|
213
234
|
if (!parsed.ok) {
|
|
@@ -245,6 +266,36 @@ export class ForgeBridgeCliService {
|
|
|
245
266
|
}
|
|
246
267
|
}
|
|
247
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* Decision 0014 `forge-bridge yield`: the host's own yield switch. It writes a
|
|
271
|
+
* flag file next to the bridge config (never bridge.json); a running bridge
|
|
272
|
+
* polls it and stops taking new attempts without a restart.
|
|
273
|
+
*/
|
|
274
|
+
async function runYieldCommand(action, io) {
|
|
275
|
+
const flagPath = resolveLocalYieldFlagPath();
|
|
276
|
+
try {
|
|
277
|
+
if (action !== "status") {
|
|
278
|
+
await writeLocalYieldFlag(flagPath, action === "on");
|
|
279
|
+
}
|
|
280
|
+
const on = await readLocalYieldFlag(flagPath);
|
|
281
|
+
if (action === "on") {
|
|
282
|
+
io.stdout.write("Local yield to foreground is on. A running bridge takes no new attempts within one heartbeat; running attempts finish.\n");
|
|
283
|
+
}
|
|
284
|
+
else if (action === "off") {
|
|
285
|
+
io.stdout.write("Local yield to foreground is off. The bridge takes new attempts again unless yield is on in Forge.\n");
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
io.stdout.write(`Local yield to foreground: ${on ? "on" : "off"}\n`);
|
|
289
|
+
}
|
|
290
|
+
io.stdout.write(`Flag file: ${flagPath}\n`);
|
|
291
|
+
io.stdout.write("The effective state also depends on Forge: the runner yields when this flag or its Yield toggle in Forge is on.\n");
|
|
292
|
+
return 0;
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
io.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
296
|
+
return 1;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
248
299
|
function attachEnvSecretGrant(dispatch) {
|
|
249
300
|
if (!dispatch.execution.requiresApiKeySecretGrant) {
|
|
250
301
|
delete process.env[apiKeySecretGrantEnv];
|
|
@@ -327,17 +378,7 @@ export function parseArgs(argv) {
|
|
|
327
378
|
return { ok: false, error: "Usage: forge-bridge server <show|set <url>>" };
|
|
328
379
|
}
|
|
329
380
|
if (argv[0] === "status") {
|
|
330
|
-
|
|
331
|
-
for (let index = 1; index < argv.length; index += 1) {
|
|
332
|
-
const arg = argv[index];
|
|
333
|
-
if (arg === "--check-updates") {
|
|
334
|
-
checkUpdates = true;
|
|
335
|
-
}
|
|
336
|
-
else {
|
|
337
|
-
return { ok: false, error: `Unknown argument: ${arg}` };
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
return { ok: true, command: "status", config: configuredBridgeServiceConfig(), checkUpdates };
|
|
381
|
+
return parseStatusArgs(argv, configuredBridgeServiceConfig);
|
|
341
382
|
}
|
|
342
383
|
if (argv[0] === "cleanup") {
|
|
343
384
|
return parseCleanupArgs(argv);
|
|
@@ -348,6 +389,13 @@ export function parseArgs(argv) {
|
|
|
348
389
|
if (argv[0] === "sandbox") {
|
|
349
390
|
return parseSandboxArgs(argv);
|
|
350
391
|
}
|
|
392
|
+
if (argv[0] === "yield") {
|
|
393
|
+
const action = argv[1] ?? "status";
|
|
394
|
+
if (argv.length > 2 || (action !== "on" && action !== "off" && action !== "status")) {
|
|
395
|
+
return { ok: false, error: "Usage: forge-bridge yield [on|off|status]" };
|
|
396
|
+
}
|
|
397
|
+
return { ok: true, command: "yield", action };
|
|
398
|
+
}
|
|
351
399
|
if (argv[0] !== "run-once") {
|
|
352
400
|
return {
|
|
353
401
|
ok: false,
|
|
@@ -761,6 +809,7 @@ function parsePairArgs(argv) {
|
|
|
761
809
|
repoRoot: repoRoot?.trim() ? path.resolve(repoRoot) : undefined,
|
|
762
810
|
cleanupWorktrees: cleanupWorktrees ?? defaultConfig.cleanupWorktrees,
|
|
763
811
|
cliProviders: cliProviders.length > 0 ? cliProviders : localConfig.cliProviders && localConfig.cliProviders.length > 0 ? [...localConfig.cliProviders] : ["codex"],
|
|
812
|
+
cliProvidersFromFlag: cliProviders.length > 0,
|
|
764
813
|
projectLabels: projectLabels.length > 0 ? projectLabels : localConfig.projectLabels ? [...localConfig.projectLabels] : []
|
|
765
814
|
};
|
|
766
815
|
}
|
|
@@ -823,9 +872,71 @@ async function claimBridgeRunner(args) {
|
|
|
823
872
|
}
|
|
824
873
|
return {
|
|
825
874
|
runnerId: value.runnerId,
|
|
826
|
-
deviceToken: value.deviceToken
|
|
875
|
+
deviceToken: value.deviceToken,
|
|
876
|
+
host: parsePairRunnerHost(value.host)
|
|
827
877
|
};
|
|
828
878
|
}
|
|
879
|
+
function parsePairRunnerHost(value) {
|
|
880
|
+
if (!value || typeof value !== "object") {
|
|
881
|
+
return undefined;
|
|
882
|
+
}
|
|
883
|
+
const host = value;
|
|
884
|
+
const name = typeof host.name === "string" && host.name.trim() ? host.name.trim() : undefined;
|
|
885
|
+
const repoRoot = typeof host.repoRoot === "string" && host.repoRoot.trim() ? host.repoRoot.trim() : undefined;
|
|
886
|
+
const cliProviders = Array.isArray(host.cliProviders)
|
|
887
|
+
? host.cliProviders.filter((provider) => typeof provider === "string" && provider.trim().length > 0)
|
|
888
|
+
: [];
|
|
889
|
+
return { name, repoRoot, cliProviders: cliProviders.length > 0 ? cliProviders : undefined };
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* Decision 0014 §5: the claim's host block carries what the Connect dialog chose. The runner name
|
|
893
|
+
* is the server's; providers and the repo folder apply unless a flag named them on this command line.
|
|
894
|
+
*/
|
|
895
|
+
function applyPairHost(args, host, repoRootFromFlag, io) {
|
|
896
|
+
if (!host) {
|
|
897
|
+
return { args, repoRootFromHost: false };
|
|
898
|
+
}
|
|
899
|
+
let repoRoot = args.repoRoot;
|
|
900
|
+
let repoRootFromHost = false;
|
|
901
|
+
if (host.repoRoot && !repoRootFromFlag) {
|
|
902
|
+
const resolved = resolveHostRepoRoot(host.repoRoot);
|
|
903
|
+
if (!resolved) {
|
|
904
|
+
io.stderr.write(`Ignoring the repo folder chosen in Forge (${host.repoRoot}): it is not a path on this machine.\n`);
|
|
905
|
+
}
|
|
906
|
+
else {
|
|
907
|
+
repoRootFromHost = true;
|
|
908
|
+
repoRoot = resolved;
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
return {
|
|
912
|
+
args: {
|
|
913
|
+
...args,
|
|
914
|
+
name: host.name ?? args.name,
|
|
915
|
+
cliProviders: host.cliProviders && !args.cliProvidersFromFlag ? [...host.cliProviders] : args.cliProviders,
|
|
916
|
+
repoRoot
|
|
917
|
+
},
|
|
918
|
+
repoRootFromHost
|
|
919
|
+
};
|
|
920
|
+
}
|
|
921
|
+
/** Expands `~` in a repo folder chosen in Forge and rejects one shaped for another OS. */
|
|
922
|
+
export function resolveHostRepoRoot(value, platform = process.platform, home = os.homedir()) {
|
|
923
|
+
const trimmed = value.trim();
|
|
924
|
+
if (!trimmed) {
|
|
925
|
+
return undefined;
|
|
926
|
+
}
|
|
927
|
+
const pathApi = platform === "win32" ? path.win32 : path.posix;
|
|
928
|
+
if (trimmed === "~") {
|
|
929
|
+
return home;
|
|
930
|
+
}
|
|
931
|
+
if (/^~[\\/]/.test(trimmed)) {
|
|
932
|
+
return pathApi.resolve(home, trimmed.slice(2));
|
|
933
|
+
}
|
|
934
|
+
const windowsShaped = /^[A-Za-z]:[\\/]/.test(trimmed) || trimmed.startsWith("\\\\");
|
|
935
|
+
if (platform === "win32") {
|
|
936
|
+
return windowsShaped || trimmed.startsWith("/") ? pathApi.resolve(trimmed) : undefined;
|
|
937
|
+
}
|
|
938
|
+
return !windowsShaped && trimmed.startsWith("/") ? pathApi.resolve(trimmed) : undefined;
|
|
939
|
+
}
|
|
829
940
|
function pairedConfig(current, args, claim) {
|
|
830
941
|
return {
|
|
831
942
|
...current,
|
|
@@ -870,11 +981,7 @@ async function resolvePairingCode(code) {
|
|
|
870
981
|
prompt.close();
|
|
871
982
|
}
|
|
872
983
|
}
|
|
873
|
-
async function
|
|
874
|
-
const fallback = path.resolve(repoRoot ?? configuredRoot ?? path.join(os.homedir(), "ForgeRepos"));
|
|
875
|
-
if (repoRoot?.trim()) {
|
|
876
|
-
return fallback;
|
|
877
|
-
}
|
|
984
|
+
async function promptPairRepoRoot(fallback) {
|
|
878
985
|
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
879
986
|
return fallback;
|
|
880
987
|
}
|
|
@@ -945,6 +1052,9 @@ async function writeJsonAtomic(outputPath, value) {
|
|
|
945
1052
|
await fs.writeFile(tempPath, `${JSON.stringify(value, null, 2)}\n`, "utf8");
|
|
946
1053
|
await fs.rename(tempPath, outputPath);
|
|
947
1054
|
}
|
|
1055
|
+
async function runStatus(args, io) {
|
|
1056
|
+
return args.idle ? await runIdleStatusCommand(args.idle, io) : await writeStatus(args.config, args.checkUpdates, io);
|
|
1057
|
+
}
|
|
948
1058
|
async function writeStatus(config, checkUpdates, io) {
|
|
949
1059
|
const detected = await detectCliProviders([...new Set([...config.cliProviders, "codex", "cursor", "claude"])]);
|
|
950
1060
|
const repos = config.repoMappings.filter((mapping) => mapping.localPath?.trim());
|
|
@@ -953,7 +1063,7 @@ async function writeStatus(config, checkUpdates, io) {
|
|
|
953
1063
|
io.stdout.write(`Server: ${config.serverUrl || "not configured"}\n`);
|
|
954
1064
|
io.stdout.write(`Device: ${config.runnerId || "not configured"}${config.deviceName ? ` (${config.deviceName})` : ""}\n`);
|
|
955
1065
|
io.stdout.write(`Device token: ${config.deviceToken ? "configured" : "missing"}\n`);
|
|
956
|
-
io.stdout.write(
|
|
1066
|
+
io.stdout.write(`${await idleSummaryLine()}\n`);
|
|
957
1067
|
io.stdout.write("Repos:\n");
|
|
958
1068
|
if (repos.length === 0) {
|
|
959
1069
|
io.stdout.write(" none\n");
|
|
@@ -971,6 +1081,7 @@ async function writeStatus(config, checkUpdates, io) {
|
|
|
971
1081
|
if (checkUpdates) {
|
|
972
1082
|
io.stdout.write("Update check: no update channel configured.\n");
|
|
973
1083
|
}
|
|
1084
|
+
return 0;
|
|
974
1085
|
}
|
|
975
1086
|
async function cleanupRepos(config, mode, force, cleanup, io) {
|
|
976
1087
|
const repos = config.repoMappings.filter((mapping) => mapping.localPath?.trim());
|
|
@@ -1003,7 +1114,11 @@ async function cleanupRepos(config, mode, force, cleanup, io) {
|
|
|
1003
1114
|
io.stdout.write(`Removed ${result.removedWorktrees} stale managed ${result.removedWorktrees === 1 ? "worktree" : "worktrees"} from ${result.worktreeRoot}\n`);
|
|
1004
1115
|
}
|
|
1005
1116
|
else {
|
|
1006
|
-
|
|
1117
|
+
const deleted = result.deletedBranches ?? 0;
|
|
1118
|
+
io.stdout.write(`Pruned stale worktree metadata and deleted ${deleted} Forge ${deleted === 1 ? "branch" : "branches"} (merged work and leftover readiness probes) in ${repoPath}\n`);
|
|
1119
|
+
if (result.mergedBaseUnresolved) {
|
|
1120
|
+
io.stderr.write(`${repoPath}: merged work branches were kept because the base branch couldn't be determined: origin/HEAD is unset or names a branch that no longer exists, and origin has none or more than one of develop, main and master. Run \`git fetch origin && git remote set-head origin --auto\`.\n`);
|
|
1121
|
+
}
|
|
1007
1122
|
}
|
|
1008
1123
|
}
|
|
1009
1124
|
catch (error) {
|
|
@@ -1013,158 +1128,6 @@ async function cleanupRepos(config, mode, force, cleanup, io) {
|
|
|
1013
1128
|
}
|
|
1014
1129
|
return failures === 0 ? 0 : 1;
|
|
1015
1130
|
}
|
|
1016
|
-
async function detectCliProviders(providers) {
|
|
1017
|
-
const results = [];
|
|
1018
|
-
for (const provider of providers) {
|
|
1019
|
-
let detected = null;
|
|
1020
|
-
for (const probe of cliProbeCommandsFor(provider)) {
|
|
1021
|
-
try {
|
|
1022
|
-
detected = await execVersionCommand(probe, probe.timeoutMs);
|
|
1023
|
-
break;
|
|
1024
|
-
}
|
|
1025
|
-
catch {
|
|
1026
|
-
// Try the next provider-specific probe.
|
|
1027
|
-
}
|
|
1028
|
-
}
|
|
1029
|
-
results.push({
|
|
1030
|
-
provider,
|
|
1031
|
-
found: detected !== null,
|
|
1032
|
-
version: detected ? versionLine(`${detected.stdout || detected.stderr}`) : "",
|
|
1033
|
-
models: detected ? await detectCliModels(provider) : []
|
|
1034
|
-
});
|
|
1035
|
-
}
|
|
1036
|
-
return results;
|
|
1037
|
-
}
|
|
1038
|
-
function cliProbeCommandsFor(provider) {
|
|
1039
|
-
const normalized = provider.toLowerCase();
|
|
1040
|
-
if (normalized === "codex") {
|
|
1041
|
-
return [
|
|
1042
|
-
{ command: "codex", args: ["-V"] },
|
|
1043
|
-
{ command: "codex", args: ["--version"] }
|
|
1044
|
-
];
|
|
1045
|
-
}
|
|
1046
|
-
if (normalized === "claude") {
|
|
1047
|
-
return [
|
|
1048
|
-
// Claude Code's Node startup can exceed the default 2s probe on a cold Windows host.
|
|
1049
|
-
{ command: "claude", args: ["--version"], timeoutMs: 8000 },
|
|
1050
|
-
{ command: "claude", args: ["-v"], timeoutMs: 8000 }
|
|
1051
|
-
];
|
|
1052
|
-
}
|
|
1053
|
-
if (normalized === "cursor") {
|
|
1054
|
-
return [
|
|
1055
|
-
{ command: "cursor-agent", args: ["-v"] },
|
|
1056
|
-
{ command: "agent", args: ["-v"] },
|
|
1057
|
-
{ command: "cursor-agent", args: ["--version"] },
|
|
1058
|
-
{ command: "agent", args: ["--version"] }
|
|
1059
|
-
];
|
|
1060
|
-
}
|
|
1061
|
-
return [
|
|
1062
|
-
{ command: provider, args: ["--version"] },
|
|
1063
|
-
{ command: provider, args: ["-V"] }
|
|
1064
|
-
];
|
|
1065
|
-
}
|
|
1066
|
-
async function execVersionCommand(probe, timeout = 2000, maxBuffer) {
|
|
1067
|
-
const directLaunch = process.platform === "win32"
|
|
1068
|
-
? await resolveCursorAgentDirectLaunch(probe.command, probe.args)
|
|
1069
|
-
: null;
|
|
1070
|
-
if (directLaunch) {
|
|
1071
|
-
return await execFileAsync(directLaunch.command, [...directLaunch.args], { timeout, maxBuffer });
|
|
1072
|
-
}
|
|
1073
|
-
try {
|
|
1074
|
-
return await execFileAsync(probe.command, probe.args, { timeout, maxBuffer });
|
|
1075
|
-
}
|
|
1076
|
-
catch (error) {
|
|
1077
|
-
if (process.platform !== "win32") {
|
|
1078
|
-
throw error;
|
|
1079
|
-
}
|
|
1080
|
-
const launch = buildWindowsCmdLaunch(probe.command, probe.args);
|
|
1081
|
-
return await execFileAsync(launch.command, [...launch.args], { timeout, maxBuffer });
|
|
1082
|
-
}
|
|
1083
|
-
}
|
|
1084
|
-
function versionLine(output) {
|
|
1085
|
-
const lines = output
|
|
1086
|
-
.trim()
|
|
1087
|
-
.split(/\r?\n/)
|
|
1088
|
-
.map((line) => line.trim())
|
|
1089
|
-
.filter((line) => line.length > 0);
|
|
1090
|
-
return lines.at(-1) ?? "";
|
|
1091
|
-
}
|
|
1092
|
-
async function detectCliModels(provider) {
|
|
1093
|
-
const normalized = provider.toLowerCase();
|
|
1094
|
-
try {
|
|
1095
|
-
if (normalized === "codex") {
|
|
1096
|
-
// Windows installs codex as a .cmd shim, which execFile cannot launch directly.
|
|
1097
|
-
const result = await execVersionCommand({ command: "codex", args: ["debug", "models"] }, 10_000, 10 * 1024 * 1024);
|
|
1098
|
-
return parseCodexModelCatalog(result.stdout);
|
|
1099
|
-
}
|
|
1100
|
-
if (normalized === "cursor") {
|
|
1101
|
-
const result = await execVersionCommand({ command: "cursor-agent", args: ["models"] }, 10_000);
|
|
1102
|
-
return parseCursorModelList(`${result.stdout || result.stderr}`);
|
|
1103
|
-
}
|
|
1104
|
-
if (normalized === "claude") {
|
|
1105
|
-
// Claude Code has no model-listing command; it accepts these aliases and full model IDs.
|
|
1106
|
-
const configured = splitCsv(process.env.FORGE_CLAUDE_MODELS ?? "");
|
|
1107
|
-
return configured.length > 0 ? configured : [...claudeDefaultModels];
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
catch {
|
|
1111
|
-
return [];
|
|
1112
|
-
}
|
|
1113
|
-
return [];
|
|
1114
|
-
}
|
|
1115
|
-
export const claudeDefaultModels = ["sonnet", "opus", "haiku"];
|
|
1116
|
-
export function parseCodexModelCatalog(raw) {
|
|
1117
|
-
try {
|
|
1118
|
-
const parsed = JSON.parse(raw);
|
|
1119
|
-
if (!isRecord(parsed) || !Array.isArray(parsed.models)) {
|
|
1120
|
-
return [];
|
|
1121
|
-
}
|
|
1122
|
-
const entries = parsed.models
|
|
1123
|
-
.map((entry, index) => {
|
|
1124
|
-
if (!isRecord(entry) || typeof entry.slug !== "string") {
|
|
1125
|
-
return null;
|
|
1126
|
-
}
|
|
1127
|
-
const visibility = typeof entry.visibility === "string" ? entry.visibility.toLowerCase() : "list";
|
|
1128
|
-
if (visibility !== "list") {
|
|
1129
|
-
return null;
|
|
1130
|
-
}
|
|
1131
|
-
const priority = typeof entry.priority === "number" && Number.isFinite(entry.priority) ? entry.priority : index;
|
|
1132
|
-
return { slug: entry.slug, priority, index };
|
|
1133
|
-
})
|
|
1134
|
-
.filter((entry) => entry !== null)
|
|
1135
|
-
.sort((left, right) => left.priority - right.priority || left.index - right.index)
|
|
1136
|
-
.map((entry) => entry.slug);
|
|
1137
|
-
return uniqueModels(entries);
|
|
1138
|
-
}
|
|
1139
|
-
catch {
|
|
1140
|
-
return [];
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
|
-
export function parseCursorModelList(raw) {
|
|
1144
|
-
return uniqueModels(raw
|
|
1145
|
-
.split(/\r?\n/)
|
|
1146
|
-
.map((line) => line.trim())
|
|
1147
|
-
.filter((line) => line.length > 0 && !line.toLowerCase().startsWith("available models"))
|
|
1148
|
-
.map((line) => line.split(/\s+-\s+/, 1)[0]?.trim() ?? "")
|
|
1149
|
-
.filter((model) => model.length > 0));
|
|
1150
|
-
}
|
|
1151
|
-
function uniqueModels(models) {
|
|
1152
|
-
const seen = new Set();
|
|
1153
|
-
const result = [];
|
|
1154
|
-
for (const model of models) {
|
|
1155
|
-
const trimmed = model.trim();
|
|
1156
|
-
const key = trimmed.toLowerCase();
|
|
1157
|
-
if (!trimmed || seen.has(key)) {
|
|
1158
|
-
continue;
|
|
1159
|
-
}
|
|
1160
|
-
seen.add(key);
|
|
1161
|
-
result.push(trimmed);
|
|
1162
|
-
}
|
|
1163
|
-
return result;
|
|
1164
|
-
}
|
|
1165
|
-
function isRecord(value) {
|
|
1166
|
-
return typeof value === "object" && value !== null;
|
|
1167
|
-
}
|
|
1168
1131
|
async function withDetectedCliProviders(config, candidates = config.cliProviders) {
|
|
1169
1132
|
const detected = await detectCliProviders(uniqueProviders(candidates));
|
|
1170
1133
|
const found = detected.filter((result) => result.found);
|