import type { GatewayConfig, ModelConfig, Usage } from "../types/index.js"; import { Container } from "../utils/container.js"; import type { WorktreeSession } from "../utils/worktreeSession.js"; export interface AIManagerCallbacks { onCompactionStateChange?: (isCompacting: boolean) => void; onUsageAdded?: (usage: Usage) => void; onCwdChange?: (newCwd: string) => void; } export interface AIManagerOptions { callbacks?: AIManagerCallbacks; workdir: string; systemPrompt?: string; subagentType?: string; /**Whether to use streaming mode for AI responses - defaults to true */ stream?: boolean; /**Optional model override (e.g. for subagents) */ modelOverride?: string; /**Optional max turns limit to prevent runaway recursion (e.g. for auto-memory extraction) */ maxTurns?: number; } export declare class AIManager { private container; isLoading: boolean; private turnGeneration; private abortController; onLoadingChange?: (loading: boolean) => void; private toolAbortController; private systemPrompt?; private subagentType?; private stream; private modelOverride?; private _onCwdChange?; private originalWorkdir; private consecutiveCompactionFailures; private readonly maxTurns?; /** Tracks file mtime/hash at read time for staleness detection on Edit/Write */ private readFileState; /** Override tool_choice for this AI manager (e.g. for structured output) */ toolChoiceOverride?: "auto" | "none" | "required" | { type: "function"; function: { name: string; }; }; constructor(container: Container, options: AIManagerOptions); private get toolManager(); private get messageManager(); private get memoryService(); private get taskManager(); private get backgroundTaskManager(); private get hookManager(); private get reversionManager(); private get permissionManager(); private get planManager(); private get configurationService(); getGatewayConfig(): GatewayConfig; getModelConfig(): ModelConfig; getMaxInputTokens(): number; getLanguage(): string | undefined; getAutoMemoryEnabled(): boolean; getWorkdir(): string; getOriginalWorkdir(): string; /** * Update the working directory mid-session (e.g., when entering/exiting a worktree). * Only updates this session's DI container; it does NOT change the process-level * process.cwd(), so concurrent sessions in the same stdio process are unaffected. * Triggers `_onCwdChange` (wired by Agent to `onWorkdirChange`) so the host is * notified of worktree switches. Unlike bash `cd`, this does NOT run CwdChanged * hooks (worktree has its own WorktreeCreate/WorktreeRemove hooks). */ setWorkdir(newWorkdir: string): void; /** * Get this session's worktree session state (null if not in a worktree). */ getWorktreeSession(): WorktreeSession | null; /** * Set this session's worktree session state. */ setWorktreeSession(session: WorktreeSession | null): void; setOnCwdChange(callback: (newCwd: string) => void): void; private isCompacting; private callbacks; /** * Get filtered tool configuration based on tools list */ private getFilteredToolsConfig; /** * Add plan mode reminder as a persistent meta message to the message manager. * Called before getMessages() so the stored message is included in the API call. */ private maybeAddPlanModeMessage; private maybeGetTaskReminderText; setIsLoading(isLoading: boolean): void; abortAIMessage(): void; private generateCompactParams; private handleTokenUsageAndCompaction; /** * Manually compact the conversation history. * Called by /compact slash command or auto-compaction trigger. */ compactConversation(options?: { customInstructions?: string; abortSignal?: AbortSignal; }): Promise; /** * Build post-compact context restoration content. * Restores file reads, working directory, plan mode, skills, and background tasks. */ private buildPostCompactContext; getIsCompacting(): boolean; setIsCompacting(isCompacting: boolean): void; private get subagentManager(); private get cronManager(); private get skillManager(); sendAIMessage(options?: { recursionDepth?: number; model?: string; /** Rules for automatic tool approval (e.g., "Bash(git status*)") */ allowedRules?: string[]; maxTokens?: number; }): Promise; /** * Execute Stop or SubagentStop hooks when AI response cycle completes * Uses "SubagentStop" hook name when triggered by a subagent, otherwise uses "Stop" * @returns Promise - true if should continue conversation, false if should stop */ private executeStopHooks; /** * Execute a single tool call: arg parsing, block emission, PreToolUse hooks, * tool execution, PostToolUse hooks, and error handling. */ private executeToolCall; /** * Execute PreToolUse hooks before tool execution * Returns true if hooks allow tool execution, false if blocked */ private executePreToolUseHooks; /** * Execute PostToolUse hooks after tool completion */ private executePostToolUseHooks; }