/**
 * @module        supervisor
 * @description   进程监管器，管理 Worker 句柄生命周期、终止与孤儿监控
 *
 * @author        eddy
 * @organization  wykj
 * @ownership     wykj/eddy
 *
 * @created       2026-03-25
 * @updated       2026-04-03
 *
 * @role          manager
 * @layer         manager
 * @boundedContext worker-lifecycle
 */
import type { ChildProcess } from 'node:child_process';
export interface SpawnOpts {
    /** Unique worker ID: `${project}:${slot}:${seq}` */
    id: string;
    project: string;
    seq: string;
    slot: string;
    worktree: string;
    branch: string;
    prompt: string;
    outputFile: string;
    tool: 'claude';
    resumeSessionId?: string;
    /** Called when child process exits. Return value is tracked as pending PostAction. */
    onExit: (exitCode: number) => Promise<void> | void;
}
/** An exit event waiting to be processed */
export interface ExitEvent {
    id: string;
    exitCode: number;
    handle: WorkerHandle;
}
export interface WorkerHandle {
    id: string;
    transport: 'acp-sdk';
    pid: number | null;
    child: ChildProcess | null;
    outputFile: string | null;
    project: string;
    seq: string;
    slot: string;
    branch: string;
    worktree: string;
    tool: 'claude';
    exitCode: number | null;
    sessionId: string | null;
    runId: string | null;
    sessionState: 'booting' | 'ready' | 'busy' | 'needs_confirmation' | 'draining' | 'offline' | null;
    remoteStatus: 'submitted' | 'running' | 'waiting_input' | 'needs_confirmation' | 'stalled_submit' | 'completed' | 'failed' | 'cancelled' | 'lost' | null;
    lastEventAt: string | null;
    startedAt: string;
    exitedAt: string | null;
}
export declare class ProcessSupervisor {
    /** Global env: process.env + ~/.coral/env (Layer 1+2) */
    private globalEnv;
    /** Active worker handles by ID */
    private readonly workers;
    /** Orphan PID poll timers (for Recovery) */
    private readonly orphanTimers;
    /** Pending PostAction promises (from exit callbacks) */
    private readonly pendingActions;
    constructor();
    kill(id: string): Promise<void>;
    get(id: string): WorkerHandle | undefined;
    getByProject(project: string): WorkerHandle[];
    getAll(): WorkerHandle[];
    remove(id: string): void;
    get activeCount(): number;
    registerAcpHandle(handle: Omit<WorkerHandle, 'child' | 'transport'> & {
        child?: ChildProcess | null;
        transport?: 'acp-sdk';
    }): WorkerHandle;
    updateAcpHandle(id: string, patch: Partial<Pick<WorkerHandle, 'sessionId' | 'runId' | 'sessionState' | 'remoteStatus' | 'lastEventAt' | 'exitCode' | 'exitedAt' | 'outputFile'>>): WorkerHandle | undefined;
    /**
     * Wait for all pending PostAction promises to settle.
     * Called by tick after each cycle to ensure exit callbacks complete.
     */
    drainPendingActions(): Promise<void>;
    /**
     * Monitor a PID that we don't have a child handle for (tick restarted).
     * Polls every 5s; when PID dies, calls onDead.
     */
    monitorOrphanPid(id: string, pid: number, handle: Omit<WorkerHandle, 'child'>, onDead: (exitCode: number) => Promise<void> | void): void;
    /**
     * Infer exit code for an orphan worker by checking output file.
     * If output contains a successful result, assume exit code 0.
     */
    private inferExitCode;
    private loadGlobalEnv;
    reloadGlobalEnv(): void;
    private extractSessionId;
    private log;
    private normalizeAcpHandle;
    private upsertHandle;
}
//# sourceMappingURL=supervisor.d.ts.map