UNPKG

overmind-mcp

Version:

Orchestrateur universel agents IA multi-modeles via MCP. Inclut le protocole 'Custom-Nickname' pour identifier vos agents avec des surnoms originaux (The Chaos Prophet, Shadow Sniper, etc.), l'isolation mémoire (Private Memory Context) et le support pour

110 lines • 3.8 kB
/** * 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 * * ZOMBIE PREVENTION (v1.1): * - Every entry has a maxAgeMs TTL (default 5min) * - Sweeper runs every 30s and prunes dead PIDs * - registerLiveAgent() refuses dead PIDs upfront * - setLiveStatus() syncs to processRegistry for cross-system visibility */ 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; } /** * Start the background sweeper. Idempotent — calling multiple times is a no-op. */ export declare function startZombieSweeper(): void; export declare function stopZombieSweeper(): void; export declare function getSweepStats(): { sweepCount: number; mapSize: number; }; /** * Register a new running agent. Call once per spawn. * * ZOMBIE GUARD: refuses to register if the PID is already dead. * This prevents stale "running" entries from accumulating. */ 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(). * SYNC: also updates processRegistry for cross-system visibility. */ 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