/** * HookService - Hook Management Service * * Provides centralized hook registration, management, and execution for the * Eliza agent runtime. Integrates with the runtime event system to dispatch * hooks when events are emitted. * * Key features: * - registry for all hook sources (bundled, workspace, plugin, runtime) * - Priority-based execution with FIFO ordering for same priority * - Eligibility checking based on OS, binaries, env vars, and config * - Directory-based hook discovery and loading * - Integration with runtime event system */ import { EventType } from "../types/events.js"; import type { HookEligibilityResult, HookHandler, HookLoadResult, HookPriority, HookRegistration, HookRegistrationOptions, HookRequirements, HookSnapshot, HookSource, IHookService } from "../types/hook.js"; import type { IAgentRuntime } from "../types/runtime.js"; import { Service } from "../types/service.js"; export declare class HookService extends Service implements IHookService { static serviceType: "hooks"; capabilityDescription: string; /** Hook registry keyed by ID */ private registry; /** Index of hook IDs by event type for fast lookup */ private eventIndex; /** Counter for generating unique hook IDs */ private idCounter; /** Version counter for snapshots */ private snapshotVersion; /** Configuration for eligibility checks */ private hookConfig; /** * Binary names {@link hasBinary} found: the PATH scan is synchronous * filesystem work, and eligibility is checked on every hook dispatch. Only * hits are kept, so a binary installed later is found on the next check. * Valid for {@link binaryCachePath}; a PATH change or stop clears it. */ private readonly binaryCache; private binaryCachePath; /** Runtime event handlers installed by {@link setupEventInterceptors}, removed on stop. */ private readonly interceptors; /** * Start the hook service */ static start(runtime: IAgentRuntime): Promise; /** * Stop the hook service */ stop(): Promise; private hasCachedBinary; /** * Set up event interceptors to dispatch to hooks */ private setupEventInterceptors; /** * Dispatch an event to all registered hooks */ private dispatchToHooks; /** * Check eligibility for a registration (internal) */ private checkEligibilityInternal; register(events: EventType | EventType[], handler: HookHandler, options: HookRegistrationOptions): string; unregister(hookId: string): boolean; registerFromDirectory(_dir: string, _source: HookSource, _options?: { pluginId?: string; }): Promise; getSnapshot(): HookSnapshot; getHooksByEvent(event: EventType): HookRegistration[]; getHook(hookId: string): HookRegistration | undefined; getAllHooks(): HookRegistration[]; setEnabled(hookId: string, enabled: boolean): void; setPriority(hookId: string, priority: HookPriority): void; /** * Set configuration for eligibility checks */ setConfig(config: Record): void; checkEligibility(hookId: string): HookEligibilityResult; checkRequirements(requirements: HookRequirements, config?: Record): HookEligibilityResult; /** * Resolve a dot-separated config path */ private resolveConfigPath; /** * Check if a value is truthy */ private isTruthy; }