/** * Supervisor: spawns the server child, watches its exit, and decides whether to * respawn (crash, with backoff), update (exit code 75), stop (0), or give up * (crash-looping). The decision is a pure function so it is unit-tested without * spawning anything; runSupervisor() wires it to real process/npm adapters. */ /** Sentinel exit code the server uses to ask the supervisor for an update. */ export declare const UPDATE_EXIT_CODE = 75; /** * Sentinel exit code the server uses when it has ALREADY installed the update * itself (fetched in the background while still serving). The supervisor just * respawns — no install, no crash accounting — so the visible downtime is a * single process restart instead of a full npm install. */ export declare const RELOAD_EXIT_CODE = 76; export interface BackoffOpts { windowMs: number; cap: number; baseMs: number; maxMs: number; } export declare const DEFAULT_BACKOFF: BackoffOpts; export type Action = { kind: "stop"; } | { kind: "update"; } | { kind: "reload"; } | { kind: "respawn"; delayMs: number; } | { kind: "give-up"; reason: string; }; /** * Map a child exit code to the next action. `recentCrashes` is the list of * timestamps (ms) of prior crash-respawns; `now` is the current time. Only * genuine crashes count toward the cap — a clean stop or an update do not. */ export declare function nextAction(code: number, recentCrashes: number[], now: number, opts?: BackoffOpts): Action; export interface SupervisorDeps { /** Spawn the server child; resolves with its exit code when it exits. */ spawnServer: () => Promise; /** Fetch + install the latest server; returns the result to hand the child. */ update: () => Promise<{ ok: true; version: string; } | { ok: false; error: string; }>; /** Persist the update result so the next server boot can announce it. */ writeUpdateResult: (r: { ok: boolean; version?: string; error?: string; }) => void; sleep: (ms: number) => Promise; now: () => number; log: (msg: string) => void; } /** Run the supervise loop until the child stops cleanly or we give up. */ export declare function runSupervisor(deps: SupervisorDeps, opts?: BackoffOpts): Promise;