@loucompanion/forge-bridge 0.1.4-dev.c1ae24134918 → 0.1.4-dev.cabe9c22da46
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 +142 -1
- 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 +87 -14
- package/dist/bridge/bridge.service.js +394 -338
- package/dist/bridge/bridge.types.d.ts +16 -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 +3 -0
- package/dist/bridge/runner-host-capabilities.js +13 -0
- package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
- package/dist/bridge/sandbox-resource-accounting.js +150 -0
- package/dist/cleanup/cleanup.service.d.ts +9 -0
- package/dist/cleanup/cleanup.service.js +76 -115
- package/dist/cleanup/cleanup.types.d.ts +4 -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 +5 -0
- package/dist/cleanup/host-runtime-ledger.js +109 -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 +149 -186
- 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-facts.d.ts +2 -1
- package/dist/runtime/host-load-admission.d.ts +18 -3
- package/dist/runtime/host-load-admission.js +19 -4
- package/dist/runtime/host-load-child-environment.d.ts +11 -6
- package/dist/runtime/host-load-child-environment.js +22 -11
- package/dist/runtime/host-load-governor-config.d.ts +19 -1
- package/dist/runtime/host-load-governor-config.js +37 -0
- package/dist/runtime/host-load-governor.d.ts +12 -0
- package/dist/runtime/host-load-governor.js +139 -26
- package/dist/runtime/host-load-ledger-lock.js +6 -4
- 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 +34 -4
- package/dist/runtime/host-load-sampler.js +73 -7
- package/dist/runtime/host-load-step-class.d.ts +3 -1
- package/dist/runtime/host-load-step-class.js +60 -5
- 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 +26 -0
- package/dist/runtime/host-load-token-ledger.js +93 -61
- 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-runtime-contract.d.ts +12 -0
- package/dist/runtime/host-runtime-contract.js +29 -1
- package/dist/runtime/host-runtime-lease.d.ts +59 -3
- package/dist/runtime/host-runtime-lease.js +209 -58
- package/dist/runtime/host-runtime-promotion.d.ts +23 -0
- package/dist/runtime/host-runtime-promotion.js +36 -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 +10 -2
- package/dist/sandbox/host-capacity-broker.js +27 -6
- package/dist/sandbox/provider-auth/codex.js +11 -11
- 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 +89 -99
- 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 +2 -0
- package/dist/session/managed-command-host-load.js +2 -1
- 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 +96 -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 +10 -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 +4 -10
- package/dist/session/phase-completion.runtime.js +77 -209
- 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-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.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 +30 -14
- package/dist/session/pre-publication-validation.js +207 -134
- 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.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.process.d.ts +15 -36
- package/dist/session/provider-cli/provider-cli.process.js +39 -430
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +5 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +72 -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 +78 -171
- package/dist/session/provider-cli/provider-cli.types.d.ts +26 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +4 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +45 -0
- package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
- package/dist/session/provider-cli/provider-output-pipes.js +67 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +2 -0
- package/dist/session/provider-cli/provider-output-state.js +6 -0
- package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
- package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
- package/dist/session/qa-sidecar-validation.d.ts +6 -0
- package/dist/session/qa-sidecar-validation.js +28 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +22 -1
- package/dist/session/sandbox-host-capacity-gate.js +42 -14
- package/dist/session/session-redaction.js +31 -181
- package/dist/session/session.base.d.ts +6 -1
- package/dist/session/session.service.d.ts +7 -2
- package/dist/session/session.service.js +100 -2
- package/dist/session/session.types.js +4 -4
- 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 +13 -1
- package/dist/shared/process/host-process-supervisor.js +66 -14
- 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/worktree.service.d.ts +5 -1
- package/dist/worktree/worktree.service.js +29 -1
- package/package.json +2 -2
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { execFile, execFileSync } from "node:child_process";
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { promisify } from "node:util";
|
|
6
7
|
import { monotonicNowMs } from "../time/monotonic.js";
|
|
8
|
+
const execFileAsync = promisify(execFile);
|
|
7
9
|
const windowsJobSupervisorPath = fileURLToPath(new URL("../../../runtime/windows-job-supervisor.ps1", import.meta.url));
|
|
8
10
|
export function resolveHostProcessSupervisedLaunch(request, resolvedCommand, resolvedArgs, platform = process.platform) {
|
|
9
11
|
const env = request.env;
|
|
@@ -154,7 +156,7 @@ export function captureHostProcessIdentity(pid, platform = process.platform) {
|
|
|
154
156
|
return null;
|
|
155
157
|
}
|
|
156
158
|
}
|
|
157
|
-
export async function terminateHostProcessTree(child, launch, graceMs = 2_000) {
|
|
159
|
+
export async function terminateHostProcessTree(child, launch, graceMs = 2_000, windowsJobGone = waitForWindowsSupervisorJobGone) {
|
|
158
160
|
if (!launch) {
|
|
159
161
|
await terminateUnsupervisedProcessTree(child, graceMs);
|
|
160
162
|
return;
|
|
@@ -162,22 +164,19 @@ export async function terminateHostProcessTree(child, launch, graceMs = 2_000) {
|
|
|
162
164
|
if (launch.strategy === "windows_job_object") {
|
|
163
165
|
const rootPid = child.pid ?? 0;
|
|
164
166
|
const metadata = readSupervisorMetadata(launch.metadataPath);
|
|
165
|
-
const rootIdentity = metadata?.rootPid === rootPid
|
|
166
|
-
? metadata.rootIdentity ?? null
|
|
167
|
-
: captureHostProcessIdentity(rootPid, "win32");
|
|
168
167
|
try {
|
|
169
168
|
child.kill("SIGTERM");
|
|
170
169
|
}
|
|
171
170
|
catch {
|
|
172
171
|
// Closing the launcher is best effort when the Job Object already settled.
|
|
173
172
|
}
|
|
174
|
-
|
|
175
|
-
|
|
173
|
+
// The root is this process's own child: its exit is observed through the handle
|
|
174
|
+
// Node holds, not by polling its identity with a PowerShell launch per check.
|
|
175
|
+
if (!await waitForChildExit(child, graceMs)) {
|
|
176
176
|
forceWindowsProcessTree(rootPid);
|
|
177
|
-
await
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
throw new Error("host_process_supervisor_termination_failed: supervised Windows root did not stop.");
|
|
177
|
+
if (!await waitForChildExit(child, graceMs)) {
|
|
178
|
+
throw new Error("host_process_supervisor_termination_failed: supervised Windows root did not stop.");
|
|
179
|
+
}
|
|
181
180
|
}
|
|
182
181
|
const providerPid = metadata?.providerPid ?? 0;
|
|
183
182
|
const providerIdentity = metadata?.providerIdentity ?? null;
|
|
@@ -188,6 +187,12 @@ export async function terminateHostProcessTree(child, launch, graceMs = 2_000) {
|
|
|
188
187
|
if (exactProcessExists(providerPid, providerIdentity, "win32")) {
|
|
189
188
|
throw new Error("host_process_supervisor_termination_failed: supervised Windows provider tree did not stop.");
|
|
190
189
|
}
|
|
190
|
+
// The root and the provider have exited; the rest of the tree (a descendant that left
|
|
191
|
+
// the provider's process tree, say) is gone only with the Job Object, which outlives
|
|
192
|
+
// its members by no more than a moment unless something still holds it.
|
|
193
|
+
if (!await windowsJobGone(launch.supervisorId, graceMs)) {
|
|
194
|
+
throw new Error(`host_process_supervisor_termination_failed: the Job Object of supervisor ${launch.supervisorId} still holds processes after its root and provider stopped.`);
|
|
195
|
+
}
|
|
191
196
|
return;
|
|
192
197
|
}
|
|
193
198
|
const processGroupId = child.pid;
|
|
@@ -218,10 +223,13 @@ async function terminateUnsupervisedProcessTree(child, graceMs) {
|
|
|
218
223
|
// root has already exited. Never target a potentially reused Windows PID.
|
|
219
224
|
if (child.exitCode !== null || child.signalCode !== null)
|
|
220
225
|
return;
|
|
221
|
-
|
|
226
|
+
// Until this child reports its exit, Node still holds its process handle, so
|
|
227
|
+
// its PID cannot name another process. Stop the tree now, rather than after a
|
|
228
|
+
// PowerShell launch to read its identity, during which the provider runs on
|
|
229
|
+
// past the stop (a success ceiling, a cancellation), and observe the exit
|
|
230
|
+
// through that same handle.
|
|
222
231
|
forceWindowsProcessTree(rootPid);
|
|
223
|
-
await
|
|
224
|
-
if (exactProcessExists(rootPid, rootIdentity, "win32")) {
|
|
232
|
+
if (!await waitForChildExit(child, graceMs)) {
|
|
225
233
|
throw new Error("host_process_supervisor_termination_failed: unsupervised Windows provider tree did not stop.");
|
|
226
234
|
}
|
|
227
235
|
return;
|
|
@@ -250,6 +258,34 @@ function assertMetadataPath(logDirectory, metadataPath) {
|
|
|
250
258
|
throw new Error("host_process_supervisor_invalid: metadata path must be inside FORGE_LOG_DIR.");
|
|
251
259
|
}
|
|
252
260
|
}
|
|
261
|
+
/**
|
|
262
|
+
* Polls for the job supervisor's named Job Object (runtime/windows-job-supervisor.ps1 names
|
|
263
|
+
* it Local\Forge-<supervisorId>). A job object exists while any handle or member process
|
|
264
|
+
* holds it, and the supervisor's handle closed with it, so its absence means no member is
|
|
265
|
+
* left. Any answer but "not found" (an unreadable job, a failed check) is not proof.
|
|
266
|
+
*/
|
|
267
|
+
export const waitForWindowsSupervisorJobGone = async (supervisorId, timeoutMs) => {
|
|
268
|
+
if (!/^[A-Za-z0-9._-]{1,200}$/u.test(supervisorId))
|
|
269
|
+
return false;
|
|
270
|
+
const script = [
|
|
271
|
+
"$ErrorActionPreference = 'Stop'",
|
|
272
|
+
"Add-Type -Namespace ForgeRecovery -Name Job -MemberDefinition '[DllImport(\"kernel32.dll\", SetLastError = true, CharSet = CharSet.Unicode)] public static extern IntPtr OpenJobObject(uint access, bool inherit, string name); [DllImport(\"kernel32.dll\")] public static extern bool CloseHandle(IntPtr handle);'",
|
|
273
|
+
`$deadline = [DateTime]::UtcNow.AddMilliseconds(${Math.max(0, Math.round(timeoutMs))})`,
|
|
274
|
+
"$result = 'alive'",
|
|
275
|
+
// JOB_OBJECT_QUERY (4); ERROR_FILE_NOT_FOUND (2) is the only answer that proves the job gone.
|
|
276
|
+
"while ($true) { "
|
|
277
|
+
+ `$handle = [ForgeRecovery.Job]::OpenJobObject(4, $false, 'Local\\Forge-${supervisorId}'); `
|
|
278
|
+
+ "if ($handle -eq [IntPtr]::Zero) { $code = [Runtime.InteropServices.Marshal]::GetLastWin32Error(); "
|
|
279
|
+
+ "if ($code -eq 2) { $result = 'gone' } else { $result = \"error:$code\" }; break }; "
|
|
280
|
+
+ "[ForgeRecovery.Job]::CloseHandle($handle) | Out-Null; "
|
|
281
|
+
+ "if ([DateTime]::UtcNow -ge $deadline) { break }; Start-Sleep -Milliseconds 25 }",
|
|
282
|
+
"Write-Output $result",
|
|
283
|
+
].join("; ");
|
|
284
|
+
const { stdout } = await execFileAsync(windowsPowerShellPath(), [
|
|
285
|
+
"-NoLogo", "-NoProfile", "-NonInteractive", "-Command", script,
|
|
286
|
+
], { encoding: "utf8", windowsHide: true, timeout: timeoutMs + 60_000 }).catch(() => ({ stdout: "" }));
|
|
287
|
+
return stdout.trim() === "gone";
|
|
288
|
+
};
|
|
253
289
|
export function windowsPowerShellPath() {
|
|
254
290
|
const systemRoot = process.env.SystemRoot?.trim() || "C:\\Windows";
|
|
255
291
|
const candidate = path.win32.join(systemRoot, "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
|
|
@@ -307,6 +343,22 @@ function processExists(pid) {
|
|
|
307
343
|
return error.code === "EPERM";
|
|
308
344
|
}
|
|
309
345
|
}
|
|
346
|
+
/** Whether this process's own child reports its exit within `timeoutMs`. */
|
|
347
|
+
async function waitForChildExit(child, timeoutMs) {
|
|
348
|
+
if (child.exitCode !== null || child.signalCode !== null)
|
|
349
|
+
return true;
|
|
350
|
+
return await new Promise(resolve => {
|
|
351
|
+
const onExit = () => {
|
|
352
|
+
clearTimeout(timer);
|
|
353
|
+
resolve(true);
|
|
354
|
+
};
|
|
355
|
+
const timer = setTimeout(() => {
|
|
356
|
+
child.off("exit", onExit);
|
|
357
|
+
resolve(child.exitCode !== null || child.signalCode !== null);
|
|
358
|
+
}, timeoutMs);
|
|
359
|
+
child.once("exit", onExit);
|
|
360
|
+
});
|
|
361
|
+
}
|
|
310
362
|
async function waitForExactProcessExit(pid, identity, timeoutMs, platform) {
|
|
311
363
|
const deadline = monotonicNowMs() + timeoutMs;
|
|
312
364
|
while (monotonicNowMs() < deadline && exactProcessExists(pid, identity, platform)) {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tools an agent commonly starts by bare name. When one of them resolves to a Microsoft Store
|
|
3
|
+
* app-execution alias (`%LOCALAPPDATA%\Microsoft\WindowsApps\pwsh.exe` and the like), Windows
|
|
4
|
+
* creates the process it starts outside the provider's Job Object: it survives the job, keeps the
|
|
5
|
+
* pipe handles it inherited, and holds the attempt's output open until it exits on its own.
|
|
6
|
+
*/
|
|
7
|
+
export declare const APP_EXECUTION_ALIAS_SENSITIVE_TOOLS: readonly ["pwsh", "node", "dotnet"];
|
|
8
|
+
export interface AppExecutionAliasFinding {
|
|
9
|
+
readonly tool: string;
|
|
10
|
+
/** The alias the tool's bare name resolves to. */
|
|
11
|
+
readonly aliasPath: string;
|
|
12
|
+
/** The first regular install later on PATH, or null when the alias is the only one. */
|
|
13
|
+
readonly nextInstallPath: string | null;
|
|
14
|
+
}
|
|
15
|
+
/** The sensitive tools whose bare name resolves, on this PATH, to an app-execution alias. */
|
|
16
|
+
export declare function findAppExecutionAliasTools(pathValue: string, pathExtValue?: string, tools?: readonly string[]): AppExecutionAliasFinding[];
|
|
17
|
+
export declare function describeAppExecutionAliasFindings(findings: readonly AppExecutionAliasFinding[]): string | null;
|
|
18
|
+
/** Reads PATH and PATHEXT from an environment whose key case is not normalized (Windows: "Path"). */
|
|
19
|
+
export declare function appExecutionAliasWarning(env: Readonly<Record<string, string | undefined>>, platform?: NodeJS.Platform): string | null;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { isWindowsAppExecutionAliasPath, resolveWindowsCommandFromPath } from "./windows-launch.js";
|
|
2
|
+
/**
|
|
3
|
+
* Tools an agent commonly starts by bare name. When one of them resolves to a Microsoft Store
|
|
4
|
+
* app-execution alias (`%LOCALAPPDATA%\Microsoft\WindowsApps\pwsh.exe` and the like), Windows
|
|
5
|
+
* creates the process it starts outside the provider's Job Object: it survives the job, keeps the
|
|
6
|
+
* pipe handles it inherited, and holds the attempt's output open until it exits on its own.
|
|
7
|
+
*/
|
|
8
|
+
export const APP_EXECUTION_ALIAS_SENSITIVE_TOOLS = ["pwsh", "node", "dotnet"];
|
|
9
|
+
/** The sensitive tools whose bare name resolves, on this PATH, to an app-execution alias. */
|
|
10
|
+
export function findAppExecutionAliasTools(pathValue, pathExtValue, tools = APP_EXECUTION_ALIAS_SENSITIVE_TOOLS) {
|
|
11
|
+
const findings = [];
|
|
12
|
+
for (const tool of tools) {
|
|
13
|
+
const aliasPath = resolveWindowsCommandFromPath(tool, pathValue, pathExtValue);
|
|
14
|
+
if (!aliasPath || !isWindowsAppExecutionAliasPath(aliasPath))
|
|
15
|
+
continue;
|
|
16
|
+
const nextInstallPath = resolveWindowsCommandFromPath(tool, pathValue, pathExtValue, { skipAppExecutionAliases: true });
|
|
17
|
+
findings.push({ tool, aliasPath, nextInstallPath });
|
|
18
|
+
}
|
|
19
|
+
return findings;
|
|
20
|
+
}
|
|
21
|
+
export function describeAppExecutionAliasFindings(findings) {
|
|
22
|
+
if (findings.length === 0)
|
|
23
|
+
return null;
|
|
24
|
+
const tools = findings.map(finding => `${finding.tool} -> ${finding.aliasPath}${finding.nextInstallPath
|
|
25
|
+
? ` (a regular install later on PATH: ${finding.nextInstallPath})`
|
|
26
|
+
: " (no regular install on PATH)"}`);
|
|
27
|
+
return "Host readiness warning: on the provider PATH, "
|
|
28
|
+
+ `${tools.join("; ")} resolve${findings.length === 1 ? "s" : ""} to a Microsoft Store app-execution alias under WindowsApps. `
|
|
29
|
+
+ "A process started through an alias is created outside the provider's Windows Job Object, survives it, "
|
|
30
|
+
+ "and can hold the attempt's output pipes open until it exits. Install the tool normally "
|
|
31
|
+
+ "(for PowerShell, the MSI under C:\\Program Files\\PowerShell\\7) and put it ahead of WindowsApps on PATH.";
|
|
32
|
+
}
|
|
33
|
+
/** Reads PATH and PATHEXT from an environment whose key case is not normalized (Windows: "Path"). */
|
|
34
|
+
export function appExecutionAliasWarning(env, platform = process.platform) {
|
|
35
|
+
if (platform !== "win32")
|
|
36
|
+
return null;
|
|
37
|
+
const pathValue = environmentValue(env, "PATH");
|
|
38
|
+
if (!pathValue)
|
|
39
|
+
return null;
|
|
40
|
+
return describeAppExecutionAliasFindings(findAppExecutionAliasTools(pathValue, environmentValue(env, "PATHEXT")));
|
|
41
|
+
}
|
|
42
|
+
function environmentValue(env, name) {
|
|
43
|
+
const key = Object.keys(env).find(candidate => candidate.toUpperCase() === name);
|
|
44
|
+
return key === undefined ? undefined : env[key];
|
|
45
|
+
}
|
|
@@ -6,3 +6,21 @@ export declare function buildWindowsCmdLaunch(command: string, args: readonly st
|
|
|
6
6
|
export declare function buildWindowsLaunchCommand(commandPath: string, args: readonly string[]): LaunchCommand;
|
|
7
7
|
export declare function windowsCommandLine(command: string, args: readonly string[]): string;
|
|
8
8
|
export declare function quoteWindowsCommandLineArg(value: string): string;
|
|
9
|
+
export interface WindowsCommandPathOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Skip candidates under a `WindowsApps` directory. Those are Microsoft Store app-execution
|
|
12
|
+
* aliases: the process they start is created outside the caller's Job Object, so it survives the
|
|
13
|
+
* job and keeps any inherited pipe open. Resolve the next real install on PATH instead.
|
|
14
|
+
*/
|
|
15
|
+
readonly skipAppExecutionAliases?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Resolves Windows commands without spawning where.exe. Runtime launches can
|
|
19
|
+
* happen while the machine is under enough process pressure for where.exe to
|
|
20
|
+
* miss its timeout; returning the unresolved package-manager name in that case
|
|
21
|
+
* makes Node fall back to a shell shim that cannot survive Job Object wrapping.
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolveWindowsCommandFromPath(command: string, pathValue?: string, pathExtValue?: string, options?: WindowsCommandPathOptions): string | null;
|
|
24
|
+
export declare function chooseWindowsCommandCandidate(candidates: readonly string[]): string | null;
|
|
25
|
+
/** True for a path inside a `WindowsApps` directory, where Store app-execution aliases live. */
|
|
26
|
+
export declare function isWindowsAppExecutionAliasPath(candidate: string): boolean;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
1
2
|
import path from "node:path";
|
|
2
3
|
export function buildWindowsCmdLaunch(command, args, comSpec = process.env.ComSpec) {
|
|
3
4
|
const resolvedComSpec = comSpec?.trim();
|
|
@@ -39,3 +40,70 @@ function powershellExecutable() {
|
|
|
39
40
|
? path.join(systemRoot, "System32", "WindowsPowerShell", "v1.0", "powershell.exe")
|
|
40
41
|
: "powershell.exe";
|
|
41
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Resolves Windows commands without spawning where.exe. Runtime launches can
|
|
45
|
+
* happen while the machine is under enough process pressure for where.exe to
|
|
46
|
+
* miss its timeout; returning the unresolved package-manager name in that case
|
|
47
|
+
* makes Node fall back to a shell shim that cannot survive Job Object wrapping.
|
|
48
|
+
*/
|
|
49
|
+
export function resolveWindowsCommandFromPath(command, pathValue = process.env.PATH ?? "", pathExtValue = process.env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD", options = {}) {
|
|
50
|
+
if (!command || path.isAbsolute(command) || command.includes("/") || command.includes("\\")) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const hasExtension = path.extname(command).length > 0;
|
|
54
|
+
const extensions = hasExtension
|
|
55
|
+
? [""]
|
|
56
|
+
: [...new Set([
|
|
57
|
+
"",
|
|
58
|
+
".exe",
|
|
59
|
+
".ps1",
|
|
60
|
+
".cmd",
|
|
61
|
+
".bat",
|
|
62
|
+
...pathExtValue.split(";").map(value => value.trim().toLowerCase()).filter(Boolean),
|
|
63
|
+
])];
|
|
64
|
+
for (const rawDirectory of pathValue.split(path.delimiter)) {
|
|
65
|
+
const directory = rawDirectory.trim().replace(/^"|"$/gu, "");
|
|
66
|
+
if (!directory)
|
|
67
|
+
continue;
|
|
68
|
+
const candidates = [];
|
|
69
|
+
for (const extension of extensions) {
|
|
70
|
+
const candidate = path.join(directory, `${command}${extension}`);
|
|
71
|
+
if (options.skipAppExecutionAliases && isWindowsAppExecutionAliasPath(candidate))
|
|
72
|
+
continue;
|
|
73
|
+
if (pathEntryExists(candidate))
|
|
74
|
+
candidates.push(candidate);
|
|
75
|
+
}
|
|
76
|
+
const resolved = chooseWindowsCommandCandidate(candidates);
|
|
77
|
+
if (resolved)
|
|
78
|
+
return resolved;
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
export function chooseWindowsCommandCandidate(candidates) {
|
|
83
|
+
const normalized = candidates
|
|
84
|
+
.map((candidate) => candidate.trim())
|
|
85
|
+
.filter((candidate) => candidate.length > 0);
|
|
86
|
+
if (normalized.length === 0) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
const preferredExtensions = [".exe", ".ps1", ".cmd", ".bat", ""];
|
|
90
|
+
for (const extension of preferredExtensions) {
|
|
91
|
+
const candidate = normalized.find((entry) => path.extname(entry).toLowerCase() === extension);
|
|
92
|
+
if (candidate) {
|
|
93
|
+
return candidate;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return normalized[0];
|
|
97
|
+
}
|
|
98
|
+
/** True for a path inside a `WindowsApps` directory, where Store app-execution aliases live. */
|
|
99
|
+
export function isWindowsAppExecutionAliasPath(candidate) {
|
|
100
|
+
return candidate.split(/[\\/]+/u).some(segment => segment.toLowerCase() === "windowsapps");
|
|
101
|
+
}
|
|
102
|
+
// An app-execution alias is a reparse point that stat() may not open, so an
|
|
103
|
+
// alias is also accepted when only lstat() can see it.
|
|
104
|
+
function pathEntryExists(candidate) {
|
|
105
|
+
if (fs.existsSync(candidate))
|
|
106
|
+
return true;
|
|
107
|
+
return isWindowsAppExecutionAliasPath(candidate)
|
|
108
|
+
&& fs.lstatSync(candidate, { throwIfNoEntry: false }) !== undefined;
|
|
109
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { bridgeChatProtocolVersion, normalizeBridgeChatCapability, unavailableBridgeChatCapability, } from "../bridge/bridge-chat.types.js";
|
|
2
|
+
import { isProviderUserConfigIsolated, userConfigIsolatedProviders } from "../session/provider-cli/provider-user-config-isolation.js";
|
|
2
3
|
const defaultBridgeChatMaxMessageBytes = 128 * 1024;
|
|
3
4
|
const defaultBridgeChatMaxContextRefs = 8;
|
|
4
5
|
export function supportsDraftImageAttachmentsFor(cliProviders) {
|
|
@@ -9,7 +10,14 @@ export function bridgeChatCapabilityFor(cliProviders, providerStatuses, baseCapa
|
|
|
9
10
|
if (base.protocolVersion !== bridgeChatProtocolVersion) {
|
|
10
11
|
return base;
|
|
11
12
|
}
|
|
12
|
-
const
|
|
13
|
+
const configuredProviders = chatProviderEntries(cliProviders, providerStatuses);
|
|
14
|
+
// Bridge Chat refuses a provider whose user configuration Forge can't keep out of the turn
|
|
15
|
+
// (cursor-agent, unknown CLIs), so it is never offered. The remaining providers decide
|
|
16
|
+
// availability: the server dispatches a turn only to a capability that is fully available.
|
|
17
|
+
const providers = configuredProviders.filter((provider) => isProviderUserConfigIsolated(provider.providerKind));
|
|
18
|
+
if (configuredProviders.length > 0 && providers.length === 0) {
|
|
19
|
+
return unavailableBridgeChatCapability(bridgeChatProtocolVersion, "no_isolated_cli_providers", `Bridge Chat runs only ${userConfigIsolatedProviders.join(" and ")}; Forge can't keep the host user's own configuration out of ${configuredProviders.map((provider) => provider.providerKind).join(", ")}.`);
|
|
20
|
+
}
|
|
13
21
|
const usableProviders = providers.filter((provider) => provider.status?.signedIn !== false);
|
|
14
22
|
if (usableProviders.length === 0) {
|
|
15
23
|
return unavailableBridgeChatCapability(bridgeChatProtocolVersion, providers.length === 0 ? "no_cli_providers" : "no_signed_in_cli_providers", providers.length === 0
|
|
@@ -40,8 +48,12 @@ function chatProviderEntries(cliProviders, providerStatuses) {
|
|
|
40
48
|
const providerKind = provider.trim().toLowerCase();
|
|
41
49
|
if (providerKind.length === 0)
|
|
42
50
|
continue;
|
|
43
|
-
statuses.set(providerKind, {
|
|
51
|
+
statuses.set(providerKind, { status });
|
|
44
52
|
}
|
|
53
|
+
// Only configured CLI providers can run a Bridge Chat turn. A status entry for a
|
|
54
|
+
// provider that is not in cliProviders (for example a leftover entry in
|
|
55
|
+
// bridge.json for a CLI that is no longer installed) annotates nothing and must
|
|
56
|
+
// not be advertised as a chat provider.
|
|
45
57
|
const providers = new Map();
|
|
46
58
|
for (const provider of cliProviders) {
|
|
47
59
|
const providerKind = provider.trim().toLowerCase();
|
|
@@ -52,11 +64,6 @@ function chatProviderEntries(cliProviders, providerStatuses) {
|
|
|
52
64
|
status: statuses.get(providerKind)?.status,
|
|
53
65
|
});
|
|
54
66
|
}
|
|
55
|
-
for (const [providerKind, entry] of statuses) {
|
|
56
|
-
if (!providers.has(providerKind)) {
|
|
57
|
-
providers.set(providerKind, entry);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
67
|
return [...providers.values()].sort((left, right) => compareStable(left.providerKind, right.providerKind));
|
|
61
68
|
}
|
|
62
69
|
function sortedUniqueStrings(values, lower) {
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const forgeBridgeVersion = "0.1.4-dev.
|
|
1
|
+
export declare const forgeBridgeVersion = "0.1.4-dev.cabe9c22da46";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const forgeBridgeVersion = "0.1.4-dev.
|
|
1
|
+
export const forgeBridgeVersion = "0.1.4-dev.cabe9c22da46";
|
|
@@ -7,9 +7,13 @@ export declare class GitWorktreeService implements WorktreeService {
|
|
|
7
7
|
private readonly coordinator;
|
|
8
8
|
/** Gates dependency install fallbacks; inert unless the governor is on. */
|
|
9
9
|
private readonly hostLoadGate?;
|
|
10
|
+
/** Holds the host runtime lease ledger; branches of live leases are never swept on release. */
|
|
11
|
+
private readonly leaseStateRoot;
|
|
10
12
|
constructor(git?: GitClient, coordinator?: WorktreeLifecycleCoordinator,
|
|
11
13
|
/** Gates dependency install fallbacks; inert unless the governor is on. */
|
|
12
|
-
hostLoadGate?: HostLoadStepGate | undefined
|
|
14
|
+
hostLoadGate?: HostLoadStepGate | undefined,
|
|
15
|
+
/** Holds the host runtime lease ledger; branches of live leases are never swept on release. */
|
|
16
|
+
leaseStateRoot?: string);
|
|
13
17
|
prepare(request: WorktreePrepareRequest): Promise<WorktreeHandle>;
|
|
14
18
|
private trackedForgePaths;
|
|
15
19
|
private registeredManagedWorktreePath;
|
|
@@ -3,22 +3,30 @@ import fs from "node:fs/promises";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { RepositoryCoordinatorLock } from "../sandbox/repository-lock.js";
|
|
5
5
|
import { GitClient } from "../shared/git/git.js";
|
|
6
|
+
import { liveLeaseBranches, readHostRuntimeLeases } from "../cleanup/host-runtime-ledger.js";
|
|
7
|
+
import { deleteBranchIfUnused, isRuntimeReadinessBranch, sweepManagedBranches } from "../cleanup/managed-branch-sweep.js";
|
|
6
8
|
import { ensureDirectory, isSubPath, resolveExistingDirectoryPath, safeSegment } from "../shared/path/path.js";
|
|
7
9
|
import { filterArtifactsForLane, injectWorktreeArtifacts } from "./artifact-injector.js";
|
|
8
10
|
import { hydratePriorPhaseArtifacts } from "./prior-phase-artifact-hydrator.js";
|
|
9
11
|
import { materializeStoryQaReferences } from "./story-qa-reference-hydrator.js";
|
|
10
12
|
import { warmWorktreeDependencies } from "./dependency-warmer.js";
|
|
11
13
|
import { defaultWorktreeCoordinatorStateRoot, managedRepoRoot, resolveManagedWorktreeRoot, } from "./worktree-paths.js";
|
|
14
|
+
// Bounds the branch sweep that runs after each release, so one release never holds the repository lock long.
|
|
15
|
+
const releaseSweepLimit = 25;
|
|
12
16
|
export class GitWorktreeService {
|
|
13
17
|
git;
|
|
14
18
|
coordinator;
|
|
15
19
|
hostLoadGate;
|
|
20
|
+
leaseStateRoot;
|
|
16
21
|
constructor(git = new GitClient(), coordinator = new RepositoryCoordinatorLock(defaultWorktreeCoordinatorStateRoot()),
|
|
17
22
|
/** Gates dependency install fallbacks; inert unless the governor is on. */
|
|
18
|
-
hostLoadGate
|
|
23
|
+
hostLoadGate,
|
|
24
|
+
/** Holds the host runtime lease ledger; branches of live leases are never swept on release. */
|
|
25
|
+
leaseStateRoot = defaultWorktreeCoordinatorStateRoot()) {
|
|
19
26
|
this.git = git;
|
|
20
27
|
this.coordinator = coordinator;
|
|
21
28
|
this.hostLoadGate = hostLoadGate;
|
|
29
|
+
this.leaseStateRoot = leaseStateRoot;
|
|
22
30
|
}
|
|
23
31
|
async prepare(request) {
|
|
24
32
|
const allowedRoot = await ensureDirectory(request.allowedRepoRoot);
|
|
@@ -176,6 +184,26 @@ export class GitWorktreeService {
|
|
|
176
184
|
// directory is fully materialized (or after an external cleanup removes it).
|
|
177
185
|
// Always prune so those missing-directory registrations do not accumulate.
|
|
178
186
|
await this.git.run(handle.repoPath, ["worktree", "prune", "--expire", "now"]).catch(() => undefined);
|
|
187
|
+
// A readiness probe's branch goes with its worktree. Other Forge branches on this device
|
|
188
|
+
// whose work is already merged into the base go too; branches with unmerged work stay.
|
|
189
|
+
// A lease can be live while its worktree is briefly missing, so its branch is protected
|
|
190
|
+
// even when no worktree has it checked out. If the ledger can't be read, sweep nothing.
|
|
191
|
+
const protectedBranches = await readHostRuntimeLeases(this.leaseStateRoot)
|
|
192
|
+
.then(liveLeaseBranches)
|
|
193
|
+
.catch(() => null);
|
|
194
|
+
if (!protectedBranches)
|
|
195
|
+
return;
|
|
196
|
+
let budget = releaseSweepLimit;
|
|
197
|
+
if (isRuntimeReadinessBranch(handle.branchName) && !protectedBranches.has(handle.branchName)
|
|
198
|
+
&& await deleteBranchIfUnused(this.git, handle.repoPath, handle.branchName)) {
|
|
199
|
+
budget -= 1;
|
|
200
|
+
}
|
|
201
|
+
await sweepManagedBranches(this.git, handle.repoPath, {
|
|
202
|
+
baseBranch: handle.baseBranch,
|
|
203
|
+
includeMergedWorkBranches: true,
|
|
204
|
+
protectedBranches,
|
|
205
|
+
limit: budget,
|
|
206
|
+
}).catch(() => undefined);
|
|
179
207
|
});
|
|
180
208
|
}
|
|
181
209
|
async restoreOrphanedWorktree(input) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loucompanion/forge-bridge",
|
|
3
|
-
"version": "0.1.4-dev.
|
|
3
|
+
"version": "0.1.4-dev.cabe9c22da46",
|
|
4
4
|
"description": "Forge runner bridge CLI for connecting local developer machines to Forge dispatch.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"test:residue": "node scripts/run-owned-residue-gate.mjs",
|
|
44
44
|
"test:watch": "vitest",
|
|
45
45
|
"smoke:package": "tsc -p tsconfig.json && node scripts/smoke-package.mjs",
|
|
46
|
-
"lint": "eslint \"src/**/*.ts\" \"scripts/**/*.mjs\" \"vitest.config.ts\" \"vitest.setup.ts\""
|
|
46
|
+
"lint": "eslint \"src/**/*.ts\" \"scripts/**/*.mjs\" \"vitest.config.ts\" \"vitest.setup.ts\" && node ../../scripts/class-design/check-eslint-ratchet.mjs bridge"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@microsoft/signalr": "^8.0.17",
|