@loucompanion/forge-bridge 0.1.3-dev.0bd9fb991b79 → 0.1.3-dev.0d26c10244e1
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 +35 -0
- package/dist/bridge/bridge.base.d.ts +4 -1
- package/dist/bridge/bridge.service.d.ts +39 -3
- package/dist/bridge/bridge.service.js +585 -56
- package/dist/bridge/bridge.types.d.ts +59 -1
- package/dist/cleanup/cleanup.service.d.ts +14 -2
- package/dist/cleanup/cleanup.service.js +469 -3
- package/dist/cleanup/cleanup.types.d.ts +10 -0
- package/dist/cleanup/index.d.ts +1 -1
- package/dist/cleanup/index.js +1 -1
- package/dist/cleanup/internals.d.ts +2 -2
- package/dist/cleanup/internals.js +1 -1
- package/dist/cli/cli.help.js +37 -3
- package/dist/cli/cli.service.d.ts +30 -2
- package/dist/cli/cli.service.js +191 -27
- package/dist/cli/local-config.d.ts +4 -0
- package/dist/cli/local-config.js +41 -1
- package/dist/runtime/aspnet-runtime-prebuild.d.ts +35 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +168 -0
- package/dist/runtime/attempt-node-runtime-launcher.d.ts +17 -0
- package/dist/runtime/attempt-node-runtime-launcher.js +105 -0
- package/dist/runtime/attempt-process-supervisor-registry.d.ts +20 -0
- package/dist/runtime/attempt-process-supervisor-registry.js +64 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +86 -0
- package/dist/runtime/attempt-process-supervisor.js +350 -0
- package/dist/runtime/generated-output-reset.d.ts +10 -0
- package/dist/runtime/generated-output-reset.js +103 -0
- package/dist/runtime/host-listener-inspector.d.ts +46 -0
- package/dist/runtime/host-listener-inspector.js +349 -0
- package/dist/runtime/host-port-broker.d.ts +76 -0
- package/dist/runtime/host-port-broker.js +333 -0
- package/dist/runtime/host-runtime-contract.d.ts +47 -0
- package/dist/runtime/host-runtime-contract.js +700 -0
- package/dist/runtime/host-runtime-lease.d.ts +179 -0
- package/dist/runtime/host-runtime-lease.js +1990 -0
- package/dist/runtime/host-runtime-promotion.d.ts +23 -0
- package/dist/runtime/host-runtime-promotion.js +159 -0
- package/dist/runtime/node-host-runtime-adapter.d.ts +54 -0
- package/dist/runtime/node-host-runtime-adapter.js +284 -0
- package/dist/runtime/playwright-host-runtime-adapter.d.ts +20 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +220 -0
- package/dist/runtime/runtime-isolation-lease.d.ts +67 -0
- package/dist/runtime/runtime-isolation-lease.js +158 -0
- package/dist/runtime/workspace-resource-estimator.d.ts +16 -0
- package/dist/runtime/workspace-resource-estimator.js +165 -0
- package/dist/sandbox/preflight.d.ts +15 -0
- package/dist/sandbox/preflight.js +100 -13
- package/dist/sandbox/process.js +125 -40
- package/dist/sandbox/repository-lock.js +37 -1
- package/dist/sandbox/runtime.d.ts +66 -3
- package/dist/sandbox/runtime.js +670 -105
- package/dist/sandbox/sandbox.types.d.ts +3 -0
- package/dist/sandbox/smoke.d.ts +76 -0
- package/dist/sandbox/smoke.js +380 -0
- package/dist/sandbox/worker-supervisor.js +1 -1
- package/dist/sandbox/worker.js +2 -5
- package/dist/sandbox/workspace.service.d.ts +1 -0
- package/dist/sandbox/workspace.service.js +28 -5
- package/dist/session/managed-attempt-tools.d.ts +18 -0
- package/dist/session/managed-attempt-tools.js +797 -0
- package/dist/session/managed-build-coordinator.d.ts +5 -0
- package/dist/session/managed-build-coordinator.js +105 -0
- package/dist/session/phase-completion.artifacts.js +21 -3
- package/dist/session/phase-completion.d.ts +11 -2
- package/dist/session/phase-completion.helpers.d.ts +5 -0
- package/dist/session/phase-completion.helpers.js +51 -10
- package/dist/session/phase-completion.js +12 -3
- package/dist/session/phase-completion.prompts.d.ts +3 -3
- package/dist/session/phase-completion.prompts.js +21 -6
- package/dist/session/phase-completion.runtime.d.ts +13 -1
- package/dist/session/phase-completion.runtime.js +187 -8
- package/dist/session/phase-completion.schemas.js +108 -3
- package/dist/session/phase-completion.validation.d.ts +4 -1
- package/dist/session/phase-completion.validation.js +150 -21
- package/dist/session/provider-cli/ci-repair-readiness.d.ts +14 -0
- package/dist/session/provider-cli/ci-repair-readiness.js +105 -0
- package/dist/session/provider-cli/provider-cli.artifacts.d.ts +3 -2
- package/dist/session/provider-cli/provider-cli.artifacts.js +65 -7
- package/dist/session/provider-cli/provider-cli.deterministic.js +47 -1
- package/dist/session/provider-cli/provider-cli.process.d.ts +16 -0
- package/dist/session/provider-cli/provider-cli.process.js +212 -25
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +4 -1
- package/dist/session/provider-cli/provider-cli.prompts.js +99 -19
- package/dist/session/provider-cli/provider-cli.qa-sidecars.js +1 -0
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +1 -1
- package/dist/session/provider-cli/provider-cli.runtime.js +3 -2
- package/dist/session/provider-cli/provider-cli.service.d.ts +20 -2
- package/dist/session/provider-cli/provider-cli.service.js +464 -102
- package/dist/session/provider-cli/provider-cli.types.d.ts +5 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +2 -0
- package/dist/session/provider-cli/provider-output-state.js +69 -7
- package/dist/session/session-redaction.d.ts +3 -0
- package/dist/session/session-redaction.js +38 -0
- package/dist/session/session.base.d.ts +6 -1
- package/dist/session/session.service.d.ts +8 -2
- package/dist/session/session.service.js +482 -41
- package/dist/session/session.types.d.ts +70 -0
- package/dist/session/session.types.js +76 -4
- package/dist/shared/format/format-bytes.d.ts +1 -0
- package/dist/shared/format/format-bytes.js +9 -0
- package/dist/shared/path/path.js +3 -1
- package/dist/shared/process/host-process-recovery.d.ts +12 -0
- package/dist/shared/process/host-process-recovery.js +78 -0
- package/dist/shared/process/host-process-supervisor.d.ts +57 -0
- package/dist/shared/process/host-process-supervisor.js +282 -0
- package/dist/shared/process/process.d.ts +1 -0
- package/dist/shared/process/process.js +1 -0
- package/dist/shared/redaction/redaction.js +6 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/artifact-injector.d.ts +3 -2
- package/dist/worktree/artifact-injector.js +43 -4
- package/dist/worktree/dependency-warmer.d.ts +10 -1
- package/dist/worktree/dependency-warmer.js +94 -5
- package/dist/worktree/index.d.ts +1 -0
- package/dist/worktree/index.js +1 -0
- package/dist/worktree/prior-phase-artifact-hydrator.d.ts +2 -0
- package/dist/worktree/prior-phase-artifact-hydrator.js +136 -0
- package/dist/worktree/worktree-paths.d.ts +4 -0
- package/dist/worktree/worktree-paths.js +30 -0
- package/dist/worktree/worktree.base.d.ts +3 -0
- package/dist/worktree/worktree.service.d.ts +8 -2
- package/dist/worktree/worktree.service.js +206 -43
- package/dist/worktree/worktree.types.d.ts +4 -1
- package/package.json +3 -2
- package/runtime/windows-job-supervisor.ps1 +356 -0
- package/runtime/windows-listener-owner.ps1 +33 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface AspNetRuntimePrebuildPlan {
|
|
2
|
+
readonly fingerprint: string;
|
|
3
|
+
readonly receiptPath: string;
|
|
4
|
+
readonly command: string;
|
|
5
|
+
readonly args: readonly string[];
|
|
6
|
+
readonly cwd: string;
|
|
7
|
+
readonly environment: Readonly<Record<string, string>>;
|
|
8
|
+
readonly projectPath: string;
|
|
9
|
+
readonly inputCommitSha: string;
|
|
10
|
+
}
|
|
11
|
+
export interface AspNetRuntimePrebuildResult {
|
|
12
|
+
readonly cacheHit: boolean;
|
|
13
|
+
readonly receiptPath: string;
|
|
14
|
+
readonly fingerprint: string;
|
|
15
|
+
}
|
|
16
|
+
export interface AspNetRuntimeBuildExecutionResult {
|
|
17
|
+
readonly exitCode: number;
|
|
18
|
+
readonly stdoutTail: string;
|
|
19
|
+
readonly stderrTail: string;
|
|
20
|
+
readonly stdoutLogPath: string;
|
|
21
|
+
readonly stderrLogPath: string;
|
|
22
|
+
}
|
|
23
|
+
export type AspNetRuntimeBuildExecutor = (plan: AspNetRuntimePrebuildPlan, signal?: AbortSignal) => Promise<AspNetRuntimeBuildExecutionResult>;
|
|
24
|
+
export declare function createAspNetRuntimePrebuildPlan(options: {
|
|
25
|
+
readonly command: string;
|
|
26
|
+
readonly args: readonly string[];
|
|
27
|
+
readonly cwd: string;
|
|
28
|
+
readonly worktreePath: string;
|
|
29
|
+
readonly environment?: Readonly<Record<string, string>>;
|
|
30
|
+
readonly inputCommitSha: string;
|
|
31
|
+
readonly runtimeContractFingerprint: string;
|
|
32
|
+
}): AspNetRuntimePrebuildPlan | null;
|
|
33
|
+
export declare function ensureAspNetRuntimePrebuilt(plan: AspNetRuntimePrebuildPlan, execute: AspNetRuntimeBuildExecutor, signal?: AbortSignal): Promise<AspNetRuntimePrebuildResult>;
|
|
34
|
+
export declare function withAspNetPrebuiltRunArguments(command: string, args: readonly string[]): readonly string[];
|
|
35
|
+
export declare function resolveWorktreeCommitSha(worktreePath: string, supplied?: string | null): Promise<string>;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import fs from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
export function createAspNetRuntimePrebuildPlan(options) {
|
|
6
|
+
if (!isDotnetRun(options.command, options.args))
|
|
7
|
+
return null;
|
|
8
|
+
const projectArgument = readOptionValue(options.args, "--project");
|
|
9
|
+
const projectPath = path.resolve(options.cwd, projectArgument ?? ".");
|
|
10
|
+
const normalizedWorktree = path.resolve(options.worktreePath);
|
|
11
|
+
const relativeProject = path.relative(normalizedWorktree, projectPath);
|
|
12
|
+
if (relativeProject.startsWith("..") || path.isAbsolute(relativeProject)) {
|
|
13
|
+
throw new Error("host_runtime_build_invalid: the ASP.NET project must remain inside the managed worktree.");
|
|
14
|
+
}
|
|
15
|
+
const projectDirectory = projectArgument && path.extname(projectPath).toLowerCase() === ".csproj"
|
|
16
|
+
? path.dirname(projectPath)
|
|
17
|
+
: projectPath;
|
|
18
|
+
const buildArgs = [
|
|
19
|
+
"build",
|
|
20
|
+
...(projectArgument ? [projectArgument] : []),
|
|
21
|
+
"--nologo",
|
|
22
|
+
"--no-restore",
|
|
23
|
+
"--disable-build-servers",
|
|
24
|
+
"-p:UseSharedCompilation=false",
|
|
25
|
+
"-p:DefaultItemExcludesInProjectFolder=TestResults/**",
|
|
26
|
+
...forwardBuildOptions(options.args),
|
|
27
|
+
];
|
|
28
|
+
const fingerprint = `sha256:${createHash("sha256").update(JSON.stringify({
|
|
29
|
+
inputCommitSha: options.inputCommitSha,
|
|
30
|
+
runtimeContractFingerprint: options.runtimeContractFingerprint,
|
|
31
|
+
project: relativeProject.replaceAll("\\", "/"),
|
|
32
|
+
args: buildArgs,
|
|
33
|
+
})).digest("hex")}`;
|
|
34
|
+
return {
|
|
35
|
+
fingerprint,
|
|
36
|
+
receiptPath: path.join(projectDirectory, "obj", ".forge-runtime-build.json"),
|
|
37
|
+
command: options.command,
|
|
38
|
+
args: buildArgs,
|
|
39
|
+
cwd: options.cwd,
|
|
40
|
+
environment: options.environment ?? {},
|
|
41
|
+
projectPath,
|
|
42
|
+
inputCommitSha: options.inputCommitSha,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export async function ensureAspNetRuntimePrebuilt(plan, execute, signal) {
|
|
46
|
+
const receipt = await readReceipt(plan.receiptPath);
|
|
47
|
+
if (receipt?.fingerprint === plan.fingerprint && receipt.inputCommitSha === plan.inputCommitSha) {
|
|
48
|
+
return { cacheHit: true, receiptPath: plan.receiptPath, fingerprint: plan.fingerprint };
|
|
49
|
+
}
|
|
50
|
+
const result = await execute(plan, signal);
|
|
51
|
+
if (result.exitCode !== 0) {
|
|
52
|
+
const evidence = [
|
|
53
|
+
diagnostic("stderr", result.stderrTail),
|
|
54
|
+
diagnostic("stdout", result.stdoutTail),
|
|
55
|
+
`stdout log: ${result.stdoutLogPath}`,
|
|
56
|
+
`stderr log: ${result.stderrLogPath}`,
|
|
57
|
+
].filter(Boolean).join("; ");
|
|
58
|
+
throw new Error(`host_runtime_build_failed: dotnet build exited with code ${result.exitCode}.${evidence ? ` ${evidence}` : ""}`);
|
|
59
|
+
}
|
|
60
|
+
await fs.mkdir(path.dirname(plan.receiptPath), { recursive: true });
|
|
61
|
+
const temporaryReceipt = `${plan.receiptPath}.${process.pid}.${Date.now()}.tmp`;
|
|
62
|
+
const nextReceipt = {
|
|
63
|
+
schemaVersion: 1,
|
|
64
|
+
fingerprint: plan.fingerprint,
|
|
65
|
+
inputCommitSha: plan.inputCommitSha,
|
|
66
|
+
projectPath: plan.projectPath,
|
|
67
|
+
completedAt: new Date().toISOString(),
|
|
68
|
+
};
|
|
69
|
+
await fs.writeFile(temporaryReceipt, `${JSON.stringify(nextReceipt)}\n`, { encoding: "utf8", mode: 0o600 });
|
|
70
|
+
await fs.rename(temporaryReceipt, plan.receiptPath);
|
|
71
|
+
return { cacheHit: false, receiptPath: plan.receiptPath, fingerprint: plan.fingerprint };
|
|
72
|
+
}
|
|
73
|
+
export function withAspNetPrebuiltRunArguments(command, args) {
|
|
74
|
+
if (!isDotnetRun(command, args)) {
|
|
75
|
+
throw new Error("node_runtime_adapter_invalid: aspnetcore adapter requires a dotnet run command.");
|
|
76
|
+
}
|
|
77
|
+
const applicationArguments = args.indexOf("--");
|
|
78
|
+
const insertionIndex = applicationArguments < 0 ? args.length : applicationArguments;
|
|
79
|
+
const beforeApplication = args.slice(0, insertionIndex);
|
|
80
|
+
return [
|
|
81
|
+
...beforeApplication,
|
|
82
|
+
...(!beforeApplication.includes("--no-build") ? ["--no-build"] : []),
|
|
83
|
+
...(!beforeApplication.includes("--no-restore") ? ["--no-restore"] : []),
|
|
84
|
+
...args.slice(insertionIndex),
|
|
85
|
+
];
|
|
86
|
+
}
|
|
87
|
+
export async function resolveWorktreeCommitSha(worktreePath, supplied) {
|
|
88
|
+
if (supplied && /^[0-9a-f]{40,64}$/iu.test(supplied))
|
|
89
|
+
return supplied.toLowerCase();
|
|
90
|
+
return await new Promise((resolve, reject) => {
|
|
91
|
+
const child = spawn("git", ["rev-parse", "--verify", "HEAD^{commit}"], {
|
|
92
|
+
cwd: worktreePath,
|
|
93
|
+
windowsHide: true,
|
|
94
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
95
|
+
});
|
|
96
|
+
let stdout = "";
|
|
97
|
+
let stderr = "";
|
|
98
|
+
child.stdout.setEncoding("utf8");
|
|
99
|
+
child.stderr.setEncoding("utf8");
|
|
100
|
+
child.stdout.on("data", chunk => { stdout = `${stdout}${String(chunk)}`.slice(-256); });
|
|
101
|
+
child.stderr.on("data", chunk => { stderr = `${stderr}${String(chunk)}`.slice(-1_000); });
|
|
102
|
+
child.once("error", reject);
|
|
103
|
+
child.once("close", code => {
|
|
104
|
+
const commit = stdout.trim();
|
|
105
|
+
if (code === 0 && /^[0-9a-f]{40,64}$/iu.test(commit))
|
|
106
|
+
resolve(commit.toLowerCase());
|
|
107
|
+
else
|
|
108
|
+
reject(new Error(`host_runtime_build_commit_unavailable: git rev-parse failed (${code ?? "unknown"}): ${stderr.trim()}`));
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
function isDotnetRun(command, args) {
|
|
113
|
+
const executable = path.basename(command).toLowerCase();
|
|
114
|
+
return (executable === "dotnet" || executable === "dotnet.exe") && args[0]?.toLowerCase() === "run";
|
|
115
|
+
}
|
|
116
|
+
function readOptionValue(args, option) {
|
|
117
|
+
const index = args.findIndex(argument => argument === option || argument.startsWith(`${option}=`));
|
|
118
|
+
if (index < 0)
|
|
119
|
+
return null;
|
|
120
|
+
const argument = args[index];
|
|
121
|
+
return argument.startsWith(`${option}=`) ? argument.slice(option.length + 1) : args[index + 1] ?? null;
|
|
122
|
+
}
|
|
123
|
+
function forwardBuildOptions(args) {
|
|
124
|
+
const forwarded = [];
|
|
125
|
+
const optionsWithValues = new Set(["-c", "--configuration", "-f", "--framework", "-r", "--runtime", "--arch", "--os"]);
|
|
126
|
+
for (let index = 1; index < args.length; index += 1) {
|
|
127
|
+
const argument = args[index];
|
|
128
|
+
if (argument === "--")
|
|
129
|
+
break;
|
|
130
|
+
if (argument === "--project") {
|
|
131
|
+
index += 1;
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (argument.startsWith("--project="))
|
|
135
|
+
continue;
|
|
136
|
+
if (optionsWithValues.has(argument)) {
|
|
137
|
+
const value = args[index + 1];
|
|
138
|
+
if (value !== undefined) {
|
|
139
|
+
forwarded.push(argument, value);
|
|
140
|
+
index += 1;
|
|
141
|
+
}
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if ([...optionsWithValues].some(option => argument.startsWith(`${option}=`))
|
|
145
|
+
|| argument.startsWith("-p:")
|
|
146
|
+
|| argument.startsWith("/p:")) {
|
|
147
|
+
forwarded.push(argument);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return forwarded;
|
|
151
|
+
}
|
|
152
|
+
async function readReceipt(receiptPath) {
|
|
153
|
+
try {
|
|
154
|
+
const parsed = JSON.parse(await fs.readFile(receiptPath, "utf8"));
|
|
155
|
+
return parsed.schemaVersion === 1 && typeof parsed.fingerprint === "string" && typeof parsed.inputCommitSha === "string"
|
|
156
|
+
? parsed
|
|
157
|
+
: null;
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
if (error.code === "ENOENT" || error instanceof SyntaxError)
|
|
161
|
+
return null;
|
|
162
|
+
throw error;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function diagnostic(label, value) {
|
|
166
|
+
const normalized = value.replaceAll(/[\r\n\t]+/gu, " ").trim();
|
|
167
|
+
return normalized ? `${label} tail: ${normalized.slice(-2_000)}` : "";
|
|
168
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AttemptProcessChildHandle, AttemptProcessSupervisor } from "./attempt-process-supervisor.js";
|
|
2
|
+
import type { HostPortLeaseOwner } from "./host-port-broker.js";
|
|
3
|
+
import { HostListenerInspector } from "./host-listener-inspector.js";
|
|
4
|
+
import type { HostListenerOwnership, NodeRuntimeCommandLauncher, NodeRuntimeLaunchRequest, NodeRuntimeReadinessDiagnostics } from "./node-host-runtime-adapter.js";
|
|
5
|
+
/** Launches one explicitly configured HTTP project beneath the attempt coordinator. */
|
|
6
|
+
export declare class AttemptNodeRuntimeLauncher implements NodeRuntimeCommandLauncher<AttemptProcessChildHandle> {
|
|
7
|
+
private readonly supervisor;
|
|
8
|
+
private readonly owner;
|
|
9
|
+
private readonly logDirectory;
|
|
10
|
+
private readonly listenerInspector;
|
|
11
|
+
private readonly diagnosticsByChild;
|
|
12
|
+
constructor(supervisor: AttemptProcessSupervisor, owner: HostPortLeaseOwner, logDirectory: string, listenerInspector?: HostListenerInspector);
|
|
13
|
+
launch(request: NodeRuntimeLaunchRequest, signal?: AbortSignal): Promise<AttemptProcessChildHandle>;
|
|
14
|
+
inspectListener(child: AttemptProcessChildHandle, request: NodeRuntimeLaunchRequest): Promise<HostListenerOwnership>;
|
|
15
|
+
stop(child: AttemptProcessChildHandle): Promise<void>;
|
|
16
|
+
readinessDiagnostics(child: AttemptProcessChildHandle): Promise<NodeRuntimeReadinessDiagnostics>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { HostListenerInspector } from "./host-listener-inspector.js";
|
|
5
|
+
const diagnosticTailLength = 4_000;
|
|
6
|
+
/** Launches one explicitly configured HTTP project beneath the attempt coordinator. */
|
|
7
|
+
export class AttemptNodeRuntimeLauncher {
|
|
8
|
+
supervisor;
|
|
9
|
+
owner;
|
|
10
|
+
logDirectory;
|
|
11
|
+
listenerInspector;
|
|
12
|
+
diagnosticsByChild = new WeakMap();
|
|
13
|
+
constructor(supervisor, owner, logDirectory, listenerInspector = new HostListenerInspector()) {
|
|
14
|
+
this.supervisor = supervisor;
|
|
15
|
+
this.owner = owner;
|
|
16
|
+
this.logDirectory = logDirectory;
|
|
17
|
+
this.listenerInspector = listenerInspector;
|
|
18
|
+
}
|
|
19
|
+
async launch(request, signal) {
|
|
20
|
+
const childName = projectChildName(request.port.name);
|
|
21
|
+
const stdoutPath = path.join(this.logDirectory, `${childName}.stdout.log`);
|
|
22
|
+
const stderrPath = path.join(this.logDirectory, `${childName}.stderr.log`);
|
|
23
|
+
const diagnostics = { exited: false, stdoutTail: "", stderrTail: "", outputRevision: 0 };
|
|
24
|
+
let child;
|
|
25
|
+
try {
|
|
26
|
+
child = await this.supervisor.startChildReady(childName, {
|
|
27
|
+
command: request.command,
|
|
28
|
+
args: request.args,
|
|
29
|
+
cwd: request.cwd,
|
|
30
|
+
env: request.environment,
|
|
31
|
+
captureOutput: false,
|
|
32
|
+
}, {
|
|
33
|
+
onStdoutLine: async (line) => {
|
|
34
|
+
diagnostics.stdoutTail = appendTail(diagnostics.stdoutTail, line);
|
|
35
|
+
diagnostics.outputRevision += 1;
|
|
36
|
+
await appendLine(stdoutPath, line);
|
|
37
|
+
},
|
|
38
|
+
onStderrLine: async (line) => {
|
|
39
|
+
diagnostics.stderrTail = appendTail(diagnostics.stderrTail, line);
|
|
40
|
+
diagnostics.outputRevision += 1;
|
|
41
|
+
await appendLine(stderrPath, line);
|
|
42
|
+
},
|
|
43
|
+
}, signal, { maxStartAttempts: 3, retryDelayMs: 250 });
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
throw enrichLaunchFailure(error, diagnostics);
|
|
47
|
+
}
|
|
48
|
+
this.diagnosticsByChild.set(child, diagnostics);
|
|
49
|
+
void child.result.then(result => {
|
|
50
|
+
diagnostics.exited = true;
|
|
51
|
+
diagnostics.exitCode = result.exitCode;
|
|
52
|
+
diagnostics.stdoutTail = appendTail(diagnostics.stdoutTail, result.stdout);
|
|
53
|
+
diagnostics.stderrTail = appendTail(diagnostics.stderrTail, result.stderr);
|
|
54
|
+
diagnostics.outputRevision += 1;
|
|
55
|
+
}, error => {
|
|
56
|
+
diagnostics.exited = true;
|
|
57
|
+
diagnostics.stderrTail = appendTail(diagnostics.stderrTail, error instanceof Error ? error.message : String(error));
|
|
58
|
+
diagnostics.outputRevision += 1;
|
|
59
|
+
});
|
|
60
|
+
return child;
|
|
61
|
+
}
|
|
62
|
+
async inspectListener(child, request) {
|
|
63
|
+
return await this.listenerInspector.inspect(child, request.port, this.owner);
|
|
64
|
+
}
|
|
65
|
+
async stop(child) {
|
|
66
|
+
await child.stop(this.owner.fencingToken);
|
|
67
|
+
}
|
|
68
|
+
async readinessDiagnostics(child) {
|
|
69
|
+
// Yield once so an already-settled result can update the diagnostic record.
|
|
70
|
+
await Promise.resolve();
|
|
71
|
+
const diagnostics = this.diagnosticsByChild.get(child);
|
|
72
|
+
return diagnostics ?? { exited: false };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function projectChildName(portName) {
|
|
76
|
+
const candidate = `project-${portName}`;
|
|
77
|
+
if (/^[a-z][a-z0-9_-]{0,31}$/u.test(candidate))
|
|
78
|
+
return candidate;
|
|
79
|
+
const digest = createHash("sha256").update(portName).digest("hex").slice(0, 16);
|
|
80
|
+
return `project-${digest}`;
|
|
81
|
+
}
|
|
82
|
+
async function appendLine(target, line) {
|
|
83
|
+
await fs.appendFile(target, `${line}\n`, { encoding: "utf8", mode: 0o600 });
|
|
84
|
+
}
|
|
85
|
+
function appendTail(current, value) {
|
|
86
|
+
if (!value)
|
|
87
|
+
return current;
|
|
88
|
+
const combined = current ? `${current}\n${value}` : value;
|
|
89
|
+
return combined.slice(-diagnosticTailLength);
|
|
90
|
+
}
|
|
91
|
+
function enrichLaunchFailure(error, diagnostics) {
|
|
92
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
93
|
+
const evidence = [
|
|
94
|
+
diagnostics.stderrTail ? `stderr tail: ${boundedDiagnostic(diagnostics.stderrTail)}` : "",
|
|
95
|
+
diagnostics.stdoutTail ? `stdout tail: ${boundedDiagnostic(diagnostics.stdoutTail)}` : "",
|
|
96
|
+
].filter(Boolean);
|
|
97
|
+
return evidence.length > 0
|
|
98
|
+
? new Error(`${message} ${evidence.join("; ")}`, { cause: error })
|
|
99
|
+
: error instanceof Error
|
|
100
|
+
? error
|
|
101
|
+
: new Error(message);
|
|
102
|
+
}
|
|
103
|
+
function boundedDiagnostic(value) {
|
|
104
|
+
return value.replaceAll(/[\r\n\t]+/gu, " ").trim().slice(-1_000);
|
|
105
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ProviderProcessHandlers, ProviderProcessRunRequest, ProviderProcessRunner, ProviderProcessRunResult } from "../session/provider-cli/provider-cli.process.js";
|
|
2
|
+
import { AttemptProcessSupervisor, type AttemptProcessSupervisorIdentity, type AttemptProcessSupervisorOptions } from "./attempt-process-supervisor.js";
|
|
3
|
+
/** Runner-local authority for active host attempt process coordinators. */
|
|
4
|
+
export declare class AttemptProcessSupervisorRegistry {
|
|
5
|
+
private readonly active;
|
|
6
|
+
register(identity: AttemptProcessSupervisorIdentity, runner: ProviderProcessRunner, options?: AttemptProcessSupervisorOptions): AttemptProcessSupervisor;
|
|
7
|
+
require(dispatchAttemptId: string, fencingToken: string): AttemptProcessSupervisor;
|
|
8
|
+
unregister(dispatchAttemptId: string, fencingToken: string): boolean;
|
|
9
|
+
has(dispatchAttemptId: string): boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Routes managed-host provider commands through the attempt's named provider
|
|
13
|
+
* child while retaining the raw runner for Docker and unmanaged execution.
|
|
14
|
+
*/
|
|
15
|
+
export declare class AttemptCoordinatedProviderProcessRunner implements ProviderProcessRunner {
|
|
16
|
+
private readonly registry;
|
|
17
|
+
private readonly rawRunner;
|
|
18
|
+
constructor(registry: AttemptProcessSupervisorRegistry, rawRunner: ProviderProcessRunner);
|
|
19
|
+
run(request: ProviderProcessRunRequest, handlers?: ProviderProcessHandlers, signal?: AbortSignal): Promise<ProviderProcessRunResult>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { AttemptProcessSupervisor, } from "./attempt-process-supervisor.js";
|
|
2
|
+
/** Runner-local authority for active host attempt process coordinators. */
|
|
3
|
+
export class AttemptProcessSupervisorRegistry {
|
|
4
|
+
active = new Map();
|
|
5
|
+
register(identity, runner, options = {}) {
|
|
6
|
+
const existing = this.active.get(identity.dispatchAttemptId);
|
|
7
|
+
if (existing) {
|
|
8
|
+
if (existing.fencingToken !== identity.fencingToken) {
|
|
9
|
+
throw new Error("attempt_process_registry_conflict: dispatch attempt is registered under a different fence.");
|
|
10
|
+
}
|
|
11
|
+
return existing.supervisor;
|
|
12
|
+
}
|
|
13
|
+
const supervisor = new AttemptProcessSupervisor(identity, runner, options);
|
|
14
|
+
this.active.set(identity.dispatchAttemptId, { fencingToken: identity.fencingToken, supervisor });
|
|
15
|
+
return supervisor;
|
|
16
|
+
}
|
|
17
|
+
require(dispatchAttemptId, fencingToken) {
|
|
18
|
+
const registered = this.active.get(dispatchAttemptId);
|
|
19
|
+
if (!registered) {
|
|
20
|
+
throw new Error("attempt_process_registry_missing: no process coordinator owns this dispatch attempt.");
|
|
21
|
+
}
|
|
22
|
+
if (registered.fencingToken !== fencingToken) {
|
|
23
|
+
throw new Error("attempt_process_registry_fenced: process coordinator fence does not match the dispatch.");
|
|
24
|
+
}
|
|
25
|
+
return registered.supervisor;
|
|
26
|
+
}
|
|
27
|
+
unregister(dispatchAttemptId, fencingToken) {
|
|
28
|
+
const registered = this.active.get(dispatchAttemptId);
|
|
29
|
+
if (!registered || registered.fencingToken !== fencingToken)
|
|
30
|
+
return false;
|
|
31
|
+
return this.active.delete(dispatchAttemptId);
|
|
32
|
+
}
|
|
33
|
+
has(dispatchAttemptId) {
|
|
34
|
+
return this.active.has(dispatchAttemptId);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Routes managed-host provider commands through the attempt's named provider
|
|
39
|
+
* child while retaining the raw runner for Docker and unmanaged execution.
|
|
40
|
+
*/
|
|
41
|
+
export class AttemptCoordinatedProviderProcessRunner {
|
|
42
|
+
registry;
|
|
43
|
+
rawRunner;
|
|
44
|
+
constructor(registry, rawRunner) {
|
|
45
|
+
this.registry = registry;
|
|
46
|
+
this.rawRunner = rawRunner;
|
|
47
|
+
}
|
|
48
|
+
async run(request, handlers, signal) {
|
|
49
|
+
if (request.env?.FORGE_RUNTIME_MODE !== "host") {
|
|
50
|
+
return await this.rawRunner.run(request, handlers, signal);
|
|
51
|
+
}
|
|
52
|
+
const dispatchAttemptId = requiredEnvironment(request, "FORGE_DISPATCH_ATTEMPT_ID");
|
|
53
|
+
const fencingToken = requiredEnvironment(request, "FORGE_FENCING_TOKEN");
|
|
54
|
+
const supervisor = this.registry.require(dispatchAttemptId, fencingToken);
|
|
55
|
+
const child = await supervisor.startChildReady("provider", request, handlers, signal, { maxStartAttempts: request.stdin === undefined ? 1 : 3, retryDelayMs: 100 });
|
|
56
|
+
return await child.result;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function requiredEnvironment(request, name) {
|
|
60
|
+
const value = request.env?.[name]?.trim();
|
|
61
|
+
if (!value)
|
|
62
|
+
throw new Error(`attempt_process_registry_invalid: ${name} is required for managed-host execution.`);
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { ProviderProcessHandlers, ProviderProcessRunRequest, ProviderProcessRunner, ProviderProcessRunResult } from "../session/provider-cli/provider-cli.process.js";
|
|
2
|
+
export type AttemptProcessChildStatus = "starting" | "running" | "stopping" | "exited" | "failed";
|
|
3
|
+
export type AttemptProcessSupervisorStatus = "active" | "stopping" | "stopped" | "degraded";
|
|
4
|
+
export interface AttemptProcessSupervisorIdentity {
|
|
5
|
+
readonly processSupervisorId: string;
|
|
6
|
+
readonly dispatchAttemptId: string;
|
|
7
|
+
readonly executionLeaseId: string;
|
|
8
|
+
readonly fencingToken: string;
|
|
9
|
+
readonly logDirectory: string;
|
|
10
|
+
}
|
|
11
|
+
export interface AttemptProcessChildLedgerEntry {
|
|
12
|
+
readonly name: string;
|
|
13
|
+
readonly generation: number;
|
|
14
|
+
readonly childId: string;
|
|
15
|
+
readonly processSupervisorId: string;
|
|
16
|
+
readonly metadataPath: string;
|
|
17
|
+
readonly status: AttemptProcessChildStatus;
|
|
18
|
+
readonly startedAt: string;
|
|
19
|
+
readonly settledAt?: string;
|
|
20
|
+
readonly exitCode?: number;
|
|
21
|
+
readonly failure?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface AttemptProcessSupervisorLedger {
|
|
24
|
+
readonly schemaVersion: 1;
|
|
25
|
+
readonly attemptSupervisorId: string;
|
|
26
|
+
readonly dispatchAttemptId: string;
|
|
27
|
+
readonly executionLeaseId: string;
|
|
28
|
+
readonly status: AttemptProcessSupervisorStatus;
|
|
29
|
+
readonly updatedAt: string;
|
|
30
|
+
readonly children: readonly AttemptProcessChildLedgerEntry[];
|
|
31
|
+
}
|
|
32
|
+
export interface AttemptProcessChildHandle {
|
|
33
|
+
readonly name: string;
|
|
34
|
+
readonly generation: number;
|
|
35
|
+
readonly childId: string;
|
|
36
|
+
readonly processSupervisorId: string;
|
|
37
|
+
readonly metadataPath: string;
|
|
38
|
+
readonly ready: Promise<void>;
|
|
39
|
+
readonly result: Promise<ProviderProcessRunResult>;
|
|
40
|
+
stop(fencingToken: string): Promise<ProviderProcessRunResult>;
|
|
41
|
+
}
|
|
42
|
+
export interface AttemptProcessSupervisorOptions {
|
|
43
|
+
readonly metadataReadyTimeoutMs?: number;
|
|
44
|
+
readonly signal?: AbortSignal;
|
|
45
|
+
}
|
|
46
|
+
export interface AttemptProcessChildReadyOptions {
|
|
47
|
+
readonly maxStartAttempts?: number;
|
|
48
|
+
readonly retryDelayMs?: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Owns the independently supervised process trees that belong to one host
|
|
52
|
+
* dispatch attempt. Each named child gets a distinct Windows Job Object or
|
|
53
|
+
* Unix process group through the existing process runner, while this
|
|
54
|
+
* coordinator supplies shared fencing, cancellation, and a durable ledger.
|
|
55
|
+
*/
|
|
56
|
+
export declare class AttemptProcessSupervisor {
|
|
57
|
+
private readonly runner;
|
|
58
|
+
readonly ledgerPath: string;
|
|
59
|
+
private readonly identity;
|
|
60
|
+
private readonly metadataReadyTimeoutMs;
|
|
61
|
+
private readonly records;
|
|
62
|
+
private readonly currentByName;
|
|
63
|
+
private readonly attemptController;
|
|
64
|
+
private status;
|
|
65
|
+
private persistTail;
|
|
66
|
+
private persistenceFailure;
|
|
67
|
+
private stopOperation;
|
|
68
|
+
constructor(identity: AttemptProcessSupervisorIdentity, runner: ProviderProcessRunner, options?: AttemptProcessSupervisorOptions);
|
|
69
|
+
startChild(name: string, request: ProviderProcessRunRequest, handlers?: ProviderProcessHandlers, signal?: AbortSignal): Promise<AttemptProcessChildHandle>;
|
|
70
|
+
/**
|
|
71
|
+
* Starts a child and proves that the OS process tree is supervised before
|
|
72
|
+
* returning it to the caller. A launch that settles before producing its
|
|
73
|
+
* provider-ready supervision record is safe to retry: the raw runner only
|
|
74
|
+
* persists that record after the actual provider child has started, before
|
|
75
|
+
* Forge announces the provider as active.
|
|
76
|
+
*/
|
|
77
|
+
startChildReady(name: string, request: ProviderProcessRunRequest, handlers?: ProviderProcessHandlers, signal?: AbortSignal, options?: AttemptProcessChildReadyOptions): Promise<AttemptProcessChildHandle>;
|
|
78
|
+
stopChild(name: string, generation: number, fencingToken: string, reason?: unknown): Promise<ProviderProcessRunResult>;
|
|
79
|
+
stopAll(fencingToken: string, reason?: unknown): Promise<void>;
|
|
80
|
+
private performStopAll;
|
|
81
|
+
snapshot(): AttemptProcessSupervisorLedger;
|
|
82
|
+
private observeChildReady;
|
|
83
|
+
private settleChild;
|
|
84
|
+
private assertFence;
|
|
85
|
+
private persist;
|
|
86
|
+
}
|