/** * Persistent CLI Adapter - Wraps PersistentClaudeProcess with ClaudeCLIWrapper interface * * WHY THIS EXISTS: * - PersistentClaudeProcess uses stream-json for efficient multi-turn conversations * - AgentLoop expects ClaudeCLIWrapper interface (prompt, setSessionId, setSystemPrompt) * - This adapter bridges the two, enabling drop-in replacement * * KEY OPTIMIZATION: * - Tool results sent via stdin (tool_result message) * - Claude context preserved without re-sending full history * - System prompt sent only once at process start */ import type { ClaudeCLIWrapperOptions, PromptCallbacks, PromptResult, ToolUseBlock } from './claude-cli-wrapper.js'; import type { IModelRunner, RunnerMetrics } from './model-runner.js'; export type { ClaudeCLIWrapperOptions, PromptCallbacks, PromptResult, ToolUseBlock }; /** * PersistentCLIAdapter - Drop-in replacement for ClaudeCLIWrapper * * Implements the same interface but uses persistent CLI processes under the hood. * This enables efficient multi-turn conversations without re-sending system prompts. */ export declare class PersistentCLIAdapter implements IModelRunner { readonly backendType: "claude"; private options; private processPool; private channelKey; private currentProcess; private pendingToolResults; private lastToolUseBlocks; private _requestCount; private _failureCount; private _totalLatencyMs; private _lastRequestAt; constructor(options?: ClaudeCLIWrapperOptions); /** * Send a prompt to Claude * * This method: * 1. Gets or creates a persistent process for this channel * 2. Sends the message via stdin * 3. Parses the response from stdout * 4. Returns PromptResult compatible with ClaudeCLIWrapper */ prompt(content: string, callbacks?: PromptCallbacks, options?: { model?: string; resumeSession?: boolean; allowedTools?: string[]; disallowedTools?: string[]; }): Promise; /** * Send a tool result back to Claude * * This is a new method not in ClaudeCLIWrapper that enables efficient tool loops. * Instead of rebuilding the full history, we send just the tool result. */ sendToolResult(toolUseId: string, result: string, isError?: boolean, callbacks?: PromptCallbacks): Promise; /** * Queue a tool result to be sent with the next message * * Use this when you want to collect multiple tool results before continuing. */ queueToolResult(toolUseId: string, result: string, isError?: boolean): void; /** * Check if there are pending tool results */ hasPendingToolResults(): boolean; /** * Get the last tool use blocks from the most recent response */ getLastToolUseBlocks(): ToolUseBlock[]; /** * Get current session ID */ getSessionId(): string; /** * Create a new session (creates new process) */ resetSession(): void; /** * Set session ID (for channel-specific conversations) * * Note: This creates a new channel key, effectively switching channels. * The old process is kept alive for potential reuse. * Callers should use resetSession() if the old process is no longer needed to avoid orphan processes. */ setSessionId(sessionId: string): void; /** * Set system prompt * * IMPORTANT: This only affects new processes. Existing processes keep their prompt. * To apply a new system prompt, call resetSession() after setSystemPrompt(). */ setSystemPrompt(prompt: string): void; /** * Get current options (for debugging) */ getOptions(): ClaudeCLIWrapperOptions; /** * Check if the adapter has a live process ready to accept prompts. */ isHealthy(): boolean; /** * Collect runtime metrics. */ getMetrics(): RunnerMetrics; /** * Gracefully stop all processes (IModelRunner.stop). */ stop(): void; /** * Stop all processes (cleanup) — legacy name, delegates to stop(). */ stopAll(): void; /** * Check if the adapter is in persistent mode (always true for this adapter) */ isPersistent(): boolean; /** * Get the current process state */ getProcessState(): string; /** * Get number of active processes in the pool */ getActiveProcessCount(): number; } /** * Factory function to create a ClaudeCLIWrapper-compatible adapter * * Usage: * const wrapper = createPersistentCLIAdapter({ sessionId: 'discord-channel-123' }); * const result = await wrapper.prompt('Hello!'); * * Each adapter instance maintains its own process pool. Processes are not shared across adapter instances. */ export declare function createPersistentCLIAdapter(options?: ClaudeCLIWrapperOptions): PersistentCLIAdapter; //# sourceMappingURL=persistent-cli-adapter.d.ts.map