import type { AgentAdapter, AgentSendOpts, ChatMessage } from './types.js'; /** Internal record of a single streaming agent run. */ export interface SpawnEvent { /** Text chunk to surface to the caller. */ text: string; } /** * Self-contained description of a single CLI invocation. Returned by * prepareCommand() and consumed by spawnStream(). All per-call state lives * here — never on the adapter instance — so concurrent sendPrompt() calls * (which is the norm: one IM thread per chat) cannot clobber each other. */ export interface SpawnPlan { args: string[]; /** Extra env merged onto process.env for this spawn. */ extraEnv?: Record; /** * Working directory for the spawned CLI. Adapters use this to give each * agent (claude-code, opencode) its own isolated cwd in the IM context, so * Claude's per-cwd memory / project history and opencode's AGENTS.md don't * collide with the user's terminal sessions. Falls through to inherit * agim's own cwd ("/" under systemd) when undefined. */ cwd?: string; /** Always called once after the CLI exits, even on error/timeout/abort. */ cleanup?: () => void | Promise; } export declare abstract class AgentBase implements AgentAdapter { abstract readonly name: string; abstract readonly aliases: string[]; /** Binary name to check for isAvailable */ protected get commandName(): string; /** * Build CLI args. Pass the per-call opts so model/variant/etc. flow through * without needing instance state. Subclasses doing only synchronous arg * construction can stay here; for async setup (temp files, registry * writes) override prepareCommand() instead. */ protected abstract buildArgs(prompt: string, opts: AgentSendOpts): string[]; /** * Returns a complete spawn plan. Default implementation just wraps * buildArgs(). Subclasses needing per-call temp resources (mcp-config * file, registered run id, etc.) should override and put ALL derived * state inside the returned plan / closure — never on `this`, since * concurrent spawns would race. */ protected prepareCommand(prompt: string, opts: AgentSendOpts): Promise; /** Extract text content from a JSONL event object. */ protected abstract extractText(event: unknown): string; /** * Optional side-channel hook fired for every parsed JSONL event before * extractText. Default no-op. Used by adapters whose CLI surfaces metadata * (session id, cost, token counts) inline with content events — they * dispatch back to the caller via `opts.onAgentSessionId` / `opts.onUsage`. * * Keep it cheap: this runs on the hot stdout path. No network or disk. */ protected inspectEvent(_event: unknown, _opts: AgentSendOpts): void; /** Optional: transform error info into a user-friendly message string (resolved instead of rejected). */ protected handleError(_code: number, _stderr: string, _errorMessage: string): string | null; /** Optional: return user-friendly unavailable message. */ protected notAvailableMessage(): string; isAvailable(): Promise; /** Lightweight health probe (same as isAvailable for CLI agents). */ healthCheck(): Promise<{ ok: boolean; latencyMs?: number; }>; /** * Stream JSONL chunks live. Yields each `extractText` result as it * arrives; on non-zero exit, yields the friendly error tail (if any) and * returns. */ sendPrompt(_sessionId: string, prompt: string, history?: ChatMessage[], opts?: AgentSendOpts): AsyncGenerator; /** * Build prompt with conversation history context. * Subclasses may override for custom formatting. */ protected buildContextualPrompt(prompt: string, history?: ChatMessage[]): string; /** Idle (no-stdout) timeout for the agent child process in ms. Override per * agent via `${NAME}_IDLE_TIMEOUT_MS`, globally via `AGIM_AGENT_IDLE_TIMEOUT_MS`, * or set 0 to disable. Default 60 min — long enough to ride out an hour-long * human-in-the-loop pause, short enough to reap a truly hung child. */ protected get idleTimeoutMs(): number; /** * Sync convenience wrapper: drain the streaming generator into a single * string. Used by Job Board where the caller wants the final result. */ spawnAndCollect(prompt: string, signal?: AbortSignal, opts?: AgentSendOpts): Promise; /** * Core streaming pipeline: spawn the CLI, parse JSONL line-by-line, yield * each extracted text fragment. Handles timeout, abort, and process exit * with cleanup of all timers and listeners. */ protected spawnStream(prompt: string, signal?: AbortSignal, opts?: AgentSendOpts): AsyncGenerator; protected emptyOutputMessage(_stderr: string, _errorMessage: string): string | null; } //# sourceMappingURL=agent-base.d.ts.map