import { LLMClient } from "../grok/client.js"; import { TokenCounter } from "../utils/token-counter.js"; import { ChatEntry } from "./llm-agent.js"; /** * Dependencies required by HookManager for hook execution and state management */ export interface HookManagerDependencies { /** Get LLM client for API calls */ getLLMClient(): LLMClient; /** Get token counter for model operations */ getTokenCounter(): TokenCounter; /** API key environment variable name */ apiKeyEnvVar: string; /** LLM messages array */ messages: any[]; /** Chat history for display */ chatHistory: ChatEntry[]; /** Temperature for API calls */ temperature: number; /** Get current token count */ getCurrentTokenCount(): number; /** Get maximum context size */ getMaxContextSize(): number; /** Get current model name */ getCurrentModel(): string; /** Emit events */ emit(event: string, data: any): void; /** Set API key environment variable */ setApiKeyEnvVar(value: string): void; /** Set token counter */ setTokenCounter(counter: TokenCounter): void; /** Set LLM client */ setLLMClient(client: LLMClient): void; /** Set persona values */ setPersona(persona: string, color: string): void; /** Set mood values */ setMood(mood: string, color: string): void; /** Set active task values */ setActiveTask(task: string, action: string, color: string): void; /** Execute a tool by name with parameters (for CALL commands) */ executeToolByName?(toolName: string, parameters: Record): Promise<{ success: boolean; output?: string; error?: string; hookCommands?: any[]; }>; } /** * Manages hook execution for persona, mood, and task operations * * Handles: * - Persona/mood/task hook execution with approval workflows * - Backend and model switching with validation * - Hook command processing and environment variable management * - API testing for backend/model changes * - System message generation for state changes */ export declare class HookManager { private deps; constructor(deps: HookManagerDependencies); /** * Set agent persona with optional hook execution * Executes persona hook if configured and processes backend/model changes * * @param persona New persona name * @param color Optional display color * @returns Success status and error message if failed */ setPersona(persona: string, color?: string): Promise<{ success: boolean; error?: string; }>; /** * Set agent mood with optional hook execution * Executes mood hook if configured and adds system message to chat * * @param mood New mood name * @param color Optional display color * @returns Success status and error message if failed */ setMood(mood: string, color?: string): Promise<{ success: boolean; error?: string; }>; /** * Start a new active task with approval hook * Prevents starting if another task is already active * * @param activeTask Task name * @param action Task action/status * @param color Optional display color * @returns Success status and error message if failed */ startActiveTask(activeTask: string, action: string, color?: string): Promise<{ success: boolean; error?: string; }>; /** * Transition active task status with approval hook * Requires an active task to be running * * @param action New task action/status * @param color Optional display color * @returns Success status and error message if failed */ transitionActiveTaskStatus(action: string, color?: string): Promise<{ success: boolean; error?: string; }>; /** * Stop active task with approval hook and minimum delay * Enforces 3-second minimum delay for task completion * * @param reason Reason for stopping task * @param documentationFile Documentation file path * @param color Optional display color * @returns Success status and error message if failed */ stopActiveTask(reason: string, documentationFile: string, color?: string): Promise<{ success: boolean; error?: string; }>; /** * Process hook result commands and apply environment changes * Handles backend/model changes, environment variables, and system messages * * @param hookResult Hook execution result with commands * @param envKey Optional environment key to extract transformed value * @returns Success status and transformed value if applicable */ processHookResult(hookResult: { commands?: any[]; }, envKey?: string): Promise<{ success: boolean; transformedValue?: string; }>; /** * Process hook commands with backend/model testing * Tests API connectivity before applying changes * * @param commands Processed hook commands * @returns Success status of command processing */ private processHookCommands; /** * Render system message with current variable state * Updates messages[0] with fresh system prompt from variables */ private renderSystemMessage; /** * Test model change by making API call * Validates model compatibility before switching * * @param newModel Model name to test * @returns Success status and error message if failed */ private testModel; /** * Test backend and model change by making API call * Validates backend connectivity and model compatibility * * @param backend Backend name * @param baseUrl API base URL * @param apiKeyEnvVar Environment variable for API key * @param model Optional model name * @returns Success status and error message if failed */ private testBackendModelChange; /** * Strip in-progress tool calls from messages for API testing * Removes incomplete tool call sequences to avoid API errors * * @param messages Message array to clean * @returns Cleaned message array without incomplete tool calls */ private stripInProgressToolCalls; /** * Execute CALL commands asynchronously with recursion depth and duplicate tracking * Fire-and-forget execution that processes hooks from called tools * * @param calls Array of CALL command strings * @param context Call context for tracking recursion and duplicates */ private executeCalls; /** * Execute a single CALL asynchronously with hook processing * Runs tool hooks which may generate more CALL commands * * @param toolName Tool to execute * @param parameters Tool parameters * @param context Call context for tracking recursion */ private executeCallAsync; }