@loucompanion/forge-bridge 0.1.4-dev.bbb61d3d6127 → 0.1.4-dev.bd2cfb6b7438
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 +55 -0
- package/dist/bridge/bridge-chat-provider-command.d.ts +16 -0
- package/dist/bridge/bridge-chat-provider-command.js +137 -0
- package/dist/bridge/bridge-chat.types.d.ts +10 -0
- package/dist/bridge/bridge-chat.types.js +16 -1
- package/dist/bridge/bridge.base.d.ts +9 -0
- package/dist/bridge/bridge.service.d.ts +71 -2
- package/dist/bridge/bridge.service.js +292 -118
- package/dist/bridge/bridge.types.d.ts +11 -0
- package/dist/bridge/local-yield-flag.d.ts +6 -0
- package/dist/bridge/local-yield-flag.js +34 -0
- package/dist/bridge/runner-host-capabilities.d.ts +3 -0
- package/dist/bridge/runner-host-capabilities.js +13 -0
- package/dist/cleanup/cleanup.service.d.ts +9 -0
- package/dist/cleanup/cleanup.service.js +72 -109
- 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 +18 -0
- package/dist/cli/cli.service.d.ts +16 -0
- package/dist/cli/cli.service.js +140 -16
- package/dist/cli/local-config.d.ts +4 -0
- package/dist/cli/local-config.js +26 -4
- package/dist/runtime/aspnet-runtime-prebuild.js +94 -6
- 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 +27 -0
- package/dist/runtime/host-load-child-environment.js +76 -0
- package/dist/runtime/host-load-forge-cgroups.d.ts +41 -0
- package/dist/runtime/host-load-forge-cgroups.js +93 -4
- 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 +72 -11
- package/dist/runtime/host-load-governor.js +284 -67
- package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
- package/dist/runtime/host-load-runtime-settings.js +78 -0
- package/dist/runtime/host-load-sampler.d.ts +39 -4
- package/dist/runtime/host-load-sampler.js +83 -9
- package/dist/runtime/host-load-step-class.d.ts +37 -0
- package/dist/runtime/host-load-step-class.js +117 -2
- 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 +82 -17
- package/dist/runtime/host-load-token-ledger.js +187 -79
- 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-lease.d.ts +62 -3
- package/dist/runtime/host-runtime-lease.js +258 -13
- package/dist/runtime/host-runtime-promotion.d.ts +23 -0
- package/dist/runtime/host-runtime-promotion.js +36 -0
- 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 +100 -0
- package/dist/runtime/runner-settings.js +214 -0
- package/dist/sandbox/host-capacity-broker.d.ts +113 -0
- package/dist/sandbox/host-capacity-broker.js +334 -0
- package/dist/sandbox/runtime.d.ts +10 -1
- package/dist/sandbox/runtime.js +45 -2
- 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 +200 -92
- 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 +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 +4 -0
- package/dist/session/phase-completion.helpers.js +13 -12
- package/dist/session/phase-completion.js +4 -0
- package/dist/session/phase-completion.prompts.js +6 -1
- package/dist/session/phase-completion.runtime.d.ts +5 -3
- package/dist/session/phase-completion.runtime.js +50 -20
- 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.js +31 -16
- 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 +23 -11
- 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 +211 -134
- package/dist/session/provider-cli/claude-background-work.d.ts +66 -0
- package/dist/session/provider-cli/claude-background-work.js +180 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +40 -0
- package/dist/session/provider-cli/pre-publication-repair.js +243 -0
- package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +73 -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 +13 -22
- package/dist/session/provider-cli/provider-cli.process.js +38 -339
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +2 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +50 -10
- package/dist/session/provider-cli/provider-cli.runtime.js +7 -0
- package/dist/session/provider-cli/provider-cli.service.d.ts +4 -1
- package/dist/session/provider-cli/provider-cli.service.js +93 -162
- 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-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/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 +30 -0
- package/dist/session/sandbox-host-capacity-gate.js +238 -0
- 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 +115 -5
- 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/process/host-process-supervisor.d.ts +1 -0
- package/dist/shared/process/host-process-supervisor.js +1 -1
- 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 +5 -6
- 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/worktree.service.d.ts +10 -1
- package/dist/worktree/worktree.service.js +42 -2
- package/dist/worktree/worktree.types.d.ts +7 -0
- package/package.json +2 -2
|
@@ -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
|
+
}
|
|
@@ -40,8 +40,12 @@ function chatProviderEntries(cliProviders, providerStatuses) {
|
|
|
40
40
|
const providerKind = provider.trim().toLowerCase();
|
|
41
41
|
if (providerKind.length === 0)
|
|
42
42
|
continue;
|
|
43
|
-
statuses.set(providerKind, {
|
|
43
|
+
statuses.set(providerKind, { status });
|
|
44
44
|
}
|
|
45
|
+
// Only configured CLI providers can run a Bridge Chat turn. A status entry for a
|
|
46
|
+
// provider that is not in cliProviders (for example a leftover entry in
|
|
47
|
+
// bridge.json for a CLI that is no longer installed) annotates nothing and must
|
|
48
|
+
// not be advertised as a chat provider.
|
|
45
49
|
const providers = new Map();
|
|
46
50
|
for (const provider of cliProviders) {
|
|
47
51
|
const providerKind = provider.trim().toLowerCase();
|
|
@@ -52,11 +56,6 @@ function chatProviderEntries(cliProviders, providerStatuses) {
|
|
|
52
56
|
status: statuses.get(providerKind)?.status,
|
|
53
57
|
});
|
|
54
58
|
}
|
|
55
|
-
for (const [providerKind, entry] of statuses) {
|
|
56
|
-
if (!providers.has(providerKind)) {
|
|
57
|
-
providers.set(providerKind, entry);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
59
|
return [...providers.values()].sort((left, right) => compareStable(left.providerKind, right.providerKind));
|
|
61
60
|
}
|
|
62
61
|
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.bd2cfb6b7438";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const forgeBridgeVersion = "0.1.4-dev.
|
|
1
|
+
export const forgeBridgeVersion = "0.1.4-dev.bd2cfb6b7438";
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { HostLoadStepGate } from "../runtime/host-load-governor.js";
|
|
2
|
+
import type { HostLoadTokenPriority } from "../runtime/host-load-token-ledger.js";
|
|
1
3
|
export type DependencyEcosystem = "node" | "dotnet" | "python";
|
|
2
4
|
export interface WarmPathEntry {
|
|
3
5
|
readonly relativePath: string;
|
|
@@ -10,6 +12,18 @@ export interface WarmDependenciesRequest {
|
|
|
10
12
|
readonly allowedRoot: string;
|
|
11
13
|
readonly warmPathOverrides?: readonly string[];
|
|
12
14
|
readonly preparationPolicy?: DependencyPreparationPolicy;
|
|
15
|
+
/** Install fallbacks wait for host capacity first (decision 0013). */
|
|
16
|
+
readonly hostLoad?: DependencyInstallHostLoad;
|
|
17
|
+
/**
|
|
18
|
+
* The attempt's cancellation: a queued install stops waiting and a running one
|
|
19
|
+
* is stopped (its whole process group) before its host capacity is returned.
|
|
20
|
+
*/
|
|
21
|
+
readonly signal?: AbortSignal;
|
|
22
|
+
}
|
|
23
|
+
export interface DependencyInstallHostLoad {
|
|
24
|
+
readonly gate: HostLoadStepGate;
|
|
25
|
+
readonly dispatchAttemptId: string | null;
|
|
26
|
+
readonly priority: HostLoadTokenPriority;
|
|
13
27
|
}
|
|
14
28
|
export interface DependencyPreparationPolicy {
|
|
15
29
|
readonly isolation?: string;
|
|
@@ -45,6 +59,15 @@ export interface CommandExecutor {
|
|
|
45
59
|
export interface CommandExecutionOptions {
|
|
46
60
|
readonly env?: NodeJS.ProcessEnv;
|
|
47
61
|
readonly windowsVerbatimArguments?: boolean;
|
|
62
|
+
/** Stops the install (a reclaimed host load token, decision 0013). */
|
|
63
|
+
readonly signal?: AbortSignal;
|
|
64
|
+
/** Called with the install's pid once it starts, so its token records the process. */
|
|
65
|
+
readonly onSpawn?: (pid: number) => void;
|
|
66
|
+
/**
|
|
67
|
+
* Unix: the install leads its own process group, which is stopped as a whole
|
|
68
|
+
* (on abort, and anything left once the install exits) before the run settles.
|
|
69
|
+
*/
|
|
70
|
+
readonly processGroup?: boolean;
|
|
48
71
|
}
|
|
49
72
|
export declare function detectWarmPaths(repoRoot: string, warmPathOverrides?: readonly string[]): Promise<WarmPathEntry[]>;
|
|
50
73
|
export declare function warmWorktreeDependencies(request: WarmDependenciesRequest, executor?: CommandExecutor): Promise<WarmDependenciesResult>;
|
|
@@ -82,3 +105,5 @@ export declare function unattendedDependencyEnvironment(env?: NodeJS.ProcessEnv)
|
|
|
82
105
|
export declare function compactWindowsPackageManagerPath(pathValue: string, env?: NodeJS.ProcessEnv, options?: PackageManagerEnvironmentOptions): string;
|
|
83
106
|
export declare function windowsPackageManagerLifecyclePathPrefix(packageRoot: string): string;
|
|
84
107
|
export declare function windowsPackageManagerPathBudget(packageRoot: string): number;
|
|
108
|
+
/** Runs dependency installs; exported for tests. */
|
|
109
|
+
export declare const defaultCommandExecutor: CommandExecutor;
|
|
@@ -9,6 +9,9 @@ import { NodeProcessRunner } from "../shared/process/process.js";
|
|
|
9
9
|
import { buildWindowsCmdLaunch } from "../shared/process/windows-launch.js";
|
|
10
10
|
import { isSubPath } from "../shared/path/path.js";
|
|
11
11
|
import { defaultWorktreeCoordinatorStateRoot } from "./worktree-paths.js";
|
|
12
|
+
import { dependencyInstallStepClass } from "../runtime/host-load-step-class.js";
|
|
13
|
+
import { runHostGovernedStep } from "../runtime/host-load-step-run.js";
|
|
14
|
+
import { captureHostProcessIdentity } from "../shared/process/host-process-supervisor.js";
|
|
12
15
|
const SKIP_DIR_NAMES = new Set([
|
|
13
16
|
".git",
|
|
14
17
|
"node_modules",
|
|
@@ -78,7 +81,7 @@ export async function warmWorktreeDependencies(request, executor = defaultComman
|
|
|
78
81
|
continue;
|
|
79
82
|
}
|
|
80
83
|
installedNodeRoots.add(packageKey);
|
|
81
|
-
const preparation = await ensureInstallFallback({ ...entry, packageRoot: installPackageRoot }, worktreePath, "Managed worktrees require isolated Node dependencies.", executor, request.preparationPolicy);
|
|
84
|
+
const preparation = await ensureInstallFallback({ ...entry, packageRoot: installPackageRoot }, worktreePath, "Managed worktrees require isolated Node dependencies.", executor, request.preparationPolicy, request.hostLoad, request.signal);
|
|
82
85
|
receipts.push(preparation.receipt);
|
|
83
86
|
if (preparation.install)
|
|
84
87
|
fallbacks.push(preparation.install);
|
|
@@ -93,7 +96,7 @@ export async function warmWorktreeDependencies(request, executor = defaultComman
|
|
|
93
96
|
continue;
|
|
94
97
|
}
|
|
95
98
|
restoredDotNetRoots.add(packageKey);
|
|
96
|
-
const preparation = await ensureInstallFallback(entry, worktreePath, "Managed worktrees require isolated .NET build outputs.", executor, request.preparationPolicy);
|
|
99
|
+
const preparation = await ensureInstallFallback(entry, worktreePath, "Managed worktrees require isolated .NET build outputs.", executor, request.preparationPolicy, request.hostLoad, request.signal);
|
|
97
100
|
receipts.push(preparation.receipt);
|
|
98
101
|
if (preparation.install)
|
|
99
102
|
fallbacks.push(preparation.install);
|
|
@@ -102,7 +105,7 @@ export async function warmWorktreeDependencies(request, executor = defaultComman
|
|
|
102
105
|
const sourceExists = await directoryExists(sourcePath);
|
|
103
106
|
const fallbackReason = await resolveFallbackReason(entry, baseCheckoutPath, worktreePath, sourceExists);
|
|
104
107
|
if (fallbackReason) {
|
|
105
|
-
const preparation = await ensureInstallFallback(entry, worktreePath, fallbackReason, executor, request.preparationPolicy);
|
|
108
|
+
const preparation = await ensureInstallFallback(entry, worktreePath, fallbackReason, executor, request.preparationPolicy, request.hostLoad, request.signal);
|
|
106
109
|
receipts.push(preparation.receipt);
|
|
107
110
|
if (preparation.install)
|
|
108
111
|
fallbacks.push(preparation.install);
|
|
@@ -242,7 +245,7 @@ export async function lockfilesDiffer(baseCheckoutPath, worktreePath, packageRoo
|
|
|
242
245
|
}
|
|
243
246
|
return false;
|
|
244
247
|
}
|
|
245
|
-
async function ensureInstallFallback(entry, worktreePath, reason, executor, policy) {
|
|
248
|
+
async function ensureInstallFallback(entry, worktreePath, reason, executor, policy, hostLoad, signal) {
|
|
246
249
|
const startedAt = performance.now();
|
|
247
250
|
const cwd = path.resolve(worktreePath, entry.packageRoot === "." ? "" : entry.packageRoot);
|
|
248
251
|
assertWithinRoot(path.resolve(worktreePath), cwd, "Dependency package root");
|
|
@@ -271,7 +274,32 @@ async function ensureInstallFallback(entry, worktreePath, reason, executor, poli
|
|
|
271
274
|
},
|
|
272
275
|
};
|
|
273
276
|
}
|
|
274
|
-
|
|
277
|
+
// Inside the per-root lock, and only on a real install: a verified receipt never queues.
|
|
278
|
+
const install = await runHostGovernedStep(hostLoad?.gate, {
|
|
279
|
+
classification: dependencyInstallStepClass,
|
|
280
|
+
label: `${command} (${entry.packageRoot})`,
|
|
281
|
+
dispatchAttemptId: hostLoad?.dispatchAttemptId ?? null,
|
|
282
|
+
priority: hostLoad?.priority ?? "foreground",
|
|
283
|
+
// Attempt cancellation ends the wait for capacity too.
|
|
284
|
+
signal,
|
|
285
|
+
}, async (_waitMs, hostLoadControl) => {
|
|
286
|
+
// The install stops when the attempt is cancelled, its token is lost, or its
|
|
287
|
+
// process group cannot be recorded on the token. The runner settles only once
|
|
288
|
+
// the whole group is gone, so the token is never returned while it still runs.
|
|
289
|
+
const unrecorded = new AbortController();
|
|
290
|
+
const stop = [signal, hostLoadControl.fenced, unrecorded.signal].filter((value) => value !== undefined);
|
|
291
|
+
return await runInstallFallback(entry, worktreePath, reason, executor, {
|
|
292
|
+
signal: AbortSignal.any(stop),
|
|
293
|
+
processGroup: true,
|
|
294
|
+
onSpawn: hostLoadControl.attachProcess
|
|
295
|
+
? pid => void hostLoadControl.attachProcess({
|
|
296
|
+
rootPid: pid,
|
|
297
|
+
rootIdentity: captureHostProcessIdentity(pid),
|
|
298
|
+
processGroup: process.platform !== "win32",
|
|
299
|
+
}).catch((error) => unrecorded.abort(error))
|
|
300
|
+
: undefined,
|
|
301
|
+
});
|
|
302
|
+
});
|
|
275
303
|
// npm is allowed to omit node_modules when the package graph is empty. Keep
|
|
276
304
|
// an isolated, ignored output directory so the durable receipt still has a
|
|
277
305
|
// concrete marker whose removal invalidates reuse.
|
|
@@ -449,7 +477,7 @@ async function persistDependencyPreparationReceipt(receiptPath, receipt) {
|
|
|
449
477
|
function sha256Text(value) {
|
|
450
478
|
return createHash("sha256").update(value).digest("hex");
|
|
451
479
|
}
|
|
452
|
-
async function runInstallFallback(entry, worktreePath, reason, executor) {
|
|
480
|
+
async function runInstallFallback(entry, worktreePath, reason, executor, control = {}) {
|
|
453
481
|
assertHostDatabaseCapabilityBoundary();
|
|
454
482
|
const cwd = path.join(worktreePath, entry.packageRoot === "." ? "" : entry.packageRoot);
|
|
455
483
|
if (entry.ecosystem === "node") {
|
|
@@ -463,6 +491,7 @@ async function runInstallFallback(entry, worktreePath, reason, executor) {
|
|
|
463
491
|
requiredPathDirectories: launch.requiredPathDirectories,
|
|
464
492
|
}),
|
|
465
493
|
windowsVerbatimArguments: launch.windowsVerbatimArguments,
|
|
494
|
+
...control,
|
|
466
495
|
});
|
|
467
496
|
return { ecosystem: entry.ecosystem, packageRoot: entry.packageRoot, reason, command: `pnpm ${args.join(" ")}` };
|
|
468
497
|
}
|
|
@@ -475,16 +504,17 @@ async function runInstallFallback(entry, worktreePath, reason, executor) {
|
|
|
475
504
|
requiredPathDirectories: launch.requiredPathDirectories,
|
|
476
505
|
}),
|
|
477
506
|
windowsVerbatimArguments: launch.windowsVerbatimArguments,
|
|
507
|
+
...control,
|
|
478
508
|
});
|
|
479
509
|
return { ecosystem: entry.ecosystem, packageRoot: entry.packageRoot, reason, command: `npm ${args.join(" ")}` };
|
|
480
510
|
}
|
|
481
511
|
if (entry.ecosystem === "python") {
|
|
482
512
|
const environment = unattendedDependencyEnvironment();
|
|
483
|
-
await executor.run(cwd, "python", ["-m", "venv", ".venv"], { env: environment });
|
|
513
|
+
await executor.run(cwd, "python", ["-m", "venv", ".venv"], { env: environment, ...control });
|
|
484
514
|
const requirements = path.join(cwd, "requirements.txt");
|
|
485
515
|
if (await pathExists(requirements)) {
|
|
486
516
|
const pip = process.platform === "win32" ? path.join(".venv", "Scripts", "pip") : path.join(".venv", "bin", "pip");
|
|
487
|
-
await executor.run(cwd, pip, ["install", "-r", "requirements.txt"], { env: environment });
|
|
517
|
+
await executor.run(cwd, pip, ["install", "-r", "requirements.txt"], { env: environment, ...control });
|
|
488
518
|
return {
|
|
489
519
|
ecosystem: entry.ecosystem,
|
|
490
520
|
packageRoot: entry.packageRoot,
|
|
@@ -499,7 +529,7 @@ async function runInstallFallback(entry, worktreePath, reason, executor) {
|
|
|
499
529
|
command: "python -m venv .venv"
|
|
500
530
|
};
|
|
501
531
|
}
|
|
502
|
-
await executor.run(cwd, "dotnet", ["restore"], { env: unattendedDependencyEnvironment() });
|
|
532
|
+
await executor.run(cwd, "dotnet", ["restore"], { env: unattendedDependencyEnvironment(), ...control });
|
|
503
533
|
return {
|
|
504
534
|
ecosystem: entry.ecosystem,
|
|
505
535
|
packageRoot: entry.packageRoot,
|
|
@@ -960,7 +990,8 @@ function defaultNpmCliCandidates(execPath, homeDir) {
|
|
|
960
990
|
candidates.push("/usr/bin/npm", "/usr/local/bin/npm", path.join(homeDir, ".npm-global", "bin", "npm"), path.join(homeDir, ".npm-global", "lib", "node_modules", "npm", "bin", "npm-cli.js"));
|
|
961
991
|
return candidates;
|
|
962
992
|
}
|
|
963
|
-
|
|
993
|
+
/** Runs dependency installs; exported for tests. */
|
|
994
|
+
export const defaultCommandExecutor = {
|
|
964
995
|
async run(cwd, command, args, options) {
|
|
965
996
|
const result = await defaultProcessRunner.run({
|
|
966
997
|
command,
|
|
@@ -968,6 +999,11 @@ const defaultCommandExecutor = {
|
|
|
968
999
|
args,
|
|
969
1000
|
env: options?.env,
|
|
970
1001
|
windowsVerbatimArguments: options?.windowsVerbatimArguments,
|
|
1002
|
+
signal: options?.signal,
|
|
1003
|
+
onSpawn: options?.onSpawn,
|
|
1004
|
+
processGroup: options?.processGroup,
|
|
1005
|
+
// Only a failure excerpt is ever reported; a noisy install keeps its last 1 MiB.
|
|
1006
|
+
maxOutputChars: 1024 * 1024,
|
|
971
1007
|
});
|
|
972
1008
|
if (result.exitCode !== 0) {
|
|
973
1009
|
const output = formatCommandFailureOutput(result.stdout, result.stderr);
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { GitClient } from "../shared/git/git.js";
|
|
2
|
+
import type { HostLoadStepGate } from "../runtime/host-load-governor.js";
|
|
2
3
|
import type { WorktreeLifecycleCoordinator, WorktreeService } from "./worktree.base.js";
|
|
3
4
|
import type { WorktreeHandle, WorktreePrepareRequest } from "./worktree.types.js";
|
|
4
5
|
export declare class GitWorktreeService implements WorktreeService {
|
|
5
6
|
private readonly git;
|
|
6
7
|
private readonly coordinator;
|
|
7
|
-
|
|
8
|
+
/** Gates dependency install fallbacks; inert unless the governor is on. */
|
|
9
|
+
private readonly hostLoadGate?;
|
|
10
|
+
/** Holds the host runtime lease ledger; branches of live leases are never swept on release. */
|
|
11
|
+
private readonly leaseStateRoot;
|
|
12
|
+
constructor(git?: GitClient, coordinator?: WorktreeLifecycleCoordinator,
|
|
13
|
+
/** Gates dependency install fallbacks; inert unless the governor is on. */
|
|
14
|
+
hostLoadGate?: HostLoadStepGate | undefined,
|
|
15
|
+
/** Holds the host runtime lease ledger; branches of live leases are never swept on release. */
|
|
16
|
+
leaseStateRoot?: string);
|
|
8
17
|
prepare(request: WorktreePrepareRequest): Promise<WorktreeHandle>;
|
|
9
18
|
private trackedForgePaths;
|
|
10
19
|
private registeredManagedWorktreePath;
|
|
@@ -3,18 +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;
|
|
21
|
+
constructor(git = new GitClient(), coordinator = new RepositoryCoordinatorLock(defaultWorktreeCoordinatorStateRoot()),
|
|
22
|
+
/** Gates dependency install fallbacks; inert unless the governor is on. */
|
|
23
|
+
hostLoadGate,
|
|
24
|
+
/** Holds the host runtime lease ledger; branches of live leases are never swept on release. */
|
|
25
|
+
leaseStateRoot = defaultWorktreeCoordinatorStateRoot()) {
|
|
16
26
|
this.git = git;
|
|
17
27
|
this.coordinator = coordinator;
|
|
28
|
+
this.hostLoadGate = hostLoadGate;
|
|
29
|
+
this.leaseStateRoot = leaseStateRoot;
|
|
18
30
|
}
|
|
19
31
|
async prepare(request) {
|
|
20
32
|
const allowedRoot = await ensureDirectory(request.allowedRepoRoot);
|
|
@@ -102,7 +114,15 @@ export class GitWorktreeService {
|
|
|
102
114
|
baseCheckoutPath: repoPath,
|
|
103
115
|
worktreePath: resolvedWorktreePath,
|
|
104
116
|
allowedRoot,
|
|
105
|
-
warmPathOverrides: request.warmPathOverrides
|
|
117
|
+
warmPathOverrides: request.warmPathOverrides,
|
|
118
|
+
hostLoad: this.hostLoadGate?.enabled
|
|
119
|
+
? {
|
|
120
|
+
gate: this.hostLoadGate,
|
|
121
|
+
dispatchAttemptId: request.hostLoadOwner?.dispatchAttemptId ?? null,
|
|
122
|
+
priority: request.hostLoadOwner?.priority ?? "foreground",
|
|
123
|
+
}
|
|
124
|
+
: undefined,
|
|
125
|
+
signal: request.signal,
|
|
106
126
|
})
|
|
107
127
|
: undefined;
|
|
108
128
|
return {
|
|
@@ -164,6 +184,26 @@ export class GitWorktreeService {
|
|
|
164
184
|
// directory is fully materialized (or after an external cleanup removes it).
|
|
165
185
|
// Always prune so those missing-directory registrations do not accumulate.
|
|
166
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);
|
|
167
207
|
});
|
|
168
208
|
}
|
|
169
209
|
async restoreOrphanedWorktree(input) {
|
|
@@ -21,6 +21,13 @@ export interface WorktreePrepareRequest {
|
|
|
21
21
|
readonly warmPathOverrides?: readonly string[];
|
|
22
22
|
readonly applicationRuntimeRequired?: boolean;
|
|
23
23
|
readonly preserveExistingState?: boolean;
|
|
24
|
+
/** The attempt dependency installs reserve host capacity for (decision 0013). */
|
|
25
|
+
readonly hostLoadOwner?: {
|
|
26
|
+
readonly dispatchAttemptId: string | null;
|
|
27
|
+
readonly priority: "foreground" | "background";
|
|
28
|
+
};
|
|
29
|
+
/** The attempt's cancellation: queued installs stop waiting and running ones are stopped. */
|
|
30
|
+
readonly signal?: AbortSignal;
|
|
24
31
|
}
|
|
25
32
|
export interface WorktreeHandle {
|
|
26
33
|
readonly repoPath: string;
|
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.bd2cfb6b7438",
|
|
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",
|