/** * Hook System Types * * Type definitions for the Hari Seldon hooks system. * Hooks allow custom code to run in response to events during agent execution. * Modeled after Claude Code's hooks system. */ /** * Hook event types that can trigger hook execution. */ export type HookEvent = 'PreToolUse' | 'PostToolUse' | 'Setup' | 'ToolError' | 'TaskStart' | 'TaskComplete' | 'TaskFail' | 'ProviderError' | 'Failover'; /** * All valid hook events as an array for validation. */ export declare const HOOK_EVENTS: readonly HookEvent[]; /** * Hook decision for PreToolUse hooks. * Determines whether tool execution should proceed. */ export type HookDecision = 'allow' | 'deny' | 'ask'; /** * Input provided to hooks via stdin as JSON. * Contains event context and relevant data depending on event type. */ export interface HookInput { /** The event type that triggered this hook */ event: HookEvent; /** Timestamp when the event occurred */ timestamp: Date; /** Session ID for the current MCP session */ sessionId?: string; /** Task ID if this hook is related to a task */ taskId?: string; /** Worktree path if operating in a worktree */ worktreePath?: string; /** Name of the tool being executed (for tool events) */ toolName?: string; /** Input parameters passed to the tool */ toolInput?: Record; /** Output from the tool (for PostToolUse) */ toolOutput?: unknown; /** Error from the tool (for ToolError) */ toolError?: Error; /** Provider name (for provider events) */ provider?: string; /** Model identifier */ model?: string; /** Agent role being used */ role?: string; /** HTTP status code (for error events) */ errorCode?: number; /** Error message */ errorMessage?: string; /** Original provider that failed (for Failover) */ fromProvider?: string; /** New provider being tried (for Failover) */ toProvider?: string; /** Attempt number in failover chain */ attemptNumber?: number; } /** * Output from hook execution, parsed from stdout JSON. * Hooks can influence agent behavior through these fields. */ export interface HookOutput { /** Decision for PreToolUse hooks (allow/deny/ask) */ decision?: HookDecision; /** Additional context to inject into agent prompt */ additionalContext?: string; /** Modified tool input (replaces original input) */ updatedInput?: Record; /** Message to display to user/log */ message?: string; /** Abort execution entirely */ abort?: boolean; /** Exit code from the hook process */ exitCode?: number; /** Raw stdout from the hook */ stdout?: string; /** Raw stderr from the hook */ stderr?: string; } /** * Hook definition in configuration. * Defines a hook's trigger conditions and execution parameters. */ export interface HookDefinition { /** Unique name for this hook */ name: string; /** Event that triggers this hook */ event: HookEvent; /** Description of what this hook does */ description?: string; /** Shell command to execute */ command: string; /** Working directory for command */ cwd?: string; /** Environment variables to set for the hook process */ env?: Record; /** Timeout in milliseconds (overrides default) */ timeout_ms?: number; /** Only run once per session */ once?: boolean; /** Only trigger for specific tools (tool name patterns) */ tools?: string[]; /** Only trigger for specific providers */ providers?: string[]; /** Only trigger for specific roles */ roles?: string[]; /** Error codes that trigger this hook (for ToolError, ProviderError) */ error_codes?: number[]; /** Whether this hook is enabled */ enabled?: boolean; } /** * Complete hooks configuration. * Can be defined in config.yaml under the 'hooks' key. */ export interface HooksConfig { /** Enable hooks system globally */ enabled: boolean; /** Hook definitions */ hooks: HookDefinition[]; /** Global timeout for hooks in milliseconds */ default_timeout_ms: number; /** Fail silently on hook errors (don't abort main operation) */ fail_silent: boolean; /** Path to external hooks configuration file (optional) */ hooks_file?: string; } /** * Default hooks configuration. */ export declare const DEFAULT_HOOKS_CONFIG: HooksConfig; /** * Variable substitutions available in hook commands. * Variables are substituted using ${VAR_NAME} syntax. */ export interface HookVariables { /** Current MCP session ID */ CLAUDE_SESSION_ID: string; /** Task ID being executed */ TASK_ID: string; /** Path to the worktree directory */ WORKTREE_PATH: string; /** Name of the tool being executed */ TOOL_NAME: string; /** Provider name */ PROVIDER: string; /** Model identifier */ MODEL: string; /** Agent role */ ROLE: string; /** Error code (HTTP status) */ ERROR_CODE: string; /** Error message */ ERROR_MESSAGE: string; /** Original provider (for failover) */ FROM_PROVIDER: string; /** Target provider (for failover) */ TO_PROVIDER: string; /** Attempt number */ ATTEMPT_NUMBER: string; } /** * Result of a single hook execution. */ export interface HookExecutionResult { /** Hook that was executed */ hook: HookDefinition; /** Whether execution succeeded */ success: boolean; /** Output from the hook */ output?: HookOutput; /** Error if execution failed */ error?: Error; /** Duration in milliseconds */ durationMs: number; } /** * Combined result from triggering an event (multiple hooks). */ export interface HookTriggerResult { /** Event that was triggered */ event: HookEvent; /** Number of hooks executed */ hooksExecuted: number; /** Results from each hook */ results: HookExecutionResult[]; /** Combined output from all hooks */ combinedOutput: HookOutput; /** Whether any hook failed */ hasErrors: boolean; /** Whether execution should be aborted */ shouldAbort: boolean; } /** * Events emitted by the HookManager. */ export interface HookManagerEvents { /** Emitted before a hook is executed */ 'hook:before': { hook: HookDefinition; input: HookInput; }; /** Emitted after a hook completes */ 'hook:after': { hook: HookDefinition; result: HookExecutionResult; }; /** Emitted when a hook fails */ 'hook:error': { hook: HookDefinition; error: Error; }; /** Emitted when hooks are reloaded */ 'hooks:reload': { count: number; }; } //# sourceMappingURL=types.d.ts.map