/** * Hook Manager * * Central orchestrator for the hooks system. Handles configuration loading, * validation, and hook execution across all supported events. */ import { type HookEvent, type HookExecutionContext, type ExtendedHookExecutionContext, type HookExecutionResult, type HookValidationResult, type SessionEndSource } from "../types/hooks.js"; import type { WaveConfiguration, PartialHookConfiguration } from "../types/configuration.js"; import { HookMatcher } from "../utils/hookMatcher.js"; import type { MessageManager } from "./messageManager.js"; import { Container } from "../utils/container.js"; export declare class HookManager { private container; private configuration; private programmaticHooks; private pluginHooks; private waveConfigHooks; private readonly matcher; private readonly workdir; constructor(container: Container, workdir: string, matcher?: HookMatcher); /** * Load hook configuration from programmatic source (AgentOptions.hooks) */ loadConfiguration(hooks?: PartialHookConfiguration): void; /** * Load hooks configuration from a pre-loaded WaveConfiguration * Configuration loading is now handled by ConfigurationService */ loadConfigurationFromWaveConfig(waveConfig: WaveConfiguration | null): void; /** * Rebuild the full configuration from all sources: * programmatic (AgentOptions.hooks) + plugin + wave config (settings.json) * Order determines precedence on conflict (later sources append). */ private rebuildConfiguration; /** * Execute hooks for a specific event */ executeHooks(event: HookEvent, context: HookExecutionContext | ExtendedHookExecutionContext): Promise; /** * Process hook execution results and determine appropriate actions * based on exit codes and hook event type */ processHookResults(event: HookEvent, results: HookExecutionResult[], messageManager?: MessageManager, toolId?: string, toolParameters?: string): { shouldBlock: boolean; errorMessage?: string; }; /** * Handle successful hook execution (exit code 0) */ private handleHookSuccess; /** * Handle blocking error (exit code 2) - behavior varies by hook type */ private handleBlockingError; /** * Handle non-blocking error (other exit codes) */ private handleNonBlockingError; /** * Check if hooks are configured for an event/tool combination */ hasHooks(event: HookEvent, toolName?: string): boolean; /** * Validate Wave configuration structure and content */ validateConfiguration(config: WaveConfiguration): HookValidationResult; /** * Validate partial hook configuration structure and content */ private validatePartialConfiguration; /** * Get current configuration */ getConfiguration(): PartialHookConfiguration | undefined; /** * Clear current configuration */ clearConfiguration(): void; /** * Validate execution context for a specific event */ private validateExecutionContext; /** * Generate a summary of hook execution results */ private generateExecutionSummary; /** * Merge hook configurations, with the second taking precedence */ private mergeHooksConfiguration; /** * Check if a hook configuration applies to the current context */ private configApplies; /** * Validate a single event configuration */ private validateEventConfig; /** * Get statistics about current configuration */ getConfigurationStats(): { totalEvents: number; totalConfigs: number; totalCommands: number; eventBreakdown: Record; }; /** * Execute CwdChanged hooks. */ executeCwdChangedHooks(oldCwd: string, newCwd: string, sessionId: string, transcriptPath: string, env: Record): Promise; /** * Register hooks provided by a plugin */ registerPluginHooks(pluginRoot: string, hooks: PartialHookConfiguration): void; /** * Execute SessionStart hooks during initialization. * Collects additionalContext and initialUserMessage from hook stdout. */ executeSessionStartHooks(source: "startup" | "compact" | "clear", sessionId: string, transcriptPath: string, agentType?: string): Promise<{ results: HookExecutionResult[]; additionalContext?: string; initialUserMessage?: string; }>; /** * Execute SessionEnd hooks during agent destruction. * Non-blocking: always continues shutdown even if hooks fail. * No stdout processing needed (SessionEnd hooks are fire-and-forget cleanup). */ executeSessionEndHooks(source: SessionEndSource, sessionId: string, transcriptPath: string): Promise; /** * Execute PreCompact hooks before compaction. * Returns custom instructions from hook stdout. */ executePreCompactHooks(sessionId: string, transcriptPath: string, customInstructions?: string): Promise<{ results: HookExecutionResult[]; additionalInstructions?: string; }>; /** * Execute PostCompact hooks after compaction. * Receives the compact summary text. */ executePostCompactHooks(sessionId: string, transcriptPath: string, compactSummary: string): Promise; }