import { EventEmitter } from 'node:events'; import type { OrckitConfig } from '../config/schema.js'; import { type OutputLine } from '../process/output.js'; import { type BuildEvent } from '../process/parsers.js'; import { type ProcessState } from './lifecycle.js'; import { type HookKind } from './hooks.js'; import { type PreflightResult } from './preflight.js'; export interface BootSummary { ready: string[]; failed: string[]; pending: string[]; /** * Subset of `failed` that did NOT opt into `manual_retry: true`. When this * is non-empty, `start()` will throw `BootFailedError` immediately after * emitting `boot:complete` — reporters should treat the boot as fatal and * not suggest a retry. */ strictFailures: string[]; } /** * Thrown by `start()` when one or more processes that are NOT marked * `manual_retry: true` failed during boot. The orchestrator's other * processes will already have been started but the boot is considered * fatal — the caller should typically tear down and exit. */ export declare class BootFailedError extends Error { readonly strictFailures: string[]; readonly summary: BootSummary; constructor(strictFailures: string[], summary: BootSummary); } /** * Thrown (internally) by a startup that was cancelled because a shutdown or * restart landed while it was still in flight — mid `pre_start` hook, between * hook and spawn, or during the health wait. It deliberately does NOT mark the * process `failed`: a cancelled start is not a failure, and treating it as one * would turn every Ctrl-C during boot into a spurious `BootFailedError`. */ export declare class StartupAbortedError extends Error { constructor(name: string); } export type OrckitEvents = { 'preflight:start': []; 'preflight:result': [result: PreflightResult]; 'preflight:complete': [allPassed: boolean]; 'process:state': [name: string, state: ProcessState]; 'process:starting': [name: string]; /** * The subprocess exists: `pid` is also its process-group id (children are * spawned detached). Emitted once per spawn attempt, before any ready check. * Consumers that need to reach the OS process — session tracking, external * supervisors — should key off this rather than `process:starting`, which * fires before the spawn. */ 'process:spawned': [name: string, pid: number, command: string]; 'process:ready': [name: string, durationMs: number]; 'process:running': [name: string]; 'process:finished': [name: string, durationMs: number]; 'process:stopping': [name: string]; 'process:killed': [name: string, signal: NodeJS.Signals]; 'process:port-freed': [name: string, port: number, pid: number]; /** * A descendant of this process escaped the process group and survived * SIGKILL of the tree — teardown could not prove it was reaped. Rare; the * fix is usually declaring the process's `ports` with `kill_orphan_ports`. */ 'process:escaped': [name: string]; 'process:stopped': [name: string, durationMs?: number]; 'process:failed': [name: string, error?: Error]; 'process:restarting': [name: string, attempt: number]; 'process:line': [name: string, line: OutputLine]; 'process:build': [name: string, event: BuildEvent]; 'hook:start': [name: string, hook: HookKind]; 'hook:line': [name: string, hook: HookKind, text: string, stream: 'stdout' | 'stderr']; 'hook:complete': [name: string, hook: HookKind]; 'hook:failed': [name: string, hook: HookKind, error: Error]; 'boot:complete': [summary: BootSummary]; 'all:ready': [names: string[]]; }; export interface RestartOptions { /** When true (default), also restart all transitive dependents of each target. */ cascade?: boolean; } export declare class Orckit extends EventEmitter { readonly config: OrckitConfig; private readonly graph; private readonly handles; private stopping; /** Set once by dispose(); permanently blocks every spawn path afterwards. */ private disposed; private inStartLoop; constructor(config: OrckitConfig); get projectName(): string; start(targets?: string[]): Promise; stop(targets?: string[]): Promise; /** * Start additional processes at runtime, after the initial `start()` boot. * Pulls in transitive dependencies (skipping any already in a ready/running * state). Does NOT emit `boot:complete` or `all:ready`, and does NOT throw * `BootFailedError` — the caller already chose to add these, so a failure * is theirs to handle (typically by retrying via the REPL or web UI). * * Use for optional processes, on-demand admin tools, or anything you didn't * include in the original boot set. */ startTargets(targets: string[]): Promise; restart(targets: string[], options?: RestartOptions): Promise; state(name: string): ProcessState; states(): Map; output(name: string, n?: number): OutputLine[]; /** * Snapshot of a process's runtime metadata. Exposes the bits of the private * `Handle` that consumers (status reporters, MCP server) need without * letting them mutate it. */ inspect(name: string): { state: ProcessState; pid: number | null; startedAt: number | null; retries: number; }; dispose(): Promise; /** * Last-ditch, fully SYNCHRONOUS kill sweep for crash paths * (uncaughtException / unhandledRejection) where no async teardown can be * awaited. SIGKILLs every live runner's process group. Skips hooks, docker * cleanup and port sweeps — this is strictly better than exiting with the * children alive, not a replacement for `dispose()`. */ emergencyKill(): void; private bootSummary; private depsReady; /** * Start any pending process whose dependencies are now ready. Fire-and-forget. * Skipped while a start/restart loop is driving startup itself — that loop * awaits each child sequentially and would race with a kicked start. */ private kickPending; private doPreflight; private startOne; private spawnAndAwaitReady; private doSpawnAndAwaitReady; private announceSpawn; private markReadyAndRunning; private markReadyAndFinished; private stopOne; /** * Post-stop backstop for `kill_orphan_ports`: once the normal teardown has run * (SIGTERM → grace → SIGKILL of the whole tree, docker cleanup, post_stop), * force-kill anything still bound to one of this process's declared `ports` * (plus its tcp ready-check port). This is what reaps children that escaped the * process group and kept a port held — classically the JVM Firebase emulators. * No-op unless the process opted in. Emits `process:port-freed` per reaped pid. */ private sweepOrphanPorts; private handleLine; private handleExit; private maybeRestart; private runHookSafe; private applyEvent; private makeHandle; private requireHandle; } //# sourceMappingURL=orchestrator.d.ts.map