@loucompanion/forge-bridge 0.1.4-dev.fb770705136a → 0.2.1-dev.0f07274d438b
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 +183 -4
- package/dist/bridge/bridge-chat-giphy-look.d.ts +48 -0
- package/dist/bridge/bridge-chat-giphy-look.js +55 -0
- package/dist/bridge/bridge-chat-provider-command.d.ts +40 -0
- package/dist/bridge/bridge-chat-provider-command.js +230 -0
- package/dist/bridge/bridge-chat.types.d.ts +20 -0
- package/dist/bridge/bridge-chat.types.js +28 -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 +15 -0
- package/dist/bridge/bridge-state-io.js +68 -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 +102 -14
- package/dist/bridge/bridge.service.js +499 -471
- package/dist/bridge/bridge.types.d.ts +37 -0
- package/dist/bridge/bridge.types.js +2 -1
- package/dist/bridge/default-session-service.d.ts +13 -0
- package/dist/bridge/default-session-service.js +22 -0
- package/dist/bridge/dispatch-offer-policy.d.ts +22 -0
- package/dist/bridge/dispatch-offer-policy.js +58 -0
- package/dist/bridge/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 +31 -1
- 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/bridge/windows-bash-resolution.d.ts +31 -0
- package/dist/bridge/windows-bash-resolution.js +153 -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 +11 -0
- package/dist/cleanup/forge-owned-paths.js +62 -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 +75 -13
- package/dist/cli/cli.service.d.ts +19 -10
- package/dist/cli/cli.service.js +161 -228
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +18 -1
- package/dist/cli/local-config.js +67 -5
- package/dist/cli/provider-cli-advertising.d.ts +24 -0
- package/dist/cli/provider-cli-advertising.js +88 -0
- 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.d.ts +36 -0
- package/dist/runtime/attempt-node-runtime-launcher.js +169 -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-listener-inspector.d.ts +26 -0
- package/dist/runtime/host-listener-inspector.js +84 -3
- package/dist/runtime/host-load-admission.d.ts +72 -0
- package/dist/runtime/host-load-admission.js +99 -0
- package/dist/runtime/host-load-capacity.d.ts +198 -0
- package/dist/runtime/host-load-capacity.js +353 -0
- package/dist/runtime/host-load-child-environment.d.ts +40 -0
- package/dist/runtime/host-load-child-environment.js +110 -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 +82 -0
- package/dist/runtime/host-load-governor-config.js +104 -0
- package/dist/runtime/host-load-governor.d.ts +273 -0
- package/dist/runtime/host-load-governor.js +831 -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-live-test-slots.d.ts +61 -0
- package/dist/runtime/host-load-live-test-slots.js +193 -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 +92 -2
- package/dist/runtime/host-load-sampler.js +166 -8
- 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 +107 -0
- package/dist/runtime/host-load-step-run.js +158 -0
- package/dist/runtime/host-load-test-slot.d.ts +46 -0
- package/dist/runtime/host-load-test-slot.js +100 -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 +21 -1
- package/dist/runtime/host-pressure-stall.js +48 -1
- package/dist/runtime/host-runtime-contract.d.ts +15 -0
- package/dist/runtime/host-runtime-contract.js +39 -6
- package/dist/runtime/host-runtime-lease.d.ts +101 -6
- package/dist/runtime/host-runtime-lease.js +408 -294
- 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 +101 -2
- package/dist/runtime/host-runtime-promotion.js +355 -14
- 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.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/prepared-runtime-identity.d.ts +4 -0
- package/dist/runtime/prepared-runtime-identity.js +130 -9
- package/dist/runtime/prepared-runtime-readiness.d.ts +23 -1
- package/dist/runtime/prepared-runtime-readiness.js +89 -18
- 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 +11 -3
- package/dist/sandbox/runtime.js +53 -20
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -0
- package/dist/sandbox/sandbox-input.d.ts +22 -0
- package/dist/sandbox/sandbox-input.js +49 -0
- package/dist/sandbox/workspace.service.js +15 -2
- package/dist/session/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 +204 -141
- 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 +7 -0
- package/dist/session/managed-build-receipt.js +11 -3
- package/dist/session/managed-command-environment.d.ts +8 -0
- package/dist/session/managed-command-environment.js +28 -0
- package/dist/session/managed-command-host-load.d.ts +52 -0
- package/dist/session/managed-command-host-load.js +87 -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.artifact-bundle.d.ts +20 -0
- package/dist/session/phase-completion.artifact-bundle.js +167 -0
- package/dist/session/phase-completion.artifacts.d.ts +9 -17
- package/dist/session/phase-completion.artifacts.js +158 -190
- 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 +31 -2
- package/dist/session/phase-completion.helpers.js +18 -65
- package/dist/session/phase-completion.js +19 -32
- package/dist/session/phase-completion.mcp-args.d.ts +9 -0
- package/dist/session/phase-completion.mcp-args.js +195 -0
- package/dist/session/phase-completion.phase-aliases.d.ts +5 -0
- package/dist/session/phase-completion.phase-aliases.js +43 -0
- package/dist/session/phase-completion.pr-review-schema.d.ts +1 -0
- package/dist/session/phase-completion.pr-review-schema.js +75 -0
- package/dist/session/phase-completion.pr-review-validation.d.ts +11 -0
- package/dist/session/phase-completion.pr-review-validation.js +212 -0
- package/dist/session/phase-completion.pr-review.d.ts +36 -0
- package/dist/session/phase-completion.pr-review.js +294 -0
- package/dist/session/phase-completion.prompts.d.ts +1 -1
- package/dist/session/phase-completion.prompts.js +20 -1
- package/dist/session/phase-completion.runtime.d.ts +13 -12
- package/dist/session/phase-completion.runtime.js +113 -214
- 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 +219 -232
- package/dist/session/phase-completion.validation.d.ts +3 -3
- package/dist/session/phase-completion.validation.js +58 -94
- package/dist/session/pr-review-diff-base.d.ts +18 -0
- package/dist/session/pr-review-diff-base.js +44 -0
- package/dist/session/pr-review-placement.d.ts +50 -0
- package/dist/session/pr-review-placement.js +91 -0
- package/dist/session/pre-publication-change-set.d.ts +62 -0
- package/dist/session/pre-publication-change-set.js +166 -0
- package/dist/session/pre-publication-host-load.d.ts +27 -0
- package/dist/session/pre-publication-host-load.js +112 -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 +3 -0
- package/dist/session/pre-publication-process.js +32 -19
- 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 +39 -22
- package/dist/session/pre-publication-validation.js +241 -207
- 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/dispatch-target-branch.d.ts +7 -0
- package/dist/session/provider-cli/dispatch-target-branch.js +8 -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/pr-review-credential-isolation.d.ts +83 -0
- package/dist/session/provider-cli/pr-review-credential-isolation.js +144 -0
- package/dist/session/provider-cli/pr-review-guardrails.d.ts +70 -0
- package/dist/session/provider-cli/pr-review-guardrails.js +360 -0
- package/dist/session/provider-cli/pr-review-prompt.d.ts +2 -0
- package/dist/session/provider-cli/pr-review-prompt.js +119 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
- package/dist/session/provider-cli/pre-publication-repair.js +281 -0
- package/dist/session/provider-cli/provider-cli.base.d.ts +1 -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.deterministic.d.ts +1 -0
- package/dist/session/provider-cli/provider-cli.deterministic.js +5 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +6 -3
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +29 -10
- package/dist/session/provider-cli/provider-cli.pr-review.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.pr-review.js +213 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +15 -36
- package/dist/session/provider-cli/provider-cli.process.js +41 -432
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +15 -3
- package/dist/session/provider-cli/provider-cli.prompts.js +183 -90
- package/dist/session/provider-cli/provider-cli.reapply-conflicts.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.reapply-conflicts.js +37 -0
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +15 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +43 -1
- package/dist/session/provider-cli/provider-cli.service-support.d.ts +37 -0
- package/dist/session/provider-cli/provider-cli.service-support.js +146 -0
- package/dist/session/provider-cli/provider-cli.service.d.ts +18 -18
- package/dist/session/provider-cli/provider-cli.service.js +127 -317
- package/dist/session/provider-cli/provider-cli.types.d.ts +35 -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 +51 -0
- package/dist/session/sandbox-host-capacity-gate.js +279 -0
- package/dist/session/session-host-project.d.ts +22 -0
- package/dist/session/session-host-project.js +98 -0
- package/dist/session/session-redaction.js +31 -181
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.parse-helpers.d.ts +10 -0
- package/dist/session/session.parse-helpers.js +84 -0
- package/dist/session/session.runtime-refresh.d.ts +46 -0
- package/dist/session/session.runtime-refresh.js +116 -0
- package/dist/session/session.service.d.ts +16 -2
- package/dist/session/session.service.js +208 -155
- package/dist/session/session.types.d.ts +8 -0
- package/dist/session/session.types.js +13 -83
- package/dist/session/session.types.pr-review.d.ts +48 -0
- package/dist/session/session.types.pr-review.js +51 -0
- 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.d.ts +2 -0
- package/dist/shared/provider-capabilities.js +23 -7
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/artifact-injector.js +24 -0
- package/dist/worktree/dependency-warmer.d.ts +25 -0
- package/dist/worktree/dependency-warmer.js +46 -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 +58 -0
- package/dist/worktree/wip-git.js +182 -0
- package/dist/worktree/wip-refs.d.ts +85 -0
- package/dist/worktree/wip-refs.js +169 -0
- package/dist/worktree/wip-restore.d.ts +51 -0
- package/dist/worktree/wip-restore.js +324 -0
- package/dist/worktree/wip-snapshot.d.ts +53 -0
- package/dist/worktree/wip-snapshot.js +270 -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 +35 -0
- package/dist/worktree/worktree-origin-sync.js +128 -0
- package/dist/worktree/worktree-wip-events.d.ts +20 -0
- package/dist/worktree/worktree-wip-events.js +148 -0
- package/dist/worktree/worktree-wip.d.ts +57 -0
- package/dist/worktree/worktree-wip.js +200 -0
- package/dist/worktree/worktree.base.d.ts +7 -1
- package/dist/worktree/worktree.service.d.ts +58 -5
- package/dist/worktree/worktree.service.js +237 -161
- package/dist/worktree/worktree.types.d.ts +54 -0
- package/package.json +2 -2
- package/runtime/windows-listener-owner.ps1 +12 -1
package/dist/cli/cli.service.js
CHANGED
|
@@ -1,19 +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
|
-
import { supportsDraftImageAttachmentsFor } from "../shared/provider-capabilities.js";
|
|
11
6
|
import { redactText } from "../shared/redaction/redaction.js";
|
|
12
|
-
import { defaultBridgeServiceConfig, ForgeBridgeService } from "../bridge/bridge.service.js";
|
|
7
|
+
import { BridgeRevokedError, bridgeRevokedExitCode, defaultBridgeServiceConfig, ForgeBridgeService, } from "../bridge/bridge.service.js";
|
|
13
8
|
import { forgeBridgeVersion } from "../version.js";
|
|
14
9
|
import { ManagedWorktreeCleanupService } from "../cleanup/cleanup.service.js";
|
|
15
|
-
import { addRepoMapping, applyLocalConfigDefaults, providerStatusesFor, readLocalConfigSync, removeRepoMapping, resolveLocalConfigPath, setSandboxPolicy, setServerUrl, writeLocalConfig } from "./local-config.js";
|
|
16
|
-
import { BridgeSessionService } from "../session/session.service.js";
|
|
10
|
+
import { addRepoMapping, applyLocalConfigDefaults, pairDerivedCapabilities, providerStatusesFor, readLocalConfigSync, removeRepoMapping, resolveLocalConfigPath, resolveLocalYieldFlagPath, setSandboxPolicy, setServerUrl, writeLocalConfig } from "./local-config.js";
|
|
11
|
+
import { BridgeSessionService, runOnceWithReviewPlacement } from "../session/session.service.js";
|
|
17
12
|
import { redactRunnerDispatchEvent, redactRunOnceResultPacket } from "../session/session-redaction.js";
|
|
18
13
|
import { validateDockerfilePolicy, validateSandboxContract } from "../sandbox/contract.js";
|
|
19
14
|
import { DockerPreflight } from "../sandbox/preflight.js";
|
|
@@ -22,15 +17,20 @@ import { DockerSandboxSmoke } from "../sandbox/smoke.js";
|
|
|
22
17
|
import { parseCompletionMcpArgs, runCompletionMcpServer } from "../session/phase-completion.js";
|
|
23
18
|
import { failureFactsFromError, failureResult, parseRunOnceDispatchPacket } from "../session/session.types.js";
|
|
24
19
|
import { commandHelpText, helpText } from "./cli.help.js";
|
|
20
|
+
import { readLocalYieldFlag, writeLocalYieldFlag } from "../bridge/local-yield-flag.js";
|
|
21
|
+
import { detectKnownCliProviders, knownProviderCandidates, withDetectedCliProviders } from "./provider-cli-advertising.js";
|
|
22
|
+
import { idleSummaryLine, parseStatusArgs, runIdleStatusCommand } from "./idle-status.js";
|
|
23
|
+
export { claudeDefaultModels, parseCodexModelCatalog, parseCursorModelList } from "./provider-cli-detection.js";
|
|
25
24
|
const apiKeySecretGrantEnv = "FORGE_API_KEY_SECRET_GRANT";
|
|
26
|
-
const execFileAsync = promisify(execFile);
|
|
27
25
|
export class ForgeBridgeCliService {
|
|
28
26
|
sessions;
|
|
29
27
|
bridgeFactory;
|
|
30
28
|
pairRunner;
|
|
31
29
|
cleanupFactory;
|
|
32
30
|
dotNetToolchainConfigurator;
|
|
33
|
-
constructor(
|
|
31
|
+
constructor(
|
|
32
|
+
// In a Docker sandbox the default chain's validator asks the host bridge for host load tokens (decision 0013).
|
|
33
|
+
sessions = new BridgeSessionService(), bridgeFactory = (config) => new ForgeBridgeService(config), pairRunner = claimBridgeRunner, cleanupFactory = stateRoot => new ManagedWorktreeCleanupService(stateRoot), dotNetToolchainConfigurator = configureDotNetToolchain) {
|
|
34
34
|
this.sessions = sessions;
|
|
35
35
|
this.bridgeFactory = bridgeFactory;
|
|
36
36
|
this.pairRunner = pairRunner;
|
|
@@ -60,7 +60,9 @@ export class ForgeBridgeCliService {
|
|
|
60
60
|
return 2;
|
|
61
61
|
}
|
|
62
62
|
if (args.command === "connect") {
|
|
63
|
-
|
|
63
|
+
// Probe every known provider CLI, not only the configured ones, so a CLI installed after
|
|
64
|
+
// pairing gets advertised.
|
|
65
|
+
const config = await withDetectedCliProviders(args.config, knownProviderCandidates(args.config.cliProviders));
|
|
64
66
|
const missing = [
|
|
65
67
|
["server", config.serverUrl],
|
|
66
68
|
["runner id", config.runnerId],
|
|
@@ -89,11 +91,22 @@ export class ForgeBridgeCliService {
|
|
|
89
91
|
if (config.cleanupWorktrees && config.repoMappings.some(mapping => mapping.localPath?.trim())) {
|
|
90
92
|
io.stdout.write("Cleaning stale managed worktrees before accepting dispatches.\n");
|
|
91
93
|
await cleanupRepos(config, "stale", true, this.cleanupFactory(config.sandboxStateRoot), io);
|
|
94
|
+
// Forge branches on this device whose work has merged since the bridge last ran.
|
|
95
|
+
await cleanupRepos(config, "merged", true, this.cleanupFactory(config.sandboxStateRoot), io);
|
|
92
96
|
}
|
|
93
97
|
io.stdout.write(connectStartupText(config));
|
|
94
98
|
await this.bridgeFactory(config).run(controller.signal);
|
|
95
99
|
return 0;
|
|
96
100
|
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
if (error instanceof BridgeRevokedError) {
|
|
103
|
+
// Decision 0014: removed from Forge. Exit with a distinct code so a supervisor can
|
|
104
|
+
// tell "pair again" apart from a crash.
|
|
105
|
+
io.stderr.write(`${error.message}\n`);
|
|
106
|
+
return bridgeRevokedExitCode;
|
|
107
|
+
}
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
97
110
|
finally {
|
|
98
111
|
process.off("SIGINT", stop);
|
|
99
112
|
process.off("SIGTERM", stop);
|
|
@@ -117,13 +130,22 @@ export class ForgeBridgeCliService {
|
|
|
117
130
|
const current = readLocalConfigSync();
|
|
118
131
|
io.stdout.write(`Pairing with server: ${args.serverUrl}\n`);
|
|
119
132
|
const code = await resolvePairingCode(args.code);
|
|
120
|
-
const
|
|
121
|
-
await
|
|
122
|
-
const pairArgs = await withDetectedPairCliProviders({ ...args, code, repoRoot });
|
|
133
|
+
const provisionalRoot = path.resolve(args.repoRoot ?? current.defaultRepoRoot ?? path.join(os.homedir(), "ForgeRepos"));
|
|
134
|
+
const pairArgs = await withDetectedPairCliProviders({ ...args, code, repoRoot: provisionalRoot });
|
|
123
135
|
const claim = await this.pairRunner(pairArgs);
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
136
|
+
// The code is spent now: save the credentials before anything else can fail or prompt.
|
|
137
|
+
const applied = applyPairHost(pairArgs, claim.host, args.repoRoot !== undefined, io);
|
|
138
|
+
await writeLocalConfig(pairedConfig(current, applied.args, claim));
|
|
139
|
+
let repoRoot = applied.args.repoRoot;
|
|
140
|
+
if (!args.repoRoot && !applied.repoRootFromHost) {
|
|
141
|
+
const answered = await promptPairRepoRoot(repoRoot);
|
|
142
|
+
if (answered !== repoRoot) {
|
|
143
|
+
repoRoot = answered;
|
|
144
|
+
await writeLocalConfig(pairedConfig(current, { ...applied.args, repoRoot }, claim));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
await fs.mkdir(repoRoot, { recursive: true });
|
|
148
|
+
io.stdout.write(`Paired runner ${claim.runnerId}${applied.args.name ? ` (${applied.args.name})` : ""}.\n`);
|
|
127
149
|
io.stdout.write(`Repo folder: ${repoRoot}\n`);
|
|
128
150
|
io.stdout.write(`Config: ${resolveLocalConfigPath()}\n`);
|
|
129
151
|
io.stdout.write("Start the bridge with: forge-bridge connect\n");
|
|
@@ -172,8 +194,7 @@ export class ForgeBridgeCliService {
|
|
|
172
194
|
}
|
|
173
195
|
}
|
|
174
196
|
if (args.command === "status") {
|
|
175
|
-
await
|
|
176
|
-
return 0;
|
|
197
|
+
return await runStatus(args, io);
|
|
177
198
|
}
|
|
178
199
|
if (args.command === "cleanup") {
|
|
179
200
|
return await cleanupRepos(args.config, args.mode, args.force, this.cleanupFactory(args.config.sandboxStateRoot), io);
|
|
@@ -206,6 +227,9 @@ export class ForgeBridgeCliService {
|
|
|
206
227
|
writeSandboxPolicyStatus(readLocalConfigSync(), io);
|
|
207
228
|
return 0;
|
|
208
229
|
}
|
|
230
|
+
if (args.command === "yield") {
|
|
231
|
+
return await runYieldCommand(args.action, io);
|
|
232
|
+
}
|
|
209
233
|
if (args.command === "mcp") {
|
|
210
234
|
const parsed = parseCompletionMcpArgs(args.argv);
|
|
211
235
|
if (!parsed.ok) {
|
|
@@ -220,7 +244,7 @@ export class ForgeBridgeCliService {
|
|
|
220
244
|
const dispatchJson = await fs.readFile(args.dispatchPath, "utf8");
|
|
221
245
|
const dispatch = attachEnvSecretGrant(parseRunOnceDispatchPacket(JSON.parse(dispatchJson)));
|
|
222
246
|
redactionSecrets = exactSecrets(dispatch);
|
|
223
|
-
const result = await this.sessions.runOnce(
|
|
247
|
+
const result = await runOnceWithReviewPlacement(dispatch, (packet) => this.sessions.runOnce(packet, {
|
|
224
248
|
emit: async (event) => {
|
|
225
249
|
const line = {
|
|
226
250
|
type: "runner_event",
|
|
@@ -228,7 +252,7 @@ export class ForgeBridgeCliService {
|
|
|
228
252
|
};
|
|
229
253
|
io.stdout.write(`${JSON.stringify(line)}\n`);
|
|
230
254
|
}
|
|
231
|
-
});
|
|
255
|
+
}));
|
|
232
256
|
await writeJsonAtomic(args.resultPath, redactRunOnceResultPacket(result, redactionSecrets));
|
|
233
257
|
return result.exitCode;
|
|
234
258
|
}
|
|
@@ -243,6 +267,36 @@ export class ForgeBridgeCliService {
|
|
|
243
267
|
}
|
|
244
268
|
}
|
|
245
269
|
}
|
|
270
|
+
/**
|
|
271
|
+
* Decision 0014 `forge-bridge yield`: the host's own yield switch. It writes a
|
|
272
|
+
* flag file next to the bridge config (never bridge.json); a running bridge
|
|
273
|
+
* polls it and stops taking new attempts without a restart.
|
|
274
|
+
*/
|
|
275
|
+
async function runYieldCommand(action, io) {
|
|
276
|
+
const flagPath = resolveLocalYieldFlagPath();
|
|
277
|
+
try {
|
|
278
|
+
if (action !== "status") {
|
|
279
|
+
await writeLocalYieldFlag(flagPath, action === "on");
|
|
280
|
+
}
|
|
281
|
+
const on = await readLocalYieldFlag(flagPath);
|
|
282
|
+
if (action === "on") {
|
|
283
|
+
io.stdout.write("Local yield to foreground is on. A running bridge takes no new attempts within one heartbeat; running attempts finish.\n");
|
|
284
|
+
}
|
|
285
|
+
else if (action === "off") {
|
|
286
|
+
io.stdout.write("Local yield to foreground is off. The bridge takes new attempts again unless yield is on in Forge.\n");
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
io.stdout.write(`Local yield to foreground: ${on ? "on" : "off"}\n`);
|
|
290
|
+
}
|
|
291
|
+
io.stdout.write(`Flag file: ${flagPath}\n`);
|
|
292
|
+
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");
|
|
293
|
+
return 0;
|
|
294
|
+
}
|
|
295
|
+
catch (error) {
|
|
296
|
+
io.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
297
|
+
return 1;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
246
300
|
function attachEnvSecretGrant(dispatch) {
|
|
247
301
|
if (!dispatch.execution.requiresApiKeySecretGrant) {
|
|
248
302
|
delete process.env[apiKeySecretGrantEnv];
|
|
@@ -325,17 +379,7 @@ export function parseArgs(argv) {
|
|
|
325
379
|
return { ok: false, error: "Usage: forge-bridge server <show|set <url>>" };
|
|
326
380
|
}
|
|
327
381
|
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 };
|
|
382
|
+
return parseStatusArgs(argv, configuredBridgeServiceConfig);
|
|
339
383
|
}
|
|
340
384
|
if (argv[0] === "cleanup") {
|
|
341
385
|
return parseCleanupArgs(argv);
|
|
@@ -346,6 +390,13 @@ export function parseArgs(argv) {
|
|
|
346
390
|
if (argv[0] === "sandbox") {
|
|
347
391
|
return parseSandboxArgs(argv);
|
|
348
392
|
}
|
|
393
|
+
if (argv[0] === "yield") {
|
|
394
|
+
const action = argv[1] ?? "status";
|
|
395
|
+
if (argv.length > 2 || (action !== "on" && action !== "off" && action !== "status")) {
|
|
396
|
+
return { ok: false, error: "Usage: forge-bridge yield [on|off|status]" };
|
|
397
|
+
}
|
|
398
|
+
return { ok: true, command: "yield", action };
|
|
399
|
+
}
|
|
349
400
|
if (argv[0] !== "run-once") {
|
|
350
401
|
return {
|
|
351
402
|
ok: false,
|
|
@@ -759,6 +810,7 @@ function parsePairArgs(argv) {
|
|
|
759
810
|
repoRoot: repoRoot?.trim() ? path.resolve(repoRoot) : undefined,
|
|
760
811
|
cleanupWorktrees: cleanupWorktrees ?? defaultConfig.cleanupWorktrees,
|
|
761
812
|
cliProviders: cliProviders.length > 0 ? cliProviders : localConfig.cliProviders && localConfig.cliProviders.length > 0 ? [...localConfig.cliProviders] : ["codex"],
|
|
813
|
+
cliProvidersFromFlag: cliProviders.length > 0,
|
|
762
814
|
projectLabels: projectLabels.length > 0 ? projectLabels : localConfig.projectLabels ? [...localConfig.projectLabels] : []
|
|
763
815
|
};
|
|
764
816
|
}
|
|
@@ -821,9 +873,71 @@ async function claimBridgeRunner(args) {
|
|
|
821
873
|
}
|
|
822
874
|
return {
|
|
823
875
|
runnerId: value.runnerId,
|
|
824
|
-
deviceToken: value.deviceToken
|
|
876
|
+
deviceToken: value.deviceToken,
|
|
877
|
+
host: parsePairRunnerHost(value.host)
|
|
825
878
|
};
|
|
826
879
|
}
|
|
880
|
+
function parsePairRunnerHost(value) {
|
|
881
|
+
if (!value || typeof value !== "object") {
|
|
882
|
+
return undefined;
|
|
883
|
+
}
|
|
884
|
+
const host = value;
|
|
885
|
+
const name = typeof host.name === "string" && host.name.trim() ? host.name.trim() : undefined;
|
|
886
|
+
const repoRoot = typeof host.repoRoot === "string" && host.repoRoot.trim() ? host.repoRoot.trim() : undefined;
|
|
887
|
+
const cliProviders = Array.isArray(host.cliProviders)
|
|
888
|
+
? host.cliProviders.filter((provider) => typeof provider === "string" && provider.trim().length > 0)
|
|
889
|
+
: [];
|
|
890
|
+
return { name, repoRoot, cliProviders: cliProviders.length > 0 ? cliProviders : undefined };
|
|
891
|
+
}
|
|
892
|
+
/**
|
|
893
|
+
* Decision 0014 §5: the claim's host block carries what the Connect dialog chose. The runner name
|
|
894
|
+
* is the server's; providers and the repo folder apply unless a flag named them on this command line.
|
|
895
|
+
*/
|
|
896
|
+
function applyPairHost(args, host, repoRootFromFlag, io) {
|
|
897
|
+
if (!host) {
|
|
898
|
+
return { args, repoRootFromHost: false };
|
|
899
|
+
}
|
|
900
|
+
let repoRoot = args.repoRoot;
|
|
901
|
+
let repoRootFromHost = false;
|
|
902
|
+
if (host.repoRoot && !repoRootFromFlag) {
|
|
903
|
+
const resolved = resolveHostRepoRoot(host.repoRoot);
|
|
904
|
+
if (!resolved) {
|
|
905
|
+
io.stderr.write(`Ignoring the repo folder chosen in Forge (${host.repoRoot}): it is not a path on this machine.\n`);
|
|
906
|
+
}
|
|
907
|
+
else {
|
|
908
|
+
repoRootFromHost = true;
|
|
909
|
+
repoRoot = resolved;
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
return {
|
|
913
|
+
args: {
|
|
914
|
+
...args,
|
|
915
|
+
name: host.name ?? args.name,
|
|
916
|
+
cliProviders: host.cliProviders && !args.cliProvidersFromFlag ? [...host.cliProviders] : args.cliProviders,
|
|
917
|
+
repoRoot
|
|
918
|
+
},
|
|
919
|
+
repoRootFromHost
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
/** Expands `~` in a repo folder chosen in Forge and rejects one shaped for another OS. */
|
|
923
|
+
export function resolveHostRepoRoot(value, platform = process.platform, home = os.homedir()) {
|
|
924
|
+
const trimmed = value.trim();
|
|
925
|
+
if (!trimmed) {
|
|
926
|
+
return undefined;
|
|
927
|
+
}
|
|
928
|
+
const pathApi = platform === "win32" ? path.win32 : path.posix;
|
|
929
|
+
if (trimmed === "~") {
|
|
930
|
+
return home;
|
|
931
|
+
}
|
|
932
|
+
if (/^~[\\/]/.test(trimmed)) {
|
|
933
|
+
return pathApi.resolve(home, trimmed.slice(2));
|
|
934
|
+
}
|
|
935
|
+
const windowsShaped = /^[A-Za-z]:[\\/]/.test(trimmed) || trimmed.startsWith("\\\\");
|
|
936
|
+
if (platform === "win32") {
|
|
937
|
+
return windowsShaped || trimmed.startsWith("/") ? pathApi.resolve(trimmed) : undefined;
|
|
938
|
+
}
|
|
939
|
+
return !windowsShaped && trimmed.startsWith("/") ? pathApi.resolve(trimmed) : undefined;
|
|
940
|
+
}
|
|
827
941
|
function pairedConfig(current, args, claim) {
|
|
828
942
|
return {
|
|
829
943
|
...current,
|
|
@@ -843,7 +957,7 @@ function pairedConfig(current, args, claim) {
|
|
|
843
957
|
supportsRunnerAuthoredPhaseArtifacts: current.supportsRunnerAuthoredPhaseArtifacts ?? true,
|
|
844
958
|
supportsDraftRunOnce: current.supportsDraftRunOnce ?? true,
|
|
845
959
|
supportsDraftAttachments: current.supportsDraftAttachments ?? true,
|
|
846
|
-
|
|
960
|
+
...pairDerivedCapabilities(current, args.cliProviders),
|
|
847
961
|
repoMappings: current.repoMappings ?? []
|
|
848
962
|
};
|
|
849
963
|
}
|
|
@@ -868,11 +982,7 @@ async function resolvePairingCode(code) {
|
|
|
868
982
|
prompt.close();
|
|
869
983
|
}
|
|
870
984
|
}
|
|
871
|
-
async function
|
|
872
|
-
const fallback = path.resolve(repoRoot ?? configuredRoot ?? path.join(os.homedir(), "ForgeRepos"));
|
|
873
|
-
if (repoRoot?.trim()) {
|
|
874
|
-
return fallback;
|
|
875
|
-
}
|
|
985
|
+
async function promptPairRepoRoot(fallback) {
|
|
876
986
|
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
877
987
|
return fallback;
|
|
878
988
|
}
|
|
@@ -943,15 +1053,18 @@ async function writeJsonAtomic(outputPath, value) {
|
|
|
943
1053
|
await fs.writeFile(tempPath, `${JSON.stringify(value, null, 2)}\n`, "utf8");
|
|
944
1054
|
await fs.rename(tempPath, outputPath);
|
|
945
1055
|
}
|
|
1056
|
+
async function runStatus(args, io) {
|
|
1057
|
+
return args.idle ? await runIdleStatusCommand(args.idle, io) : await writeStatus(args.config, args.checkUpdates, io);
|
|
1058
|
+
}
|
|
946
1059
|
async function writeStatus(config, checkUpdates, io) {
|
|
947
|
-
const detected = await
|
|
1060
|
+
const detected = await detectKnownCliProviders(config.cliProviders);
|
|
948
1061
|
const repos = config.repoMappings.filter((mapping) => mapping.localPath?.trim());
|
|
949
1062
|
io.stdout.write(`Forge bridge ${config.version}\n`);
|
|
950
1063
|
io.stdout.write(`Config: ${resolveLocalConfigPath()}\n`);
|
|
951
1064
|
io.stdout.write(`Server: ${config.serverUrl || "not configured"}\n`);
|
|
952
1065
|
io.stdout.write(`Device: ${config.runnerId || "not configured"}${config.deviceName ? ` (${config.deviceName})` : ""}\n`);
|
|
953
1066
|
io.stdout.write(`Device token: ${config.deviceToken ? "configured" : "missing"}\n`);
|
|
954
|
-
io.stdout.write(
|
|
1067
|
+
io.stdout.write(`${await idleSummaryLine()}\n`);
|
|
955
1068
|
io.stdout.write("Repos:\n");
|
|
956
1069
|
if (repos.length === 0) {
|
|
957
1070
|
io.stdout.write(" none\n");
|
|
@@ -969,6 +1082,7 @@ async function writeStatus(config, checkUpdates, io) {
|
|
|
969
1082
|
if (checkUpdates) {
|
|
970
1083
|
io.stdout.write("Update check: no update channel configured.\n");
|
|
971
1084
|
}
|
|
1085
|
+
return 0;
|
|
972
1086
|
}
|
|
973
1087
|
async function cleanupRepos(config, mode, force, cleanup, io) {
|
|
974
1088
|
const repos = config.repoMappings.filter((mapping) => mapping.localPath?.trim());
|
|
@@ -1001,7 +1115,11 @@ async function cleanupRepos(config, mode, force, cleanup, io) {
|
|
|
1001
1115
|
io.stdout.write(`Removed ${result.removedWorktrees} stale managed ${result.removedWorktrees === 1 ? "worktree" : "worktrees"} from ${result.worktreeRoot}\n`);
|
|
1002
1116
|
}
|
|
1003
1117
|
else {
|
|
1004
|
-
|
|
1118
|
+
const deleted = result.deletedBranches ?? 0;
|
|
1119
|
+
io.stdout.write(`Pruned stale worktree metadata and deleted ${deleted} Forge ${deleted === 1 ? "branch" : "branches"} (merged work and leftover readiness probes) in ${repoPath}\n`);
|
|
1120
|
+
if (result.mergedBaseUnresolved) {
|
|
1121
|
+
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`);
|
|
1122
|
+
}
|
|
1005
1123
|
}
|
|
1006
1124
|
}
|
|
1007
1125
|
catch (error) {
|
|
@@ -1011,184 +1129,8 @@ async function cleanupRepos(config, mode, force, cleanup, io) {
|
|
|
1011
1129
|
}
|
|
1012
1130
|
return failures === 0 ? 0 : 1;
|
|
1013
1131
|
}
|
|
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
|
-
async function withDetectedCliProviders(config, candidates = config.cliProviders) {
|
|
1167
|
-
const detected = await detectCliProviders(uniqueProviders(candidates));
|
|
1168
|
-
const found = detected.filter((result) => result.found);
|
|
1169
|
-
if (found.length === 0) {
|
|
1170
|
-
return config;
|
|
1171
|
-
}
|
|
1172
|
-
const cliProviders = uniqueProviders([...config.cliProviders, ...found.map((result) => result.provider)]);
|
|
1173
|
-
const providerStatuses = { ...config.providerStatuses };
|
|
1174
|
-
for (const result of found) {
|
|
1175
|
-
const existing = providerStatuses[result.provider];
|
|
1176
|
-
providerStatuses[result.provider] = {
|
|
1177
|
-
signedIn: existing?.signedIn ?? true,
|
|
1178
|
-
version: result.version || existing?.version || "",
|
|
1179
|
-
models: result.models.length > 0
|
|
1180
|
-
? result.models
|
|
1181
|
-
: existing?.models ?? providerStatusesFor([result.provider])[result.provider]?.models ?? []
|
|
1182
|
-
};
|
|
1183
|
-
}
|
|
1184
|
-
return {
|
|
1185
|
-
...config,
|
|
1186
|
-
cliProviders,
|
|
1187
|
-
providerStatuses
|
|
1188
|
-
};
|
|
1189
|
-
}
|
|
1190
1132
|
async function withDetectedPairCliProviders(args) {
|
|
1191
|
-
const configured =
|
|
1133
|
+
const configured = knownProviderCandidates(args.cliProviders);
|
|
1192
1134
|
const detectedConfig = await withDetectedCliProviders({
|
|
1193
1135
|
...defaultBridgeServiceConfig({
|
|
1194
1136
|
serverUrl: args.serverUrl,
|
|
@@ -1204,12 +1146,3 @@ async function withDetectedPairCliProviders(args) {
|
|
|
1204
1146
|
cliProviders: detectedConfig.cliProviders
|
|
1205
1147
|
};
|
|
1206
1148
|
}
|
|
1207
|
-
function configuredProviderCandidates(providers) {
|
|
1208
|
-
return uniqueProviders([...providers, "codex", "cursor", "claude"]);
|
|
1209
|
-
}
|
|
1210
|
-
function uniqueProviders(providers) {
|
|
1211
|
-
return providers
|
|
1212
|
-
.map((provider) => provider.trim())
|
|
1213
|
-
.filter((provider) => provider.length > 0)
|
|
1214
|
-
.filter((provider, index, all) => all.findIndex((candidate) => candidate.toLowerCase() === provider.toLowerCase()) === index);
|
|
1215
|
-
}
|
|
@@ -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
|
+
};
|