@loucompanion/forge-bridge 0.1.4-dev.04a1e5b9e484 → 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 +145 -4
- 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 +101 -15
- package/dist/bridge/bridge.service.js +472 -345
- package/dist/bridge/bridge.types.d.ts +27 -0
- package/dist/bridge/dispatch-result-outbox.d.ts +11 -1
- package/dist/bridge/dispatch-result-outbox.js +31 -6
- 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 +5 -0
- package/dist/bridge/runner-host-capabilities.js +17 -0
- package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
- package/dist/bridge/sandbox-resource-accounting.js +150 -0
- package/dist/bridge/test-postgres-capability.d.ts +14 -0
- package/dist/bridge/test-postgres-capability.js +120 -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 +20 -1
- package/dist/cleanup/cleanup.service.js +150 -169
- package/dist/cleanup/cleanup.types.d.ts +6 -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 +7 -0
- package/dist/cleanup/host-runtime-ledger.js +130 -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 +76 -14
- package/dist/cli/cli.service.d.ts +19 -10
- package/dist/cli/cli.service.js +152 -187
- 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 +184 -18
- 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 +21 -0
- package/dist/runtime/attempt-process-supervisor.js +62 -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-database-capability-boundary.d.ts +1 -1
- package/dist/runtime/host-database-capability-boundary.js +1 -0
- package/dist/runtime/host-facts.d.ts +36 -0
- package/dist/runtime/host-facts.js +95 -0
- package/dist/runtime/host-load-admission.d.ts +67 -0
- package/dist/runtime/host-load-admission.js +99 -0
- package/dist/runtime/host-load-child-environment.d.ts +27 -0
- package/dist/runtime/host-load-child-environment.js +76 -0
- package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
- package/dist/runtime/host-load-forge-cgroups.js +140 -0
- package/dist/runtime/host-load-governor-config.d.ts +52 -0
- package/dist/runtime/host-load-governor-config.js +83 -0
- package/dist/runtime/host-load-governor.d.ts +186 -0
- package/dist/runtime/host-load-governor.js +632 -0
- package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
- package/dist/runtime/host-load-ledger-lock.js +187 -0
- 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 +156 -0
- package/dist/runtime/host-load-sampler.js +298 -0
- package/dist/runtime/host-load-step-class.d.ts +70 -0
- package/dist/runtime/host-load-step-class.js +161 -0
- package/dist/runtime/host-load-step-reaper.d.ts +27 -0
- package/dist/runtime/host-load-step-reaper.js +95 -0
- package/dist/runtime/host-load-step-run.d.ts +73 -0
- package/dist/runtime/host-load-step-run.js +102 -0
- 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 +200 -0
- package/dist/runtime/host-load-token-ledger.js +453 -0
- 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-pressure-stall.d.ts +61 -0
- package/dist/runtime/host-pressure-stall.js +168 -0
- package/dist/runtime/host-runtime-contract.d.ts +16 -0
- package/dist/runtime/host-runtime-contract.js +35 -2
- package/dist/runtime/host-runtime-lease.d.ts +77 -5
- package/dist/runtime/host-runtime-lease.js +328 -136
- 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 +48 -0
- package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
- package/dist/runtime/host-runtime-requirements-check.js +29 -0
- package/dist/runtime/host-runtime-requirements.d.ts +36 -0
- package/dist/runtime/host-runtime-requirements.js +117 -0
- package/dist/runtime/managed-command-teardown.d.ts +62 -0
- package/dist/runtime/managed-command-teardown.js +596 -0
- 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-browser-cache.d.ts +39 -0
- package/dist/runtime/playwright-browser-cache.js +227 -0
- package/dist/runtime/playwright-host-runtime-adapter.d.ts +18 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +61 -55
- 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 +115 -0
- package/dist/sandbox/host-capacity-broker.js +336 -0
- 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.d.ts +10 -1
- package/dist/sandbox/runtime.js +47 -8
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -0
- 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 +27 -7
- package/dist/session/managed-attempt-tools.js +406 -123
- package/dist/session/managed-build-coordinator.d.ts +17 -1
- package/dist/session/managed-build-coordinator.js +14 -1
- 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 +47 -0
- package/dist/session/managed-command-host-load.js +83 -0
- 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 +100 -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 +12 -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 +5 -11
- package/dist/session/phase-completion.runtime.js +111 -230
- 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-host-load.d.ts +27 -0
- package/dist/session/pre-publication-host-load.js +111 -0
- 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.d.ts +23 -0
- package/dist/session/pre-publication-process.js +109 -0
- package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
- package/dist/session/pre-publication-skipped-tests.js +109 -0
- package/dist/session/pre-publication-step-execution.d.ts +12 -0
- package/dist/session/pre-publication-step-execution.js +50 -0
- package/dist/session/pre-publication-validation.d.ts +37 -21
- package/dist/session/pre-publication-validation.js +228 -219
- 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.artifacts.d.ts +2 -1
- package/dist/session/provider-cli/provider-cli.artifacts.js +21 -15
- 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.merge-integrity.d.ts +89 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +46 -31
- package/dist/session/provider-cli/provider-cli.process.js +286 -403
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +87 -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 +207 -192
- package/dist/session/provider-cli/provider-cli.types.d.ts +30 -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 +10 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +92 -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 +8 -0
- package/dist/session/provider-cli/provider-output-state.js +15 -0
- package/dist/session/provider-cli/provider-usage.d.ts +2 -1
- 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/publishable-worktree-changes.d.ts +54 -0
- package/dist/session/publishable-worktree-changes.js +193 -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 +51 -0
- package/dist/session/sandbox-host-capacity-gate.js +257 -0
- package/dist/session/session-redaction.js +31 -181
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.service.d.ts +11 -2
- package/dist/session/session.service.js +189 -69
- package/dist/session/session.types.d.ts +3 -0
- package/dist/session/session.types.js +15 -3
- 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 +14 -1
- package/dist/shared/process/host-process-supervisor.js +67 -15
- package/dist/shared/process/process-tree.d.ts +52 -0
- package/dist/shared/process/process-tree.js +144 -0
- package/dist/shared/process/process.d.ts +67 -0
- package/dist/shared/process/process.js +213 -11
- 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/dependency-warmer.d.ts +25 -0
- package/dist/worktree/dependency-warmer.js +120 -10
- 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 +36 -5
- package/dist/worktree/worktree.service.js +124 -155
- package/dist/worktree/worktree.types.d.ts +38 -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,15 +18,20 @@ 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;
|
|
30
29
|
pairRunner;
|
|
31
30
|
cleanupFactory;
|
|
32
31
|
dotNetToolchainConfigurator;
|
|
33
|
-
constructor(
|
|
32
|
+
constructor(
|
|
33
|
+
// In a Docker sandbox the default chain's validator asks the host bridge for host load tokens (decision 0013).
|
|
34
|
+
sessions = new BridgeSessionService(), bridgeFactory = (config) => new ForgeBridgeService(config), pairRunner = claimBridgeRunner, cleanupFactory = stateRoot => new ManagedWorktreeCleanupService(stateRoot), dotNetToolchainConfigurator = configureDotNetToolchain) {
|
|
34
35
|
this.sessions = sessions;
|
|
35
36
|
this.bridgeFactory = bridgeFactory;
|
|
36
37
|
this.pairRunner = pairRunner;
|
|
@@ -89,11 +90,22 @@ export class ForgeBridgeCliService {
|
|
|
89
90
|
if (config.cleanupWorktrees && config.repoMappings.some(mapping => mapping.localPath?.trim())) {
|
|
90
91
|
io.stdout.write("Cleaning stale managed worktrees before accepting dispatches.\n");
|
|
91
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);
|
|
92
95
|
}
|
|
93
96
|
io.stdout.write(connectStartupText(config));
|
|
94
97
|
await this.bridgeFactory(config).run(controller.signal);
|
|
95
98
|
return 0;
|
|
96
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
|
+
}
|
|
97
109
|
finally {
|
|
98
110
|
process.off("SIGINT", stop);
|
|
99
111
|
process.off("SIGTERM", stop);
|
|
@@ -117,13 +129,22 @@ export class ForgeBridgeCliService {
|
|
|
117
129
|
const current = readLocalConfigSync();
|
|
118
130
|
io.stdout.write(`Pairing with server: ${args.serverUrl}\n`);
|
|
119
131
|
const code = await resolvePairingCode(args.code);
|
|
120
|
-
const
|
|
121
|
-
await
|
|
122
|
-
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 });
|
|
123
134
|
const claim = await this.pairRunner(pairArgs);
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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`);
|
|
127
148
|
io.stdout.write(`Repo folder: ${repoRoot}\n`);
|
|
128
149
|
io.stdout.write(`Config: ${resolveLocalConfigPath()}\n`);
|
|
129
150
|
io.stdout.write("Start the bridge with: forge-bridge connect\n");
|
|
@@ -172,8 +193,7 @@ export class ForgeBridgeCliService {
|
|
|
172
193
|
}
|
|
173
194
|
}
|
|
174
195
|
if (args.command === "status") {
|
|
175
|
-
await
|
|
176
|
-
return 0;
|
|
196
|
+
return await runStatus(args, io);
|
|
177
197
|
}
|
|
178
198
|
if (args.command === "cleanup") {
|
|
179
199
|
return await cleanupRepos(args.config, args.mode, args.force, this.cleanupFactory(args.config.sandboxStateRoot), io);
|
|
@@ -206,6 +226,9 @@ export class ForgeBridgeCliService {
|
|
|
206
226
|
writeSandboxPolicyStatus(readLocalConfigSync(), io);
|
|
207
227
|
return 0;
|
|
208
228
|
}
|
|
229
|
+
if (args.command === "yield") {
|
|
230
|
+
return await runYieldCommand(args.action, io);
|
|
231
|
+
}
|
|
209
232
|
if (args.command === "mcp") {
|
|
210
233
|
const parsed = parseCompletionMcpArgs(args.argv);
|
|
211
234
|
if (!parsed.ok) {
|
|
@@ -243,6 +266,36 @@ export class ForgeBridgeCliService {
|
|
|
243
266
|
}
|
|
244
267
|
}
|
|
245
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
|
+
}
|
|
246
299
|
function attachEnvSecretGrant(dispatch) {
|
|
247
300
|
if (!dispatch.execution.requiresApiKeySecretGrant) {
|
|
248
301
|
delete process.env[apiKeySecretGrantEnv];
|
|
@@ -325,17 +378,7 @@ export function parseArgs(argv) {
|
|
|
325
378
|
return { ok: false, error: "Usage: forge-bridge server <show|set <url>>" };
|
|
326
379
|
}
|
|
327
380
|
if (argv[0] === "status") {
|
|
328
|
-
|
|
329
|
-
for (let index = 1; index < argv.length; index += 1) {
|
|
330
|
-
const arg = argv[index];
|
|
331
|
-
if (arg === "--check-updates") {
|
|
332
|
-
checkUpdates = true;
|
|
333
|
-
}
|
|
334
|
-
else {
|
|
335
|
-
return { ok: false, error: `Unknown argument: ${arg}` };
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
return { ok: true, command: "status", config: configuredBridgeServiceConfig(), checkUpdates };
|
|
381
|
+
return parseStatusArgs(argv, configuredBridgeServiceConfig);
|
|
339
382
|
}
|
|
340
383
|
if (argv[0] === "cleanup") {
|
|
341
384
|
return parseCleanupArgs(argv);
|
|
@@ -346,6 +389,13 @@ export function parseArgs(argv) {
|
|
|
346
389
|
if (argv[0] === "sandbox") {
|
|
347
390
|
return parseSandboxArgs(argv);
|
|
348
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
|
+
}
|
|
349
399
|
if (argv[0] !== "run-once") {
|
|
350
400
|
return {
|
|
351
401
|
ok: false,
|
|
@@ -759,6 +809,7 @@ function parsePairArgs(argv) {
|
|
|
759
809
|
repoRoot: repoRoot?.trim() ? path.resolve(repoRoot) : undefined,
|
|
760
810
|
cleanupWorktrees: cleanupWorktrees ?? defaultConfig.cleanupWorktrees,
|
|
761
811
|
cliProviders: cliProviders.length > 0 ? cliProviders : localConfig.cliProviders && localConfig.cliProviders.length > 0 ? [...localConfig.cliProviders] : ["codex"],
|
|
812
|
+
cliProvidersFromFlag: cliProviders.length > 0,
|
|
762
813
|
projectLabels: projectLabels.length > 0 ? projectLabels : localConfig.projectLabels ? [...localConfig.projectLabels] : []
|
|
763
814
|
};
|
|
764
815
|
}
|
|
@@ -821,9 +872,71 @@ async function claimBridgeRunner(args) {
|
|
|
821
872
|
}
|
|
822
873
|
return {
|
|
823
874
|
runnerId: value.runnerId,
|
|
824
|
-
deviceToken: value.deviceToken
|
|
875
|
+
deviceToken: value.deviceToken,
|
|
876
|
+
host: parsePairRunnerHost(value.host)
|
|
825
877
|
};
|
|
826
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
|
+
}
|
|
827
940
|
function pairedConfig(current, args, claim) {
|
|
828
941
|
return {
|
|
829
942
|
...current,
|
|
@@ -868,11 +981,7 @@ async function resolvePairingCode(code) {
|
|
|
868
981
|
prompt.close();
|
|
869
982
|
}
|
|
870
983
|
}
|
|
871
|
-
async function
|
|
872
|
-
const fallback = path.resolve(repoRoot ?? configuredRoot ?? path.join(os.homedir(), "ForgeRepos"));
|
|
873
|
-
if (repoRoot?.trim()) {
|
|
874
|
-
return fallback;
|
|
875
|
-
}
|
|
984
|
+
async function promptPairRepoRoot(fallback) {
|
|
876
985
|
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
877
986
|
return fallback;
|
|
878
987
|
}
|
|
@@ -943,6 +1052,9 @@ async function writeJsonAtomic(outputPath, value) {
|
|
|
943
1052
|
await fs.writeFile(tempPath, `${JSON.stringify(value, null, 2)}\n`, "utf8");
|
|
944
1053
|
await fs.rename(tempPath, outputPath);
|
|
945
1054
|
}
|
|
1055
|
+
async function runStatus(args, io) {
|
|
1056
|
+
return args.idle ? await runIdleStatusCommand(args.idle, io) : await writeStatus(args.config, args.checkUpdates, io);
|
|
1057
|
+
}
|
|
946
1058
|
async function writeStatus(config, checkUpdates, io) {
|
|
947
1059
|
const detected = await detectCliProviders([...new Set([...config.cliProviders, "codex", "cursor", "claude"])]);
|
|
948
1060
|
const repos = config.repoMappings.filter((mapping) => mapping.localPath?.trim());
|
|
@@ -951,7 +1063,7 @@ async function writeStatus(config, checkUpdates, io) {
|
|
|
951
1063
|
io.stdout.write(`Server: ${config.serverUrl || "not configured"}\n`);
|
|
952
1064
|
io.stdout.write(`Device: ${config.runnerId || "not configured"}${config.deviceName ? ` (${config.deviceName})` : ""}\n`);
|
|
953
1065
|
io.stdout.write(`Device token: ${config.deviceToken ? "configured" : "missing"}\n`);
|
|
954
|
-
io.stdout.write(
|
|
1066
|
+
io.stdout.write(`${await idleSummaryLine()}\n`);
|
|
955
1067
|
io.stdout.write("Repos:\n");
|
|
956
1068
|
if (repos.length === 0) {
|
|
957
1069
|
io.stdout.write(" none\n");
|
|
@@ -969,6 +1081,7 @@ async function writeStatus(config, checkUpdates, io) {
|
|
|
969
1081
|
if (checkUpdates) {
|
|
970
1082
|
io.stdout.write("Update check: no update channel configured.\n");
|
|
971
1083
|
}
|
|
1084
|
+
return 0;
|
|
972
1085
|
}
|
|
973
1086
|
async function cleanupRepos(config, mode, force, cleanup, io) {
|
|
974
1087
|
const repos = config.repoMappings.filter((mapping) => mapping.localPath?.trim());
|
|
@@ -1001,7 +1114,11 @@ async function cleanupRepos(config, mode, force, cleanup, io) {
|
|
|
1001
1114
|
io.stdout.write(`Removed ${result.removedWorktrees} stale managed ${result.removedWorktrees === 1 ? "worktree" : "worktrees"} from ${result.worktreeRoot}\n`);
|
|
1002
1115
|
}
|
|
1003
1116
|
else {
|
|
1004
|
-
|
|
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
|
+
}
|
|
1005
1122
|
}
|
|
1006
1123
|
}
|
|
1007
1124
|
catch (error) {
|
|
@@ -1011,158 +1128,6 @@ async function cleanupRepos(config, mode, force, cleanup, io) {
|
|
|
1011
1128
|
}
|
|
1012
1129
|
return failures === 0 ? 0 : 1;
|
|
1013
1130
|
}
|
|
1014
|
-
async function detectCliProviders(providers) {
|
|
1015
|
-
const results = [];
|
|
1016
|
-
for (const provider of providers) {
|
|
1017
|
-
let detected = null;
|
|
1018
|
-
for (const probe of cliProbeCommandsFor(provider)) {
|
|
1019
|
-
try {
|
|
1020
|
-
detected = await execVersionCommand(probe, probe.timeoutMs);
|
|
1021
|
-
break;
|
|
1022
|
-
}
|
|
1023
|
-
catch {
|
|
1024
|
-
// Try the next provider-specific probe.
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
results.push({
|
|
1028
|
-
provider,
|
|
1029
|
-
found: detected !== null,
|
|
1030
|
-
version: detected ? versionLine(`${detected.stdout || detected.stderr}`) : "",
|
|
1031
|
-
models: detected ? await detectCliModels(provider) : []
|
|
1032
|
-
});
|
|
1033
|
-
}
|
|
1034
|
-
return results;
|
|
1035
|
-
}
|
|
1036
|
-
function cliProbeCommandsFor(provider) {
|
|
1037
|
-
const normalized = provider.toLowerCase();
|
|
1038
|
-
if (normalized === "codex") {
|
|
1039
|
-
return [
|
|
1040
|
-
{ command: "codex", args: ["-V"] },
|
|
1041
|
-
{ command: "codex", args: ["--version"] }
|
|
1042
|
-
];
|
|
1043
|
-
}
|
|
1044
|
-
if (normalized === "claude") {
|
|
1045
|
-
return [
|
|
1046
|
-
// Claude Code's Node startup can exceed the default 2s probe on a cold Windows host.
|
|
1047
|
-
{ command: "claude", args: ["--version"], timeoutMs: 8000 },
|
|
1048
|
-
{ command: "claude", args: ["-v"], timeoutMs: 8000 }
|
|
1049
|
-
];
|
|
1050
|
-
}
|
|
1051
|
-
if (normalized === "cursor") {
|
|
1052
|
-
return [
|
|
1053
|
-
{ command: "cursor-agent", args: ["-v"] },
|
|
1054
|
-
{ command: "agent", args: ["-v"] },
|
|
1055
|
-
{ command: "cursor-agent", args: ["--version"] },
|
|
1056
|
-
{ command: "agent", args: ["--version"] }
|
|
1057
|
-
];
|
|
1058
|
-
}
|
|
1059
|
-
return [
|
|
1060
|
-
{ command: provider, args: ["--version"] },
|
|
1061
|
-
{ command: provider, args: ["-V"] }
|
|
1062
|
-
];
|
|
1063
|
-
}
|
|
1064
|
-
async function execVersionCommand(probe, timeout = 2000, maxBuffer) {
|
|
1065
|
-
const directLaunch = process.platform === "win32"
|
|
1066
|
-
? await resolveCursorAgentDirectLaunch(probe.command, probe.args)
|
|
1067
|
-
: null;
|
|
1068
|
-
if (directLaunch) {
|
|
1069
|
-
return await execFileAsync(directLaunch.command, [...directLaunch.args], { timeout, maxBuffer });
|
|
1070
|
-
}
|
|
1071
|
-
try {
|
|
1072
|
-
return await execFileAsync(probe.command, probe.args, { timeout, maxBuffer });
|
|
1073
|
-
}
|
|
1074
|
-
catch (error) {
|
|
1075
|
-
if (process.platform !== "win32") {
|
|
1076
|
-
throw error;
|
|
1077
|
-
}
|
|
1078
|
-
const launch = buildWindowsCmdLaunch(probe.command, probe.args);
|
|
1079
|
-
return await execFileAsync(launch.command, [...launch.args], { timeout, maxBuffer });
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
function versionLine(output) {
|
|
1083
|
-
const lines = output
|
|
1084
|
-
.trim()
|
|
1085
|
-
.split(/\r?\n/)
|
|
1086
|
-
.map((line) => line.trim())
|
|
1087
|
-
.filter((line) => line.length > 0);
|
|
1088
|
-
return lines.at(-1) ?? "";
|
|
1089
|
-
}
|
|
1090
|
-
async function detectCliModels(provider) {
|
|
1091
|
-
const normalized = provider.toLowerCase();
|
|
1092
|
-
try {
|
|
1093
|
-
if (normalized === "codex") {
|
|
1094
|
-
// Windows installs codex as a .cmd shim, which execFile cannot launch directly.
|
|
1095
|
-
const result = await execVersionCommand({ command: "codex", args: ["debug", "models"] }, 10_000, 10 * 1024 * 1024);
|
|
1096
|
-
return parseCodexModelCatalog(result.stdout);
|
|
1097
|
-
}
|
|
1098
|
-
if (normalized === "cursor") {
|
|
1099
|
-
const result = await execVersionCommand({ command: "cursor-agent", args: ["models"] }, 10_000);
|
|
1100
|
-
return parseCursorModelList(`${result.stdout || result.stderr}`);
|
|
1101
|
-
}
|
|
1102
|
-
if (normalized === "claude") {
|
|
1103
|
-
// Claude Code has no model-listing command; it accepts these aliases and full model IDs.
|
|
1104
|
-
const configured = splitCsv(process.env.FORGE_CLAUDE_MODELS ?? "");
|
|
1105
|
-
return configured.length > 0 ? configured : [...claudeDefaultModels];
|
|
1106
|
-
}
|
|
1107
|
-
}
|
|
1108
|
-
catch {
|
|
1109
|
-
return [];
|
|
1110
|
-
}
|
|
1111
|
-
return [];
|
|
1112
|
-
}
|
|
1113
|
-
export const claudeDefaultModels = ["sonnet", "opus", "haiku"];
|
|
1114
|
-
export function parseCodexModelCatalog(raw) {
|
|
1115
|
-
try {
|
|
1116
|
-
const parsed = JSON.parse(raw);
|
|
1117
|
-
if (!isRecord(parsed) || !Array.isArray(parsed.models)) {
|
|
1118
|
-
return [];
|
|
1119
|
-
}
|
|
1120
|
-
const entries = parsed.models
|
|
1121
|
-
.map((entry, index) => {
|
|
1122
|
-
if (!isRecord(entry) || typeof entry.slug !== "string") {
|
|
1123
|
-
return null;
|
|
1124
|
-
}
|
|
1125
|
-
const visibility = typeof entry.visibility === "string" ? entry.visibility.toLowerCase() : "list";
|
|
1126
|
-
if (visibility !== "list") {
|
|
1127
|
-
return null;
|
|
1128
|
-
}
|
|
1129
|
-
const priority = typeof entry.priority === "number" && Number.isFinite(entry.priority) ? entry.priority : index;
|
|
1130
|
-
return { slug: entry.slug, priority, index };
|
|
1131
|
-
})
|
|
1132
|
-
.filter((entry) => entry !== null)
|
|
1133
|
-
.sort((left, right) => left.priority - right.priority || left.index - right.index)
|
|
1134
|
-
.map((entry) => entry.slug);
|
|
1135
|
-
return uniqueModels(entries);
|
|
1136
|
-
}
|
|
1137
|
-
catch {
|
|
1138
|
-
return [];
|
|
1139
|
-
}
|
|
1140
|
-
}
|
|
1141
|
-
export function parseCursorModelList(raw) {
|
|
1142
|
-
return uniqueModels(raw
|
|
1143
|
-
.split(/\r?\n/)
|
|
1144
|
-
.map((line) => line.trim())
|
|
1145
|
-
.filter((line) => line.length > 0 && !line.toLowerCase().startsWith("available models"))
|
|
1146
|
-
.map((line) => line.split(/\s+-\s+/, 1)[0]?.trim() ?? "")
|
|
1147
|
-
.filter((model) => model.length > 0));
|
|
1148
|
-
}
|
|
1149
|
-
function uniqueModels(models) {
|
|
1150
|
-
const seen = new Set();
|
|
1151
|
-
const result = [];
|
|
1152
|
-
for (const model of models) {
|
|
1153
|
-
const trimmed = model.trim();
|
|
1154
|
-
const key = trimmed.toLowerCase();
|
|
1155
|
-
if (!trimmed || seen.has(key)) {
|
|
1156
|
-
continue;
|
|
1157
|
-
}
|
|
1158
|
-
seen.add(key);
|
|
1159
|
-
result.push(trimmed);
|
|
1160
|
-
}
|
|
1161
|
-
return result;
|
|
1162
|
-
}
|
|
1163
|
-
function isRecord(value) {
|
|
1164
|
-
return typeof value === "object" && value !== null;
|
|
1165
|
-
}
|
|
1166
1131
|
async function withDetectedCliProviders(config, candidates = config.cliProviders) {
|
|
1167
1132
|
const detected = await detectCliProviders(uniqueProviders(candidates));
|
|
1168
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
|
+
};
|