/**
 * agent_lifecycle.ts — Lightweight in-memory agent lifecycle manager
 * =================================================================
 *
 * Single source of truth for LIVE agent state during execution.
 * No disk I/O, no async on the hot path.
 *
 * Two layers working together:
 *   - agent_lifecycle (RAM): outputBuffer, status, sessionId, PID → O(1) access
 *   - processRegistry (disk): persistence, sweeper, OS-level kill
 *
 * Design goals:
 *   - appendLiveOutput() → O(1) in-memory string concat, zero disk I/O
 *   - agent_control     → direct Map read, no disk poll
 *   - 10+ agents        → all in RAM, zero contention
 *   - wait()            → AbortController-based, instant resolution
 */
import { ChildProcess } from 'child_process';
export type LifecycleStatus = 'running' | 'done' | 'failed' | 'orphaned';
export interface LiveAgent {
    pid: number;
    runner: string;
    agentName: string;
    sessionId: string;
    status: LifecycleStatus;
    outputBuffer: string;
    exitCode: number | null;
    startedAt: number;
    lastOutputAt: number;
    abortController?: AbortController;
    cleanupFn: () => Promise<void>;
    childRef: ChildProcess | null;
}
/**
 * Register a new running agent. Call once per spawn.
 */
export declare function registerLiveAgent(agent: {
    pid: number;
    runner: string;
    agentName: string;
    sessionId: string;
    abortController?: AbortController;
    cleanupFn: () => Promise<void>;
    childRef: ChildProcess | null;
}): void;
/**
 * Append a text chunk to the agent's ring buffer. O(1).
 */
export declare function appendLiveOutput(pid: number, chunk: string): void;
/**
 * Update sessionId after the runner resolves it from the JSON response.
 */
export declare function linkLiveSession(pid: number, sessionId: string): void;
/**
 * Transition an agent to a terminal state.
 * Resolves any pending wait() via AbortController.abort().
 */
export declare function setLiveStatus(pid: number, status: LifecycleStatus, exitCode?: number | null): void;
/**
 * Unregister and remove from map. Called after 'exit' event in the runner.
 */
export declare function unregisterLiveAgent(pid: number): void;
/**
 * Get a live agent by agentName (+ optionally by runner).
 */
export declare function getLiveAgent(agentName: string, runner?: string): LiveAgent | undefined;
/**
 * Get a live agent by PID.
 */
export declare function getLiveAgentByPid(pid: number): LiveAgent | undefined;
/**
 * All currently running agents.
 */
export declare function getRunningAgents(): LiveAgent[];
/**
 * Agent counts.
 */
export declare function getAgentCount(): {
    running: number;
    total: number;
};
/**
 * Attach an AbortController to a running agent (for wait() resolution).
 */
export declare function setLiveAbortController(pid: number, ac: AbortController): void;
/**
 * Drain all agents — called on SIGTERM/SIGINT.
 * Best-effort cleanup of all running processes.
 */
export declare function drainAllAgents(): Promise<void>;
//# sourceMappingURL=agent_lifecycle.d.ts.map