@loucompanion/forge-bridge 0.1.4-dev.138b79c6feb3 → 0.1.4-dev.176dfdaf5020
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +142 -1
- package/dist/bridge/bridge-chat-provider-command.d.ts +19 -0
- package/dist/bridge/bridge-chat-provider-command.js +132 -0
- package/dist/bridge/bridge-chat.types.d.ts +10 -0
- package/dist/bridge/bridge-chat.types.js +16 -1
- package/dist/bridge/bridge-state-file.d.ts +161 -0
- package/dist/bridge/bridge-state-file.js +376 -0
- package/dist/bridge/bridge-state-io.d.ts +11 -0
- package/dist/bridge/bridge-state-io.js +50 -0
- package/dist/bridge/bridge-state-lock.d.ts +11 -0
- package/dist/bridge/bridge-state-lock.js +102 -0
- package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
- package/dist/bridge/bridge-state-unpublished.js +111 -0
- package/dist/bridge/bridge.base.d.ts +9 -0
- package/dist/bridge/bridge.service.d.ts +87 -14
- package/dist/bridge/bridge.service.js +393 -337
- package/dist/bridge/bridge.types.d.ts +16 -0
- package/dist/bridge/in-flight-registry.d.ts +62 -0
- package/dist/bridge/in-flight-registry.js +207 -0
- package/dist/bridge/local-yield-flag.d.ts +6 -0
- package/dist/bridge/local-yield-flag.js +34 -0
- package/dist/bridge/readiness-result-outbox.d.ts +5 -1
- package/dist/bridge/readiness-result-outbox.js +20 -0
- package/dist/bridge/runner-host-capabilities.d.ts +3 -0
- package/dist/bridge/runner-host-capabilities.js +13 -0
- package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
- package/dist/bridge/sandbox-resource-accounting.js +150 -0
- package/dist/cleanup/cleanup-wip.d.ts +12 -0
- package/dist/cleanup/cleanup-wip.js +66 -0
- package/dist/cleanup/cleanup.service.d.ts +11 -1
- package/dist/cleanup/cleanup.service.js +80 -62
- package/dist/cleanup/cleanup.types.d.ts +2 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +2 -0
- package/dist/cleanup/host-runtime-ledger.js +30 -9
- package/dist/cli/cli.help.js +74 -12
- package/dist/cli/cli.service.d.ts +19 -10
- package/dist/cli/cli.service.js +142 -185
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +6 -0
- package/dist/cli/local-config.js +32 -4
- package/dist/cli/provider-cli-detection.d.ts +10 -0
- package/dist/cli/provider-cli-detection.js +160 -0
- package/dist/runtime/aspnet-runtime-prebuild.d.ts +20 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +104 -26
- package/dist/runtime/attempt-database-broker.d.ts +1 -1
- package/dist/runtime/attempt-node-runtime-launcher.js +9 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +2 -0
- package/dist/runtime/attempt-process-supervisor.js +12 -6
- package/dist/runtime/docker-engine-probe.d.ts +5 -0
- package/dist/runtime/docker-engine-probe.js +7 -0
- package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
- package/dist/runtime/dotnet-build-outputs.js +402 -0
- package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
- package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
- package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
- package/dist/runtime/ephemeral-test-postgres.js +303 -0
- package/dist/runtime/host-facts.d.ts +2 -1
- package/dist/runtime/host-load-admission.d.ts +18 -3
- package/dist/runtime/host-load-admission.js +19 -4
- package/dist/runtime/host-load-child-environment.d.ts +11 -6
- package/dist/runtime/host-load-child-environment.js +22 -11
- package/dist/runtime/host-load-governor-config.d.ts +19 -1
- package/dist/runtime/host-load-governor-config.js +37 -0
- package/dist/runtime/host-load-governor.d.ts +14 -0
- package/dist/runtime/host-load-governor.js +139 -26
- package/dist/runtime/host-load-ledger-lock.js +6 -4
- package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
- package/dist/runtime/host-load-runtime-settings.js +80 -0
- package/dist/runtime/host-load-sampler.d.ts +34 -4
- package/dist/runtime/host-load-sampler.js +73 -7
- package/dist/runtime/host-load-step-class.d.ts +3 -1
- package/dist/runtime/host-load-step-class.js +60 -5
- package/dist/runtime/host-load-test-slot.d.ts +43 -0
- package/dist/runtime/host-load-test-slot.js +81 -0
- package/dist/runtime/host-load-token-ledger.d.ts +26 -0
- package/dist/runtime/host-load-token-ledger.js +93 -61
- package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
- package/dist/runtime/host-load-windows-cpu.js +85 -0
- package/dist/runtime/host-runtime-contract.d.ts +12 -0
- package/dist/runtime/host-runtime-contract.js +29 -1
- package/dist/runtime/host-runtime-lease.d.ts +32 -4
- package/dist/runtime/host-runtime-lease.js +109 -173
- package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
- package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
- package/dist/runtime/host-runtime-promotion.d.ts +23 -0
- package/dist/runtime/host-runtime-promotion.js +36 -0
- package/dist/runtime/managed-command-teardown.js +5 -16
- package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
- package/dist/runtime/native-test-postgres-fallback.js +60 -8
- package/dist/runtime/runner-settings.d.ts +104 -0
- package/dist/runtime/runner-settings.js +236 -0
- package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
- package/dist/runtime/supervised-runtime-build-guard.js +112 -0
- package/dist/sandbox/host-capacity-broker.d.ts +10 -2
- package/dist/sandbox/host-capacity-broker.js +27 -6
- package/dist/sandbox/managed-branch.d.ts +13 -0
- package/dist/sandbox/managed-branch.js +90 -0
- package/dist/sandbox/provider-auth/codex.js +11 -11
- package/dist/sandbox/runtime.js +2 -6
- package/dist/session/architect-waits.d.ts +2 -0
- package/dist/session/architect-waits.js +138 -0
- package/dist/session/managed-attempt-tools.d.ts +0 -7
- package/dist/session/managed-attempt-tools.js +58 -91
- package/dist/session/managed-build-coordinator.d.ts +16 -0
- package/dist/session/managed-build-coordinator.js +10 -0
- package/dist/session/managed-build-receipt.d.ts +5 -0
- package/dist/session/managed-build-receipt.js +8 -3
- package/dist/session/managed-command-host-load.d.ts +2 -0
- package/dist/session/managed-command-host-load.js +2 -1
- package/dist/session/phase-completion.artifacts.js +2 -1
- package/dist/session/phase-completion.d.ts +8 -0
- package/dist/session/phase-completion.js +1 -0
- package/dist/session/phase-completion.mcp-args.d.ts +9 -0
- package/dist/session/phase-completion.mcp-args.js +156 -0
- package/dist/session/phase-completion.runtime.d.ts +0 -8
- package/dist/session/phase-completion.runtime.js +43 -197
- package/dist/session/phase-completion.schemas.js +25 -23
- package/dist/session/phase-completion.validation.js +3 -1
- package/dist/session/pre-publication-native-postgres.d.ts +30 -0
- package/dist/session/pre-publication-native-postgres.js +111 -0
- package/dist/session/pre-publication-pass.d.ts +61 -0
- package/dist/session/pre-publication-pass.js +148 -0
- package/dist/session/pre-publication-process.js +10 -10
- package/dist/session/pre-publication-step-execution.d.ts +2 -1
- package/dist/session/pre-publication-step-execution.js +6 -5
- package/dist/session/pre-publication-validation.d.ts +30 -14
- package/dist/session/pre-publication-validation.js +207 -134
- package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
- package/dist/session/provider-cli/claude-background-work.js +181 -0
- package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
- package/dist/session/provider-cli/host-build-lock.js +30 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
- package/dist/session/provider-cli/pre-publication-repair.js +276 -0
- package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +75 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +15 -36
- package/dist/session/provider-cli/provider-cli.process.js +39 -430
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +5 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +68 -31
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +8 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +29 -1
- package/dist/session/provider-cli/provider-cli.service.d.ts +5 -5
- package/dist/session/provider-cli/provider-cli.service.js +70 -263
- package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +4 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +45 -0
- package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
- package/dist/session/provider-cli/provider-output-pipes.js +67 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +2 -0
- package/dist/session/provider-cli/provider-output-state.js +6 -0
- package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
- package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
- package/dist/session/qa-sidecar-validation.d.ts +6 -0
- package/dist/session/qa-sidecar-validation.js +28 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +22 -1
- package/dist/session/sandbox-host-capacity-gate.js +42 -14
- package/dist/session/session-redaction.js +31 -181
- package/dist/session/session.base.d.ts +6 -1
- package/dist/session/session.service.d.ts +6 -1
- package/dist/session/session.service.js +75 -64
- package/dist/session/session.types.js +3 -3
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -0
- package/dist/shared/fs/file-identity.d.ts +10 -0
- package/dist/shared/fs/file-identity.js +15 -0
- package/dist/shared/fs/replace-file.d.ts +7 -0
- package/dist/shared/fs/replace-file.js +33 -0
- package/dist/shared/process/host-process-recovery.d.ts +14 -3
- package/dist/shared/process/host-process-recovery.js +23 -3
- package/dist/shared/process/host-process-supervisor.d.ts +13 -1
- package/dist/shared/process/host-process-supervisor.js +66 -14
- package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
- package/dist/shared/process/windows-app-execution-alias.js +45 -0
- package/dist/shared/process/windows-launch.d.ts +18 -0
- package/dist/shared/process/windows-launch.js +68 -0
- package/dist/shared/provider-capabilities.js +14 -7
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/orphan-relink.d.ts +19 -0
- package/dist/worktree/orphan-relink.js +106 -0
- package/dist/worktree/wip-git.d.ts +33 -0
- package/dist/worktree/wip-git.js +122 -0
- package/dist/worktree/wip-refs.d.ts +62 -0
- package/dist/worktree/wip-refs.js +119 -0
- package/dist/worktree/wip-restore.d.ts +38 -0
- package/dist/worktree/wip-restore.js +190 -0
- package/dist/worktree/wip-snapshot.d.ts +50 -0
- package/dist/worktree/wip-snapshot.js +268 -0
- package/dist/worktree/worktree-inputs.d.ts +8 -0
- package/dist/worktree/worktree-inputs.js +134 -0
- package/dist/worktree/worktree-origin-sync.d.ts +34 -0
- package/dist/worktree/worktree-origin-sync.js +127 -0
- package/dist/worktree/worktree-wip-events.d.ts +18 -0
- package/dist/worktree/worktree-wip-events.js +98 -0
- package/dist/worktree/worktree-wip.d.ts +50 -0
- package/dist/worktree/worktree-wip.js +185 -0
- package/dist/worktree/worktree.base.d.ts +7 -1
- package/dist/worktree/worktree.service.d.ts +27 -5
- package/dist/worktree/worktree.service.js +110 -181
- package/dist/worktree/worktree.types.d.ts +31 -0
- package/package.json +2 -2
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;
|
|
@@ -98,6 +97,15 @@ export class ForgeBridgeCliService {
|
|
|
98
97
|
await this.bridgeFactory(config).run(controller.signal);
|
|
99
98
|
return 0;
|
|
100
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
|
+
}
|
|
101
109
|
finally {
|
|
102
110
|
process.off("SIGINT", stop);
|
|
103
111
|
process.off("SIGTERM", stop);
|
|
@@ -121,13 +129,22 @@ export class ForgeBridgeCliService {
|
|
|
121
129
|
const current = readLocalConfigSync();
|
|
122
130
|
io.stdout.write(`Pairing with server: ${args.serverUrl}\n`);
|
|
123
131
|
const code = await resolvePairingCode(args.code);
|
|
124
|
-
const
|
|
125
|
-
await
|
|
126
|
-
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 });
|
|
127
134
|
const claim = await this.pairRunner(pairArgs);
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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`);
|
|
131
148
|
io.stdout.write(`Repo folder: ${repoRoot}\n`);
|
|
132
149
|
io.stdout.write(`Config: ${resolveLocalConfigPath()}\n`);
|
|
133
150
|
io.stdout.write("Start the bridge with: forge-bridge connect\n");
|
|
@@ -176,8 +193,7 @@ export class ForgeBridgeCliService {
|
|
|
176
193
|
}
|
|
177
194
|
}
|
|
178
195
|
if (args.command === "status") {
|
|
179
|
-
await
|
|
180
|
-
return 0;
|
|
196
|
+
return await runStatus(args, io);
|
|
181
197
|
}
|
|
182
198
|
if (args.command === "cleanup") {
|
|
183
199
|
return await cleanupRepos(args.config, args.mode, args.force, this.cleanupFactory(args.config.sandboxStateRoot), io);
|
|
@@ -210,6 +226,9 @@ export class ForgeBridgeCliService {
|
|
|
210
226
|
writeSandboxPolicyStatus(readLocalConfigSync(), io);
|
|
211
227
|
return 0;
|
|
212
228
|
}
|
|
229
|
+
if (args.command === "yield") {
|
|
230
|
+
return await runYieldCommand(args.action, io);
|
|
231
|
+
}
|
|
213
232
|
if (args.command === "mcp") {
|
|
214
233
|
const parsed = parseCompletionMcpArgs(args.argv);
|
|
215
234
|
if (!parsed.ok) {
|
|
@@ -247,6 +266,36 @@ export class ForgeBridgeCliService {
|
|
|
247
266
|
}
|
|
248
267
|
}
|
|
249
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
|
+
}
|
|
250
299
|
function attachEnvSecretGrant(dispatch) {
|
|
251
300
|
if (!dispatch.execution.requiresApiKeySecretGrant) {
|
|
252
301
|
delete process.env[apiKeySecretGrantEnv];
|
|
@@ -329,17 +378,7 @@ export function parseArgs(argv) {
|
|
|
329
378
|
return { ok: false, error: "Usage: forge-bridge server <show|set <url>>" };
|
|
330
379
|
}
|
|
331
380
|
if (argv[0] === "status") {
|
|
332
|
-
|
|
333
|
-
for (let index = 1; index < argv.length; index += 1) {
|
|
334
|
-
const arg = argv[index];
|
|
335
|
-
if (arg === "--check-updates") {
|
|
336
|
-
checkUpdates = true;
|
|
337
|
-
}
|
|
338
|
-
else {
|
|
339
|
-
return { ok: false, error: `Unknown argument: ${arg}` };
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
return { ok: true, command: "status", config: configuredBridgeServiceConfig(), checkUpdates };
|
|
381
|
+
return parseStatusArgs(argv, configuredBridgeServiceConfig);
|
|
343
382
|
}
|
|
344
383
|
if (argv[0] === "cleanup") {
|
|
345
384
|
return parseCleanupArgs(argv);
|
|
@@ -350,6 +389,13 @@ export function parseArgs(argv) {
|
|
|
350
389
|
if (argv[0] === "sandbox") {
|
|
351
390
|
return parseSandboxArgs(argv);
|
|
352
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
|
+
}
|
|
353
399
|
if (argv[0] !== "run-once") {
|
|
354
400
|
return {
|
|
355
401
|
ok: false,
|
|
@@ -763,6 +809,7 @@ function parsePairArgs(argv) {
|
|
|
763
809
|
repoRoot: repoRoot?.trim() ? path.resolve(repoRoot) : undefined,
|
|
764
810
|
cleanupWorktrees: cleanupWorktrees ?? defaultConfig.cleanupWorktrees,
|
|
765
811
|
cliProviders: cliProviders.length > 0 ? cliProviders : localConfig.cliProviders && localConfig.cliProviders.length > 0 ? [...localConfig.cliProviders] : ["codex"],
|
|
812
|
+
cliProvidersFromFlag: cliProviders.length > 0,
|
|
766
813
|
projectLabels: projectLabels.length > 0 ? projectLabels : localConfig.projectLabels ? [...localConfig.projectLabels] : []
|
|
767
814
|
};
|
|
768
815
|
}
|
|
@@ -825,9 +872,71 @@ async function claimBridgeRunner(args) {
|
|
|
825
872
|
}
|
|
826
873
|
return {
|
|
827
874
|
runnerId: value.runnerId,
|
|
828
|
-
deviceToken: value.deviceToken
|
|
875
|
+
deviceToken: value.deviceToken,
|
|
876
|
+
host: parsePairRunnerHost(value.host)
|
|
829
877
|
};
|
|
830
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
|
+
}
|
|
831
940
|
function pairedConfig(current, args, claim) {
|
|
832
941
|
return {
|
|
833
942
|
...current,
|
|
@@ -872,11 +981,7 @@ async function resolvePairingCode(code) {
|
|
|
872
981
|
prompt.close();
|
|
873
982
|
}
|
|
874
983
|
}
|
|
875
|
-
async function
|
|
876
|
-
const fallback = path.resolve(repoRoot ?? configuredRoot ?? path.join(os.homedir(), "ForgeRepos"));
|
|
877
|
-
if (repoRoot?.trim()) {
|
|
878
|
-
return fallback;
|
|
879
|
-
}
|
|
984
|
+
async function promptPairRepoRoot(fallback) {
|
|
880
985
|
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
881
986
|
return fallback;
|
|
882
987
|
}
|
|
@@ -947,6 +1052,9 @@ async function writeJsonAtomic(outputPath, value) {
|
|
|
947
1052
|
await fs.writeFile(tempPath, `${JSON.stringify(value, null, 2)}\n`, "utf8");
|
|
948
1053
|
await fs.rename(tempPath, outputPath);
|
|
949
1054
|
}
|
|
1055
|
+
async function runStatus(args, io) {
|
|
1056
|
+
return args.idle ? await runIdleStatusCommand(args.idle, io) : await writeStatus(args.config, args.checkUpdates, io);
|
|
1057
|
+
}
|
|
950
1058
|
async function writeStatus(config, checkUpdates, io) {
|
|
951
1059
|
const detected = await detectCliProviders([...new Set([...config.cliProviders, "codex", "cursor", "claude"])]);
|
|
952
1060
|
const repos = config.repoMappings.filter((mapping) => mapping.localPath?.trim());
|
|
@@ -955,7 +1063,7 @@ async function writeStatus(config, checkUpdates, io) {
|
|
|
955
1063
|
io.stdout.write(`Server: ${config.serverUrl || "not configured"}\n`);
|
|
956
1064
|
io.stdout.write(`Device: ${config.runnerId || "not configured"}${config.deviceName ? ` (${config.deviceName})` : ""}\n`);
|
|
957
1065
|
io.stdout.write(`Device token: ${config.deviceToken ? "configured" : "missing"}\n`);
|
|
958
|
-
io.stdout.write(
|
|
1066
|
+
io.stdout.write(`${await idleSummaryLine()}\n`);
|
|
959
1067
|
io.stdout.write("Repos:\n");
|
|
960
1068
|
if (repos.length === 0) {
|
|
961
1069
|
io.stdout.write(" none\n");
|
|
@@ -973,6 +1081,7 @@ async function writeStatus(config, checkUpdates, io) {
|
|
|
973
1081
|
if (checkUpdates) {
|
|
974
1082
|
io.stdout.write("Update check: no update channel configured.\n");
|
|
975
1083
|
}
|
|
1084
|
+
return 0;
|
|
976
1085
|
}
|
|
977
1086
|
async function cleanupRepos(config, mode, force, cleanup, io) {
|
|
978
1087
|
const repos = config.repoMappings.filter((mapping) => mapping.localPath?.trim());
|
|
@@ -1019,158 +1128,6 @@ async function cleanupRepos(config, mode, force, cleanup, io) {
|
|
|
1019
1128
|
}
|
|
1020
1129
|
return failures === 0 ? 0 : 1;
|
|
1021
1130
|
}
|
|
1022
|
-
async function detectCliProviders(providers) {
|
|
1023
|
-
const results = [];
|
|
1024
|
-
for (const provider of providers) {
|
|
1025
|
-
let detected = null;
|
|
1026
|
-
for (const probe of cliProbeCommandsFor(provider)) {
|
|
1027
|
-
try {
|
|
1028
|
-
detected = await execVersionCommand(probe, probe.timeoutMs);
|
|
1029
|
-
break;
|
|
1030
|
-
}
|
|
1031
|
-
catch {
|
|
1032
|
-
// Try the next provider-specific probe.
|
|
1033
|
-
}
|
|
1034
|
-
}
|
|
1035
|
-
results.push({
|
|
1036
|
-
provider,
|
|
1037
|
-
found: detected !== null,
|
|
1038
|
-
version: detected ? versionLine(`${detected.stdout || detected.stderr}`) : "",
|
|
1039
|
-
models: detected ? await detectCliModels(provider) : []
|
|
1040
|
-
});
|
|
1041
|
-
}
|
|
1042
|
-
return results;
|
|
1043
|
-
}
|
|
1044
|
-
function cliProbeCommandsFor(provider) {
|
|
1045
|
-
const normalized = provider.toLowerCase();
|
|
1046
|
-
if (normalized === "codex") {
|
|
1047
|
-
return [
|
|
1048
|
-
{ command: "codex", args: ["-V"] },
|
|
1049
|
-
{ command: "codex", args: ["--version"] }
|
|
1050
|
-
];
|
|
1051
|
-
}
|
|
1052
|
-
if (normalized === "claude") {
|
|
1053
|
-
return [
|
|
1054
|
-
// Claude Code's Node startup can exceed the default 2s probe on a cold Windows host.
|
|
1055
|
-
{ command: "claude", args: ["--version"], timeoutMs: 8000 },
|
|
1056
|
-
{ command: "claude", args: ["-v"], timeoutMs: 8000 }
|
|
1057
|
-
];
|
|
1058
|
-
}
|
|
1059
|
-
if (normalized === "cursor") {
|
|
1060
|
-
return [
|
|
1061
|
-
{ command: "cursor-agent", args: ["-v"] },
|
|
1062
|
-
{ command: "agent", args: ["-v"] },
|
|
1063
|
-
{ command: "cursor-agent", args: ["--version"] },
|
|
1064
|
-
{ command: "agent", args: ["--version"] }
|
|
1065
|
-
];
|
|
1066
|
-
}
|
|
1067
|
-
return [
|
|
1068
|
-
{ command: provider, args: ["--version"] },
|
|
1069
|
-
{ command: provider, args: ["-V"] }
|
|
1070
|
-
];
|
|
1071
|
-
}
|
|
1072
|
-
async function execVersionCommand(probe, timeout = 2000, maxBuffer) {
|
|
1073
|
-
const directLaunch = process.platform === "win32"
|
|
1074
|
-
? await resolveCursorAgentDirectLaunch(probe.command, probe.args)
|
|
1075
|
-
: null;
|
|
1076
|
-
if (directLaunch) {
|
|
1077
|
-
return await execFileAsync(directLaunch.command, [...directLaunch.args], { timeout, maxBuffer });
|
|
1078
|
-
}
|
|
1079
|
-
try {
|
|
1080
|
-
return await execFileAsync(probe.command, probe.args, { timeout, maxBuffer });
|
|
1081
|
-
}
|
|
1082
|
-
catch (error) {
|
|
1083
|
-
if (process.platform !== "win32") {
|
|
1084
|
-
throw error;
|
|
1085
|
-
}
|
|
1086
|
-
const launch = buildWindowsCmdLaunch(probe.command, probe.args);
|
|
1087
|
-
return await execFileAsync(launch.command, [...launch.args], { timeout, maxBuffer });
|
|
1088
|
-
}
|
|
1089
|
-
}
|
|
1090
|
-
function versionLine(output) {
|
|
1091
|
-
const lines = output
|
|
1092
|
-
.trim()
|
|
1093
|
-
.split(/\r?\n/)
|
|
1094
|
-
.map((line) => line.trim())
|
|
1095
|
-
.filter((line) => line.length > 0);
|
|
1096
|
-
return lines.at(-1) ?? "";
|
|
1097
|
-
}
|
|
1098
|
-
async function detectCliModels(provider) {
|
|
1099
|
-
const normalized = provider.toLowerCase();
|
|
1100
|
-
try {
|
|
1101
|
-
if (normalized === "codex") {
|
|
1102
|
-
// Windows installs codex as a .cmd shim, which execFile cannot launch directly.
|
|
1103
|
-
const result = await execVersionCommand({ command: "codex", args: ["debug", "models"] }, 10_000, 10 * 1024 * 1024);
|
|
1104
|
-
return parseCodexModelCatalog(result.stdout);
|
|
1105
|
-
}
|
|
1106
|
-
if (normalized === "cursor") {
|
|
1107
|
-
const result = await execVersionCommand({ command: "cursor-agent", args: ["models"] }, 10_000);
|
|
1108
|
-
return parseCursorModelList(`${result.stdout || result.stderr}`);
|
|
1109
|
-
}
|
|
1110
|
-
if (normalized === "claude") {
|
|
1111
|
-
// Claude Code has no model-listing command; it accepts these aliases and full model IDs.
|
|
1112
|
-
const configured = splitCsv(process.env.FORGE_CLAUDE_MODELS ?? "");
|
|
1113
|
-
return configured.length > 0 ? configured : [...claudeDefaultModels];
|
|
1114
|
-
}
|
|
1115
|
-
}
|
|
1116
|
-
catch {
|
|
1117
|
-
return [];
|
|
1118
|
-
}
|
|
1119
|
-
return [];
|
|
1120
|
-
}
|
|
1121
|
-
export const claudeDefaultModels = ["sonnet", "opus", "haiku"];
|
|
1122
|
-
export function parseCodexModelCatalog(raw) {
|
|
1123
|
-
try {
|
|
1124
|
-
const parsed = JSON.parse(raw);
|
|
1125
|
-
if (!isRecord(parsed) || !Array.isArray(parsed.models)) {
|
|
1126
|
-
return [];
|
|
1127
|
-
}
|
|
1128
|
-
const entries = parsed.models
|
|
1129
|
-
.map((entry, index) => {
|
|
1130
|
-
if (!isRecord(entry) || typeof entry.slug !== "string") {
|
|
1131
|
-
return null;
|
|
1132
|
-
}
|
|
1133
|
-
const visibility = typeof entry.visibility === "string" ? entry.visibility.toLowerCase() : "list";
|
|
1134
|
-
if (visibility !== "list") {
|
|
1135
|
-
return null;
|
|
1136
|
-
}
|
|
1137
|
-
const priority = typeof entry.priority === "number" && Number.isFinite(entry.priority) ? entry.priority : index;
|
|
1138
|
-
return { slug: entry.slug, priority, index };
|
|
1139
|
-
})
|
|
1140
|
-
.filter((entry) => entry !== null)
|
|
1141
|
-
.sort((left, right) => left.priority - right.priority || left.index - right.index)
|
|
1142
|
-
.map((entry) => entry.slug);
|
|
1143
|
-
return uniqueModels(entries);
|
|
1144
|
-
}
|
|
1145
|
-
catch {
|
|
1146
|
-
return [];
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
|
-
export function parseCursorModelList(raw) {
|
|
1150
|
-
return uniqueModels(raw
|
|
1151
|
-
.split(/\r?\n/)
|
|
1152
|
-
.map((line) => line.trim())
|
|
1153
|
-
.filter((line) => line.length > 0 && !line.toLowerCase().startsWith("available models"))
|
|
1154
|
-
.map((line) => line.split(/\s+-\s+/, 1)[0]?.trim() ?? "")
|
|
1155
|
-
.filter((model) => model.length > 0));
|
|
1156
|
-
}
|
|
1157
|
-
function uniqueModels(models) {
|
|
1158
|
-
const seen = new Set();
|
|
1159
|
-
const result = [];
|
|
1160
|
-
for (const model of models) {
|
|
1161
|
-
const trimmed = model.trim();
|
|
1162
|
-
const key = trimmed.toLowerCase();
|
|
1163
|
-
if (!trimmed || seen.has(key)) {
|
|
1164
|
-
continue;
|
|
1165
|
-
}
|
|
1166
|
-
seen.add(key);
|
|
1167
|
-
result.push(trimmed);
|
|
1168
|
-
}
|
|
1169
|
-
return result;
|
|
1170
|
-
}
|
|
1171
|
-
function isRecord(value) {
|
|
1172
|
-
return typeof value === "object" && value !== null;
|
|
1173
|
-
}
|
|
1174
1131
|
async function withDetectedCliProviders(config, candidates = config.cliProviders) {
|
|
1175
1132
|
const detected = await detectCliProviders(uniqueProviders(candidates));
|
|
1176
1133
|
const found = detected.filter((result) => result.found);
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { type BridgeIdleEvaluation, type BridgeStateRead } from "../bridge/bridge-state-file.js";
|
|
2
|
+
import { type InFlightEntry } from "../bridge/in-flight-registry.js";
|
|
3
|
+
import type { BridgeServiceConfig } from "../bridge/bridge.types.js";
|
|
4
|
+
import type { CliIo } from "./cli.base.js";
|
|
5
|
+
export interface IdleStatusOptions {
|
|
6
|
+
readonly json: boolean;
|
|
7
|
+
/** Seconds to keep polling while the bridge is busy, stale or not yet yielding; 0 (or no --wait) checks once. */
|
|
8
|
+
readonly waitSeconds: number;
|
|
9
|
+
/** Idle counts only once the bridge itself reports yield (exit 5 until then). */
|
|
10
|
+
readonly requireYield: boolean;
|
|
11
|
+
}
|
|
12
|
+
export type StatusArgs = {
|
|
13
|
+
readonly ok: true;
|
|
14
|
+
readonly command: "status";
|
|
15
|
+
readonly config: BridgeServiceConfig;
|
|
16
|
+
readonly checkUpdates: boolean;
|
|
17
|
+
readonly idle: IdleStatusOptions | null;
|
|
18
|
+
} | {
|
|
19
|
+
readonly ok: false;
|
|
20
|
+
readonly error: string;
|
|
21
|
+
};
|
|
22
|
+
export declare function parseStatusArgs(argv: readonly string[], config: () => BridgeServiceConfig): StatusArgs;
|
|
23
|
+
export interface IdleStatusDependencies {
|
|
24
|
+
readonly statePath: string;
|
|
25
|
+
readonly now: () => number;
|
|
26
|
+
readonly pidAlive: (pid: number) => boolean;
|
|
27
|
+
readonly read: (statePath: string) => Promise<BridgeStateRead>;
|
|
28
|
+
readonly localYield: () => Promise<boolean>;
|
|
29
|
+
readonly sleep: (ms: number) => Promise<void>;
|
|
30
|
+
readonly pollMs: number;
|
|
31
|
+
}
|
|
32
|
+
export declare function defaultIdleStatusDependencies(): IdleStatusDependencies;
|
|
33
|
+
export declare function runIdleStatusCommand(options: IdleStatusOptions, io: CliIo, deps?: IdleStatusDependencies): Promise<number>;
|
|
34
|
+
/** One line for plain `forge-bridge status`. */
|
|
35
|
+
export declare function idleSummaryLine(deps?: IdleStatusDependencies): Promise<string>;
|
|
36
|
+
export declare function idleStatusJson(evaluation: BridgeIdleEvaluation, deps: Pick<IdleStatusDependencies, "statePath" | "now">, localYield: boolean): {
|
|
37
|
+
pid: null;
|
|
38
|
+
runnerId: null;
|
|
39
|
+
runnerInstanceId: null;
|
|
40
|
+
version: null;
|
|
41
|
+
state: null;
|
|
42
|
+
startedAt: null;
|
|
43
|
+
updatedAt: null;
|
|
44
|
+
connected: null;
|
|
45
|
+
yielding: null;
|
|
46
|
+
yieldApplied: null;
|
|
47
|
+
conflict: null;
|
|
48
|
+
inFlight: readonly InFlightEntry[];
|
|
49
|
+
schemaVersion: number;
|
|
50
|
+
verdict: import("../bridge/bridge-state-file.js").BridgeIdleVerdict;
|
|
51
|
+
idle: boolean;
|
|
52
|
+
exitCode: number;
|
|
53
|
+
reason: string;
|
|
54
|
+
statePath: string;
|
|
55
|
+
checkedAt: string;
|
|
56
|
+
pidAlive: boolean | null;
|
|
57
|
+
heartbeatAgeMs: number | null;
|
|
58
|
+
staleAfterMs: number;
|
|
59
|
+
localYield: boolean;
|
|
60
|
+
} | {
|
|
61
|
+
pid: number;
|
|
62
|
+
runnerId: string;
|
|
63
|
+
runnerInstanceId: string;
|
|
64
|
+
version: string;
|
|
65
|
+
state: "running" | "stopped";
|
|
66
|
+
startedAt: string;
|
|
67
|
+
updatedAt: string;
|
|
68
|
+
connected: boolean;
|
|
69
|
+
yielding: boolean;
|
|
70
|
+
yieldApplied: boolean;
|
|
71
|
+
conflict: import("../bridge/bridge-state-file.js").BridgeStateConflict | null;
|
|
72
|
+
inFlight: readonly InFlightEntry[];
|
|
73
|
+
schemaVersion: number;
|
|
74
|
+
verdict: import("../bridge/bridge-state-file.js").BridgeIdleVerdict;
|
|
75
|
+
idle: boolean;
|
|
76
|
+
exitCode: number;
|
|
77
|
+
reason: string;
|
|
78
|
+
statePath: string;
|
|
79
|
+
checkedAt: string;
|
|
80
|
+
pidAlive: boolean | null;
|
|
81
|
+
heartbeatAgeMs: number | null;
|
|
82
|
+
staleAfterMs: number;
|
|
83
|
+
localYield: boolean;
|
|
84
|
+
};
|