@loucompanion/forge-bridge 0.1.4-dev.d2d83bc81b6a → 0.1.4-dev.deb7f72e7930
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 +144 -3
- package/dist/bridge/bridge-chat-provider-command.d.ts +19 -0
- package/dist/bridge/bridge-chat-provider-command.js +132 -0
- package/dist/bridge/bridge-chat.types.d.ts +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.base.d.ts +9 -0
- package/dist/bridge/bridge.service.d.ts +92 -15
- package/dist/bridge/bridge.service.js +432 -342
- package/dist/bridge/bridge.types.d.ts +27 -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 +17 -0
- package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
- package/dist/bridge/sandbox-resource-accounting.js +150 -0
- package/dist/bridge/test-postgres-capability.d.ts +14 -0
- package/dist/bridge/test-postgres-capability.js +120 -0
- package/dist/cleanup/cleanup-wip.d.ts +12 -0
- package/dist/cleanup/cleanup-wip.js +66 -0
- package/dist/cleanup/cleanup.service.d.ts +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 +9 -0
- package/dist/cleanup/forge-owned-paths.js +53 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +7 -0
- package/dist/cleanup/host-runtime-ledger.js +130 -0
- package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
- package/dist/cleanup/managed-branch-sweep.js +111 -0
- package/dist/cli/cli.help.js +74 -12
- package/dist/cli/cli.service.d.ts +19 -10
- package/dist/cli/cli.service.js +152 -187
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +6 -0
- package/dist/cli/local-config.js +32 -4
- package/dist/cli/provider-cli-detection.d.ts +10 -0
- package/dist/cli/provider-cli-detection.js +160 -0
- package/dist/runtime/aspnet-runtime-prebuild.d.ts +5 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +140 -7
- package/dist/runtime/attempt-database-broker.d.ts +1 -1
- package/dist/runtime/docker-engine-probe.d.ts +5 -0
- package/dist/runtime/docker-engine-probe.js +7 -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-database-capability-boundary.d.ts +1 -1
- package/dist/runtime/host-database-capability-boundary.js +1 -0
- package/dist/runtime/host-facts.d.ts +36 -0
- package/dist/runtime/host-facts.js +95 -0
- package/dist/runtime/host-load-admission.d.ts +67 -0
- package/dist/runtime/host-load-admission.js +99 -0
- package/dist/runtime/host-load-child-environment.d.ts +27 -0
- package/dist/runtime/host-load-child-environment.js +76 -0
- package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
- package/dist/runtime/host-load-forge-cgroups.js +140 -0
- package/dist/runtime/host-load-governor-config.d.ts +52 -0
- package/dist/runtime/host-load-governor-config.js +83 -0
- package/dist/runtime/host-load-governor.d.ts +186 -0
- package/dist/runtime/host-load-governor.js +632 -0
- package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
- package/dist/runtime/host-load-ledger-lock.js +187 -0
- package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
- package/dist/runtime/host-load-runtime-settings.js +80 -0
- package/dist/runtime/host-load-sampler.d.ts +156 -0
- package/dist/runtime/host-load-sampler.js +298 -0
- package/dist/runtime/host-load-step-class.d.ts +70 -0
- package/dist/runtime/host-load-step-class.js +161 -0
- package/dist/runtime/host-load-step-reaper.d.ts +27 -0
- package/dist/runtime/host-load-step-reaper.js +95 -0
- package/dist/runtime/host-load-step-run.d.ts +73 -0
- package/dist/runtime/host-load-step-run.js +102 -0
- package/dist/runtime/host-load-test-slot.d.ts +43 -0
- package/dist/runtime/host-load-test-slot.js +81 -0
- package/dist/runtime/host-load-token-ledger.d.ts +200 -0
- package/dist/runtime/host-load-token-ledger.js +453 -0
- package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
- package/dist/runtime/host-load-windows-cpu.js +85 -0
- package/dist/runtime/host-pressure-stall.d.ts +61 -0
- package/dist/runtime/host-pressure-stall.js +168 -0
- package/dist/runtime/host-runtime-contract.d.ts +16 -0
- package/dist/runtime/host-runtime-contract.js +35 -2
- package/dist/runtime/host-runtime-lease.d.ts +74 -4
- package/dist/runtime/host-runtime-lease.js +285 -55
- package/dist/runtime/host-runtime-promotion.d.ts +23 -0
- package/dist/runtime/host-runtime-promotion.js +48 -0
- 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/runner-settings.d.ts +104 -0
- package/dist/runtime/runner-settings.js +236 -0
- package/dist/sandbox/host-capacity-broker.d.ts +115 -0
- package/dist/sandbox/host-capacity-broker.js +336 -0
- package/dist/sandbox/managed-branch.d.ts +13 -0
- package/dist/sandbox/managed-branch.js +36 -0
- package/dist/sandbox/provider-auth/codex.js +11 -11
- package/dist/sandbox/runtime.d.ts +10 -1
- package/dist/sandbox/runtime.js +47 -8
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -0
- package/dist/session/architect-waits.d.ts +2 -0
- package/dist/session/architect-waits.js +138 -0
- package/dist/session/managed-attempt-tools.d.ts +2 -7
- package/dist/session/managed-attempt-tools.js +202 -116
- package/dist/session/managed-build-receipt.d.ts +5 -0
- package/dist/session/managed-build-receipt.js +8 -3
- package/dist/session/managed-command-host-load.d.ts +47 -0
- package/dist/session/managed-command-host-load.js +83 -0
- package/dist/session/mcp-argument-coercion.d.ts +23 -0
- package/dist/session/mcp-argument-coercion.js +121 -0
- package/dist/session/phase-completion.artifacts.d.ts +7 -0
- package/dist/session/phase-completion.artifacts.js +100 -26
- 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 +12 -0
- package/dist/session/phase-completion.helpers.js +13 -12
- package/dist/session/phase-completion.js +5 -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.prompts.js +6 -1
- package/dist/session/phase-completion.runtime.d.ts +5 -11
- package/dist/session/phase-completion.runtime.js +91 -215
- 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 +208 -231
- package/dist/session/phase-completion.validation.d.ts +2 -3
- package/dist/session/phase-completion.validation.js +49 -93
- package/dist/session/pre-publication-host-load.d.ts +27 -0
- package/dist/session/pre-publication-host-load.js +111 -0
- package/dist/session/pre-publication-native-postgres.d.ts +30 -0
- package/dist/session/pre-publication-native-postgres.js +111 -0
- package/dist/session/pre-publication-pass.d.ts +61 -0
- package/dist/session/pre-publication-pass.js +148 -0
- package/dist/session/pre-publication-process.d.ts +3 -0
- package/dist/session/pre-publication-process.js +33 -20
- package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
- package/dist/session/pre-publication-skipped-tests.js +109 -0
- package/dist/session/pre-publication-step-execution.d.ts +12 -0
- package/dist/session/pre-publication-step-execution.js +50 -0
- package/dist/session/pre-publication-validation.d.ts +37 -21
- package/dist/session/pre-publication-validation.js +224 -166
- package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
- package/dist/session/provider-cli/claude-background-work.js +181 -0
- package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
- package/dist/session/provider-cli/host-build-lock.js +30 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
- package/dist/session/provider-cli/pre-publication-repair.js +276 -0
- package/dist/session/provider-cli/provider-cli.artifacts.d.ts +2 -1
- package/dist/session/provider-cli/provider-cli.artifacts.js +21 -15
- 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.merge-integrity.d.ts +89 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +41 -31
- package/dist/session/provider-cli/provider-cli.process.js +139 -438
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +87 -32
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +8 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +29 -1
- package/dist/session/provider-cli/provider-cli.service.d.ts +7 -1
- package/dist/session/provider-cli/provider-cli.service.js +200 -189
- package/dist/session/provider-cli/provider-cli.types.d.ts +30 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +10 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +92 -0
- package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
- package/dist/session/provider-cli/provider-output-pipes.js +67 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +8 -0
- package/dist/session/provider-cli/provider-output-state.js +15 -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/publishable-worktree-changes.d.ts +54 -0
- package/dist/session/publishable-worktree-changes.js +193 -0
- package/dist/session/qa-sidecar-validation.d.ts +6 -0
- package/dist/session/qa-sidecar-validation.js +28 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +51 -0
- package/dist/session/sandbox-host-capacity-gate.js +257 -0
- package/dist/session/session-redaction.js +31 -181
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.service.d.ts +11 -2
- package/dist/session/session.service.js +182 -61
- package/dist/session/session.types.d.ts +3 -0
- package/dist/session/session.types.js +15 -3
- 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.js +14 -7
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/dependency-warmer.d.ts +25 -0
- package/dist/worktree/dependency-warmer.js +46 -10
- 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 +49 -0
- package/dist/worktree/worktree-wip.js +182 -0
- package/dist/worktree/worktree.base.d.ts +7 -1
- package/dist/worktree/worktree.service.d.ts +36 -5
- package/dist/worktree/worktree.service.js +120 -155
- package/dist/worktree/worktree.types.d.ts +38 -0
- package/package.json +2 -2
|
@@ -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
|
+
}
|
|
@@ -30,8 +30,14 @@ export interface LocalRepoMapping extends BridgeRepoMapping {
|
|
|
30
30
|
export declare function resolveLocalConfigPath(): string;
|
|
31
31
|
export declare function readLocalConfig(): Promise<BridgeLocalConfig>;
|
|
32
32
|
export declare function readLocalConfigSync(): BridgeLocalConfig;
|
|
33
|
+
/** Decision 0014 §5: `bridge.json` holds the device token, so only its owner may read it. */
|
|
34
|
+
export declare const localConfigFileMode = 384;
|
|
33
35
|
export declare function writeLocalConfig(config: BridgeLocalConfig): Promise<void>;
|
|
34
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;
|
|
39
|
+
/** Decision 0014: the `forge-bridge yield` flag, beside the bridge config and never inside it. */
|
|
40
|
+
export declare function resolveLocalYieldFlagPath(): string;
|
|
35
41
|
export declare function addRepoMapping(label: string, repoPath: string): Promise<BridgeLocalConfig>;
|
|
36
42
|
export declare function removeRepoMapping(label: string): Promise<{
|
|
37
43
|
readonly config: BridgeLocalConfig;
|
package/dist/cli/local-config.js
CHANGED
|
@@ -2,6 +2,8 @@ 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 { localYieldFlagPathFor } from "../bridge/local-yield-flag.js";
|
|
6
|
+
import { bridgeStatePathFor } from "../bridge/bridge-state-file.js";
|
|
5
7
|
export function resolveLocalConfigPath() {
|
|
6
8
|
if (process.env.FORGE_BRIDGE_CONFIG?.trim()) {
|
|
7
9
|
return path.resolve(process.env.FORGE_BRIDGE_CONFIG);
|
|
@@ -28,12 +30,28 @@ export function readLocalConfigSync() {
|
|
|
28
30
|
}
|
|
29
31
|
return parseLocalConfig(fsSync.readFileSync(configPath, "utf8"));
|
|
30
32
|
}
|
|
33
|
+
/** Decision 0014 §5: `bridge.json` holds the device token, so only its owner may read it. */
|
|
34
|
+
export const localConfigFileMode = 0o600;
|
|
35
|
+
const localConfigDirectoryMode = 0o700;
|
|
31
36
|
export async function writeLocalConfig(config) {
|
|
32
37
|
const configPath = resolveLocalConfigPath();
|
|
33
|
-
await fs.mkdir(path.dirname(configPath), { recursive: true });
|
|
38
|
+
await fs.mkdir(path.dirname(configPath), { recursive: true, mode: localConfigDirectoryMode });
|
|
34
39
|
const tempPath = `${configPath}.${process.pid}.${Date.now()}.tmp`;
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
try {
|
|
41
|
+
await fs.writeFile(tempPath, `${JSON.stringify(normalizeLocalConfig(config), null, 2)}\n`, {
|
|
42
|
+
encoding: "utf8",
|
|
43
|
+
mode: localConfigFileMode
|
|
44
|
+
});
|
|
45
|
+
if (process.platform !== "win32") {
|
|
46
|
+
// The create mode is masked by the umask; set it exactly before the file becomes visible.
|
|
47
|
+
await fs.chmod(tempPath, localConfigFileMode);
|
|
48
|
+
}
|
|
49
|
+
await fs.rename(tempPath, configPath);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
await fs.rm(tempPath, { force: true }).catch(() => undefined);
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
37
55
|
}
|
|
38
56
|
export function applyLocalConfigDefaults(config, local) {
|
|
39
57
|
const cliProviders = local.cliProviders && local.cliProviders.length > 0 ? [...local.cliProviders] : config.cliProviders;
|
|
@@ -65,9 +83,19 @@ export function applyLocalConfigDefaults(config, local) {
|
|
|
65
83
|
supportsRunnerAuthoredPhaseArtifacts: local.supportsRunnerAuthoredPhaseArtifacts ?? config.supportsRunnerAuthoredPhaseArtifacts,
|
|
66
84
|
supportsDraftRunOnce: local.supportsDraftRunOnce ?? config.supportsDraftRunOnce,
|
|
67
85
|
supportsDraftAttachments: local.supportsDraftAttachments ?? config.supportsDraftAttachments,
|
|
68
|
-
supportsDraftImageAttachments: local.supportsDraftImageAttachments ?? config.supportsDraftImageAttachments
|
|
86
|
+
supportsDraftImageAttachments: local.supportsDraftImageAttachments ?? config.supportsDraftImageAttachments,
|
|
87
|
+
localYieldFlagPath: resolveLocalYieldFlagPath(),
|
|
88
|
+
bridgeStatePath: resolveBridgeStatePath()
|
|
69
89
|
};
|
|
70
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
|
+
}
|
|
95
|
+
/** Decision 0014: the `forge-bridge yield` flag, beside the bridge config and never inside it. */
|
|
96
|
+
export function resolveLocalYieldFlagPath() {
|
|
97
|
+
return localYieldFlagPathFor(resolveLocalConfigPath());
|
|
98
|
+
}
|
|
71
99
|
export async function addRepoMapping(label, repoPath) {
|
|
72
100
|
const normalizedLabel = normalizeLabel(label);
|
|
73
101
|
const localPath = path.resolve(repoPath);
|
|
@@ -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
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AttemptProcessSupervisor } from "./attempt-process-supervisor.js";
|
|
1
2
|
export interface AspNetRuntimePrebuildPlan {
|
|
2
3
|
readonly fingerprint: string;
|
|
3
4
|
readonly receiptPath: string;
|
|
@@ -22,6 +23,10 @@ export interface AspNetRuntimeBuildExecutionResult {
|
|
|
22
23
|
readonly stderrLogPath: string;
|
|
23
24
|
}
|
|
24
25
|
export type AspNetRuntimeBuildExecutor = (plan: AspNetRuntimePrebuildPlan, signal?: AbortSignal) => Promise<AspNetRuntimeBuildExecutionResult>;
|
|
26
|
+
/** Runs one ASP.NET runtime build under the attempt's supervisor, logging only redacted output. */
|
|
27
|
+
export declare function executeAspNetRuntimeBuild(supervisor: AttemptProcessSupervisor, logDirectory: string, plan: AspNetRuntimePrebuildPlan, signal?: AbortSignal, exactSecrets?: readonly string[],
|
|
28
|
+
/** Once the build's supervised tree is up: records it on the build's host load token. */
|
|
29
|
+
onStarted?: (metadataPath: string) => Promise<void>): Promise<AspNetRuntimeBuildExecutionResult>;
|
|
25
30
|
export declare function createAspNetRuntimePrebuildPlan(options: {
|
|
26
31
|
readonly command: string;
|
|
27
32
|
readonly args: readonly string[];
|
|
@@ -3,7 +3,52 @@ import { spawn } from "node:child_process";
|
|
|
3
3
|
import fs from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { ForgeFailureError } from "../session/session.types.js";
|
|
6
|
+
import { redactText } from "../shared/redaction/redaction.js";
|
|
7
|
+
import { replaceFile } from "../shared/fs/replace-file.js";
|
|
6
8
|
const inFlightPrebuilds = new Map();
|
|
9
|
+
/** Runs one ASP.NET runtime build under the attempt's supervisor, logging only redacted output. */
|
|
10
|
+
export async function executeAspNetRuntimeBuild(supervisor, logDirectory, plan, signal, exactSecrets = [],
|
|
11
|
+
/** Once the build's supervised tree is up: records it on the build's host load token. */
|
|
12
|
+
onStarted) {
|
|
13
|
+
const childName = `runtime-build-${plan.fingerprint.slice(-12)}`;
|
|
14
|
+
const stdoutLogPath = path.join(logDirectory, `${childName}.stdout.log`);
|
|
15
|
+
const stderrLogPath = path.join(logDirectory, `${childName}.stderr.log`);
|
|
16
|
+
let stdoutTail = "";
|
|
17
|
+
let stderrTail = "";
|
|
18
|
+
const append = async (target, line) => {
|
|
19
|
+
await fs.appendFile(target, `${redactText(line, exactSecrets)}\n`, { encoding: "utf8", mode: 0o600 });
|
|
20
|
+
};
|
|
21
|
+
const child = await supervisor.startChildReady(childName, {
|
|
22
|
+
command: plan.command,
|
|
23
|
+
args: plan.args,
|
|
24
|
+
cwd: plan.cwd,
|
|
25
|
+
env: plan.environment,
|
|
26
|
+
captureOutput: false,
|
|
27
|
+
}, {
|
|
28
|
+
onStdoutLine: async (line) => {
|
|
29
|
+
stdoutTail = appendRuntimeBuildTail(stdoutTail, redactText(line, exactSecrets));
|
|
30
|
+
await append(stdoutLogPath, line);
|
|
31
|
+
},
|
|
32
|
+
onStderrLine: async (line) => {
|
|
33
|
+
stderrTail = appendRuntimeBuildTail(stderrTail, redactText(line, exactSecrets));
|
|
34
|
+
await append(stderrLogPath, line);
|
|
35
|
+
},
|
|
36
|
+
}, signal, { maxStartAttempts: 2, retryDelayMs: 250 });
|
|
37
|
+
await onStarted?.(child.metadataPath);
|
|
38
|
+
const result = await child.result;
|
|
39
|
+
return {
|
|
40
|
+
exitCode: result.exitCode,
|
|
41
|
+
stdoutTail: appendRuntimeBuildTail(stdoutTail, redactText(result.stdout, exactSecrets)),
|
|
42
|
+
stderrTail: appendRuntimeBuildTail(stderrTail, redactText(result.stderr, exactSecrets)),
|
|
43
|
+
stdoutLogPath,
|
|
44
|
+
stderrLogPath,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function appendRuntimeBuildTail(current, value) {
|
|
48
|
+
if (!value)
|
|
49
|
+
return current;
|
|
50
|
+
return `${current}${current ? "\n" : ""}${value}`.slice(-4_000);
|
|
51
|
+
}
|
|
7
52
|
export function createAspNetRuntimePrebuildPlan(options) {
|
|
8
53
|
if (!isDotnetRun(options.command, options.args))
|
|
9
54
|
return null;
|
|
@@ -101,7 +146,7 @@ async function ensureAspNetRuntimePrebuiltCore(plan, execute, signal) {
|
|
|
101
146
|
};
|
|
102
147
|
await fs.writeFile(temporaryReceipt, `${JSON.stringify(nextReceipt)}\n`, { encoding: "utf8", mode: 0o600 });
|
|
103
148
|
try {
|
|
104
|
-
await
|
|
149
|
+
await replaceFile(temporaryReceipt, plan.receiptPath);
|
|
105
150
|
}
|
|
106
151
|
finally {
|
|
107
152
|
await fs.rm(temporaryReceipt, { force: true }).catch(() => undefined);
|
|
@@ -211,7 +256,7 @@ async function aspNetBuildInputs(plan) {
|
|
|
211
256
|
const projectDirectory = path.extname(plan.projectPath).toLowerCase() === ".csproj"
|
|
212
257
|
? path.dirname(plan.projectPath)
|
|
213
258
|
: plan.projectPath;
|
|
214
|
-
const sourceDigest = await
|
|
259
|
+
const sourceDigest = await projectSourceDigest(plan, projectDirectory);
|
|
215
260
|
const dependencyReceipt = path.join(projectDirectory, "obj", ".forge-dependency-preparation.json");
|
|
216
261
|
const dependencyContent = await fs.readFile(dependencyReceipt).catch(() => null);
|
|
217
262
|
const globalJson = await findAncestorFile(projectDirectory, plan.worktreePath, "global.json");
|
|
@@ -225,18 +270,106 @@ async function aspNetBuildInputs(plan) {
|
|
|
225
270
|
sdkVersion: await dotnetSdkVersion(plan.cwd),
|
|
226
271
|
};
|
|
227
272
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
273
|
+
/**
|
|
274
|
+
* Digest of everything the project build compiles from inside the worktree: the
|
|
275
|
+
* project directory, every project it references (transitively, through
|
|
276
|
+
* ProjectReference), and the Directory.Build/Directory.Packages files above them.
|
|
277
|
+
* A change in a referenced project must invalidate the receipt, or the launch
|
|
278
|
+
* reuses a binary built from the previous source.
|
|
279
|
+
*/
|
|
280
|
+
async function projectSourceDigest(plan, projectDirectory) {
|
|
281
|
+
const worktree = path.resolve(plan.worktreePath);
|
|
282
|
+
const directories = await projectSourceDirectories(plan, projectDirectory);
|
|
283
|
+
const files = new Set();
|
|
284
|
+
for (const directory of directories) {
|
|
285
|
+
const collected = [];
|
|
286
|
+
await collectInputFiles(directory, directory, collected);
|
|
287
|
+
for (const file of collected)
|
|
288
|
+
files.add(file);
|
|
289
|
+
for (const buildFile of await ancestorBuildFiles(directory, worktree))
|
|
290
|
+
files.add(buildFile);
|
|
291
|
+
}
|
|
231
292
|
const hash = createHash("sha256");
|
|
232
|
-
for (const file of files.sort((left, right) => left.localeCompare(right))) {
|
|
233
|
-
hash.update(path.relative(
|
|
293
|
+
for (const file of [...files].sort((left, right) => left.localeCompare(right))) {
|
|
294
|
+
hash.update(path.relative(worktree, file).replaceAll("\\", "/"));
|
|
234
295
|
hash.update("\0");
|
|
235
296
|
hash.update(await fs.readFile(file));
|
|
236
297
|
hash.update("\0");
|
|
237
298
|
}
|
|
238
299
|
return `sha256:${hash.digest("hex")}`;
|
|
239
300
|
}
|
|
301
|
+
const msbuildProjectExtensions = new Set([".csproj", ".fsproj", ".vbproj"]);
|
|
302
|
+
const msbuildDirectoryFiles = ["Directory.Build.props", "Directory.Build.targets", "Directory.Packages.props"];
|
|
303
|
+
/** The project directory and the directories of the projects it references inside the worktree. */
|
|
304
|
+
async function projectSourceDirectories(plan, projectDirectory) {
|
|
305
|
+
const worktree = path.resolve(plan.worktreePath);
|
|
306
|
+
const directories = new Set([path.resolve(projectDirectory)]);
|
|
307
|
+
const queue = msbuildProjectExtensions.has(path.extname(plan.projectPath).toLowerCase())
|
|
308
|
+
? [path.resolve(plan.projectPath)]
|
|
309
|
+
: await projectFilesIn(projectDirectory);
|
|
310
|
+
const visited = new Set();
|
|
311
|
+
while (queue.length > 0) {
|
|
312
|
+
const projectFile = queue.shift();
|
|
313
|
+
if (visited.has(projectFile))
|
|
314
|
+
continue;
|
|
315
|
+
visited.add(projectFile);
|
|
316
|
+
const content = await fs.readFile(projectFile, "utf8").catch(() => null);
|
|
317
|
+
if (content === null)
|
|
318
|
+
continue;
|
|
319
|
+
for (const include of projectReferenceIncludes(content)) {
|
|
320
|
+
// An MSBuild property cannot be resolved here; the referenced source stays outside the digest.
|
|
321
|
+
if (include.includes("$("))
|
|
322
|
+
continue;
|
|
323
|
+
const referenced = path.resolve(path.dirname(projectFile), include.replaceAll("\\", "/"));
|
|
324
|
+
if (!containedIn(worktree, referenced))
|
|
325
|
+
continue;
|
|
326
|
+
directories.add(path.dirname(referenced));
|
|
327
|
+
queue.push(referenced);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return [...directories];
|
|
331
|
+
}
|
|
332
|
+
async function projectFilesIn(directory) {
|
|
333
|
+
const entries = await fs.readdir(directory, { withFileTypes: true }).catch(() => []);
|
|
334
|
+
return entries
|
|
335
|
+
.filter(entry => entry.isFile() && msbuildProjectExtensions.has(path.extname(entry.name).toLowerCase()))
|
|
336
|
+
.map(entry => path.join(directory, entry.name));
|
|
337
|
+
}
|
|
338
|
+
function projectReferenceIncludes(projectXml) {
|
|
339
|
+
const withoutComments = projectXml.replaceAll(/<!--[\s\S]*?-->/gu, "");
|
|
340
|
+
const includes = [];
|
|
341
|
+
for (const match of withoutComments.matchAll(/<ProjectReference\b[^>]*?\bInclude\s*=\s*(?:"([^"]*)"|'([^']*)')/giu)) {
|
|
342
|
+
const value = match[1] ?? match[2] ?? "";
|
|
343
|
+
for (const part of value.split(";")) {
|
|
344
|
+
const trimmed = part.trim();
|
|
345
|
+
if (trimmed)
|
|
346
|
+
includes.push(trimmed);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return includes;
|
|
350
|
+
}
|
|
351
|
+
async function ancestorBuildFiles(directory, worktree) {
|
|
352
|
+
const found = [];
|
|
353
|
+
let current = path.resolve(directory);
|
|
354
|
+
while (containedIn(worktree, current)) {
|
|
355
|
+
for (const name of msbuildDirectoryFiles) {
|
|
356
|
+
const candidate = path.join(current, name);
|
|
357
|
+
if (await fs.stat(candidate).then(stat => stat.isFile()).catch(() => false))
|
|
358
|
+
found.push(candidate);
|
|
359
|
+
}
|
|
360
|
+
if (current === worktree)
|
|
361
|
+
break;
|
|
362
|
+
const parent = path.dirname(current);
|
|
363
|
+
if (parent === current)
|
|
364
|
+
break;
|
|
365
|
+
current = parent;
|
|
366
|
+
}
|
|
367
|
+
return found;
|
|
368
|
+
}
|
|
369
|
+
function containedIn(root, candidate) {
|
|
370
|
+
const relative = path.relative(root, candidate);
|
|
371
|
+
return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
|
|
372
|
+
}
|
|
240
373
|
async function collectInputFiles(root, directory, files) {
|
|
241
374
|
const entries = await fs.readdir(directory, { withFileTypes: true }).catch(() => []);
|
|
242
375
|
for (const entry of entries) {
|
|
@@ -75,7 +75,7 @@ export interface NativeTestClusterAdmin {
|
|
|
75
75
|
readonly username: string;
|
|
76
76
|
readonly password: string;
|
|
77
77
|
}
|
|
78
|
-
export declare function nativeTestClusterAdmin(fallback: NativeTestPostgresFallback): NativeTestClusterAdmin;
|
|
78
|
+
export declare function nativeTestClusterAdmin(fallback: Pick<NativeTestPostgresFallback, "connectionString" | "endpoint">): NativeTestClusterAdmin;
|
|
79
79
|
/** Runs SQL through the psql that ships with the PostgreSQL install hosting the native test cluster. */
|
|
80
80
|
export declare function psqlSqlRunner(admin: NativeTestClusterAdmin, psqlPath: string, timeoutMs?: number): AttemptDatabaseSqlRunner;
|
|
81
81
|
/** psql beside the cluster's pg_ctl: FORGE_NATIVE_TEST_POSTGRES_PSQL, a Windows install, or PATH. */
|
|
@@ -62,6 +62,11 @@ export declare class DockerEngineProbe {
|
|
|
62
62
|
constructor(options?: DockerEngineProbeOptions, commands?: CommandRunner, cacheMs?: number);
|
|
63
63
|
current(): DockerEngineCapabilitySnapshot | null;
|
|
64
64
|
refresh(force?: boolean): Promise<DockerEngineCapabilitySnapshot>;
|
|
65
|
+
/**
|
|
66
|
+
* One fresh daemon reading that never starts recovery and leaves the cache and the
|
|
67
|
+
* failure streak alone, for callers that only need to know whether Docker is up.
|
|
68
|
+
*/
|
|
69
|
+
probeWithoutRecovery(): Promise<DockerEngineCapabilitySnapshot>;
|
|
65
70
|
/**
|
|
66
71
|
* Establishes a fresh daemon fence for work that declares Docker as a hard
|
|
67
72
|
* prerequisite. This remains bounded, cooldown protected and single-flight;
|
|
@@ -69,6 +69,13 @@ export class DockerEngineProbe {
|
|
|
69
69
|
this.inFlight = operation;
|
|
70
70
|
return await operation;
|
|
71
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* One fresh daemon reading that never starts recovery and leaves the cache and the
|
|
74
|
+
* failure streak alone, for callers that only need to know whether Docker is up.
|
|
75
|
+
*/
|
|
76
|
+
async probeWithoutRecovery() {
|
|
77
|
+
return await this.inspectSafely();
|
|
78
|
+
}
|
|
72
79
|
/**
|
|
73
80
|
* Establishes a fresh daemon fence for work that declares Docker as a hard
|
|
74
81
|
* prerequisite. This remains bounded, cooldown protected and single-flight;
|