@loucompanion/forge-bridge 0.1.4-dev.f22f5e3d01fe → 0.2.1-dev.0f07274d438b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +128 -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 +27 -3
- package/dist/bridge/bridge-chat-provider-command.js +131 -26
- 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.service.d.ts +29 -12
- package/dist/bridge/bridge.service.js +215 -380
- package/dist/bridge/bridge.types.d.ts +21 -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/readiness-result-outbox.d.ts +5 -1
- package/dist/bridge/readiness-result-outbox.js +20 -0
- package/dist/bridge/runner-host-capabilities.js +14 -1
- package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
- package/dist/bridge/sandbox-resource-accounting.js +150 -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 +11 -1
- package/dist/cleanup/cleanup.service.js +80 -62
- package/dist/cleanup/cleanup.types.d.ts +2 -0
- package/dist/cleanup/forge-owned-paths.d.ts +2 -0
- package/dist/cleanup/forge-owned-paths.js +9 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +2 -0
- package/dist/cleanup/host-runtime-ledger.js +30 -9
- package/dist/cli/cli.help.js +57 -13
- package/dist/cli/cli.service.d.ts +3 -10
- package/dist/cli/cli.service.js +20 -213
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +14 -1
- package/dist/cli/local-config.js +42 -2
- 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 +104 -26
- 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-listener-inspector.d.ts +26 -0
- package/dist/runtime/host-listener-inspector.js +84 -3
- package/dist/runtime/host-load-admission.d.ts +5 -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 +13 -0
- package/dist/runtime/host-load-child-environment.js +35 -1
- package/dist/runtime/host-load-governor-config.d.ts +33 -3
- package/dist/runtime/host-load-governor-config.js +24 -3
- package/dist/runtime/host-load-governor.d.ts +91 -2
- package/dist/runtime/host-load-governor.js +217 -18
- package/dist/runtime/host-load-ledger-lock.js +6 -4
- 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.js +4 -2
- package/dist/runtime/host-load-sampler.d.ts +25 -1
- package/dist/runtime/host-load-sampler.js +38 -7
- package/dist/runtime/host-load-step-run.d.ts +37 -3
- package/dist/runtime/host-load-step-run.js +63 -7
- package/dist/runtime/host-load-test-slot.d.ts +3 -0
- package/dist/runtime/host-load-test-slot.js +26 -7
- package/dist/runtime/host-runtime-contract.d.ts +12 -0
- package/dist/runtime/host-runtime-contract.js +35 -5
- package/dist/runtime/host-runtime-lease.d.ts +28 -3
- package/dist/runtime/host-runtime-lease.js +140 -296
- 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 +78 -2
- package/dist/runtime/host-runtime-promotion.js +307 -14
- 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/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 +4 -0
- package/dist/runtime/runner-settings.js +22 -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 +3 -1
- package/dist/sandbox/host-capacity-broker.js +4 -2
- 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 +1 -2
- package/dist/sandbox/runtime.js +9 -19
- 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/managed-attempt-tools.d.ts +0 -7
- package/dist/session/managed-attempt-tools.js +54 -109
- 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 +10 -5
- package/dist/session/managed-command-host-load.js +18 -14
- 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 +2 -17
- package/dist/session/phase-completion.artifacts.js +65 -166
- package/dist/session/phase-completion.d.ts +27 -2
- package/dist/session/phase-completion.helpers.js +5 -53
- package/dist/session/phase-completion.js +15 -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 +14 -0
- package/dist/session/phase-completion.runtime.d.ts +8 -9
- package/dist/session/phase-completion.runtime.js +65 -196
- package/dist/session/phase-completion.schemas.js +12 -2
- package/dist/session/phase-completion.validation.d.ts +1 -0
- package/dist/session/phase-completion.validation.js +9 -1
- 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.js +6 -5
- 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-process.js +13 -12
- package/dist/session/pre-publication-step-execution.d.ts +2 -1
- package/dist/session/pre-publication-step-execution.js +6 -5
- package/dist/session/pre-publication-validation.d.ts +9 -4
- package/dist/session/pre-publication-validation.js +62 -65
- package/dist/session/provider-cli/claude-background-work.d.ts +3 -2
- package/dist/session/provider-cli/claude-background-work.js +4 -3
- 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 +16 -0
- package/dist/session/provider-cli/pre-publication-repair.js +41 -3
- package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +4 -2
- 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 +2 -14
- package/dist/session/provider-cli/provider-cli.process.js +4 -94
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +13 -3
- package/dist/session/provider-cli/provider-cli.prompts.js +137 -84
- 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 +37 -2
- 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 +15 -18
- package/dist/session/provider-cli/provider-cli.service.js +59 -190
- package/dist/session/provider-cli/provider-cli.types.d.ts +7 -2
- 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-user-config-isolation.d.ts +69 -0
- package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
- package/dist/session/qa-sidecar-validation.d.ts +6 -0
- package/dist/session/qa-sidecar-validation.js +28 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +22 -1
- package/dist/session/sandbox-host-capacity-gate.js +63 -22
- 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.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 +8 -1
- package/dist/session/session.service.js +177 -239
- package/dist/session/session.types.d.ts +5 -0
- package/dist/session/session.types.js +9 -79
- 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/shared/fs/file-identity.d.ts +10 -0
- package/dist/shared/fs/file-identity.js +15 -0
- package/dist/shared/fs/replace-file.d.ts +7 -0
- package/dist/shared/fs/replace-file.js +33 -0
- package/dist/shared/process/host-process-recovery.d.ts +14 -3
- package/dist/shared/process/host-process-recovery.js +23 -3
- package/dist/shared/process/host-process-supervisor.d.ts +13 -1
- package/dist/shared/process/host-process-supervisor.js +66 -14
- package/dist/shared/provider-capabilities.d.ts +2 -0
- package/dist/shared/provider-capabilities.js +18 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/artifact-injector.js +24 -0
- 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 +49 -5
- package/dist/worktree/worktree.service.js +223 -187
- package/dist/worktree/worktree.types.d.ts +47 -0
- package/package.json +1 -1
- package/runtime/windows-listener-owner.ps1 +12 -1
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
// <kind>/<12 hex> a work item (story, task, bug, feature, work_order) or
|
|
5
5
|
// its Architect phase (architect)
|
|
6
6
|
// decompose/<feature|work_order>/<12 hex> a decompose session
|
|
7
|
+
// pr-review/<12 hex>-<12 hex> a Forge PR review of one head (work item, head SHA); it is
|
|
8
|
+
// detached and review-only, so it holds nothing to save
|
|
7
9
|
// runtime-readiness-<UUID> a runtime readiness probe (session.service.ts)
|
|
8
10
|
// draft-<32 hex> a drafting session (DraftingService on the server)
|
|
9
11
|
// A release that couldn't finish deleting can leave `<one of those>.forge-release-<UUID>` beside it.
|
|
@@ -16,10 +18,12 @@ const releaseSuffix = `(?:\\.forge-release-${uuid})?`;
|
|
|
16
18
|
const forgeOwnedWorktreePathPattern = new RegExp("^(?:"
|
|
17
19
|
+ `(?:story|task|bug|feature|work_order|architect)/${hex12}`
|
|
18
20
|
+ `|decompose/(?:feature|work_order)/${hex12}`
|
|
21
|
+
+ `|pr-review/${hex12}-${hex12}`
|
|
19
22
|
+ `|runtime-readiness-${uuid}`
|
|
20
23
|
+ "|draft-[0-9a-f]{32}"
|
|
21
24
|
+ `)${releaseSuffix}$`);
|
|
22
25
|
const runtimeReadinessNamePattern = new RegExp(`^runtime-readiness-${uuid}$`);
|
|
26
|
+
const prReviewWorktreeKeyPattern = new RegExp(`^pr-review/${hex12}-${hex12}$`);
|
|
23
27
|
// Folders that only group Forge's worktrees; cleanup may look inside them but never removes them.
|
|
24
28
|
const forgeWorktreeContainers = new Set([
|
|
25
29
|
"story",
|
|
@@ -31,6 +35,7 @@ const forgeWorktreeContainers = new Set([
|
|
|
31
35
|
"decompose",
|
|
32
36
|
"decompose/feature",
|
|
33
37
|
"decompose/work_order",
|
|
38
|
+
"pr-review",
|
|
34
39
|
]);
|
|
35
40
|
// Split only on the separators the filesystem itself uses. On POSIX a backslash is an ordinary
|
|
36
41
|
// filename character, so a folder a person named `story\0123456789ab` must not read as Forge's
|
|
@@ -51,3 +56,7 @@ export function isForgeWorktreeContainer(relativePath, separator = path.sep) {
|
|
|
51
56
|
export function isRuntimeReadinessName(name) {
|
|
52
57
|
return runtimeReadinessNamePattern.test(name);
|
|
53
58
|
}
|
|
59
|
+
/** True for a Forge PR review's worktree key, pr-review/<12 hex>-<12 hex>: nothing in it is anyone's work. */
|
|
60
|
+
export function isPrReviewWorktreeKey(name) {
|
|
61
|
+
return prReviewWorktreeKeyPattern.test(name);
|
|
62
|
+
}
|
|
@@ -3,3 +3,5 @@ import { type RuntimeIsolationLease } from "../runtime/runtime-isolation-lease.j
|
|
|
3
3
|
export declare function readHostRuntimeLeases(stateRoot: string): Promise<readonly RuntimeIsolationLease[]>;
|
|
4
4
|
/** Branches that a lease which isn't released yet may still use. */
|
|
5
5
|
export declare function liveLeaseBranches(leases: readonly RuntimeIsolationLease[]): ReadonlySet<string>;
|
|
6
|
+
/** A runtime lease's worktree path, resolved; throws when it is redirected or changes while being resolved. */
|
|
7
|
+
export declare function resolveRuntimeLeasePath(leasePath: string): Promise<string>;
|
|
@@ -2,6 +2,8 @@ import { constants as fsConstants } from "node:fs";
|
|
|
2
2
|
import fs from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { validRuntimeIsolationLease } from "../runtime/runtime-isolation-lease.js";
|
|
5
|
+
import { fileIdentityChanged } from "../shared/fs/file-identity.js";
|
|
6
|
+
import { resolvePathIdentity } from "../shared/path/path.js";
|
|
5
7
|
// The host runtime ledger (<state root>/runtime-ledger/host/*.json) records every runtime lease this
|
|
6
8
|
// bridge holds. Cleanup reads it to keep live leases' worktrees and branches; any ledger it can't
|
|
7
9
|
// trust stops the cleanup rather than guessing.
|
|
@@ -31,7 +33,7 @@ export async function readHostRuntimeLeases(stateRoot) {
|
|
|
31
33
|
return leases;
|
|
32
34
|
}
|
|
33
35
|
async function readRuntimeLedger(target, entryName) {
|
|
34
|
-
const pathStat = await fs.lstat(target).catch(error => {
|
|
36
|
+
const pathStat = await fs.lstat(target, { bigint: true }).catch(error => {
|
|
35
37
|
if (isEnoent(error))
|
|
36
38
|
return null;
|
|
37
39
|
throw error;
|
|
@@ -51,20 +53,20 @@ async function readRuntimeLedger(target, entryName) {
|
|
|
51
53
|
throw new Error(`Refusing managed worktree cleanup because runtime ledger ${entryName} could not be opened safely.`, { cause: error });
|
|
52
54
|
}
|
|
53
55
|
try {
|
|
54
|
-
const openedStat = await handle.stat();
|
|
55
|
-
const reopenedPathStat = await fs.lstat(target);
|
|
56
|
+
const openedStat = await handle.stat({ bigint: true });
|
|
57
|
+
const reopenedPathStat = await fs.lstat(target, { bigint: true });
|
|
56
58
|
validateRuntimeLedgerStat(entryName, openedStat);
|
|
57
59
|
validateRuntimeLedgerStat(entryName, reopenedPathStat);
|
|
58
60
|
validateSameRuntimeLedgerFile(entryName, pathStat, openedStat);
|
|
59
61
|
validateSameRuntimeLedgerFile(entryName, openedStat, reopenedPathStat);
|
|
60
62
|
const content = await handle.readFile("utf8");
|
|
61
|
-
const afterStat = await handle.stat();
|
|
62
|
-
const afterPathStat = await fs.lstat(target);
|
|
63
|
+
const afterStat = await handle.stat({ bigint: true });
|
|
64
|
+
const afterPathStat = await fs.lstat(target, { bigint: true });
|
|
63
65
|
validateRuntimeLedgerStat(entryName, afterStat);
|
|
64
66
|
validateRuntimeLedgerStat(entryName, afterPathStat);
|
|
65
67
|
validateSameRuntimeLedgerFile(entryName, openedStat, afterStat);
|
|
66
68
|
validateSameRuntimeLedgerFile(entryName, afterStat, afterPathStat);
|
|
67
|
-
if (openedStat.size !== afterStat.size || Buffer.byteLength(content, "utf8") !== afterStat.size) {
|
|
69
|
+
if (openedStat.size !== afterStat.size || BigInt(Buffer.byteLength(content, "utf8")) !== afterStat.size) {
|
|
68
70
|
throw new Error(`Refusing managed worktree cleanup because runtime ledger ${entryName} changed while being read.`);
|
|
69
71
|
}
|
|
70
72
|
try {
|
|
@@ -82,13 +84,12 @@ function validateRuntimeLedgerStat(entryName, stat) {
|
|
|
82
84
|
if (stat.isSymbolicLink() || !stat.isFile()) {
|
|
83
85
|
throw new Error(`Refusing managed worktree cleanup because runtime ledger ${entryName} is not a regular file.`);
|
|
84
86
|
}
|
|
85
|
-
if (stat.size >
|
|
87
|
+
if (stat.size > 256n * 1024n) {
|
|
86
88
|
throw new Error(`Refusing managed worktree cleanup because runtime ledger ${entryName} is oversized.`);
|
|
87
89
|
}
|
|
88
90
|
}
|
|
89
91
|
function validateSameRuntimeLedgerFile(entryName, before, after) {
|
|
90
|
-
if (before
|
|
91
|
-
&& (before.dev !== after.dev || before.ino !== after.ino)) {
|
|
92
|
+
if (fileIdentityChanged(before, after)) {
|
|
92
93
|
throw new Error(`Refusing managed worktree cleanup because runtime ledger ${entryName} changed while being read.`);
|
|
93
94
|
}
|
|
94
95
|
}
|
|
@@ -107,3 +108,23 @@ function isEnoent(error) {
|
|
|
107
108
|
function isRecord(value) {
|
|
108
109
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
109
110
|
}
|
|
111
|
+
/** A runtime lease's worktree path, resolved; throws when it is redirected or changes while being resolved. */
|
|
112
|
+
export async function resolveRuntimeLeasePath(leasePath) {
|
|
113
|
+
const resolved = path.resolve(leasePath);
|
|
114
|
+
const before = await fs.lstat(resolved, { bigint: true }).catch(error => {
|
|
115
|
+
if (isEnoent(error))
|
|
116
|
+
return null;
|
|
117
|
+
throw error;
|
|
118
|
+
});
|
|
119
|
+
if (!before)
|
|
120
|
+
return await resolvePathIdentity(resolved);
|
|
121
|
+
if (before.isSymbolicLink() || !before.isDirectory()) {
|
|
122
|
+
throw new Error(`Refusing managed worktree cleanup because runtime lease path ${resolved} is redirected or is not a directory.`);
|
|
123
|
+
}
|
|
124
|
+
const real = await fs.realpath(resolved);
|
|
125
|
+
const after = await fs.lstat(resolved, { bigint: true });
|
|
126
|
+
if (after.isSymbolicLink() || !after.isDirectory() || fileIdentityChanged(before, after)) {
|
|
127
|
+
throw new Error(`Refusing managed worktree cleanup because runtime lease path ${resolved} changed while being resolved.`);
|
|
128
|
+
}
|
|
129
|
+
return real;
|
|
130
|
+
}
|
package/dist/cli/cli.help.js
CHANGED
|
@@ -15,7 +15,7 @@ export function helpText() {
|
|
|
15
15
|
" Hint: commands suffixed with * have detailed help. Run <command> --help for details.",
|
|
16
16
|
" connect * Start the runner bridge and wait for Forge dispatches",
|
|
17
17
|
" pair * Pair this machine with Forge and save runner credentials",
|
|
18
|
-
" status * Show config, runner identity, repos, provider CLIs, and
|
|
18
|
+
" status * Show config, runner identity, repos, provider CLIs, updates, and idle state",
|
|
19
19
|
" server * Show or change the saved Forge server URL",
|
|
20
20
|
" add-repo * Map a Forge repo label/name to a local checkout path",
|
|
21
21
|
" remove-repo * Remove a saved repo mapping",
|
|
@@ -32,6 +32,7 @@ export function helpText() {
|
|
|
32
32
|
" forge-bridge pair 1234-5678 --server https://forge.example.ts.net:8443 --repo-root \"%USERPROFILE%\\ForgeRepos\"",
|
|
33
33
|
" forge-bridge connect",
|
|
34
34
|
" forge-bridge status --check-updates",
|
|
35
|
+
" forge-bridge status --idle --require-yield --wait 600",
|
|
35
36
|
" forge-bridge server set http://localhost:5208",
|
|
36
37
|
" forge-bridge add-repo Forge D:\\Programming\\repos\\Forge",
|
|
37
38
|
" forge-bridge cleanup --stale",
|
|
@@ -40,12 +41,61 @@ export function helpText() {
|
|
|
40
41
|
" If Forge says the bridge is old: npm install -g @loucompanion/forge-bridge@next",
|
|
41
42
|
" If connect shows 502/500: leave it open; it reconnects with backoff while dev restarts.",
|
|
42
43
|
" If a provider is missing: run forge-bridge status --check-updates and verify CLI login.",
|
|
44
|
+
" Before restarting or updating the bridge: forge-bridge help status (yield on, wait for idle, restart, yield off).",
|
|
43
45
|
"",
|
|
44
46
|
"Docs:",
|
|
45
47
|
" https://github.com/coleman399/Forge/tree/develop/tools/forge-bridge#readme",
|
|
46
48
|
"",
|
|
47
49
|
].join("\n");
|
|
48
50
|
}
|
|
51
|
+
// The status help, kept out of commandHelpText so that function stays within its length ceiling.
|
|
52
|
+
const statusHelpLines = [
|
|
53
|
+
"Forge Bridge — status",
|
|
54
|
+
"Show saved configuration, paired runner identity, repo mappings, detected provider CLIs, and optional update info.",
|
|
55
|
+
"",
|
|
56
|
+
"Usage:",
|
|
57
|
+
" forge-bridge status [--check-updates]",
|
|
58
|
+
" forge-bridge status --idle [--require-yield] [--json] [--wait <seconds>]",
|
|
59
|
+
"",
|
|
60
|
+
"--idle reports whether the running `forge-bridge connect` can be restarted without killing work.",
|
|
61
|
+
"The bridge publishes its in-flight work to bridge.state.json next to bridge.json: accepted offers,",
|
|
62
|
+
"dispatches in admission, worktree and dependency preparation, prepared-runtime probes, running",
|
|
63
|
+
"attempts and their teardown, chat turns, readiness probes and result delivery.",
|
|
64
|
+
"",
|
|
65
|
+
"Options:",
|
|
66
|
+
" --idle Check the running bridge's published idle state.",
|
|
67
|
+
" --require-yield Count idle only once Forge has acknowledged this bridge's yield (with --idle).",
|
|
68
|
+
" --json Print the result as JSON (with --idle).",
|
|
69
|
+
" --wait <seconds> Keep checking until idle, the bridge process has exited, or time is up (with --idle).",
|
|
70
|
+
" --wait 0 checks once, like no --wait.",
|
|
71
|
+
"",
|
|
72
|
+
"Exit codes with --idle:",
|
|
73
|
+
" 0 idle: a live bridge reported a fresh heartbeat with nothing in flight",
|
|
74
|
+
" 1 busy: work is in flight; restarting now would kill it",
|
|
75
|
+
" 2 usage error",
|
|
76
|
+
" 3 stale or unknown: old heartbeat, unreadable or missing state file, two bridges on one",
|
|
77
|
+
" config, or the bridge is shutting down; idle cannot be confirmed (a bridge older than",
|
|
78
|
+
" this check writes no file)",
|
|
79
|
+
" 4 not running: the recorded bridge process has exited; there is nothing to interrupt",
|
|
80
|
+
" 5 not yielding (with --require-yield): idle, but Forge has not acknowledged yield yet",
|
|
81
|
+
"",
|
|
82
|
+
"Yield stops new attempts (Offers) and defers readiness probes. It does not stop a Bridge Chat",
|
|
83
|
+
"turn on a chat lease already bound to this runner, or a legacy Dispatch (protocol-1 bridges",
|
|
84
|
+
"only); those run and count as busy.",
|
|
85
|
+
"",
|
|
86
|
+
"Restart or update procedure:",
|
|
87
|
+
" forge-bridge yield on # no new attempts; running work finishes",
|
|
88
|
+
" forge-bridge status --idle --require-yield --wait 3600 # exit 0 only once idle and yielding",
|
|
89
|
+
" (stop forge-bridge connect, update it, start it again)",
|
|
90
|
+
" forge-bridge yield off # after the new bridge connects, or after a failed wait",
|
|
91
|
+
"Run these as the same user and with the same FORGE_BRIDGE_CONFIG as the bridge, so they",
|
|
92
|
+
"read and write the bridge's own files.",
|
|
93
|
+
"",
|
|
94
|
+
"Examples:",
|
|
95
|
+
" forge-bridge status --check-updates",
|
|
96
|
+
" forge-bridge status --idle --json",
|
|
97
|
+
"",
|
|
98
|
+
];
|
|
49
99
|
export function commandHelpText(command) {
|
|
50
100
|
switch (command) {
|
|
51
101
|
case "pair":
|
|
@@ -92,17 +142,7 @@ export function commandHelpText(command) {
|
|
|
92
142
|
"",
|
|
93
143
|
].join("\n");
|
|
94
144
|
case "status":
|
|
95
|
-
return
|
|
96
|
-
"Forge Bridge — status",
|
|
97
|
-
"Show saved configuration, paired runner identity, repo mappings, detected provider CLIs, and optional update info.",
|
|
98
|
-
"",
|
|
99
|
-
"Usage:",
|
|
100
|
-
" forge-bridge status [--check-updates]",
|
|
101
|
-
"",
|
|
102
|
-
"Example:",
|
|
103
|
-
" forge-bridge status --check-updates",
|
|
104
|
-
"",
|
|
105
|
-
].join("\n");
|
|
145
|
+
return statusHelpLines.join("\n");
|
|
106
146
|
case "server":
|
|
107
147
|
return [
|
|
108
148
|
"Forge Bridge — server",
|
|
@@ -196,6 +236,10 @@ export function commandHelpText(command) {
|
|
|
196
236
|
"The flag is saved in its own file next to bridge.json. Yield is also on when the",
|
|
197
237
|
"runner's Yield toggle in Forge is on: either side turns it on.",
|
|
198
238
|
"",
|
|
239
|
+
"To restart or update the bridge safely, yield first, wait until",
|
|
240
|
+
"`forge-bridge status --idle --require-yield --wait <seconds>` exits 0, restart, then run",
|
|
241
|
+
"`forge-bridge yield off` once the new bridge has connected. See `forge-bridge help status`.",
|
|
242
|
+
"",
|
|
199
243
|
].join("\n");
|
|
200
244
|
case "run-once":
|
|
201
245
|
return [
|
|
@@ -212,7 +256,7 @@ export function commandHelpText(command) {
|
|
|
212
256
|
"Internal MCP server used by provider CLIs to report Forge phase artifacts.",
|
|
213
257
|
"",
|
|
214
258
|
"Usage:",
|
|
215
|
-
" forge-bridge mcp --worktree <path> --work-item-id <id> --phase <phase> # includes ci-repair",
|
|
259
|
+
" forge-bridge mcp --worktree <path> --work-item-id <id> --phase <phase> # includes ci-repair, comment-repair, pr-review",
|
|
216
260
|
"",
|
|
217
261
|
].join("\n");
|
|
218
262
|
case "version":
|
|
@@ -5,6 +5,8 @@ import type { CleanupMode } from "../cleanup/cleanup.types.js";
|
|
|
5
5
|
import type { CleanupService } from "../cleanup/cleanup.base.js";
|
|
6
6
|
import type { SessionService } from "../session/session.base.js";
|
|
7
7
|
import type { CliIo, CliService } from "./cli.base.js";
|
|
8
|
+
import { type StatusArgs } from "./idle-status.js";
|
|
9
|
+
export { claudeDefaultModels, parseCodexModelCatalog, parseCursorModelList } from "./provider-cli-detection.js";
|
|
8
10
|
type DotNetToolchainConfigurator = (repoRoots: readonly string[], options?: {
|
|
9
11
|
readonly cloneFolders?: readonly string[];
|
|
10
12
|
}) => Promise<DotNetToolchainSelection | null>;
|
|
@@ -47,12 +49,7 @@ export declare function parseArgs(argv: readonly string[]): {
|
|
|
47
49
|
readonly ok: true;
|
|
48
50
|
readonly command: "server-set";
|
|
49
51
|
readonly serverUrl: string;
|
|
50
|
-
} | {
|
|
51
|
-
readonly ok: true;
|
|
52
|
-
readonly command: "status";
|
|
53
|
-
readonly config: BridgeServiceConfig;
|
|
54
|
-
readonly checkUpdates: boolean;
|
|
55
|
-
} | {
|
|
52
|
+
} | StatusArgs | {
|
|
56
53
|
readonly ok: true;
|
|
57
54
|
readonly command: "cleanup";
|
|
58
55
|
readonly config: BridgeServiceConfig;
|
|
@@ -127,8 +124,4 @@ interface PairRunnerClaim {
|
|
|
127
124
|
type PairRunnerClient = (args: PairArgs) => Promise<PairRunnerClaim>;
|
|
128
125
|
/** Expands `~` in a repo folder chosen in Forge and rejects one shaped for another OS. */
|
|
129
126
|
export declare function resolveHostRepoRoot(value: string, platform?: NodeJS.Platform, home?: string): string | undefined;
|
|
130
|
-
export declare const claudeDefaultModels: readonly string[];
|
|
131
|
-
export declare function parseCodexModelCatalog(raw: string): string[];
|
|
132
|
-
export declare function parseCursorModelList(raw: string): string[];
|
|
133
127
|
type CleanupServiceFactory = (stateRoot: string) => CleanupService;
|
|
134
|
-
export {};
|
package/dist/cli/cli.service.js
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
|
-
import { execFile } from "node:child_process";
|
|
3
2
|
import os from "node:os";
|
|
4
3
|
import path from "node:path";
|
|
5
4
|
import { createInterface } from "node:readline/promises";
|
|
6
|
-
import { promisify } from "node:util";
|
|
7
|
-
import { resolveCursorAgentDirectLaunch } from "../shared/cursor-agent/cursor-agent.launch.js";
|
|
8
|
-
import { buildWindowsCmdLaunch } from "../shared/process/windows-launch.js";
|
|
9
5
|
import { configureDotNetToolchain } from "../shared/process/dotnet-toolchain.js";
|
|
10
|
-
import { supportsDraftImageAttachmentsFor } from "../shared/provider-capabilities.js";
|
|
11
6
|
import { redactText } from "../shared/redaction/redaction.js";
|
|
12
7
|
import { BridgeRevokedError, bridgeRevokedExitCode, defaultBridgeServiceConfig, ForgeBridgeService, } from "../bridge/bridge.service.js";
|
|
13
8
|
import { forgeBridgeVersion } from "../version.js";
|
|
14
9
|
import { ManagedWorktreeCleanupService } from "../cleanup/cleanup.service.js";
|
|
15
|
-
import { addRepoMapping, applyLocalConfigDefaults, providerStatusesFor, readLocalConfigSync, removeRepoMapping, resolveLocalConfigPath, resolveLocalYieldFlagPath, setSandboxPolicy, setServerUrl, writeLocalConfig } from "./local-config.js";
|
|
16
|
-
import { BridgeSessionService } from "../session/session.service.js";
|
|
10
|
+
import { addRepoMapping, applyLocalConfigDefaults, pairDerivedCapabilities, providerStatusesFor, readLocalConfigSync, removeRepoMapping, resolveLocalConfigPath, resolveLocalYieldFlagPath, setSandboxPolicy, setServerUrl, writeLocalConfig } from "./local-config.js";
|
|
11
|
+
import { BridgeSessionService, runOnceWithReviewPlacement } from "../session/session.service.js";
|
|
17
12
|
import { redactRunnerDispatchEvent, redactRunOnceResultPacket } from "../session/session-redaction.js";
|
|
18
13
|
import { validateDockerfilePolicy, validateSandboxContract } from "../sandbox/contract.js";
|
|
19
14
|
import { DockerPreflight } from "../sandbox/preflight.js";
|
|
@@ -23,8 +18,10 @@ import { parseCompletionMcpArgs, runCompletionMcpServer } from "../session/phase
|
|
|
23
18
|
import { failureFactsFromError, failureResult, parseRunOnceDispatchPacket } from "../session/session.types.js";
|
|
24
19
|
import { commandHelpText, helpText } from "./cli.help.js";
|
|
25
20
|
import { readLocalYieldFlag, writeLocalYieldFlag } from "../bridge/local-yield-flag.js";
|
|
21
|
+
import { detectKnownCliProviders, knownProviderCandidates, withDetectedCliProviders } from "./provider-cli-advertising.js";
|
|
22
|
+
import { idleSummaryLine, parseStatusArgs, runIdleStatusCommand } from "./idle-status.js";
|
|
23
|
+
export { claudeDefaultModels, parseCodexModelCatalog, parseCursorModelList } from "./provider-cli-detection.js";
|
|
26
24
|
const apiKeySecretGrantEnv = "FORGE_API_KEY_SECRET_GRANT";
|
|
27
|
-
const execFileAsync = promisify(execFile);
|
|
28
25
|
export class ForgeBridgeCliService {
|
|
29
26
|
sessions;
|
|
30
27
|
bridgeFactory;
|
|
@@ -63,7 +60,9 @@ export class ForgeBridgeCliService {
|
|
|
63
60
|
return 2;
|
|
64
61
|
}
|
|
65
62
|
if (args.command === "connect") {
|
|
66
|
-
|
|
63
|
+
// Probe every known provider CLI, not only the configured ones, so a CLI installed after
|
|
64
|
+
// pairing gets advertised.
|
|
65
|
+
const config = await withDetectedCliProviders(args.config, knownProviderCandidates(args.config.cliProviders));
|
|
67
66
|
const missing = [
|
|
68
67
|
["server", config.serverUrl],
|
|
69
68
|
["runner id", config.runnerId],
|
|
@@ -195,8 +194,7 @@ export class ForgeBridgeCliService {
|
|
|
195
194
|
}
|
|
196
195
|
}
|
|
197
196
|
if (args.command === "status") {
|
|
198
|
-
await
|
|
199
|
-
return 0;
|
|
197
|
+
return await runStatus(args, io);
|
|
200
198
|
}
|
|
201
199
|
if (args.command === "cleanup") {
|
|
202
200
|
return await cleanupRepos(args.config, args.mode, args.force, this.cleanupFactory(args.config.sandboxStateRoot), io);
|
|
@@ -246,7 +244,7 @@ export class ForgeBridgeCliService {
|
|
|
246
244
|
const dispatchJson = await fs.readFile(args.dispatchPath, "utf8");
|
|
247
245
|
const dispatch = attachEnvSecretGrant(parseRunOnceDispatchPacket(JSON.parse(dispatchJson)));
|
|
248
246
|
redactionSecrets = exactSecrets(dispatch);
|
|
249
|
-
const result = await this.sessions.runOnce(
|
|
247
|
+
const result = await runOnceWithReviewPlacement(dispatch, (packet) => this.sessions.runOnce(packet, {
|
|
250
248
|
emit: async (event) => {
|
|
251
249
|
const line = {
|
|
252
250
|
type: "runner_event",
|
|
@@ -254,7 +252,7 @@ export class ForgeBridgeCliService {
|
|
|
254
252
|
};
|
|
255
253
|
io.stdout.write(`${JSON.stringify(line)}\n`);
|
|
256
254
|
}
|
|
257
|
-
});
|
|
255
|
+
}));
|
|
258
256
|
await writeJsonAtomic(args.resultPath, redactRunOnceResultPacket(result, redactionSecrets));
|
|
259
257
|
return result.exitCode;
|
|
260
258
|
}
|
|
@@ -381,17 +379,7 @@ export function parseArgs(argv) {
|
|
|
381
379
|
return { ok: false, error: "Usage: forge-bridge server <show|set <url>>" };
|
|
382
380
|
}
|
|
383
381
|
if (argv[0] === "status") {
|
|
384
|
-
|
|
385
|
-
for (let index = 1; index < argv.length; index += 1) {
|
|
386
|
-
const arg = argv[index];
|
|
387
|
-
if (arg === "--check-updates") {
|
|
388
|
-
checkUpdates = true;
|
|
389
|
-
}
|
|
390
|
-
else {
|
|
391
|
-
return { ok: false, error: `Unknown argument: ${arg}` };
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
return { ok: true, command: "status", config: configuredBridgeServiceConfig(), checkUpdates };
|
|
382
|
+
return parseStatusArgs(argv, configuredBridgeServiceConfig);
|
|
395
383
|
}
|
|
396
384
|
if (argv[0] === "cleanup") {
|
|
397
385
|
return parseCleanupArgs(argv);
|
|
@@ -969,7 +957,7 @@ function pairedConfig(current, args, claim) {
|
|
|
969
957
|
supportsRunnerAuthoredPhaseArtifacts: current.supportsRunnerAuthoredPhaseArtifacts ?? true,
|
|
970
958
|
supportsDraftRunOnce: current.supportsDraftRunOnce ?? true,
|
|
971
959
|
supportsDraftAttachments: current.supportsDraftAttachments ?? true,
|
|
972
|
-
|
|
960
|
+
...pairDerivedCapabilities(current, args.cliProviders),
|
|
973
961
|
repoMappings: current.repoMappings ?? []
|
|
974
962
|
};
|
|
975
963
|
}
|
|
@@ -1065,15 +1053,18 @@ async function writeJsonAtomic(outputPath, value) {
|
|
|
1065
1053
|
await fs.writeFile(tempPath, `${JSON.stringify(value, null, 2)}\n`, "utf8");
|
|
1066
1054
|
await fs.rename(tempPath, outputPath);
|
|
1067
1055
|
}
|
|
1056
|
+
async function runStatus(args, io) {
|
|
1057
|
+
return args.idle ? await runIdleStatusCommand(args.idle, io) : await writeStatus(args.config, args.checkUpdates, io);
|
|
1058
|
+
}
|
|
1068
1059
|
async function writeStatus(config, checkUpdates, io) {
|
|
1069
|
-
const detected = await
|
|
1060
|
+
const detected = await detectKnownCliProviders(config.cliProviders);
|
|
1070
1061
|
const repos = config.repoMappings.filter((mapping) => mapping.localPath?.trim());
|
|
1071
1062
|
io.stdout.write(`Forge bridge ${config.version}\n`);
|
|
1072
1063
|
io.stdout.write(`Config: ${resolveLocalConfigPath()}\n`);
|
|
1073
1064
|
io.stdout.write(`Server: ${config.serverUrl || "not configured"}\n`);
|
|
1074
1065
|
io.stdout.write(`Device: ${config.runnerId || "not configured"}${config.deviceName ? ` (${config.deviceName})` : ""}\n`);
|
|
1075
1066
|
io.stdout.write(`Device token: ${config.deviceToken ? "configured" : "missing"}\n`);
|
|
1076
|
-
io.stdout.write(
|
|
1067
|
+
io.stdout.write(`${await idleSummaryLine()}\n`);
|
|
1077
1068
|
io.stdout.write("Repos:\n");
|
|
1078
1069
|
if (repos.length === 0) {
|
|
1079
1070
|
io.stdout.write(" none\n");
|
|
@@ -1091,6 +1082,7 @@ async function writeStatus(config, checkUpdates, io) {
|
|
|
1091
1082
|
if (checkUpdates) {
|
|
1092
1083
|
io.stdout.write("Update check: no update channel configured.\n");
|
|
1093
1084
|
}
|
|
1085
|
+
return 0;
|
|
1094
1086
|
}
|
|
1095
1087
|
async function cleanupRepos(config, mode, force, cleanup, io) {
|
|
1096
1088
|
const repos = config.repoMappings.filter((mapping) => mapping.localPath?.trim());
|
|
@@ -1137,184 +1129,8 @@ async function cleanupRepos(config, mode, force, cleanup, io) {
|
|
|
1137
1129
|
}
|
|
1138
1130
|
return failures === 0 ? 0 : 1;
|
|
1139
1131
|
}
|
|
1140
|
-
async function detectCliProviders(providers) {
|
|
1141
|
-
const results = [];
|
|
1142
|
-
for (const provider of providers) {
|
|
1143
|
-
let detected = null;
|
|
1144
|
-
for (const probe of cliProbeCommandsFor(provider)) {
|
|
1145
|
-
try {
|
|
1146
|
-
detected = await execVersionCommand(probe, probe.timeoutMs);
|
|
1147
|
-
break;
|
|
1148
|
-
}
|
|
1149
|
-
catch {
|
|
1150
|
-
// Try the next provider-specific probe.
|
|
1151
|
-
}
|
|
1152
|
-
}
|
|
1153
|
-
results.push({
|
|
1154
|
-
provider,
|
|
1155
|
-
found: detected !== null,
|
|
1156
|
-
version: detected ? versionLine(`${detected.stdout || detected.stderr}`) : "",
|
|
1157
|
-
models: detected ? await detectCliModels(provider) : []
|
|
1158
|
-
});
|
|
1159
|
-
}
|
|
1160
|
-
return results;
|
|
1161
|
-
}
|
|
1162
|
-
function cliProbeCommandsFor(provider) {
|
|
1163
|
-
const normalized = provider.toLowerCase();
|
|
1164
|
-
if (normalized === "codex") {
|
|
1165
|
-
return [
|
|
1166
|
-
{ command: "codex", args: ["-V"] },
|
|
1167
|
-
{ command: "codex", args: ["--version"] }
|
|
1168
|
-
];
|
|
1169
|
-
}
|
|
1170
|
-
if (normalized === "claude") {
|
|
1171
|
-
return [
|
|
1172
|
-
// Claude Code's Node startup can exceed the default 2s probe on a cold Windows host.
|
|
1173
|
-
{ command: "claude", args: ["--version"], timeoutMs: 8000 },
|
|
1174
|
-
{ command: "claude", args: ["-v"], timeoutMs: 8000 }
|
|
1175
|
-
];
|
|
1176
|
-
}
|
|
1177
|
-
if (normalized === "cursor") {
|
|
1178
|
-
return [
|
|
1179
|
-
{ command: "cursor-agent", args: ["-v"] },
|
|
1180
|
-
{ command: "agent", args: ["-v"] },
|
|
1181
|
-
{ command: "cursor-agent", args: ["--version"] },
|
|
1182
|
-
{ command: "agent", args: ["--version"] }
|
|
1183
|
-
];
|
|
1184
|
-
}
|
|
1185
|
-
return [
|
|
1186
|
-
{ command: provider, args: ["--version"] },
|
|
1187
|
-
{ command: provider, args: ["-V"] }
|
|
1188
|
-
];
|
|
1189
|
-
}
|
|
1190
|
-
async function execVersionCommand(probe, timeout = 2000, maxBuffer) {
|
|
1191
|
-
const directLaunch = process.platform === "win32"
|
|
1192
|
-
? await resolveCursorAgentDirectLaunch(probe.command, probe.args)
|
|
1193
|
-
: null;
|
|
1194
|
-
if (directLaunch) {
|
|
1195
|
-
return await execFileAsync(directLaunch.command, [...directLaunch.args], { timeout, maxBuffer });
|
|
1196
|
-
}
|
|
1197
|
-
try {
|
|
1198
|
-
return await execFileAsync(probe.command, probe.args, { timeout, maxBuffer });
|
|
1199
|
-
}
|
|
1200
|
-
catch (error) {
|
|
1201
|
-
if (process.platform !== "win32") {
|
|
1202
|
-
throw error;
|
|
1203
|
-
}
|
|
1204
|
-
const launch = buildWindowsCmdLaunch(probe.command, probe.args);
|
|
1205
|
-
return await execFileAsync(launch.command, [...launch.args], { timeout, maxBuffer });
|
|
1206
|
-
}
|
|
1207
|
-
}
|
|
1208
|
-
function versionLine(output) {
|
|
1209
|
-
const lines = output
|
|
1210
|
-
.trim()
|
|
1211
|
-
.split(/\r?\n/)
|
|
1212
|
-
.map((line) => line.trim())
|
|
1213
|
-
.filter((line) => line.length > 0);
|
|
1214
|
-
return lines.at(-1) ?? "";
|
|
1215
|
-
}
|
|
1216
|
-
async function detectCliModels(provider) {
|
|
1217
|
-
const normalized = provider.toLowerCase();
|
|
1218
|
-
try {
|
|
1219
|
-
if (normalized === "codex") {
|
|
1220
|
-
// Windows installs codex as a .cmd shim, which execFile cannot launch directly.
|
|
1221
|
-
const result = await execVersionCommand({ command: "codex", args: ["debug", "models"] }, 10_000, 10 * 1024 * 1024);
|
|
1222
|
-
return parseCodexModelCatalog(result.stdout);
|
|
1223
|
-
}
|
|
1224
|
-
if (normalized === "cursor") {
|
|
1225
|
-
const result = await execVersionCommand({ command: "cursor-agent", args: ["models"] }, 10_000);
|
|
1226
|
-
return parseCursorModelList(`${result.stdout || result.stderr}`);
|
|
1227
|
-
}
|
|
1228
|
-
if (normalized === "claude") {
|
|
1229
|
-
// Claude Code has no model-listing command; it accepts these aliases and full model IDs.
|
|
1230
|
-
const configured = splitCsv(process.env.FORGE_CLAUDE_MODELS ?? "");
|
|
1231
|
-
return configured.length > 0 ? configured : [...claudeDefaultModels];
|
|
1232
|
-
}
|
|
1233
|
-
}
|
|
1234
|
-
catch {
|
|
1235
|
-
return [];
|
|
1236
|
-
}
|
|
1237
|
-
return [];
|
|
1238
|
-
}
|
|
1239
|
-
export const claudeDefaultModels = ["sonnet", "opus", "haiku"];
|
|
1240
|
-
export function parseCodexModelCatalog(raw) {
|
|
1241
|
-
try {
|
|
1242
|
-
const parsed = JSON.parse(raw);
|
|
1243
|
-
if (!isRecord(parsed) || !Array.isArray(parsed.models)) {
|
|
1244
|
-
return [];
|
|
1245
|
-
}
|
|
1246
|
-
const entries = parsed.models
|
|
1247
|
-
.map((entry, index) => {
|
|
1248
|
-
if (!isRecord(entry) || typeof entry.slug !== "string") {
|
|
1249
|
-
return null;
|
|
1250
|
-
}
|
|
1251
|
-
const visibility = typeof entry.visibility === "string" ? entry.visibility.toLowerCase() : "list";
|
|
1252
|
-
if (visibility !== "list") {
|
|
1253
|
-
return null;
|
|
1254
|
-
}
|
|
1255
|
-
const priority = typeof entry.priority === "number" && Number.isFinite(entry.priority) ? entry.priority : index;
|
|
1256
|
-
return { slug: entry.slug, priority, index };
|
|
1257
|
-
})
|
|
1258
|
-
.filter((entry) => entry !== null)
|
|
1259
|
-
.sort((left, right) => left.priority - right.priority || left.index - right.index)
|
|
1260
|
-
.map((entry) => entry.slug);
|
|
1261
|
-
return uniqueModels(entries);
|
|
1262
|
-
}
|
|
1263
|
-
catch {
|
|
1264
|
-
return [];
|
|
1265
|
-
}
|
|
1266
|
-
}
|
|
1267
|
-
export function parseCursorModelList(raw) {
|
|
1268
|
-
return uniqueModels(raw
|
|
1269
|
-
.split(/\r?\n/)
|
|
1270
|
-
.map((line) => line.trim())
|
|
1271
|
-
.filter((line) => line.length > 0 && !line.toLowerCase().startsWith("available models"))
|
|
1272
|
-
.map((line) => line.split(/\s+-\s+/, 1)[0]?.trim() ?? "")
|
|
1273
|
-
.filter((model) => model.length > 0));
|
|
1274
|
-
}
|
|
1275
|
-
function uniqueModels(models) {
|
|
1276
|
-
const seen = new Set();
|
|
1277
|
-
const result = [];
|
|
1278
|
-
for (const model of models) {
|
|
1279
|
-
const trimmed = model.trim();
|
|
1280
|
-
const key = trimmed.toLowerCase();
|
|
1281
|
-
if (!trimmed || seen.has(key)) {
|
|
1282
|
-
continue;
|
|
1283
|
-
}
|
|
1284
|
-
seen.add(key);
|
|
1285
|
-
result.push(trimmed);
|
|
1286
|
-
}
|
|
1287
|
-
return result;
|
|
1288
|
-
}
|
|
1289
|
-
function isRecord(value) {
|
|
1290
|
-
return typeof value === "object" && value !== null;
|
|
1291
|
-
}
|
|
1292
|
-
async function withDetectedCliProviders(config, candidates = config.cliProviders) {
|
|
1293
|
-
const detected = await detectCliProviders(uniqueProviders(candidates));
|
|
1294
|
-
const found = detected.filter((result) => result.found);
|
|
1295
|
-
if (found.length === 0) {
|
|
1296
|
-
return config;
|
|
1297
|
-
}
|
|
1298
|
-
const cliProviders = uniqueProviders([...config.cliProviders, ...found.map((result) => result.provider)]);
|
|
1299
|
-
const providerStatuses = { ...config.providerStatuses };
|
|
1300
|
-
for (const result of found) {
|
|
1301
|
-
const existing = providerStatuses[result.provider];
|
|
1302
|
-
providerStatuses[result.provider] = {
|
|
1303
|
-
signedIn: existing?.signedIn ?? true,
|
|
1304
|
-
version: result.version || existing?.version || "",
|
|
1305
|
-
models: result.models.length > 0
|
|
1306
|
-
? result.models
|
|
1307
|
-
: existing?.models ?? providerStatusesFor([result.provider])[result.provider]?.models ?? []
|
|
1308
|
-
};
|
|
1309
|
-
}
|
|
1310
|
-
return {
|
|
1311
|
-
...config,
|
|
1312
|
-
cliProviders,
|
|
1313
|
-
providerStatuses
|
|
1314
|
-
};
|
|
1315
|
-
}
|
|
1316
1132
|
async function withDetectedPairCliProviders(args) {
|
|
1317
|
-
const configured =
|
|
1133
|
+
const configured = knownProviderCandidates(args.cliProviders);
|
|
1318
1134
|
const detectedConfig = await withDetectedCliProviders({
|
|
1319
1135
|
...defaultBridgeServiceConfig({
|
|
1320
1136
|
serverUrl: args.serverUrl,
|
|
@@ -1330,12 +1146,3 @@ async function withDetectedPairCliProviders(args) {
|
|
|
1330
1146
|
cliProviders: detectedConfig.cliProviders
|
|
1331
1147
|
};
|
|
1332
1148
|
}
|
|
1333
|
-
function configuredProviderCandidates(providers) {
|
|
1334
|
-
return uniqueProviders([...providers, "codex", "cursor", "claude"]);
|
|
1335
|
-
}
|
|
1336
|
-
function uniqueProviders(providers) {
|
|
1337
|
-
return providers
|
|
1338
|
-
.map((provider) => provider.trim())
|
|
1339
|
-
.filter((provider) => provider.length > 0)
|
|
1340
|
-
.filter((provider, index, all) => all.findIndex((candidate) => candidate.toLowerCase() === provider.toLowerCase()) === index);
|
|
1341
|
-
}
|