@warlock.js/process 5.44.0 → 5.46.0
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/CHANGELOG.md +17 -0
- package/README.md +1 -1
- package/cjs/index.cjs +43 -3
- package/cjs/index.cjs.map +1 -1
- package/esm/index.d.mts +2 -2
- package/esm/index.mjs +2 -2
- package/esm/platform.d.mts.map +1 -1
- package/esm/platform.mjs +8 -1
- package/esm/platform.mjs.map +1 -1
- package/esm/supervisor.d.mts +6 -0
- package/esm/supervisor.d.mts.map +1 -1
- package/esm/supervisor.mjs +37 -5
- package/esm/supervisor.mjs.map +1 -1
- package/esm/types.d.mts +12 -0
- package/esm/types.d.mts.map +1 -1
- package/llms-full.txt +24 -0
- package/package.json +1 -1
- package/skills/SKILL.md +24 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog — @warlock.js/process
|
|
2
2
|
|
|
3
|
+
## 5.45.0 - 2026-11-05
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- `pidWaitMs` supervisor option: how long a terminal may take to report a real process ID after `spawnPty()`. Defaults to 10 s. ConPTY reports pid 0 for a moment after spawn on Windows; the supervisor now waits for the real pid instead of supervising pid 0.
|
|
8
|
+
- `setupTimeoutMs` supervisor option: how long a launched child has to reach its resource setup gate. Defaults to 5 s on Linux and 30 s on Windows and macOS. Explicit values win.
|
|
9
|
+
- `ProcessStartupError`, thrown when a launch cannot be supervised. Its `reason` is `no-pid` (no real pid arrived within `pidWaitMs`), `exited` (the child exited before its gate) or `setup-timeout` (the gate was not reached within `setupTimeoutMs`).
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- The setup gate deadline is 30 s on Windows and macOS (it was 5 s on every platform). Linux keeps 5 s.
|
|
14
|
+
- A launch that fails at its setup gate now rejects with `ProcessStartupError`; the message is unchanged.
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- A terminal that reported pid 0 right after `spawnPty()` could be supervised under pid 0. The launch now waits for a real pid, and a terminal that never reports one is stopped on a best-effort basis and rejected with `ProcessStartupError`.
|
|
19
|
+
|
|
3
20
|
## 5.40.0 - 2026-10-29
|
|
4
21
|
|
|
5
22
|
### Fixed
|
package/README.md
CHANGED
|
@@ -45,7 +45,7 @@ On these platforms the handle PID belongs to a small Node guardian that launches
|
|
|
45
45
|
the workload after registry persistence. It proves its inherited environment
|
|
46
46
|
token through a live local socket/named pipe; polling includes guardian overhead
|
|
47
47
|
and descendants. Recovery uses the same PID/start-time/token verification.
|
|
48
|
-
Windows needs Windows PowerShell with CIM available. `pollIntervalMs` defaults to 100 ms on Linux, 500 on macOS and 1500 on Windows; `observationTimeoutMs` to 2 s on Linux and 15 s elsewhere. `cpuSeconds` is POSIX-only;
|
|
48
|
+
Windows needs Windows PowerShell with CIM available. `pollIntervalMs` defaults to 100 ms on Linux, 500 on macOS and 1500 on Windows; `observationTimeoutMs` to 2 s on Linux and 15 s elsewhere; `setupTimeoutMs` (setup gate) to 5 s on Linux and 30 s elsewhere; `pidWaitMs` (terminal pid wait) to 10 s. `cpuSeconds` is POSIX-only;
|
|
49
49
|
`virtualMemoryBytes` is Linux-only. Timeouts work on all three platforms.
|
|
50
50
|
Windows stops force the entire PID tree immediately; Job Objects are a future
|
|
51
51
|
improvement for hard containment and memory caps.
|
package/cjs/index.cjs
CHANGED
|
@@ -49,6 +49,13 @@ function defaultPollIntervalMs(platform) {
|
|
|
49
49
|
function defaultObservationTimeoutMs(platform) {
|
|
50
50
|
return platform === "win32" || platform === "darwin" ? 15e3 : 2e3;
|
|
51
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Longest wait for a launched child to reach the resource setup gate. Linux answers
|
|
54
|
+
* from /proc; Windows and macOS answer through the guardian and helpers under load.
|
|
55
|
+
*/
|
|
56
|
+
function defaultSetupTimeoutMs(platform) {
|
|
57
|
+
return platform === "linux" ? 5e3 : 3e4;
|
|
58
|
+
}
|
|
52
59
|
var UnsupportedProcessPlatformError = class extends Error {
|
|
53
60
|
platform;
|
|
54
61
|
constructor(platform) {
|
|
@@ -872,6 +879,26 @@ function createWindowsHelper(options = {}) {
|
|
|
872
879
|
|
|
873
880
|
//#endregion
|
|
874
881
|
//#region ../../packages/process/src/supervisor.ts
|
|
882
|
+
/** The launch failed before the child could be supervised. */
|
|
883
|
+
var ProcessStartupError = class extends Error {
|
|
884
|
+
reason;
|
|
885
|
+
/** `no-pid`: a terminal never reported a process ID. `exited`: the child exited before its gate. `setup-timeout`: the gate was not reached in time. */
|
|
886
|
+
constructor(reason, message) {
|
|
887
|
+
super(message);
|
|
888
|
+
this.reason = reason;
|
|
889
|
+
this.name = "ProcessStartupError";
|
|
890
|
+
}
|
|
891
|
+
};
|
|
892
|
+
/**
|
|
893
|
+
* ConPTY reports pid 0 until the child has started. Wait for a real pid so the
|
|
894
|
+
* supervisor never tracks pid 0; give up after `waitMs` with a typed error.
|
|
895
|
+
*/
|
|
896
|
+
async function terminalPid(terminal, waitMs) {
|
|
897
|
+
const deadline = Date.now() + waitMs;
|
|
898
|
+
while (!terminal.pid && Date.now() < deadline) await (0, node_timers_promises.setTimeout)(10);
|
|
899
|
+
if (!terminal.pid) throw new ProcessStartupError("no-pid", `Terminal did not report a process ID within ${waitMs} ms`);
|
|
900
|
+
return terminal.pid;
|
|
901
|
+
}
|
|
875
902
|
function info(entry) {
|
|
876
903
|
const { token: _token, start: _start, cgroup: _cgroup, gated: _gated, ...visible } = entry;
|
|
877
904
|
return structuredClone(visible);
|
|
@@ -899,6 +926,10 @@ function supervisor(options) {
|
|
|
899
926
|
if (live && live.owner === options.owner) return live.api;
|
|
900
927
|
const observationMs = options.observationTimeoutMs ?? defaultObservationTimeoutMs(process.platform);
|
|
901
928
|
if (!Number.isSafeInteger(observationMs) || observationMs < 100) throw new Error("Invalid observationTimeoutMs: expected an integer of at least 100");
|
|
929
|
+
const pidWaitMs = options.pidWaitMs ?? 1e4;
|
|
930
|
+
if (!Number.isSafeInteger(pidWaitMs) || pidWaitMs < 0) throw new Error("Invalid pidWaitMs: expected a nonnegative integer");
|
|
931
|
+
const setupMs = options.setupTimeoutMs ?? defaultSetupTimeoutMs(process.platform);
|
|
932
|
+
if (!Number.isSafeInteger(setupMs) || setupMs < 100) throw new Error("Invalid setupTimeoutMs: expected an integer of at least 100");
|
|
902
933
|
let helper;
|
|
903
934
|
function observe() {
|
|
904
935
|
if (process.platform === "win32") helper ??= createWindowsHelper({ timeoutMs: observationMs });
|
|
@@ -1182,7 +1213,14 @@ function supervisor(options) {
|
|
|
1182
1213
|
rows: input.rows ?? 24,
|
|
1183
1214
|
name: "xterm-256color"
|
|
1184
1215
|
});
|
|
1185
|
-
|
|
1216
|
+
try {
|
|
1217
|
+
pid = await terminalPid(terminalProcess, pidWaitMs);
|
|
1218
|
+
} catch (error) {
|
|
1219
|
+
try {
|
|
1220
|
+
terminalProcess.kill?.();
|
|
1221
|
+
} catch {}
|
|
1222
|
+
throw error;
|
|
1223
|
+
}
|
|
1186
1224
|
const output = new node_stream.PassThrough();
|
|
1187
1225
|
const errors = new node_stream.PassThrough();
|
|
1188
1226
|
const instance = terminalProcess;
|
|
@@ -1226,7 +1264,7 @@ function supervisor(options) {
|
|
|
1226
1264
|
}
|
|
1227
1265
|
let entry;
|
|
1228
1266
|
try {
|
|
1229
|
-
const deadline = Date.now() +
|
|
1267
|
+
const deadline = Date.now() + setupMs;
|
|
1230
1268
|
const portable = process.platform !== "linux";
|
|
1231
1269
|
const gate = async () => {
|
|
1232
1270
|
if (portable) {
|
|
@@ -1237,7 +1275,8 @@ function supervisor(options) {
|
|
|
1237
1275
|
let current = await gate();
|
|
1238
1276
|
while (!current?.state.startsWith("T") || current.token !== token) {
|
|
1239
1277
|
if (spawnError) throw spawnError;
|
|
1240
|
-
if (exit
|
|
1278
|
+
if (exit) throw new ProcessStartupError("exited", "Child failed to reach the resource setup gate");
|
|
1279
|
+
if (Date.now() >= deadline) throw new ProcessStartupError("setup-timeout", "Child failed to reach the resource setup gate");
|
|
1241
1280
|
await (0, node_timers_promises.setTimeout)(10);
|
|
1242
1281
|
current = await gate();
|
|
1243
1282
|
}
|
|
@@ -1396,6 +1435,7 @@ function sameProcessSupervisors() {
|
|
|
1396
1435
|
|
|
1397
1436
|
//#endregion
|
|
1398
1437
|
exports.ProcessNotOwnedError = ProcessNotOwnedError;
|
|
1438
|
+
exports.ProcessStartupError = ProcessStartupError;
|
|
1399
1439
|
exports.UnsupportedProcessPlatformError = UnsupportedProcessPlatformError;
|
|
1400
1440
|
exports.supervisor = supervisor;
|
|
1401
1441
|
//# sourceMappingURL=index.cjs.map
|
package/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["path","readFile","mkdir","writeFile","rmdir","randomBytes","createHmac","connect","promisify","execFile","readFile","mkdir","path","readFile","randomBytes","rename","rm","writeFile","spawnChild","path","delay","PassThrough","randomBytes","Writable","spawnChild"],"sources":["../../../../../../../packages/process/src/platform.ts","../../../../../../../packages/process/src/resources.ts","../../../../../../../packages/process/src/guardian.ts","../../../../../../../packages/process/src/identity.ts","../../../../../../../packages/process/src/registry.ts","../../../../../../../packages/process/src/windows-helper.ts","../../../../../../../packages/process/src/supervisor.ts"],"sourcesContent":["import type { Identity } from \"./identity\";\n\nexport type PortablePlatform = \"darwin\" | \"win32\";\nexport type Command = { file: string; args: string[]; env?: Record<string, string> };\nexport type Execute = (command: Command) => Promise<string>;\nexport type OwnershipProof = { pid: number; token: string; gated: boolean };\nexport type ReadProof = (pid: number) => Promise<OwnershipProof | undefined>;\nexport type Row = {\n pid: number;\n parent: number;\n start: string;\n rss: number;\n group: number;\n state: string;\n};\n\n/**\n * Defaults per platform. Linux reads /proc directly, so it is cheap to poll\n * often and a guardian reply is never awaited. Windows and macOS observe\n * through helper programs and a named pipe, which need more time and a slower\n * poll to stay out of the workload's way.\n */\nexport function defaultPollIntervalMs(platform: string): number {\n return platform === \"win32\" ? 1500 : platform === \"darwin\" ? 500 : 100;\n}\nexport function defaultObservationTimeoutMs(platform: string): number {\n return platform === \"win32\" || platform === \"darwin\" ? 15_000 : 2000;\n}\n\nexport class UnsupportedProcessPlatformError extends Error {\n constructor(public readonly platform: string) {\n super(`Process supervision is unsupported on ${platform}`);\n this.name = \"UnsupportedProcessPlatformError\";\n }\n}\nexport function supported(platform: string): void {\n if (![\"linux\", \"darwin\", \"win32\"].includes(platform))\n throw new UnsupportedProcessPlatformError(platform);\n}\nfunction validPid(pid: number): void {\n if (!Number.isSafeInteger(pid) || pid <= 1) throw new Error(\"Invalid process PID\");\n}\n\n/** Apple ps(1): lstart uses strftime %c. LC_ALL=C gives %a %b %e %H:%M:%S %Y.\n * https://github.com/apple-oss-distributions/adv_cmds/blob/main/ps/ps.1\n * https://github.com/apple-oss-distributions/adv_cmds/blob/main/ps/print.c (lstarted)\n * https://github.com/apple-oss-distributions/Libc/blob/main/stdtime/FreeBSD/timelocal.c (_C_time_locale)\n */\nexport function parseDarwinStart(source: string): string {\n const match =\n /^(Sun|Mon|Tue|Wed|Thu|Fri|Sat) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\s+(\\d{1,2}) (\\d{2}):(\\d{2}):(\\d{2}) (\\d{4})$/.exec(\n source.trim(),\n );\n if (!match) throw new Error(\"Invalid macOS process start time\");\n const [, weekday, month, day, hour, minute, second, year] = match;\n const monthIndex = \"Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec\"\n .split(\" \")\n .indexOf(month ?? \"\");\n const date = new Date(\n Date.UTC(Number(year), monthIndex, Number(day), Number(hour), Number(minute), Number(second)),\n );\n if (\n date.getUTCFullYear() !== Number(year) ||\n date.getUTCMonth() !== monthIndex ||\n date.getUTCDate() !== Number(day) ||\n date.getUTCHours() !== Number(hour) ||\n date.getUTCMinutes() !== Number(minute) ||\n date.getUTCSeconds() !== Number(second) ||\n \"Sun Mon Tue Wed Thu Fri Sat\".split(\" \")[date.getUTCDay()] !== weekday\n )\n throw new Error(\"Invalid macOS process start time\");\n return String(date.getTime() / 1000);\n}\nexport function darwinCommand(pid: number, tree = false): Command {\n validPid(pid);\n return {\n file: \"/bin/ps\",\n args: [...(tree ? [\"-ax\"] : [\"-p\", String(pid)]), \"-o\", \"pid=,ppid=,pgid=,state=,rss=,lstart=\"],\n env: { LC_ALL: \"C\", TZ: \"UTC\" },\n };\n}\nexport function parseDarwinRows(source: string): Row[] {\n return source.trim()\n ? source\n .trim()\n .split(\"\\n\")\n .map((line) => {\n const match = /^\\s*(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\S+)\\s+(\\d+)\\s+(.+?)\\s*$/.exec(line);\n if (!match) throw new Error(\"Invalid macOS process observation\");\n return {\n pid: Number(match[1]),\n parent: Number(match[2]),\n group: Number(match[3]),\n state: match[4] ?? \"\",\n rss: Number(match[5]) * 1024,\n start: parseDarwinStart(match[6] ?? \"\"),\n };\n })\n : [];\n}\n\n/** CIM CreationDate is a DateTime; serialize UTC ticks as text, never a locale date\n * or JSON number (100ns ticks exceed Number's precision). WorkingSetSize is bytes.\n * https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-process\n */\nexport function windowsCommand(pid: number, tree = false): Command {\n validPid(pid);\n const query = `Get-CimInstance Win32_Process${tree ? \"\" : ` -Filter 'ProcessId=${pid}'`}`;\n const script = [\n \"$ErrorActionPreference = 'Stop'\",\n `$rows = @(${query} | ForEach-Object {`,\n `if ([int]$_.ProcessId -eq ${pid} -and $null -eq $_.CreationDate) { throw 'Cannot read process creation time' }`,\n \"if ($null -ne $_.CreationDate) {\",\n \"[pscustomobject]@{ pid = [int]$_.ProcessId; parent = [int]$_.ParentProcessId; start = $_.CreationDate.ToUniversalTime().Ticks.ToString([Globalization.CultureInfo]::InvariantCulture); rss = [double]$_.WorkingSetSize }\",\n \"}\",\n \"})\",\n \"ConvertTo-Json -InputObject $rows -Compress\",\n ].join(\"\\n\");\n return {\n file: \"powershell.exe\",\n args: [\"-NoLogo\", \"-NoProfile\", \"-NonInteractive\", \"-Command\", script],\n };\n}\nexport function parseWindowsRows(source: string): Row[] {\n return windowsRows(JSON.parse(source.replace(/^\\uFEFF/, \"\")));\n}\n/** Validates rows decoded from PowerShell, whether one-shot or from the long-lived helper. */\nexport function windowsRows(value: unknown): Row[] {\n if (!Array.isArray(value)) throw new Error(\"Invalid Windows process observation\");\n return value.map((row: unknown) => {\n if (\n !row ||\n typeof row !== \"object\" ||\n !(\"pid\" in row) ||\n typeof row.pid !== \"number\" ||\n !Number.isSafeInteger(row.pid) ||\n row.pid < 0 ||\n !(\"parent\" in row) ||\n typeof row.parent !== \"number\" ||\n !Number.isSafeInteger(row.parent) ||\n row.parent < 0 ||\n !(\"start\" in row) ||\n typeof row.start !== \"string\" ||\n !/^\\d{18}$/.test(row.start) ||\n !(\"rss\" in row) ||\n typeof row.rss !== \"number\" ||\n !Number.isFinite(row.rss) ||\n row.rss < 0\n )\n throw new Error(\"Invalid Windows process observation\");\n return {\n pid: row.pid,\n parent: row.parent,\n start: row.start,\n rss: row.rss,\n group: row.pid,\n state: \"R\",\n };\n });\n}\nexport function taskkillCommand(pid: number): Command {\n validPid(pid);\n // Never accept an image name, filter, wildcard or shell interpolation.\n return { file: \"taskkill.exe\", args: [\"/PID\", String(pid), \"/T\", \"/F\"] };\n}\nexport function treeMemory(rows: Row[], pid: number): number {\n const root = rows.find((row) => row.pid === pid);\n if (!root) return 0;\n const included = new Map<number, Row>([[pid, root]]);\n let changed = true;\n while (changed) {\n changed = false;\n for (const row of rows) {\n const parent = included.get(row.parent);\n // Reject a reused parent PID whose creation time is later than the child.\n if (!included.has(row.pid) && parent && BigInt(row.start) >= BigInt(parent.start)) {\n included.set(row.pid, row);\n changed = true;\n }\n }\n }\n return [...included.values()].reduce((total, row) => total + row.rss, 0);\n}\n\n/** Reads process rows. `tree` asks for the whole table; `maxAgeMs` accepts a recent snapshot. */\nexport type RowSource = (pids: number[], tree: boolean, maxAgeMs?: number) => Promise<Row[]>;\n\n/** All OS effects are injected; foreign-platform specs never execute real commands. */\nexport async function portableIdentity(\n platform: PortablePlatform,\n pid: number,\n token: boolean,\n execute: Execute,\n readProof: ReadProof,\n source?: RowSource,\n maxAgeMs = 0,\n): Promise<Identity | undefined> {\n validPid(pid);\n const command = platform === \"darwin\" ? darwinCommand : windowsCommand;\n const parse = platform === \"darwin\" ? parseDarwinRows : parseWindowsRows;\n const read: RowSource =\n source ?? (async (pids, tree) => parse(await execute(command(pids[0] ?? pid, tree))));\n const rows = await read([pid], token, maxAgeMs);\n const before = rows.find((row) => row.pid === pid);\n if (!before || /^[ZX]/.test(before.state)) return undefined;\n if (!token) return before;\n const proof = await readProof(pid);\n const after = (await read([pid], false, maxAgeMs)).find((row) => row.pid === pid);\n if (\n !after ||\n after.start !== before.start ||\n after.group !== before.group ||\n /^[ZX]/.test(after.state)\n )\n return undefined;\n return {\n start: after.start,\n group: after.group,\n state: proof?.pid === pid && proof.gated ? \"T\" : after.state,\n rss: treeMemory(rows, pid),\n token: proof?.pid === pid ? proof.token : undefined,\n };\n}\n","import { mkdir, readFile, rmdir, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { ProcessLimits } from \"./types\";\n\nfunction mountedCgroup(membership: string): string | undefined {\n const mount = \"/sys/fs/cgroup\";\n const directory = path.resolve(mount, `.${membership}`);\n // A cgroup namespace can report ancestors using /../ components. Never\n // normalize those into writes outside the standard cgroup mount.\n return directory === mount || directory.startsWith(`${mount}/`) ? directory : undefined;\n}\n\nexport function validateLimits(limits: ProcessLimits, platform: string = process.platform): void {\n for (const [key, value] of Object.entries(limits)) {\n if (\n ![\"timeoutMs\", \"memoryBytes\", \"cpuSeconds\", \"virtualMemoryBytes\"].includes(key) ||\n !Number.isSafeInteger(value) ||\n value <= 0\n )\n throw new Error(`Invalid process limit: ${key}`);\n }\n if (platform !== \"linux\" && limits.virtualMemoryBytes !== undefined)\n throw new Error(\"virtualMemoryBytes is supported only on Linux\");\n if (platform === \"win32\" && limits.cpuSeconds !== undefined)\n throw new Error(\"cpuSeconds is supported only on POSIX platforms\");\n}\n\n/**\n * POSIX shell applies inherited limits. Linux stops here; macOS execs a gated guardian.\n * Flags/units: Apple's bash-3.2/builtins/ulimit.def and installed Bash manual.\n * https://github.com/apple-oss-distributions/bash/blob/main/bash-3.2/builtins/ulimit.def\n */\nexport function launcher(limits: ProcessLimits, platform: string = process.platform): string {\n const commands = [\"set -e\"];\n if (limits.cpuSeconds) commands.push(`ulimit -t ${limits.cpuSeconds}`);\n if (limits.virtualMemoryBytes)\n commands.push(`ulimit -v ${Math.ceil(limits.virtualMemoryBytes / 1024)}`);\n // Linux ignores RLIMIT_RSS; polling remains the fallback resident-memory cap.\n // Darwin's RLIMIT_DATA restricts heap growth, not total resident memory.\n if (limits.memoryBytes)\n commands.push(\n `ulimit -${platform === \"darwin\" ? \"d\" : \"m\"} ${Math.ceil(limits.memoryBytes / 1024)}`,\n );\n if (platform === \"linux\") commands.push('kill -STOP \"$$\"');\n commands.push('exec \"$@\"');\n return commands.join(\"\\n\");\n}\n\n/** https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html */\nexport async function attachCgroup(\n pid: number,\n token: string,\n limits: ProcessLimits,\n root?: string,\n): Promise<string | undefined> {\n if (process.platform !== \"linux\") return undefined;\n let directory: string | undefined;\n try {\n const own = (await readFile(\"/proc/self/cgroup\", \"utf8\"))\n .split(\"\\n\")\n .find((line) => line.startsWith(\"0::\"))\n ?.slice(3);\n if (!root && own === undefined) return undefined;\n const parent = root ?? mountedCgroup(own ?? \"/\");\n if (!parent) return undefined;\n // Do not enable controllers or move the app: delegation belongs to the service manager.\n await readFile(path.join(parent, \"cgroup.controllers\"), \"utf8\");\n directory = path.join(parent, `warlock-${token}`);\n await mkdir(directory);\n if (limits.memoryBytes) {\n await writeFile(path.join(directory, \"memory.max\"), String(limits.memoryBytes));\n await writeFile(path.join(directory, \"memory.oom.group\"), \"1\");\n }\n await writeFile(path.join(directory, \"cgroup.procs\"), String(pid));\n return directory;\n } catch {\n if (directory) await rmdir(directory).catch(() => undefined);\n return undefined;\n }\n}\n\nexport async function cgroupMemory(directory: string): Promise<{ peak: number; oom: boolean }> {\n const [peak, events] = await Promise.all([\n readFile(path.join(directory, \"memory.peak\"), \"utf8\").catch(() => \"0\"),\n readFile(path.join(directory, \"memory.events\"), \"utf8\").catch(() => \"\"),\n ]);\n return { peak: Number(peak) || 0, oom: Number(/^oom_kill (\\d+)/m.exec(events)?.[1] ?? 0) > 0 };\n}\n\n/** Only reattach the token-specific cgroup confirmed by the kernel membership file. */\nexport async function recoveredCgroup(pid: number, token: string): Promise<string | undefined> {\n if (process.platform !== \"linux\") return undefined;\n let source: string;\n try {\n source = await readFile(`/proc/${pid}/cgroup`, \"utf8\");\n } catch (error) {\n if ([\"ENOENT\", \"ESRCH\"].includes(String((error as NodeJS.ErrnoException).code)))\n return undefined;\n throw error;\n }\n const membership = source\n .split(\"\\n\")\n .find((line) => line.startsWith(\"0::\"))\n ?.slice(3);\n if (!membership || path.basename(membership) !== `warlock-${token}`) return undefined;\n return mountedCgroup(membership);\n}\n\nexport async function cleanCgroup(directory: string): Promise<void> {\n // This unique cgroup was created for this token, or recovered after identity proof.\n // cgroup.kill also covers descendants that created their own POSIX session.\n await writeFile(path.join(directory, \"cgroup.kill\"), \"1\").catch(() => undefined);\n await rmdir(directory).catch(() => undefined);\n}\n","import { createHmac, randomBytes } from \"node:crypto\";\nimport { connect } from \"node:net\";\nimport type { Command, OwnershipProof } from \"./platform\";\nimport { defaultObservationTimeoutMs } from \"./platform\";\nimport { launcher } from \"./resources\";\nimport type { ProcessLimits } from \"./types\";\n\nexport function guardianAddress(platform: string, pid: number, uid: number): string {\n return platform === \"win32\"\n ? `\\\\\\\\.\\\\pipe\\\\warlock-process-${pid}`\n : `/tmp/warlock-process-${uid}-${pid}.sock`;\n}\n\n/** A live guardian reads its own environment, never argv, to prove ownership.\n * Node IPC is native-free: https://nodejs.org/api/net.html#ipc-support\n * The stable root PID stays alive for the workload and survives supervisor restarts.\n */\nexport const guardianScript = String.raw`\nconst { createServer } = require(\"node:net\");\nconst { createHmac } = require(\"node:crypto\");\nconst { spawn } = require(\"node:child_process\");\nconst { chmodSync, unlinkSync } = require(\"node:fs\");\nconst token = process.env.WARLOCK_PROCESS_TOKEN;\nconst address = process.platform === \"win32\"\n ? \"\\\\\\\\.\\\\pipe\\\\warlock-process-\" + process.pid\n : \"/tmp/warlock-process-\" + process.getuid() + \"-\" + process.pid + \".sock\";\nlet gated = true;\nconst finish = (code) => { server.close(); process.exit(code); };\nconst launch = () => {\n const [command, ...args] = JSON.parse(process.env.WARLOCK_PROCESS_LAUNCH);\n const env = { ...process.env };\n for (const key of Object.keys(env)) {\n const name = process.platform === \"win32\" ? key.toUpperCase() : key;\n if (name === \"WARLOCK_PROCESS_TOKEN\" || name === \"WARLOCK_PROCESS_LAUNCH\") delete env[key];\n }\n const child = spawn(command, args, { env, stdio: \"inherit\", windowsHide: true });\n child.on(\"error\", (error) => { console.error(error.message); finish(127); });\n child.on(\"exit\", (code, signal) => {\n if (signal && process.platform !== \"win32\") process.kill(process.pid, signal);\n else finish(code ?? 1);\n });\n};\nconst server = createServer((socket) => {\n socket.setTimeout(2000, () => socket.destroy());\n socket.on(\"error\", () => {});\n let input = \"\";\n socket.on(\"data\", (chunk) => {\n input += chunk;\n if (input.length > 1024) { socket.destroy(); return; }\n if (!input.endsWith(\"\\n\")) return;\n try {\n const request = JSON.parse(input);\n if (!/^[a-f0-9]{64}$/.test(request.nonce)) { socket.destroy(); return; }\n const sign = (value) => createHmac(\"sha256\", token).update(value).digest(\"hex\");\n const resume = gated && request.resume === sign(request.nonce + \":resume\");\n // Reply first, then start the workload: a slow program start must never\n // eat into the client's observation timeout.\n if (resume) gated = false;\n socket.end(JSON.stringify({ pid: process.pid, digest: sign(request.nonce + \":\" + process.pid + \":\" + gated), gated }) + \"\\n\");\n if (resume) setImmediate(launch);\n } catch { socket.destroy(); }\n });\n});\nserver.on(\"error\", (error) => { console.error(error.message); process.exit(126); });\nif (process.platform !== \"win32\") {\n try { unlinkSync(address); } catch (error) { if (error.code !== \"ENOENT\") throw error; }\n process.on(\"exit\", () => { try { unlinkSync(address); } catch {} });\n}\nserver.listen(address, () => { if (process.platform !== \"win32\") chmodSync(address, 0o600); });\n`;\n\nexport async function guardianProof(\n pid: number,\n resume?: string,\n expectedToken: string | undefined = resume,\n timeoutMs: number = defaultObservationTimeoutMs(process.platform),\n): Promise<OwnershipProof | undefined> {\n if (!expectedToken) return undefined;\n const token = expectedToken;\n const nonce = randomBytes(32).toString(\"hex\");\n const sign = (value: string) => createHmac(\"sha256\", token).update(value).digest(\"hex\");\n const address = guardianAddress(process.platform, pid, process.getuid?.() ?? 0);\n return new Promise((resolve, reject) => {\n const socket = connect(address);\n let data = \"\";\n const fail = (error: Error) => {\n socket.destroy();\n reject(error);\n };\n socket.setTimeout(timeoutMs, () =>\n fail(\n new Error(\n `Process ownership observation timed out after ${timeoutMs} ms; raise the observationTimeoutMs supervisor option`,\n ),\n ),\n );\n socket.on(\"connect\", () =>\n socket.write(\n JSON.stringify({ nonce, resume: resume ? sign(nonce + \":resume\") : undefined }) + \"\\n\",\n ),\n );\n socket.on(\"data\", (chunk: Buffer) => {\n data += chunk.toString();\n if (data.length > 1024) fail(new Error(\"Invalid process ownership response\"));\n });\n socket.on(\"error\", (error: NodeJS.ErrnoException) => {\n if ([\"ENOENT\", \"ECONNREFUSED\", \"EPIPE\", \"ECONNRESET\"].includes(error.code ?? \"\"))\n resolve(undefined);\n else reject(error);\n });\n socket.on(\"end\", () => {\n // A guardian that is exiting closes the pipe without answering; that is no proof, not corrupt data.\n if (!data) {\n resolve(undefined);\n return;\n }\n try {\n resolve(parseGuardianProof(data, pid, nonce, token));\n } catch (error) {\n reject(error);\n }\n });\n });\n}\n\n/** Malformed observation is an error; an authenticated identity mismatch is unowned. */\nexport function parseGuardianProof(\n source: string,\n pid: number,\n nonce: string,\n token: string,\n): OwnershipProof | undefined {\n const proof: unknown = JSON.parse(source);\n if (\n !proof ||\n typeof proof !== \"object\" ||\n !(\"pid\" in proof) ||\n typeof proof.pid !== \"number\" ||\n !(\"gated\" in proof) ||\n typeof proof.gated !== \"boolean\" ||\n !(\"digest\" in proof) ||\n typeof proof.digest !== \"string\"\n )\n throw new Error(\"Invalid process ownership response\");\n const expected = createHmac(\"sha256\", token)\n .update(nonce + \":\" + pid + \":\" + proof.gated)\n .digest(\"hex\");\n if (proof.pid !== pid || proof.digest !== expected) return undefined;\n return { pid, token, gated: proof.gated };\n}\n\n/** Pure launch construction, including case-insensitive Windows environment keys. */\nexport function launchCommand(\n platform: string,\n node: string,\n command: string,\n args: string[],\n limits: ProcessLimits,\n environment: NodeJS.ProcessEnv,\n token: string,\n): Omit<Command, \"env\"> & { env: NodeJS.ProcessEnv } {\n const portable = platform !== \"linux\";\n const env: NodeJS.ProcessEnv = Object.fromEntries(\n Object.entries(environment).filter(\n ([key]) =>\n ![\"WARLOCK_PROCESS_TOKEN\", \"WARLOCK_PROCESS_LAUNCH\"].includes(\n platform === \"win32\" ? key.toUpperCase() : key,\n ),\n ),\n );\n env.WARLOCK_PROCESS_TOKEN = token;\n if (portable) env.WARLOCK_PROCESS_LAUNCH = JSON.stringify([command, ...args]);\n const executable = portable ? node : command;\n const arguments_ = portable ? [\"-e\", guardianScript] : args;\n return {\n file: platform === \"win32\" ? executable : \"/bin/sh\",\n args:\n platform === \"win32\"\n ? arguments_\n : [\"-c\", launcher(limits, platform), \"warlock-process\", executable, ...arguments_],\n env,\n };\n}\n","import { execFile } from \"node:child_process\";\nimport { readFile } from \"node:fs/promises\";\nimport { promisify } from \"node:util\";\n\nimport { guardianProof } from \"./guardian\";\nimport { defaultObservationTimeoutMs, portableIdentity, type Command } from \"./platform\";\nimport type { WindowsProcessHelper } from \"./windows-helper\";\n\nconst execute = promisify(execFile);\nexport async function executeCommand(command: Command): Promise<string> {\n const { stdout } = await execute(command.file, command.args, {\n env: { ...process.env, ...command.env },\n timeout: 5000,\n maxBuffer: 4 * 1024 * 1024,\n windowsHide: true,\n });\n return stdout;\n}\n/** How a supervisor observes processes off Linux. Linux ignores all of it. */\nexport type Observation = {\n /** Longest wait for a guardian reply or a helper answer. */\n timeoutMs?: number;\n /** Long-lived Windows helper; without it each observation runs PowerShell once. */\n helper?: WindowsProcessHelper;\n /** Accept a process-table snapshot this old (polling only, never before a signal). */\n maxAgeMs?: number;\n};\nexport const TOKEN_ENV = \"WARLOCK_PROCESS_TOKEN\";\nexport type Identity = { start: string; group: number; state: string; rss: number; token?: string };\n\nfunction statFields(stat: string): string[] {\n return stat\n .slice(stat.lastIndexOf(\")\") + 2)\n .trim()\n .split(/\\s+/);\n}\n\n/**\n * A task that is exiting has already released its memory map (stat field 23,\n * vsize, reads 0) before it turns into a zombie. Linux then reports its /proc\n * files as root-owned, so it is never a live child to verify or signal.\n */\nfunction exiting(fields: string[]): boolean {\n return [\"Z\", \"X\"].includes(fields[0] ?? \"\") || fields[20] === \"0\";\n}\n\n/** /proc fields: https://man7.org/linux/man-pages/man5/proc_pid_stat.5.html */\nexport async function identity(\n pid: number,\n token = false,\n expectedToken?: string,\n observation: Observation = {},\n): Promise<Identity | undefined> {\n if (!Number.isSafeInteger(pid) || pid <= 1) return undefined;\n try {\n if (process.platform === \"linux\") {\n const stat = await readFile(`/proc/${pid}/stat`, \"utf8\");\n const fields = statFields(stat);\n const state = fields[0];\n const start = fields[19];\n if (!state || !start || exiting(fields)) return undefined;\n const boot = (await readFile(\"/proc/sys/kernel/random/boot_id\", \"utf8\")).trim();\n const status = await readFile(`/proc/${pid}/status`, \"utf8\");\n let environment = \"\";\n if (token) {\n try {\n environment = await readFile(`/proc/${pid}/environ`, \"utf8\");\n } catch (error) {\n // Without root, the environment of a task that started exiting after\n // the first stat read is unreadable. Only that case counts as gone;\n // any other unreadable environment still fails closed.\n if ((error as { code?: unknown }).code !== \"EACCES\") throw error;\n const now = statFields(await readFile(`/proc/${pid}/stat`, \"utf8\"));\n if (now[19] !== start || exiting(now)) return undefined;\n throw error;\n }\n }\n // /proc reads are separate operations. Reject PID reuse or a group change\n // during observation before combining a token with a start identity.\n const after = statFields(await readFile(`/proc/${pid}/stat`, \"utf8\"));\n if (after[19] !== start || after[2] !== fields[2] || exiting(after)) return undefined;\n return {\n start: `${boot}:${start}`,\n group: Number(fields[2]),\n state: after[0] ?? state,\n rss: Number(/^VmRSS:\\s+(\\d+)/m.exec(status)?.[1] ?? 0) * 1024,\n token: environment\n .split(\"\\0\")\n .find((entry) => entry.startsWith(`${TOKEN_ENV}=`))\n ?.slice(TOKEN_ENV.length + 1),\n };\n }\n if (process.platform === \"darwin\" || process.platform === \"win32\") {\n const { helper } = observation;\n return await portableIdentity(\n process.platform,\n pid,\n token,\n executeCommand,\n (selected) =>\n guardianProof(\n selected,\n undefined,\n expectedToken,\n observation.timeoutMs ?? defaultObservationTimeoutMs(process.platform),\n ),\n process.platform === \"win32\" && helper\n ? (pids, tree, maxAgeMs) => helper.query(pids, tree, maxAgeMs)\n : undefined,\n observation.maxAgeMs,\n );\n }\n return undefined;\n } catch (error) {\n const code = (error as { code?: unknown }).code;\n if (\n (process.platform === \"linux\" && [\"ENOENT\", \"ESRCH\"].includes(String(code))) ||\n (process.platform === \"darwin\" &&\n code === 1 &&\n !(error as { stdout?: string }).stdout?.trim())\n )\n return undefined;\n throw error;\n }\n}\n\nexport class ProcessNotOwnedError extends Error {\n constructor(public readonly pid: number) {\n super(`Process ${pid} does not have a verified supervisor identity`);\n this.name = \"ProcessNotOwnedError\";\n }\n}\n\nexport async function owns(\n entry: { pid: number; start: string; token: string },\n observation?: Observation,\n): Promise<boolean> {\n const current = await identity(entry.pid, true, entry.token, observation);\n return (\n current?.start === entry.start && current.token === entry.token && current.group === entry.pid\n );\n}\n","import { randomBytes } from \"node:crypto\";\nimport { mkdir, readFile, rename, rm, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { identity } from \"./identity\";\nimport type { ProcessInfo } from \"./types\";\n\nexport type RegistryEntry = ProcessInfo & {\n token: string;\n start: string;\n cgroup?: string;\n /** Persisted launch gate: recovery may resume an adopted, interrupted launch. */\n gated?: boolean;\n};\n\nfunction record(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\nfunction strings(value: unknown): value is Record<string, string> {\n return record(value) && Object.values(value).every((item) => typeof item === \"string\");\n}\nexport function parseRegistry(source: string, owner: string): RegistryEntry[] {\n const value: unknown = JSON.parse(source);\n if (\n !record(value) ||\n value.version !== 1 ||\n value.owner !== owner ||\n !Array.isArray(value.entries)\n )\n throw new Error(\"Invalid process registry or different owner\");\n const entries: RegistryEntry[] = [];\n for (const entry of value.entries) {\n if (\n !record(entry) ||\n entry.owner !== owner ||\n typeof entry.pid !== \"number\" ||\n !Number.isSafeInteger(entry.pid) ||\n Number(entry.pid) <= 1 ||\n typeof entry.token !== \"string\" ||\n !/^[a-f0-9]{64}$/.test(entry.token) ||\n typeof entry.start !== \"string\" ||\n typeof entry.type !== \"string\" ||\n typeof entry.command !== \"string\" ||\n !Array.isArray(entry.args) ||\n !entry.args.every((arg) => typeof arg === \"string\") ||\n !strings(entry.labels) ||\n typeof entry.startedAt !== \"number\" ||\n !Number.isFinite(entry.startedAt) ||\n entry.startedAt < 0 ||\n !record(entry.limits) ||\n !Object.entries(entry.limits).every(\n ([key, limit]) =>\n [\"timeoutMs\", \"memoryBytes\", \"cpuSeconds\", \"virtualMemoryBytes\"].includes(key) &&\n typeof limit === \"number\" &&\n Number.isSafeInteger(limit) &&\n limit > 0,\n ) ||\n ![\"cgroup-v2\", \"rlimit-polling\", \"rss-polling\"].includes(String(entry.enforcement)) ||\n typeof entry.peakMemoryBytes !== \"number\" ||\n !Number.isFinite(entry.peakMemoryBytes) ||\n entry.peakMemoryBytes < 0 ||\n (entry.cgroup !== undefined && typeof entry.cgroup !== \"string\") ||\n (entry.gated !== undefined && typeof entry.gated !== \"boolean\")\n )\n throw new Error(\"Invalid process registry entry\");\n entries.push(entry as RegistryEntry);\n }\n if (new Set(entries.map((entry) => entry.pid)).size !== entries.length)\n throw new Error(\"Duplicate registry PID\");\n return entries;\n}\n\n/** One writer per registry. A crash leaves a lease which only a dead identity can release. */\nexport class Registry {\n private queue: Promise<void> = Promise.resolve();\n private locked = false;\n constructor(\n public readonly file: string,\n private readonly owner: string,\n private readonly read: (pid: number) => ReturnType<typeof identity> = (pid) => identity(pid),\n ) {}\n async open(): Promise<RegistryEntry[]> {\n await mkdir(path.dirname(this.file), { recursive: true, mode: 0o700 });\n const self = await this.read(process.pid);\n if (!self) throw new Error(\"Cannot verify registry writer identity\");\n const lock = `${this.file}.lock`;\n try {\n await mkdir(lock, { mode: 0o700 });\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"EEXIST\") throw error;\n const reclaim = `${lock}.reclaim`;\n await mkdir(reclaim, { mode: 0o700 });\n try {\n const lease: unknown = JSON.parse(await readFile(path.join(lock, \"writer.json\"), \"utf8\"));\n if (!record(lease) || typeof lease.pid !== \"number\" || typeof lease.start !== \"string\")\n throw new Error(\"Invalid registry writer lease; inspect it manually\");\n const writer = await this.read(lease.pid);\n if (writer?.start === lease.start) throw new Error(\"Process registry is already in use\");\n const stale = `${lock}.${randomBytes(8).toString(\"hex\")}`;\n await rename(lock, stale);\n await rm(stale, { recursive: true });\n await mkdir(lock, { mode: 0o700 });\n } finally {\n await rm(reclaim, { recursive: true });\n }\n }\n this.locked = true;\n try {\n await writeFile(\n path.join(lock, \"writer.json\"),\n JSON.stringify({ pid: process.pid, start: self.start }),\n { mode: 0o600 },\n );\n try {\n return parseRegistry(await readFile(this.file, \"utf8\"), this.owner);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\") return [];\n throw error;\n }\n } catch (error) {\n await this.close();\n throw error;\n }\n }\n save(entries: RegistryEntry[]): Promise<void> {\n const source = JSON.stringify({ version: 1, owner: this.owner, entries }, null, 2) + \"\\n\";\n const next = this.queue.then(async () => {\n const temporary = `${this.file}.${randomBytes(8).toString(\"hex\")}.tmp`;\n try {\n await writeFile(temporary, source, { mode: 0o600, flag: \"wx\" });\n await rename(temporary, this.file);\n } finally {\n await rm(temporary, { force: true });\n }\n });\n this.queue = next.catch(() => undefined);\n return next;\n }\n async close(): Promise<void> {\n await this.queue;\n if (this.locked) {\n await rm(`${this.file}.lock`, { recursive: true });\n this.locked = false;\n }\n }\n}\n","import { spawn as spawnChild } from \"node:child_process\";\nimport type { Readable, Writable } from \"node:stream\";\nimport { windowsRows, type Row } from \"./platform\";\n\n/**\n * One long-lived PowerShell per supervisor answers batched process queries over\n * stdin/stdout, one JSON object per line:\n *\n * request {\"id\":1,\"pids\":[42,43],\"all\":false}\n * response {\"id\":1,\"rows\":[{\"pid\":42,\"parent\":4,\"start\":\"638...\",\"rss\":1024}]}\n * failure {\"id\":1,\"error\":\"message\"}\n *\n * `all: true` returns the whole process table (needed to sum a process tree).\n * Starting PowerShell costs about a second on Windows; paying that once instead\n * of twice per observation is what keeps a busy machine responsive.\n */\nexport const helperScript = [\n \"$ErrorActionPreference = 'Stop'\",\n \"[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding($false)\",\n \"$reader = [Console]::In\",\n \"while ($null -ne ($line = $reader.ReadLine())) {\",\n \" $id = 0\",\n \" try {\",\n \" $request = $line | ConvertFrom-Json\",\n \" $id = [int]$request.id\",\n \" $wanted = @($request.pids | ForEach-Object { [int]$_ })\",\n \" if ($request.all) { $found = @(Get-CimInstance Win32_Process) }\",\n \" elseif ($wanted.Count -eq 0) { $found = @() }\",\n \" else { $found = @(Get-CimInstance Win32_Process -Filter (($wanted | ForEach-Object { 'ProcessId=' + $_ }) -join ' OR ')) }\",\n \" $rows = @($found | ForEach-Object {\",\n \" if ($wanted -contains [int]$_.ProcessId -and $null -eq $_.CreationDate) { throw 'Cannot read process creation time' }\",\n \" if ($null -ne $_.CreationDate) {\",\n \" [pscustomobject]@{ pid = [int]$_.ProcessId; parent = [int]$_.ParentProcessId; start = $_.CreationDate.ToUniversalTime().Ticks.ToString([Globalization.CultureInfo]::InvariantCulture); rss = [double]$_.WorkingSetSize }\",\n \" }\",\n \" })\",\n \" $reply = ConvertTo-Json -InputObject @{ id = $id; rows = $rows } -Compress -Depth 4\",\n \" } catch {\",\n \" $reply = ConvertTo-Json -InputObject @{ id = $id; error = [string]$_.Exception.Message } -Compress\",\n \" }\",\n \" [Console]::Out.WriteLine($reply)\",\n \" [Console]::Out.Flush()\",\n \"}\",\n].join(\"\\n\");\n\n/** The subset of ChildProcess the helper uses; tests inject a fake. */\nexport type HelperChild = {\n pid?: number;\n stdin: Writable;\n stdout: Readable;\n on(event: \"exit\" | \"error\", listener: () => void): unknown;\n kill(): unknown;\n unref?(): void;\n};\nexport type HelperSpawn = (file: string, args: string[]) => HelperChild;\n\nexport function defaultHelperSpawn(file: string, args: string[]): HelperChild {\n const child = spawnChild(file, args, { stdio: [\"pipe\", \"pipe\", \"ignore\"], windowsHide: true });\n // The helper must never keep the host process alive; stopAll() closes it.\n child.unref();\n (child.stdin as unknown as { unref?(): void }).unref?.();\n (child.stdout as unknown as { unref?(): void }).unref?.();\n return child;\n}\n\nexport function helperArguments(): string[] {\n return [\n \"-NoLogo\",\n \"-NoProfile\",\n \"-NonInteractive\",\n \"-EncodedCommand\",\n Buffer.from(helperScript, \"utf16le\").toString(\"base64\"),\n ];\n}\n\nexport type WindowsHelperOptions = {\n spawn?: HelperSpawn;\n /** Longest wait for one response, including PowerShell's own start-up. */\n timeoutMs?: number;\n now?: () => number;\n};\n\ntype Waiter = { resolve(rows: Row[]): void; reject(error: unknown): void; pids: number[] };\ntype Batch = { pids: Set<number>; all: boolean; waiters: Waiter[] };\ntype Flight = {\n id: number;\n pids: number[];\n all: boolean;\n waiters: Waiter[];\n attempts: number;\n timer?: ReturnType<typeof setTimeout>;\n};\ntype Snapshot = { at: number; all: boolean; pids: Set<number>; rows: Row[] };\n\nexport class WindowsProcessHelper {\n private child: HelperChild | undefined;\n private buffer = \"\";\n private flight: Flight | undefined;\n private batch: Batch | undefined;\n private scheduled = false;\n private nextId = 1;\n private closed = false;\n private last: Snapshot | undefined;\n /** Number of PowerShell processes started; a restart shows up here. */\n starts = 0;\n /** Number of requests written to the helper. */\n requests = 0;\n private readonly spawn: HelperSpawn;\n private readonly timeoutMs: number;\n private readonly now: () => number;\n\n constructor(options: WindowsHelperOptions = {}) {\n this.spawn = options.spawn ?? defaultHelperSpawn;\n this.timeoutMs = options.timeoutMs ?? 15_000;\n this.now = options.now ?? Date.now;\n }\n\n /**\n * Rows for the given PIDs, or the whole table with `all`. Calls made while a\n * request is in flight share the next request, so N concurrent observations\n * cost one query. `maxAgeMs` accepts a snapshot at most that old.\n */\n query(pids: number[], all = false, maxAgeMs = 0): Promise<Row[]> {\n if (this.closed) return Promise.reject(new Error(\"Windows process helper is closed\"));\n const cached = this.last;\n if (\n maxAgeMs > 0 &&\n cached &&\n this.now() - cached.at <= maxAgeMs &&\n (cached.all || (!all && pids.every((pid) => cached.pids.has(pid))))\n )\n return Promise.resolve(cached.rows);\n return new Promise<Row[]>((resolve, reject) => {\n const batch = (this.batch ??= { pids: new Set(), all: false, waiters: [] });\n for (const pid of pids) batch.pids.add(pid);\n batch.all ||= all;\n batch.waiters.push({ resolve, reject, pids });\n this.schedule();\n });\n }\n\n /** Stops the helper; pending queries reject. Safe to call twice. */\n async close(): Promise<void> {\n this.closed = true;\n const error = new Error(\"Windows process helper is closed\");\n this.failAll(error);\n this.discard();\n }\n\n private schedule(): void {\n if (this.flight || this.scheduled) return;\n this.scheduled = true;\n // Let observations started in the same tick join one request.\n setImmediate(() => {\n this.scheduled = false;\n this.dispatch();\n });\n }\n\n private dispatch(): void {\n if (this.flight || !this.batch) return;\n const batch = this.batch;\n this.batch = undefined;\n this.flight = {\n id: this.nextId++,\n pids: [...batch.pids],\n all: batch.all,\n waiters: batch.waiters,\n attempts: 0,\n };\n this.send(this.flight);\n }\n\n private send(flight: Flight): void {\n flight.attempts += 1;\n try {\n const child = this.ensure();\n this.requests += 1;\n child.stdin.write(\n JSON.stringify({ id: flight.id, pids: flight.pids, all: flight.all }) + \"\\n\",\n );\n } catch (error) {\n this.retryOrFail(flight, error);\n return;\n }\n clearTimeout(flight.timer);\n flight.timer = setTimeout(() => {\n // A wedged helper is replaced, never trusted for the next request.\n this.discard();\n this.retryOrFail(\n flight,\n new Error(\n `Windows process helper did not answer within ${this.timeoutMs} ms; raise the observationTimeoutMs supervisor option`,\n ),\n );\n }, this.timeoutMs);\n flight.timer.unref?.();\n }\n\n private ensure(): HelperChild {\n if (this.child) return this.child;\n const child = this.spawn(\"powershell.exe\", helperArguments());\n this.starts += 1;\n this.child = child;\n this.buffer = \"\";\n child.stdout.setEncoding?.(\"utf8\");\n child.stdout.on(\"data\", (chunk: string | Buffer) => {\n if (this.child !== child) return;\n this.buffer += chunk.toString();\n let newline = this.buffer.indexOf(\"\\n\");\n while (newline >= 0) {\n const line = this.buffer.slice(0, newline).replace(/^/, \"\").trim();\n this.buffer = this.buffer.slice(newline + 1);\n if (line) this.receive(line);\n newline = this.buffer.indexOf(\"\\n\");\n }\n });\n child.stdin.on(\"error\", () => undefined);\n const died = () => {\n if (this.child !== child) return;\n this.child = undefined;\n const flight = this.flight;\n if (flight) this.retryOrFail(flight, new Error(\"Windows process helper exited unexpectedly\"));\n };\n child.on(\"exit\", died);\n child.on(\"error\", died);\n return child;\n }\n\n private receive(line: string): void {\n const flight = this.flight;\n if (!flight) return;\n let reply: { id?: unknown; rows?: unknown; error?: unknown };\n try {\n reply = JSON.parse(line) as typeof reply;\n } catch {\n return; // Banner or stray output; only well-formed replies count.\n }\n if (reply.id !== flight.id) return;\n clearTimeout(flight.timer);\n this.flight = undefined;\n try {\n if (typeof reply.error === \"string\") throw new Error(reply.error);\n const rows = windowsRows(reply.rows);\n this.last = {\n at: this.now(),\n all: flight.all,\n pids: new Set(flight.pids),\n rows,\n };\n for (const waiter of flight.waiters) waiter.resolve(rows);\n } catch (error) {\n for (const waiter of flight.waiters) waiter.reject(error);\n }\n if (this.batch) this.schedule();\n }\n\n /** One automatic retry on a fresh helper; queries are read-only, so repeating is safe. */\n private retryOrFail(flight: Flight, error: unknown): void {\n clearTimeout(flight.timer);\n if (this.closed || flight.attempts >= 2) {\n if (this.flight === flight) this.flight = undefined;\n for (const waiter of flight.waiters) waiter.reject(error);\n if (this.batch && !this.closed) this.schedule();\n return;\n }\n this.discard();\n this.send(flight);\n }\n\n private failAll(error: unknown): void {\n const flight = this.flight;\n this.flight = undefined;\n clearTimeout(flight?.timer);\n const batch = this.batch;\n this.batch = undefined;\n for (const waiter of [...(flight?.waiters ?? []), ...(batch?.waiters ?? [])])\n waiter.reject(error);\n }\n\n private discard(): void {\n const child = this.child;\n this.child = undefined;\n this.last = undefined;\n if (!child) return;\n try {\n child.stdin.end();\n } catch {\n /* Already closed. */\n }\n try {\n child.kill();\n } catch {\n /* Already gone. */\n }\n }\n}\n\nexport function createWindowsHelper(options: WindowsHelperOptions = {}): WindowsProcessHelper {\n return new WindowsProcessHelper(options);\n}\n","import { spawn as spawnChild } from \"node:child_process\";\nimport { randomBytes } from \"node:crypto\";\nimport path from \"node:path\";\nimport { PassThrough, Writable } from \"node:stream\";\nimport { setTimeout as delay } from \"node:timers/promises\";\nimport { identity, owns, ProcessNotOwnedError, executeCommand, type Observation } from \"./identity\";\nimport { guardianProof, launchCommand } from \"./guardian\";\nimport {\n defaultObservationTimeoutMs,\n defaultPollIntervalMs,\n supported,\n taskkillCommand,\n} from \"./platform\";\nimport { Registry, type RegistryEntry } from \"./registry\";\nimport { createWindowsHelper, type WindowsProcessHelper } from \"./windows-helper\";\nimport {\n attachCgroup,\n cgroupMemory,\n cleanCgroup,\n recoveredCgroup,\n validateLimits,\n} from \"./resources\";\nimport type {\n ProcessExit,\n ProcessFilter,\n ProcessHandle,\n ProcessInfo,\n ProcessSupervisor,\n PtyHandle,\n RecoveryResult,\n SpawnOptions,\n SupervisorOptions,\n} from \"./types\";\n\ntype Pty = {\n pid: number;\n onData(listener: (data: string) => void): { dispose(): void };\n onExit(listener: (event: { exitCode: number; signal?: number }) => void): { dispose(): void };\n write(data: string): void;\n resize(columns: number, rows: number): void;\n};\ntype PtyModule = {\n spawn(\n command: string,\n args: string[],\n options: {\n cwd?: string;\n env: Record<string, string>;\n cols: number;\n rows: number;\n name: string;\n },\n ): Pty;\n};\ntype Active = {\n entry: RegistryEntry;\n handle: ProcessHandle;\n reason?: ProcessExit[\"reason\"];\n finish(code: number | null, signal: string | null): Promise<void>;\n stopping?: Promise<void>;\n timer?: ReturnType<typeof setInterval>;\n finished: boolean;\n adopted: boolean;\n fail(error: unknown): void;\n};\n\nfunction info(entry: RegistryEntry): ProcessInfo {\n const { token: _token, start: _start, cgroup: _cgroup, gated: _gated, ...visible } = entry;\n return structuredClone(visible);\n}\nfunction validateFilter(filter: ProcessFilter): void {\n if (\n !filter ||\n typeof filter !== \"object\" ||\n Array.isArray(filter) ||\n Object.keys(filter).some((key) => key !== \"labels\")\n )\n throw new Error(\"Only label filters are supported\");\n if (\n filter.labels !== undefined &&\n (filter.labels === null ||\n typeof filter.labels !== \"object\" ||\n Array.isArray(filter.labels) ||\n !Object.values(filter.labels).every((value) => typeof value === \"string\"))\n )\n throw new Error(\"Labels must be string key/value pairs\");\n}\nfunction matches(entry: RegistryEntry, filter: ProcessFilter): boolean {\n return Object.entries(filter.labels ?? {}).every(([key, value]) => entry.labels[key] === value);\n}\n\nexport function supervisor(options: SupervisorOptions): ProcessSupervisor {\n for (const option of [\"owner\", \"registry\"] as const) {\n if (!options || typeof options[option] !== \"string\" || !options[option].trim()) {\n throw new TypeError(`Invalid supervisor configuration: ${option} must be a nonempty string`);\n }\n }\n validateLimits(options.defaults ?? {});\n // Caller-owned configuration must not change an active supervisor's identity.\n options = { ...options, defaults: { ...options.defaults } };\n const pollMs = options.pollIntervalMs ?? defaultPollIntervalMs(process.platform);\n const graceMs = options.stopGraceMs ?? 1000;\n if (!Number.isSafeInteger(pollMs) || pollMs < 10 || !Number.isSafeInteger(graceMs) || graceMs < 0)\n throw new Error(\"Invalid polling interval or stop grace period\");\n const registryPath = path.resolve(options.registry);\n // `warlock dev` can evaluate this module more than once in one process. A second supervisor over\n // the same registry would find its own process holding the lock, so reuse the live one.\n const sameProcess = sameProcessSupervisors();\n const live = sameProcess.get(registryPath);\n if (live && live.owner === options.owner) return live.api;\n const observationMs =\n options.observationTimeoutMs ?? defaultObservationTimeoutMs(process.platform);\n if (!Number.isSafeInteger(observationMs) || observationMs < 100)\n throw new Error(\"Invalid observationTimeoutMs: expected an integer of at least 100\");\n // One helper per supervisor, created on first use and closed by stopAll().\n let helper: WindowsProcessHelper | undefined;\n function observe(): Observation {\n if (process.platform === \"win32\") helper ??= createWindowsHelper({ timeoutMs: observationMs });\n return { timeoutMs: observationMs, helper };\n }\n /** Polling tolerates a snapshot up to one interval old; signals never do. */\n function polling(): Observation {\n return { ...observe(), maxAgeMs: pollMs };\n }\n /**\n * Registry lease checks read identities too. Off Linux they go through the shared\n * helper, and a transient failure (an exiting process reports no creation time) is\n * retried instead of failing the whole operation.\n */\n async function lease(pid: number) {\n for (let attempt = 1; ; attempt++) {\n try {\n return await identity(pid, false, undefined, observe());\n } catch (error) {\n if (process.platform === \"linux\" || attempt >= 3) throw error;\n await delay(200);\n }\n }\n }\n const registry = new Registry(registryPath, options.owner, lease);\n const entries = new Map<number, RegistryEntry>();\n const active = new Map<number, Active>();\n let ready: Promise<void> | undefined;\n let closing = false;\n let shutdown: Promise<void> | undefined;\n // Serialize public operations, including shutdown, so a gated spawn cannot escape stopAll.\n let queue: Promise<unknown> = Promise.resolve();\n function serial<T>(operation: () => Promise<T>): Promise<T> {\n const next = queue.then(operation);\n queue = next.catch(() => undefined);\n return next;\n }\n async function open(): Promise<void> {\n supported(process.platform);\n if (closing) throw new Error(\"Supervisor has shut down\");\n ready ??= registry.open().then((saved) => {\n for (const entry of saved) {\n delete entry.cgroup;\n entries.set(entry.pid, entry);\n }\n });\n await ready;\n }\n const save = () => registry.save([...entries.values()]);\n\n async function signal(entry: RegistryEntry, value: NodeJS.Signals): Promise<void> {\n if (!(await owns(entry, observe()))) throw new ProcessNotOwnedError(entry.pid);\n if (process.platform !== \"linux\" && value === \"SIGCONT\") {\n const proof = await guardianProof(entry.pid, entry.token, entry.token, observationMs);\n if (!proof || proof.token !== entry.token || proof.gated)\n throw new ProcessNotOwnedError(entry.pid);\n return;\n }\n if (process.platform === \"win32\") {\n try {\n await executeCommand(taskkillCommand(entry.pid));\n } catch (error) {\n if (await owns(entry, observe())) throw error;\n }\n return;\n }\n // Negative PID targets only the session/group established for this child.\n // Recheck for every signal, including escalation; never match a command line.\n try {\n process.kill(-entry.pid, value);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ESRCH\") throw error;\n }\n }\n /**\n * A process that is exiting can still be listed for a moment after its guardian\n * (and so its token) is gone. Read fresh a few times; only a process that has\n * disappeared counts as gone, and a live one keeps its not-owned failure.\n */\n async function gone(pid: number): Promise<boolean> {\n for (let attempt = 0; attempt < 5; attempt++) {\n if (!(await identity(pid, false, undefined, observe()))) return true;\n await delay(100);\n }\n return false;\n }\n /**\n * Right after SIGCONT the launcher is replacing itself with the workload\n * (exec). For that instant the kernel reports an empty memory map and\n * environment, so a live, owned process momentarily fails verification. A\n * handle returned by launch() must always be stoppable, so wait that window\n * out; a process that stays unverified is still refused.\n */\n async function ownsSettled(entry: RegistryEntry): Promise<boolean> {\n for (let attempt = 0; attempt < 25; attempt++) {\n if (await owns(entry, observe())) return true;\n await delay(20);\n }\n return false;\n }\n async function stopEntry(\n entry: RegistryEntry,\n reason: ProcessExit[\"reason\"] = \"stopped\",\n ): Promise<void> {\n const tracked = active.get(entry.pid);\n let running: Active;\n if (!tracked) {\n if (!(await owns(entry, observe()))) throw new ProcessNotOwnedError(entry.pid);\n entry.cgroup = await recoveredCgroup(entry.pid, entry.token);\n running = track(entry);\n } else running = tracked;\n if (running.finished) return running.finish(null, null);\n if (running.stopping) return running.stopping;\n const stopping = (async () => {\n if (!(await ownsSettled(entry))) throw new ProcessNotOwnedError(entry.pid);\n running.reason ??= reason;\n await signal(entry, \"SIGTERM\");\n const deadline = Date.now() + graceMs;\n while (await owns(entry, observe())) {\n if (Date.now() >= deadline) {\n await signal(entry, \"SIGKILL\");\n break;\n }\n await delay(20);\n }\n const killedDeadline = Date.now() + 5000;\n while (await owns(entry, observe())) {\n if (Date.now() >= killedDeadline)\n throw new Error(`Process ${entry.pid} did not exit after SIGKILL`);\n await delay(20);\n }\n await running.finish(null, null);\n })();\n running.stopping = stopping;\n try {\n await stopping;\n } catch (error) {\n running.stopping = undefined;\n // The leader may exit between identity verification and a signal. A\n // missing identity is harmless for a tracked handle; a live mismatch is\n // still an ownership failure and must never receive another signal.\n if (error instanceof ProcessNotOwnedError && (await gone(entry.pid))) {\n await running.finish(null, null);\n return;\n }\n throw error;\n }\n }\n\n function track(\n entry: RegistryEntry,\n streams?: Pick<ProcessHandle, \"stdin\" | \"stdout\" | \"stderr\">,\n ): Active {\n let resolveExit: (exit: ProcessExit) => void = () => undefined;\n let rejectExit: (error: unknown) => void = () => undefined;\n const exited = new Promise<ProcessExit>((resolve, reject) => {\n resolveExit = resolve;\n rejectExit = reject;\n });\n // A rejected persistence operation is still observable through handle.exited.\n void exited.catch(() => undefined);\n const stdout = streams?.stdout ?? new PassThrough();\n const stderr = streams?.stderr ?? new PassThrough();\n const stdin = streams?.stdin ?? new PassThrough();\n let finishing: Promise<void> | undefined;\n const running: Active = {\n entry,\n finished: false,\n adopted: !streams,\n fail: (error) => rejectExit(error),\n handle: {\n pid: entry.pid,\n stdout,\n stderr,\n stdin,\n exited,\n stop: () =>\n serial(async () => {\n if (!running.finished) await stopEntry(entry);\n }),\n },\n finish(code, sig) {\n finishing ??= (async () => {\n running.finished = true;\n clearInterval(running.timer);\n if (entry.cgroup) {\n const memory = await cgroupMemory(entry.cgroup);\n entry.peakMemoryBytes = Math.max(entry.peakMemoryBytes, memory.peak);\n if (memory.oom) running.reason = \"memory-cap\";\n await cleanCgroup(entry.cgroup);\n }\n active.delete(entry.pid);\n entries.delete(entry.pid);\n try {\n await save();\n resolveExit({\n reason: running.reason ?? \"exit\",\n code,\n signal: sig,\n peakMemoryBytes: entry.peakMemoryBytes,\n });\n } catch (error) {\n rejectExit(error);\n throw error;\n }\n if (!streams) {\n (stdout as PassThrough).end();\n (stderr as PassThrough).end();\n stdin.end();\n }\n })();\n return finishing;\n },\n };\n active.set(entry.pid, running);\n return running;\n }\n\n function monitor(running: Active): void {\n if (running.finished) return;\n let sampling = false;\n const sample = async () => {\n if (sampling || running.finished) return;\n sampling = true;\n try {\n const entry = running.entry;\n let current = await identity(entry.pid, true, entry.token, polling());\n const matches = (value: typeof current) =>\n value?.start === entry.start && value.token === entry.token && value.group === entry.pid;\n // A snapshot taken while the process was exiting can still list it after\n // its guardian is gone. Before calling a mismatch a failure, read fresh\n // (no snapshot) a few times; a process that vanished simply exited.\n for (let attempt = 0; current && !matches(current) && attempt < 3; attempt++) {\n if (running.finished) return;\n await delay(50);\n current = await identity(entry.pid, true, entry.token, observe());\n }\n if (running.finished) return;\n if (\n current?.start !== entry.start ||\n current.token !== entry.token ||\n current.group !== entry.pid\n ) {\n if (!current) {\n if (running.adopted) await running.finish(null, null);\n } else {\n // A live child that changes its environment or group can no longer\n // be supervised safely. Preserve the entry and surface the failure.\n throw new ProcessNotOwnedError(entry.pid);\n }\n return;\n }\n entry.peakMemoryBytes = Math.max(entry.peakMemoryBytes, current.rss);\n if (entry.cgroup) {\n const memory = await cgroupMemory(entry.cgroup);\n if (running.finished) return;\n entry.peakMemoryBytes = Math.max(entry.peakMemoryBytes, memory.peak);\n if (memory.oom) running.reason = \"memory-cap\";\n }\n if (entry.limits.memoryBytes && entry.peakMemoryBytes > entry.limits.memoryBytes)\n await stopEntry(entry, \"memory-cap\");\n else if (entry.limits.timeoutMs && Date.now() - entry.startedAt >= entry.limits.timeoutMs)\n await stopEntry(entry, \"timeout\");\n } finally {\n sampling = false;\n }\n };\n running.timer = setInterval(() => {\n void sample().catch((error: unknown) => {\n // Never signal on an observation error. Surface it to the caller and keep the registry.\n clearInterval(running.timer);\n if (!running.finished) running.fail(error);\n });\n }, pollMs);\n running.timer.unref();\n }\n\n async function launch(\n input: SpawnOptions & { columns?: number; rows?: number },\n terminal: boolean,\n ): Promise<ProcessHandle | PtyHandle> {\n await open();\n if ([...entries.keys()].some((pid) => !active.has(pid)))\n throw new Error(\"Call recover() before spawning with an existing registry\");\n if (\n typeof input.command !== \"string\" ||\n !input.command ||\n typeof input.kind !== \"string\" ||\n !input.kind\n )\n throw new Error(\"kind and command are required\");\n validateFilter({ labels: input.labels });\n if (\n terminal &&\n [input.columns ?? 80, input.rows ?? 24].some(\n (size) => !Number.isSafeInteger(size) || size <= 0,\n )\n )\n throw new Error(\"Terminal dimensions must be positive safe integers\");\n const limits = { ...options.defaults, ...input.limits };\n validateLimits(limits);\n const token = randomBytes(32).toString(\"hex\");\n const {\n file: executable,\n args,\n env,\n } = launchCommand(\n process.platform,\n process.execPath,\n input.command,\n input.args ?? [],\n limits,\n { ...process.env, ...input.env },\n token,\n );\n let pid: number;\n let streams: Pick<ProcessHandle, \"stdin\" | \"stdout\" | \"stderr\">;\n let terminalProcess: Pty | undefined;\n let exit: { code: number | null; signal: string | null } | undefined;\n let spawnError: Error | undefined;\n let running: Active | undefined;\n const onExit = (code: number | null, sig: string | null) => {\n exit = { code, signal: sig };\n if (running) void running.finish(code, sig).catch(() => undefined);\n };\n if (terminal) {\n // Optional peer loaded only here. Structural types follow node-pty's official typings.\n const peer = \"node-pty\";\n const pty = (await import(peer)) as PtyModule;\n terminalProcess = pty.spawn(executable, args, {\n cwd: input.cwd,\n env: Object.fromEntries(\n Object.entries(env).filter((pair): pair is [string, string] => pair[1] !== undefined),\n ),\n cols: input.columns ?? 80,\n rows: input.rows ?? 24,\n name: \"xterm-256color\",\n });\n pid = terminalProcess.pid;\n const output = new PassThrough();\n const errors = new PassThrough();\n const instance = terminalProcess;\n const dataSubscription = instance.onData((data) => output.write(data));\n const inputStream = new Writable({\n write(chunk: Buffer, _encoding, callback) {\n instance.write(chunk.toString());\n callback();\n },\n });\n const exitSubscription = instance.onExit((event) => {\n dataSubscription.dispose();\n exitSubscription.dispose();\n output.end();\n errors.end();\n inputStream.end();\n onExit(event.exitCode, event.signal ? String(event.signal) : null);\n });\n streams = { stdout: output, stderr: errors, stdin: inputStream };\n } else {\n const child = spawnChild(executable, args, {\n cwd: input.cwd,\n env,\n detached: process.platform !== \"win32\",\n windowsHide: true,\n stdio: \"pipe\",\n });\n child.on(\"error\", (error) => {\n spawnError = error;\n });\n // Finish on leader exit so cgroup cleanup can stop remaining members;\n // waiting for close could deadlock on a descendant holding a pipe open.\n child.on(\"exit\", onExit);\n if (!child.pid) throw new Error(\"Could not start process\");\n pid = child.pid;\n streams = { stdout: child.stdout, stderr: child.stderr, stdin: child.stdin };\n }\n let entry: RegistryEntry | undefined;\n try {\n const deadline = Date.now() + 5000;\n // Off Linux an identity read costs a helper query, so poll the guardian's\n // pipe (cheap) until it reports the gate, and read the identity once.\n const portable = process.platform !== \"linux\";\n const gate = async () => {\n if (portable) {\n const proof = await guardianProof(pid, undefined, token, observationMs);\n if (!proof?.gated) return undefined;\n }\n return identity(pid, true, token, observe());\n };\n let current = await gate();\n while (!current?.state.startsWith(\"T\") || current.token !== token) {\n if (spawnError) throw spawnError;\n if (exit || Date.now() >= deadline)\n throw new Error(\"Child failed to reach the resource setup gate\");\n await delay(10);\n current = await gate();\n }\n if (current.group !== pid) throw new Error(\"Child did not create an isolated process group\");\n entry = {\n pid,\n owner: options.owner,\n type: input.kind,\n command: input.command,\n args: [...(input.args ?? [])],\n labels: { ...input.labels },\n startedAt: Date.now(),\n limits,\n enforcement: process.platform === \"win32\" ? \"rss-polling\" : \"rlimit-polling\",\n peakMemoryBytes: current.rss,\n token,\n start: current.start,\n gated: true,\n };\n entry.cgroup = await attachCgroup(pid, token, limits, options.cgroupRoot);\n if (entry.cgroup) entry.enforcement = \"cgroup-v2\";\n entries.set(pid, entry);\n await save();\n running = track(entry, streams);\n await signal(entry, \"SIGCONT\");\n delete entry.gated;\n await save();\n monitor(running);\n if (terminalProcess) {\n const instance = terminalProcess;\n return {\n ...running.handle,\n write: (data: string) => instance.write(data),\n resize: (columns: number, rows: number) => instance.resize(columns, rows),\n };\n }\n return running.handle;\n } catch (error) {\n // This PID was created by this call. Kill only after its random token is verified.\n const current = await identity(pid, true, token, observe());\n if (current?.token === token) {\n const failed = { pid, token, start: current.start };\n if (await owns(failed, observe())) {\n try {\n if (process.platform === \"win32\") await executeCommand(taskkillCommand(pid));\n else process.kill(-pid, \"SIGKILL\");\n } catch {\n /* Already exited. */\n }\n }\n }\n if (entry && !running) {\n entries.delete(pid);\n await save();\n }\n if (entry?.cgroup) await cleanCgroup(entry.cgroup);\n throw error;\n }\n }\n\n const api: ProcessSupervisor = {\n spawn: (input) => serial(() => launch(input, false)),\n spawnPty: (input) => serial(async () => (await launch(input, true)) as PtyHandle),\n list: (filter = {}) =>\n serial(async () => {\n validateFilter(filter);\n await open();\n return [...entries.values()].filter((entry) => matches(entry, filter)).map(info);\n }),\n stop: (filter = {}) =>\n serial(async () => {\n validateFilter(filter);\n await open();\n for (const entry of [...entries.values()].filter((entry) => matches(entry, filter)))\n await stopEntry(entry);\n }),\n stopPid: (pid) =>\n serial(async () => {\n await open();\n const entry = entries.get(pid);\n if (!entry) throw new ProcessNotOwnedError(pid);\n await stopEntry(entry);\n }),\n recover: (recovery = {}) =>\n serial(async () => {\n await open();\n const result: RecoveryResult = { adopted: [], stopped: [], cleared: [] };\n for (const entry of [...entries.values()]) {\n if (active.has(entry.pid)) continue;\n if (!(await owns(entry, observe()))) {\n entries.delete(entry.pid);\n result.cleared.push(entry.pid);\n continue;\n }\n // Never trust a persisted filesystem path for cgroup I/O after a restart.\n entry.cgroup = await recoveredCgroup(entry.pid, entry.token);\n entry.enforcement = entry.cgroup\n ? \"cgroup-v2\"\n : process.platform === \"win32\"\n ? \"rss-polling\"\n : \"rlimit-polling\";\n const keep = await recovery.keep?.(info(entry));\n if (keep) {\n const running = track(entry);\n monitor(running);\n if (entry.gated) {\n await signal(entry, \"SIGCONT\");\n delete entry.gated;\n }\n result.adopted.push(entry.pid);\n } else {\n await stopEntry(entry);\n result.stopped.push(entry.pid);\n }\n }\n await save();\n return result;\n }),\n stopAll() {\n shutdown ??= serial(async () => {\n await open();\n closing = true;\n try {\n const errors: unknown[] = [];\n for (const entry of [...entries.values()]) {\n try {\n if (await owns(entry, observe())) await stopEntry(entry);\n else {\n const running = active.get(entry.pid);\n if (running) await running.finish(null, null);\n else entries.delete(entry.pid);\n }\n } catch (error) {\n errors.push(error);\n }\n }\n await save();\n if (errors.length)\n throw new AggregateError(errors, \"Some owned processes could not be stopped\");\n } finally {\n await helper?.close();\n await registry.close();\n }\n });\n return shutdown;\n },\n };\n const stopAll = api.stopAll;\n api.stopAll = () => {\n const stopping = stopAll();\n const forget = () => {\n if (sameProcess.get(registryPath)?.api === api) sameProcess.delete(registryPath);\n };\n stopping.then(forget, forget);\n return stopping;\n };\n sameProcess.set(registryPath, { owner: options.owner, api });\n return api;\n}\n\nconst SUPERVISORS = Symbol.for(\"@warlock.js/process.supervisors\");\n\n/** Live supervisors of this process by registry path; shared by every copy of this module. */\nfunction sameProcessSupervisors(): Map<string, { owner: string; api: ProcessSupervisor }> {\n const holder = globalThis as unknown as Record<symbol, Map<string, any> | undefined>;\n return (holder[SUPERVISORS] ??= new Map());\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,sBAAsB,UAA0B;CAC9D,OAAO,aAAa,UAAU,OAAO,aAAa,WAAW,MAAM;AACrE;AACA,SAAgB,4BAA4B,UAA0B;CACpE,OAAO,aAAa,WAAW,aAAa,WAAW,OAAS;AAClE;AAEA,IAAa,kCA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AQ,OAAO,CAAC,GACtC,IAAI;MACF,IAAI,MAAM,KAAK,OAAO,QAAQ,CAAC,GAAG,MAAM,UAAU,KAAK;WAClD;OACH,MAAM,UAAU,OAAO,IAAI,MAAM,GAAG;OACpC,IAAI,SAAS,MAAM,QAAQ,OAAO,MAAM,IAAI;YACvC,QAAQ,OAAO,MAAM,GAAG;MAC/B;KACF,SAAS,OAAO;MACd,OAAO,KAAK,KAAK;KACnB;KAEF,MAAM,KAAK;KACX,IAAI,OAAO,QACT,MAAM,IAAI,eAAe,QAAQ,2CAA2C;IAChF,UAAU;KACR,MAAM,QAAQ,MAAM;KACpB,MAAM,SAAS,MAAM;IACvB;GACF,CAAC;GACD,OAAO;EACT;CACF;CACA,MAAM,UAAU,IAAI;CACpB,IAAI,gBAAgB;EAClB,MAAM,WAAW,QAAQ;EACzB,MAAM,eAAe;GACnB,IAAI,YAAY,IAAI,YAAY,CAAC,EAAE,QAAQ,KAAK,YAAY,OAAO,YAAY;EACjF;EACA,SAAS,KAAK,QAAQ,MAAM;EAC5B,OAAO;CACT;CACA,YAAY,IAAI,cAAc;EAAE,OAAO,QAAQ;EAAO;CAAI,CAAC;CAC3D,OAAO;AACT;AAEA,MAAM,cAAc,OAAO,IAAI,iCAAiC;;AAGhE,SAAS,yBAAiF;CACxF,MAAM,SAAS;CACf,OAAQ,OAAO,iCAAiB,IAAI,IAAI;AAC1C"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["path","readFile","mkdir","writeFile","rmdir","randomBytes","createHmac","connect","promisify","execFile","readFile","mkdir","path","readFile","randomBytes","rename","rm","writeFile","spawnChild","delay","path","PassThrough","randomBytes","Writable","spawnChild"],"sources":["../../../../../../../packages/process/src/platform.ts","../../../../../../../packages/process/src/resources.ts","../../../../../../../packages/process/src/guardian.ts","../../../../../../../packages/process/src/identity.ts","../../../../../../../packages/process/src/registry.ts","../../../../../../../packages/process/src/windows-helper.ts","../../../../../../../packages/process/src/supervisor.ts"],"sourcesContent":["import type { Identity } from \"./identity\";\n\nexport type PortablePlatform = \"darwin\" | \"win32\";\nexport type Command = { file: string; args: string[]; env?: Record<string, string> };\nexport type Execute = (command: Command) => Promise<string>;\nexport type OwnershipProof = { pid: number; token: string; gated: boolean };\nexport type ReadProof = (pid: number) => Promise<OwnershipProof | undefined>;\nexport type Row = {\n pid: number;\n parent: number;\n start: string;\n rss: number;\n group: number;\n state: string;\n};\n\n/**\n * Defaults per platform. Linux reads /proc directly, so it is cheap to poll\n * often and a guardian reply is never awaited. Windows and macOS observe\n * through helper programs and a named pipe, which need more time and a slower\n * poll to stay out of the workload's way.\n */\nexport function defaultPollIntervalMs(platform: string): number {\n return platform === \"win32\" ? 1500 : platform === \"darwin\" ? 500 : 100;\n}\nexport function defaultObservationTimeoutMs(platform: string): number {\n return platform === \"win32\" || platform === \"darwin\" ? 15_000 : 2000;\n}\n/**\n * Longest wait for a launched child to reach the resource setup gate. Linux answers\n * from /proc; Windows and macOS answer through the guardian and helpers under load.\n */\nexport function defaultSetupTimeoutMs(platform: string): number {\n return platform === \"linux\" ? 5000 : 30_000;\n}\n\nexport class UnsupportedProcessPlatformError extends Error {\n constructor(public readonly platform: string) {\n super(`Process supervision is unsupported on ${platform}`);\n this.name = \"UnsupportedProcessPlatformError\";\n }\n}\nexport function supported(platform: string): void {\n if (![\"linux\", \"darwin\", \"win32\"].includes(platform))\n throw new UnsupportedProcessPlatformError(platform);\n}\nfunction validPid(pid: number): void {\n if (!Number.isSafeInteger(pid) || pid <= 1) throw new Error(\"Invalid process PID\");\n}\n\n/** Apple ps(1): lstart uses strftime %c. LC_ALL=C gives %a %b %e %H:%M:%S %Y.\n * https://github.com/apple-oss-distributions/adv_cmds/blob/main/ps/ps.1\n * https://github.com/apple-oss-distributions/adv_cmds/blob/main/ps/print.c (lstarted)\n * https://github.com/apple-oss-distributions/Libc/blob/main/stdtime/FreeBSD/timelocal.c (_C_time_locale)\n */\nexport function parseDarwinStart(source: string): string {\n const match =\n /^(Sun|Mon|Tue|Wed|Thu|Fri|Sat) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\s+(\\d{1,2}) (\\d{2}):(\\d{2}):(\\d{2}) (\\d{4})$/.exec(\n source.trim(),\n );\n if (!match) throw new Error(\"Invalid macOS process start time\");\n const [, weekday, month, day, hour, minute, second, year] = match;\n const monthIndex = \"Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec\"\n .split(\" \")\n .indexOf(month ?? \"\");\n const date = new Date(\n Date.UTC(Number(year), monthIndex, Number(day), Number(hour), Number(minute), Number(second)),\n );\n if (\n date.getUTCFullYear() !== Number(year) ||\n date.getUTCMonth() !== monthIndex ||\n date.getUTCDate() !== Number(day) ||\n date.getUTCHours() !== Number(hour) ||\n date.getUTCMinutes() !== Number(minute) ||\n date.getUTCSeconds() !== Number(second) ||\n \"Sun Mon Tue Wed Thu Fri Sat\".split(\" \")[date.getUTCDay()] !== weekday\n )\n throw new Error(\"Invalid macOS process start time\");\n return String(date.getTime() / 1000);\n}\nexport function darwinCommand(pid: number, tree = false): Command {\n validPid(pid);\n return {\n file: \"/bin/ps\",\n args: [...(tree ? [\"-ax\"] : [\"-p\", String(pid)]), \"-o\", \"pid=,ppid=,pgid=,state=,rss=,lstart=\"],\n env: { LC_ALL: \"C\", TZ: \"UTC\" },\n };\n}\nexport function parseDarwinRows(source: string): Row[] {\n return source.trim()\n ? source\n .trim()\n .split(\"\\n\")\n .map((line) => {\n const match = /^\\s*(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\S+)\\s+(\\d+)\\s+(.+?)\\s*$/.exec(line);\n if (!match) throw new Error(\"Invalid macOS process observation\");\n return {\n pid: Number(match[1]),\n parent: Number(match[2]),\n group: Number(match[3]),\n state: match[4] ?? \"\",\n rss: Number(match[5]) * 1024,\n start: parseDarwinStart(match[6] ?? \"\"),\n };\n })\n : [];\n}\n\n/** CIM CreationDate is a DateTime; serialize UTC ticks as text, never a locale date\n * or JSON number (100ns ticks exceed Number's precision). WorkingSetSize is bytes.\n * https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-process\n */\nexport function windowsCommand(pid: number, tree = false): Command {\n validPid(pid);\n const query = `Get-CimInstance Win32_Process${tree ? \"\" : ` -Filter 'ProcessId=${pid}'`}`;\n const script = [\n \"$ErrorActionPreference = 'Stop'\",\n `$rows = @(${query} | ForEach-Object {`,\n `if ([int]$_.ProcessId -eq ${pid} -and $null -eq $_.CreationDate) { throw 'Cannot read process creation time' }`,\n \"if ($null -ne $_.CreationDate) {\",\n \"[pscustomobject]@{ pid = [int]$_.ProcessId; parent = [int]$_.ParentProcessId; start = $_.CreationDate.ToUniversalTime().Ticks.ToString([Globalization.CultureInfo]::InvariantCulture); rss = [double]$_.WorkingSetSize }\",\n \"}\",\n \"})\",\n \"ConvertTo-Json -InputObject $rows -Compress\",\n ].join(\"\\n\");\n return {\n file: \"powershell.exe\",\n args: [\"-NoLogo\", \"-NoProfile\", \"-NonInteractive\", \"-Command\", script],\n };\n}\nexport function parseWindowsRows(source: string): Row[] {\n return windowsRows(JSON.parse(source.replace(/^\\uFEFF/, \"\")));\n}\n/** Validates rows decoded from PowerShell, whether one-shot or from the long-lived helper. */\nexport function windowsRows(value: unknown): Row[] {\n if (!Array.isArray(value)) throw new Error(\"Invalid Windows process observation\");\n return value.map((row: unknown) => {\n if (\n !row ||\n typeof row !== \"object\" ||\n !(\"pid\" in row) ||\n typeof row.pid !== \"number\" ||\n !Number.isSafeInteger(row.pid) ||\n row.pid < 0 ||\n !(\"parent\" in row) ||\n typeof row.parent !== \"number\" ||\n !Number.isSafeInteger(row.parent) ||\n row.parent < 0 ||\n !(\"start\" in row) ||\n typeof row.start !== \"string\" ||\n !/^\\d{18}$/.test(row.start) ||\n !(\"rss\" in row) ||\n typeof row.rss !== \"number\" ||\n !Number.isFinite(row.rss) ||\n row.rss < 0\n )\n throw new Error(\"Invalid Windows process observation\");\n return {\n pid: row.pid,\n parent: row.parent,\n start: row.start,\n rss: row.rss,\n group: row.pid,\n state: \"R\",\n };\n });\n}\nexport function taskkillCommand(pid: number): Command {\n validPid(pid);\n // Never accept an image name, filter, wildcard or shell interpolation.\n return { file: \"taskkill.exe\", args: [\"/PID\", String(pid), \"/T\", \"/F\"] };\n}\nexport function treeMemory(rows: Row[], pid: number): number {\n const root = rows.find((row) => row.pid === pid);\n if (!root) return 0;\n const included = new Map<number, Row>([[pid, root]]);\n let changed = true;\n while (changed) {\n changed = false;\n for (const row of rows) {\n const parent = included.get(row.parent);\n // Reject a reused parent PID whose creation time is later than the child.\n if (!included.has(row.pid) && parent && BigInt(row.start) >= BigInt(parent.start)) {\n included.set(row.pid, row);\n changed = true;\n }\n }\n }\n return [...included.values()].reduce((total, row) => total + row.rss, 0);\n}\n\n/** Reads process rows. `tree` asks for the whole table; `maxAgeMs` accepts a recent snapshot. */\nexport type RowSource = (pids: number[], tree: boolean, maxAgeMs?: number) => Promise<Row[]>;\n\n/** All OS effects are injected; foreign-platform specs never execute real commands. */\nexport async function portableIdentity(\n platform: PortablePlatform,\n pid: number,\n token: boolean,\n execute: Execute,\n readProof: ReadProof,\n source?: RowSource,\n maxAgeMs = 0,\n): Promise<Identity | undefined> {\n validPid(pid);\n const command = platform === \"darwin\" ? darwinCommand : windowsCommand;\n const parse = platform === \"darwin\" ? parseDarwinRows : parseWindowsRows;\n const read: RowSource =\n source ?? (async (pids, tree) => parse(await execute(command(pids[0] ?? pid, tree))));\n const rows = await read([pid], token, maxAgeMs);\n const before = rows.find((row) => row.pid === pid);\n if (!before || /^[ZX]/.test(before.state)) return undefined;\n if (!token) return before;\n const proof = await readProof(pid);\n const after = (await read([pid], false, maxAgeMs)).find((row) => row.pid === pid);\n if (\n !after ||\n after.start !== before.start ||\n after.group !== before.group ||\n /^[ZX]/.test(after.state)\n )\n return undefined;\n return {\n start: after.start,\n group: after.group,\n state: proof?.pid === pid && proof.gated ? \"T\" : after.state,\n rss: treeMemory(rows, pid),\n token: proof?.pid === pid ? proof.token : undefined,\n };\n}\n","import { mkdir, readFile, rmdir, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { ProcessLimits } from \"./types\";\n\nfunction mountedCgroup(membership: string): string | undefined {\n const mount = \"/sys/fs/cgroup\";\n const directory = path.resolve(mount, `.${membership}`);\n // A cgroup namespace can report ancestors using /../ components. Never\n // normalize those into writes outside the standard cgroup mount.\n return directory === mount || directory.startsWith(`${mount}/`) ? directory : undefined;\n}\n\nexport function validateLimits(limits: ProcessLimits, platform: string = process.platform): void {\n for (const [key, value] of Object.entries(limits)) {\n if (\n ![\"timeoutMs\", \"memoryBytes\", \"cpuSeconds\", \"virtualMemoryBytes\"].includes(key) ||\n !Number.isSafeInteger(value) ||\n value <= 0\n )\n throw new Error(`Invalid process limit: ${key}`);\n }\n if (platform !== \"linux\" && limits.virtualMemoryBytes !== undefined)\n throw new Error(\"virtualMemoryBytes is supported only on Linux\");\n if (platform === \"win32\" && limits.cpuSeconds !== undefined)\n throw new Error(\"cpuSeconds is supported only on POSIX platforms\");\n}\n\n/**\n * POSIX shell applies inherited limits. Linux stops here; macOS execs a gated guardian.\n * Flags/units: Apple's bash-3.2/builtins/ulimit.def and installed Bash manual.\n * https://github.com/apple-oss-distributions/bash/blob/main/bash-3.2/builtins/ulimit.def\n */\nexport function launcher(limits: ProcessLimits, platform: string = process.platform): string {\n const commands = [\"set -e\"];\n if (limits.cpuSeconds) commands.push(`ulimit -t ${limits.cpuSeconds}`);\n if (limits.virtualMemoryBytes)\n commands.push(`ulimit -v ${Math.ceil(limits.virtualMemoryBytes / 1024)}`);\n // Linux ignores RLIMIT_RSS; polling remains the fallback resident-memory cap.\n // Darwin's RLIMIT_DATA restricts heap growth, not total resident memory.\n if (limits.memoryBytes)\n commands.push(\n `ulimit -${platform === \"darwin\" ? \"d\" : \"m\"} ${Math.ceil(limits.memoryBytes / 1024)}`,\n );\n if (platform === \"linux\") commands.push('kill -STOP \"$$\"');\n commands.push('exec \"$@\"');\n return commands.join(\"\\n\");\n}\n\n/** https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html */\nexport async function attachCgroup(\n pid: number,\n token: string,\n limits: ProcessLimits,\n root?: string,\n): Promise<string | undefined> {\n if (process.platform !== \"linux\") return undefined;\n let directory: string | undefined;\n try {\n const own = (await readFile(\"/proc/self/cgroup\", \"utf8\"))\n .split(\"\\n\")\n .find((line) => line.startsWith(\"0::\"))\n ?.slice(3);\n if (!root && own === undefined) return undefined;\n const parent = root ?? mountedCgroup(own ?? \"/\");\n if (!parent) return undefined;\n // Do not enable controllers or move the app: delegation belongs to the service manager.\n await readFile(path.join(parent, \"cgroup.controllers\"), \"utf8\");\n directory = path.join(parent, `warlock-${token}`);\n await mkdir(directory);\n if (limits.memoryBytes) {\n await writeFile(path.join(directory, \"memory.max\"), String(limits.memoryBytes));\n await writeFile(path.join(directory, \"memory.oom.group\"), \"1\");\n }\n await writeFile(path.join(directory, \"cgroup.procs\"), String(pid));\n return directory;\n } catch {\n if (directory) await rmdir(directory).catch(() => undefined);\n return undefined;\n }\n}\n\nexport async function cgroupMemory(directory: string): Promise<{ peak: number; oom: boolean }> {\n const [peak, events] = await Promise.all([\n readFile(path.join(directory, \"memory.peak\"), \"utf8\").catch(() => \"0\"),\n readFile(path.join(directory, \"memory.events\"), \"utf8\").catch(() => \"\"),\n ]);\n return { peak: Number(peak) || 0, oom: Number(/^oom_kill (\\d+)/m.exec(events)?.[1] ?? 0) > 0 };\n}\n\n/** Only reattach the token-specific cgroup confirmed by the kernel membership file. */\nexport async function recoveredCgroup(pid: number, token: string): Promise<string | undefined> {\n if (process.platform !== \"linux\") return undefined;\n let source: string;\n try {\n source = await readFile(`/proc/${pid}/cgroup`, \"utf8\");\n } catch (error) {\n if ([\"ENOENT\", \"ESRCH\"].includes(String((error as NodeJS.ErrnoException).code)))\n return undefined;\n throw error;\n }\n const membership = source\n .split(\"\\n\")\n .find((line) => line.startsWith(\"0::\"))\n ?.slice(3);\n if (!membership || path.basename(membership) !== `warlock-${token}`) return undefined;\n return mountedCgroup(membership);\n}\n\nexport async function cleanCgroup(directory: string): Promise<void> {\n // This unique cgroup was created for this token, or recovered after identity proof.\n // cgroup.kill also covers descendants that created their own POSIX session.\n await writeFile(path.join(directory, \"cgroup.kill\"), \"1\").catch(() => undefined);\n await rmdir(directory).catch(() => undefined);\n}\n","import { createHmac, randomBytes } from \"node:crypto\";\nimport { connect } from \"node:net\";\nimport type { Command, OwnershipProof } from \"./platform\";\nimport { defaultObservationTimeoutMs } from \"./platform\";\nimport { launcher } from \"./resources\";\nimport type { ProcessLimits } from \"./types\";\n\nexport function guardianAddress(platform: string, pid: number, uid: number): string {\n return platform === \"win32\"\n ? `\\\\\\\\.\\\\pipe\\\\warlock-process-${pid}`\n : `/tmp/warlock-process-${uid}-${pid}.sock`;\n}\n\n/** A live guardian reads its own environment, never argv, to prove ownership.\n * Node IPC is native-free: https://nodejs.org/api/net.html#ipc-support\n * The stable root PID stays alive for the workload and survives supervisor restarts.\n */\nexport const guardianScript = String.raw`\nconst { createServer } = require(\"node:net\");\nconst { createHmac } = require(\"node:crypto\");\nconst { spawn } = require(\"node:child_process\");\nconst { chmodSync, unlinkSync } = require(\"node:fs\");\nconst token = process.env.WARLOCK_PROCESS_TOKEN;\nconst address = process.platform === \"win32\"\n ? \"\\\\\\\\.\\\\pipe\\\\warlock-process-\" + process.pid\n : \"/tmp/warlock-process-\" + process.getuid() + \"-\" + process.pid + \".sock\";\nlet gated = true;\nconst finish = (code) => { server.close(); process.exit(code); };\nconst launch = () => {\n const [command, ...args] = JSON.parse(process.env.WARLOCK_PROCESS_LAUNCH);\n const env = { ...process.env };\n for (const key of Object.keys(env)) {\n const name = process.platform === \"win32\" ? key.toUpperCase() : key;\n if (name === \"WARLOCK_PROCESS_TOKEN\" || name === \"WARLOCK_PROCESS_LAUNCH\") delete env[key];\n }\n const child = spawn(command, args, { env, stdio: \"inherit\", windowsHide: true });\n child.on(\"error\", (error) => { console.error(error.message); finish(127); });\n child.on(\"exit\", (code, signal) => {\n if (signal && process.platform !== \"win32\") process.kill(process.pid, signal);\n else finish(code ?? 1);\n });\n};\nconst server = createServer((socket) => {\n socket.setTimeout(2000, () => socket.destroy());\n socket.on(\"error\", () => {});\n let input = \"\";\n socket.on(\"data\", (chunk) => {\n input += chunk;\n if (input.length > 1024) { socket.destroy(); return; }\n if (!input.endsWith(\"\\n\")) return;\n try {\n const request = JSON.parse(input);\n if (!/^[a-f0-9]{64}$/.test(request.nonce)) { socket.destroy(); return; }\n const sign = (value) => createHmac(\"sha256\", token).update(value).digest(\"hex\");\n const resume = gated && request.resume === sign(request.nonce + \":resume\");\n // Reply first, then start the workload: a slow program start must never\n // eat into the client's observation timeout.\n if (resume) gated = false;\n socket.end(JSON.stringify({ pid: process.pid, digest: sign(request.nonce + \":\" + process.pid + \":\" + gated), gated }) + \"\\n\");\n if (resume) setImmediate(launch);\n } catch { socket.destroy(); }\n });\n});\nserver.on(\"error\", (error) => { console.error(error.message); process.exit(126); });\nif (process.platform !== \"win32\") {\n try { unlinkSync(address); } catch (error) { if (error.code !== \"ENOENT\") throw error; }\n process.on(\"exit\", () => { try { unlinkSync(address); } catch {} });\n}\nserver.listen(address, () => { if (process.platform !== \"win32\") chmodSync(address, 0o600); });\n`;\n\nexport async function guardianProof(\n pid: number,\n resume?: string,\n expectedToken: string | undefined = resume,\n timeoutMs: number = defaultObservationTimeoutMs(process.platform),\n): Promise<OwnershipProof | undefined> {\n if (!expectedToken) return undefined;\n const token = expectedToken;\n const nonce = randomBytes(32).toString(\"hex\");\n const sign = (value: string) => createHmac(\"sha256\", token).update(value).digest(\"hex\");\n const address = guardianAddress(process.platform, pid, process.getuid?.() ?? 0);\n return new Promise((resolve, reject) => {\n const socket = connect(address);\n let data = \"\";\n const fail = (error: Error) => {\n socket.destroy();\n reject(error);\n };\n socket.setTimeout(timeoutMs, () =>\n fail(\n new Error(\n `Process ownership observation timed out after ${timeoutMs} ms; raise the observationTimeoutMs supervisor option`,\n ),\n ),\n );\n socket.on(\"connect\", () =>\n socket.write(\n JSON.stringify({ nonce, resume: resume ? sign(nonce + \":resume\") : undefined }) + \"\\n\",\n ),\n );\n socket.on(\"data\", (chunk: Buffer) => {\n data += chunk.toString();\n if (data.length > 1024) fail(new Error(\"Invalid process ownership response\"));\n });\n socket.on(\"error\", (error: NodeJS.ErrnoException) => {\n if ([\"ENOENT\", \"ECONNREFUSED\", \"EPIPE\", \"ECONNRESET\"].includes(error.code ?? \"\"))\n resolve(undefined);\n else reject(error);\n });\n socket.on(\"end\", () => {\n // A guardian that is exiting closes the pipe without answering; that is no proof, not corrupt data.\n if (!data) {\n resolve(undefined);\n return;\n }\n try {\n resolve(parseGuardianProof(data, pid, nonce, token));\n } catch (error) {\n reject(error);\n }\n });\n });\n}\n\n/** Malformed observation is an error; an authenticated identity mismatch is unowned. */\nexport function parseGuardianProof(\n source: string,\n pid: number,\n nonce: string,\n token: string,\n): OwnershipProof | undefined {\n const proof: unknown = JSON.parse(source);\n if (\n !proof ||\n typeof proof !== \"object\" ||\n !(\"pid\" in proof) ||\n typeof proof.pid !== \"number\" ||\n !(\"gated\" in proof) ||\n typeof proof.gated !== \"boolean\" ||\n !(\"digest\" in proof) ||\n typeof proof.digest !== \"string\"\n )\n throw new Error(\"Invalid process ownership response\");\n const expected = createHmac(\"sha256\", token)\n .update(nonce + \":\" + pid + \":\" + proof.gated)\n .digest(\"hex\");\n if (proof.pid !== pid || proof.digest !== expected) return undefined;\n return { pid, token, gated: proof.gated };\n}\n\n/** Pure launch construction, including case-insensitive Windows environment keys. */\nexport function launchCommand(\n platform: string,\n node: string,\n command: string,\n args: string[],\n limits: ProcessLimits,\n environment: NodeJS.ProcessEnv,\n token: string,\n): Omit<Command, \"env\"> & { env: NodeJS.ProcessEnv } {\n const portable = platform !== \"linux\";\n const env: NodeJS.ProcessEnv = Object.fromEntries(\n Object.entries(environment).filter(\n ([key]) =>\n ![\"WARLOCK_PROCESS_TOKEN\", \"WARLOCK_PROCESS_LAUNCH\"].includes(\n platform === \"win32\" ? key.toUpperCase() : key,\n ),\n ),\n );\n env.WARLOCK_PROCESS_TOKEN = token;\n if (portable) env.WARLOCK_PROCESS_LAUNCH = JSON.stringify([command, ...args]);\n const executable = portable ? node : command;\n const arguments_ = portable ? [\"-e\", guardianScript] : args;\n return {\n file: platform === \"win32\" ? executable : \"/bin/sh\",\n args:\n platform === \"win32\"\n ? arguments_\n : [\"-c\", launcher(limits, platform), \"warlock-process\", executable, ...arguments_],\n env,\n };\n}\n","import { execFile } from \"node:child_process\";\nimport { readFile } from \"node:fs/promises\";\nimport { promisify } from \"node:util\";\n\nimport { guardianProof } from \"./guardian\";\nimport { defaultObservationTimeoutMs, portableIdentity, type Command } from \"./platform\";\nimport type { WindowsProcessHelper } from \"./windows-helper\";\n\nconst execute = promisify(execFile);\nexport async function executeCommand(command: Command): Promise<string> {\n const { stdout } = await execute(command.file, command.args, {\n env: { ...process.env, ...command.env },\n timeout: 5000,\n maxBuffer: 4 * 1024 * 1024,\n windowsHide: true,\n });\n return stdout;\n}\n/** How a supervisor observes processes off Linux. Linux ignores all of it. */\nexport type Observation = {\n /** Longest wait for a guardian reply or a helper answer. */\n timeoutMs?: number;\n /** Long-lived Windows helper; without it each observation runs PowerShell once. */\n helper?: WindowsProcessHelper;\n /** Accept a process-table snapshot this old (polling only, never before a signal). */\n maxAgeMs?: number;\n};\nexport const TOKEN_ENV = \"WARLOCK_PROCESS_TOKEN\";\nexport type Identity = { start: string; group: number; state: string; rss: number; token?: string };\n\nfunction statFields(stat: string): string[] {\n return stat\n .slice(stat.lastIndexOf(\")\") + 2)\n .trim()\n .split(/\\s+/);\n}\n\n/**\n * A task that is exiting has already released its memory map (stat field 23,\n * vsize, reads 0) before it turns into a zombie. Linux then reports its /proc\n * files as root-owned, so it is never a live child to verify or signal.\n */\nfunction exiting(fields: string[]): boolean {\n return [\"Z\", \"X\"].includes(fields[0] ?? \"\") || fields[20] === \"0\";\n}\n\n/** /proc fields: https://man7.org/linux/man-pages/man5/proc_pid_stat.5.html */\nexport async function identity(\n pid: number,\n token = false,\n expectedToken?: string,\n observation: Observation = {},\n): Promise<Identity | undefined> {\n if (!Number.isSafeInteger(pid) || pid <= 1) return undefined;\n try {\n if (process.platform === \"linux\") {\n const stat = await readFile(`/proc/${pid}/stat`, \"utf8\");\n const fields = statFields(stat);\n const state = fields[0];\n const start = fields[19];\n if (!state || !start || exiting(fields)) return undefined;\n const boot = (await readFile(\"/proc/sys/kernel/random/boot_id\", \"utf8\")).trim();\n const status = await readFile(`/proc/${pid}/status`, \"utf8\");\n let environment = \"\";\n if (token) {\n try {\n environment = await readFile(`/proc/${pid}/environ`, \"utf8\");\n } catch (error) {\n // Without root, the environment of a task that started exiting after\n // the first stat read is unreadable. Only that case counts as gone;\n // any other unreadable environment still fails closed.\n if ((error as { code?: unknown }).code !== \"EACCES\") throw error;\n const now = statFields(await readFile(`/proc/${pid}/stat`, \"utf8\"));\n if (now[19] !== start || exiting(now)) return undefined;\n throw error;\n }\n }\n // /proc reads are separate operations. Reject PID reuse or a group change\n // during observation before combining a token with a start identity.\n const after = statFields(await readFile(`/proc/${pid}/stat`, \"utf8\"));\n if (after[19] !== start || after[2] !== fields[2] || exiting(after)) return undefined;\n return {\n start: `${boot}:${start}`,\n group: Number(fields[2]),\n state: after[0] ?? state,\n rss: Number(/^VmRSS:\\s+(\\d+)/m.exec(status)?.[1] ?? 0) * 1024,\n token: environment\n .split(\"\\0\")\n .find((entry) => entry.startsWith(`${TOKEN_ENV}=`))\n ?.slice(TOKEN_ENV.length + 1),\n };\n }\n if (process.platform === \"darwin\" || process.platform === \"win32\") {\n const { helper } = observation;\n return await portableIdentity(\n process.platform,\n pid,\n token,\n executeCommand,\n (selected) =>\n guardianProof(\n selected,\n undefined,\n expectedToken,\n observation.timeoutMs ?? defaultObservationTimeoutMs(process.platform),\n ),\n process.platform === \"win32\" && helper\n ? (pids, tree, maxAgeMs) => helper.query(pids, tree, maxAgeMs)\n : undefined,\n observation.maxAgeMs,\n );\n }\n return undefined;\n } catch (error) {\n const code = (error as { code?: unknown }).code;\n if (\n (process.platform === \"linux\" && [\"ENOENT\", \"ESRCH\"].includes(String(code))) ||\n (process.platform === \"darwin\" &&\n code === 1 &&\n !(error as { stdout?: string }).stdout?.trim())\n )\n return undefined;\n throw error;\n }\n}\n\nexport class ProcessNotOwnedError extends Error {\n constructor(public readonly pid: number) {\n super(`Process ${pid} does not have a verified supervisor identity`);\n this.name = \"ProcessNotOwnedError\";\n }\n}\n\nexport async function owns(\n entry: { pid: number; start: string; token: string },\n observation?: Observation,\n): Promise<boolean> {\n const current = await identity(entry.pid, true, entry.token, observation);\n return (\n current?.start === entry.start && current.token === entry.token && current.group === entry.pid\n );\n}\n","import { randomBytes } from \"node:crypto\";\nimport { mkdir, readFile, rename, rm, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { identity } from \"./identity\";\nimport type { ProcessInfo } from \"./types\";\n\nexport type RegistryEntry = ProcessInfo & {\n token: string;\n start: string;\n cgroup?: string;\n /** Persisted launch gate: recovery may resume an adopted, interrupted launch. */\n gated?: boolean;\n};\n\nfunction record(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\nfunction strings(value: unknown): value is Record<string, string> {\n return record(value) && Object.values(value).every((item) => typeof item === \"string\");\n}\nexport function parseRegistry(source: string, owner: string): RegistryEntry[] {\n const value: unknown = JSON.parse(source);\n if (\n !record(value) ||\n value.version !== 1 ||\n value.owner !== owner ||\n !Array.isArray(value.entries)\n )\n throw new Error(\"Invalid process registry or different owner\");\n const entries: RegistryEntry[] = [];\n for (const entry of value.entries) {\n if (\n !record(entry) ||\n entry.owner !== owner ||\n typeof entry.pid !== \"number\" ||\n !Number.isSafeInteger(entry.pid) ||\n Number(entry.pid) <= 1 ||\n typeof entry.token !== \"string\" ||\n !/^[a-f0-9]{64}$/.test(entry.token) ||\n typeof entry.start !== \"string\" ||\n typeof entry.type !== \"string\" ||\n typeof entry.command !== \"string\" ||\n !Array.isArray(entry.args) ||\n !entry.args.every((arg) => typeof arg === \"string\") ||\n !strings(entry.labels) ||\n typeof entry.startedAt !== \"number\" ||\n !Number.isFinite(entry.startedAt) ||\n entry.startedAt < 0 ||\n !record(entry.limits) ||\n !Object.entries(entry.limits).every(\n ([key, limit]) =>\n [\"timeoutMs\", \"memoryBytes\", \"cpuSeconds\", \"virtualMemoryBytes\"].includes(key) &&\n typeof limit === \"number\" &&\n Number.isSafeInteger(limit) &&\n limit > 0,\n ) ||\n ![\"cgroup-v2\", \"rlimit-polling\", \"rss-polling\"].includes(String(entry.enforcement)) ||\n typeof entry.peakMemoryBytes !== \"number\" ||\n !Number.isFinite(entry.peakMemoryBytes) ||\n entry.peakMemoryBytes < 0 ||\n (entry.cgroup !== undefined && typeof entry.cgroup !== \"string\") ||\n (entry.gated !== undefined && typeof entry.gated !== \"boolean\")\n )\n throw new Error(\"Invalid process registry entry\");\n entries.push(entry as RegistryEntry);\n }\n if (new Set(entries.map((entry) => entry.pid)).size !== entries.length)\n throw new Error(\"Duplicate registry PID\");\n return entries;\n}\n\n/** One writer per registry. A crash leaves a lease which only a dead identity can release. */\nexport class Registry {\n private queue: Promise<void> = Promise.resolve();\n private locked = false;\n constructor(\n public readonly file: string,\n private readonly owner: string,\n private readonly read: (pid: number) => ReturnType<typeof identity> = (pid) => identity(pid),\n ) {}\n async open(): Promise<RegistryEntry[]> {\n await mkdir(path.dirname(this.file), { recursive: true, mode: 0o700 });\n const self = await this.read(process.pid);\n if (!self) throw new Error(\"Cannot verify registry writer identity\");\n const lock = `${this.file}.lock`;\n try {\n await mkdir(lock, { mode: 0o700 });\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"EEXIST\") throw error;\n const reclaim = `${lock}.reclaim`;\n await mkdir(reclaim, { mode: 0o700 });\n try {\n const lease: unknown = JSON.parse(await readFile(path.join(lock, \"writer.json\"), \"utf8\"));\n if (!record(lease) || typeof lease.pid !== \"number\" || typeof lease.start !== \"string\")\n throw new Error(\"Invalid registry writer lease; inspect it manually\");\n const writer = await this.read(lease.pid);\n if (writer?.start === lease.start) throw new Error(\"Process registry is already in use\");\n const stale = `${lock}.${randomBytes(8).toString(\"hex\")}`;\n await rename(lock, stale);\n await rm(stale, { recursive: true });\n await mkdir(lock, { mode: 0o700 });\n } finally {\n await rm(reclaim, { recursive: true });\n }\n }\n this.locked = true;\n try {\n await writeFile(\n path.join(lock, \"writer.json\"),\n JSON.stringify({ pid: process.pid, start: self.start }),\n { mode: 0o600 },\n );\n try {\n return parseRegistry(await readFile(this.file, \"utf8\"), this.owner);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\") return [];\n throw error;\n }\n } catch (error) {\n await this.close();\n throw error;\n }\n }\n save(entries: RegistryEntry[]): Promise<void> {\n const source = JSON.stringify({ version: 1, owner: this.owner, entries }, null, 2) + \"\\n\";\n const next = this.queue.then(async () => {\n const temporary = `${this.file}.${randomBytes(8).toString(\"hex\")}.tmp`;\n try {\n await writeFile(temporary, source, { mode: 0o600, flag: \"wx\" });\n await rename(temporary, this.file);\n } finally {\n await rm(temporary, { force: true });\n }\n });\n this.queue = next.catch(() => undefined);\n return next;\n }\n async close(): Promise<void> {\n await this.queue;\n if (this.locked) {\n await rm(`${this.file}.lock`, { recursive: true });\n this.locked = false;\n }\n }\n}\n","import { spawn as spawnChild } from \"node:child_process\";\nimport type { Readable, Writable } from \"node:stream\";\nimport { windowsRows, type Row } from \"./platform\";\n\n/**\n * One long-lived PowerShell per supervisor answers batched process queries over\n * stdin/stdout, one JSON object per line:\n *\n * request {\"id\":1,\"pids\":[42,43],\"all\":false}\n * response {\"id\":1,\"rows\":[{\"pid\":42,\"parent\":4,\"start\":\"638...\",\"rss\":1024}]}\n * failure {\"id\":1,\"error\":\"message\"}\n *\n * `all: true` returns the whole process table (needed to sum a process tree).\n * Starting PowerShell costs about a second on Windows; paying that once instead\n * of twice per observation is what keeps a busy machine responsive.\n */\nexport const helperScript = [\n \"$ErrorActionPreference = 'Stop'\",\n \"[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding($false)\",\n \"$reader = [Console]::In\",\n \"while ($null -ne ($line = $reader.ReadLine())) {\",\n \" $id = 0\",\n \" try {\",\n \" $request = $line | ConvertFrom-Json\",\n \" $id = [int]$request.id\",\n \" $wanted = @($request.pids | ForEach-Object { [int]$_ })\",\n \" if ($request.all) { $found = @(Get-CimInstance Win32_Process) }\",\n \" elseif ($wanted.Count -eq 0) { $found = @() }\",\n \" else { $found = @(Get-CimInstance Win32_Process -Filter (($wanted | ForEach-Object { 'ProcessId=' + $_ }) -join ' OR ')) }\",\n \" $rows = @($found | ForEach-Object {\",\n \" if ($wanted -contains [int]$_.ProcessId -and $null -eq $_.CreationDate) { throw 'Cannot read process creation time' }\",\n \" if ($null -ne $_.CreationDate) {\",\n \" [pscustomobject]@{ pid = [int]$_.ProcessId; parent = [int]$_.ParentProcessId; start = $_.CreationDate.ToUniversalTime().Ticks.ToString([Globalization.CultureInfo]::InvariantCulture); rss = [double]$_.WorkingSetSize }\",\n \" }\",\n \" })\",\n \" $reply = ConvertTo-Json -InputObject @{ id = $id; rows = $rows } -Compress -Depth 4\",\n \" } catch {\",\n \" $reply = ConvertTo-Json -InputObject @{ id = $id; error = [string]$_.Exception.Message } -Compress\",\n \" }\",\n \" [Console]::Out.WriteLine($reply)\",\n \" [Console]::Out.Flush()\",\n \"}\",\n].join(\"\\n\");\n\n/** The subset of ChildProcess the helper uses; tests inject a fake. */\nexport type HelperChild = {\n pid?: number;\n stdin: Writable;\n stdout: Readable;\n on(event: \"exit\" | \"error\", listener: () => void): unknown;\n kill(): unknown;\n unref?(): void;\n};\nexport type HelperSpawn = (file: string, args: string[]) => HelperChild;\n\nexport function defaultHelperSpawn(file: string, args: string[]): HelperChild {\n const child = spawnChild(file, args, { stdio: [\"pipe\", \"pipe\", \"ignore\"], windowsHide: true });\n // The helper must never keep the host process alive; stopAll() closes it.\n child.unref();\n (child.stdin as unknown as { unref?(): void }).unref?.();\n (child.stdout as unknown as { unref?(): void }).unref?.();\n return child;\n}\n\nexport function helperArguments(): string[] {\n return [\n \"-NoLogo\",\n \"-NoProfile\",\n \"-NonInteractive\",\n \"-EncodedCommand\",\n Buffer.from(helperScript, \"utf16le\").toString(\"base64\"),\n ];\n}\n\nexport type WindowsHelperOptions = {\n spawn?: HelperSpawn;\n /** Longest wait for one response, including PowerShell's own start-up. */\n timeoutMs?: number;\n now?: () => number;\n};\n\ntype Waiter = { resolve(rows: Row[]): void; reject(error: unknown): void; pids: number[] };\ntype Batch = { pids: Set<number>; all: boolean; waiters: Waiter[] };\ntype Flight = {\n id: number;\n pids: number[];\n all: boolean;\n waiters: Waiter[];\n attempts: number;\n timer?: ReturnType<typeof setTimeout>;\n};\ntype Snapshot = { at: number; all: boolean; pids: Set<number>; rows: Row[] };\n\nexport class WindowsProcessHelper {\n private child: HelperChild | undefined;\n private buffer = \"\";\n private flight: Flight | undefined;\n private batch: Batch | undefined;\n private scheduled = false;\n private nextId = 1;\n private closed = false;\n private last: Snapshot | undefined;\n /** Number of PowerShell processes started; a restart shows up here. */\n starts = 0;\n /** Number of requests written to the helper. */\n requests = 0;\n private readonly spawn: HelperSpawn;\n private readonly timeoutMs: number;\n private readonly now: () => number;\n\n constructor(options: WindowsHelperOptions = {}) {\n this.spawn = options.spawn ?? defaultHelperSpawn;\n this.timeoutMs = options.timeoutMs ?? 15_000;\n this.now = options.now ?? Date.now;\n }\n\n /**\n * Rows for the given PIDs, or the whole table with `all`. Calls made while a\n * request is in flight share the next request, so N concurrent observations\n * cost one query. `maxAgeMs` accepts a snapshot at most that old.\n */\n query(pids: number[], all = false, maxAgeMs = 0): Promise<Row[]> {\n if (this.closed) return Promise.reject(new Error(\"Windows process helper is closed\"));\n const cached = this.last;\n if (\n maxAgeMs > 0 &&\n cached &&\n this.now() - cached.at <= maxAgeMs &&\n (cached.all || (!all && pids.every((pid) => cached.pids.has(pid))))\n )\n return Promise.resolve(cached.rows);\n return new Promise<Row[]>((resolve, reject) => {\n const batch = (this.batch ??= { pids: new Set(), all: false, waiters: [] });\n for (const pid of pids) batch.pids.add(pid);\n batch.all ||= all;\n batch.waiters.push({ resolve, reject, pids });\n this.schedule();\n });\n }\n\n /** Stops the helper; pending queries reject. Safe to call twice. */\n async close(): Promise<void> {\n this.closed = true;\n const error = new Error(\"Windows process helper is closed\");\n this.failAll(error);\n this.discard();\n }\n\n private schedule(): void {\n if (this.flight || this.scheduled) return;\n this.scheduled = true;\n // Let observations started in the same tick join one request.\n setImmediate(() => {\n this.scheduled = false;\n this.dispatch();\n });\n }\n\n private dispatch(): void {\n if (this.flight || !this.batch) return;\n const batch = this.batch;\n this.batch = undefined;\n this.flight = {\n id: this.nextId++,\n pids: [...batch.pids],\n all: batch.all,\n waiters: batch.waiters,\n attempts: 0,\n };\n this.send(this.flight);\n }\n\n private send(flight: Flight): void {\n flight.attempts += 1;\n try {\n const child = this.ensure();\n this.requests += 1;\n child.stdin.write(\n JSON.stringify({ id: flight.id, pids: flight.pids, all: flight.all }) + \"\\n\",\n );\n } catch (error) {\n this.retryOrFail(flight, error);\n return;\n }\n clearTimeout(flight.timer);\n flight.timer = setTimeout(() => {\n // A wedged helper is replaced, never trusted for the next request.\n this.discard();\n this.retryOrFail(\n flight,\n new Error(\n `Windows process helper did not answer within ${this.timeoutMs} ms; raise the observationTimeoutMs supervisor option`,\n ),\n );\n }, this.timeoutMs);\n flight.timer.unref?.();\n }\n\n private ensure(): HelperChild {\n if (this.child) return this.child;\n const child = this.spawn(\"powershell.exe\", helperArguments());\n this.starts += 1;\n this.child = child;\n this.buffer = \"\";\n child.stdout.setEncoding?.(\"utf8\");\n child.stdout.on(\"data\", (chunk: string | Buffer) => {\n if (this.child !== child) return;\n this.buffer += chunk.toString();\n let newline = this.buffer.indexOf(\"\\n\");\n while (newline >= 0) {\n const line = this.buffer.slice(0, newline).replace(/^/, \"\").trim();\n this.buffer = this.buffer.slice(newline + 1);\n if (line) this.receive(line);\n newline = this.buffer.indexOf(\"\\n\");\n }\n });\n child.stdin.on(\"error\", () => undefined);\n const died = () => {\n if (this.child !== child) return;\n this.child = undefined;\n const flight = this.flight;\n if (flight) this.retryOrFail(flight, new Error(\"Windows process helper exited unexpectedly\"));\n };\n child.on(\"exit\", died);\n child.on(\"error\", died);\n return child;\n }\n\n private receive(line: string): void {\n const flight = this.flight;\n if (!flight) return;\n let reply: { id?: unknown; rows?: unknown; error?: unknown };\n try {\n reply = JSON.parse(line) as typeof reply;\n } catch {\n return; // Banner or stray output; only well-formed replies count.\n }\n if (reply.id !== flight.id) return;\n clearTimeout(flight.timer);\n this.flight = undefined;\n try {\n if (typeof reply.error === \"string\") throw new Error(reply.error);\n const rows = windowsRows(reply.rows);\n this.last = {\n at: this.now(),\n all: flight.all,\n pids: new Set(flight.pids),\n rows,\n };\n for (const waiter of flight.waiters) waiter.resolve(rows);\n } catch (error) {\n for (const waiter of flight.waiters) waiter.reject(error);\n }\n if (this.batch) this.schedule();\n }\n\n /** One automatic retry on a fresh helper; queries are read-only, so repeating is safe. */\n private retryOrFail(flight: Flight, error: unknown): void {\n clearTimeout(flight.timer);\n if (this.closed || flight.attempts >= 2) {\n if (this.flight === flight) this.flight = undefined;\n for (const waiter of flight.waiters) waiter.reject(error);\n if (this.batch && !this.closed) this.schedule();\n return;\n }\n this.discard();\n this.send(flight);\n }\n\n private failAll(error: unknown): void {\n const flight = this.flight;\n this.flight = undefined;\n clearTimeout(flight?.timer);\n const batch = this.batch;\n this.batch = undefined;\n for (const waiter of [...(flight?.waiters ?? []), ...(batch?.waiters ?? [])])\n waiter.reject(error);\n }\n\n private discard(): void {\n const child = this.child;\n this.child = undefined;\n this.last = undefined;\n if (!child) return;\n try {\n child.stdin.end();\n } catch {\n /* Already closed. */\n }\n try {\n child.kill();\n } catch {\n /* Already gone. */\n }\n }\n}\n\nexport function createWindowsHelper(options: WindowsHelperOptions = {}): WindowsProcessHelper {\n return new WindowsProcessHelper(options);\n}\n","import { spawn as spawnChild } from \"node:child_process\";\nimport { randomBytes } from \"node:crypto\";\nimport path from \"node:path\";\nimport { PassThrough, Writable } from \"node:stream\";\nimport { setTimeout as delay } from \"node:timers/promises\";\nimport { identity, owns, ProcessNotOwnedError, executeCommand, type Observation } from \"./identity\";\nimport { guardianProof, launchCommand } from \"./guardian\";\nimport {\n defaultObservationTimeoutMs,\n defaultPollIntervalMs,\n defaultSetupTimeoutMs,\n supported,\n taskkillCommand,\n} from \"./platform\";\nimport { Registry, type RegistryEntry } from \"./registry\";\nimport { createWindowsHelper, type WindowsProcessHelper } from \"./windows-helper\";\nimport {\n attachCgroup,\n cgroupMemory,\n cleanCgroup,\n recoveredCgroup,\n validateLimits,\n} from \"./resources\";\nimport type {\n ProcessExit,\n ProcessFilter,\n ProcessHandle,\n ProcessInfo,\n ProcessSupervisor,\n PtyHandle,\n RecoveryResult,\n SpawnOptions,\n SupervisorOptions,\n} from \"./types\";\n\n/** The launch failed before the child could be supervised. */\nexport class ProcessStartupError extends Error {\n /** `no-pid`: a terminal never reported a process ID. `exited`: the child exited before its gate. `setup-timeout`: the gate was not reached in time. */\n constructor(\n public readonly reason: \"no-pid\" | \"exited\" | \"setup-timeout\",\n message: string,\n ) {\n super(message);\n this.name = \"ProcessStartupError\";\n }\n}\ntype Pty = {\n pid: number;\n kill?(signal?: string): void;\n onData(listener: (data: string) => void): { dispose(): void };\n onExit(listener: (event: { exitCode: number; signal?: number }) => void): { dispose(): void };\n write(data: string): void;\n resize(columns: number, rows: number): void;\n};\ntype PtyModule = {\n spawn(\n command: string,\n args: string[],\n options: {\n cwd?: string;\n env: Record<string, string>;\n cols: number;\n rows: number;\n name: string;\n },\n ): Pty;\n};\ntype Active = {\n entry: RegistryEntry;\n handle: ProcessHandle;\n reason?: ProcessExit[\"reason\"];\n finish(code: number | null, signal: string | null): Promise<void>;\n stopping?: Promise<void>;\n timer?: ReturnType<typeof setInterval>;\n finished: boolean;\n adopted: boolean;\n fail(error: unknown): void;\n};\n\n/**\n * ConPTY reports pid 0 until the child has started. Wait for a real pid so the\n * supervisor never tracks pid 0; give up after `waitMs` with a typed error.\n */\nexport async function terminalPid(terminal: Pty, waitMs: number): Promise<number> {\n const deadline = Date.now() + waitMs;\n while (!terminal.pid && Date.now() < deadline) await delay(10);\n if (!terminal.pid)\n throw new ProcessStartupError(\n \"no-pid\",\n `Terminal did not report a process ID within ${waitMs} ms`,\n );\n return terminal.pid;\n}\n\nfunction info(entry: RegistryEntry): ProcessInfo {\n const { token: _token, start: _start, cgroup: _cgroup, gated: _gated, ...visible } = entry;\n return structuredClone(visible);\n}\nfunction validateFilter(filter: ProcessFilter): void {\n if (\n !filter ||\n typeof filter !== \"object\" ||\n Array.isArray(filter) ||\n Object.keys(filter).some((key) => key !== \"labels\")\n )\n throw new Error(\"Only label filters are supported\");\n if (\n filter.labels !== undefined &&\n (filter.labels === null ||\n typeof filter.labels !== \"object\" ||\n Array.isArray(filter.labels) ||\n !Object.values(filter.labels).every((value) => typeof value === \"string\"))\n )\n throw new Error(\"Labels must be string key/value pairs\");\n}\nfunction matches(entry: RegistryEntry, filter: ProcessFilter): boolean {\n return Object.entries(filter.labels ?? {}).every(([key, value]) => entry.labels[key] === value);\n}\n\nexport function supervisor(options: SupervisorOptions): ProcessSupervisor {\n for (const option of [\"owner\", \"registry\"] as const) {\n if (!options || typeof options[option] !== \"string\" || !options[option].trim()) {\n throw new TypeError(`Invalid supervisor configuration: ${option} must be a nonempty string`);\n }\n }\n validateLimits(options.defaults ?? {});\n // Caller-owned configuration must not change an active supervisor's identity.\n options = { ...options, defaults: { ...options.defaults } };\n const pollMs = options.pollIntervalMs ?? defaultPollIntervalMs(process.platform);\n const graceMs = options.stopGraceMs ?? 1000;\n if (!Number.isSafeInteger(pollMs) || pollMs < 10 || !Number.isSafeInteger(graceMs) || graceMs < 0)\n throw new Error(\"Invalid polling interval or stop grace period\");\n const registryPath = path.resolve(options.registry);\n // `warlock dev` can evaluate this module more than once in one process. A second supervisor over\n // the same registry would find its own process holding the lock, so reuse the live one.\n const sameProcess = sameProcessSupervisors();\n const live = sameProcess.get(registryPath);\n if (live && live.owner === options.owner) return live.api;\n const observationMs =\n options.observationTimeoutMs ?? defaultObservationTimeoutMs(process.platform);\n if (!Number.isSafeInteger(observationMs) || observationMs < 100)\n throw new Error(\"Invalid observationTimeoutMs: expected an integer of at least 100\");\n const pidWaitMs = options.pidWaitMs ?? 10_000;\n if (!Number.isSafeInteger(pidWaitMs) || pidWaitMs < 0)\n throw new Error(\"Invalid pidWaitMs: expected a nonnegative integer\");\n const setupMs = options.setupTimeoutMs ?? defaultSetupTimeoutMs(process.platform);\n if (!Number.isSafeInteger(setupMs) || setupMs < 100)\n throw new Error(\"Invalid setupTimeoutMs: expected an integer of at least 100\");\n // One helper per supervisor, created on first use and closed by stopAll().\n let helper: WindowsProcessHelper | undefined;\n function observe(): Observation {\n if (process.platform === \"win32\") helper ??= createWindowsHelper({ timeoutMs: observationMs });\n return { timeoutMs: observationMs, helper };\n }\n /** Polling tolerates a snapshot up to one interval old; signals never do. */\n function polling(): Observation {\n return { ...observe(), maxAgeMs: pollMs };\n }\n /**\n * Registry lease checks read identities too. Off Linux they go through the shared\n * helper, and a transient failure (an exiting process reports no creation time) is\n * retried instead of failing the whole operation.\n */\n async function lease(pid: number) {\n for (let attempt = 1; ; attempt++) {\n try {\n return await identity(pid, false, undefined, observe());\n } catch (error) {\n if (process.platform === \"linux\" || attempt >= 3) throw error;\n await delay(200);\n }\n }\n }\n const registry = new Registry(registryPath, options.owner, lease);\n const entries = new Map<number, RegistryEntry>();\n const active = new Map<number, Active>();\n let ready: Promise<void> | undefined;\n let closing = false;\n let shutdown: Promise<void> | undefined;\n // Serialize public operations, including shutdown, so a gated spawn cannot escape stopAll.\n let queue: Promise<unknown> = Promise.resolve();\n function serial<T>(operation: () => Promise<T>): Promise<T> {\n const next = queue.then(operation);\n queue = next.catch(() => undefined);\n return next;\n }\n async function open(): Promise<void> {\n supported(process.platform);\n if (closing) throw new Error(\"Supervisor has shut down\");\n ready ??= registry.open().then((saved) => {\n for (const entry of saved) {\n delete entry.cgroup;\n entries.set(entry.pid, entry);\n }\n });\n await ready;\n }\n const save = () => registry.save([...entries.values()]);\n\n async function signal(entry: RegistryEntry, value: NodeJS.Signals): Promise<void> {\n if (!(await owns(entry, observe()))) throw new ProcessNotOwnedError(entry.pid);\n if (process.platform !== \"linux\" && value === \"SIGCONT\") {\n const proof = await guardianProof(entry.pid, entry.token, entry.token, observationMs);\n if (!proof || proof.token !== entry.token || proof.gated)\n throw new ProcessNotOwnedError(entry.pid);\n return;\n }\n if (process.platform === \"win32\") {\n try {\n await executeCommand(taskkillCommand(entry.pid));\n } catch (error) {\n if (await owns(entry, observe())) throw error;\n }\n return;\n }\n // Negative PID targets only the session/group established for this child.\n // Recheck for every signal, including escalation; never match a command line.\n try {\n process.kill(-entry.pid, value);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ESRCH\") throw error;\n }\n }\n /**\n * A process that is exiting can still be listed for a moment after its guardian\n * (and so its token) is gone. Read fresh a few times; only a process that has\n * disappeared counts as gone, and a live one keeps its not-owned failure.\n */\n async function gone(pid: number): Promise<boolean> {\n for (let attempt = 0; attempt < 5; attempt++) {\n if (!(await identity(pid, false, undefined, observe()))) return true;\n await delay(100);\n }\n return false;\n }\n /**\n * Right after SIGCONT the launcher is replacing itself with the workload\n * (exec). For that instant the kernel reports an empty memory map and\n * environment, so a live, owned process momentarily fails verification. A\n * handle returned by launch() must always be stoppable, so wait that window\n * out; a process that stays unverified is still refused.\n */\n async function ownsSettled(entry: RegistryEntry): Promise<boolean> {\n for (let attempt = 0; attempt < 25; attempt++) {\n if (await owns(entry, observe())) return true;\n await delay(20);\n }\n return false;\n }\n async function stopEntry(\n entry: RegistryEntry,\n reason: ProcessExit[\"reason\"] = \"stopped\",\n ): Promise<void> {\n const tracked = active.get(entry.pid);\n let running: Active;\n if (!tracked) {\n if (!(await owns(entry, observe()))) throw new ProcessNotOwnedError(entry.pid);\n entry.cgroup = await recoveredCgroup(entry.pid, entry.token);\n running = track(entry);\n } else running = tracked;\n if (running.finished) return running.finish(null, null);\n if (running.stopping) return running.stopping;\n const stopping = (async () => {\n if (!(await ownsSettled(entry))) throw new ProcessNotOwnedError(entry.pid);\n running.reason ??= reason;\n await signal(entry, \"SIGTERM\");\n const deadline = Date.now() + graceMs;\n while (await owns(entry, observe())) {\n if (Date.now() >= deadline) {\n await signal(entry, \"SIGKILL\");\n break;\n }\n await delay(20);\n }\n const killedDeadline = Date.now() + 5000;\n while (await owns(entry, observe())) {\n if (Date.now() >= killedDeadline)\n throw new Error(`Process ${entry.pid} did not exit after SIGKILL`);\n await delay(20);\n }\n await running.finish(null, null);\n })();\n running.stopping = stopping;\n try {\n await stopping;\n } catch (error) {\n running.stopping = undefined;\n // The leader may exit between identity verification and a signal. A\n // missing identity is harmless for a tracked handle; a live mismatch is\n // still an ownership failure and must never receive another signal.\n if (error instanceof ProcessNotOwnedError && (await gone(entry.pid))) {\n await running.finish(null, null);\n return;\n }\n throw error;\n }\n }\n\n function track(\n entry: RegistryEntry,\n streams?: Pick<ProcessHandle, \"stdin\" | \"stdout\" | \"stderr\">,\n ): Active {\n let resolveExit: (exit: ProcessExit) => void = () => undefined;\n let rejectExit: (error: unknown) => void = () => undefined;\n const exited = new Promise<ProcessExit>((resolve, reject) => {\n resolveExit = resolve;\n rejectExit = reject;\n });\n // A rejected persistence operation is still observable through handle.exited.\n void exited.catch(() => undefined);\n const stdout = streams?.stdout ?? new PassThrough();\n const stderr = streams?.stderr ?? new PassThrough();\n const stdin = streams?.stdin ?? new PassThrough();\n let finishing: Promise<void> | undefined;\n const running: Active = {\n entry,\n finished: false,\n adopted: !streams,\n fail: (error) => rejectExit(error),\n handle: {\n pid: entry.pid,\n stdout,\n stderr,\n stdin,\n exited,\n stop: () =>\n serial(async () => {\n if (!running.finished) await stopEntry(entry);\n }),\n },\n finish(code, sig) {\n finishing ??= (async () => {\n running.finished = true;\n clearInterval(running.timer);\n if (entry.cgroup) {\n const memory = await cgroupMemory(entry.cgroup);\n entry.peakMemoryBytes = Math.max(entry.peakMemoryBytes, memory.peak);\n if (memory.oom) running.reason = \"memory-cap\";\n await cleanCgroup(entry.cgroup);\n }\n active.delete(entry.pid);\n entries.delete(entry.pid);\n try {\n await save();\n resolveExit({\n reason: running.reason ?? \"exit\",\n code,\n signal: sig,\n peakMemoryBytes: entry.peakMemoryBytes,\n });\n } catch (error) {\n rejectExit(error);\n throw error;\n }\n if (!streams) {\n (stdout as PassThrough).end();\n (stderr as PassThrough).end();\n stdin.end();\n }\n })();\n return finishing;\n },\n };\n active.set(entry.pid, running);\n return running;\n }\n\n function monitor(running: Active): void {\n if (running.finished) return;\n let sampling = false;\n const sample = async () => {\n if (sampling || running.finished) return;\n sampling = true;\n try {\n const entry = running.entry;\n let current = await identity(entry.pid, true, entry.token, polling());\n const matches = (value: typeof current) =>\n value?.start === entry.start && value.token === entry.token && value.group === entry.pid;\n // A snapshot taken while the process was exiting can still list it after\n // its guardian is gone. Before calling a mismatch a failure, read fresh\n // (no snapshot) a few times; a process that vanished simply exited.\n for (let attempt = 0; current && !matches(current) && attempt < 3; attempt++) {\n if (running.finished) return;\n await delay(50);\n current = await identity(entry.pid, true, entry.token, observe());\n }\n if (running.finished) return;\n if (\n current?.start !== entry.start ||\n current.token !== entry.token ||\n current.group !== entry.pid\n ) {\n if (!current) {\n if (running.adopted) await running.finish(null, null);\n } else {\n // A live child that changes its environment or group can no longer\n // be supervised safely. Preserve the entry and surface the failure.\n throw new ProcessNotOwnedError(entry.pid);\n }\n return;\n }\n entry.peakMemoryBytes = Math.max(entry.peakMemoryBytes, current.rss);\n if (entry.cgroup) {\n const memory = await cgroupMemory(entry.cgroup);\n if (running.finished) return;\n entry.peakMemoryBytes = Math.max(entry.peakMemoryBytes, memory.peak);\n if (memory.oom) running.reason = \"memory-cap\";\n }\n if (entry.limits.memoryBytes && entry.peakMemoryBytes > entry.limits.memoryBytes)\n await stopEntry(entry, \"memory-cap\");\n else if (entry.limits.timeoutMs && Date.now() - entry.startedAt >= entry.limits.timeoutMs)\n await stopEntry(entry, \"timeout\");\n } finally {\n sampling = false;\n }\n };\n running.timer = setInterval(() => {\n void sample().catch((error: unknown) => {\n // Never signal on an observation error. Surface it to the caller and keep the registry.\n clearInterval(running.timer);\n if (!running.finished) running.fail(error);\n });\n }, pollMs);\n running.timer.unref();\n }\n\n async function launch(\n input: SpawnOptions & { columns?: number; rows?: number },\n terminal: boolean,\n ): Promise<ProcessHandle | PtyHandle> {\n await open();\n if ([...entries.keys()].some((pid) => !active.has(pid)))\n throw new Error(\"Call recover() before spawning with an existing registry\");\n if (\n typeof input.command !== \"string\" ||\n !input.command ||\n typeof input.kind !== \"string\" ||\n !input.kind\n )\n throw new Error(\"kind and command are required\");\n validateFilter({ labels: input.labels });\n if (\n terminal &&\n [input.columns ?? 80, input.rows ?? 24].some(\n (size) => !Number.isSafeInteger(size) || size <= 0,\n )\n )\n throw new Error(\"Terminal dimensions must be positive safe integers\");\n const limits = { ...options.defaults, ...input.limits };\n validateLimits(limits);\n const token = randomBytes(32).toString(\"hex\");\n const {\n file: executable,\n args,\n env,\n } = launchCommand(\n process.platform,\n process.execPath,\n input.command,\n input.args ?? [],\n limits,\n { ...process.env, ...input.env },\n token,\n );\n let pid: number;\n let streams: Pick<ProcessHandle, \"stdin\" | \"stdout\" | \"stderr\">;\n let terminalProcess: Pty | undefined;\n let exit: { code: number | null; signal: string | null } | undefined;\n let spawnError: Error | undefined;\n let running: Active | undefined;\n const onExit = (code: number | null, sig: string | null) => {\n exit = { code, signal: sig };\n if (running) void running.finish(code, sig).catch(() => undefined);\n };\n if (terminal) {\n // Optional peer loaded only here. Structural types follow node-pty's official typings.\n const peer = \"node-pty\";\n const pty = (await import(peer)) as PtyModule;\n terminalProcess = pty.spawn(executable, args, {\n cwd: input.cwd,\n env: Object.fromEntries(\n Object.entries(env).filter((pair): pair is [string, string] => pair[1] !== undefined),\n ),\n cols: input.columns ?? 80,\n rows: input.rows ?? 24,\n name: \"xterm-256color\",\n });\n try {\n pid = await terminalPid(terminalProcess, pidWaitMs);\n } catch (error) {\n try {\n terminalProcess.kill?.();\n } catch {\n /* Best effort: the child has no reported pid to verify. */\n }\n throw error;\n }\n const output = new PassThrough();\n const errors = new PassThrough();\n const instance = terminalProcess;\n const dataSubscription = instance.onData((data) => output.write(data));\n const inputStream = new Writable({\n write(chunk: Buffer, _encoding, callback) {\n instance.write(chunk.toString());\n callback();\n },\n });\n const exitSubscription = instance.onExit((event) => {\n dataSubscription.dispose();\n exitSubscription.dispose();\n output.end();\n errors.end();\n inputStream.end();\n onExit(event.exitCode, event.signal ? String(event.signal) : null);\n });\n streams = { stdout: output, stderr: errors, stdin: inputStream };\n } else {\n const child = spawnChild(executable, args, {\n cwd: input.cwd,\n env,\n detached: process.platform !== \"win32\",\n windowsHide: true,\n stdio: \"pipe\",\n });\n child.on(\"error\", (error) => {\n spawnError = error;\n });\n // Finish on leader exit so cgroup cleanup can stop remaining members;\n // waiting for close could deadlock on a descendant holding a pipe open.\n child.on(\"exit\", onExit);\n if (!child.pid) throw new Error(\"Could not start process\");\n pid = child.pid;\n streams = { stdout: child.stdout, stderr: child.stderr, stdin: child.stdin };\n }\n let entry: RegistryEntry | undefined;\n try {\n const deadline = Date.now() + setupMs;\n // Off Linux an identity read costs a helper query, so poll the guardian's\n // pipe (cheap) until it reports the gate, and read the identity once.\n const portable = process.platform !== \"linux\";\n const gate = async () => {\n if (portable) {\n const proof = await guardianProof(pid, undefined, token, observationMs);\n if (!proof?.gated) return undefined;\n }\n return identity(pid, true, token, observe());\n };\n let current = await gate();\n while (!current?.state.startsWith(\"T\") || current.token !== token) {\n if (spawnError) throw spawnError;\n if (exit)\n throw new ProcessStartupError(\"exited\", \"Child failed to reach the resource setup gate\");\n if (Date.now() >= deadline)\n throw new ProcessStartupError(\n \"setup-timeout\",\n \"Child failed to reach the resource setup gate\",\n );\n await delay(10);\n current = await gate();\n }\n if (current.group !== pid) throw new Error(\"Child did not create an isolated process group\");\n entry = {\n pid,\n owner: options.owner,\n type: input.kind,\n command: input.command,\n args: [...(input.args ?? [])],\n labels: { ...input.labels },\n startedAt: Date.now(),\n limits,\n enforcement: process.platform === \"win32\" ? \"rss-polling\" : \"rlimit-polling\",\n peakMemoryBytes: current.rss,\n token,\n start: current.start,\n gated: true,\n };\n entry.cgroup = await attachCgroup(pid, token, limits, options.cgroupRoot);\n if (entry.cgroup) entry.enforcement = \"cgroup-v2\";\n entries.set(pid, entry);\n await save();\n running = track(entry, streams);\n await signal(entry, \"SIGCONT\");\n delete entry.gated;\n await save();\n monitor(running);\n if (terminalProcess) {\n const instance = terminalProcess;\n return {\n ...running.handle,\n write: (data: string) => instance.write(data),\n resize: (columns: number, rows: number) => instance.resize(columns, rows),\n };\n }\n return running.handle;\n } catch (error) {\n // This PID was created by this call. Kill only after its random token is verified.\n const current = await identity(pid, true, token, observe());\n if (current?.token === token) {\n const failed = { pid, token, start: current.start };\n if (await owns(failed, observe())) {\n try {\n if (process.platform === \"win32\") await executeCommand(taskkillCommand(pid));\n else process.kill(-pid, \"SIGKILL\");\n } catch {\n /* Already exited. */\n }\n }\n }\n if (entry && !running) {\n entries.delete(pid);\n await save();\n }\n if (entry?.cgroup) await cleanCgroup(entry.cgroup);\n throw error;\n }\n }\n\n const api: ProcessSupervisor = {\n spawn: (input) => serial(() => launch(input, false)),\n spawnPty: (input) => serial(async () => (await launch(input, true)) as PtyHandle),\n list: (filter = {}) =>\n serial(async () => {\n validateFilter(filter);\n await open();\n return [...entries.values()].filter((entry) => matches(entry, filter)).map(info);\n }),\n stop: (filter = {}) =>\n serial(async () => {\n validateFilter(filter);\n await open();\n for (const entry of [...entries.values()].filter((entry) => matches(entry, filter)))\n await stopEntry(entry);\n }),\n stopPid: (pid) =>\n serial(async () => {\n await open();\n const entry = entries.get(pid);\n if (!entry) throw new ProcessNotOwnedError(pid);\n await stopEntry(entry);\n }),\n recover: (recovery = {}) =>\n serial(async () => {\n await open();\n const result: RecoveryResult = { adopted: [], stopped: [], cleared: [] };\n for (const entry of [...entries.values()]) {\n if (active.has(entry.pid)) continue;\n if (!(await owns(entry, observe()))) {\n entries.delete(entry.pid);\n result.cleared.push(entry.pid);\n continue;\n }\n // Never trust a persisted filesystem path for cgroup I/O after a restart.\n entry.cgroup = await recoveredCgroup(entry.pid, entry.token);\n entry.enforcement = entry.cgroup\n ? \"cgroup-v2\"\n : process.platform === \"win32\"\n ? \"rss-polling\"\n : \"rlimit-polling\";\n const keep = await recovery.keep?.(info(entry));\n if (keep) {\n const running = track(entry);\n monitor(running);\n if (entry.gated) {\n await signal(entry, \"SIGCONT\");\n delete entry.gated;\n }\n result.adopted.push(entry.pid);\n } else {\n await stopEntry(entry);\n result.stopped.push(entry.pid);\n }\n }\n await save();\n return result;\n }),\n stopAll() {\n shutdown ??= serial(async () => {\n await open();\n closing = true;\n try {\n const errors: unknown[] = [];\n for (const entry of [...entries.values()]) {\n try {\n if (await owns(entry, observe())) await stopEntry(entry);\n else {\n const running = active.get(entry.pid);\n if (running) await running.finish(null, null);\n else entries.delete(entry.pid);\n }\n } catch (error) {\n errors.push(error);\n }\n }\n await save();\n if (errors.length)\n throw new AggregateError(errors, \"Some owned processes could not be stopped\");\n } finally {\n await helper?.close();\n await registry.close();\n }\n });\n return shutdown;\n },\n };\n const stopAll = api.stopAll;\n api.stopAll = () => {\n const stopping = stopAll();\n const forget = () => {\n if (sameProcess.get(registryPath)?.api === api) sameProcess.delete(registryPath);\n };\n stopping.then(forget, forget);\n return stopping;\n };\n sameProcess.set(registryPath, { owner: options.owner, api });\n return api;\n}\n\nconst SUPERVISORS = Symbol.for(\"@warlock.js/process.supervisors\");\n\n/** Live supervisors of this process by registry path; shared by every copy of this module. */\nfunction sameProcessSupervisors(): Map<string, { owner: string; api: ProcessSupervisor }> {\n const holder = globalThis as unknown as Record<symbol, Map<string, any> | undefined>;\n return (holder[SUPERVISORS] ??= new Map());\n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OACpC,IAAI,SAAS,MAAM,QAAQ,OAAO,MAAM,IAAI;YACvC,QAAQ,OAAO,MAAM,GAAG;MAC/B;KACF,SAAS,OAAO;MACd,OAAO,KAAK,KAAK;KACnB;KAEF,MAAM,KAAK;KACX,IAAI,OAAO,QACT,MAAM,IAAI,eAAe,QAAQ,2CAA2C;IAChF,UAAU;KACR,MAAM,QAAQ,MAAM;KACpB,MAAM,SAAS,MAAM;IACvB;GACF,CAAC;GACD,OAAO;EACT;CACF;CACA,MAAM,UAAU,IAAI;CACpB,IAAI,gBAAgB;EAClB,MAAM,WAAW,QAAQ;EACzB,MAAM,eAAe;GACnB,IAAI,YAAY,IAAI,YAAY,CAAC,EAAE,QAAQ,KAAK,YAAY,OAAO,YAAY;EACjF;EACA,SAAS,KAAK,QAAQ,MAAM;EAC5B,OAAO;CACT;CACA,YAAY,IAAI,cAAc;EAAE,OAAO,QAAQ;EAAO;CAAI,CAAC;CAC3D,OAAO;AACT;AAEA,MAAM,cAAc,OAAO,IAAI,iCAAiC;;AAGhE,SAAS,yBAAiF;CACxF,MAAM,SAAS;CACf,OAAQ,OAAO,iCAAiB,IAAI,IAAI;AAC1C"}
|
package/esm/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ProcessExit, ProcessFilter, ProcessHandle, ProcessInfo, ProcessLimits, ProcessSupervisor, PtyHandle, RecoveryResult, SpawnOptions, SupervisorOptions } from "./types.mjs";
|
|
2
|
-
import { supervisor } from "./supervisor.mjs";
|
|
2
|
+
import { ProcessStartupError, supervisor } from "./supervisor.mjs";
|
|
3
3
|
import { UnsupportedProcessPlatformError } from "./platform.mjs";
|
|
4
4
|
import { ProcessNotOwnedError } from "./identity.mjs";
|
|
5
|
-
export { type ProcessExit, type ProcessFilter, type ProcessHandle, type ProcessInfo, type ProcessLimits, ProcessNotOwnedError, type ProcessSupervisor, type PtyHandle, type RecoveryResult, type SpawnOptions, type SupervisorOptions, UnsupportedProcessPlatformError, supervisor };
|
|
5
|
+
export { type ProcessExit, type ProcessFilter, type ProcessHandle, type ProcessInfo, type ProcessLimits, ProcessNotOwnedError, ProcessStartupError, type ProcessSupervisor, type PtyHandle, type RecoveryResult, type SpawnOptions, type SupervisorOptions, UnsupportedProcessPlatformError, supervisor };
|
package/esm/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UnsupportedProcessPlatformError } from "./platform.mjs";
|
|
2
2
|
import { ProcessNotOwnedError } from "./identity.mjs";
|
|
3
|
-
import { supervisor } from "./supervisor.mjs";
|
|
3
|
+
import { ProcessStartupError, supervisor } from "./supervisor.mjs";
|
|
4
4
|
|
|
5
|
-
export { ProcessNotOwnedError, UnsupportedProcessPlatformError, supervisor };
|
|
5
|
+
export { ProcessNotOwnedError, ProcessStartupError, UnsupportedProcessPlatformError, supervisor };
|
package/esm/platform.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.d.mts","names":[],"sources":["../../../../../../../packages/process/src/platform.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"platform.d.mts","names":[],"sources":["../../../../../../../packages/process/src/platform.ts"],"mappings":";qBAoCa,wCAAwC;WACvB;EAA5B,YAA4B"}
|
package/esm/platform.mjs
CHANGED
|
@@ -11,6 +11,13 @@ function defaultPollIntervalMs(platform) {
|
|
|
11
11
|
function defaultObservationTimeoutMs(platform) {
|
|
12
12
|
return platform === "win32" || platform === "darwin" ? 15e3 : 2e3;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Longest wait for a launched child to reach the resource setup gate. Linux answers
|
|
16
|
+
* from /proc; Windows and macOS answer through the guardian and helpers under load.
|
|
17
|
+
*/
|
|
18
|
+
function defaultSetupTimeoutMs(platform) {
|
|
19
|
+
return platform === "linux" ? 5e3 : 3e4;
|
|
20
|
+
}
|
|
14
21
|
var UnsupportedProcessPlatformError = class extends Error {
|
|
15
22
|
platform;
|
|
16
23
|
constructor(platform) {
|
|
@@ -168,5 +175,5 @@ async function portableIdentity(platform, pid, token, execute, readProof, source
|
|
|
168
175
|
}
|
|
169
176
|
|
|
170
177
|
//#endregion
|
|
171
|
-
export { UnsupportedProcessPlatformError, darwinCommand, defaultObservationTimeoutMs, defaultPollIntervalMs, parseDarwinRows, parseDarwinStart, parseWindowsRows, portableIdentity, supported, taskkillCommand, treeMemory, windowsCommand, windowsRows };
|
|
178
|
+
export { UnsupportedProcessPlatformError, darwinCommand, defaultObservationTimeoutMs, defaultPollIntervalMs, defaultSetupTimeoutMs, parseDarwinRows, parseDarwinStart, parseWindowsRows, portableIdentity, supported, taskkillCommand, treeMemory, windowsCommand, windowsRows };
|
|
172
179
|
//# sourceMappingURL=platform.mjs.map
|
package/esm/platform.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.mjs","names":[],"sources":["../../../../../../../packages/process/src/platform.ts"],"sourcesContent":["import type { Identity } from \"./identity\";\n\nexport type PortablePlatform = \"darwin\" | \"win32\";\nexport type Command = { file: string; args: string[]; env?: Record<string, string> };\nexport type Execute = (command: Command) => Promise<string>;\nexport type OwnershipProof = { pid: number; token: string; gated: boolean };\nexport type ReadProof = (pid: number) => Promise<OwnershipProof | undefined>;\nexport type Row = {\n pid: number;\n parent: number;\n start: string;\n rss: number;\n group: number;\n state: string;\n};\n\n/**\n * Defaults per platform. Linux reads /proc directly, so it is cheap to poll\n * often and a guardian reply is never awaited. Windows and macOS observe\n * through helper programs and a named pipe, which need more time and a slower\n * poll to stay out of the workload's way.\n */\nexport function defaultPollIntervalMs(platform: string): number {\n return platform === \"win32\" ? 1500 : platform === \"darwin\" ? 500 : 100;\n}\nexport function defaultObservationTimeoutMs(platform: string): number {\n return platform === \"win32\" || platform === \"darwin\" ? 15_000 : 2000;\n}\n\nexport class UnsupportedProcessPlatformError extends Error {\n constructor(public readonly platform: string) {\n super(`Process supervision is unsupported on ${platform}`);\n this.name = \"UnsupportedProcessPlatformError\";\n }\n}\nexport function supported(platform: string): void {\n if (![\"linux\", \"darwin\", \"win32\"].includes(platform))\n throw new UnsupportedProcessPlatformError(platform);\n}\nfunction validPid(pid: number): void {\n if (!Number.isSafeInteger(pid) || pid <= 1) throw new Error(\"Invalid process PID\");\n}\n\n/** Apple ps(1): lstart uses strftime %c. LC_ALL=C gives %a %b %e %H:%M:%S %Y.\n * https://github.com/apple-oss-distributions/adv_cmds/blob/main/ps/ps.1\n * https://github.com/apple-oss-distributions/adv_cmds/blob/main/ps/print.c (lstarted)\n * https://github.com/apple-oss-distributions/Libc/blob/main/stdtime/FreeBSD/timelocal.c (_C_time_locale)\n */\nexport function parseDarwinStart(source: string): string {\n const match =\n /^(Sun|Mon|Tue|Wed|Thu|Fri|Sat) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\s+(\\d{1,2}) (\\d{2}):(\\d{2}):(\\d{2}) (\\d{4})$/.exec(\n source.trim(),\n );\n if (!match) throw new Error(\"Invalid macOS process start time\");\n const [, weekday, month, day, hour, minute, second, year] = match;\n const monthIndex = \"Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec\"\n .split(\" \")\n .indexOf(month ?? \"\");\n const date = new Date(\n Date.UTC(Number(year), monthIndex, Number(day), Number(hour), Number(minute), Number(second)),\n );\n if (\n date.getUTCFullYear() !== Number(year) ||\n date.getUTCMonth() !== monthIndex ||\n date.getUTCDate() !== Number(day) ||\n date.getUTCHours() !== Number(hour) ||\n date.getUTCMinutes() !== Number(minute) ||\n date.getUTCSeconds() !== Number(second) ||\n \"Sun Mon Tue Wed Thu Fri Sat\".split(\" \")[date.getUTCDay()] !== weekday\n )\n throw new Error(\"Invalid macOS process start time\");\n return String(date.getTime() / 1000);\n}\nexport function darwinCommand(pid: number, tree = false): Command {\n validPid(pid);\n return {\n file: \"/bin/ps\",\n args: [...(tree ? [\"-ax\"] : [\"-p\", String(pid)]), \"-o\", \"pid=,ppid=,pgid=,state=,rss=,lstart=\"],\n env: { LC_ALL: \"C\", TZ: \"UTC\" },\n };\n}\nexport function parseDarwinRows(source: string): Row[] {\n return source.trim()\n ? source\n .trim()\n .split(\"\\n\")\n .map((line) => {\n const match = /^\\s*(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\S+)\\s+(\\d+)\\s+(.+?)\\s*$/.exec(line);\n if (!match) throw new Error(\"Invalid macOS process observation\");\n return {\n pid: Number(match[1]),\n parent: Number(match[2]),\n group: Number(match[3]),\n state: match[4] ?? \"\",\n rss: Number(match[5]) * 1024,\n start: parseDarwinStart(match[6] ?? \"\"),\n };\n })\n : [];\n}\n\n/** CIM CreationDate is a DateTime; serialize UTC ticks as text, never a locale date\n * or JSON number (100ns ticks exceed Number's precision). WorkingSetSize is bytes.\n * https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-process\n */\nexport function windowsCommand(pid: number, tree = false): Command {\n validPid(pid);\n const query = `Get-CimInstance Win32_Process${tree ? \"\" : ` -Filter 'ProcessId=${pid}'`}`;\n const script = [\n \"$ErrorActionPreference = 'Stop'\",\n `$rows = @(${query} | ForEach-Object {`,\n `if ([int]$_.ProcessId -eq ${pid} -and $null -eq $_.CreationDate) { throw 'Cannot read process creation time' }`,\n \"if ($null -ne $_.CreationDate) {\",\n \"[pscustomobject]@{ pid = [int]$_.ProcessId; parent = [int]$_.ParentProcessId; start = $_.CreationDate.ToUniversalTime().Ticks.ToString([Globalization.CultureInfo]::InvariantCulture); rss = [double]$_.WorkingSetSize }\",\n \"}\",\n \"})\",\n \"ConvertTo-Json -InputObject $rows -Compress\",\n ].join(\"\\n\");\n return {\n file: \"powershell.exe\",\n args: [\"-NoLogo\", \"-NoProfile\", \"-NonInteractive\", \"-Command\", script],\n };\n}\nexport function parseWindowsRows(source: string): Row[] {\n return windowsRows(JSON.parse(source.replace(/^\\uFEFF/, \"\")));\n}\n/** Validates rows decoded from PowerShell, whether one-shot or from the long-lived helper. */\nexport function windowsRows(value: unknown): Row[] {\n if (!Array.isArray(value)) throw new Error(\"Invalid Windows process observation\");\n return value.map((row: unknown) => {\n if (\n !row ||\n typeof row !== \"object\" ||\n !(\"pid\" in row) ||\n typeof row.pid !== \"number\" ||\n !Number.isSafeInteger(row.pid) ||\n row.pid < 0 ||\n !(\"parent\" in row) ||\n typeof row.parent !== \"number\" ||\n !Number.isSafeInteger(row.parent) ||\n row.parent < 0 ||\n !(\"start\" in row) ||\n typeof row.start !== \"string\" ||\n !/^\\d{18}$/.test(row.start) ||\n !(\"rss\" in row) ||\n typeof row.rss !== \"number\" ||\n !Number.isFinite(row.rss) ||\n row.rss < 0\n )\n throw new Error(\"Invalid Windows process observation\");\n return {\n pid: row.pid,\n parent: row.parent,\n start: row.start,\n rss: row.rss,\n group: row.pid,\n state: \"R\",\n };\n });\n}\nexport function taskkillCommand(pid: number): Command {\n validPid(pid);\n // Never accept an image name, filter, wildcard or shell interpolation.\n return { file: \"taskkill.exe\", args: [\"/PID\", String(pid), \"/T\", \"/F\"] };\n}\nexport function treeMemory(rows: Row[], pid: number): number {\n const root = rows.find((row) => row.pid === pid);\n if (!root) return 0;\n const included = new Map<number, Row>([[pid, root]]);\n let changed = true;\n while (changed) {\n changed = false;\n for (const row of rows) {\n const parent = included.get(row.parent);\n // Reject a reused parent PID whose creation time is later than the child.\n if (!included.has(row.pid) && parent && BigInt(row.start) >= BigInt(parent.start)) {\n included.set(row.pid, row);\n changed = true;\n }\n }\n }\n return [...included.values()].reduce((total, row) => total + row.rss, 0);\n}\n\n/** Reads process rows. `tree` asks for the whole table; `maxAgeMs` accepts a recent snapshot. */\nexport type RowSource = (pids: number[], tree: boolean, maxAgeMs?: number) => Promise<Row[]>;\n\n/** All OS effects are injected; foreign-platform specs never execute real commands. */\nexport async function portableIdentity(\n platform: PortablePlatform,\n pid: number,\n token: boolean,\n execute: Execute,\n readProof: ReadProof,\n source?: RowSource,\n maxAgeMs = 0,\n): Promise<Identity | undefined> {\n validPid(pid);\n const command = platform === \"darwin\" ? darwinCommand : windowsCommand;\n const parse = platform === \"darwin\" ? parseDarwinRows : parseWindowsRows;\n const read: RowSource =\n source ?? (async (pids, tree) => parse(await execute(command(pids[0] ?? pid, tree))));\n const rows = await read([pid], token, maxAgeMs);\n const before = rows.find((row) => row.pid === pid);\n if (!before || /^[ZX]/.test(before.state)) return undefined;\n if (!token) return before;\n const proof = await readProof(pid);\n const after = (await read([pid], false, maxAgeMs)).find((row) => row.pid === pid);\n if (\n !after ||\n after.start !== before.start ||\n after.group !== before.group ||\n /^[ZX]/.test(after.state)\n )\n return undefined;\n return {\n start: after.start,\n group: after.group,\n state: proof?.pid === pid && proof.gated ? \"T\" : after.state,\n rss: treeMemory(rows, pid),\n token: proof?.pid === pid ? proof.token : undefined,\n };\n}\n"],"mappings":";;;;;;;AAsBA,SAAgB,sBAAsB,UAA0B;CAC9D,OAAO,aAAa,UAAU,OAAO,aAAa,WAAW,MAAM;AACrE;AACA,SAAgB,4BAA4B,UAA0B;CACpE,OAAO,aAAa,WAAW,aAAa,WAAW,OAAS;AAClE;AAEA,IAAa,kCAAb,cAAqD,MAAM;CAC7B;CAA5B,YAAY,AAAgB,UAAkB;EAC5C,MAAM,yCAAyC,UAAU;EAD/B;EAE1B,KAAK,OAAO;CACd;AACF;AACA,SAAgB,UAAU,UAAwB;CAChD,IAAI,CAAC;EAAC;EAAS;EAAU;CAAO,CAAC,CAAC,SAAS,QAAQ,GACjD,MAAM,IAAI,gCAAgC,QAAQ;AACtD;AACA,SAAS,SAAS,KAAmB;CACnC,IAAI,CAAC,OAAO,cAAc,GAAG,KAAK,OAAO,GAAG,MAAM,IAAI,MAAM,qBAAqB;AACnF;;;;;;AAOA,SAAgB,iBAAiB,QAAwB;CACvD,MAAM,QACJ,gIAAgI,KAC9H,OAAO,KAAK,CACd;CACF,IAAI,CAAC,OAAO,MAAM,IAAI,MAAM,kCAAkC;CAC9D,MAAM,GAAG,SAAS,OAAO,KAAK,MAAM,QAAQ,QAAQ,QAAQ;CAC5D,MAAM,aAAa,kDAChB,M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KAAK,GAExB,OAAO;CACT,OAAO;EACL,OAAO,MAAM;EACb,OAAO,MAAM;EACb,OAAO,OAAO,QAAQ,OAAO,MAAM,QAAQ,MAAM,MAAM;EACvD,KAAK,WAAW,MAAM,GAAG;EACzB,OAAO,OAAO,QAAQ,MAAM,MAAM,QAAQ;CAC5C;AACF"}
|
|
1
|
+
{"version":3,"file":"platform.mjs","names":[],"sources":["../../../../../../../packages/process/src/platform.ts"],"sourcesContent":["import type { Identity } from \"./identity\";\n\nexport type PortablePlatform = \"darwin\" | \"win32\";\nexport type Command = { file: string; args: string[]; env?: Record<string, string> };\nexport type Execute = (command: Command) => Promise<string>;\nexport type OwnershipProof = { pid: number; token: string; gated: boolean };\nexport type ReadProof = (pid: number) => Promise<OwnershipProof | undefined>;\nexport type Row = {\n pid: number;\n parent: number;\n start: string;\n rss: number;\n group: number;\n state: string;\n};\n\n/**\n * Defaults per platform. Linux reads /proc directly, so it is cheap to poll\n * often and a guardian reply is never awaited. Windows and macOS observe\n * through helper programs and a named pipe, which need more time and a slower\n * poll to stay out of the workload's way.\n */\nexport function defaultPollIntervalMs(platform: string): number {\n return platform === \"win32\" ? 1500 : platform === \"darwin\" ? 500 : 100;\n}\nexport function defaultObservationTimeoutMs(platform: string): number {\n return platform === \"win32\" || platform === \"darwin\" ? 15_000 : 2000;\n}\n/**\n * Longest wait for a launched child to reach the resource setup gate. Linux answers\n * from /proc; Windows and macOS answer through the guardian and helpers under load.\n */\nexport function defaultSetupTimeoutMs(platform: string): number {\n return platform === \"linux\" ? 5000 : 30_000;\n}\n\nexport class UnsupportedProcessPlatformError extends Error {\n constructor(public readonly platform: string) {\n super(`Process supervision is unsupported on ${platform}`);\n this.name = \"UnsupportedProcessPlatformError\";\n }\n}\nexport function supported(platform: string): void {\n if (![\"linux\", \"darwin\", \"win32\"].includes(platform))\n throw new UnsupportedProcessPlatformError(platform);\n}\nfunction validPid(pid: number): void {\n if (!Number.isSafeInteger(pid) || pid <= 1) throw new Error(\"Invalid process PID\");\n}\n\n/** Apple ps(1): lstart uses strftime %c. LC_ALL=C gives %a %b %e %H:%M:%S %Y.\n * https://github.com/apple-oss-distributions/adv_cmds/blob/main/ps/ps.1\n * https://github.com/apple-oss-distributions/adv_cmds/blob/main/ps/print.c (lstarted)\n * https://github.com/apple-oss-distributions/Libc/blob/main/stdtime/FreeBSD/timelocal.c (_C_time_locale)\n */\nexport function parseDarwinStart(source: string): string {\n const match =\n /^(Sun|Mon|Tue|Wed|Thu|Fri|Sat) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\s+(\\d{1,2}) (\\d{2}):(\\d{2}):(\\d{2}) (\\d{4})$/.exec(\n source.trim(),\n );\n if (!match) throw new Error(\"Invalid macOS process start time\");\n const [, weekday, month, day, hour, minute, second, year] = match;\n const monthIndex = \"Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec\"\n .split(\" \")\n .indexOf(month ?? \"\");\n const date = new Date(\n Date.UTC(Number(year), monthIndex, Number(day), Number(hour), Number(minute), Number(second)),\n );\n if (\n date.getUTCFullYear() !== Number(year) ||\n date.getUTCMonth() !== monthIndex ||\n date.getUTCDate() !== Number(day) ||\n date.getUTCHours() !== Number(hour) ||\n date.getUTCMinutes() !== Number(minute) ||\n date.getUTCSeconds() !== Number(second) ||\n \"Sun Mon Tue Wed Thu Fri Sat\".split(\" \")[date.getUTCDay()] !== weekday\n )\n throw new Error(\"Invalid macOS process start time\");\n return String(date.getTime() / 1000);\n}\nexport function darwinCommand(pid: number, tree = false): Command {\n validPid(pid);\n return {\n file: \"/bin/ps\",\n args: [...(tree ? [\"-ax\"] : [\"-p\", String(pid)]), \"-o\", \"pid=,ppid=,pgid=,state=,rss=,lstart=\"],\n env: { LC_ALL: \"C\", TZ: \"UTC\" },\n };\n}\nexport function parseDarwinRows(source: string): Row[] {\n return source.trim()\n ? source\n .trim()\n .split(\"\\n\")\n .map((line) => {\n const match = /^\\s*(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\S+)\\s+(\\d+)\\s+(.+?)\\s*$/.exec(line);\n if (!match) throw new Error(\"Invalid macOS process observation\");\n return {\n pid: Number(match[1]),\n parent: Number(match[2]),\n group: Number(match[3]),\n state: match[4] ?? \"\",\n rss: Number(match[5]) * 1024,\n start: parseDarwinStart(match[6] ?? \"\"),\n };\n })\n : [];\n}\n\n/** CIM CreationDate is a DateTime; serialize UTC ticks as text, never a locale date\n * or JSON number (100ns ticks exceed Number's precision). WorkingSetSize is bytes.\n * https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-process\n */\nexport function windowsCommand(pid: number, tree = false): Command {\n validPid(pid);\n const query = `Get-CimInstance Win32_Process${tree ? \"\" : ` -Filter 'ProcessId=${pid}'`}`;\n const script = [\n \"$ErrorActionPreference = 'Stop'\",\n `$rows = @(${query} | ForEach-Object {`,\n `if ([int]$_.ProcessId -eq ${pid} -and $null -eq $_.CreationDate) { throw 'Cannot read process creation time' }`,\n \"if ($null -ne $_.CreationDate) {\",\n \"[pscustomobject]@{ pid = [int]$_.ProcessId; parent = [int]$_.ParentProcessId; start = $_.CreationDate.ToUniversalTime().Ticks.ToString([Globalization.CultureInfo]::InvariantCulture); rss = [double]$_.WorkingSetSize }\",\n \"}\",\n \"})\",\n \"ConvertTo-Json -InputObject $rows -Compress\",\n ].join(\"\\n\");\n return {\n file: \"powershell.exe\",\n args: [\"-NoLogo\", \"-NoProfile\", \"-NonInteractive\", \"-Command\", script],\n };\n}\nexport function parseWindowsRows(source: string): Row[] {\n return windowsRows(JSON.parse(source.replace(/^\\uFEFF/, \"\")));\n}\n/** Validates rows decoded from PowerShell, whether one-shot or from the long-lived helper. */\nexport function windowsRows(value: unknown): Row[] {\n if (!Array.isArray(value)) throw new Error(\"Invalid Windows process observation\");\n return value.map((row: unknown) => {\n if (\n !row ||\n typeof row !== \"object\" ||\n !(\"pid\" in row) ||\n typeof row.pid !== \"number\" ||\n !Number.isSafeInteger(row.pid) ||\n row.pid < 0 ||\n !(\"parent\" in row) ||\n typeof row.parent !== \"number\" ||\n !Number.isSafeInteger(row.parent) ||\n row.parent < 0 ||\n !(\"start\" in row) ||\n typeof row.start !== \"string\" ||\n !/^\\d{18}$/.test(row.start) ||\n !(\"rss\" in row) ||\n typeof row.rss !== \"number\" ||\n !Number.isFinite(row.rss) ||\n row.rss < 0\n )\n throw new Error(\"Invalid Windows process observation\");\n return {\n pid: row.pid,\n parent: row.parent,\n start: row.start,\n rss: row.rss,\n group: row.pid,\n state: \"R\",\n };\n });\n}\nexport function taskkillCommand(pid: number): Command {\n validPid(pid);\n // Never accept an image name, filter, wildcard or shell interpolation.\n return { file: \"taskkill.exe\", args: [\"/PID\", String(pid), \"/T\", \"/F\"] };\n}\nexport function treeMemory(rows: Row[], pid: number): number {\n const root = rows.find((row) => row.pid === pid);\n if (!root) return 0;\n const included = new Map<number, Row>([[pid, root]]);\n let changed = true;\n while (changed) {\n changed = false;\n for (const row of rows) {\n const parent = included.get(row.parent);\n // Reject a reused parent PID whose creation time is later than the child.\n if (!included.has(row.pid) && parent && BigInt(row.start) >= BigInt(parent.start)) {\n included.set(row.pid, row);\n changed = true;\n }\n }\n }\n return [...included.values()].reduce((total, row) => total + row.rss, 0);\n}\n\n/** Reads process rows. `tree` asks for the whole table; `maxAgeMs` accepts a recent snapshot. */\nexport type RowSource = (pids: number[], tree: boolean, maxAgeMs?: number) => Promise<Row[]>;\n\n/** All OS effects are injected; foreign-platform specs never execute real commands. */\nexport async function portableIdentity(\n platform: PortablePlatform,\n pid: number,\n token: boolean,\n execute: Execute,\n readProof: ReadProof,\n source?: RowSource,\n maxAgeMs = 0,\n): Promise<Identity | undefined> {\n validPid(pid);\n const command = platform === \"darwin\" ? darwinCommand : windowsCommand;\n const parse = platform === \"darwin\" ? parseDarwinRows : parseWindowsRows;\n const read: RowSource =\n source ?? (async (pids, tree) => parse(await execute(command(pids[0] ?? pid, tree))));\n const rows = await read([pid], token, maxAgeMs);\n const before = rows.find((row) => row.pid === pid);\n if (!before || /^[ZX]/.test(before.state)) return undefined;\n if (!token) return before;\n const proof = await readProof(pid);\n const after = (await read([pid], false, maxAgeMs)).find((row) => row.pid === pid);\n if (\n !after ||\n after.start !== before.start ||\n after.group !== before.group ||\n /^[ZX]/.test(after.state)\n )\n return undefined;\n return {\n start: after.start,\n group: after.group,\n state: proof?.pid === pid && proof.gated ? \"T\" : after.state,\n rss: treeMemory(rows, pid),\n token: proof?.pid === pid ? proof.token : undefined,\n };\n}\n"],"mappings":";;;;;;;AAsBA,SAAgB,sBAAsB,UAA0B;CAC9D,OAAO,aAAa,UAAU,OAAO,aAAa,WAAW,MAAM;AACrE;AACA,SAAgB,4BAA4B,UAA0B;CACpE,OAAO,aAAa,WAAW,aAAa,WAAW,OAAS;AAClE;;;;;AAKA,SAAgB,sBAAsB,UAA0B;CAC9D,OAAO,aAAa,UAAU,MAAO;AACvC;AAEA,IAAa,kCAAb,cAAqD,MAAM;CAC7B;CAA5B,YAAY,AAAgB,UAAkB;EAC5C,MAAM,yCAAyC,UAAU;EAD/B;EAE1B,KAAK,OAAO;CACd;AACF;AACA,SAAgB,UAAU,UAAwB;CAChD,IAAI,CAAC;EAAC;EAAS;EAAU;CAAO,CAAC,CAAC,SAAS,QAAQ,GACjD,MAAM,IAAI,gCAAgC,QAAQ;AACtD;AACA,SAAS,SAAS,KAAmB;CACnC,IAAI,CAAC,OAAO,cAAc,GAAG,KAAK,OAAO,GAAG,MAAM,IAAI,MAAM,qBAAqB;AACnF;;;;;;AAOA,SAAgB,iBAAiB,QAAwB;CACvD,MAAM,QACJ,gIAAgI,KAC9H,OAAO,KAAK,CACd;CACF,IAAI,CAAC,OAAO,MAAM,IAAI,MAAM,kCAAkC;CAC9D,MAAM,GAAG,SAAS,OAAO,KAAK,MAAM,QAAQ,QAAQ,QAAQ;CAC5D,MAAM,aAAa,kDAChB,MAAM,GAAG,CAAC,CACV,QAAQ,SAAS,EAAE;CACtB,MAAM,OAAO,IAAI,KACf,KAAK,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AO,QAAQ,OAAO,MAAM,QAAQ,MAAM,MAAM;EACvD,KAAK,WAAW,MAAM,GAAG;EACzB,OAAO,OAAO,QAAQ,MAAM,MAAM,QAAQ;CAC5C;AACF"}
|
package/esm/supervisor.d.mts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { ProcessSupervisor, SupervisorOptions } from "./types.mjs";
|
|
2
2
|
//#region ../../packages/process/src/supervisor.d.ts
|
|
3
|
+
/** The launch failed before the child could be supervised. */
|
|
4
|
+
export declare class ProcessStartupError extends Error {
|
|
5
|
+
readonly reason: "no-pid" | "exited" | "setup-timeout";
|
|
6
|
+
/** `no-pid`: a terminal never reported a process ID. `exited`: the child exited before its gate. `setup-timeout`: the gate was not reached in time. */
|
|
7
|
+
constructor(reason: "no-pid" | "exited" | "setup-timeout", message: string);
|
|
8
|
+
}
|
|
3
9
|
export declare function supervisor(options: SupervisorOptions): ProcessSupervisor;
|
|
4
10
|
//#endregion
|
|
5
11
|
//# sourceMappingURL=supervisor.d.mts.map
|
package/esm/supervisor.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supervisor.d.mts","names":[],"sources":["../../../../../../../packages/process/src/supervisor.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"supervisor.d.mts","names":[],"sources":["../../../../../../../packages/process/src/supervisor.ts"],"mappings":";;;qBAoCa,4BAA4B;WAGrB;;EADlB,YACkB,+CAChB;;wBA+EY,WAAW,SAAS,oBAAoB"}
|
package/esm/supervisor.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defaultObservationTimeoutMs, defaultPollIntervalMs, supported, taskkillCommand } from "./platform.mjs";
|
|
1
|
+
import { defaultObservationTimeoutMs, defaultPollIntervalMs, defaultSetupTimeoutMs, supported, taskkillCommand } from "./platform.mjs";
|
|
2
2
|
import { attachCgroup, cgroupMemory, cleanCgroup, recoveredCgroup, validateLimits } from "./resources.mjs";
|
|
3
3
|
import { guardianProof, launchCommand } from "./guardian.mjs";
|
|
4
4
|
import { ProcessNotOwnedError, executeCommand, identity, owns } from "./identity.mjs";
|
|
@@ -11,6 +11,26 @@ import { PassThrough, Writable } from "node:stream";
|
|
|
11
11
|
import { setTimeout } from "node:timers/promises";
|
|
12
12
|
|
|
13
13
|
//#region ../../packages/process/src/supervisor.ts
|
|
14
|
+
/** The launch failed before the child could be supervised. */
|
|
15
|
+
var ProcessStartupError = class extends Error {
|
|
16
|
+
reason;
|
|
17
|
+
/** `no-pid`: a terminal never reported a process ID. `exited`: the child exited before its gate. `setup-timeout`: the gate was not reached in time. */
|
|
18
|
+
constructor(reason, message) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.reason = reason;
|
|
21
|
+
this.name = "ProcessStartupError";
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* ConPTY reports pid 0 until the child has started. Wait for a real pid so the
|
|
26
|
+
* supervisor never tracks pid 0; give up after `waitMs` with a typed error.
|
|
27
|
+
*/
|
|
28
|
+
async function terminalPid(terminal, waitMs) {
|
|
29
|
+
const deadline = Date.now() + waitMs;
|
|
30
|
+
while (!terminal.pid && Date.now() < deadline) await setTimeout(10);
|
|
31
|
+
if (!terminal.pid) throw new ProcessStartupError("no-pid", `Terminal did not report a process ID within ${waitMs} ms`);
|
|
32
|
+
return terminal.pid;
|
|
33
|
+
}
|
|
14
34
|
function info(entry) {
|
|
15
35
|
const { token: _token, start: _start, cgroup: _cgroup, gated: _gated, ...visible } = entry;
|
|
16
36
|
return structuredClone(visible);
|
|
@@ -38,6 +58,10 @@ function supervisor(options) {
|
|
|
38
58
|
if (live && live.owner === options.owner) return live.api;
|
|
39
59
|
const observationMs = options.observationTimeoutMs ?? defaultObservationTimeoutMs(process.platform);
|
|
40
60
|
if (!Number.isSafeInteger(observationMs) || observationMs < 100) throw new Error("Invalid observationTimeoutMs: expected an integer of at least 100");
|
|
61
|
+
const pidWaitMs = options.pidWaitMs ?? 1e4;
|
|
62
|
+
if (!Number.isSafeInteger(pidWaitMs) || pidWaitMs < 0) throw new Error("Invalid pidWaitMs: expected a nonnegative integer");
|
|
63
|
+
const setupMs = options.setupTimeoutMs ?? defaultSetupTimeoutMs(process.platform);
|
|
64
|
+
if (!Number.isSafeInteger(setupMs) || setupMs < 100) throw new Error("Invalid setupTimeoutMs: expected an integer of at least 100");
|
|
41
65
|
let helper;
|
|
42
66
|
function observe() {
|
|
43
67
|
if (process.platform === "win32") helper ??= createWindowsHelper({ timeoutMs: observationMs });
|
|
@@ -321,7 +345,14 @@ function supervisor(options) {
|
|
|
321
345
|
rows: input.rows ?? 24,
|
|
322
346
|
name: "xterm-256color"
|
|
323
347
|
});
|
|
324
|
-
|
|
348
|
+
try {
|
|
349
|
+
pid = await terminalPid(terminalProcess, pidWaitMs);
|
|
350
|
+
} catch (error) {
|
|
351
|
+
try {
|
|
352
|
+
terminalProcess.kill?.();
|
|
353
|
+
} catch {}
|
|
354
|
+
throw error;
|
|
355
|
+
}
|
|
325
356
|
const output = new PassThrough();
|
|
326
357
|
const errors = new PassThrough();
|
|
327
358
|
const instance = terminalProcess;
|
|
@@ -365,7 +396,7 @@ function supervisor(options) {
|
|
|
365
396
|
}
|
|
366
397
|
let entry;
|
|
367
398
|
try {
|
|
368
|
-
const deadline = Date.now() +
|
|
399
|
+
const deadline = Date.now() + setupMs;
|
|
369
400
|
const portable = process.platform !== "linux";
|
|
370
401
|
const gate = async () => {
|
|
371
402
|
if (portable) {
|
|
@@ -376,7 +407,8 @@ function supervisor(options) {
|
|
|
376
407
|
let current = await gate();
|
|
377
408
|
while (!current?.state.startsWith("T") || current.token !== token) {
|
|
378
409
|
if (spawnError) throw spawnError;
|
|
379
|
-
if (exit
|
|
410
|
+
if (exit) throw new ProcessStartupError("exited", "Child failed to reach the resource setup gate");
|
|
411
|
+
if (Date.now() >= deadline) throw new ProcessStartupError("setup-timeout", "Child failed to reach the resource setup gate");
|
|
380
412
|
await setTimeout(10);
|
|
381
413
|
current = await gate();
|
|
382
414
|
}
|
|
@@ -534,5 +566,5 @@ function sameProcessSupervisors() {
|
|
|
534
566
|
}
|
|
535
567
|
|
|
536
568
|
//#endregion
|
|
537
|
-
export { supervisor };
|
|
569
|
+
export { ProcessStartupError, supervisor, terminalPid };
|
|
538
570
|
//# sourceMappingURL=supervisor.mjs.map
|
package/esm/supervisor.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supervisor.mjs","names":["delay","spawnChild"],"sources":["../../../../../../../packages/process/src/supervisor.ts"],"sourcesContent":["import { spawn as spawnChild } from \"node:child_process\";\nimport { randomBytes } from \"node:crypto\";\nimport path from \"node:path\";\nimport { PassThrough, Writable } from \"node:stream\";\nimport { setTimeout as delay } from \"node:timers/promises\";\nimport { identity, owns, ProcessNotOwnedError, executeCommand, type Observation } from \"./identity\";\nimport { guardianProof, launchCommand } from \"./guardian\";\nimport {\n defaultObservationTimeoutMs,\n defaultPollIntervalMs,\n supported,\n taskkillCommand,\n} from \"./platform\";\nimport { Registry, type RegistryEntry } from \"./registry\";\nimport { createWindowsHelper, type WindowsProcessHelper } from \"./windows-helper\";\nimport {\n attachCgroup,\n cgroupMemory,\n cleanCgroup,\n recoveredCgroup,\n validateLimits,\n} from \"./resources\";\nimport type {\n ProcessExit,\n ProcessFilter,\n ProcessHandle,\n ProcessInfo,\n ProcessSupervisor,\n PtyHandle,\n RecoveryResult,\n SpawnOptions,\n SupervisorOptions,\n} from \"./types\";\n\ntype Pty = {\n pid: number;\n onData(listener: (data: string) => void): { dispose(): void };\n onExit(listener: (event: { exitCode: number; signal?: number }) => void): { dispose(): void };\n write(data: string): void;\n resize(columns: number, rows: number): void;\n};\ntype PtyModule = {\n spawn(\n command: string,\n args: string[],\n options: {\n cwd?: string;\n env: Record<string, string>;\n cols: number;\n rows: number;\n name: string;\n },\n ): Pty;\n};\ntype Active = {\n entry: RegistryEntry;\n handle: ProcessHandle;\n reason?: ProcessExit[\"reason\"];\n finish(code: number | null, signal: string | null): Promise<void>;\n stopping?: Promise<void>;\n timer?: ReturnType<typeof setInterval>;\n finished: boolean;\n adopted: boolean;\n fail(error: unknown): void;\n};\n\nfunction info(entry: RegistryEntry): ProcessInfo {\n const { token: _token, start: _start, cgroup: _cgroup, gated: _gated, ...visible } = entry;\n return structuredClone(visible);\n}\nfunction validateFilter(filter: ProcessFilter): void {\n if (\n !filter ||\n typeof filter !== \"object\" ||\n Array.isArray(filter) ||\n Object.keys(filter).some((key) => key !== \"labels\")\n )\n throw new Error(\"Only label filters are supported\");\n if (\n filter.labels !== undefined &&\n (filter.labels === null ||\n typeof filter.labels !== \"object\" ||\n Array.isArray(filter.labels) ||\n !Object.values(filter.labels).every((value) => typeof value === \"string\"))\n )\n throw new Error(\"Labels must be string key/value pairs\");\n}\nfunction matches(entry: RegistryEntry, filter: ProcessFilter): boolean {\n return Object.entries(filter.labels ?? {}).every(([key, value]) => entry.labels[key] === value);\n}\n\nexport function supervisor(options: SupervisorOptions): ProcessSupervisor {\n for (const option of [\"owner\", \"registry\"] as const) {\n if (!options || typeof options[option] !== \"string\" || !options[option].trim()) {\n throw new TypeError(`Invalid supervisor configuration: ${option} must be a nonempty string`);\n }\n }\n validateLimits(options.defaults ?? {});\n // Caller-owned configuration must not change an active supervisor's identity.\n options = { ...options, defaults: { ...options.defaults } };\n const pollMs = options.pollIntervalMs ?? defaultPollIntervalMs(process.platform);\n const graceMs = options.stopGraceMs ?? 1000;\n if (!Number.isSafeInteger(pollMs) || pollMs < 10 || !Number.isSafeInteger(graceMs) || graceMs < 0)\n throw new Error(\"Invalid polling interval or stop grace period\");\n const registryPath = path.resolve(options.registry);\n // `warlock dev` can evaluate this module more than once in one process. A second supervisor over\n // the same registry would find its own process holding the lock, so reuse the live one.\n const sameProcess = sameProcessSupervisors();\n const live = sameProcess.get(registryPath);\n if (live && live.owner === options.owner) return live.api;\n const observationMs =\n options.observationTimeoutMs ?? defaultObservationTimeoutMs(process.platform);\n if (!Number.isSafeInteger(observationMs) || observationMs < 100)\n throw new Error(\"Invalid observationTimeoutMs: expected an integer of at least 100\");\n // One helper per supervisor, created on first use and closed by stopAll().\n let helper: WindowsProcessHelper | undefined;\n function observe(): Observation {\n if (process.platform === \"win32\") helper ??= createWindowsHelper({ timeoutMs: observationMs });\n return { timeoutMs: observationMs, helper };\n }\n /** Polling tolerates a snapshot up to one interval old; signals never do. */\n function polling(): Observation {\n return { ...observe(), maxAgeMs: pollMs };\n }\n /**\n * Registry lease checks read identities too. Off Linux they go through the shared\n * helper, and a transient failure (an exiting process reports no creation time) is\n * retried instead of failing the whole operation.\n */\n async function lease(pid: number) {\n for (let attempt = 1; ; attempt++) {\n try {\n return await identity(pid, false, undefined, observe());\n } catch (error) {\n if (process.platform === \"linux\" || attempt >= 3) throw error;\n await delay(200);\n }\n }\n }\n const registry = new Registry(registryPath, options.owner, lease);\n const entries = new Map<number, RegistryEntry>();\n const active = new Map<number, Active>();\n let ready: Promise<void> | undefined;\n let closing = false;\n let shutdown: Promise<void> | undefined;\n // Serialize public operations, including shutdown, so a gated spawn cannot escape stopAll.\n let queue: Promise<unknown> = Promise.resolve();\n function serial<T>(operation: () => Promise<T>): Promise<T> {\n const next = queue.then(operation);\n queue = next.catch(() => undefined);\n return next;\n }\n async function open(): Promise<void> {\n supported(process.platform);\n if (closing) throw new Error(\"Supervisor has shut down\");\n ready ??= registry.open().then((saved) => {\n for (const entry of saved) {\n delete entry.cgroup;\n entries.set(entry.pid, entry);\n }\n });\n await ready;\n }\n const save = () => registry.save([...entries.values()]);\n\n async function signal(entry: RegistryEntry, value: NodeJS.Signals): Promise<void> {\n if (!(await owns(entry, observe()))) throw new ProcessNotOwnedError(entry.pid);\n if (process.platform !== \"linux\" && value === \"SIGCONT\") {\n const proof = await guardianProof(entry.pid, entry.token, entry.token, observationMs);\n if (!proof || proof.token !== entry.token || proof.gated)\n throw new ProcessNotOwnedError(entry.pid);\n return;\n }\n if (process.platform === \"win32\") {\n try {\n await executeCommand(taskkillCommand(entry.pid));\n } catch (error) {\n if (await owns(entry, observe())) throw error;\n }\n return;\n }\n // Negative PID targets only the session/group established for this child.\n // Recheck for every signal, including escalation; never match a command line.\n try {\n process.kill(-entry.pid, value);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ESRCH\") throw error;\n }\n }\n /**\n * A process that is exiting can still be listed for a moment after its guardian\n * (and so its token) is gone. Read fresh a few times; only a process that has\n * disappeared counts as gone, and a live one keeps its not-owned failure.\n */\n async function gone(pid: number): Promise<boolean> {\n for (let attempt = 0; attempt < 5; attempt++) {\n if (!(await identity(pid, false, undefined, observe()))) return true;\n await delay(100);\n }\n return false;\n }\n /**\n * Right after SIGCONT the launcher is replacing itself with the workload\n * (exec). For that instant the kernel reports an empty memory map and\n * environment, so a live, owned process momentarily fails verification. A\n * handle returned by launch() must always be stoppable, so wait that window\n * out; a process that stays unverified is still refused.\n */\n async function ownsSettled(entry: RegistryEntry): Promise<boolean> {\n for (let attempt = 0; attempt < 25; attempt++) {\n if (await owns(entry, observe())) return true;\n await delay(20);\n }\n return false;\n }\n async function stopEntry(\n entry: RegistryEntry,\n reason: ProcessExit[\"reason\"] = \"stopped\",\n ): Promise<void> {\n const tracked = active.get(entry.pid);\n let running: Active;\n if (!tracked) {\n if (!(await owns(entry, observe()))) throw new ProcessNotOwnedError(entry.pid);\n entry.cgroup = await recoveredCgroup(entry.pid, entry.token);\n running = track(entry);\n } else running = tracked;\n if (running.finished) return running.finish(null, null);\n if (running.stopping) return running.stopping;\n const stopping = (async () => {\n if (!(await ownsSettled(entry))) throw new ProcessNotOwnedError(entry.pid);\n running.reason ??= reason;\n await signal(entry, \"SIGTERM\");\n const deadline = Date.now() + graceMs;\n while (await owns(entry, observe())) {\n if (Date.now() >= deadline) {\n await signal(entry, \"SIGKILL\");\n break;\n }\n await delay(20);\n }\n const killedDeadline = Date.now() + 5000;\n while (await owns(entry, observe())) {\n if (Date.now() >= killedDeadline)\n throw new Error(`Process ${entry.pid} did not exit after SIGKILL`);\n await delay(20);\n }\n await running.finish(null, null);\n })();\n running.stopping = stopping;\n try {\n await stopping;\n } catch (error) {\n running.stopping = undefined;\n // The leader may exit between identity verification and a signal. A\n // missing identity is harmless for a tracked handle; a live mismatch is\n // still an ownership failure and must never receive another signal.\n if (error instanceof ProcessNotOwnedError && (await gone(entry.pid))) {\n await running.finish(null, null);\n return;\n }\n throw error;\n }\n }\n\n function track(\n entry: RegistryEntry,\n streams?: Pick<ProcessHandle, \"stdin\" | \"stdout\" | \"stderr\">,\n ): Active {\n let resolveExit: (exit: ProcessExit) => void = () => undefined;\n let rejectExit: (error: unknown) => void = () => undefined;\n const exited = new Promise<ProcessExit>((resolve, reject) => {\n resolveExit = resolve;\n rejectExit = reject;\n });\n // A rejected persistence operation is still observable through handle.exited.\n void exited.catch(() => undefined);\n const stdout = streams?.stdout ?? new PassThrough();\n const stderr = streams?.stderr ?? new PassThrough();\n const stdin = streams?.stdin ?? new PassThrough();\n let finishing: Promise<void> | undefined;\n const running: Active = {\n entry,\n finished: false,\n adopted: !streams,\n fail: (error) => rejectExit(error),\n handle: {\n pid: entry.pid,\n stdout,\n stderr,\n stdin,\n exited,\n stop: () =>\n serial(async () => {\n if (!running.finished) await stopEntry(entry);\n }),\n },\n finish(code, sig) {\n finishing ??= (async () => {\n running.finished = true;\n clearInterval(running.timer);\n if (entry.cgroup) {\n const memory = await cgroupMemory(entry.cgroup);\n entry.peakMemoryBytes = Math.max(entry.peakMemoryBytes, memory.peak);\n if (memory.oom) running.reason = \"memory-cap\";\n await cleanCgroup(entry.cgroup);\n }\n active.delete(entry.pid);\n entries.delete(entry.pid);\n try {\n await save();\n resolveExit({\n reason: running.reason ?? \"exit\",\n code,\n signal: sig,\n peakMemoryBytes: entry.peakMemoryBytes,\n });\n } catch (error) {\n rejectExit(error);\n throw error;\n }\n if (!streams) {\n (stdout as PassThrough).end();\n (stderr as PassThrough).end();\n stdin.end();\n }\n })();\n return finishing;\n },\n };\n active.set(entry.pid, running);\n return running;\n }\n\n function monitor(running: Active): void {\n if (running.finished) return;\n let sampling = false;\n const sample = async () => {\n if (sampling || running.finished) return;\n sampling = true;\n try {\n const entry = running.entry;\n let current = await identity(entry.pid, true, entry.token, polling());\n const matches = (value: typeof current) =>\n value?.start === entry.start && value.token === entry.token && value.group === entry.pid;\n // A snapshot taken while the process was exiting can still list it after\n // its guardian is gone. Before calling a mismatch a failure, read fresh\n // (no snapshot) a few times; a process that vanished simply exited.\n for (let attempt = 0; current && !matches(current) && attempt < 3; attempt++) {\n if (running.finished) return;\n await delay(50);\n current = await identity(entry.pid, true, entry.token, observe());\n }\n if (running.finished) return;\n if (\n current?.start !== entry.start ||\n current.token !== entry.token ||\n current.group !== entry.pid\n ) {\n if (!current) {\n if (running.adopted) await running.finish(null, null);\n } else {\n // A live child that changes its environment or group can no longer\n // be supervised safely. Preserve the entry and surface the failure.\n throw new ProcessNotOwnedError(entry.pid);\n }\n return;\n }\n entry.peakMemoryBytes = Math.max(entry.peakMemoryBytes, current.rss);\n if (entry.cgroup) {\n const memory = await cgroupMemory(entry.cgroup);\n if (running.finished) return;\n entry.peakMemoryBytes = Math.max(entry.peakMemoryBytes, memory.peak);\n if (memory.oom) running.reason = \"memory-cap\";\n }\n if (entry.limits.memoryBytes && entry.peakMemoryBytes > entry.limits.memoryBytes)\n await stopEntry(entry, \"memory-cap\");\n else if (entry.limits.timeoutMs && Date.now() - entry.startedAt >= entry.limits.timeoutMs)\n await stopEntry(entry, \"timeout\");\n } finally {\n sampling = false;\n }\n };\n running.timer = setInterval(() => {\n void sample().catch((error: unknown) => {\n // Never signal on an observation error. Surface it to the caller and keep the registry.\n clearInterval(running.timer);\n if (!running.finished) running.fail(error);\n });\n }, pollMs);\n running.timer.unref();\n }\n\n async function launch(\n input: SpawnOptions & { columns?: number; rows?: number },\n terminal: boolean,\n ): Promise<ProcessHandle | PtyHandle> {\n await open();\n if ([...entries.keys()].some((pid) => !active.has(pid)))\n throw new Error(\"Call recover() before spawning with an existing registry\");\n if (\n typeof input.command !== \"string\" ||\n !input.command ||\n typeof input.kind !== \"string\" ||\n !input.kind\n )\n throw new Error(\"kind and command are required\");\n validateFilter({ labels: input.labels });\n if (\n terminal &&\n [input.columns ?? 80, input.rows ?? 24].some(\n (size) => !Number.isSafeInteger(size) || size <= 0,\n )\n )\n throw new Error(\"Terminal dimensions must be positive safe integers\");\n const limits = { ...options.defaults, ...input.limits };\n validateLimits(limits);\n const token = randomBytes(32).toString(\"hex\");\n const {\n file: executable,\n args,\n env,\n } = launchCommand(\n process.platform,\n process.execPath,\n input.command,\n input.args ?? [],\n limits,\n { ...process.env, ...input.env },\n token,\n );\n let pid: number;\n let streams: Pick<ProcessHandle, \"stdin\" | \"stdout\" | \"stderr\">;\n let terminalProcess: Pty | undefined;\n let exit: { code: number | null; signal: string | null } | undefined;\n let spawnError: Error | undefined;\n let running: Active | undefined;\n const onExit = (code: number | null, sig: string | null) => {\n exit = { code, signal: sig };\n if (running) void running.finish(code, sig).catch(() => undefined);\n };\n if (terminal) {\n // Optional peer loaded only here. Structural types follow node-pty's official typings.\n const peer = \"node-pty\";\n const pty = (await import(peer)) as PtyModule;\n terminalProcess = pty.spawn(executable, args, {\n cwd: input.cwd,\n env: Object.fromEntries(\n Object.entries(env).filter((pair): pair is [string, string] => pair[1] !== undefined),\n ),\n cols: input.columns ?? 80,\n rows: input.rows ?? 24,\n name: \"xterm-256color\",\n });\n pid = terminalProcess.pid;\n const output = new PassThrough();\n const errors = new PassThrough();\n const instance = terminalProcess;\n const dataSubscription = instance.onData((data) => output.write(data));\n const inputStream = new Writable({\n write(chunk: Buffer, _encoding, callback) {\n instance.write(chunk.toString());\n callback();\n },\n });\n const exitSubscription = instance.onExit((event) => {\n dataSubscription.dispose();\n exitSubscription.dispose();\n output.end();\n errors.end();\n inputStream.end();\n onExit(event.exitCode, event.signal ? String(event.signal) : null);\n });\n streams = { stdout: output, stderr: errors, stdin: inputStream };\n } else {\n const child = spawnChild(executable, args, {\n cwd: input.cwd,\n env,\n detached: process.platform !== \"win32\",\n windowsHide: true,\n stdio: \"pipe\",\n });\n child.on(\"error\", (error) => {\n spawnError = error;\n });\n // Finish on leader exit so cgroup cleanup can stop remaining members;\n // waiting for close could deadlock on a descendant holding a pipe open.\n child.on(\"exit\", onExit);\n if (!child.pid) throw new Error(\"Could not start process\");\n pid = child.pid;\n streams = { stdout: child.stdout, stderr: child.stderr, stdin: child.stdin };\n }\n let entry: RegistryEntry | undefined;\n try {\n const deadline = Date.now() + 5000;\n // Off Linux an identity read costs a helper query, so poll the guardian's\n // pipe (cheap) until it reports the gate, and read the identity once.\n const portable = process.platform !== \"linux\";\n const gate = async () => {\n if (portable) {\n const proof = await guardianProof(pid, undefined, token, observationMs);\n if (!proof?.gated) return undefined;\n }\n return identity(pid, true, token, observe());\n };\n let current = await gate();\n while (!current?.state.startsWith(\"T\") || current.token !== token) {\n if (spawnError) throw spawnError;\n if (exit || Date.now() >= deadline)\n throw new Error(\"Child failed to reach the resource setup gate\");\n await delay(10);\n current = await gate();\n }\n if (current.group !== pid) throw new Error(\"Child did not create an isolated process group\");\n entry = {\n pid,\n owner: options.owner,\n type: input.kind,\n command: input.command,\n args: [...(input.args ?? [])],\n labels: { ...input.labels },\n startedAt: Date.now(),\n limits,\n enforcement: process.platform === \"win32\" ? \"rss-polling\" : \"rlimit-polling\",\n peakMemoryBytes: current.rss,\n token,\n start: current.start,\n gated: true,\n };\n entry.cgroup = await attachCgroup(pid, token, limits, options.cgroupRoot);\n if (entry.cgroup) entry.enforcement = \"cgroup-v2\";\n entries.set(pid, entry);\n await save();\n running = track(entry, streams);\n await signal(entry, \"SIGCONT\");\n delete entry.gated;\n await save();\n monitor(running);\n if (terminalProcess) {\n const instance = terminalProcess;\n return {\n ...running.handle,\n write: (data: string) => instance.write(data),\n resize: (columns: number, rows: number) => instance.resize(columns, rows),\n };\n }\n return running.handle;\n } catch (error) {\n // This PID was created by this call. Kill only after its random token is verified.\n const current = await identity(pid, true, token, observe());\n if (current?.token === token) {\n const failed = { pid, token, start: current.start };\n if (await owns(failed, observe())) {\n try {\n if (process.platform === \"win32\") await executeCommand(taskkillCommand(pid));\n else process.kill(-pid, \"SIGKILL\");\n } catch {\n /* Already exited. */\n }\n }\n }\n if (entry && !running) {\n entries.delete(pid);\n await save();\n }\n if (entry?.cgroup) await cleanCgroup(entry.cgroup);\n throw error;\n }\n }\n\n const api: ProcessSupervisor = {\n spawn: (input) => serial(() => launch(input, false)),\n spawnPty: (input) => serial(async () => (await launch(input, true)) as PtyHandle),\n list: (filter = {}) =>\n serial(async () => {\n validateFilter(filter);\n await open();\n return [...entries.values()].filter((entry) => matches(entry, filter)).map(info);\n }),\n stop: (filter = {}) =>\n serial(async () => {\n validateFilter(filter);\n await open();\n for (const entry of [...entries.values()].filter((entry) => matches(entry, filter)))\n await stopEntry(entry);\n }),\n stopPid: (pid) =>\n serial(async () => {\n await open();\n const entry = entries.get(pid);\n if (!entry) throw new ProcessNotOwnedError(pid);\n await stopEntry(entry);\n }),\n recover: (recovery = {}) =>\n serial(async () => {\n await open();\n const result: RecoveryResult = { adopted: [], stopped: [], cleared: [] };\n for (const entry of [...entries.values()]) {\n if (active.has(entry.pid)) continue;\n if (!(await owns(entry, observe()))) {\n entries.delete(entry.pid);\n result.cleared.push(entry.pid);\n continue;\n }\n // Never trust a persisted filesystem path for cgroup I/O after a restart.\n entry.cgroup = await recoveredCgroup(entry.pid, entry.token);\n entry.enforcement = entry.cgroup\n ? \"cgroup-v2\"\n : process.platform === \"win32\"\n ? \"rss-polling\"\n : \"rlimit-polling\";\n const keep = await recovery.keep?.(info(entry));\n if (keep) {\n const running = track(entry);\n monitor(running);\n if (entry.gated) {\n await signal(entry, \"SIGCONT\");\n delete entry.gated;\n }\n result.adopted.push(entry.pid);\n } else {\n await stopEntry(entry);\n result.stopped.push(entry.pid);\n }\n }\n await save();\n return result;\n }),\n stopAll() {\n shutdown ??= serial(async () => {\n await open();\n closing = true;\n try {\n const errors: unknown[] = [];\n for (const entry of [...entries.values()]) {\n try {\n if (await owns(entry, observe())) await stopEntry(entry);\n else {\n const running = active.get(entry.pid);\n if (running) await running.finish(null, null);\n else entries.delete(entry.pid);\n }\n } catch (error) {\n errors.push(error);\n }\n }\n await save();\n if (errors.length)\n throw new AggregateError(errors, \"Some owned processes could not be stopped\");\n } finally {\n await helper?.close();\n await registry.close();\n }\n });\n return shutdown;\n },\n };\n const stopAll = api.stopAll;\n api.stopAll = () => {\n const stopping = stopAll();\n const forget = () => {\n if (sameProcess.get(registryPath)?.api === api) sameProcess.delete(registryPath);\n };\n stopping.then(forget, forget);\n return stopping;\n };\n sameProcess.set(registryPath, { owner: options.owner, api });\n return api;\n}\n\nconst SUPERVISORS = Symbol.for(\"@warlock.js/process.supervisors\");\n\n/** Live supervisors of this process by registry path; shared by every copy of this module. */\nfunction sameProcessSupervisors(): Map<string, { owner: string; api: ProcessSupervisor }> {\n const holder = globalThis as unknown as Record<symbol, Map<string, any> | undefined>;\n return (holder[SUPERVISORS] ??= new Map());\n}\n"],"mappings":";;;;;;;;;;;;;AAkEA,SAAS,KAAK,OAAmC;CAC/C,MAAM,EAAE,OAAO,QAAQ,OAAO,QAAQ,QAAQ,SAAS,OAAO,QAAQ,GAAG,YAAY;CACrF,OAAO,gBAAgB,OAAO;AAChC;AACA,SAAS,eAAe,QAA6B;CACnD,IACE,CAAC,UACD,OAAO,WAAW,YAClB,MAAM,QAAQ,MAAM,KACpB,OAAO,KAAK,MAAM,CAAC,CAAC,MAAM,QAAQ,QAAQ,QAAQ,GAElD,MAAM,IAAI,MAAM,kCAAkC;CACpD,IACE,OAAO,WAAW,WACjB,OAAO,WAAW,QACjB,OAAO,OAAO,WAAW,YACzB,MAAM,QAAQ,OAAO,MAAM,KAC3B,CAAC,OAAO,OAAO,OAAO,MAAM,CAAC,CAAC,OAAO,UAAU,OAAO,UAAU,QAAQ,IAE1E,MAAM,IAAI,MAAM,uCAAuC;AAC3D;AACA,SAAS,QAAQ,OAAsB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names":["delay","spawnChild"],"sources":["../../../../../../../packages/process/src/supervisor.ts"],"sourcesContent":["import { spawn as spawnChild } from \"node:child_process\";\nimport { randomBytes } from \"node:crypto\";\nimport path from \"node:path\";\nimport { PassThrough, Writable } from \"node:stream\";\nimport { setTimeout as delay } from \"node:timers/promises\";\nimport { identity, owns, ProcessNotOwnedError, executeCommand, type Observation } from \"./identity\";\nimport { guardianProof, launchCommand } from \"./guardian\";\nimport {\n defaultObservationTimeoutMs,\n defaultPollIntervalMs,\n defaultSetupTimeoutMs,\n supported,\n taskkillCommand,\n} from \"./platform\";\nimport { Registry, type RegistryEntry } from \"./registry\";\nimport { createWindowsHelper, type WindowsProcessHelper } from \"./windows-helper\";\nimport {\n attachCgroup,\n cgroupMemory,\n cleanCgroup,\n recoveredCgroup,\n validateLimits,\n} from \"./resources\";\nimport type {\n ProcessExit,\n ProcessFilter,\n ProcessHandle,\n ProcessInfo,\n ProcessSupervisor,\n PtyHandle,\n RecoveryResult,\n SpawnOptions,\n SupervisorOptions,\n} from \"./types\";\n\n/** The launch failed before the child could be supervised. */\nexport class ProcessStartupError extends Error {\n /** `no-pid`: a terminal never reported a process ID. `exited`: the child exited before its gate. `setup-timeout`: the gate was not reached in time. */\n constructor(\n public readonly reason: \"no-pid\" | \"exited\" | \"setup-timeout\",\n message: string,\n ) {\n super(message);\n this.name = \"ProcessStartupError\";\n }\n}\ntype Pty = {\n pid: number;\n kill?(signal?: string): void;\n onData(listener: (data: string) => void): { dispose(): void };\n onExit(listener: (event: { exitCode: number; signal?: number }) => void): { dispose(): void };\n write(data: string): void;\n resize(columns: number, rows: number): void;\n};\ntype PtyModule = {\n spawn(\n command: string,\n args: string[],\n options: {\n cwd?: string;\n env: Record<string, string>;\n cols: number;\n rows: number;\n name: string;\n },\n ): Pty;\n};\ntype Active = {\n entry: RegistryEntry;\n handle: ProcessHandle;\n reason?: ProcessExit[\"reason\"];\n finish(code: number | null, signal: string | null): Promise<void>;\n stopping?: Promise<void>;\n timer?: ReturnType<typeof setInterval>;\n finished: boolean;\n adopted: boolean;\n fail(error: unknown): void;\n};\n\n/**\n * ConPTY reports pid 0 until the child has started. Wait for a real pid so the\n * supervisor never tracks pid 0; give up after `waitMs` with a typed error.\n */\nexport async function terminalPid(terminal: Pty, waitMs: number): Promise<number> {\n const deadline = Date.now() + waitMs;\n while (!terminal.pid && Date.now() < deadline) await delay(10);\n if (!terminal.pid)\n throw new ProcessStartupError(\n \"no-pid\",\n `Terminal did not report a process ID within ${waitMs} ms`,\n );\n return terminal.pid;\n}\n\nfunction info(entry: RegistryEntry): ProcessInfo {\n const { token: _token, start: _start, cgroup: _cgroup, gated: _gated, ...visible } = entry;\n return structuredClone(visible);\n}\nfunction validateFilter(filter: ProcessFilter): void {\n if (\n !filter ||\n typeof filter !== \"object\" ||\n Array.isArray(filter) ||\n Object.keys(filter).some((key) => key !== \"labels\")\n )\n throw new Error(\"Only label filters are supported\");\n if (\n filter.labels !== undefined &&\n (filter.labels === null ||\n typeof filter.labels !== \"object\" ||\n Array.isArray(filter.labels) ||\n !Object.values(filter.labels).every((value) => typeof value === \"string\"))\n )\n throw new Error(\"Labels must be string key/value pairs\");\n}\nfunction matches(entry: RegistryEntry, filter: ProcessFilter): boolean {\n return Object.entries(filter.labels ?? {}).every(([key, value]) => entry.labels[key] === value);\n}\n\nexport function supervisor(options: SupervisorOptions): ProcessSupervisor {\n for (const option of [\"owner\", \"registry\"] as const) {\n if (!options || typeof options[option] !== \"string\" || !options[option].trim()) {\n throw new TypeError(`Invalid supervisor configuration: ${option} must be a nonempty string`);\n }\n }\n validateLimits(options.defaults ?? {});\n // Caller-owned configuration must not change an active supervisor's identity.\n options = { ...options, defaults: { ...options.defaults } };\n const pollMs = options.pollIntervalMs ?? defaultPollIntervalMs(process.platform);\n const graceMs = options.stopGraceMs ?? 1000;\n if (!Number.isSafeInteger(pollMs) || pollMs < 10 || !Number.isSafeInteger(graceMs) || graceMs < 0)\n throw new Error(\"Invalid polling interval or stop grace period\");\n const registryPath = path.resolve(options.registry);\n // `warlock dev` can evaluate this module more than once in one process. A second supervisor over\n // the same registry would find its own process holding the lock, so reuse the live one.\n const sameProcess = sameProcessSupervisors();\n const live = sameProcess.get(registryPath);\n if (live && live.owner === options.owner) return live.api;\n const observationMs =\n options.observationTimeoutMs ?? defaultObservationTimeoutMs(process.platform);\n if (!Number.isSafeInteger(observationMs) || observationMs < 100)\n throw new Error(\"Invalid observationTimeoutMs: expected an integer of at least 100\");\n const pidWaitMs = options.pidWaitMs ?? 10_000;\n if (!Number.isSafeInteger(pidWaitMs) || pidWaitMs < 0)\n throw new Error(\"Invalid pidWaitMs: expected a nonnegative integer\");\n const setupMs = options.setupTimeoutMs ?? defaultSetupTimeoutMs(process.platform);\n if (!Number.isSafeInteger(setupMs) || setupMs < 100)\n throw new Error(\"Invalid setupTimeoutMs: expected an integer of at least 100\");\n // One helper per supervisor, created on first use and closed by stopAll().\n let helper: WindowsProcessHelper | undefined;\n function observe(): Observation {\n if (process.platform === \"win32\") helper ??= createWindowsHelper({ timeoutMs: observationMs });\n return { timeoutMs: observationMs, helper };\n }\n /** Polling tolerates a snapshot up to one interval old; signals never do. */\n function polling(): Observation {\n return { ...observe(), maxAgeMs: pollMs };\n }\n /**\n * Registry lease checks read identities too. Off Linux they go through the shared\n * helper, and a transient failure (an exiting process reports no creation time) is\n * retried instead of failing the whole operation.\n */\n async function lease(pid: number) {\n for (let attempt = 1; ; attempt++) {\n try {\n return await identity(pid, false, undefined, observe());\n } catch (error) {\n if (process.platform === \"linux\" || attempt >= 3) throw error;\n await delay(200);\n }\n }\n }\n const registry = new Registry(registryPath, options.owner, lease);\n const entries = new Map<number, RegistryEntry>();\n const active = new Map<number, Active>();\n let ready: Promise<void> | undefined;\n let closing = false;\n let shutdown: Promise<void> | undefined;\n // Serialize public operations, including shutdown, so a gated spawn cannot escape stopAll.\n let queue: Promise<unknown> = Promise.resolve();\n function serial<T>(operation: () => Promise<T>): Promise<T> {\n const next = queue.then(operation);\n queue = next.catch(() => undefined);\n return next;\n }\n async function open(): Promise<void> {\n supported(process.platform);\n if (closing) throw new Error(\"Supervisor has shut down\");\n ready ??= registry.open().then((saved) => {\n for (const entry of saved) {\n delete entry.cgroup;\n entries.set(entry.pid, entry);\n }\n });\n await ready;\n }\n const save = () => registry.save([...entries.values()]);\n\n async function signal(entry: RegistryEntry, value: NodeJS.Signals): Promise<void> {\n if (!(await owns(entry, observe()))) throw new ProcessNotOwnedError(entry.pid);\n if (process.platform !== \"linux\" && value === \"SIGCONT\") {\n const proof = await guardianProof(entry.pid, entry.token, entry.token, observationMs);\n if (!proof || proof.token !== entry.token || proof.gated)\n throw new ProcessNotOwnedError(entry.pid);\n return;\n }\n if (process.platform === \"win32\") {\n try {\n await executeCommand(taskkillCommand(entry.pid));\n } catch (error) {\n if (await owns(entry, observe())) throw error;\n }\n return;\n }\n // Negative PID targets only the session/group established for this child.\n // Recheck for every signal, including escalation; never match a command line.\n try {\n process.kill(-entry.pid, value);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ESRCH\") throw error;\n }\n }\n /**\n * A process that is exiting can still be listed for a moment after its guardian\n * (and so its token) is gone. Read fresh a few times; only a process that has\n * disappeared counts as gone, and a live one keeps its not-owned failure.\n */\n async function gone(pid: number): Promise<boolean> {\n for (let attempt = 0; attempt < 5; attempt++) {\n if (!(await identity(pid, false, undefined, observe()))) return true;\n await delay(100);\n }\n return false;\n }\n /**\n * Right after SIGCONT the launcher is replacing itself with the workload\n * (exec). For that instant the kernel reports an empty memory map and\n * environment, so a live, owned process momentarily fails verification. A\n * handle returned by launch() must always be stoppable, so wait that window\n * out; a process that stays unverified is still refused.\n */\n async function ownsSettled(entry: RegistryEntry): Promise<boolean> {\n for (let attempt = 0; attempt < 25; attempt++) {\n if (await owns(entry, observe())) return true;\n await delay(20);\n }\n return false;\n }\n async function stopEntry(\n entry: RegistryEntry,\n reason: ProcessExit[\"reason\"] = \"stopped\",\n ): Promise<void> {\n const tracked = active.get(entry.pid);\n let running: Active;\n if (!tracked) {\n if (!(await owns(entry, observe()))) throw new ProcessNotOwnedError(entry.pid);\n entry.cgroup = await recoveredCgroup(entry.pid, entry.token);\n running = track(entry);\n } else running = tracked;\n if (running.finished) return running.finish(null, null);\n if (running.stopping) return running.stopping;\n const stopping = (async () => {\n if (!(await ownsSettled(entry))) throw new ProcessNotOwnedError(entry.pid);\n running.reason ??= reason;\n await signal(entry, \"SIGTERM\");\n const deadline = Date.now() + graceMs;\n while (await owns(entry, observe())) {\n if (Date.now() >= deadline) {\n await signal(entry, \"SIGKILL\");\n break;\n }\n await delay(20);\n }\n const killedDeadline = Date.now() + 5000;\n while (await owns(entry, observe())) {\n if (Date.now() >= killedDeadline)\n throw new Error(`Process ${entry.pid} did not exit after SIGKILL`);\n await delay(20);\n }\n await running.finish(null, null);\n })();\n running.stopping = stopping;\n try {\n await stopping;\n } catch (error) {\n running.stopping = undefined;\n // The leader may exit between identity verification and a signal. A\n // missing identity is harmless for a tracked handle; a live mismatch is\n // still an ownership failure and must never receive another signal.\n if (error instanceof ProcessNotOwnedError && (await gone(entry.pid))) {\n await running.finish(null, null);\n return;\n }\n throw error;\n }\n }\n\n function track(\n entry: RegistryEntry,\n streams?: Pick<ProcessHandle, \"stdin\" | \"stdout\" | \"stderr\">,\n ): Active {\n let resolveExit: (exit: ProcessExit) => void = () => undefined;\n let rejectExit: (error: unknown) => void = () => undefined;\n const exited = new Promise<ProcessExit>((resolve, reject) => {\n resolveExit = resolve;\n rejectExit = reject;\n });\n // A rejected persistence operation is still observable through handle.exited.\n void exited.catch(() => undefined);\n const stdout = streams?.stdout ?? new PassThrough();\n const stderr = streams?.stderr ?? new PassThrough();\n const stdin = streams?.stdin ?? new PassThrough();\n let finishing: Promise<void> | undefined;\n const running: Active = {\n entry,\n finished: false,\n adopted: !streams,\n fail: (error) => rejectExit(error),\n handle: {\n pid: entry.pid,\n stdout,\n stderr,\n stdin,\n exited,\n stop: () =>\n serial(async () => {\n if (!running.finished) await stopEntry(entry);\n }),\n },\n finish(code, sig) {\n finishing ??= (async () => {\n running.finished = true;\n clearInterval(running.timer);\n if (entry.cgroup) {\n const memory = await cgroupMemory(entry.cgroup);\n entry.peakMemoryBytes = Math.max(entry.peakMemoryBytes, memory.peak);\n if (memory.oom) running.reason = \"memory-cap\";\n await cleanCgroup(entry.cgroup);\n }\n active.delete(entry.pid);\n entries.delete(entry.pid);\n try {\n await save();\n resolveExit({\n reason: running.reason ?? \"exit\",\n code,\n signal: sig,\n peakMemoryBytes: entry.peakMemoryBytes,\n });\n } catch (error) {\n rejectExit(error);\n throw error;\n }\n if (!streams) {\n (stdout as PassThrough).end();\n (stderr as PassThrough).end();\n stdin.end();\n }\n })();\n return finishing;\n },\n };\n active.set(entry.pid, running);\n return running;\n }\n\n function monitor(running: Active): void {\n if (running.finished) return;\n let sampling = false;\n const sample = async () => {\n if (sampling || running.finished) return;\n sampling = true;\n try {\n const entry = running.entry;\n let current = await identity(entry.pid, true, entry.token, polling());\n const matches = (value: typeof current) =>\n value?.start === entry.start && value.token === entry.token && value.group === entry.pid;\n // A snapshot taken while the process was exiting can still list it after\n // its guardian is gone. Before calling a mismatch a failure, read fresh\n // (no snapshot) a few times; a process that vanished simply exited.\n for (let attempt = 0; current && !matches(current) && attempt < 3; attempt++) {\n if (running.finished) return;\n await delay(50);\n current = await identity(entry.pid, true, entry.token, observe());\n }\n if (running.finished) return;\n if (\n current?.start !== entry.start ||\n current.token !== entry.token ||\n current.group !== entry.pid\n ) {\n if (!current) {\n if (running.adopted) await running.finish(null, null);\n } else {\n // A live child that changes its environment or group can no longer\n // be supervised safely. Preserve the entry and surface the failure.\n throw new ProcessNotOwnedError(entry.pid);\n }\n return;\n }\n entry.peakMemoryBytes = Math.max(entry.peakMemoryBytes, current.rss);\n if (entry.cgroup) {\n const memory = await cgroupMemory(entry.cgroup);\n if (running.finished) return;\n entry.peakMemoryBytes = Math.max(entry.peakMemoryBytes, memory.peak);\n if (memory.oom) running.reason = \"memory-cap\";\n }\n if (entry.limits.memoryBytes && entry.peakMemoryBytes > entry.limits.memoryBytes)\n await stopEntry(entry, \"memory-cap\");\n else if (entry.limits.timeoutMs && Date.now() - entry.startedAt >= entry.limits.timeoutMs)\n await stopEntry(entry, \"timeout\");\n } finally {\n sampling = false;\n }\n };\n running.timer = setInterval(() => {\n void sample().catch((error: unknown) => {\n // Never signal on an observation error. Surface it to the caller and keep the registry.\n clearInterval(running.timer);\n if (!running.finished) running.fail(error);\n });\n }, pollMs);\n running.timer.unref();\n }\n\n async function launch(\n input: SpawnOptions & { columns?: number; rows?: number },\n terminal: boolean,\n ): Promise<ProcessHandle | PtyHandle> {\n await open();\n if ([...entries.keys()].some((pid) => !active.has(pid)))\n throw new Error(\"Call recover() before spawning with an existing registry\");\n if (\n typeof input.command !== \"string\" ||\n !input.command ||\n typeof input.kind !== \"string\" ||\n !input.kind\n )\n throw new Error(\"kind and command are required\");\n validateFilter({ labels: input.labels });\n if (\n terminal &&\n [input.columns ?? 80, input.rows ?? 24].some(\n (size) => !Number.isSafeInteger(size) || size <= 0,\n )\n )\n throw new Error(\"Terminal dimensions must be positive safe integers\");\n const limits = { ...options.defaults, ...input.limits };\n validateLimits(limits);\n const token = randomBytes(32).toString(\"hex\");\n const {\n file: executable,\n args,\n env,\n } = launchCommand(\n process.platform,\n process.execPath,\n input.command,\n input.args ?? [],\n limits,\n { ...process.env, ...input.env },\n token,\n );\n let pid: number;\n let streams: Pick<ProcessHandle, \"stdin\" | \"stdout\" | \"stderr\">;\n let terminalProcess: Pty | undefined;\n let exit: { code: number | null; signal: string | null } | undefined;\n let spawnError: Error | undefined;\n let running: Active | undefined;\n const onExit = (code: number | null, sig: string | null) => {\n exit = { code, signal: sig };\n if (running) void running.finish(code, sig).catch(() => undefined);\n };\n if (terminal) {\n // Optional peer loaded only here. Structural types follow node-pty's official typings.\n const peer = \"node-pty\";\n const pty = (await import(peer)) as PtyModule;\n terminalProcess = pty.spawn(executable, args, {\n cwd: input.cwd,\n env: Object.fromEntries(\n Object.entries(env).filter((pair): pair is [string, string] => pair[1] !== undefined),\n ),\n cols: input.columns ?? 80,\n rows: input.rows ?? 24,\n name: \"xterm-256color\",\n });\n try {\n pid = await terminalPid(terminalProcess, pidWaitMs);\n } catch (error) {\n try {\n terminalProcess.kill?.();\n } catch {\n /* Best effort: the child has no reported pid to verify. */\n }\n throw error;\n }\n const output = new PassThrough();\n const errors = new PassThrough();\n const instance = terminalProcess;\n const dataSubscription = instance.onData((data) => output.write(data));\n const inputStream = new Writable({\n write(chunk: Buffer, _encoding, callback) {\n instance.write(chunk.toString());\n callback();\n },\n });\n const exitSubscription = instance.onExit((event) => {\n dataSubscription.dispose();\n exitSubscription.dispose();\n output.end();\n errors.end();\n inputStream.end();\n onExit(event.exitCode, event.signal ? String(event.signal) : null);\n });\n streams = { stdout: output, stderr: errors, stdin: inputStream };\n } else {\n const child = spawnChild(executable, args, {\n cwd: input.cwd,\n env,\n detached: process.platform !== \"win32\",\n windowsHide: true,\n stdio: \"pipe\",\n });\n child.on(\"error\", (error) => {\n spawnError = error;\n });\n // Finish on leader exit so cgroup cleanup can stop remaining members;\n // waiting for close could deadlock on a descendant holding a pipe open.\n child.on(\"exit\", onExit);\n if (!child.pid) throw new Error(\"Could not start process\");\n pid = child.pid;\n streams = { stdout: child.stdout, stderr: child.stderr, stdin: child.stdin };\n }\n let entry: RegistryEntry | undefined;\n try {\n const deadline = Date.now() + setupMs;\n // Off Linux an identity read costs a helper query, so poll the guardian's\n // pipe (cheap) until it reports the gate, and read the identity once.\n const portable = process.platform !== \"linux\";\n const gate = async () => {\n if (portable) {\n const proof = await guardianProof(pid, undefined, token, observationMs);\n if (!proof?.gated) return undefined;\n }\n return identity(pid, true, token, observe());\n };\n let current = await gate();\n while (!current?.state.startsWith(\"T\") || current.token !== token) {\n if (spawnError) throw spawnError;\n if (exit)\n throw new ProcessStartupError(\"exited\", \"Child failed to reach the resource setup gate\");\n if (Date.now() >= deadline)\n throw new ProcessStartupError(\n \"setup-timeout\",\n \"Child failed to reach the resource setup gate\",\n );\n await delay(10);\n current = await gate();\n }\n if (current.group !== pid) throw new Error(\"Child did not create an isolated process group\");\n entry = {\n pid,\n owner: options.owner,\n type: input.kind,\n command: input.command,\n args: [...(input.args ?? [])],\n labels: { ...input.labels },\n startedAt: Date.now(),\n limits,\n enforcement: process.platform === \"win32\" ? \"rss-polling\" : \"rlimit-polling\",\n peakMemoryBytes: current.rss,\n token,\n start: current.start,\n gated: true,\n };\n entry.cgroup = await attachCgroup(pid, token, limits, options.cgroupRoot);\n if (entry.cgroup) entry.enforcement = \"cgroup-v2\";\n entries.set(pid, entry);\n await save();\n running = track(entry, streams);\n await signal(entry, \"SIGCONT\");\n delete entry.gated;\n await save();\n monitor(running);\n if (terminalProcess) {\n const instance = terminalProcess;\n return {\n ...running.handle,\n write: (data: string) => instance.write(data),\n resize: (columns: number, rows: number) => instance.resize(columns, rows),\n };\n }\n return running.handle;\n } catch (error) {\n // This PID was created by this call. Kill only after its random token is verified.\n const current = await identity(pid, true, token, observe());\n if (current?.token === token) {\n const failed = { pid, token, start: current.start };\n if (await owns(failed, observe())) {\n try {\n if (process.platform === \"win32\") await executeCommand(taskkillCommand(pid));\n else process.kill(-pid, \"SIGKILL\");\n } catch {\n /* Already exited. */\n }\n }\n }\n if (entry && !running) {\n entries.delete(pid);\n await save();\n }\n if (entry?.cgroup) await cleanCgroup(entry.cgroup);\n throw error;\n }\n }\n\n const api: ProcessSupervisor = {\n spawn: (input) => serial(() => launch(input, false)),\n spawnPty: (input) => serial(async () => (await launch(input, true)) as PtyHandle),\n list: (filter = {}) =>\n serial(async () => {\n validateFilter(filter);\n await open();\n return [...entries.values()].filter((entry) => matches(entry, filter)).map(info);\n }),\n stop: (filter = {}) =>\n serial(async () => {\n validateFilter(filter);\n await open();\n for (const entry of [...entries.values()].filter((entry) => matches(entry, filter)))\n await stopEntry(entry);\n }),\n stopPid: (pid) =>\n serial(async () => {\n await open();\n const entry = entries.get(pid);\n if (!entry) throw new ProcessNotOwnedError(pid);\n await stopEntry(entry);\n }),\n recover: (recovery = {}) =>\n serial(async () => {\n await open();\n const result: RecoveryResult = { adopted: [], stopped: [], cleared: [] };\n for (const entry of [...entries.values()]) {\n if (active.has(entry.pid)) continue;\n if (!(await owns(entry, observe()))) {\n entries.delete(entry.pid);\n result.cleared.push(entry.pid);\n continue;\n }\n // Never trust a persisted filesystem path for cgroup I/O after a restart.\n entry.cgroup = await recoveredCgroup(entry.pid, entry.token);\n entry.enforcement = entry.cgroup\n ? \"cgroup-v2\"\n : process.platform === \"win32\"\n ? \"rss-polling\"\n : \"rlimit-polling\";\n const keep = await recovery.keep?.(info(entry));\n if (keep) {\n const running = track(entry);\n monitor(running);\n if (entry.gated) {\n await signal(entry, \"SIGCONT\");\n delete entry.gated;\n }\n result.adopted.push(entry.pid);\n } else {\n await stopEntry(entry);\n result.stopped.push(entry.pid);\n }\n }\n await save();\n return result;\n }),\n stopAll() {\n shutdown ??= serial(async () => {\n await open();\n closing = true;\n try {\n const errors: unknown[] = [];\n for (const entry of [...entries.values()]) {\n try {\n if (await owns(entry, observe())) await stopEntry(entry);\n else {\n const running = active.get(entry.pid);\n if (running) await running.finish(null, null);\n else entries.delete(entry.pid);\n }\n } catch (error) {\n errors.push(error);\n }\n }\n await save();\n if (errors.length)\n throw new AggregateError(errors, \"Some owned processes could not be stopped\");\n } finally {\n await helper?.close();\n await registry.close();\n }\n });\n return shutdown;\n },\n };\n const stopAll = api.stopAll;\n api.stopAll = () => {\n const stopping = stopAll();\n const forget = () => {\n if (sameProcess.get(registryPath)?.api === api) sameProcess.delete(registryPath);\n };\n stopping.then(forget, forget);\n return stopping;\n };\n sameProcess.set(registryPath, { owner: options.owner, api });\n return api;\n}\n\nconst SUPERVISORS = Symbol.for(\"@warlock.js/process.supervisors\");\n\n/** Live supervisors of this process by registry path; shared by every copy of this module. */\nfunction sameProcessSupervisors(): Map<string, { owner: string; api: ProcessSupervisor }> {\n const holder = globalThis as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AO;CAAI,CAAC;CAC3D,OAAO;AACT;AAEA,MAAM,cAAc,OAAO,IAAI,iCAAiC;;AAGhE,SAAS,yBAAiF;CACxF,MAAM,SAAS;CACf,OAAQ,OAAO,iCAAiB,IAAI,IAAI;AAC1C"}
|
package/esm/types.d.mts
CHANGED
|
@@ -25,6 +25,18 @@ export type SupervisorOptions = {
|
|
|
25
25
|
*/
|
|
26
26
|
observationTimeoutMs?: number;
|
|
27
27
|
stopGraceMs?: number;
|
|
28
|
+
/**
|
|
29
|
+
* Longest wait, in milliseconds, for a real process ID when a terminal reports pid 0 or
|
|
30
|
+
* no pid right after spawn (ConPTY does this for a moment on Windows). Defaults to 10000.
|
|
31
|
+
* If no pid arrives in time the launch fails with `ProcessStartupError`; pid 0 is never supervised.
|
|
32
|
+
*/
|
|
33
|
+
pidWaitMs?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Longest wait, in milliseconds, for a launched child to reach its resource setup gate.
|
|
36
|
+
* Defaults to 5000 on Linux and 30000 on Windows and macOS, where the guardian and helpers
|
|
37
|
+
* are slower under load.
|
|
38
|
+
*/
|
|
39
|
+
setupTimeoutMs?: number;
|
|
28
40
|
/** Linux delegated cgroup v2 directory; defaults to this process's cgroup. */
|
|
29
41
|
cgroupRoot?: string;
|
|
30
42
|
};
|
package/esm/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","names":[],"sources":["../../../../../../../packages/process/src/types.ts"],"mappings":";;YAEY;EACV;EACA;;EAEA;;EAEA;;YAEU;EACV;;EAEA;EACA,WAAW;;;;;EAKX;;;;;;EAMA;EACA;;EAEA;;YAEU;;EAEV;EACA;EACA;EACA;EACA,MAAM,OAAO;EACb,SAAS;EACT,SAAS;;YAEC;EAAkB,SAAS;;YAC3B;EACV;EACA;EACA;EACA;;YAEU;EACV;EACA;EACA;EACA;EACA;EACA,QAAQ;EACR;EACA,QAAQ;EACR;EACA;;YAEU;EACV;EACA,QAAQ;EACR,QAAQ;EACR,OAAO;EACP,QAAQ,QAAQ;EAChB,QAAQ;;YAEE,YAAY;EACtB,MAAM;EACN,OAAO,iBAAiB;;YAEd;EAAmB;EAAmB;EAAmB;;YACzD;EACV,MAAM,SAAS,eAAe,QAAQ;EACtC,SAAS,SAAS;IAAiB;IAAkB;MAAkB,QAAQ;EAC/E,KAAK,SAAS,gBAAgB,QAAQ;EACtC,KAAK,SAAS,gBAAgB;EAC9B,QAAQ,cAAc;EACtB,QAAQ;IACN,QAAQ,OAAO,0BAA0B;MACvC,QAAQ;EACZ,WAAW"}
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../../../../../../../packages/process/src/types.ts"],"mappings":";;YAEY;EACV;EACA;;EAEA;;EAEA;;YAEU;EACV;;EAEA;EACA,WAAW;;;;;EAKX;;;;;;EAMA;EACA;;;;;;EAMA;;;;;;EAMA;;EAEA;;YAEU;;EAEV;EACA;EACA;EACA;EACA,MAAM,OAAO;EACb,SAAS;EACT,SAAS;;YAEC;EAAkB,SAAS;;YAC3B;EACV;EACA;EACA;EACA;;YAEU;EACV;EACA;EACA;EACA;EACA;EACA,QAAQ;EACR;EACA,QAAQ;EACR;EACA;;YAEU;EACV;EACA,QAAQ;EACR,QAAQ;EACR,OAAO;EACP,QAAQ,QAAQ;EAChB,QAAQ;;YAEE,YAAY;EACtB,MAAM;EACN,OAAO,iBAAiB;;YAEd;EAAmB;EAAmB;EAAmB;;YACzD;EACV,MAAM,SAAS,eAAe,QAAQ;EACtC,SAAS,SAAS;IAAiB;IAAkB;MAAkB,QAAQ;EAC/E,KAAK,SAAS,gBAAgB,QAAQ;EACtC,KAAK,SAAS,gBAAgB;EAC9B,QAAQ,cAAc;EACtB,QAAQ;IACN,QAAQ,OAAO,0BAA0B;MACvC,QAAQ;EACZ,WAAW"}
|
package/llms-full.txt
CHANGED
|
@@ -89,6 +89,27 @@ await terminals.stopAll();
|
|
|
89
89
|
```
|
|
90
90
|
|
|
91
91
|
PTY stdout combines terminal output; stderr is empty. `stdin` is writable too.
|
|
92
|
+
ConPTY can report pid 0 right after spawn. The supervisor waits up to `pidWaitMs`
|
|
93
|
+
(default 10 s) for a real pid and never supervises pid 0. If none arrives it stops
|
|
94
|
+
the terminal on a best-effort basis and rejects with `ProcessStartupError`
|
|
95
|
+
(`reason: "no-pid"`). Catch it by class, for example:
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import { ProcessStartupError, supervisor } from "@warlock.js/process";
|
|
99
|
+
|
|
100
|
+
const terminals = supervisor({
|
|
101
|
+
owner: "terminals",
|
|
102
|
+
registry: "storage/terminals.json",
|
|
103
|
+
pidWaitMs: 5000,
|
|
104
|
+
setupTimeoutMs: 30_000,
|
|
105
|
+
});
|
|
106
|
+
try {
|
|
107
|
+
await terminals.spawnPty({ kind: "terminal", command: "powershell.exe" });
|
|
108
|
+
} catch (error) {
|
|
109
|
+
if (error instanceof ProcessStartupError) console.error(error.reason, error.message);
|
|
110
|
+
else throw error;
|
|
111
|
+
}
|
|
112
|
+
```
|
|
92
113
|
|
|
93
114
|
## Resource and lifecycle decisions
|
|
94
115
|
|
|
@@ -110,6 +131,9 @@ PTY stdout combines terminal output; stderr is empty. `stdin` is writable too.
|
|
|
110
131
|
until registry persistence, and survives supervisor restarts for recovery.
|
|
111
132
|
Memory includes the guardian and its descendants. No identity-helper setup
|
|
112
133
|
or custom native compilation is needed.
|
|
134
|
+
- Setup gate: `setupTimeoutMs` defaults to 5 s on Linux and 30 s on Windows and macOS.
|
|
135
|
+
A child that exits before its gate, or misses the deadline, rejects `spawn`/`spawnPty`
|
|
136
|
+
with `ProcessStartupError` (`reason`: `exited` or `setup-timeout`).
|
|
113
137
|
- Defaults per platform: `pollIntervalMs` 100 ms Linux, 500 macOS, 1500 Windows;
|
|
114
138
|
`observationTimeoutMs` (ownership check wait) 2 s Linux, 15 s macOS/Windows. Explicit
|
|
115
139
|
options win. Raise `observationTimeoutMs` on a loaded machine; the timeout error names it.
|
package/package.json
CHANGED
package/skills/SKILL.md
CHANGED
|
@@ -81,6 +81,27 @@ await terminals.stopAll();
|
|
|
81
81
|
```
|
|
82
82
|
|
|
83
83
|
PTY stdout combines terminal output; stderr is empty. `stdin` is writable too.
|
|
84
|
+
ConPTY can report pid 0 right after spawn. The supervisor waits up to `pidWaitMs`
|
|
85
|
+
(default 10 s) for a real pid and never supervises pid 0. If none arrives it stops
|
|
86
|
+
the terminal on a best-effort basis and rejects with `ProcessStartupError`
|
|
87
|
+
(`reason: "no-pid"`). Catch it by class, for example:
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
import { ProcessStartupError, supervisor } from "@warlock.js/process";
|
|
91
|
+
|
|
92
|
+
const terminals = supervisor({
|
|
93
|
+
owner: "terminals",
|
|
94
|
+
registry: "storage/terminals.json",
|
|
95
|
+
pidWaitMs: 5000,
|
|
96
|
+
setupTimeoutMs: 30_000,
|
|
97
|
+
});
|
|
98
|
+
try {
|
|
99
|
+
await terminals.spawnPty({ kind: "terminal", command: "powershell.exe" });
|
|
100
|
+
} catch (error) {
|
|
101
|
+
if (error instanceof ProcessStartupError) console.error(error.reason, error.message);
|
|
102
|
+
else throw error;
|
|
103
|
+
}
|
|
104
|
+
```
|
|
84
105
|
|
|
85
106
|
## Resource and lifecycle decisions
|
|
86
107
|
|
|
@@ -102,6 +123,9 @@ PTY stdout combines terminal output; stderr is empty. `stdin` is writable too.
|
|
|
102
123
|
until registry persistence, and survives supervisor restarts for recovery.
|
|
103
124
|
Memory includes the guardian and its descendants. No identity-helper setup
|
|
104
125
|
or custom native compilation is needed.
|
|
126
|
+
- Setup gate: `setupTimeoutMs` defaults to 5 s on Linux and 30 s on Windows and macOS.
|
|
127
|
+
A child that exits before its gate, or misses the deadline, rejects `spawn`/`spawnPty`
|
|
128
|
+
with `ProcessStartupError` (`reason`: `exited` or `setup-timeout`).
|
|
105
129
|
- Defaults per platform: `pollIntervalMs` 100 ms Linux, 500 macOS, 1500 Windows;
|
|
106
130
|
`observationTimeoutMs` (ownership check wait) 2 s Linux, 15 s macOS/Windows. Explicit
|
|
107
131
|
options win. Raise `observationTimeoutMs` on a loaded machine; the timeout error names it.
|