@loucompanion/forge-bridge 0.1.3-dev.fbe15023cdfe → 0.1.4-dev.0098fdb4e213
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 +232 -5
- 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 +121 -0
- package/dist/bridge/bridge-chat.types.js +416 -0
- 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 +13 -1
- package/dist/bridge/bridge.service.d.ts +169 -14
- package/dist/bridge/bridge.service.js +1868 -330
- package/dist/bridge/bridge.types.d.ts +73 -1
- package/dist/bridge/dispatch-result-outbox.d.ts +35 -0
- package/dist/bridge/dispatch-result-outbox.js +87 -0
- package/dist/bridge/dispatch-result-worker.d.ts +2 -0
- package/dist/bridge/dispatch-result-worker.js +122 -0
- package/dist/bridge/in-flight-registry.d.ts +62 -0
- package/dist/bridge/in-flight-registry.js +207 -0
- package/dist/bridge/internals.d.ts +2 -0
- package/dist/bridge/internals.js +1 -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 +25 -0
- package/dist/bridge/readiness-result-outbox.js +74 -0
- package/dist/bridge/readiness-result-worker.d.ts +2 -0
- package/dist/bridge/readiness-result-worker.js +121 -0
- package/dist/bridge/runner-host-capabilities.d.ts +20 -0
- package/dist/bridge/runner-host-capabilities.js +110 -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 +21 -1
- package/dist/cleanup/cleanup.service.js +185 -143
- 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 +78 -16
- package/dist/cli/cli.service.d.ts +32 -15
- package/dist/cli/cli.service.js +206 -182
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +7 -0
- package/dist/cli/local-config.js +36 -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 +41 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +474 -0
- package/dist/runtime/attempt-database-broker.d.ts +89 -0
- package/dist/runtime/attempt-database-broker.js +390 -0
- package/dist/runtime/attempt-node-runtime-launcher.d.ts +2 -1
- package/dist/runtime/attempt-node-runtime-launcher.js +57 -18
- package/dist/runtime/attempt-path-operation.d.ts +21 -0
- package/dist/runtime/attempt-path-operation.js +94 -0
- package/dist/runtime/attempt-private-directory.d.ts +6 -0
- package/dist/runtime/attempt-private-directory.js +54 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +35 -0
- package/dist/runtime/attempt-process-supervisor.js +144 -23
- package/dist/runtime/canonical-source-file.d.ts +3 -0
- package/dist/runtime/canonical-source-file.js +54 -0
- package/dist/runtime/docker-engine-probe.d.ts +95 -0
- package/dist/runtime/docker-engine-probe.js +340 -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/generated-output-reset.d.ts +10 -0
- package/dist/runtime/generated-output-reset.js +62 -8
- package/dist/runtime/host-database-capability-boundary.d.ts +16 -0
- package/dist/runtime/host-database-capability-boundary.js +63 -0
- package/dist/runtime/host-diagnostics.d.ts +11 -0
- package/dist/runtime/host-diagnostics.js +192 -0
- package/dist/runtime/host-execution-root.d.ts +4 -0
- package/dist/runtime/host-execution-root.js +39 -0
- package/dist/runtime/host-facts.d.ts +36 -0
- package/dist/runtime/host-facts.js +95 -0
- package/dist/runtime/host-listener-inspector.d.ts +8 -1
- package/dist/runtime/host-listener-inspector.js +121 -60
- 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 +28 -1
- package/dist/runtime/host-runtime-contract.js +203 -57
- package/dist/runtime/host-runtime-lease.d.ts +163 -9
- package/dist/runtime/host-runtime-lease.js +1427 -124
- package/dist/runtime/host-runtime-promotion.d.ts +35 -3
- package/dist/runtime/host-runtime-promotion.js +107 -12
- 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/memory-capacity.d.ts +70 -0
- package/dist/runtime/memory-capacity.js +123 -0
- package/dist/runtime/native-test-postgres-fallback.d.ts +69 -0
- package/dist/runtime/native-test-postgres-fallback.js +143 -0
- package/dist/runtime/node-host-runtime-adapter.d.ts +3 -0
- package/dist/runtime/node-host-runtime-adapter.js +29 -11
- package/dist/runtime/pinned-directory-process.d.ts +9 -0
- package/dist/runtime/pinned-directory-process.js +61 -0
- package/dist/runtime/pinned-source-directory.d.ts +17 -0
- package/dist/runtime/pinned-source-directory.js +94 -0
- 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 +19 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +113 -59
- package/dist/runtime/prepared-runtime-identity.d.ts +6 -0
- package/dist/runtime/prepared-runtime-identity.js +218 -0
- package/dist/runtime/prepared-runtime-readiness.d.ts +30 -0
- package/dist/runtime/prepared-runtime-readiness.js +285 -0
- package/dist/runtime/runner-settings.d.ts +104 -0
- package/dist/runtime/runner-settings.js +236 -0
- package/dist/runtime/runtime-isolation-lease.js +4 -1
- package/dist/runtime/workspace-resource-estimator.d.ts +17 -0
- package/dist/runtime/workspace-resource-estimator.js +174 -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 +36 -0
- package/dist/sandbox/preflight.d.ts +31 -1
- package/dist/sandbox/preflight.js +237 -51
- package/dist/sandbox/provider-auth/codex.js +11 -11
- package/dist/sandbox/repository-lock.d.ts +2 -1
- package/dist/sandbox/repository-lock.js +19 -9
- package/dist/sandbox/runtime.d.ts +16 -2
- package/dist/sandbox/runtime.js +183 -114
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -0
- package/dist/sandbox/sandbox.types.d.ts +7 -0
- package/dist/sandbox/workspace.service.js +2 -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 +37 -1
- package/dist/session/managed-attempt-tools.js +822 -84
- package/dist/session/managed-build-coordinator.d.ts +5 -0
- package/dist/session/managed-build-coordinator.js +109 -0
- package/dist/session/managed-build-receipt.d.ts +26 -0
- package/dist/session/managed-build-receipt.js +342 -0
- package/dist/session/managed-command-host-load.d.ts +47 -0
- package/dist/session/managed-command-host-load.js +83 -0
- package/dist/session/managed-verification-timeouts.d.ts +8 -0
- package/dist/session/managed-verification-timeouts.js +17 -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 +24 -0
- package/dist/session/phase-completion.artifacts.js +321 -45
- 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 +23 -1
- package/dist/session/phase-completion.helpers.d.ts +5 -0
- package/dist/session/phase-completion.helpers.js +43 -19
- package/dist/session/phase-completion.js +19 -3
- 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 +22 -18
- package/dist/session/phase-completion.runtime.d.ts +6 -10
- package/dist/session/phase-completion.runtime.js +214 -224
- 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 +250 -226
- package/dist/session/phase-completion.validation.d.ts +3 -3
- package/dist/session/phase-completion.validation.js +135 -89
- 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 +91 -0
- package/dist/session/pre-publication-validation.js +670 -0
- package/dist/session/provider-cli/bridge-cli.conformance-fixtures.d.ts +72 -0
- package/dist/session/provider-cli/bridge-cli.conformance-fixtures.js +462 -0
- package/dist/session/provider-cli/ci-repair-readiness.d.ts +8 -0
- package/dist/session/provider-cli/ci-repair-readiness.js +23 -3
- 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 +6 -3
- package/dist/session/provider-cli/provider-cli.artifacts.js +62 -22
- 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.js +34 -2
- 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 +85 -19
- package/dist/session/provider-cli/provider-cli.process.js +566 -283
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +15 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +211 -36
- package/dist/session/provider-cli/provider-cli.repair-epoch.d.ts +6 -0
- package/dist/session/provider-cli/provider-cli.repair-epoch.js +11 -0
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +22 -1
- package/dist/session/provider-cli/provider-cli.runtime.js +83 -4
- package/dist/session/provider-cli/provider-cli.service.d.ts +36 -5
- package/dist/session/provider-cli/provider-cli.service.js +818 -99
- package/dist/session/provider-cli/provider-cli.types.d.ts +32 -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 +18 -0
- package/dist/session/provider-cli/provider-output-state.js +376 -17
- package/dist/session/provider-cli/provider-usage.d.ts +9 -1
- package/dist/session/provider-cli/provider-usage.js +28 -5
- 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 +284 -9
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.service.d.ts +11 -2
- package/dist/session/session.service.js +301 -58
- package/dist/session/session.types.d.ts +150 -2
- package/dist/session/session.types.js +599 -7
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -0
- package/dist/session/unreferenced-exports.d.ts +12 -0
- package/dist/session/unreferenced-exports.js +59 -0
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -0
- package/dist/shared/format/format-bytes.d.ts +1 -0
- package/dist/shared/format/format-bytes.js +9 -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/git/git.js +2 -1
- package/dist/shared/path/path.d.ts +1 -0
- package/dist/shared/path/path.js +18 -0
- package/dist/shared/process/dotnet-toolchain.d.ts +17 -0
- package/dist/shared/process/dotnet-toolchain.js +307 -0
- package/dist/shared/process/host-process-recovery.d.ts +14 -3
- package/dist/shared/process/host-process-recovery.js +26 -5
- package/dist/shared/process/host-process-supervisor.d.ts +16 -1
- package/dist/shared/process/host-process-supervisor.js +124 -23
- 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 +69 -0
- package/dist/shared/process/process.js +223 -16
- 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 +3 -0
- package/dist/shared/provider-capabilities.js +92 -0
- package/dist/shared/redaction/redaction.d.ts +1 -0
- package/dist/shared/redaction/redaction.js +39 -3
- package/dist/shared/time/monotonic.d.ts +1 -0
- package/dist/shared/time/monotonic.js +8 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/dependency-warmer.d.ts +66 -9
- package/dist/worktree/dependency-warmer.js +609 -24
- package/dist/worktree/index.d.ts +1 -1
- package/dist/worktree/story-qa-reference-hydrator.d.ts +4 -0
- package/dist/worktree/story-qa-reference-hydrator.js +253 -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-wip-events.d.ts +18 -0
- package/dist/worktree/worktree-wip-events.js +98 -0
- package/dist/worktree/worktree-wip.d.ts +49 -0
- package/dist/worktree/worktree-wip.js +182 -0
- package/dist/worktree/worktree.base.d.ts +7 -1
- package/dist/worktree/worktree.service.d.ts +22 -2
- package/dist/worktree/worktree.service.js +302 -25
- package/dist/worktree/worktree.types.d.ts +36 -1
- package/package.json +8 -6
- package/runtime/windows-job-supervisor.ps1 +380 -14
package/dist/cli/cli.service.js
CHANGED
|
@@ -1,17 +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 {
|
|
7
|
-
import { resolveCursorAgentDirectLaunch } from "../shared/cursor-agent/cursor-agent.launch.js";
|
|
8
|
-
import { buildWindowsCmdLaunch } from "../shared/process/windows-launch.js";
|
|
5
|
+
import { configureDotNetToolchain } from "../shared/process/dotnet-toolchain.js";
|
|
9
6
|
import { supportsDraftImageAttachmentsFor } from "../shared/provider-capabilities.js";
|
|
10
7
|
import { redactText } from "../shared/redaction/redaction.js";
|
|
11
|
-
import { defaultBridgeServiceConfig, ForgeBridgeService } from "../bridge/bridge.service.js";
|
|
8
|
+
import { BridgeRevokedError, bridgeRevokedExitCode, defaultBridgeServiceConfig, ForgeBridgeService, } from "../bridge/bridge.service.js";
|
|
12
9
|
import { forgeBridgeVersion } from "../version.js";
|
|
13
10
|
import { ManagedWorktreeCleanupService } from "../cleanup/cleanup.service.js";
|
|
14
|
-
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";
|
|
15
12
|
import { BridgeSessionService } from "../session/session.service.js";
|
|
16
13
|
import { redactRunnerDispatchEvent, redactRunOnceResultPacket } from "../session/session-redaction.js";
|
|
17
14
|
import { validateDockerfilePolicy, validateSandboxContract } from "../sandbox/contract.js";
|
|
@@ -19,20 +16,27 @@ import { DockerPreflight } from "../sandbox/preflight.js";
|
|
|
19
16
|
import { DockerSandboxRuntime } from "../sandbox/runtime.js";
|
|
20
17
|
import { DockerSandboxSmoke } from "../sandbox/smoke.js";
|
|
21
18
|
import { parseCompletionMcpArgs, runCompletionMcpServer } from "../session/phase-completion.js";
|
|
22
|
-
import { failureResult, parseRunOnceDispatchPacket } from "../session/session.types.js";
|
|
19
|
+
import { failureFactsFromError, failureResult, parseRunOnceDispatchPacket } from "../session/session.types.js";
|
|
23
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";
|
|
24
25
|
const apiKeySecretGrantEnv = "FORGE_API_KEY_SECRET_GRANT";
|
|
25
|
-
const execFileAsync = promisify(execFile);
|
|
26
26
|
export class ForgeBridgeCliService {
|
|
27
27
|
sessions;
|
|
28
28
|
bridgeFactory;
|
|
29
29
|
pairRunner;
|
|
30
30
|
cleanupFactory;
|
|
31
|
-
|
|
31
|
+
dotNetToolchainConfigurator;
|
|
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) {
|
|
32
35
|
this.sessions = sessions;
|
|
33
36
|
this.bridgeFactory = bridgeFactory;
|
|
34
37
|
this.pairRunner = pairRunner;
|
|
35
38
|
this.cleanupFactory = cleanupFactory;
|
|
39
|
+
this.dotNetToolchainConfigurator = dotNetToolchainConfigurator;
|
|
36
40
|
}
|
|
37
41
|
async run(argv, io = { stdout: process.stdout, stderr: process.stderr }) {
|
|
38
42
|
if (argv.length === 0 || argv[0] === "--help" || argv[0] === "-h") {
|
|
@@ -67,15 +71,41 @@ export class ForgeBridgeCliService {
|
|
|
67
71
|
io.stderr.write(`forge-bridge connect requires ${missing[0]}.\n`);
|
|
68
72
|
return 2;
|
|
69
73
|
}
|
|
74
|
+
let dotNetToolchain;
|
|
75
|
+
try {
|
|
76
|
+
dotNetToolchain = await this.dotNetToolchainConfigurator(await dotNetPreflightRoots(config, args.implicitCloneDestination), { cloneFolders: [config.defaultRepoRoot.trim()].filter(Boolean) });
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
io.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
80
|
+
return 1;
|
|
81
|
+
}
|
|
82
|
+
if (dotNetToolchain) {
|
|
83
|
+
io.stdout.write(`Using .NET SDK ${dotNetToolchain.sdkVersion}: ${dotNetToolchain.executablePath}\n`);
|
|
84
|
+
}
|
|
70
85
|
const controller = new AbortController();
|
|
71
86
|
const stop = () => controller.abort("signal received");
|
|
72
87
|
process.once("SIGINT", stop);
|
|
73
88
|
process.once("SIGTERM", stop);
|
|
74
89
|
try {
|
|
90
|
+
if (config.cleanupWorktrees && config.repoMappings.some(mapping => mapping.localPath?.trim())) {
|
|
91
|
+
io.stdout.write("Cleaning stale managed worktrees before accepting dispatches.\n");
|
|
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);
|
|
95
|
+
}
|
|
75
96
|
io.stdout.write(connectStartupText(config));
|
|
76
97
|
await this.bridgeFactory(config).run(controller.signal);
|
|
77
98
|
return 0;
|
|
78
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
|
+
}
|
|
79
109
|
finally {
|
|
80
110
|
process.off("SIGINT", stop);
|
|
81
111
|
process.off("SIGTERM", stop);
|
|
@@ -99,13 +129,22 @@ export class ForgeBridgeCliService {
|
|
|
99
129
|
const current = readLocalConfigSync();
|
|
100
130
|
io.stdout.write(`Pairing with server: ${args.serverUrl}\n`);
|
|
101
131
|
const code = await resolvePairingCode(args.code);
|
|
102
|
-
const
|
|
103
|
-
await
|
|
104
|
-
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 });
|
|
105
134
|
const claim = await this.pairRunner(pairArgs);
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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`);
|
|
109
148
|
io.stdout.write(`Repo folder: ${repoRoot}\n`);
|
|
110
149
|
io.stdout.write(`Config: ${resolveLocalConfigPath()}\n`);
|
|
111
150
|
io.stdout.write("Start the bridge with: forge-bridge connect\n");
|
|
@@ -154,8 +193,7 @@ export class ForgeBridgeCliService {
|
|
|
154
193
|
}
|
|
155
194
|
}
|
|
156
195
|
if (args.command === "status") {
|
|
157
|
-
await
|
|
158
|
-
return 0;
|
|
196
|
+
return await runStatus(args, io);
|
|
159
197
|
}
|
|
160
198
|
if (args.command === "cleanup") {
|
|
161
199
|
return await cleanupRepos(args.config, args.mode, args.force, this.cleanupFactory(args.config.sandboxStateRoot), io);
|
|
@@ -188,6 +226,9 @@ export class ForgeBridgeCliService {
|
|
|
188
226
|
writeSandboxPolicyStatus(readLocalConfigSync(), io);
|
|
189
227
|
return 0;
|
|
190
228
|
}
|
|
229
|
+
if (args.command === "yield") {
|
|
230
|
+
return await runYieldCommand(args.action, io);
|
|
231
|
+
}
|
|
191
232
|
if (args.command === "mcp") {
|
|
192
233
|
const parsed = parseCompletionMcpArgs(args.argv);
|
|
193
234
|
if (!parsed.ok) {
|
|
@@ -216,7 +257,7 @@ export class ForgeBridgeCliService {
|
|
|
216
257
|
}
|
|
217
258
|
catch (error) {
|
|
218
259
|
const summary = redactText(error instanceof Error ? error.message : String(error), redactionSecrets);
|
|
219
|
-
await writeJsonAtomic(args.resultPath, failureResult(summary)).catch(() => undefined);
|
|
260
|
+
await writeJsonAtomic(args.resultPath, redactRunOnceResultPacket(failureResult(summary, [], failureFactsFromError(error, { source: "bridge" })), redactionSecrets)).catch(() => undefined);
|
|
220
261
|
io.stderr.write(`${summary}\n`);
|
|
221
262
|
return 1;
|
|
222
263
|
}
|
|
@@ -225,6 +266,36 @@ export class ForgeBridgeCliService {
|
|
|
225
266
|
}
|
|
226
267
|
}
|
|
227
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
|
+
}
|
|
228
299
|
function attachEnvSecretGrant(dispatch) {
|
|
229
300
|
if (!dispatch.execution.requiresApiKeySecretGrant) {
|
|
230
301
|
delete process.env[apiKeySecretGrantEnv];
|
|
@@ -307,17 +378,7 @@ export function parseArgs(argv) {
|
|
|
307
378
|
return { ok: false, error: "Usage: forge-bridge server <show|set <url>>" };
|
|
308
379
|
}
|
|
309
380
|
if (argv[0] === "status") {
|
|
310
|
-
|
|
311
|
-
for (let index = 1; index < argv.length; index += 1) {
|
|
312
|
-
const arg = argv[index];
|
|
313
|
-
if (arg === "--check-updates") {
|
|
314
|
-
checkUpdates = true;
|
|
315
|
-
}
|
|
316
|
-
else {
|
|
317
|
-
return { ok: false, error: `Unknown argument: ${arg}` };
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
return { ok: true, command: "status", config: configuredBridgeServiceConfig(), checkUpdates };
|
|
381
|
+
return parseStatusArgs(argv, configuredBridgeServiceConfig);
|
|
321
382
|
}
|
|
322
383
|
if (argv[0] === "cleanup") {
|
|
323
384
|
return parseCleanupArgs(argv);
|
|
@@ -328,6 +389,13 @@ export function parseArgs(argv) {
|
|
|
328
389
|
if (argv[0] === "sandbox") {
|
|
329
390
|
return parseSandboxArgs(argv);
|
|
330
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
|
+
}
|
|
331
399
|
if (argv[0] !== "run-once") {
|
|
332
400
|
return {
|
|
333
401
|
ok: false,
|
|
@@ -582,6 +650,28 @@ async function reapSandboxes(io) {
|
|
|
582
650
|
await preflight.release();
|
|
583
651
|
}
|
|
584
652
|
}
|
|
653
|
+
async function dotNetPreflightRoots(config, implicitCloneDestination) {
|
|
654
|
+
const roots = config.repoMappings.map((mapping) => mapping.localPath?.trim())
|
|
655
|
+
.filter((repoRoot) => Boolean(repoRoot));
|
|
656
|
+
const defaultRoot = config.defaultRepoRoot.trim();
|
|
657
|
+
if (!defaultRoot)
|
|
658
|
+
return roots;
|
|
659
|
+
if (implicitCloneDestination) {
|
|
660
|
+
try {
|
|
661
|
+
// The built-in clone destination need not exist on first connect. lstat
|
|
662
|
+
// deliberately retains dangling links for the strict SDK scanner to reject.
|
|
663
|
+
// Explicit mappings (including this same path) remain required inputs.
|
|
664
|
+
await fs.lstat(defaultRoot);
|
|
665
|
+
}
|
|
666
|
+
catch (error) {
|
|
667
|
+
if (error.code === "ENOENT")
|
|
668
|
+
return roots;
|
|
669
|
+
throw error;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
roots.push(defaultRoot);
|
|
673
|
+
return roots;
|
|
674
|
+
}
|
|
585
675
|
function parseConnectArgs(argv) {
|
|
586
676
|
let serverUrl = null;
|
|
587
677
|
let runnerId = null;
|
|
@@ -651,7 +741,10 @@ function parseConnectArgs(argv) {
|
|
|
651
741
|
return {
|
|
652
742
|
ok: true,
|
|
653
743
|
command: "connect",
|
|
654
|
-
config: configuredBridgeServiceConfig(overrides, localConfig)
|
|
744
|
+
config: configuredBridgeServiceConfig(overrides, localConfig),
|
|
745
|
+
implicitCloneDestination: repoRoot === null
|
|
746
|
+
&& process.env.FORGE_REPO_ROOT === undefined
|
|
747
|
+
&& localConfig.defaultRepoRoot === undefined,
|
|
655
748
|
};
|
|
656
749
|
}
|
|
657
750
|
function parsePairArgs(argv) {
|
|
@@ -714,8 +807,9 @@ function parsePairArgs(argv) {
|
|
|
714
807
|
name: name?.trim() || defaultName,
|
|
715
808
|
fingerprint: fingerprint?.trim() || `local-bridge:${os.hostname()}:${user}`,
|
|
716
809
|
repoRoot: repoRoot?.trim() ? path.resolve(repoRoot) : undefined,
|
|
717
|
-
cleanupWorktrees: cleanupWorktrees ??
|
|
810
|
+
cleanupWorktrees: cleanupWorktrees ?? defaultConfig.cleanupWorktrees,
|
|
718
811
|
cliProviders: cliProviders.length > 0 ? cliProviders : localConfig.cliProviders && localConfig.cliProviders.length > 0 ? [...localConfig.cliProviders] : ["codex"],
|
|
812
|
+
cliProvidersFromFlag: cliProviders.length > 0,
|
|
719
813
|
projectLabels: projectLabels.length > 0 ? projectLabels : localConfig.projectLabels ? [...localConfig.projectLabels] : []
|
|
720
814
|
};
|
|
721
815
|
}
|
|
@@ -778,9 +872,71 @@ async function claimBridgeRunner(args) {
|
|
|
778
872
|
}
|
|
779
873
|
return {
|
|
780
874
|
runnerId: value.runnerId,
|
|
781
|
-
deviceToken: value.deviceToken
|
|
875
|
+
deviceToken: value.deviceToken,
|
|
876
|
+
host: parsePairRunnerHost(value.host)
|
|
782
877
|
};
|
|
783
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
|
+
}
|
|
784
940
|
function pairedConfig(current, args, claim) {
|
|
785
941
|
return {
|
|
786
942
|
...current,
|
|
@@ -825,11 +981,7 @@ async function resolvePairingCode(code) {
|
|
|
825
981
|
prompt.close();
|
|
826
982
|
}
|
|
827
983
|
}
|
|
828
|
-
async function
|
|
829
|
-
const fallback = path.resolve(repoRoot ?? configuredRoot ?? path.join(os.homedir(), "ForgeRepos"));
|
|
830
|
-
if (repoRoot?.trim()) {
|
|
831
|
-
return fallback;
|
|
832
|
-
}
|
|
984
|
+
async function promptPairRepoRoot(fallback) {
|
|
833
985
|
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
834
986
|
return fallback;
|
|
835
987
|
}
|
|
@@ -869,6 +1021,7 @@ function connectStartupText(config) {
|
|
|
869
1021
|
` repo folder: ${config.defaultRepoRoot || "not configured"}`,
|
|
870
1022
|
` providers: ${formatList(config.cliProviders)}`,
|
|
871
1023
|
` cleanup worktrees: ${config.cleanupWorktrees ? "enabled" : "disabled"}`,
|
|
1024
|
+
` Docker Desktop auto-recovery: ${config.dockerDesktopRecoveryEnabled ? "enabled" : "disabled"}`,
|
|
872
1025
|
` open public sandbox networking: ${config.allowOpenPublicSandbox ? "enabled" : "disabled"}`,
|
|
873
1026
|
"",
|
|
874
1027
|
"Press Ctrl+C to stop.",
|
|
@@ -899,15 +1052,18 @@ async function writeJsonAtomic(outputPath, value) {
|
|
|
899
1052
|
await fs.writeFile(tempPath, `${JSON.stringify(value, null, 2)}\n`, "utf8");
|
|
900
1053
|
await fs.rename(tempPath, outputPath);
|
|
901
1054
|
}
|
|
1055
|
+
async function runStatus(args, io) {
|
|
1056
|
+
return args.idle ? await runIdleStatusCommand(args.idle, io) : await writeStatus(args.config, args.checkUpdates, io);
|
|
1057
|
+
}
|
|
902
1058
|
async function writeStatus(config, checkUpdates, io) {
|
|
903
|
-
const detected = await detectCliProviders([...new Set([...config.cliProviders, "codex", "cursor"])]);
|
|
1059
|
+
const detected = await detectCliProviders([...new Set([...config.cliProviders, "codex", "cursor", "claude"])]);
|
|
904
1060
|
const repos = config.repoMappings.filter((mapping) => mapping.localPath?.trim());
|
|
905
1061
|
io.stdout.write(`Forge bridge ${config.version}\n`);
|
|
906
1062
|
io.stdout.write(`Config: ${resolveLocalConfigPath()}\n`);
|
|
907
1063
|
io.stdout.write(`Server: ${config.serverUrl || "not configured"}\n`);
|
|
908
1064
|
io.stdout.write(`Device: ${config.runnerId || "not configured"}${config.deviceName ? ` (${config.deviceName})` : ""}\n`);
|
|
909
1065
|
io.stdout.write(`Device token: ${config.deviceToken ? "configured" : "missing"}\n`);
|
|
910
|
-
io.stdout.write(
|
|
1066
|
+
io.stdout.write(`${await idleSummaryLine()}\n`);
|
|
911
1067
|
io.stdout.write("Repos:\n");
|
|
912
1068
|
if (repos.length === 0) {
|
|
913
1069
|
io.stdout.write(" none\n");
|
|
@@ -925,6 +1081,7 @@ async function writeStatus(config, checkUpdates, io) {
|
|
|
925
1081
|
if (checkUpdates) {
|
|
926
1082
|
io.stdout.write("Update check: no update channel configured.\n");
|
|
927
1083
|
}
|
|
1084
|
+
return 0;
|
|
928
1085
|
}
|
|
929
1086
|
async function cleanupRepos(config, mode, force, cleanup, io) {
|
|
930
1087
|
const repos = config.repoMappings.filter((mapping) => mapping.localPath?.trim());
|
|
@@ -957,7 +1114,11 @@ async function cleanupRepos(config, mode, force, cleanup, io) {
|
|
|
957
1114
|
io.stdout.write(`Removed ${result.removedWorktrees} stale managed ${result.removedWorktrees === 1 ? "worktree" : "worktrees"} from ${result.worktreeRoot}\n`);
|
|
958
1115
|
}
|
|
959
1116
|
else {
|
|
960
|
-
|
|
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
|
+
}
|
|
961
1122
|
}
|
|
962
1123
|
}
|
|
963
1124
|
catch (error) {
|
|
@@ -967,146 +1128,8 @@ async function cleanupRepos(config, mode, force, cleanup, io) {
|
|
|
967
1128
|
}
|
|
968
1129
|
return failures === 0 ? 0 : 1;
|
|
969
1130
|
}
|
|
970
|
-
async function
|
|
971
|
-
const
|
|
972
|
-
for (const provider of providers) {
|
|
973
|
-
let detected = null;
|
|
974
|
-
for (const probe of cliProbeCommandsFor(provider)) {
|
|
975
|
-
try {
|
|
976
|
-
detected = await execVersionCommand(probe);
|
|
977
|
-
break;
|
|
978
|
-
}
|
|
979
|
-
catch {
|
|
980
|
-
// Try the next provider-specific probe.
|
|
981
|
-
}
|
|
982
|
-
}
|
|
983
|
-
results.push({
|
|
984
|
-
provider,
|
|
985
|
-
found: detected !== null,
|
|
986
|
-
version: detected ? versionLine(`${detected.stdout || detected.stderr}`) : "",
|
|
987
|
-
models: detected ? await detectCliModels(provider) : []
|
|
988
|
-
});
|
|
989
|
-
}
|
|
990
|
-
return results;
|
|
991
|
-
}
|
|
992
|
-
function cliProbeCommandsFor(provider) {
|
|
993
|
-
const normalized = provider.toLowerCase();
|
|
994
|
-
if (normalized === "codex") {
|
|
995
|
-
return [
|
|
996
|
-
{ command: "codex", args: ["-V"] },
|
|
997
|
-
{ command: "codex", args: ["--version"] }
|
|
998
|
-
];
|
|
999
|
-
}
|
|
1000
|
-
if (normalized === "cursor") {
|
|
1001
|
-
return [
|
|
1002
|
-
{ command: "cursor-agent", args: ["-v"] },
|
|
1003
|
-
{ command: "agent", args: ["-v"] },
|
|
1004
|
-
{ command: "cursor-agent", args: ["--version"] },
|
|
1005
|
-
{ command: "agent", args: ["--version"] }
|
|
1006
|
-
];
|
|
1007
|
-
}
|
|
1008
|
-
return [
|
|
1009
|
-
{ command: provider, args: ["--version"] },
|
|
1010
|
-
{ command: provider, args: ["-V"] }
|
|
1011
|
-
];
|
|
1012
|
-
}
|
|
1013
|
-
async function execVersionCommand(probe, timeout = 2000) {
|
|
1014
|
-
const directLaunch = process.platform === "win32"
|
|
1015
|
-
? await resolveCursorAgentDirectLaunch(probe.command, probe.args)
|
|
1016
|
-
: null;
|
|
1017
|
-
if (directLaunch) {
|
|
1018
|
-
return await execFileAsync(directLaunch.command, [...directLaunch.args], { timeout });
|
|
1019
|
-
}
|
|
1020
|
-
try {
|
|
1021
|
-
return await execFileAsync(probe.command, probe.args, { timeout });
|
|
1022
|
-
}
|
|
1023
|
-
catch (error) {
|
|
1024
|
-
if (process.platform !== "win32") {
|
|
1025
|
-
throw error;
|
|
1026
|
-
}
|
|
1027
|
-
const launch = buildWindowsCmdLaunch(probe.command, probe.args);
|
|
1028
|
-
return await execFileAsync(launch.command, [...launch.args], { timeout });
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
function versionLine(output) {
|
|
1032
|
-
const lines = output
|
|
1033
|
-
.trim()
|
|
1034
|
-
.split(/\r?\n/)
|
|
1035
|
-
.map((line) => line.trim())
|
|
1036
|
-
.filter((line) => line.length > 0);
|
|
1037
|
-
return lines.at(-1) ?? "";
|
|
1038
|
-
}
|
|
1039
|
-
async function detectCliModels(provider) {
|
|
1040
|
-
const normalized = provider.toLowerCase();
|
|
1041
|
-
try {
|
|
1042
|
-
if (normalized === "codex") {
|
|
1043
|
-
const result = await execFileAsync("codex", ["debug", "models"], { timeout: 5000, maxBuffer: 10 * 1024 * 1024 });
|
|
1044
|
-
return parseCodexModelCatalog(result.stdout);
|
|
1045
|
-
}
|
|
1046
|
-
if (normalized === "cursor") {
|
|
1047
|
-
const result = await execVersionCommand({ command: "cursor-agent", args: ["models"] }, 10_000);
|
|
1048
|
-
return parseCursorModelList(`${result.stdout || result.stderr}`);
|
|
1049
|
-
}
|
|
1050
|
-
}
|
|
1051
|
-
catch {
|
|
1052
|
-
return [];
|
|
1053
|
-
}
|
|
1054
|
-
return [];
|
|
1055
|
-
}
|
|
1056
|
-
export function parseCodexModelCatalog(raw) {
|
|
1057
|
-
try {
|
|
1058
|
-
const parsed = JSON.parse(raw);
|
|
1059
|
-
if (!isRecord(parsed) || !Array.isArray(parsed.models)) {
|
|
1060
|
-
return [];
|
|
1061
|
-
}
|
|
1062
|
-
const entries = parsed.models
|
|
1063
|
-
.map((entry, index) => {
|
|
1064
|
-
if (!isRecord(entry) || typeof entry.slug !== "string") {
|
|
1065
|
-
return null;
|
|
1066
|
-
}
|
|
1067
|
-
const visibility = typeof entry.visibility === "string" ? entry.visibility.toLowerCase() : "list";
|
|
1068
|
-
if (visibility !== "list") {
|
|
1069
|
-
return null;
|
|
1070
|
-
}
|
|
1071
|
-
const priority = typeof entry.priority === "number" && Number.isFinite(entry.priority) ? entry.priority : index;
|
|
1072
|
-
return { slug: entry.slug, priority, index };
|
|
1073
|
-
})
|
|
1074
|
-
.filter((entry) => entry !== null)
|
|
1075
|
-
.sort((left, right) => left.priority - right.priority || left.index - right.index)
|
|
1076
|
-
.map((entry) => entry.slug);
|
|
1077
|
-
return uniqueModels(entries);
|
|
1078
|
-
}
|
|
1079
|
-
catch {
|
|
1080
|
-
return [];
|
|
1081
|
-
}
|
|
1082
|
-
}
|
|
1083
|
-
export function parseCursorModelList(raw) {
|
|
1084
|
-
return uniqueModels(raw
|
|
1085
|
-
.split(/\r?\n/)
|
|
1086
|
-
.map((line) => line.trim())
|
|
1087
|
-
.filter((line) => line.length > 0 && !line.toLowerCase().startsWith("available models"))
|
|
1088
|
-
.map((line) => line.split(/\s+-\s+/, 1)[0]?.trim() ?? "")
|
|
1089
|
-
.filter((model) => model.length > 0));
|
|
1090
|
-
}
|
|
1091
|
-
function uniqueModels(models) {
|
|
1092
|
-
const seen = new Set();
|
|
1093
|
-
const result = [];
|
|
1094
|
-
for (const model of models) {
|
|
1095
|
-
const trimmed = model.trim();
|
|
1096
|
-
const key = trimmed.toLowerCase();
|
|
1097
|
-
if (!trimmed || seen.has(key)) {
|
|
1098
|
-
continue;
|
|
1099
|
-
}
|
|
1100
|
-
seen.add(key);
|
|
1101
|
-
result.push(trimmed);
|
|
1102
|
-
}
|
|
1103
|
-
return result;
|
|
1104
|
-
}
|
|
1105
|
-
function isRecord(value) {
|
|
1106
|
-
return typeof value === "object" && value !== null;
|
|
1107
|
-
}
|
|
1108
|
-
async function withDetectedCliProviders(config) {
|
|
1109
|
-
const detected = await detectCliProviders(configuredProviderCandidates(config.cliProviders));
|
|
1131
|
+
async function withDetectedCliProviders(config, candidates = config.cliProviders) {
|
|
1132
|
+
const detected = await detectCliProviders(uniqueProviders(candidates));
|
|
1110
1133
|
const found = detected.filter((result) => result.found);
|
|
1111
1134
|
if (found.length === 0) {
|
|
1112
1135
|
return config;
|
|
@@ -1130,6 +1153,7 @@ async function withDetectedCliProviders(config) {
|
|
|
1130
1153
|
};
|
|
1131
1154
|
}
|
|
1132
1155
|
async function withDetectedPairCliProviders(args) {
|
|
1156
|
+
const configured = configuredProviderCandidates(args.cliProviders);
|
|
1133
1157
|
const detectedConfig = await withDetectedCliProviders({
|
|
1134
1158
|
...defaultBridgeServiceConfig({
|
|
1135
1159
|
serverUrl: args.serverUrl,
|
|
@@ -1139,14 +1163,14 @@ async function withDetectedPairCliProviders(args) {
|
|
|
1139
1163
|
cleanupWorktrees: args.cleanupWorktrees,
|
|
1140
1164
|
defaultRepoRoot: args.repoRoot ?? defaultBridgeServiceConfig().defaultRepoRoot
|
|
1141
1165
|
})
|
|
1142
|
-
});
|
|
1166
|
+
}, configured);
|
|
1143
1167
|
return {
|
|
1144
1168
|
...args,
|
|
1145
1169
|
cliProviders: detectedConfig.cliProviders
|
|
1146
1170
|
};
|
|
1147
1171
|
}
|
|
1148
1172
|
function configuredProviderCandidates(providers) {
|
|
1149
|
-
return uniqueProviders([...providers, "codex", "cursor"]);
|
|
1173
|
+
return uniqueProviders([...providers, "codex", "cursor", "claude"]);
|
|
1150
1174
|
}
|
|
1151
1175
|
function uniqueProviders(providers) {
|
|
1152
1176
|
return providers
|
|
@@ -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
|
+
};
|