import { EventEmitter } from 'node:events'; import type { ProcessConfig } from '../config/schema.js'; export type Stream = 'stdout' | 'stderr'; export interface RunnerEvents { line: [text: string, stream: Stream]; exit: [code: number | null, signal: NodeJS.Signals | null]; error: [error: Error]; /** * A termination signal was sent to the process tree. Emitted with `SIGTERM` * when graceful stop begins and again with `SIGKILL` if the grace window * expires and the process has to be force-killed. Lets a reporter surface * "force killing X" rather than the kill happening silently. */ kill: [signal: NodeJS.Signals]; /** * An orphaned process holding one of the configured `ports` was force-killed * after the normal stop path completed (see `kill_orphan_ports`). Emitted once * per freed (port, pid) so a reporter can surface the resource-based cleanup. */ port_freed: [port: number, pid: number]; /** * The stop path had to synthesize this process's exit: after SIGKILL its * stdio pipes were still held, which means at least one descendant escaped * the process group and is probably still running. This is the one case * where teardown cannot guarantee a reaped tree — a reporter should say so * rather than print a clean "stopped". */ escaped: []; } export declare class Runner extends EventEmitter { readonly name: string; readonly config: ProcessConfig; private process; private exited; private stopPromise; /** * The descendant tree captured by the most recent `stop()`. Retained because * a graceful stop kills the intermediate parents first: once they are gone, * an escaped grandchild has reparented to init and a fresh `ppid` walk can no * longer find it. The emergency path (double Ctrl-C, crash) needs this * remembered set to finish the job. */ private lastTree; private _exitCode; private _exitSignal; constructor(name: string, config: ProcessConfig); get pid(): number | undefined; get running(): boolean; get exitCode(): number | null; get exitSignal(): NodeJS.Signals | null; start(): void; stop(graceMs?: number): Promise; private doStop; /** * Post-stop verification: confirm every process we snapshotted is actually * gone, and escalate on the ones that aren't (SIGTERM, brief grace, SIGKILL). * Emits `escaped` only if something outlives even that — the one case where * teardown genuinely cannot prove a reaped tree. */ private reapSurvivors; /** * Synchronous, unconditional SIGKILL of everything this runner spawned, for * the emergency paths (double Ctrl-C, uncaughtException) that must finish * before `process.exit()`. * * Signals the union of a fresh snapshot and the tree remembered from an * in-flight `stop()`: the fresh one covers a crash during normal operation, * the remembered one covers a force-quit *during* a graceful shutdown, where * the intermediate parents are already dead and the survivors have reparented * out of reach. */ emergencyKill(): void; /** * Resource-based teardown backstop, run after the process tree is reaped. When * `kill_orphan_ports` is set, force-kill anything still bound to one of the * process's declared ports — the escaped grandchild (e.g. a Firebase emulator * JVM) that survived the group/tree kill and would otherwise keep its port * bound for the next boot. No-op unless opted in and ports are known. */ private sweepOrphanPorts; /** * Ports the sweep should reclaim: the explicit `ports` list plus the local * `tcp`/`http` ready-check port (the one most likely to be held), * de-duplicated. */ private declaredPorts; /** * Last resort when a process tree won't release our stdio pipes after SIGKILL * (see stop()). Tears down our readers so the dangling execa promise can't * keep the event loop alive, and synthesizes the `exit` event so listeners * waiting on a clean stop (the orchestrator's state machine) aren't stranded. */ private forceExit; private runStopCommand; private awaitExit; } //# sourceMappingURL=runner.d.ts.map