/** * ACE-TUI Agent Runner * * Subagent process management with hermetic isolation. * Inspired by arttime's feeder isolation pattern: * - Agent crash does NOT crash TUI * - Agent output does NOT corrupt TUI state * - Agents can be killed and restarted independently */ import { type ChildProcess } from "node:child_process"; import { EventEmitter } from "node:events"; export type AgentState = "idle" | "starting" | "running" | "blocked" | "paused" | "errored" | "stopped"; export interface AgentProcess { role: string; instance_id: string; state: AgentState; pid?: number; startTime: number; process?: ChildProcess; outputBuffer: string[]; thinking?: string; tokensIn: number; tokensOut: number; errorCount: number; lastError?: string; stop_requested: boolean; } /** Messages from agent → TUI */ export type AgentMessage = { type: "output"; text: string; } | { type: "thinking"; text: string; } | { type: "status"; state: AgentState; } | { type: "file_change"; path: string; op: "create" | "edit" | "delete"; } | { type: "handoff"; from: string; to: string; payload: Record; } | { type: "tool_call"; tool: string; args: Record; } | { type: "tool_result"; tool: string; ok: boolean; summary: string; error?: string; } | { type: "tokens"; input: number; output: number; } | { type: "error"; message: string; } | { type: "done"; summary: string; }; /** Messages from TUI → agent */ export type TuiToAgentMessage = { type: "init"; role: string; workspace_root: string; instructions?: string; options?: { provider?: string; model?: string; systemPrompt?: string; task?: string; }; } | { type: "input"; text: string; } | { type: "interrupt"; } | { type: "config"; key: string; value: string; } | { type: "shutdown"; }; export declare class AgentRunner extends EventEmitter { private agents; private workspaceRoot; private readonly startupTimeoutMs; constructor(workspaceRoot: string); /** Get all agent processes */ getAll(): Map; /** Get a specific agent process */ get(role: string): AgentProcess | undefined; /** Get list of active agent roles */ getActiveRoles(): string[]; /** Get count of active agents */ getActiveCount(): number; /** Start a new agent process (hermetically isolated) */ startAgent(role: string, options?: { provider?: string; model?: string; systemPrompt?: string; task?: string; }): Promise; /** Stop an agent process */ stopAgent(role: string): void; /** Send a message to an agent */ sendToAgent(role: string, message: TuiToAgentMessage): boolean; /** Record output from an agent (called when agent sends IPC message) */ recordOutput(role: string, text: string): void; /** Record thinking from an agent */ recordThinking(role: string, text: string): void; /** Record token usage */ recordTokens(role: string, input: number, output: number): void; /** Stop all agents */ stopAll(): void; /** Get total token counts across all agents */ getTotalTokens(): { input: number; output: number; }; private loadAgentInstructions; /** Handle IPC message from a child process */ private handleAgentMessage; private isCurrentInstance; private waitForRunningState; } //# sourceMappingURL=agent-runner.d.ts.map