@powerhousedao/host-core 6.4.0-next.3 → 6.4.0-next.5
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/dist/{compound-L62ALvYc.d.mts → compound-BLhEewO6.d.mts} +8 -2
- package/dist/compound-BLhEewO6.d.mts.map +1 -0
- package/dist/{compound-Q9sZSEZF.mjs → compound-g6x_KkWp.mjs} +133 -1208
- package/dist/compound-g6x_KkWp.mjs.map +1 -0
- package/dist/control-channel-DVn4dvfQ.d.mts +206 -0
- package/dist/control-channel-DVn4dvfQ.d.mts.map +1 -0
- package/dist/control-channel.d.mts +2 -2
- package/dist/control-channel.mjs +358 -47
- package/dist/control-channel.mjs.map +1 -1
- package/dist/host-entry-B8n_590_.mjs +188 -0
- package/dist/host-entry-B8n_590_.mjs.map +1 -0
- package/dist/index.d.mts +68 -102
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +6 -3
- package/dist/index.mjs.map +1 -1
- package/dist/instance-C6uugZ32.d.mts +165 -0
- package/dist/instance-C6uugZ32.d.mts.map +1 -0
- package/dist/instance.d.mts +3 -0
- package/dist/instance.mjs +145 -0
- package/dist/instance.mjs.map +1 -0
- package/dist/kill-tree.d.mts +2 -0
- package/dist/kill-tree.d.mts.map +1 -1
- package/dist/kill-tree.mjs +1 -1
- package/dist/kill-tree.mjs.map +1 -1
- package/dist/run-record-C6oTZF_C.mjs +1077 -0
- package/dist/run-record-C6oTZF_C.mjs.map +1 -0
- package/dist/runners/compound.d.mts +1 -1
- package/dist/runners/compound.mjs +2 -1
- package/dist/runners/compound.mjs.map +1 -1
- package/dist/spawn-host-DWroRe1S.d.mts +107 -0
- package/dist/spawn-host-DWroRe1S.d.mts.map +1 -0
- package/dist/supervisor-record.d.mts +88 -0
- package/dist/supervisor-record.d.mts.map +1 -0
- package/dist/supervisor-record.mjs +127 -0
- package/dist/supervisor-record.mjs.map +1 -0
- package/dist/supervisor.d.mts +205 -0
- package/dist/supervisor.d.mts.map +1 -0
- package/dist/supervisor.mjs +905 -0
- package/dist/supervisor.mjs.map +1 -0
- package/package.json +21 -3
- package/dist/compound-L62ALvYc.d.mts.map +0 -1
- package/dist/compound-Q9sZSEZF.mjs.map +0 -1
- package/dist/control-channel-eqvyUF03.d.mts +0 -123
- package/dist/control-channel-eqvyUF03.d.mts.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supervisor.mjs","names":[],"sources":["../src/process-tree.ts","../src/supervisor-client.ts","../src/supervisor.ts"],"sourcesContent":["import { execFile } from \"node:child_process\";\nimport path from \"node:path\";\nimport { killTree, treePids } from \"./kill-tree.js\";\nimport { isPidAlive, processStartedAtMs } from \"./run-record.js\";\n\n/**\n * The processes below a supervised one, so that those it leaves behind when\n * it ends by itself can be ended too. A process that exits takes no\n * descendant with it: on Windows `taskkill /T` no longer finds them once\n * their parent is gone, elsewhere they are handed to init.\n */\n\n/** Windows: every process as `pid parent created`, created in ticks. */\nfunction windowsProcessTable(): Promise<[number, number, number][]> {\n const powershell = path.join(\n process.env.SystemRoot ?? \"C:\\\\Windows\",\n \"System32\",\n \"WindowsPowerShell\",\n \"v1.0\",\n \"powershell.exe\",\n );\n return new Promise((resolve) => {\n execFile(\n powershell,\n [\n \"-NoProfile\",\n \"-NonInteractive\",\n \"-Command\",\n \"Get-CimInstance Win32_Process -Property ProcessId,ParentProcessId,CreationDate | \" +\n 'ForEach-Object { \"$($_.ProcessId) $($_.ParentProcessId) $($_.CreationDate.Ticks)\" }',\n ],\n { windowsHide: true, timeout: 20_000, encoding: \"utf8\" },\n (error, stdout) => {\n if (error) {\n resolve([]);\n return;\n }\n resolve(\n stdout\n .split(/\\r?\\n/)\n .map((line) => line.trim().split(/\\s+/).map(Number))\n .filter(\n (row): row is [number, number, number] =>\n Number.isInteger(row[0]) && Number.isInteger(row[1]),\n )\n .map(([pid, parent, created]) => [pid, parent, created || 0]),\n );\n },\n );\n });\n}\n\n/**\n * The pids of every descendant of `root`, without `root`. Empty when the\n * process table cannot be read.\n */\nexport async function descendantPids(root: number): Promise<number[]> {\n if (process.platform !== \"win32\") return treePids(root).slice(1);\n const table = await windowsProcessTable();\n const created = new Map(table.map(([pid, , at]) => [pid, at]));\n const tree = [root];\n for (let i = 0; i < tree.length; i++) {\n const parent = tree[i]!;\n const parentCreated = created.get(parent) ?? 0;\n for (const [pid, ppid, at] of table) {\n // A parent id outlives its process: a child is younger than its parent.\n if (ppid !== parent || tree.includes(pid) || at < parentCreated) continue;\n tree.push(pid);\n }\n }\n return tree.slice(1);\n}\n\n/**\n * Ends, with their trees, the processes of `pids` that still run and started\n * before `listedAt` (when the list was taken: a pid given to a newer process\n * since is left alone). Returns the pids it ended.\n */\nexport function killSurvivors(pids: readonly number[], listedAt: number) {\n const killed: number[] = [];\n for (const pid of pids) {\n if (!isPidAlive(pid)) continue;\n const started = processStartedAtMs(pid);\n if (started === undefined || started > listedAt) continue;\n killTree(pid, \"SIGKILL\");\n killed.push(pid);\n }\n return killed;\n}\n","import { randomUUID } from \"node:crypto\";\nimport {\n callControl,\n ControlError,\n type CallControlOptions,\n type ControlRecord,\n} from \"./control-channel.js\";\nimport { isPidAlive } from \"./run-record.js\";\nimport type { RunRecord } from \"./run-record-schema.js\";\nimport type { HostExit, SpawnedHost } from \"./spawn-host.js\";\nimport type {\n InstanceLifetime,\n SupervisedInstance,\n SupervisorStartParams,\n} from \"./supervisor.js\";\n\n/**\n * A tool's side of the supervisor: the requests of supervisor.ts as calls.\n * It opens a connection per request and loads nothing of the supervisor.\n */\n\n/** A lease: the supervisor stops what was started with the caller under it\n * when its connection ends, which it does with this process. */\nexport interface SupervisorLease {\n id: string;\n /** Ends it now: what lives with this caller is stopped. */\n release(): Promise<void>;\n /** Resolves when the supervisor no longer holds it (released, or the\n * supervisor went away). */\n readonly ended: Promise<void>;\n}\n\n/** Takes a lease. The connection does not keep this process running. */\nexport function holdSupervisorLease(\n control: ControlRecord,\n): Promise<SupervisorLease> {\n const id = randomUUID();\n const abort = new AbortController();\n return new Promise<SupervisorLease>((resolve, reject) => {\n let held = false;\n // The connection does not keep the process running; until the lease is\n // held, this does.\n const waiting = setInterval(() => undefined, 1_000);\n const ended = callControl(\n control,\n \"lease\",\n { id },\n {\n unref: true,\n signal: abort.signal,\n onOutput: () => {\n if (held) return;\n held = true;\n clearInterval(waiting);\n resolve({\n id,\n ended,\n release: () => {\n abort.abort();\n return ended;\n },\n });\n },\n },\n ).then(\n () => {\n clearInterval(waiting);\n if (!held) reject(new Error(\"The supervisor did not hold the lease.\"));\n },\n (error: unknown) => {\n clearInterval(waiting);\n if (!held)\n reject(error instanceof Error ? error : new Error(String(error)));\n },\n );\n });\n}\n\nexport interface SupervisedList {\n supervisor: { pid: number; mode: string; version: string; home: string };\n instances: SupervisedInstance[];\n}\n\n/** What the supervisor holds, and what else runs on `dataDir`. */\nexport async function listSupervised(\n control: ControlRecord,\n dataDir?: string,\n options: CallControlOptions = {},\n): Promise<SupervisedList> {\n return (await callControl(\n control,\n \"list\",\n dataDir === undefined ? {} : { dataDir },\n options,\n )) as SupervisedList;\n}\n\nexport async function startSupervised(\n control: ControlRecord,\n params: SupervisorStartParams,\n options: CallControlOptions = {},\n): Promise<{ instance: SupervisedInstance; started: boolean }> {\n return (await callControl(control, \"start\", params, options)) as {\n instance: SupervisedInstance;\n started: boolean;\n };\n}\n\nexport async function stopSupervised(\n control: ControlRecord,\n handle: string,\n): Promise<SupervisedInstance> {\n const result = (await callControl(control, \"stop\", { handle })) as {\n instance: SupervisedInstance;\n };\n return result.instance;\n}\n\nexport async function restartSupervised(\n control: ControlRecord,\n handle: string,\n options: CallControlOptions = {},\n): Promise<SupervisedInstance> {\n const result = (await callControl(\n control,\n \"restart\",\n { handle },\n options,\n )) as { instance: SupervisedInstance };\n return result.instance;\n}\n\nexport async function supervisedLogs(\n control: ControlRecord,\n handle: string,\n lines?: number,\n): Promise<{ text: string; logFile: string }> {\n return (await callControl(control, \"logs\", {\n handle,\n ...(lines === undefined ? {} : { lines }),\n })) as { text: string; logFile: string };\n}\n\n/** Stops the supervisor, and with it what it holds. */\nexport async function shutdownSupervisor(\n control: ControlRecord,\n): Promise<{ pid: number; held: number }> {\n return (await callControl(control, \"shutdown\")) as {\n pid: number;\n held: number;\n };\n}\n\n/** A host the supervisor holds, in the shape `spawnHost` returns. */\nexport interface SupervisedHost extends SpawnedHost {\n handle: string;\n lifetime: InstanceLifetime | undefined;\n /** What the supervisor said of it when it was started. */\n instance: SupervisedInstance;\n}\n\nconst EXITED_POLL_MS = 500;\n\n/**\n * `spawnHost` through the supervisor: the instance is the supervisor's\n * child, not this process's. `existing` is set when the key ran already;\n * its `stop()` then leaves it running, as `spawnHost`'s does. Aborting\n * `signal` while it starts stops it.\n */\nexport async function startSupervisedHost(\n control: ControlRecord,\n params: SupervisorStartParams,\n options: { signal?: AbortSignal } = {},\n): Promise<SupervisedHost> {\n const { instance, started } = await startSupervised(control, params, {\n ...(options.signal ? { signal: options.signal } : {}),\n });\n if (!instance.record) {\n throw new Error(\n `${params.host} runs under the supervisor (pid ${instance.pid}) without a run record this version reads: ${instance.missing.join(\"; \")}.`,\n );\n }\n const record: RunRecord = instance.record;\n const exit: HostExit = { code: null, signal: null, forced: false };\n const exited = new Promise<HostExit>((resolve) => {\n const timer = setInterval(() => {\n if (isPidAlive(instance.pid)) return;\n clearInterval(timer);\n resolve(exit);\n }, EXITED_POLL_MS);\n timer.unref();\n });\n const mine = started && instance.mine;\n return {\n handle: instance.handle,\n lifetime: instance.lifetime,\n instance,\n pid: instance.pid,\n dataDir: instance.dataDir,\n record,\n outputs: record.outputs,\n members: record.members,\n ...(mine ? {} : { existing: true as const }),\n exited,\n stop: async () => {\n if (!mine) return exit;\n try {\n const stopped = await stopSupervised(control, instance.handle);\n if (stopped.exit) {\n exit.code = stopped.exit.code;\n exit.signal = stopped.exit.signal as NodeJS.Signals | null;\n exit.forced = stopped.exit.forced;\n }\n } catch (error) {\n // The supervisor is gone, and what it held with it.\n if (!(error instanceof ControlError && error.code === \"unreachable\")) {\n throw error;\n }\n }\n return exit;\n },\n };\n}\n","import { spawn, type ChildProcess } from \"node:child_process\";\nimport fs from \"node:fs\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport { z } from \"zod\";\nimport {\n CONTROL_PROTOCOL,\n controlProtocolOf,\n openControlChannel,\n type ControlCall,\n type ControlChannel,\n} from \"./control-channel.js\";\nimport {\n childEnv,\n phCliEntryVersion,\n resolvePhCliEntry,\n stopsOnStdin,\n} from \"./host-entry.js\";\nimport {\n instanceOfRecord,\n restartDecision,\n runningInstance,\n type RestartPolicy,\n type RestartState,\n} from \"./instance.js\";\nimport { instanceKey, instanceRunDir } from \"./instance-key.js\";\nimport { killTree } from \"./kill-tree.js\";\nimport { writeOwnerOnlyFile } from \"./owner-only.js\";\nimport { descendantPids, killSurvivors } from \"./process-tree.js\";\nimport { isPidAlive, listRunRecords, recordKeyOf } from \"./run-record.js\";\nimport { runRecordSchema, type RunRecord } from \"./run-record-schema.js\";\nimport { requestStop, STOP_ON_STDIN_ENV } from \"./stop-channel.js\";\nimport {\n findSupervisor,\n supervisorHome,\n supervisorLockHolder,\n supervisorLockPath,\n supervisorRecordPath,\n type FoundSupervisor,\n type SupervisorMode,\n type SupervisorRecord,\n} from \"./supervisor-record.js\";\n\nexport * from \"./supervisor-record.js\";\nexport * from \"./supervisor-client.js\";\n\n/**\n * The supervisor of an OS user: one process that starts, stops and lists\n * instances for every tool of that user, and holds no application itself.\n *\n * An instance is the project's own `ph run <host>` as a child process: the\n * project's installed ph-cli (else ph-run) is found through its\n * `package.json` and started; nothing of the project is loaded here. After\n * that the supervisor knows an instance through its run record and its\n * process only, so projects on different versions run side by side. A host\n * that writes an older record, or none, is still started, listed and stopped\n * (by its process tree); what cannot be done with it is said in\n * {@link SupervisedInstance.missing}.\n *\n * Requests arrive on a control channel (control-channel.ts): `start`, `stop`,\n * `restart`, `list`, `logs`, `lease` and `shutdown`. An instance lives `with\n * the caller` (the default) or `with the supervisor`. A caller's lease is a\n * `lease` request it keeps open: when its connection ends, however the\n * caller ended, every instance started with the caller under that lease is\n * stopped with its process tree.\n *\n * A `start` may carry a restart policy. The supervisor then applies it, and\n * is the one party that does: an instance that was ready and ends on its own\n * is started again under its handle after the policy's delay, until it has\n * been restarted `maxRetries` times in a row without getting ready. A stop\n * that was asked for, a caller that left, or the supervisor stopping, never\n * restarts.\n */\n\ntype Env = Readonly<Record<string, string | undefined>>;\n\nexport type InstanceLifetime = \"caller\" | \"supervisor\";\n\n/** An instance as `list` shows it. */\nexport interface SupervisedInstance {\n /** Short, for commands: `stop 3`. */\n handle: string;\n /** The host as `ph run` takes it. */\n host: string;\n verb?: string;\n projectDir: string;\n dataDir: string;\n /** Of its last run, while it waits for a restart or after it ended. */\n pid: number;\n /** `restarting`: it ended on its own and its restart policy starts it\n * again after the delay. `failed`: that policy gave up; `restart.failed`\n * says why. */\n status:\n | \"starting\"\n | \"running\"\n | \"stopping\"\n | \"exited\"\n | \"restarting\"\n | \"failed\";\n /** False: it runs on a data folder this supervisor knows and was started\n * by something else. Listed from its run record, never stopped here. */\n mine: boolean;\n lifetime?: InstanceLifetime;\n startedAt: string;\n /** Where its output goes. */\n logFile?: string;\n /** The version of the project's ph-cli (or ph-run) that runs it. */\n runnerVersion?: string;\n /** Its run record, when it wrote one this version reads. */\n record?: RunRecord;\n /** The ports it bound and the URLs it published, from its record. */\n ports?: Record<string, number>;\n endpoints?: Record<string, string>;\n /** The protocol of its control channel, when its record names one. */\n controlProtocol?: number;\n /** What cannot be done with it, each with the reason. */\n missing: string[];\n /** How it ended. */\n exit?: { code: number | null; signal: string | null; forced: boolean };\n /** Where its restart policy stands, when it was started with one. */\n restart?: RestartState;\n}\n\nconst startParamsSchema = z.object({\n host: z.string().min(1),\n projectDir: z.string().min(1),\n /** The instance's data folder (default: the project folder). */\n dataDir: z.string().min(1).optional(),\n verb: z.string().min(1).optional(),\n /** What follows `ph run <host> [verb]`. */\n argv: z.array(z.string()).optional(),\n /** The entry's arguments in place of `run <host> [verb] -- <argv>`, for a\n * project whose version starts the host another way. */\n args: z.array(z.string()).optional(),\n /** Merged over the base env; may not set PH_USER_DATA_DIR. */\n env: z.record(z.string(), z.string()).optional(),\n /** The env the instance starts from, as the caller has it (default: a\n * clean one, see `childEnv`). */\n baseEnv: z.record(z.string(), z.string()).optional(),\n lifetime: z.enum([\"caller\", \"supervisor\"]).optional(),\n /** The caller's lease; needed to start with the caller. */\n lease: z.string().min(1).optional(),\n readyTimeoutMs: z.number().int().positive().optional(),\n stopTimeoutMs: z.number().int().positive().optional(),\n /** Both output streams are appended here (default: a file under the\n * supervisor's `logs/`). */\n logFile: z.string().min(1).optional(),\n /** `optional`: a host that has written no run record when the ready\n * timeout ends counts as running (default: it is stopped, and the start\n * fails). */\n record: z.enum([\"required\", \"optional\"]).optional(),\n /** Applied here when it ends on its own after it was ready (see\n * `restartDecision`). The supervisor is then the one party that restarts\n * it: its caller must not. */\n restart: z\n .object({\n enabled: z.boolean().optional(),\n maxRetries: z.number().int().min(0),\n delay: z.number().min(0),\n })\n .optional(),\n});\nexport type SupervisorStartParams = z.infer<typeof startParamsSchema>;\n\nconst handleParamsSchema = z.object({ handle: z.string().min(1) });\nconst listParamsSchema = z.object({\n /** Also lists what runs on this data folder. */\n dataDir: z.string().min(1).optional(),\n});\nconst logsParamsSchema = handleParamsSchema.extend({\n lines: z.number().int().positive().optional(),\n});\nconst leaseParamsSchema = z.object({ id: z.string().min(1) });\n\nfunction parse<T>(schema: z.ZodType<T>, params: unknown): T {\n const parsed = schema.safeParse(params ?? {});\n if (!parsed.success) {\n throw new Error(\n `Bad parameters: ${parsed.error.issues.map((i) => `${i.path.join(\".\") || \"<root>\"}: ${i.message}`).join(\"; \")}`,\n );\n }\n return parsed.data;\n}\n\nconst READY_TIMEOUT_MS = 120_000;\nconst STOP_TIMEOUT_MS = 30_000;\n/** How long a host that reads no stdin is given before it is asked again. */\nconst STOP_ASK_AGAIN_MS = 3_000;\nconst POLL_MS = 100;\nconst TAIL_BYTES = 8 * 1024;\n/** Ended instances kept for `list` and `logs`. */\nconst MAX_EXITED = 20;\nconst LOCK_WAIT_MS = 10_000;\n\nconst sleep = (ms: number) =>\n new Promise<void>((resolve) => {\n setTimeout(resolve, ms);\n });\n\n/** The record files under a data folder's `.ph/run/`, any version. */\nfunction runFiles(dataDir: string): string[] {\n const files: string[] = [];\n const walk = (dir: string, depth: number) => {\n let entries: fs.Dirent[];\n try {\n entries = fs.readdirSync(dir, { withFileTypes: true });\n } catch {\n return;\n }\n for (const entry of entries) {\n const at = path.join(dir, entry.name);\n if (entry.isFile() && entry.name.endsWith(\".json\")) files.push(at);\n // `<pkg>/` and `@scope/<pkg>/`.\n else if (entry.isDirectory() && depth < 2) walk(at, depth + 1);\n }\n };\n walk(instanceRunDir({ dataDir }), 0);\n return files;\n}\n\n/** The record the process `pid` wrote under `dataDir`: `record` when this\n * version reads it, `file` alone when it is of another shape. */\nfunction recordOfPid(\n dataDir: string,\n pid: number,\n): { file: string; record?: RunRecord } | undefined {\n let other: { file: string } | undefined;\n for (const file of runFiles(dataDir)) {\n let raw: unknown;\n try {\n raw = JSON.parse(fs.readFileSync(file, \"utf8\"));\n } catch {\n continue;\n }\n if ((raw as { pid?: unknown } | null)?.pid !== pid) continue;\n const parsed = runRecordSchema.safeParse(raw);\n if (parsed.success) return { file, record: parsed.data };\n other = { file };\n }\n return other;\n}\n\nfunction tailOf(file: string, from: number): string {\n try {\n const { size } = fs.statSync(file);\n const start = Math.max(from, size - TAIL_BYTES);\n const fd = fs.openSync(file, \"r\");\n try {\n const buffer = Buffer.alloc(Math.max(0, size - start));\n fs.readSync(fd, buffer, 0, buffer.length, start);\n return buffer.toString(\"utf8\");\n } finally {\n fs.closeSync(fd);\n }\n } catch {\n return \"\";\n }\n}\n\nconst NO_CHANNEL =\n \"no control channel: commands are not forwarded to it (it is listed, and stopped through its stdin or by its process tree)\";\n\n/** What cannot be done with an instance, from what it recorded. */\nfunction missingOf(found: { record?: RunRecord } | undefined): string[] {\n if (!found) {\n return [\n \"no run record: readiness, ports and endpoints are unknown\",\n NO_CHANNEL,\n ];\n }\n if (!found.record) {\n return [\n \"a run record of another version: ports and endpoints are not read\",\n NO_CHANNEL,\n ];\n }\n const protocol = controlProtocolOf(found.record);\n if (protocol === undefined) return [NO_CHANNEL];\n if (protocol !== CONTROL_PROTOCOL) {\n return [\n `control protocol ${protocol}, this supervisor speaks ${CONTROL_PROTOCOL}: commands are not forwarded to it from this version`,\n ];\n }\n return [];\n}\n\n/** The restart policy of a handle, kept across the runs it starts. */\ninterface Restarts {\n policy: RestartPolicy;\n /** Restarts made since it last got ready. */\n attempt: number;\n /** A run under this handle was ready once. */\n everReady: boolean;\n lastExit?: RestartState[\"lastExit\"];\n /** The restart it waits for. */\n timer?: NodeJS.Timeout;\n nextAt?: string;\n failed?: string;\n}\n\ninterface Managed {\n handle: string;\n key: string;\n params: SupervisorStartParams;\n projectDir: string;\n dataDir: string;\n lifetime: InstanceLifetime;\n lease?: string;\n child: ChildProcess;\n pid: number;\n status: \"starting\" | \"running\" | \"stopping\" | \"exited\";\n /** Set when it was started with a restart policy. */\n restarts?: Restarts;\n /** A stop was asked for: it is never restarted. */\n stopAsked: boolean;\n startedAt: string;\n logFile: string;\n runnerVersion?: string;\n /** Its release stops a standalone host when its stdin ends. */\n stopsOnStdin: boolean;\n found?: { file: string; record?: RunRecord };\n /** A record was waited for and none came. */\n recordless: boolean;\n exit?: SupervisedInstance[\"exit\"];\n /** Settles when it is ready, or could not be. */\n ready: Promise<void>;\n exited: Promise<void>;\n stop(): Promise<void>;\n}\n\nexport interface SupervisorOptions {\n /** Where `PH_SUPERVISOR_HOME` is read from (default: this process). */\n env?: Env;\n /** The version of the package this runs from, for `hello`. */\n version?: string;\n mode?: SupervisorMode;\n /** One line per event, for the terminal it runs in. */\n log?: (line: string) => void;\n}\n\nexport interface Supervisor {\n readonly record: SupervisorRecord;\n readonly home: string;\n /** Whether the system lets this user alone open its channel. */\n readonly ownerOnly: boolean;\n instances(): SupervisedInstance[];\n /** Stops what it holds, each with its process tree, removes its record\n * and closes its channel. */\n stop(): Promise<void>;\n /** Resolves once it has stopped, on `stop()` or a `shutdown` request. */\n readonly stopped: Promise<void>;\n}\n\nexport type SupervisorStart =\n | { supervisor: Supervisor }\n /** Another process is this user's supervisor: nothing was started. */\n | { existing: Exclude<FoundSupervisor, { status: \"none\" }> };\n\n/** Takes the user's supervisor lock; returns the process that holds it. */\nasync function takeLock(env: Env): Promise<{ pid: number } | undefined> {\n const file = supervisorLockPath(env);\n fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });\n const mine = JSON.stringify({\n pid: process.pid,\n startedAt: new Date().toISOString(),\n });\n for (let attempt = 0; attempt < 2; attempt++) {\n try {\n fs.writeFileSync(file, mine, { flag: \"wx\" });\n } catch {\n const holder = supervisorLockHolder(env);\n if (holder) return holder;\n // Left by a process that is gone.\n fs.rmSync(file, { force: true });\n continue;\n }\n // Two starters may each have cleared the other's leftover.\n await sleep(50);\n const holder = supervisorLockHolder(env);\n if (holder && holder.pid !== process.pid) return holder;\n if (holder) return undefined;\n }\n throw new Error(`Cannot take the supervisor lock ${file}.`);\n}\n\n/**\n * Makes this process the supervisor of its OS user. With one running\n * already (or recorded and silent) nothing is started and it is returned as\n * `existing`.\n */\nexport async function startSupervisor(\n options: SupervisorOptions = {},\n): Promise<SupervisorStart> {\n const env = options.env ?? process.env;\n const home = supervisorHome(env);\n const log = options.log ?? (() => undefined);\n const mode: SupervisorMode = options.mode ?? \"standalone\";\n const version = options.version ?? \"unknown\";\n\n const holder = await takeLock(env);\n if (holder) {\n // It may still be opening its channel.\n const deadline = Date.now() + LOCK_WAIT_MS;\n for (;;) {\n const found = await findSupervisor(env);\n if (found.status === \"running\" && found.record.pid === holder.pid) {\n return { existing: found };\n }\n if (Date.now() >= deadline) {\n return {\n existing:\n found.status === \"silent\"\n ? found\n : {\n status: \"silent\",\n pid: holder.pid,\n reason: \"it holds the lock and has recorded no channel.\",\n },\n };\n }\n if (!isPidAlive(holder.pid)) return startSupervisor(options);\n await sleep(200);\n }\n }\n\n const lockFile = supervisorLockPath(env);\n const recordFile = supervisorRecordPath(env);\n let channel: ControlChannel;\n try {\n channel = await openControlChannel({ mode });\n } catch (error) {\n fs.rmSync(lockFile, { force: true });\n throw error;\n }\n\n const instances = new Map<string, Managed>();\n const leases = new Set<string>();\n /** Data folders an instance was started on, by key, with a project. */\n const folders = new Map<string, { dataDir: string; projectDir: string }>();\n let counter = 0;\n let closing = false;\n\n const view = (m: Managed): SupervisedInstance => {\n // The record as it is now: a compound adds to it as members start.\n const record =\n m.status === \"exited\" ? m.found?.record : currentRecord(m)?.record;\n const facts = record\n ? instanceOfRecord(m.projectDir, record, {\n PH_USER_DATA_DIR: m.dataDir,\n })\n : undefined;\n const protocol = controlProtocolOf(record);\n return {\n handle: m.handle,\n host: m.params.host,\n ...(m.params.verb === undefined ? {} : { verb: m.params.verb }),\n projectDir: m.projectDir,\n dataDir: m.dataDir,\n pid: m.pid,\n status:\n m.status !== \"exited\"\n ? m.status\n : m.restarts?.timer\n ? \"restarting\"\n : m.restarts?.failed !== undefined\n ? \"failed\"\n : \"exited\",\n mine: true,\n lifetime: m.lifetime,\n startedAt: m.startedAt,\n logFile: m.logFile,\n ...(m.runnerVersion === undefined\n ? {}\n : { runnerVersion: m.runnerVersion }),\n ...(record ? { record } : {}),\n ...(facts ? { ports: facts.ports, endpoints: facts.endpoints } : {}),\n ...(protocol === undefined ? {} : { controlProtocol: protocol }),\n missing:\n m.status === \"starting\"\n ? []\n : [\n ...missingOf(m.recordless ? undefined : (m.found ?? {})),\n ...(m.stopsOnStdin\n ? []\n : [\n `a host of ${m.runnerVersion}: it does not stop with its stdin, so it is asked over its stop channel`,\n ]),\n ],\n ...(m.exit ? { exit: m.exit } : {}),\n ...(m.restarts\n ? {\n restart: {\n maxRetries: m.restarts.policy.maxRetries,\n delay: m.restarts.policy.delay,\n attempt: m.restarts.attempt,\n ...(m.restarts.lastExit ? { lastExit: m.restarts.lastExit } : {}),\n ...(m.restarts.nextAt === undefined\n ? {}\n : { nextAt: m.restarts.nextAt }),\n ...(m.restarts.failed === undefined\n ? {}\n : { failed: m.restarts.failed }),\n },\n }\n : {}),\n };\n };\n\n const leaseHeld = (m: Managed) =>\n m.lifetime !== \"caller\" || (m.lease !== undefined && leases.has(m.lease));\n\n /** Drops the restart `m` waits for; true when there was one. */\n const cancelRestart = (m: Managed): boolean => {\n const waiting = m.restarts?.timer;\n if (!m.restarts || !waiting) return false;\n clearTimeout(waiting);\n delete m.restarts.timer;\n delete m.restarts.nextAt;\n return true;\n };\n\n /**\n * The restart policy of an instance, applied here and nowhere else: the\n * run `m` ended on its own. Not after a stop that was asked for, while the\n * supervisor stops, or for a caller that has left.\n */\n const afterOwnExit = (m: Managed): void => {\n const restarts = m.restarts;\n if (!restarts || m.stopAsked || instances.get(m.handle) !== m) return;\n restarts.lastExit = {\n code: m.exit?.code ?? null,\n signal: m.exit?.signal ?? null,\n at: new Date().toISOString(),\n };\n if (!leaseHeld(m)) return;\n const decision = restartDecision(restarts.policy, {\n attempt: restarts.attempt,\n wasReady: restarts.everReady,\n closing,\n });\n if (decision.action === \"give-up\") {\n if (!restarts.everReady) return;\n const how =\n restarts.lastExit.signal !== null\n ? `signal ${restarts.lastExit.signal}`\n : `code ${restarts.lastExit.code}`;\n restarts.failed = `it ended on its own (${how}) after ${decision.attempts} restart(s) in a row; its restart policy allows ${restarts.policy.maxRetries}`;\n log(`[${m.handle}] ${m.params.host} is left ended: ${restarts.failed}.`);\n return;\n }\n if (decision.action !== \"restart\") return;\n restarts.attempt = decision.attempt;\n restarts.nextAt = new Date(Date.now() + decision.delayMs).toISOString();\n log(\n `[${m.handle}] ${m.params.host} ended on its own: restart ${decision.attempt} of ${restarts.policy.maxRetries} in ${decision.delayMs} ms.`,\n );\n restarts.timer = setTimeout(() => {\n delete restarts.timer;\n delete restarts.nextAt;\n if (closing || m.stopAsked || instances.get(m.handle) !== m) return;\n if (!leaseHeld(m)) return;\n // Something started it meanwhile: that one is the instance.\n const other = [...instances.values()].some(\n (x) => x !== m && x.key === m.key && x.status !== \"exited\",\n );\n if (other) return;\n try {\n const next = launch(m.params, m.handle, undefined, restarts);\n instances.set(m.handle, next);\n log(`[${m.handle}] restarting ${m.params.host} (pid ${next.pid}).`);\n } catch (error) {\n restarts.failed = `it could not be started again: ${error instanceof Error ? error.message : String(error)}`;\n log(`[${m.handle}] ${m.params.host} is left ended: ${restarts.failed}`);\n }\n }, decision.delayMs);\n };\n\n const currentRecord = (m: Managed) => {\n if (!m.found) return undefined;\n const now = recordOfPid(m.dataDir, m.pid);\n if (now) m.found = now;\n return m.found;\n };\n\n /** Instances on the known data folders that something else started. */\n const notMine = (extraDataDir?: string): SupervisedInstance[] => {\n const known = new Map(folders);\n if (extraDataDir) {\n const dataDir = path.resolve(extraDataDir);\n known.set(instanceKey(\"\", dataDir, {}).id, {\n dataDir,\n projectDir: dataDir,\n });\n }\n const listed: SupervisedInstance[] = [];\n for (const { dataDir, projectDir } of known.values()) {\n const readerEnv = { PH_USER_DATA_DIR: dataDir };\n const own = [...instances.values()].filter(\n (m) => m.dataDir === dataDir && m.status !== \"exited\",\n );\n const ownPids = new Set(own.map((m) => m.pid));\n // A compound's members write records of their own.\n const memberHosts = new Set(\n own.flatMap((m) =>\n Object.values(m.found?.record?.members ?? {}).map((x) => x.host),\n ),\n );\n let records: RunRecord[] = [];\n try {\n records = listRunRecords(projectDir, readerEnv);\n } catch {\n // an unreadable folder lists nothing\n }\n for (const record of records) {\n const key = recordKeyOf(record);\n if (ownPids.has(record.pid) || memberHosts.has(key)) continue;\n if (!isPidAlive(record.pid)) continue;\n const facts = instanceOfRecord(projectDir, record, readerEnv);\n const protocol = controlProtocolOf(record);\n listed.push({\n handle: \"-\",\n host: key,\n verb: record.verb,\n projectDir,\n dataDir,\n pid: record.pid,\n status: \"running\",\n mine: false,\n startedAt: record.startedAt,\n record,\n ports: facts.ports,\n endpoints: facts.endpoints,\n ...(protocol === undefined ? {} : { controlProtocol: protocol }),\n missing: [\n \"not started by this supervisor: it is not stopped or restarted here\",\n ],\n });\n }\n }\n return listed;\n };\n\n const find = (ref: string): Managed => {\n const exact = instances.get(ref);\n if (exact) return exact;\n const live = [...instances.values()].filter((m) => m.status !== \"exited\");\n const named = live.filter(\n (m) => m.params.host === ref || path.basename(m.projectDir) === ref,\n );\n if (named.length === 1) return named[0]!;\n throw new Error(\n named.length > 1\n ? `\"${ref}\" names ${named.length} instances (${named.map((m) => m.handle).join(\", \")}): give the handle.`\n : `No instance \"${ref}\" is held by this supervisor.`,\n );\n };\n\n const prune = () => {\n // One that waits for its restart is not history yet.\n const ended = [...instances.values()].filter(\n (m) => m.status === \"exited\" && !m.restarts?.timer,\n );\n for (const m of ended.slice(0, Math.max(0, ended.length - MAX_EXITED))) {\n instances.delete(m.handle);\n }\n };\n\n function launch(\n params: SupervisorStartParams,\n handle: string,\n signal?: AbortSignal,\n /** The handle's restart state, when its policy starts this run. */\n carried?: Restarts,\n ): Managed {\n const projectDir = path.resolve(params.projectDir);\n const dataDir = path.resolve(params.dataDir ?? projectDir);\n const key = instanceKey(params.host, projectDir, {\n PH_USER_DATA_DIR: dataDir,\n }).id;\n const lifetime = params.lifetime ?? \"caller\";\n const readyTimeoutMs = params.readyTimeoutMs ?? READY_TIMEOUT_MS;\n const stopTimeoutMs = params.stopTimeoutMs ?? STOP_TIMEOUT_MS;\n let entry: string;\n try {\n entry = resolvePhCliEntry(projectDir);\n } catch {\n throw new Error(\n `${projectDir} has neither @powerhousedao/ph-cli nor @powerhousedao/ph-run installed: there is nothing to start ${params.host} with.`,\n );\n }\n const runnerVersion = phCliEntryVersion(entry);\n const childEnvironment = childEnv(\n dataDir,\n { ...params.env, [STOP_ON_STDIN_ENV]: \"1\" },\n params.baseEnv,\n );\n fs.mkdirSync(dataDir, { recursive: true });\n const logFile =\n params.logFile ??\n path.join(\n home,\n \"logs\",\n `${handle}-${params.host.replace(/[^\\w.-]+/g, \"_\")}.log`,\n );\n fs.mkdirSync(path.dirname(logFile), { recursive: true });\n const args = params.args ?? [\n \"run\",\n params.host,\n ...(params.verb === undefined ? [] : [params.verb]),\n ...(params.argv?.length ? [\"--\", ...params.argv] : []),\n ];\n const logFd = fs.openSync(logFile, \"a\");\n const logStart = fs.fstatSync(logFd).size;\n let child: ChildProcess;\n try {\n child = spawn(process.execPath, [entry, ...args], {\n cwd: projectDir,\n env: childEnvironment,\n stdio: [\"pipe\", logFd, logFd],\n windowsHide: true,\n });\n } finally {\n fs.closeSync(logFd);\n }\n child.stdin?.on(\"error\", () => undefined);\n if (child.pid === undefined) {\n throw new Error(`${params.host} could not be started in ${projectDir}.`);\n }\n const pid: number = child.pid;\n\n let forced = false;\n let resolveExited!: () => void;\n const exited = new Promise<void>((resolve) => (resolveExited = resolve));\n const what = `ph run ${params.host}`;\n\n const m: Managed = {\n handle,\n key,\n params,\n projectDir,\n dataDir,\n lifetime,\n ...(params.lease === undefined ? {} : { lease: params.lease }),\n child,\n pid,\n status: \"starting\",\n ...(carried\n ? { restarts: carried }\n : params.restart?.enabled\n ? {\n restarts: {\n policy: params.restart,\n attempt: 0,\n everReady: false,\n },\n }\n : {}),\n stopAsked: false,\n startedAt: new Date().toISOString(),\n logFile,\n ...(runnerVersion === undefined ? {} : { runnerVersion }),\n stopsOnStdin: stopsOnStdin(runnerVersion),\n recordless: false,\n ready: Promise.resolve(),\n exited,\n // Asked for from outside: its restart policy does not bring it back.\n stop: () => {\n m.stopAsked = true;\n cancelRestart(m);\n return stop();\n },\n };\n\n const clearRecords = () => {\n for (const file of runFiles(dataDir)) {\n try {\n const raw = JSON.parse(fs.readFileSync(file, \"utf8\")) as {\n pid?: unknown;\n } | null;\n if (raw?.pid === pid) fs.rmSync(file, { force: true });\n } catch {\n // not a record, or gone\n }\n }\n };\n\n child.once(\"exit\", (code, sig) => {\n m.exit = { code, signal: sig, forced };\n m.status = \"exited\";\n // A killed host skips its own clear.\n clearRecords();\n log(\n `[${handle}] ${params.host} ended (${sig !== null ? `signal ${sig}` : `code ${code}`}${forced ? \", killed\" : \"\"}).`,\n );\n resolveExited();\n // With a restart policy, after that has decided.\n if (!m.restarts) prune();\n });\n child.once(\"error\", () => undefined);\n\n let stopping: Promise<void> | undefined;\n function stop(): Promise<void> {\n stopping ??= (async () => {\n if (m.status === \"exited\") return;\n m.status = \"stopping\";\n // What it leaves behind is ended after it.\n const listedAt = Date.now();\n const below = await descendantPids(pid);\n if ((m.status as string) !== \"exited\") {\n let timers: NodeJS.Timeout[] = [];\n if (m.stopsOnStdin) {\n // The end of its stdin is the request to stop.\n child.stdin?.end();\n } else {\n // Its own `--stop`; its stdin stays open, so nothing is asked twice.\n void requestStop(pid);\n }\n // One that wrote no record of this version may not read stdin.\n if (m.stopsOnStdin && !m.found?.record) {\n timers.push(\n setTimeout(() => void requestStop(pid), STOP_ASK_AGAIN_MS),\n );\n }\n const timedOut = await Promise.race([\n exited.then(() => false),\n new Promise<boolean>((resolve) => {\n timers.push(setTimeout(() => resolve(true), stopTimeoutMs));\n }),\n ]);\n for (const timer of timers) clearTimeout(timer);\n timers = [];\n if (timedOut) {\n forced = true;\n killTree(pid, \"SIGKILL\");\n }\n await exited;\n }\n const left = killSurvivors(below, listedAt);\n if (left.length > 0) {\n log(\n `[${handle}] ${params.host} left ${left.length} process(es) behind (${left.join(\", \")}): ended.`,\n );\n }\n clearRecords();\n })();\n return stopping;\n }\n\n m.ready = (async () => {\n const deadline = Date.now() + readyTimeoutMs;\n for (;;) {\n if (m.status === \"exited\") {\n const how =\n m.exit?.signal != null\n ? `signal ${m.exit.signal}`\n : `code ${m.exit?.code}`;\n throw new StartFailed(\n `supervisor: ${what} exited (${how}) before writing its run record.`,\n tailOf(logFile, logStart),\n );\n }\n if (m.status === \"stopping\" || signal?.aborted) {\n await stop();\n throw new StartFailed(\n `supervisor: ${what} was stopped before it was ready.`,\n tailOf(logFile, logStart),\n );\n }\n const found = recordOfPid(dataDir, pid);\n if (found) {\n m.found = found;\n m.status = \"running\";\n return;\n }\n if (Date.now() >= deadline) {\n if (params.record === \"optional\") {\n m.recordless = true;\n m.status = \"running\";\n return;\n }\n const tail = tailOf(logFile, logStart);\n await stop();\n throw new StartFailed(\n `supervisor: ${what} wrote no run record within ${readyTimeoutMs} ms.`,\n tail,\n );\n }\n await Promise.race([sleep(POLL_MS), exited]);\n }\n })();\n // Awaited by the start that asked; a later one reads the status.\n m.ready.catch(() => undefined);\n const { restarts } = m;\n if (restarts) {\n void m.ready\n .then(\n () => {\n // A ready start resets the count.\n restarts.everReady = true;\n restarts.attempt = 0;\n },\n () => undefined,\n )\n .then(() => exited)\n .then(() => {\n afterOwnExit(m);\n prune();\n });\n }\n return m;\n }\n\n async function start(\n params: SupervisorStartParams,\n call?: ControlCall,\n ): Promise<{ instance: SupervisedInstance; started: boolean }> {\n if (closing) throw new Error(\"The supervisor is stopping.\");\n const projectDir = path.resolve(params.projectDir);\n const dataDir = path.resolve(params.dataDir ?? projectDir);\n const readerEnv = { PH_USER_DATA_DIR: dataDir };\n const key = instanceKey(params.host, projectDir, readerEnv).id;\n const lifetime = params.lifetime ?? \"caller\";\n folders.set(instanceKey(\"\", projectDir, readerEnv).id, {\n dataDir,\n projectDir,\n });\n\n // One instance per (host, data folder): the one that runs is returned.\n for (;;) {\n const held = [...instances.values()].find(\n (m) => m.key === key && m.status !== \"exited\",\n );\n if (!held) break;\n if (held.status === \"stopping\") {\n await held.exited;\n continue;\n }\n await held.ready.catch(() => undefined);\n if ((held.status as string) !== \"running\") continue;\n return { instance: view(held), started: false };\n }\n // This start takes the place of a restart the key waits for.\n for (const m of instances.values()) {\n if (m.key === key && cancelRestart(m)) {\n log(\n `[${m.handle}] ${m.params.host} is started anew: its restart is dropped.`,\n );\n }\n }\n let theirs: ReturnType<typeof runningInstance>;\n try {\n theirs = runningInstance(projectDir, params.host, { env: readerEnv });\n } catch {\n // The host's name is not its record's key: its own `ph run` decides.\n }\n if (theirs) {\n const other = notMine(dataDir).find((i) => i.pid === theirs.pid);\n if (other) return { instance: other, started: false };\n }\n if (lifetime === \"caller\" && !(params.lease && leases.has(params.lease))) {\n throw new Error(\n `${params.host} was not started: an instance that lives with its caller needs the caller's lease (a \"lease\" request held open), and \"${params.lease ?? \"\"}\" is not held.`,\n );\n }\n\n const handle = String(++counter);\n const managed = launch({ ...params, lifetime }, handle, call?.signal);\n instances.set(handle, managed);\n log(\n `[${handle}] starting ${params.host} in ${projectDir} (pid ${managed.pid}, with the ${lifetime}).`,\n );\n await managed.ready;\n // The lease may have ended while it started.\n if (managed.lease && !leases.has(managed.lease) && lifetime === \"caller\") {\n await managed.stop();\n throw new Error(\n `${params.host} was stopped: its caller ended while it started.`,\n );\n }\n log(`[${handle}] ${params.host} is running.`);\n return { instance: view(managed), started: true };\n }\n\n const stopAll = async (which: (m: Managed) => boolean): Promise<number> => {\n // One that waits for its restart counts: the stop drops the restart.\n const targets = [...instances.values()].filter(\n (m) => (m.status !== \"exited\" || m.restarts?.timer) && which(m),\n );\n await Promise.all(targets.map((m) => m.stop()));\n return targets.length;\n };\n\n channel.describe({ supervisor: true, version });\n channel.handle(\"start\", (params, call) =>\n start(parse(startParamsSchema, params), call),\n );\n channel.handle(\"stop\", async (params) => {\n const m = find(parse(handleParamsSchema, params).handle);\n await m.stop();\n return { instance: view(m) };\n });\n channel.handle(\"restart\", async (params, call) => {\n const m = find(parse(handleParamsSchema, params).handle);\n await m.stop();\n if (m.lifetime === \"caller\" && !(m.lease && leases.has(m.lease))) {\n throw new Error(\n `${m.params.host} was stopped and not started again: its caller has ended.`,\n );\n }\n if (closing) throw new Error(\"The supervisor is stopping.\");\n // The same handle names the new run.\n const next = launch(m.params, m.handle, call.signal);\n instances.set(m.handle, next);\n log(`[${m.handle}] restarting ${m.params.host} (pid ${next.pid}).`);\n await next.ready;\n return { instance: view(next) };\n });\n channel.handle(\"list\", (params) => {\n const { dataDir } = parse(listParamsSchema, params);\n return {\n supervisor: { pid: process.pid, mode, version, home },\n instances: [...[...instances.values()].map(view), ...notMine(dataDir)],\n };\n });\n channel.handle(\"logs\", (params) => {\n const { handle, lines } = parse(logsParamsSchema, params);\n const m = find(handle);\n let text = \"\";\n try {\n text = fs\n .readFileSync(m.logFile, \"utf8\")\n .split(\"\\n\")\n .slice(-(lines ?? 50) - 1)\n .join(\"\\n\");\n } catch {\n // no output yet\n }\n return { text, logFile: m.logFile };\n });\n channel.handle(\"lease\", async (params, call) => {\n const { id } = parse(leaseParamsSchema, params);\n if (leases.has(id)) throw new Error(`The lease \"${id}\" is held already.`);\n leases.add(id);\n call.write(\"stdout\", \"held\\n\");\n await new Promise<void>((resolve) => {\n if (call.signal.aborted) resolve();\n else\n call.signal.addEventListener(\"abort\", () => resolve(), { once: true });\n });\n leases.delete(id);\n const stopped = await stopAll(\n (m) => m.lifetime === \"caller\" && m.lease === id,\n );\n if (stopped > 0) {\n log(`A caller ended: ${stopped} instance(s) that lived with it stopped.`);\n }\n return { stopped };\n });\n\n let resolveStopped!: () => void;\n const stopped = new Promise<void>((resolve) => (resolveStopped = resolve));\n\n const removeOwn = () => {\n try {\n const recorded = JSON.parse(fs.readFileSync(recordFile, \"utf8\")) as {\n pid?: unknown;\n };\n if (recorded.pid === process.pid) fs.rmSync(recordFile, { force: true });\n } catch {\n // none, or not readable\n }\n try {\n const locked = JSON.parse(fs.readFileSync(lockFile, \"utf8\")) as {\n pid?: unknown;\n };\n if (locked.pid === process.pid) fs.rmSync(lockFile, { force: true });\n } catch {\n // none\n }\n };\n // When this process ends without `stop()`: an instance that reads its\n // stdin stops as that closes; one that may not is ended here.\n const onExit = () => {\n for (const m of instances.values()) {\n if (m.status === \"exited\") continue;\n if (!m.found?.record || !m.stopsOnStdin) killTree(m.pid, \"SIGKILL\");\n }\n removeOwn();\n };\n process.once(\"exit\", onExit);\n\n let stoppingAll: Promise<void> | undefined;\n const stop = (): Promise<void> =>\n (stoppingAll ??= (async () => {\n closing = true;\n // Those still starting see `stopping` and end their wait.\n const held = await stopAll(() => true);\n if (held > 0) log(`Stopped ${held} instance(s).`);\n removeOwn();\n process.off(\"exit\", onExit);\n await channel.close();\n resolveStopped();\n })());\n\n channel.handle(\"shutdown\", () => {\n const held = [...instances.values()].filter(\n (m) => m.status !== \"exited\",\n ).length;\n // After the answer: closing the channel ends this request's connection.\n setTimeout(() => void stop(), 20);\n return { pid: process.pid, held };\n });\n\n let user = \"\";\n try {\n user = os.userInfo().username;\n } catch {\n // no entry for this uid\n }\n const record: SupervisorRecord = {\n version: 1,\n pid: process.pid,\n startedAt: new Date().toISOString(),\n supervisorVersion: version,\n mode,\n user,\n control: channel.record,\n };\n try {\n writeOwnerOnlyFile(recordFile, `${JSON.stringify(record, null, 2)}\\n`);\n } catch (error) {\n process.off(\"exit\", onExit);\n removeOwn();\n await channel.close();\n throw error;\n }\n\n return {\n supervisor: {\n record,\n home,\n ownerOnly: channel.ownerOnly,\n instances: () => [...instances.values()].map(view),\n stop,\n stopped,\n },\n };\n}\n\n/** A start that failed, with the end of the instance's output. The message\n * holds both, as `SpawnHostError`'s does. */\nclass StartFailed extends Error {\n constructor(message: string, outputTail: string) {\n super(\n outputTail ? `${message}\\n--- output tail ---\\n${outputTail}` : message,\n );\n this.name = \"StartFailed\";\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAaA,SAAS,sBAA2D;CAClE,MAAM,aAAa,KAAK,KACtB,QAAQ,IAAI,cAAc,eAC1B,YACA,qBACA,QACA,gBACF;CACA,OAAO,IAAI,SAAS,YAAY;EAC9B,SACE,YACA;GACE;GACA;GACA;GACA;EAEF,GACA;GAAE,aAAa;GAAM,SAAS;GAAQ,UAAU;EAAO,IACtD,OAAO,WAAW;GACjB,IAAI,OAAO;IACT,QAAQ,CAAC,CAAC;IACV;GACF;GACA,QACE,OACG,MAAM,OAAO,CAAC,CACd,KAAK,SAAS,KAAK,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,IAAI,MAAM,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EACd,QAAQ,IAAI,QAAQ,MAAM;EAC1B,UAAU;EACV,MAAM,QAAQ,MAAM;EACpB,MAAM;CACR;CAEA,OAAO,EACL,YAAY;EACV;EACA;EACA,WAAW,QAAQ;EACnB,iBAAiB,CAAC,GAAG,UAAU,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI;EACjD;EACA;CACF,EACF;AACF;;;AAIA,IAAM,cAAN,cAA0B,MAAM;CAC9B,YAAY,SAAiB,YAAoB;EAC/C,MACE,aAAa,GAAG,QAAQ,yBAAyB,eAAe,OAClE;EACA,KAAK,OAAO;CACd;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerhousedao/host-core",
|
|
3
|
-
"version": "6.4.0-next.
|
|
3
|
+
"version": "6.4.0-next.5",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -41,6 +41,24 @@
|
|
|
41
41
|
"import": "./dist/control-channel.mjs",
|
|
42
42
|
"default": "./dist/control-channel.mjs"
|
|
43
43
|
},
|
|
44
|
+
"./instance": {
|
|
45
|
+
"source": "./src/instance.ts",
|
|
46
|
+
"types": "./dist/instance.d.mts",
|
|
47
|
+
"import": "./dist/instance.mjs",
|
|
48
|
+
"default": "./dist/instance.mjs"
|
|
49
|
+
},
|
|
50
|
+
"./supervisor": {
|
|
51
|
+
"source": "./src/supervisor.ts",
|
|
52
|
+
"types": "./dist/supervisor.d.mts",
|
|
53
|
+
"import": "./dist/supervisor.mjs",
|
|
54
|
+
"default": "./dist/supervisor.mjs"
|
|
55
|
+
},
|
|
56
|
+
"./supervisor-record": {
|
|
57
|
+
"source": "./src/supervisor-record.ts",
|
|
58
|
+
"types": "./dist/supervisor-record.d.mts",
|
|
59
|
+
"import": "./dist/supervisor-record.mjs",
|
|
60
|
+
"default": "./dist/supervisor-record.mjs"
|
|
61
|
+
},
|
|
44
62
|
"./plugins": {
|
|
45
63
|
"source": "./src/plugins.ts",
|
|
46
64
|
"types": "./dist/plugins.d.mts",
|
|
@@ -61,13 +79,13 @@
|
|
|
61
79
|
}
|
|
62
80
|
},
|
|
63
81
|
"dependencies": {
|
|
64
|
-
"@powerhousedao/shared": "6.4.0-next.
|
|
82
|
+
"@powerhousedao/shared": "6.4.0-next.5",
|
|
65
83
|
"zod": "^4.5.4"
|
|
66
84
|
},
|
|
67
85
|
"devDependencies": {
|
|
68
86
|
"tsdown": "0.23.0",
|
|
69
87
|
"vitest": "5.0.3",
|
|
70
|
-
"@powerhousedao/reactor-monitor": "6.4.0-next.
|
|
88
|
+
"@powerhousedao/reactor-monitor": "6.4.0-next.5"
|
|
71
89
|
},
|
|
72
90
|
"scripts": {
|
|
73
91
|
"tsc": "tsc",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compound-L62ALvYc.d.mts","names":[],"sources":["../src/host-ref.ts","../src/host-schemas.ts","../src/resolve/declared.ts","../src/runner-resolver.ts","../src/child-wrapper.ts","../src/resolve/plan.ts","../src/runner-handle.ts","../src/compound.ts"],"mappings":";;;;;;;;;;;;;cAsBa,sBAAsB;EACjC,YAAY,iBAAiB;;;;UAQd;EACf;EACA;;UAGe;;EAEf;;EAEA;;;iBAIc,aAAa,cAAc;iBAyB3B,cAAc,KAAK;;;iBAMnB,cACd,gBACA,cAAc;;;;;;;;;iBA2BA,mBACd,kBACA;;;iBAkBc,gBACd,qBACA,cACA,eACC;;UAgCc;;;;EAIf;;EAEA;;EAEA;;EAEA,UAAU;;;;;;;;;;iBAgCI,WACd,qBACA,aACA,QAAQ,cACP;;;;;;;;;;;;;;;;cCnLU,mBAAiB;cACjB;cACA;cAEA,gBAAc,EAAA;;;;;cAUd,sBAAoB;;;;cAMpB,kBAAgB;cAGhB;;;;;;cAQA,mBAAiB,EAAA,mBAAA,EAAA,QAAA,EAAA;cAOjB,eAAa,EAAA;;;;;GAKxB,EAAA,KAAA;cAEW,uBAAqB,EAAA;;;;;;;;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