@loucompanion/forge-bridge 0.1.4-dev.fb770705136a → 0.2.1-dev.0f8fb73715e8
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
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { evaluateBridgeIdle, formatAge, isProcessAlive, readBridgeStateFile, } from "../bridge/bridge-state-file.js";
|
|
2
|
+
import { describeInFlightIds } from "../bridge/in-flight-registry.js";
|
|
3
|
+
import { readLocalYieldFlag } from "../bridge/local-yield-flag.js";
|
|
4
|
+
import { resolveBridgeStatePath, resolveLocalYieldFlagPath } from "./local-config.js";
|
|
5
|
+
const statusUsage = "Usage: forge-bridge status [--check-updates] | forge-bridge status --idle [--require-yield] [--json] [--wait <seconds>]";
|
|
6
|
+
export function parseStatusArgs(argv, config) {
|
|
7
|
+
// --wait is tracked apart from its value: `--wait 0` without --idle is the same usage error as `--wait 5`.
|
|
8
|
+
const flags = { checkUpdates: false, idle: false, json: false, requireYield: false, waitSeconds: null };
|
|
9
|
+
const switches = {
|
|
10
|
+
"--check-updates": "checkUpdates", "--idle": "idle", "--json": "json", "--require-yield": "requireYield",
|
|
11
|
+
};
|
|
12
|
+
for (let index = 1; index < argv.length; index += 1) {
|
|
13
|
+
const arg = argv[index];
|
|
14
|
+
if (Object.hasOwn(switches, arg)) {
|
|
15
|
+
flags[switches[arg]] = true;
|
|
16
|
+
}
|
|
17
|
+
else if (arg === "--wait") {
|
|
18
|
+
const seconds = Number(argv[++index]);
|
|
19
|
+
if (!Number.isFinite(seconds) || seconds < 0)
|
|
20
|
+
return { ok: false, error: "--wait requires a number of seconds (0 or more)." };
|
|
21
|
+
flags.waitSeconds = seconds;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
return { ok: false, error: `Unknown argument: ${arg}\n${statusUsage}` };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (!flags.idle && (flags.json || flags.requireYield || flags.waitSeconds !== null)) {
|
|
28
|
+
return { ok: false, error: `--json, --require-yield and --wait apply to --idle.\n${statusUsage}` };
|
|
29
|
+
}
|
|
30
|
+
if (flags.idle && flags.checkUpdates) {
|
|
31
|
+
return { ok: false, error: `--check-updates cannot be combined with --idle.\n${statusUsage}` };
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
ok: true,
|
|
35
|
+
command: "status",
|
|
36
|
+
config: config(),
|
|
37
|
+
checkUpdates: flags.checkUpdates,
|
|
38
|
+
idle: flags.idle ? { json: flags.json, waitSeconds: flags.waitSeconds ?? 0, requireYield: flags.requireYield } : null,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export function defaultIdleStatusDependencies() {
|
|
42
|
+
return {
|
|
43
|
+
statePath: resolveBridgeStatePath(),
|
|
44
|
+
now: () => Date.now(),
|
|
45
|
+
pidAlive: isProcessAlive,
|
|
46
|
+
read: readBridgeStateFile,
|
|
47
|
+
localYield: () => readLocalYieldFlag(resolveLocalYieldFlagPath()),
|
|
48
|
+
sleep: ms => new Promise(resolve => setTimeout(resolve, ms)),
|
|
49
|
+
pollMs: 2_000,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export async function runIdleStatusCommand(options, io, deps = defaultIdleStatusDependencies()) {
|
|
53
|
+
const check = async () => evaluateBridgeIdle(await deps.read(deps.statePath), {
|
|
54
|
+
now: deps.now(),
|
|
55
|
+
pidAlive: deps.pidAlive,
|
|
56
|
+
requireYield: options.requireYield,
|
|
57
|
+
});
|
|
58
|
+
let evaluation = await check();
|
|
59
|
+
const deadline = deps.now() + options.waitSeconds * 1000;
|
|
60
|
+
if (worthWaiting(evaluation) && deps.now() < deadline && !options.json) {
|
|
61
|
+
io.stderr.write(`Waiting up to ${options.waitSeconds}s for the bridge to become idle (${evaluation.verdict})...\n`);
|
|
62
|
+
}
|
|
63
|
+
while (worthWaiting(evaluation) && deps.now() < deadline) {
|
|
64
|
+
await deps.sleep(Math.max(1, Math.min(deps.pollMs, deadline - deps.now())));
|
|
65
|
+
evaluation = await check();
|
|
66
|
+
}
|
|
67
|
+
const localYield = await deps.localYield().catch(() => false);
|
|
68
|
+
if (options.json) {
|
|
69
|
+
io.stdout.write(`${JSON.stringify(idleStatusJson(evaluation, deps, localYield), null, 2)}\n`);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
io.stdout.write(idleStatusText(evaluation, deps, localYield));
|
|
73
|
+
}
|
|
74
|
+
return evaluation.exitCode;
|
|
75
|
+
}
|
|
76
|
+
/** One line for plain `forge-bridge status`. */
|
|
77
|
+
export async function idleSummaryLine(deps = defaultIdleStatusDependencies()) {
|
|
78
|
+
const evaluation = evaluateBridgeIdle(await deps.read(deps.statePath), { now: deps.now(), pidAlive: deps.pidAlive });
|
|
79
|
+
return `${verdictTitles[evaluation.verdict]}: ${evaluation.reason} Details: forge-bridge status --idle`;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Busy work finishes, yield reaches Forge within a heartbeat, a stale heartbeat can recover and an
|
|
83
|
+
* unreadable or missing file can be a reader holding it (antivirus, the indexer) or a bridge
|
|
84
|
+
* starting. Only a dead bridge process will not change by waiting.
|
|
85
|
+
*/
|
|
86
|
+
function worthWaiting(evaluation) {
|
|
87
|
+
return evaluation.verdict !== "idle" && evaluation.verdict !== "not_running";
|
|
88
|
+
}
|
|
89
|
+
export function idleStatusJson(evaluation, deps, localYield) {
|
|
90
|
+
return {
|
|
91
|
+
schemaVersion: 1,
|
|
92
|
+
verdict: evaluation.verdict,
|
|
93
|
+
idle: evaluation.verdict === "idle",
|
|
94
|
+
exitCode: evaluation.exitCode,
|
|
95
|
+
reason: evaluation.reason,
|
|
96
|
+
statePath: deps.statePath,
|
|
97
|
+
checkedAt: new Date(deps.now()).toISOString(),
|
|
98
|
+
pidAlive: evaluation.pidAlive,
|
|
99
|
+
heartbeatAgeMs: evaluation.heartbeatAgeMs,
|
|
100
|
+
staleAfterMs: evaluation.staleAfterMs,
|
|
101
|
+
localYield,
|
|
102
|
+
...publishedStateFields(evaluation.state),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function publishedStateFields(state) {
|
|
106
|
+
if (!state) {
|
|
107
|
+
return {
|
|
108
|
+
pid: null, runnerId: null, runnerInstanceId: null, version: null, state: null, startedAt: null,
|
|
109
|
+
updatedAt: null, connected: null, yielding: null, yieldApplied: null, conflict: null, inFlight: [],
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
pid: state.pid,
|
|
114
|
+
runnerId: state.runnerId,
|
|
115
|
+
runnerInstanceId: state.runnerInstanceId,
|
|
116
|
+
version: state.version,
|
|
117
|
+
state: state.state,
|
|
118
|
+
startedAt: state.startedAt,
|
|
119
|
+
updatedAt: state.updatedAt,
|
|
120
|
+
connected: state.connected,
|
|
121
|
+
yielding: state.yielding,
|
|
122
|
+
yieldApplied: state.yieldApplied ?? state.yielding,
|
|
123
|
+
conflict: state.conflict ?? null,
|
|
124
|
+
inFlight: state.inFlight,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
const verdictTitles = {
|
|
128
|
+
idle: "Bridge idle",
|
|
129
|
+
busy: "Bridge busy",
|
|
130
|
+
not_yielding: "Bridge idle but not yielding",
|
|
131
|
+
stale: "Bridge state stale",
|
|
132
|
+
unknown: "Bridge state unknown",
|
|
133
|
+
not_running: "Bridge not running",
|
|
134
|
+
};
|
|
135
|
+
function idleStatusText(evaluation, deps, localYield) {
|
|
136
|
+
const state = evaluation.state;
|
|
137
|
+
const lines = [`${verdictTitles[evaluation.verdict]}: ${evaluation.reason}`, `State file: ${deps.statePath}`];
|
|
138
|
+
if (state) {
|
|
139
|
+
lines.push(`Process: pid ${state.pid} (${evaluation.pidAlive ? "running" : "not running"}), runner ${state.runnerId || "unknown"}, instance ${state.runnerInstanceId}, bridge ${state.version}`, `Heartbeat: ${state.updatedAt} (${formatAge(evaluation.heartbeatAgeMs ?? Number.NaN)} ago, stale after ${formatAge(evaluation.staleAfterMs)}); connected to Forge: ${state.connected ? "yes" : "no"}`, `Yield: ${yieldLine(state)} (local flag ${localYield ? "on" : "off"})`);
|
|
140
|
+
lines.push(...inFlightLines(state.inFlight, deps.now()));
|
|
141
|
+
}
|
|
142
|
+
lines.push(nextStep(evaluation, localYield));
|
|
143
|
+
return `${lines.join("\n")}\n`;
|
|
144
|
+
}
|
|
145
|
+
function inFlightLines(entries, now) {
|
|
146
|
+
if (entries.length === 0)
|
|
147
|
+
return ["In flight: nothing"];
|
|
148
|
+
return ["In flight:", ...entries.map(entry => {
|
|
149
|
+
const phaseAge = entry.phaseSince ? ` for ${formatAge(now - Date.parse(entry.phaseSince))}` : "";
|
|
150
|
+
const since = entry.since ? `, since ${entry.since}` : "";
|
|
151
|
+
return ` - ${entry.kind}: phase ${entry.phase}${phaseAge}${since}; ${describeInFlightIds(entry.ids)}`;
|
|
152
|
+
})];
|
|
153
|
+
}
|
|
154
|
+
function nextStep(evaluation, localYield) {
|
|
155
|
+
switch (evaluation.verdict) {
|
|
156
|
+
case "idle":
|
|
157
|
+
return evaluation.state?.yielding ? "Safe to restart now. After the new bridge connects, run `forge-bridge yield off` so it takes work again." : idleWithoutYieldStep(localYield);
|
|
158
|
+
case "not_yielding":
|
|
159
|
+
return evaluation.state?.yieldApplied
|
|
160
|
+
? "The bridge applies yield but Forge has not acknowledged it yet (at most one heartbeat). Check again before restarting."
|
|
161
|
+
: idleWithoutYieldStep(localYield);
|
|
162
|
+
case "busy":
|
|
163
|
+
return "Do not restart. Run `forge-bridge yield on`, then `forge-bridge status --idle --require-yield --wait <seconds>` until it exits 0.";
|
|
164
|
+
case "not_running":
|
|
165
|
+
return "Nothing to interrupt, but confirm no other bridge process serves this runner before starting one.";
|
|
166
|
+
default:
|
|
167
|
+
return "Do not restart on this result: idle could not be confirmed.";
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function yieldLine(state) {
|
|
171
|
+
if (state.yielding)
|
|
172
|
+
return "on and acknowledged by Forge, no new attempts";
|
|
173
|
+
return state.yieldApplied ? "applied, waiting for Forge to acknowledge it" : "off, Forge can still send new work";
|
|
174
|
+
}
|
|
175
|
+
// The bridge's own report is what counts: a flag written from another environment
|
|
176
|
+
// (another user, FORGE_BRIDGE_CONFIG, or a sandbox that virtualizes %APPDATA%) never reaches it.
|
|
177
|
+
function idleWithoutYieldStep(localYield) {
|
|
178
|
+
return localYield
|
|
179
|
+
? "The local yield flag is on but the bridge has not reported yield yet. It picks the flag up within one heartbeat; if it never does, this flag file is not the one the bridge reads. Check again before restarting."
|
|
180
|
+
: "Idle now, but yield is off: run `forge-bridge yield on` and check again with --require-yield so no new work starts before the restart.";
|
|
181
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type BridgeProviderStatus, type BridgeRepoMapping, type BridgeServiceConfig, type DerivedCapabilityField } from "../bridge/bridge.types.js";
|
|
2
2
|
export interface BridgeLocalConfig {
|
|
3
3
|
readonly schemaVersion: 1 | 2;
|
|
4
4
|
readonly serverUrl?: string;
|
|
@@ -10,6 +10,8 @@ export interface BridgeLocalConfig {
|
|
|
10
10
|
readonly dockerEnabled?: boolean;
|
|
11
11
|
readonly dockerDesktopRecoveryEnabled?: boolean;
|
|
12
12
|
readonly allowOpenPublicSandbox?: boolean;
|
|
13
|
+
/** Run Forge PR reviews on this host when they are not placed in the Docker sandbox. Default false. */
|
|
14
|
+
readonly allowUnsandboxedPrReview?: boolean;
|
|
13
15
|
readonly cliProviders?: readonly string[];
|
|
14
16
|
readonly providerStatuses?: Readonly<Record<string, BridgeProviderStatus>>;
|
|
15
17
|
readonly projectLabels?: readonly string[];
|
|
@@ -22,6 +24,13 @@ export interface BridgeLocalConfig {
|
|
|
22
24
|
readonly supportsDraftRunOnce?: boolean;
|
|
23
25
|
readonly supportsDraftAttachments?: boolean;
|
|
24
26
|
readonly supportsDraftImageAttachments?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The capability fields in this file that `pair` derived from cliProviders rather than the user
|
|
29
|
+
* setting them. `connect` may re-derive these when it detects a new provider CLI; any other
|
|
30
|
+
* field present here is the user's choice and is kept. Files written before this marker
|
|
31
|
+
* existed don't have it (see `capabilitySourcesFor`).
|
|
32
|
+
*/
|
|
33
|
+
readonly derivedCapabilities?: readonly DerivedCapabilityField[];
|
|
25
34
|
}
|
|
26
35
|
export interface LocalRepoMapping extends BridgeRepoMapping {
|
|
27
36
|
readonly label: string;
|
|
@@ -30,8 +39,14 @@ export interface LocalRepoMapping extends BridgeRepoMapping {
|
|
|
30
39
|
export declare function resolveLocalConfigPath(): string;
|
|
31
40
|
export declare function readLocalConfig(): Promise<BridgeLocalConfig>;
|
|
32
41
|
export declare function readLocalConfigSync(): BridgeLocalConfig;
|
|
42
|
+
/** Decision 0014 §5: `bridge.json` holds the device token, so only its owner may read it. */
|
|
43
|
+
export declare const localConfigFileMode = 384;
|
|
33
44
|
export declare function writeLocalConfig(config: BridgeLocalConfig): Promise<void>;
|
|
34
45
|
export declare function applyLocalConfigDefaults(config: BridgeServiceConfig, local: BridgeLocalConfig): BridgeServiceConfig;
|
|
46
|
+
/** Where `forge-bridge connect` publishes whether it is idle: `bridge.state.json` beside the config. */
|
|
47
|
+
export declare function resolveBridgeStatePath(): string;
|
|
48
|
+
/** Decision 0014: the `forge-bridge yield` flag, beside the bridge config and never inside it. */
|
|
49
|
+
export declare function resolveLocalYieldFlagPath(): string;
|
|
35
50
|
export declare function addRepoMapping(label: string, repoPath: string): Promise<BridgeLocalConfig>;
|
|
36
51
|
export declare function removeRepoMapping(label: string): Promise<{
|
|
37
52
|
readonly config: BridgeLocalConfig;
|
|
@@ -40,3 +55,5 @@ export declare function removeRepoMapping(label: string): Promise<{
|
|
|
40
55
|
export declare function setServerUrl(serverUrl: string): Promise<BridgeLocalConfig>;
|
|
41
56
|
export declare function setSandboxPolicy(dockerEnabled: boolean, allowOpenPublicSandbox: boolean): Promise<BridgeLocalConfig>;
|
|
42
57
|
export declare function providerStatusesFor(providers: readonly string[]): Readonly<Record<string, BridgeProviderStatus>>;
|
|
58
|
+
/** The capability fields `pair` derives, and marks as derived, when it writes bridge.json. */
|
|
59
|
+
export declare function pairDerivedCapabilities(current: BridgeLocalConfig, cliProviders: readonly string[]): Pick<BridgeLocalConfig, "supportsDraftImageAttachments" | "derivedCapabilities">;
|
package/dist/cli/local-config.js
CHANGED
|
@@ -2,6 +2,10 @@ import fs from "node:fs/promises";
|
|
|
2
2
|
import fsSync from "node:fs";
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
|
+
import { derivedCapabilityFields, } from "../bridge/bridge.types.js";
|
|
6
|
+
import { supportsDraftImageAttachmentsFor } from "../shared/provider-capabilities.js";
|
|
7
|
+
import { localYieldFlagPathFor } from "../bridge/local-yield-flag.js";
|
|
8
|
+
import { bridgeStatePathFor } from "../bridge/bridge-state-file.js";
|
|
5
9
|
export function resolveLocalConfigPath() {
|
|
6
10
|
if (process.env.FORGE_BRIDGE_CONFIG?.trim()) {
|
|
7
11
|
return path.resolve(process.env.FORGE_BRIDGE_CONFIG);
|
|
@@ -28,12 +32,28 @@ export function readLocalConfigSync() {
|
|
|
28
32
|
}
|
|
29
33
|
return parseLocalConfig(fsSync.readFileSync(configPath, "utf8"));
|
|
30
34
|
}
|
|
35
|
+
/** Decision 0014 §5: `bridge.json` holds the device token, so only its owner may read it. */
|
|
36
|
+
export const localConfigFileMode = 0o600;
|
|
37
|
+
const localConfigDirectoryMode = 0o700;
|
|
31
38
|
export async function writeLocalConfig(config) {
|
|
32
39
|
const configPath = resolveLocalConfigPath();
|
|
33
|
-
await fs.mkdir(path.dirname(configPath), { recursive: true });
|
|
40
|
+
await fs.mkdir(path.dirname(configPath), { recursive: true, mode: localConfigDirectoryMode });
|
|
34
41
|
const tempPath = `${configPath}.${process.pid}.${Date.now()}.tmp`;
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
try {
|
|
43
|
+
await fs.writeFile(tempPath, `${JSON.stringify(normalizeLocalConfig(config), null, 2)}\n`, {
|
|
44
|
+
encoding: "utf8",
|
|
45
|
+
mode: localConfigFileMode
|
|
46
|
+
});
|
|
47
|
+
if (process.platform !== "win32") {
|
|
48
|
+
// The create mode is masked by the umask; set it exactly before the file becomes visible.
|
|
49
|
+
await fs.chmod(tempPath, localConfigFileMode);
|
|
50
|
+
}
|
|
51
|
+
await fs.rename(tempPath, configPath);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
await fs.rm(tempPath, { force: true }).catch(() => undefined);
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
37
57
|
}
|
|
38
58
|
export function applyLocalConfigDefaults(config, local) {
|
|
39
59
|
const cliProviders = local.cliProviders && local.cliProviders.length > 0 ? [...local.cliProviders] : config.cliProviders;
|
|
@@ -54,6 +74,8 @@ export function applyLocalConfigDefaults(config, local) {
|
|
|
54
74
|
allowOpenPublicSandbox: process.env.FORGE_ALLOW_OPEN_PUBLIC_SANDBOX === undefined
|
|
55
75
|
? local.allowOpenPublicSandbox ?? config.allowOpenPublicSandbox
|
|
56
76
|
: config.allowOpenPublicSandbox,
|
|
77
|
+
// Only an explicit true in bridge.json opts in; there is no environment override.
|
|
78
|
+
allowUnsandboxedPrReview: local.allowUnsandboxedPrReview === true,
|
|
57
79
|
cliProviders,
|
|
58
80
|
providerStatuses: normalizeProviderStatuses(local.providerStatuses) ?? providerStatusesFor(cliProviders),
|
|
59
81
|
projectLabels: local.projectLabels ?? config.projectLabels,
|
|
@@ -65,9 +87,20 @@ export function applyLocalConfigDefaults(config, local) {
|
|
|
65
87
|
supportsRunnerAuthoredPhaseArtifacts: local.supportsRunnerAuthoredPhaseArtifacts ?? config.supportsRunnerAuthoredPhaseArtifacts,
|
|
66
88
|
supportsDraftRunOnce: local.supportsDraftRunOnce ?? config.supportsDraftRunOnce,
|
|
67
89
|
supportsDraftAttachments: local.supportsDraftAttachments ?? config.supportsDraftAttachments,
|
|
68
|
-
supportsDraftImageAttachments: local.supportsDraftImageAttachments ?? config.supportsDraftImageAttachments
|
|
90
|
+
supportsDraftImageAttachments: local.supportsDraftImageAttachments ?? config.supportsDraftImageAttachments,
|
|
91
|
+
capabilitySources: capabilitySourcesFor(local),
|
|
92
|
+
localYieldFlagPath: resolveLocalYieldFlagPath(),
|
|
93
|
+
bridgeStatePath: resolveBridgeStatePath()
|
|
69
94
|
};
|
|
70
95
|
}
|
|
96
|
+
/** Where `forge-bridge connect` publishes whether it is idle: `bridge.state.json` beside the config. */
|
|
97
|
+
export function resolveBridgeStatePath() {
|
|
98
|
+
return bridgeStatePathFor(resolveLocalConfigPath());
|
|
99
|
+
}
|
|
100
|
+
/** Decision 0014: the `forge-bridge yield` flag, beside the bridge config and never inside it. */
|
|
101
|
+
export function resolveLocalYieldFlagPath() {
|
|
102
|
+
return localYieldFlagPathFor(resolveLocalConfigPath());
|
|
103
|
+
}
|
|
71
104
|
export async function addRepoMapping(label, repoPath) {
|
|
72
105
|
const normalizedLabel = normalizeLabel(label);
|
|
73
106
|
const localPath = path.resolve(repoPath);
|
|
@@ -131,6 +164,7 @@ function normalizeLocalConfig(config) {
|
|
|
131
164
|
dockerEnabled: config.dockerEnabled,
|
|
132
165
|
dockerDesktopRecoveryEnabled: config.dockerDesktopRecoveryEnabled,
|
|
133
166
|
allowOpenPublicSandbox: config.allowOpenPublicSandbox,
|
|
167
|
+
allowUnsandboxedPrReview: config.allowUnsandboxedPrReview === true ? true : undefined,
|
|
134
168
|
cliProviders: cleanList(config.cliProviders),
|
|
135
169
|
providerStatuses: normalizeProviderStatuses(config.providerStatuses),
|
|
136
170
|
projectLabels: cleanList(config.projectLabels),
|
|
@@ -142,9 +176,37 @@ function normalizeLocalConfig(config) {
|
|
|
142
176
|
supportsRunnerAuthoredPhaseArtifacts: config.supportsRunnerAuthoredPhaseArtifacts,
|
|
143
177
|
supportsDraftRunOnce: config.supportsDraftRunOnce,
|
|
144
178
|
supportsDraftAttachments: config.supportsDraftAttachments,
|
|
145
|
-
supportsDraftImageAttachments: config.supportsDraftImageAttachments
|
|
179
|
+
supportsDraftImageAttachments: config.supportsDraftImageAttachments,
|
|
180
|
+
derivedCapabilities: Array.isArray(config.derivedCapabilities)
|
|
181
|
+
? derivedCapabilityFields.filter((field) => config.derivedCapabilities.includes(field))
|
|
182
|
+
: undefined
|
|
146
183
|
};
|
|
147
184
|
}
|
|
185
|
+
/** The capability fields `pair` derives, and marks as derived, when it writes bridge.json. */
|
|
186
|
+
export function pairDerivedCapabilities(current, cliProviders) {
|
|
187
|
+
return {
|
|
188
|
+
supportsDraftImageAttachments: supportsDraftImageAttachmentsFor(cliProviders),
|
|
189
|
+
derivedCapabilities: derivedCapabilityFields.filter((field) => field === "supportsDraftImageAttachments" || current.derivedCapabilities?.includes(field)),
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Where each derived capability's value comes from. A field bridge.json doesn't set comes from the
|
|
194
|
+
* defaults, so it is derived. A field it sets is derived when the file's marker lists it, and the
|
|
195
|
+
* user's choice when the marker doesn't. Without a marker (a file written before it existed) the
|
|
196
|
+
* source is unknown and gets no entry.
|
|
197
|
+
*/
|
|
198
|
+
function capabilitySourcesFor(local) {
|
|
199
|
+
const sources = {};
|
|
200
|
+
for (const field of derivedCapabilityFields) {
|
|
201
|
+
if (local[field] === undefined || local.derivedCapabilities?.includes(field)) {
|
|
202
|
+
sources[field] = "derived";
|
|
203
|
+
}
|
|
204
|
+
else if (local.derivedCapabilities !== undefined) {
|
|
205
|
+
sources[field] = "explicit";
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return sources;
|
|
209
|
+
}
|
|
148
210
|
function emptyConfig() {
|
|
149
211
|
return {
|
|
150
212
|
schemaVersion: 2,
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { BridgeServiceConfig } from "../bridge/bridge.types.js";
|
|
2
|
+
import { type CliProviderDetection } from "./provider-cli-detection.js";
|
|
3
|
+
/** Every provider CLI the bridge knows how to detect. */
|
|
4
|
+
export declare const knownCliProviders: readonly string[];
|
|
5
|
+
/** The configured providers followed by every known provider, without duplicates. */
|
|
6
|
+
export declare function knownProviderCandidates(providers: readonly string[]): string[];
|
|
7
|
+
/** Probes the configured providers and every known provider, for `forge-bridge status`. */
|
|
8
|
+
export declare function detectKnownCliProviders(configured: readonly string[]): Promise<CliProviderDetection[]>;
|
|
9
|
+
/**
|
|
10
|
+
* Probes `candidates` and adds the ones found to the advertised providers, with their detected
|
|
11
|
+
* version and models.
|
|
12
|
+
*
|
|
13
|
+
* A configured provider that is no longer found stays advertised with its saved status: the probe
|
|
14
|
+
* can miss a CLI that still works (a PATH the bridge's shell doesn't see, a cold-start timeout),
|
|
15
|
+
* and dropping it would take a working runner away. Detection only ever adds providers.
|
|
16
|
+
*
|
|
17
|
+
* Capabilities derived from the provider list (image attachments, default sandbox profiles) are
|
|
18
|
+
* re-derived for the added providers; see `withRederivedCapabilities`.
|
|
19
|
+
*
|
|
20
|
+
* Advertising a provider doesn't mean the bridge will launch it: a provider whose user
|
|
21
|
+
* configuration Forge can't shut out (cursor) is still refused at launch
|
|
22
|
+
* (`provider-user-config-isolation.ts`).
|
|
23
|
+
*/
|
|
24
|
+
export declare function withDetectedCliProviders(config: BridgeServiceConfig, candidates?: readonly string[]): Promise<BridgeServiceConfig>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { defaultSandboxProfiles, supportsDraftImageAttachmentsFor } from "../shared/provider-capabilities.js";
|
|
2
|
+
import { providerStatusesFor } from "./local-config.js";
|
|
3
|
+
import { detectCliProviders } from "./provider-cli-detection.js";
|
|
4
|
+
// Which provider CLIs `forge-bridge connect` and `pair` advertise to Forge. Split out of
|
|
5
|
+
// cli.service.ts (file-size inventory plan).
|
|
6
|
+
/** Every provider CLI the bridge knows how to detect. */
|
|
7
|
+
export const knownCliProviders = Object.freeze(["codex", "cursor", "claude"]);
|
|
8
|
+
/** The configured providers followed by every known provider, without duplicates. */
|
|
9
|
+
export function knownProviderCandidates(providers) {
|
|
10
|
+
return uniqueProviders([...providers, ...knownCliProviders]);
|
|
11
|
+
}
|
|
12
|
+
/** Probes the configured providers and every known provider, for `forge-bridge status`. */
|
|
13
|
+
export async function detectKnownCliProviders(configured) {
|
|
14
|
+
return await detectCliProviders(knownProviderCandidates(configured));
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Probes `candidates` and adds the ones found to the advertised providers, with their detected
|
|
18
|
+
* version and models.
|
|
19
|
+
*
|
|
20
|
+
* A configured provider that is no longer found stays advertised with its saved status: the probe
|
|
21
|
+
* can miss a CLI that still works (a PATH the bridge's shell doesn't see, a cold-start timeout),
|
|
22
|
+
* and dropping it would take a working runner away. Detection only ever adds providers.
|
|
23
|
+
*
|
|
24
|
+
* Capabilities derived from the provider list (image attachments, default sandbox profiles) are
|
|
25
|
+
* re-derived for the added providers; see `withRederivedCapabilities`.
|
|
26
|
+
*
|
|
27
|
+
* Advertising a provider doesn't mean the bridge will launch it: a provider whose user
|
|
28
|
+
* configuration Forge can't shut out (cursor) is still refused at launch
|
|
29
|
+
* (`provider-user-config-isolation.ts`).
|
|
30
|
+
*/
|
|
31
|
+
export async function withDetectedCliProviders(config, candidates = config.cliProviders) {
|
|
32
|
+
const detected = await detectCliProviders(uniqueProviders(candidates));
|
|
33
|
+
const found = detected.filter((result) => result.found);
|
|
34
|
+
if (found.length === 0) {
|
|
35
|
+
return config;
|
|
36
|
+
}
|
|
37
|
+
const cliProviders = uniqueProviders([...config.cliProviders, ...found.map((result) => result.provider)]);
|
|
38
|
+
const providerStatuses = { ...config.providerStatuses };
|
|
39
|
+
for (const result of found) {
|
|
40
|
+
const existing = providerStatuses[result.provider];
|
|
41
|
+
providerStatuses[result.provider] = {
|
|
42
|
+
signedIn: existing?.signedIn ?? true,
|
|
43
|
+
version: result.version || existing?.version || "",
|
|
44
|
+
models: result.models.length > 0
|
|
45
|
+
? result.models
|
|
46
|
+
: existing?.models ?? providerStatusesFor([result.provider])[result.provider]?.models ?? []
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return withRederivedCapabilities(config, {
|
|
50
|
+
...config,
|
|
51
|
+
cliProviders,
|
|
52
|
+
providerStatuses
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Re-derives the capabilities that `pair` and the config defaults compute from the provider
|
|
57
|
+
* list, so a provider detected at connect gets them (codex's image attachments and sandbox).
|
|
58
|
+
* A field changes only when the added providers change what the list derives, so detection
|
|
59
|
+
* never turns a capability off. Then, by the field's source (`capabilitySources`):
|
|
60
|
+
* - derived: re-derived from the merged list;
|
|
61
|
+
* - explicit (the user set it in bridge.json): kept;
|
|
62
|
+
* - unknown (a bridge.json written before the marker): re-derived only while it still equals
|
|
63
|
+
* what the configured providers derive, since a value that differs must be the user's.
|
|
64
|
+
*/
|
|
65
|
+
function withRederivedCapabilities(before, after) {
|
|
66
|
+
const sources = before.capabilitySources ?? {};
|
|
67
|
+
return {
|
|
68
|
+
...after,
|
|
69
|
+
supportsDraftImageAttachments: rederive(sources.supportsDraftImageAttachments, before.supportsDraftImageAttachments, supportsDraftImageAttachmentsFor(before.cliProviders), supportsDraftImageAttachmentsFor(after.cliProviders), (left, right) => left === right),
|
|
70
|
+
sandboxProfiles: rederive(sources.sandboxProfiles, before.sandboxProfiles, defaultSandboxProfiles(before.cliProviders), defaultSandboxProfiles(after.cliProviders), sameList),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function rederive(source, current, fromConfigured, fromMerged, same) {
|
|
74
|
+
if (same(fromConfigured, fromMerged) || source === "explicit")
|
|
75
|
+
return current;
|
|
76
|
+
if (source === undefined && !same(current, fromConfigured))
|
|
77
|
+
return current;
|
|
78
|
+
return fromMerged;
|
|
79
|
+
}
|
|
80
|
+
function sameList(left, right) {
|
|
81
|
+
return left.length === right.length && left.every((value, index) => value.toLowerCase() === right[index]?.toLowerCase());
|
|
82
|
+
}
|
|
83
|
+
function uniqueProviders(providers) {
|
|
84
|
+
return providers
|
|
85
|
+
.map((provider) => provider.trim())
|
|
86
|
+
.filter((provider) => provider.length > 0)
|
|
87
|
+
.filter((provider, index, all) => all.findIndex((candidate) => candidate.toLowerCase() === provider.toLowerCase()) === index);
|
|
88
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface CliProviderDetection {
|
|
2
|
+
readonly provider: string;
|
|
3
|
+
readonly found: boolean;
|
|
4
|
+
readonly version: string;
|
|
5
|
+
readonly models: readonly string[];
|
|
6
|
+
}
|
|
7
|
+
export declare function detectCliProviders(providers: readonly string[]): Promise<CliProviderDetection[]>;
|
|
8
|
+
export declare const claudeDefaultModels: readonly string[];
|
|
9
|
+
export declare function parseCodexModelCatalog(raw: string): string[];
|
|
10
|
+
export declare function parseCursorModelList(raw: string): string[];
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
import { resolveCursorAgentDirectLaunch } from "../shared/cursor-agent/cursor-agent.launch.js";
|
|
4
|
+
import { buildWindowsCmdLaunch } from "../shared/process/windows-launch.js";
|
|
5
|
+
// Provider CLI detection probes for `forge-bridge status`, `connect` and `pair`: which
|
|
6
|
+
// provider CLIs are installed, their versions and the models they list. Split out of
|
|
7
|
+
// cli.service.ts (file-size inventory plan).
|
|
8
|
+
const execFileAsync = promisify(execFile);
|
|
9
|
+
export async function detectCliProviders(providers) {
|
|
10
|
+
const results = [];
|
|
11
|
+
for (const provider of providers) {
|
|
12
|
+
let detected = null;
|
|
13
|
+
for (const probe of cliProbeCommandsFor(provider)) {
|
|
14
|
+
try {
|
|
15
|
+
detected = await execVersionCommand(probe, probe.timeoutMs);
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
// Try the next provider-specific probe.
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
results.push({
|
|
23
|
+
provider,
|
|
24
|
+
found: detected !== null,
|
|
25
|
+
version: detected ? versionLine(`${detected.stdout || detected.stderr}`) : "",
|
|
26
|
+
models: detected ? await detectCliModels(provider) : []
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return results;
|
|
30
|
+
}
|
|
31
|
+
function cliProbeCommandsFor(provider) {
|
|
32
|
+
const normalized = provider.toLowerCase();
|
|
33
|
+
if (normalized === "codex") {
|
|
34
|
+
return [
|
|
35
|
+
{ command: "codex", args: ["-V"] },
|
|
36
|
+
{ command: "codex", args: ["--version"] }
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
if (normalized === "claude") {
|
|
40
|
+
return [
|
|
41
|
+
// Claude Code's Node startup can exceed the default 2s probe on a cold Windows host.
|
|
42
|
+
{ command: "claude", args: ["--version"], timeoutMs: 8000 },
|
|
43
|
+
{ command: "claude", args: ["-v"], timeoutMs: 8000 }
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
if (normalized === "cursor") {
|
|
47
|
+
return [
|
|
48
|
+
{ command: "cursor-agent", args: ["-v"] },
|
|
49
|
+
{ command: "agent", args: ["-v"] },
|
|
50
|
+
{ command: "cursor-agent", args: ["--version"] },
|
|
51
|
+
{ command: "agent", args: ["--version"] }
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
return [
|
|
55
|
+
{ command: provider, args: ["--version"] },
|
|
56
|
+
{ command: provider, args: ["-V"] }
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
async function execVersionCommand(probe, timeout = 2000, maxBuffer) {
|
|
60
|
+
const directLaunch = process.platform === "win32"
|
|
61
|
+
? await resolveCursorAgentDirectLaunch(probe.command, probe.args)
|
|
62
|
+
: null;
|
|
63
|
+
if (directLaunch) {
|
|
64
|
+
return await execFileAsync(directLaunch.command, [...directLaunch.args], { timeout, maxBuffer });
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
return await execFileAsync(probe.command, probe.args, { timeout, maxBuffer });
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
if (process.platform !== "win32") {
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
const launch = buildWindowsCmdLaunch(probe.command, probe.args);
|
|
74
|
+
return await execFileAsync(launch.command, [...launch.args], { timeout, maxBuffer });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function versionLine(output) {
|
|
78
|
+
const lines = output
|
|
79
|
+
.trim()
|
|
80
|
+
.split(/\r?\n/)
|
|
81
|
+
.map((line) => line.trim())
|
|
82
|
+
.filter((line) => line.length > 0);
|
|
83
|
+
return lines.at(-1) ?? "";
|
|
84
|
+
}
|
|
85
|
+
async function detectCliModels(provider) {
|
|
86
|
+
const normalized = provider.toLowerCase();
|
|
87
|
+
try {
|
|
88
|
+
if (normalized === "codex") {
|
|
89
|
+
// Windows installs codex as a .cmd shim, which execFile cannot launch directly.
|
|
90
|
+
const result = await execVersionCommand({ command: "codex", args: ["debug", "models"] }, 10_000, 10 * 1024 * 1024);
|
|
91
|
+
return parseCodexModelCatalog(result.stdout);
|
|
92
|
+
}
|
|
93
|
+
if (normalized === "cursor") {
|
|
94
|
+
const result = await execVersionCommand({ command: "cursor-agent", args: ["models"] }, 10_000);
|
|
95
|
+
return parseCursorModelList(`${result.stdout || result.stderr}`);
|
|
96
|
+
}
|
|
97
|
+
if (normalized === "claude") {
|
|
98
|
+
// Claude Code has no model-listing command; it accepts these aliases and full model IDs.
|
|
99
|
+
const configured = (process.env.FORGE_CLAUDE_MODELS ?? "").split(",").map(model => model.trim()).filter(Boolean);
|
|
100
|
+
return configured.length > 0 ? configured : [...claudeDefaultModels];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
export const claudeDefaultModels = ["sonnet", "opus", "haiku"];
|
|
109
|
+
export function parseCodexModelCatalog(raw) {
|
|
110
|
+
try {
|
|
111
|
+
const parsed = JSON.parse(raw);
|
|
112
|
+
if (!isRecord(parsed) || !Array.isArray(parsed.models)) {
|
|
113
|
+
return [];
|
|
114
|
+
}
|
|
115
|
+
const entries = parsed.models
|
|
116
|
+
.map((entry, index) => {
|
|
117
|
+
if (!isRecord(entry) || typeof entry.slug !== "string") {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
const visibility = typeof entry.visibility === "string" ? entry.visibility.toLowerCase() : "list";
|
|
121
|
+
if (visibility !== "list") {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
const priority = typeof entry.priority === "number" && Number.isFinite(entry.priority) ? entry.priority : index;
|
|
125
|
+
return { slug: entry.slug, priority, index };
|
|
126
|
+
})
|
|
127
|
+
.filter((entry) => entry !== null)
|
|
128
|
+
.sort((left, right) => left.priority - right.priority || left.index - right.index)
|
|
129
|
+
.map((entry) => entry.slug);
|
|
130
|
+
return uniqueModels(entries);
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
return [];
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
export function parseCursorModelList(raw) {
|
|
137
|
+
return uniqueModels(raw
|
|
138
|
+
.split(/\r?\n/)
|
|
139
|
+
.map((line) => line.trim())
|
|
140
|
+
.filter((line) => line.length > 0 && !line.toLowerCase().startsWith("available models"))
|
|
141
|
+
.map((line) => line.split(/\s+-\s+/, 1)[0]?.trim() ?? "")
|
|
142
|
+
.filter((model) => model.length > 0));
|
|
143
|
+
}
|
|
144
|
+
function uniqueModels(models) {
|
|
145
|
+
const seen = new Set();
|
|
146
|
+
const result = [];
|
|
147
|
+
for (const model of models) {
|
|
148
|
+
const trimmed = model.trim();
|
|
149
|
+
const key = trimmed.toLowerCase();
|
|
150
|
+
if (!trimmed || seen.has(key)) {
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
seen.add(key);
|
|
154
|
+
result.push(trimmed);
|
|
155
|
+
}
|
|
156
|
+
return result;
|
|
157
|
+
}
|
|
158
|
+
function isRecord(value) {
|
|
159
|
+
return typeof value === "object" && value !== null;
|
|
160
|
+
}
|