@loucompanion/forge-bridge 0.1.4-dev.6b2148ecc60c → 0.1.4-dev.724427ea7be8
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 +87 -1
- package/dist/bridge/bridge-chat-provider-command.d.ts +5 -2
- package/dist/bridge/bridge-chat-provider-command.js +29 -22
- package/dist/bridge/bridge-chat.types.d.ts +10 -0
- package/dist/bridge/bridge-chat.types.js +16 -1
- package/dist/bridge/bridge-state-file.d.ts +161 -0
- package/dist/bridge/bridge-state-file.js +376 -0
- package/dist/bridge/bridge-state-io.d.ts +11 -0
- package/dist/bridge/bridge-state-io.js +50 -0
- package/dist/bridge/bridge-state-lock.d.ts +11 -0
- package/dist/bridge/bridge-state-lock.js +102 -0
- package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
- package/dist/bridge/bridge-state-unpublished.js +111 -0
- package/dist/bridge/bridge.service.d.ts +16 -12
- package/dist/bridge/bridge.service.js +131 -243
- package/dist/bridge/bridge.types.d.ts +5 -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/sandbox-resource-accounting.d.ts +16 -0
- package/dist/bridge/sandbox-resource-accounting.js +150 -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/host-runtime-ledger.d.ts +2 -0
- package/dist/cleanup/host-runtime-ledger.js +30 -9
- package/dist/cli/cli.help.js +56 -12
- package/dist/cli/cli.service.d.ts +3 -10
- package/dist/cli/cli.service.js +10 -171
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +2 -0
- package/dist/cli/local-config.js +7 -1
- 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.js +9 -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-load-governor.d.ts +2 -0
- package/dist/runtime/host-load-ledger-lock.js +6 -4
- package/dist/runtime/host-load-runtime-settings.js +4 -2
- package/dist/runtime/host-load-sampler.d.ts +8 -1
- package/dist/runtime/host-load-sampler.js +14 -7
- package/dist/runtime/host-runtime-contract.d.ts +12 -0
- package/dist/runtime/host-runtime-contract.js +29 -1
- package/dist/runtime/host-runtime-lease.d.ts +2 -1
- package/dist/runtime/host-runtime-lease.js +30 -153
- package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
- package/dist/runtime/host-runtime-ledger-recovery.js +134 -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/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.js +2 -6
- 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 +0 -7
- package/dist/session/managed-attempt-tools.js +50 -82
- 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 +5 -0
- package/dist/session/managed-build-receipt.js +8 -3
- package/dist/session/phase-completion.artifacts.js +2 -1
- package/dist/session/phase-completion.d.ts +8 -0
- package/dist/session/phase-completion.js +1 -0
- package/dist/session/phase-completion.mcp-args.d.ts +9 -0
- package/dist/session/phase-completion.mcp-args.js +156 -0
- package/dist/session/phase-completion.runtime.d.ts +0 -8
- package/dist/session/phase-completion.runtime.js +43 -197
- package/dist/session/phase-completion.schemas.js +3 -11
- package/dist/session/phase-completion.validation.js +3 -1
- 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 +10 -10
- 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 +7 -3
- package/dist/session/pre-publication-validation.js +32 -30
- 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/host-build-lock.d.ts +18 -0
- package/dist/session/provider-cli/host-build-lock.js +30 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +16 -0
- package/dist/session/provider-cli/pre-publication-repair.js +33 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +4 -2
- 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 +3 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +27 -27
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +8 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +23 -2
- package/dist/session/provider-cli/provider-cli.service.d.ts +4 -1
- package/dist/session/provider-cli/provider-cli.service.js +27 -43
- 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 +34 -15
- package/dist/session/session-redaction.js +31 -181
- package/dist/session/session.service.d.ts +2 -0
- package/dist/session/session.service.js +69 -64
- package/dist/session/session.types.js +1 -1
- 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.js +9 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/orphan-relink.d.ts +19 -0
- package/dist/worktree/orphan-relink.js +106 -0
- package/dist/worktree/wip-git.d.ts +33 -0
- package/dist/worktree/wip-git.js +122 -0
- package/dist/worktree/wip-refs.d.ts +62 -0
- package/dist/worktree/wip-refs.js +119 -0
- package/dist/worktree/wip-restore.d.ts +38 -0
- package/dist/worktree/wip-restore.js +190 -0
- package/dist/worktree/wip-snapshot.d.ts +50 -0
- package/dist/worktree/wip-snapshot.js +268 -0
- package/dist/worktree/worktree-inputs.d.ts +8 -0
- package/dist/worktree/worktree-inputs.js +134 -0
- package/dist/worktree/worktree-origin-sync.d.ts +34 -0
- package/dist/worktree/worktree-origin-sync.js +127 -0
- package/dist/worktree/worktree-wip-events.d.ts +18 -0
- package/dist/worktree/worktree-wip-events.js +98 -0
- package/dist/worktree/worktree-wip.d.ts +50 -0
- package/dist/worktree/worktree-wip.js +185 -0
- package/dist/worktree/worktree.base.d.ts +7 -1
- package/dist/worktree/worktree.service.d.ts +27 -5
- package/dist/worktree/worktree.service.js +110 -181
- package/dist/worktree/worktree.types.d.ts +31 -0
- package/package.json +1 -1
package/dist/cli/cli.service.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
|
-
import { execFile } from "node:child_process";
|
|
3
2
|
import os from "node:os";
|
|
4
3
|
import path from "node:path";
|
|
5
4
|
import { createInterface } from "node:readline/promises";
|
|
6
|
-
import { promisify } from "node:util";
|
|
7
|
-
import { resolveCursorAgentDirectLaunch } from "../shared/cursor-agent/cursor-agent.launch.js";
|
|
8
|
-
import { buildWindowsCmdLaunch } from "../shared/process/windows-launch.js";
|
|
9
5
|
import { configureDotNetToolchain } from "../shared/process/dotnet-toolchain.js";
|
|
10
6
|
import { supportsDraftImageAttachmentsFor } from "../shared/provider-capabilities.js";
|
|
11
7
|
import { redactText } from "../shared/redaction/redaction.js";
|
|
@@ -23,8 +19,10 @@ import { parseCompletionMcpArgs, runCompletionMcpServer } from "../session/phase
|
|
|
23
19
|
import { failureFactsFromError, failureResult, parseRunOnceDispatchPacket } from "../session/session.types.js";
|
|
24
20
|
import { commandHelpText, helpText } from "./cli.help.js";
|
|
25
21
|
import { readLocalYieldFlag, writeLocalYieldFlag } from "../bridge/local-yield-flag.js";
|
|
22
|
+
import { detectCliProviders } from "./provider-cli-detection.js";
|
|
23
|
+
import { idleSummaryLine, parseStatusArgs, runIdleStatusCommand } from "./idle-status.js";
|
|
24
|
+
export { claudeDefaultModels, parseCodexModelCatalog, parseCursorModelList } from "./provider-cli-detection.js";
|
|
26
25
|
const apiKeySecretGrantEnv = "FORGE_API_KEY_SECRET_GRANT";
|
|
27
|
-
const execFileAsync = promisify(execFile);
|
|
28
26
|
export class ForgeBridgeCliService {
|
|
29
27
|
sessions;
|
|
30
28
|
bridgeFactory;
|
|
@@ -195,8 +193,7 @@ export class ForgeBridgeCliService {
|
|
|
195
193
|
}
|
|
196
194
|
}
|
|
197
195
|
if (args.command === "status") {
|
|
198
|
-
await
|
|
199
|
-
return 0;
|
|
196
|
+
return await runStatus(args, io);
|
|
200
197
|
}
|
|
201
198
|
if (args.command === "cleanup") {
|
|
202
199
|
return await cleanupRepos(args.config, args.mode, args.force, this.cleanupFactory(args.config.sandboxStateRoot), io);
|
|
@@ -381,17 +378,7 @@ export function parseArgs(argv) {
|
|
|
381
378
|
return { ok: false, error: "Usage: forge-bridge server <show|set <url>>" };
|
|
382
379
|
}
|
|
383
380
|
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 };
|
|
381
|
+
return parseStatusArgs(argv, configuredBridgeServiceConfig);
|
|
395
382
|
}
|
|
396
383
|
if (argv[0] === "cleanup") {
|
|
397
384
|
return parseCleanupArgs(argv);
|
|
@@ -1065,6 +1052,9 @@ async function writeJsonAtomic(outputPath, value) {
|
|
|
1065
1052
|
await fs.writeFile(tempPath, `${JSON.stringify(value, null, 2)}\n`, "utf8");
|
|
1066
1053
|
await fs.rename(tempPath, outputPath);
|
|
1067
1054
|
}
|
|
1055
|
+
async function runStatus(args, io) {
|
|
1056
|
+
return args.idle ? await runIdleStatusCommand(args.idle, io) : await writeStatus(args.config, args.checkUpdates, io);
|
|
1057
|
+
}
|
|
1068
1058
|
async function writeStatus(config, checkUpdates, io) {
|
|
1069
1059
|
const detected = await detectCliProviders([...new Set([...config.cliProviders, "codex", "cursor", "claude"])]);
|
|
1070
1060
|
const repos = config.repoMappings.filter((mapping) => mapping.localPath?.trim());
|
|
@@ -1073,7 +1063,7 @@ async function writeStatus(config, checkUpdates, io) {
|
|
|
1073
1063
|
io.stdout.write(`Server: ${config.serverUrl || "not configured"}\n`);
|
|
1074
1064
|
io.stdout.write(`Device: ${config.runnerId || "not configured"}${config.deviceName ? ` (${config.deviceName})` : ""}\n`);
|
|
1075
1065
|
io.stdout.write(`Device token: ${config.deviceToken ? "configured" : "missing"}\n`);
|
|
1076
|
-
io.stdout.write(
|
|
1066
|
+
io.stdout.write(`${await idleSummaryLine()}\n`);
|
|
1077
1067
|
io.stdout.write("Repos:\n");
|
|
1078
1068
|
if (repos.length === 0) {
|
|
1079
1069
|
io.stdout.write(" none\n");
|
|
@@ -1091,6 +1081,7 @@ async function writeStatus(config, checkUpdates, io) {
|
|
|
1091
1081
|
if (checkUpdates) {
|
|
1092
1082
|
io.stdout.write("Update check: no update channel configured.\n");
|
|
1093
1083
|
}
|
|
1084
|
+
return 0;
|
|
1094
1085
|
}
|
|
1095
1086
|
async function cleanupRepos(config, mode, force, cleanup, io) {
|
|
1096
1087
|
const repos = config.repoMappings.filter((mapping) => mapping.localPath?.trim());
|
|
@@ -1137,158 +1128,6 @@ async function cleanupRepos(config, mode, force, cleanup, io) {
|
|
|
1137
1128
|
}
|
|
1138
1129
|
return failures === 0 ? 0 : 1;
|
|
1139
1130
|
}
|
|
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
1131
|
async function withDetectedCliProviders(config, candidates = config.cliProviders) {
|
|
1293
1132
|
const detected = await detectCliProviders(uniqueProviders(candidates));
|
|
1294
1133
|
const found = detected.filter((result) => result.found);
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { type BridgeIdleEvaluation, type BridgeStateRead } from "../bridge/bridge-state-file.js";
|
|
2
|
+
import { type InFlightEntry } from "../bridge/in-flight-registry.js";
|
|
3
|
+
import type { BridgeServiceConfig } from "../bridge/bridge.types.js";
|
|
4
|
+
import type { CliIo } from "./cli.base.js";
|
|
5
|
+
export interface IdleStatusOptions {
|
|
6
|
+
readonly json: boolean;
|
|
7
|
+
/** Seconds to keep polling while the bridge is busy, stale or not yet yielding; 0 (or no --wait) checks once. */
|
|
8
|
+
readonly waitSeconds: number;
|
|
9
|
+
/** Idle counts only once the bridge itself reports yield (exit 5 until then). */
|
|
10
|
+
readonly requireYield: boolean;
|
|
11
|
+
}
|
|
12
|
+
export type StatusArgs = {
|
|
13
|
+
readonly ok: true;
|
|
14
|
+
readonly command: "status";
|
|
15
|
+
readonly config: BridgeServiceConfig;
|
|
16
|
+
readonly checkUpdates: boolean;
|
|
17
|
+
readonly idle: IdleStatusOptions | null;
|
|
18
|
+
} | {
|
|
19
|
+
readonly ok: false;
|
|
20
|
+
readonly error: string;
|
|
21
|
+
};
|
|
22
|
+
export declare function parseStatusArgs(argv: readonly string[], config: () => BridgeServiceConfig): StatusArgs;
|
|
23
|
+
export interface IdleStatusDependencies {
|
|
24
|
+
readonly statePath: string;
|
|
25
|
+
readonly now: () => number;
|
|
26
|
+
readonly pidAlive: (pid: number) => boolean;
|
|
27
|
+
readonly read: (statePath: string) => Promise<BridgeStateRead>;
|
|
28
|
+
readonly localYield: () => Promise<boolean>;
|
|
29
|
+
readonly sleep: (ms: number) => Promise<void>;
|
|
30
|
+
readonly pollMs: number;
|
|
31
|
+
}
|
|
32
|
+
export declare function defaultIdleStatusDependencies(): IdleStatusDependencies;
|
|
33
|
+
export declare function runIdleStatusCommand(options: IdleStatusOptions, io: CliIo, deps?: IdleStatusDependencies): Promise<number>;
|
|
34
|
+
/** One line for plain `forge-bridge status`. */
|
|
35
|
+
export declare function idleSummaryLine(deps?: IdleStatusDependencies): Promise<string>;
|
|
36
|
+
export declare function idleStatusJson(evaluation: BridgeIdleEvaluation, deps: Pick<IdleStatusDependencies, "statePath" | "now">, localYield: boolean): {
|
|
37
|
+
pid: null;
|
|
38
|
+
runnerId: null;
|
|
39
|
+
runnerInstanceId: null;
|
|
40
|
+
version: null;
|
|
41
|
+
state: null;
|
|
42
|
+
startedAt: null;
|
|
43
|
+
updatedAt: null;
|
|
44
|
+
connected: null;
|
|
45
|
+
yielding: null;
|
|
46
|
+
yieldApplied: null;
|
|
47
|
+
conflict: null;
|
|
48
|
+
inFlight: readonly InFlightEntry[];
|
|
49
|
+
schemaVersion: number;
|
|
50
|
+
verdict: import("../bridge/bridge-state-file.js").BridgeIdleVerdict;
|
|
51
|
+
idle: boolean;
|
|
52
|
+
exitCode: number;
|
|
53
|
+
reason: string;
|
|
54
|
+
statePath: string;
|
|
55
|
+
checkedAt: string;
|
|
56
|
+
pidAlive: boolean | null;
|
|
57
|
+
heartbeatAgeMs: number | null;
|
|
58
|
+
staleAfterMs: number;
|
|
59
|
+
localYield: boolean;
|
|
60
|
+
} | {
|
|
61
|
+
pid: number;
|
|
62
|
+
runnerId: string;
|
|
63
|
+
runnerInstanceId: string;
|
|
64
|
+
version: string;
|
|
65
|
+
state: "running" | "stopped";
|
|
66
|
+
startedAt: string;
|
|
67
|
+
updatedAt: string;
|
|
68
|
+
connected: boolean;
|
|
69
|
+
yielding: boolean;
|
|
70
|
+
yieldApplied: boolean;
|
|
71
|
+
conflict: import("../bridge/bridge-state-file.js").BridgeStateConflict | null;
|
|
72
|
+
inFlight: readonly InFlightEntry[];
|
|
73
|
+
schemaVersion: number;
|
|
74
|
+
verdict: import("../bridge/bridge-state-file.js").BridgeIdleVerdict;
|
|
75
|
+
idle: boolean;
|
|
76
|
+
exitCode: number;
|
|
77
|
+
reason: string;
|
|
78
|
+
statePath: string;
|
|
79
|
+
checkedAt: string;
|
|
80
|
+
pidAlive: boolean | null;
|
|
81
|
+
heartbeatAgeMs: number | null;
|
|
82
|
+
staleAfterMs: number;
|
|
83
|
+
localYield: boolean;
|
|
84
|
+
};
|
|
@@ -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
|
+
}
|
|
@@ -34,6 +34,8 @@ export declare function readLocalConfigSync(): BridgeLocalConfig;
|
|
|
34
34
|
export declare const localConfigFileMode = 384;
|
|
35
35
|
export declare function writeLocalConfig(config: BridgeLocalConfig): Promise<void>;
|
|
36
36
|
export declare function applyLocalConfigDefaults(config: BridgeServiceConfig, local: BridgeLocalConfig): BridgeServiceConfig;
|
|
37
|
+
/** Where `forge-bridge connect` publishes whether it is idle: `bridge.state.json` beside the config. */
|
|
38
|
+
export declare function resolveBridgeStatePath(): string;
|
|
37
39
|
/** Decision 0014: the `forge-bridge yield` flag, beside the bridge config and never inside it. */
|
|
38
40
|
export declare function resolveLocalYieldFlagPath(): string;
|
|
39
41
|
export declare function addRepoMapping(label: string, repoPath: string): Promise<BridgeLocalConfig>;
|
package/dist/cli/local-config.js
CHANGED
|
@@ -3,6 +3,7 @@ import fsSync from "node:fs";
|
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { localYieldFlagPathFor } from "../bridge/local-yield-flag.js";
|
|
6
|
+
import { bridgeStatePathFor } from "../bridge/bridge-state-file.js";
|
|
6
7
|
export function resolveLocalConfigPath() {
|
|
7
8
|
if (process.env.FORGE_BRIDGE_CONFIG?.trim()) {
|
|
8
9
|
return path.resolve(process.env.FORGE_BRIDGE_CONFIG);
|
|
@@ -83,9 +84,14 @@ export function applyLocalConfigDefaults(config, local) {
|
|
|
83
84
|
supportsDraftRunOnce: local.supportsDraftRunOnce ?? config.supportsDraftRunOnce,
|
|
84
85
|
supportsDraftAttachments: local.supportsDraftAttachments ?? config.supportsDraftAttachments,
|
|
85
86
|
supportsDraftImageAttachments: local.supportsDraftImageAttachments ?? config.supportsDraftImageAttachments,
|
|
86
|
-
localYieldFlagPath: resolveLocalYieldFlagPath()
|
|
87
|
+
localYieldFlagPath: resolveLocalYieldFlagPath(),
|
|
88
|
+
bridgeStatePath: resolveBridgeStatePath()
|
|
87
89
|
};
|
|
88
90
|
}
|
|
91
|
+
/** Where `forge-bridge connect` publishes whether it is idle: `bridge.state.json` beside the config. */
|
|
92
|
+
export function resolveBridgeStatePath() {
|
|
93
|
+
return bridgeStatePathFor(resolveLocalConfigPath());
|
|
94
|
+
}
|
|
89
95
|
/** Decision 0014: the `forge-bridge yield` flag, beside the bridge config and never inside it. */
|
|
90
96
|
export function resolveLocalYieldFlagPath() {
|
|
91
97
|
return localYieldFlagPathFor(resolveLocalConfigPath());
|
|
@@ -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[];
|