@loucompanion/forge-bridge 0.1.4-dev.f22f5e3d01fe → 0.2.1-dev.0fedbc5c9ef7
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 +89 -1
- package/dist/bridge/bridge-chat-giphy-look.d.ts +48 -0
- package/dist/bridge/bridge-chat-giphy-look.js +55 -0
- package/dist/bridge/bridge-chat-provider-command.d.ts +27 -3
- package/dist/bridge/bridge-chat-provider-command.js +131 -26
- package/dist/bridge/bridge-chat.types.d.ts +20 -0
- package/dist/bridge/bridge-chat.types.js +28 -1
- package/dist/bridge/bridge-state-file.d.ts +161 -0
- package/dist/bridge/bridge-state-file.js +376 -0
- package/dist/bridge/bridge-state-io.d.ts +11 -0
- package/dist/bridge/bridge-state-io.js +50 -0
- package/dist/bridge/bridge-state-lock.d.ts +11 -0
- package/dist/bridge/bridge-state-lock.js +102 -0
- package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
- package/dist/bridge/bridge-state-unpublished.js +111 -0
- package/dist/bridge/bridge.service.d.ts +19 -12
- package/dist/bridge/bridge.service.js +155 -282
- package/dist/bridge/bridge.types.d.ts +5 -0
- package/dist/bridge/in-flight-registry.d.ts +62 -0
- package/dist/bridge/in-flight-registry.js +207 -0
- package/dist/bridge/readiness-result-outbox.d.ts +5 -1
- package/dist/bridge/readiness-result-outbox.js +20 -0
- package/dist/bridge/runner-host-capabilities.js +14 -1
- package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
- package/dist/bridge/sandbox-resource-accounting.js +150 -0
- package/dist/bridge/windows-bash-resolution.d.ts +31 -0
- package/dist/bridge/windows-bash-resolution.js +153 -0
- package/dist/cleanup/cleanup-wip.d.ts +12 -0
- package/dist/cleanup/cleanup-wip.js +66 -0
- package/dist/cleanup/cleanup.service.d.ts +11 -1
- package/dist/cleanup/cleanup.service.js +80 -62
- package/dist/cleanup/cleanup.types.d.ts +2 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +2 -0
- package/dist/cleanup/host-runtime-ledger.js +30 -9
- package/dist/cli/cli.help.js +56 -12
- package/dist/cli/cli.service.d.ts +3 -10
- package/dist/cli/cli.service.js +10 -171
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +2 -0
- package/dist/cli/local-config.js +7 -1
- package/dist/cli/provider-cli-detection.d.ts +10 -0
- package/dist/cli/provider-cli-detection.js +160 -0
- package/dist/runtime/aspnet-runtime-prebuild.d.ts +20 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +104 -26
- package/dist/runtime/attempt-database-broker.d.ts +1 -1
- package/dist/runtime/attempt-node-runtime-launcher.d.ts +36 -0
- package/dist/runtime/attempt-node-runtime-launcher.js +169 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +2 -0
- package/dist/runtime/attempt-process-supervisor.js +12 -6
- package/dist/runtime/docker-engine-probe.d.ts +5 -0
- package/dist/runtime/docker-engine-probe.js +7 -0
- package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
- package/dist/runtime/dotnet-build-outputs.js +402 -0
- package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
- package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
- package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
- package/dist/runtime/ephemeral-test-postgres.js +303 -0
- package/dist/runtime/host-listener-inspector.d.ts +26 -0
- package/dist/runtime/host-listener-inspector.js +84 -3
- package/dist/runtime/host-load-admission.d.ts +5 -0
- package/dist/runtime/host-load-governor-config.d.ts +10 -1
- package/dist/runtime/host-load-governor-config.js +4 -1
- package/dist/runtime/host-load-governor.d.ts +10 -1
- package/dist/runtime/host-load-governor.js +33 -3
- package/dist/runtime/host-load-ledger-lock.js +6 -4
- package/dist/runtime/host-load-runtime-settings.js +4 -2
- package/dist/runtime/host-load-sampler.d.ts +8 -1
- package/dist/runtime/host-load-sampler.js +14 -7
- package/dist/runtime/host-load-test-slot.js +7 -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 +28 -3
- package/dist/runtime/host-runtime-lease.js +140 -296
- package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
- package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
- package/dist/runtime/host-runtime-promotion.d.ts +78 -2
- package/dist/runtime/host-runtime-promotion.js +307 -14
- package/dist/runtime/managed-command-teardown.js +5 -16
- package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
- package/dist/runtime/native-test-postgres-fallback.js +60 -8
- package/dist/runtime/prepared-runtime-identity.d.ts +4 -0
- package/dist/runtime/prepared-runtime-identity.js +130 -9
- package/dist/runtime/prepared-runtime-readiness.d.ts +13 -1
- package/dist/runtime/prepared-runtime-readiness.js +63 -16
- package/dist/runtime/runner-settings.d.ts +4 -0
- package/dist/runtime/runner-settings.js +22 -0
- package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
- package/dist/runtime/supervised-runtime-build-guard.js +112 -0
- package/dist/sandbox/host-capacity-broker.d.ts +3 -1
- package/dist/sandbox/host-capacity-broker.js +4 -2
- package/dist/sandbox/managed-branch.d.ts +13 -0
- package/dist/sandbox/managed-branch.js +90 -0
- package/dist/sandbox/provider-auth/codex.js +11 -11
- package/dist/sandbox/runtime.js +3 -7
- package/dist/session/managed-attempt-tools.d.ts +0 -7
- package/dist/session/managed-attempt-tools.js +50 -82
- package/dist/session/managed-build-coordinator.d.ts +16 -0
- package/dist/session/managed-build-coordinator.js +10 -0
- package/dist/session/managed-build-receipt.d.ts +5 -0
- package/dist/session/managed-build-receipt.js +8 -3
- package/dist/session/phase-completion.artifacts.js +2 -1
- package/dist/session/phase-completion.d.ts +8 -0
- package/dist/session/phase-completion.js +1 -0
- package/dist/session/phase-completion.mcp-args.d.ts +9 -0
- package/dist/session/phase-completion.mcp-args.js +156 -0
- package/dist/session/phase-completion.runtime.d.ts +0 -8
- package/dist/session/phase-completion.runtime.js +43 -197
- package/dist/session/pre-publication-native-postgres.d.ts +30 -0
- package/dist/session/pre-publication-native-postgres.js +111 -0
- package/dist/session/pre-publication-process.js +10 -10
- package/dist/session/pre-publication-step-execution.d.ts +2 -1
- package/dist/session/pre-publication-step-execution.js +6 -5
- package/dist/session/pre-publication-validation.d.ts +7 -3
- package/dist/session/pre-publication-validation.js +32 -30
- package/dist/session/provider-cli/claude-background-work.d.ts +3 -2
- package/dist/session/provider-cli/claude-background-work.js +4 -3
- package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
- package/dist/session/provider-cli/host-build-lock.js +30 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +16 -0
- package/dist/session/provider-cli/pre-publication-repair.js +33 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +4 -2
- package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +6 -3
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +28 -8
- package/dist/session/provider-cli/provider-cli.process.d.ts +2 -14
- package/dist/session/provider-cli/provider-cli.process.js +4 -94
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +3 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +27 -27
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +8 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +23 -2
- package/dist/session/provider-cli/provider-cli.service.d.ts +4 -1
- package/dist/session/provider-cli/provider-cli.service.js +27 -43
- package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
- package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
- package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
- package/dist/session/qa-sidecar-validation.d.ts +6 -0
- package/dist/session/qa-sidecar-validation.js +28 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +22 -1
- package/dist/session/sandbox-host-capacity-gate.js +35 -16
- package/dist/session/session-redaction.js +31 -181
- package/dist/session/session.service.d.ts +6 -0
- package/dist/session/session.service.js +131 -88
- package/dist/session/session.types.d.ts +1 -0
- package/dist/session/session.types.js +3 -3
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -0
- package/dist/shared/fs/file-identity.d.ts +10 -0
- package/dist/shared/fs/file-identity.js +15 -0
- package/dist/shared/fs/replace-file.d.ts +7 -0
- package/dist/shared/fs/replace-file.js +33 -0
- package/dist/shared/process/host-process-recovery.d.ts +14 -3
- package/dist/shared/process/host-process-recovery.js +23 -3
- package/dist/shared/process/host-process-supervisor.d.ts +13 -1
- package/dist/shared/process/host-process-supervisor.js +66 -14
- package/dist/shared/provider-capabilities.js +9 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/orphan-relink.d.ts +19 -0
- package/dist/worktree/orphan-relink.js +106 -0
- package/dist/worktree/wip-git.d.ts +42 -0
- package/dist/worktree/wip-git.js +139 -0
- package/dist/worktree/wip-refs.d.ts +77 -0
- package/dist/worktree/wip-refs.js +146 -0
- package/dist/worktree/wip-restore.d.ts +46 -0
- package/dist/worktree/wip-restore.js +280 -0
- package/dist/worktree/wip-snapshot.d.ts +53 -0
- package/dist/worktree/wip-snapshot.js +270 -0
- package/dist/worktree/worktree-inputs.d.ts +8 -0
- package/dist/worktree/worktree-inputs.js +134 -0
- package/dist/worktree/worktree-origin-sync.d.ts +35 -0
- package/dist/worktree/worktree-origin-sync.js +128 -0
- package/dist/worktree/worktree-wip-events.d.ts +18 -0
- package/dist/worktree/worktree-wip-events.js +115 -0
- package/dist/worktree/worktree-wip.d.ts +51 -0
- package/dist/worktree/worktree-wip.js +190 -0
- package/dist/worktree/worktree.base.d.ts +7 -1
- package/dist/worktree/worktree.service.d.ts +27 -5
- package/dist/worktree/worktree.service.js +112 -181
- package/dist/worktree/worktree.types.d.ts +35 -0
- package/package.json +1 -1
- package/runtime/windows-listener-owner.ps1 +12 -1
|
@@ -4,7 +4,14 @@ import path from "node:path";
|
|
|
4
4
|
import { redactText } from "../shared/redaction/redaction.js";
|
|
5
5
|
import { ForgeFailureError, sanitizeFailureError } from "../session/session.types.js";
|
|
6
6
|
import { HostListenerInspector } from "./host-listener-inspector.js";
|
|
7
|
+
import { writeSupervisedRuntimeDescriptor } from "./supervised-runtime-build-guard.js";
|
|
7
8
|
const diagnosticTailLength = 4_000;
|
|
9
|
+
export function brokeredHostPorts(ports) {
|
|
10
|
+
return new Set(ports.map(port => port.hostPort));
|
|
11
|
+
}
|
|
12
|
+
export function isolationViolationError(detail) {
|
|
13
|
+
return new ForgeFailureError("host_runtime_isolation_violation", `host_runtime_isolation_violation: ${detail}; the repository's parallel promotion was revoked and its runs are serialized until isolation is proven again.`);
|
|
14
|
+
}
|
|
8
15
|
/** Launches one explicitly configured HTTP project beneath the attempt coordinator. */
|
|
9
16
|
export class AttemptNodeRuntimeLauncher {
|
|
10
17
|
supervisor;
|
|
@@ -13,6 +20,7 @@ export class AttemptNodeRuntimeLauncher {
|
|
|
13
20
|
listenerInspector;
|
|
14
21
|
exactSecrets;
|
|
15
22
|
diagnosticsByChild = new WeakMap();
|
|
23
|
+
launchedChildren = [];
|
|
16
24
|
constructor(supervisor, owner, logDirectory, listenerInspector = new HostListenerInspector(), exactSecrets = []) {
|
|
17
25
|
this.supervisor = supervisor;
|
|
18
26
|
this.owner = owner;
|
|
@@ -27,6 +35,14 @@ export class AttemptNodeRuntimeLauncher {
|
|
|
27
35
|
const diagnostics = { exited: false, stdoutTail: "", stderrTail: "", outputRevision: 0 };
|
|
28
36
|
let child;
|
|
29
37
|
try {
|
|
38
|
+
// Recorded before the child starts, so a managed build can never see it running unrecorded.
|
|
39
|
+
await writeSupervisedRuntimeDescriptor(this.logDirectory, {
|
|
40
|
+
role: request.port.name,
|
|
41
|
+
childName,
|
|
42
|
+
command: request.command,
|
|
43
|
+
args: request.args,
|
|
44
|
+
cwd: request.cwd,
|
|
45
|
+
});
|
|
30
46
|
child = await this.supervisor.startChildReady(childName, {
|
|
31
47
|
command: request.command,
|
|
32
48
|
args: request.args,
|
|
@@ -54,6 +70,7 @@ export class AttemptNodeRuntimeLauncher {
|
|
|
54
70
|
}
|
|
55
71
|
const exposedChild = sanitizedChildHandle(child, this.exactSecrets);
|
|
56
72
|
this.diagnosticsByChild.set(exposedChild, diagnostics);
|
|
73
|
+
this.launchedChildren.push(exposedChild);
|
|
57
74
|
void exposedChild.result.then(result => {
|
|
58
75
|
diagnostics.exited = true;
|
|
59
76
|
diagnostics.exitCode = result.exitCode;
|
|
@@ -70,6 +87,65 @@ export class AttemptNodeRuntimeLauncher {
|
|
|
70
87
|
async inspectListener(child, request) {
|
|
71
88
|
return await this.listenerInspector.inspect(child, request.port, this.owner);
|
|
72
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Every loopback TCP port held by the process trees this launcher started that are still
|
|
92
|
+
* running, brokered or not. A launch the port broker retried leaves an exited child behind;
|
|
93
|
+
* it holds nothing and is skipped.
|
|
94
|
+
*/
|
|
95
|
+
async ownedListenerPorts() {
|
|
96
|
+
const ports = new Set();
|
|
97
|
+
for (const child of this.launchedChildren) {
|
|
98
|
+
if (this.diagnosticsByChild.get(child)?.exited)
|
|
99
|
+
continue;
|
|
100
|
+
for (const port of await this.listenerInspector.inspectOwnedTcpListeners(child, this.owner))
|
|
101
|
+
ports.add(port);
|
|
102
|
+
}
|
|
103
|
+
return [...ports].sort((left, right) => left - right);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Why these process trees break isolation, or null when they do not: a listener the port
|
|
107
|
+
* broker did not assign, or listeners that could not be inspected (unproven isolation).
|
|
108
|
+
*/
|
|
109
|
+
async unbrokeredListenerViolation(brokered) {
|
|
110
|
+
try {
|
|
111
|
+
const stray = (await this.ownedListenerPorts()).filter(port => !brokered.has(port));
|
|
112
|
+
return stray.length === 0
|
|
113
|
+
? null
|
|
114
|
+
: `the launched runtime listens on port(s) the port broker did not assign (${stray.join(", ")})`;
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
return `the launched runtime's listeners could not be inspected (${error instanceof Error ? error.message : String(error)})`;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Re-audits these process trees on an interval until stopped, so a listener opened after
|
|
122
|
+
* readiness (say, a fixed admin port bound once a database connects) is caught within one
|
|
123
|
+
* interval. `brokered` returning null skips a tick. The first violation is reported once and
|
|
124
|
+
* ends the monitor. Returns the function that stops it.
|
|
125
|
+
*/
|
|
126
|
+
monitorListeners(brokered, onViolation) {
|
|
127
|
+
let stopped = false;
|
|
128
|
+
let timer;
|
|
129
|
+
const schedule = () => {
|
|
130
|
+
timer = setTimeout(() => void tick(), this.listenerInspector.ownedListenerAuditIntervalMs);
|
|
131
|
+
timer.unref();
|
|
132
|
+
};
|
|
133
|
+
const tick = async () => {
|
|
134
|
+
const ports = stopped ? null : brokered();
|
|
135
|
+
const violation = ports === null ? null : await this.unbrokeredListenerViolation(ports);
|
|
136
|
+
if (stopped)
|
|
137
|
+
return;
|
|
138
|
+
if (violation === null)
|
|
139
|
+
return schedule();
|
|
140
|
+
stopped = true;
|
|
141
|
+
await onViolation(violation).catch(() => undefined);
|
|
142
|
+
};
|
|
143
|
+
schedule();
|
|
144
|
+
return () => {
|
|
145
|
+
stopped = true;
|
|
146
|
+
clearTimeout(timer);
|
|
147
|
+
};
|
|
148
|
+
}
|
|
73
149
|
async stop(child) {
|
|
74
150
|
await child.stop(this.owner.fencingToken);
|
|
75
151
|
}
|
|
@@ -138,3 +214,96 @@ function replaceSanitizedErrorMessage(error, message) {
|
|
|
138
214
|
function boundedDiagnostic(value) {
|
|
139
215
|
return value.replaceAll(/[\r\n\t]+/gu, " ").trim().slice(-1_000);
|
|
140
216
|
}
|
|
217
|
+
/** Runs a provider process beneath an attempt supervisor; an analysis-only provider may open no loopback listener. */
|
|
218
|
+
export class AttemptSupervisedProviderProcessRunner {
|
|
219
|
+
supervisor;
|
|
220
|
+
owner;
|
|
221
|
+
listenerInspector;
|
|
222
|
+
enforceNoListeners;
|
|
223
|
+
onProcessTreeStarted;
|
|
224
|
+
constructor(supervisor, owner, listenerInspector, enforceNoListeners, onProcessTreeStarted) {
|
|
225
|
+
this.supervisor = supervisor;
|
|
226
|
+
this.owner = owner;
|
|
227
|
+
this.listenerInspector = listenerInspector;
|
|
228
|
+
this.enforceNoListeners = enforceNoListeners;
|
|
229
|
+
this.onProcessTreeStarted = onProcessTreeStarted;
|
|
230
|
+
}
|
|
231
|
+
async run(request, handlers = {}, signal) {
|
|
232
|
+
const baselineListeners = this.enforceNoListeners
|
|
233
|
+
? new Set(await this.listenerInspector.inspectLoopbackListeners())
|
|
234
|
+
: new Set();
|
|
235
|
+
const child = await this.supervisor.startChildReady("provider", request, handlers, signal, { maxStartAttempts: request.stdin === undefined ? 1 : 3, retryDelayMs: 100 });
|
|
236
|
+
this.onProcessTreeStarted();
|
|
237
|
+
try {
|
|
238
|
+
return await this.awaitProviderResult(child, baselineListeners, signal);
|
|
239
|
+
}
|
|
240
|
+
finally {
|
|
241
|
+
// The provider tree, and the MCP server inside it, is gone. A managed command that
|
|
242
|
+
// server started now has no supervisor and no receipt writer, so it must not keep
|
|
243
|
+
// running into the next provider generation. This never rejects; a command it
|
|
244
|
+
// cannot prove stopped is left to attempt teardown, which fails closed.
|
|
245
|
+
await this.supervisor.stopOrphanedManagedCommands();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
async awaitProviderResult(child, baselineListeners, signal) {
|
|
249
|
+
if (!this.enforceNoListeners)
|
|
250
|
+
return await child.result;
|
|
251
|
+
let settled = false;
|
|
252
|
+
let inspectionFailure;
|
|
253
|
+
const monitor = (async () => {
|
|
254
|
+
while (!settled) {
|
|
255
|
+
try {
|
|
256
|
+
const ports = (await this.listenerInspector.inspectOwnedLoopbackListeners(child, this.owner))
|
|
257
|
+
.filter(port => !baselineListeners.has(port));
|
|
258
|
+
if (ports.length > 0) {
|
|
259
|
+
inspectionFailure = new Error(`host_analysis_listener_violation: analysis-only provider opened undeclared loopback listener(s): ${ports.join(", ")}.`);
|
|
260
|
+
await child.stop(this.owner.fencingToken).catch(() => undefined);
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
inspectionFailure = error;
|
|
266
|
+
await child.stop(this.owner.fencingToken).catch(() => undefined);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
await waitForAnalysisInspection(250, signal).catch(error => {
|
|
270
|
+
if (!settled && !signal?.aborted)
|
|
271
|
+
inspectionFailure = error;
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
})();
|
|
275
|
+
try {
|
|
276
|
+
const result = await child.result;
|
|
277
|
+
settled = true;
|
|
278
|
+
await monitor;
|
|
279
|
+
if (inspectionFailure)
|
|
280
|
+
throw inspectionFailure;
|
|
281
|
+
return result;
|
|
282
|
+
}
|
|
283
|
+
catch (error) {
|
|
284
|
+
settled = true;
|
|
285
|
+
await monitor.catch(() => undefined);
|
|
286
|
+
if (inspectionFailure)
|
|
287
|
+
throw inspectionFailure;
|
|
288
|
+
throw error;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
function waitForAnalysisInspection(milliseconds, signal) {
|
|
293
|
+
if (signal?.aborted)
|
|
294
|
+
return Promise.reject(cancellationError(signal));
|
|
295
|
+
return new Promise((resolve, reject) => {
|
|
296
|
+
const timer = setTimeout(() => {
|
|
297
|
+
signal?.removeEventListener("abort", abort);
|
|
298
|
+
resolve();
|
|
299
|
+
}, milliseconds);
|
|
300
|
+
const abort = () => {
|
|
301
|
+
clearTimeout(timer);
|
|
302
|
+
reject(cancellationError(signal));
|
|
303
|
+
};
|
|
304
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
function cancellationError(signal) {
|
|
308
|
+
return new Error(String(signal?.reason ?? "Dispatch cancelled while waiting for host runtime singleton ownership."));
|
|
309
|
+
}
|
|
@@ -57,6 +57,8 @@ export interface AttemptProcessChildReadyOptions {
|
|
|
57
57
|
readonly maxStartAttempts?: number;
|
|
58
58
|
readonly retryDelayMs?: number;
|
|
59
59
|
}
|
|
60
|
+
/** The attempt's durable child ledger; managed commands read it to find the attempt's running runtimes. */
|
|
61
|
+
export declare function attemptProcessSupervisorLedgerPath(logDirectory: string): string;
|
|
60
62
|
/**
|
|
61
63
|
* Owns the independently supervised process trees that belong to one host
|
|
62
64
|
* dispatch attempt. Each named child gets a distinct Windows Job Object or
|
|
@@ -4,6 +4,10 @@ import path from "node:path";
|
|
|
4
4
|
import { ForgeFailureError, sanitizeFailureError } from "../session/session.types.js";
|
|
5
5
|
import { terminateAttemptManagedCommands, } from "./managed-command-teardown.js";
|
|
6
6
|
import { monotonicNowMs } from "../shared/time/monotonic.js";
|
|
7
|
+
/** The attempt's durable child ledger; managed commands read it to find the attempt's running runtimes. */
|
|
8
|
+
export function attemptProcessSupervisorLedgerPath(logDirectory) {
|
|
9
|
+
return path.join(logDirectory, "attempt-process-supervisor.json");
|
|
10
|
+
}
|
|
7
11
|
const terminalChildStatuses = new Set(["exited", "failed"]);
|
|
8
12
|
const defaultMetadataReadyTimeoutMs = process.platform === "win32" ? 60_000 : 10_000;
|
|
9
13
|
// Windows refuses to replace a file another process (a scanner or indexer) briefly holds
|
|
@@ -41,7 +45,7 @@ export class AttemptProcessSupervisor {
|
|
|
41
45
|
this.replaceLedgerFile = options.replaceLedgerFile ?? ((temporaryPath, ledgerPath) => fs.rename(temporaryPath, ledgerPath));
|
|
42
46
|
this.ledgerReplaceRetryMs = options.ledgerReplaceRetryMs ?? defaultLedgerReplaceRetryMs;
|
|
43
47
|
this.managedCommandTeardownGraceMs = options.managedCommandTeardownGraceMs;
|
|
44
|
-
this.ledgerPath =
|
|
48
|
+
this.ledgerPath = attemptProcessSupervisorLedgerPath(this.identity.logDirectory);
|
|
45
49
|
if (options.signal?.aborted) {
|
|
46
50
|
this.status = "stopping";
|
|
47
51
|
this.attemptController.abort(options.signal.reason);
|
|
@@ -109,17 +113,19 @@ export class AttemptProcessSupervisor {
|
|
|
109
113
|
};
|
|
110
114
|
this.records.push(record);
|
|
111
115
|
this.currentByName.set(name, record);
|
|
112
|
-
|
|
113
|
-
record.result = result;
|
|
114
|
-
void result.then(value => this.settleChild(record, "exited", value.exitCode, undefined, value), error => this.settleChild(record, "failed", undefined, error));
|
|
116
|
+
// Durable before the process exists, so a ledger reader (the managed-build guard) never misses a child about to run.
|
|
115
117
|
try {
|
|
116
118
|
await this.persist();
|
|
117
119
|
}
|
|
118
120
|
catch (error) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
+
// Never spawned: the record settles as failed, with the reason the ledger could not be written.
|
|
122
|
+
Object.assign(record, { status: "failed", settledAt: new Date().toISOString() });
|
|
123
|
+
record.failure = boundedFailure(error, failureRedactionValues);
|
|
121
124
|
throw error;
|
|
122
125
|
}
|
|
126
|
+
const result = this.runner.run(childRequest, handlers, combinedSignal);
|
|
127
|
+
record.result = result;
|
|
128
|
+
void result.then(value => this.settleChild(record, "exited", value.exitCode, undefined, value), error => this.settleChild(record, "failed", undefined, error));
|
|
123
129
|
const ready = this.observeChildReady(record);
|
|
124
130
|
void ready.catch(() => undefined);
|
|
125
131
|
return {
|
|
@@ -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;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a supervised ASP.NET runtime builds and runs from, relative to each project in its
|
|
3
|
+
* graph. Agent builds keep the default `bin/<Configuration>/<TargetFramework>/` output, so they
|
|
4
|
+
* never overwrite (or, on Windows, fail on the locks of) the files a running runtime executes.
|
|
5
|
+
*/
|
|
6
|
+
export declare const supervisedRuntimeOutputRoot = "bin/forge-runtime";
|
|
7
|
+
export type DotnetPathPlatform = "win32" | "posix";
|
|
8
|
+
/** A directory option: CLI options are fixed for the whole graph, MSBuild properties resolve per project. */
|
|
9
|
+
export interface DotnetOutputLocation {
|
|
10
|
+
readonly path: string;
|
|
11
|
+
readonly perProject: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface DotnetOutputSettings {
|
|
14
|
+
readonly configuration: string;
|
|
15
|
+
readonly framework: string | null;
|
|
16
|
+
readonly runtime: string | null;
|
|
17
|
+
/** `-p:OutDir` or `-p:OutputPath`: MSBuild resolves a relative value against each project. */
|
|
18
|
+
readonly outDir: DotnetOutputLocation | null;
|
|
19
|
+
/** `-o`/`--output`: one directory for every project the command builds. */
|
|
20
|
+
readonly output: DotnetOutputLocation | null;
|
|
21
|
+
readonly baseOutputPath: DotnetOutputLocation | null;
|
|
22
|
+
readonly artifactsPath: DotnetOutputLocation | null;
|
|
23
|
+
}
|
|
24
|
+
/** A dotnet command that writes (or, for a runtime, executes from) project build output. */
|
|
25
|
+
export interface DotnetOutputCommand {
|
|
26
|
+
readonly verb: string;
|
|
27
|
+
readonly cwd: string;
|
|
28
|
+
/** Absolute target candidates (project, solution, or directory); empty means the working directory. */
|
|
29
|
+
readonly targets: readonly string[];
|
|
30
|
+
readonly settings: DotnetOutputSettings;
|
|
31
|
+
}
|
|
32
|
+
export interface DotnetProjectFiles {
|
|
33
|
+
readonly read: (file: string) => Promise<string | null>;
|
|
34
|
+
readonly list: (directory: string) => Promise<readonly string[] | null>;
|
|
35
|
+
/** The real location of a path (canonicalExistingPath); without it paths compare as written. */
|
|
36
|
+
readonly canonical?: (target: string) => Promise<string>;
|
|
37
|
+
}
|
|
38
|
+
export interface DotnetOutputCollision {
|
|
39
|
+
/** The project whose output both commands use. */
|
|
40
|
+
readonly project: string;
|
|
41
|
+
readonly outputDirectory: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Where a path really is, existing or not yet: its deepest existing ancestor resolved through every
|
|
45
|
+
* symlink and junction, with the rest appended. A lexical path alone lets a link alias another directory.
|
|
46
|
+
* A link whose target does not exist yet still leads to that target, so it is followed by its
|
|
47
|
+
* link text, never taken as its own location; a link loop fails with `path_link_unresolvable`.
|
|
48
|
+
*/
|
|
49
|
+
export declare function canonicalExistingPath(target: string): Promise<string>;
|
|
50
|
+
/** canonicalExistingPath, for synchronous planning. */
|
|
51
|
+
export declare function canonicalExistingPathSync(target: string): string;
|
|
52
|
+
export declare const fileSystemProjectFiles: DotnetProjectFiles;
|
|
53
|
+
export declare function hostPathPlatform(): DotnetPathPlatform;
|
|
54
|
+
export declare function isDotnetExecutable(command: string, platform?: DotnetPathPlatform): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Reads a dotnet command's build-output intent: its verb, target candidates, and output
|
|
57
|
+
* settings. Returns null when the command writes no build output. With `holder`, the command is
|
|
58
|
+
* a running runtime's `dotnet run`: `--no-build` does not matter, it executes from the output.
|
|
59
|
+
*/
|
|
60
|
+
export declare function parseDotnetOutputCommand(command: string, args: readonly string[], cwd: string, options?: {
|
|
61
|
+
readonly platform?: DotnetPathPlatform;
|
|
62
|
+
readonly holder?: boolean;
|
|
63
|
+
}): DotnetOutputCommand | null;
|
|
64
|
+
/** True when the arguments already choose where the build output goes. */
|
|
65
|
+
export declare function declaresDotnetOutput(settings: DotnetOutputSettings): boolean;
|
|
66
|
+
/** What the project file itself decides about its output layout. */
|
|
67
|
+
export interface DotnetProjectLayout {
|
|
68
|
+
/** The project sets `<TargetFrameworks>`: the artifacts layout then adds the framework to its pivot. */
|
|
69
|
+
readonly multiTargeted?: boolean;
|
|
70
|
+
}
|
|
71
|
+
/** True when a project file multi-targets (`<TargetFrameworks>`, even with one entry). */
|
|
72
|
+
export declare function isMultiTargetedProject(projectXml: string): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* The directory a project's primary output lands in under these settings. An unknown target
|
|
75
|
+
* framework is the wildcard `*`, which matches any framework in sameOutputDirectory.
|
|
76
|
+
*/
|
|
77
|
+
export declare function projectOutputDirectory(projectFile: string, settings: DotnetOutputSettings, platform?: DotnetPathPlatform, layout?: DotnetProjectLayout): string;
|
|
78
|
+
/**
|
|
79
|
+
* The one directory holding every build output of a project under these settings, whatever
|
|
80
|
+
* configuration or framework they leave open: what a runtime's build receipt verifies. Without
|
|
81
|
+
* the project file's name, an artifacts layout's root is its `bin`, above every project's folder.
|
|
82
|
+
*/
|
|
83
|
+
export declare function projectOutputRoot(projectDirectory: string, projectFile: string | null, settings: DotnetOutputSettings, platform?: DotnetPathPlatform): string;
|
|
84
|
+
/**
|
|
85
|
+
* Compares two output directories segment by segment. `*` matches any run of characters inside
|
|
86
|
+
* one segment: `*` is any framework folder, and `debug_*` any framework pivot.
|
|
87
|
+
*/
|
|
88
|
+
export declare function sameOutputDirectory(left: string, right: string, platform?: DotnetPathPlatform): boolean;
|
|
89
|
+
/** ProjectReference Include values of a project file, ignoring commented-out references. */
|
|
90
|
+
export declare function projectReferenceIncludes(projectXml: string): readonly string[];
|
|
91
|
+
/** Project paths a .sln or .slnx lists. */
|
|
92
|
+
export declare function solutionProjectPaths(solution: string, content: string): readonly string[];
|
|
93
|
+
/** Every project file a command builds: its targets, solution members, and their ProjectReference closure. */
|
|
94
|
+
export declare function dotnetCommandProjects(command: DotnetOutputCommand, files?: DotnetProjectFiles, platform?: DotnetPathPlatform): Promise<readonly string[]>;
|
|
95
|
+
/**
|
|
96
|
+
* The projects whose output a build (`writer`) would write while a runtime (`holder`) executes
|
|
97
|
+
* from that same output, in the runtime's graph order (its own project first).
|
|
98
|
+
*/
|
|
99
|
+
export declare function findDotnetOutputCollisions(writer: DotnetOutputCommand, holder: DotnetOutputCommand, files?: DotnetProjectFiles, platform?: DotnetPathPlatform): Promise<readonly DotnetOutputCollision[]>;
|
|
100
|
+
/** A runtime role as a directory name: kept when it is already safe, otherwise a stable digest. */
|
|
101
|
+
export declare function runtimeOutputName(role: string): string;
|
|
102
|
+
/**
|
|
103
|
+
* Gives a supervised `dotnet run` its own build output, `bin/forge-runtime/<role>/` under each
|
|
104
|
+
* project, unless the configured arguments already choose one. The ASP.NET prebuild forwards the
|
|
105
|
+
* same property to its `dotnet build`, so the runtime builds and runs from that directory.
|
|
106
|
+
*/
|
|
107
|
+
export declare function isolatedRuntimeOutputArguments(command: string, args: readonly string[], role: string, platform?: DotnetPathPlatform): readonly string[];
|