Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | /** * V3 Hooks System - Type Definitions * * Provides extensible hook points for tool execution, file operations, * and session lifecycle events. Integrates with event bus for coordination. * * @module v3/shared/hooks/types */ /** * Hook event types */ export enum HookEvent { // Tool execution hooks PreToolUse = 'hook:pre-tool-use', PostToolUse = 'hook:post-tool-use', // File operation hooks PreEdit = 'hook:pre-edit', PostEdit = 'hook:post-edit', PreRead = 'hook:pre-read', PostRead = 'hook:post-read', PreWrite = 'hook:pre-write', PostWrite = 'hook:post-write', // Command execution hooks PreCommand = 'hook:pre-command', PostCommand = 'hook:post-command', // Session lifecycle hooks SessionStart = 'hook:session-start', SessionEnd = 'hook:session-end', SessionPause = 'hook:session-pause', SessionResume = 'hook:session-resume', // Agent lifecycle hooks PreAgentSpawn = 'hook:pre-agent-spawn', PostAgentSpawn = 'hook:post-agent-spawn', PreAgentTerminate = 'hook:pre-agent-terminate', PostAgentTerminate = 'hook:post-agent-terminate', // Task lifecycle hooks PreTaskExecute = 'hook:pre-task-execute', PostTaskExecute = 'hook:post-task-execute', PreTaskComplete = 'hook:pre-task-complete', PostTaskComplete = 'hook:post-task-complete', // Memory hooks PreMemoryStore = 'hook:pre-memory-store', PostMemoryStore = 'hook:post-memory-store', PreMemoryRetrieve = 'hook:pre-memory-retrieve', PostMemoryRetrieve = 'hook:post-memory-retrieve', // Error hooks OnError = 'hook:on-error', OnWarning = 'hook:on-warning', } /** * Hook priority levels (higher = earlier execution) */ export enum HookPriority { Critical = 1000, High = 500, Normal = 0, Low = -500, Lowest = -1000, } /** * Tool information for tool-related hooks */ export interface ToolInfo { /** Tool name (e.g., 'Read', 'Write', 'Bash') */ name: string; /** Tool parameters */ parameters: Record<string, unknown>; /** Estimated execution time in ms */ estimatedDuration?: number; /** Tool category */ category?: 'file' | 'bash' | 'search' | 'edit' | 'git' | 'other'; } /** * Command information for command-related hooks */ export interface CommandInfo { /** Command string */ command: string; /** Working directory */ cwd?: string; /** Environment variables */ env?: Record<string, string>; /** Command timeout in ms */ timeout?: number; /** Whether command is destructive */ isDestructive?: boolean; } /** * File operation information */ export interface FileOperationInfo { /** File path */ path: string; /** Operation type */ operation: 'read' | 'write' | 'edit' | 'delete'; /** File content (for write/edit operations) */ content?: string; /** Previous content (for edit operations) */ previousContent?: string; /** File size in bytes */ size?: number; } /** * Session information */ export interface SessionInfo { /** Session ID */ id: string; /** Session start time */ startTime: Date; /** Session end time */ endTime?: Date; /** Session metadata */ metadata?: Record<string, unknown>; /** User ID (if available) */ userId?: string; } /** * Agent information */ export interface AgentInfo { /** Agent ID */ id: string; /** Agent type/role */ type: string; /** Agent configuration */ config?: Record<string, unknown>; /** Parent agent ID */ parentId?: string; } /** * Task information */ export interface TaskInfo { /** Task ID */ id: string; /** Task description */ description: string; /** Task priority */ priority?: number; /** Assigned agent ID */ agentId?: string; /** Task metadata */ metadata?: Record<string, unknown>; } /** * Memory operation information */ export interface MemoryInfo { /** Memory key */ key: string; /** Memory value */ value?: unknown; /** Memory namespace */ namespace?: string; /** TTL in seconds */ ttl?: number; } /** * Error information */ export interface ErrorInfo { /** Error object */ error: Error; /** Error context */ context?: string; /** Error severity */ severity: 'warning' | 'error' | 'fatal'; /** Recoverable flag */ recoverable: boolean; } /** * Hook context - contains information about the event being hooked */ export interface HookContext { /** Event type */ event: HookEvent; /** Timestamp when hook was triggered */ timestamp: Date; /** Correlation ID for tracking related events */ correlationId?: string; /** Tool information (for tool hooks) */ tool?: ToolInfo; /** Command information (for command hooks) */ command?: CommandInfo; /** File operation information (for file hooks) */ file?: FileOperationInfo; /** Session information (for session hooks) */ session?: SessionInfo; /** Agent information (for agent hooks) */ agent?: AgentInfo; /** Task information (for task hooks) */ task?: TaskInfo; /** Memory information (for memory hooks) */ memory?: MemoryInfo; /** Error information (for error hooks) */ error?: ErrorInfo; /** Additional metadata */ metadata?: Record<string, unknown>; } /** * Hook result - returned by hook handlers */ export interface HookResult { /** Whether the hook succeeded */ success: boolean; /** Result data (can modify context) */ data?: Partial<HookContext>; /** Error if hook failed */ error?: Error; /** Whether to continue executing other hooks */ continueChain?: boolean; /** Whether to abort the operation */ abort?: boolean; /** Hook execution time in ms */ executionTime?: number; /** Additional metadata */ metadata?: Record<string, unknown>; } /** * Hook handler function type */ export type HookHandler = (context: HookContext) => Promise<HookResult> | HookResult; /** * Hook definition with metadata */ export interface HookDefinition { /** Unique hook ID */ id: string; /** Hook event type */ event: HookEvent; /** Hook handler function */ handler: HookHandler; /** Hook priority */ priority: HookPriority; /** Hook name/description */ name?: string; /** Whether hook is enabled */ enabled: boolean; /** Hook timeout in ms */ timeout?: number; /** Hook metadata */ metadata?: Record<string, unknown>; } /** * Hook statistics */ export interface HookStats { /** Total hooks registered */ totalHooks: number; /** Hooks by event type */ byEvent: Record<HookEvent, number>; /** Total executions */ totalExecutions: number; /** Total failures */ totalFailures: number; /** Average execution time in ms */ avgExecutionTime: number; /** Total execution time in ms */ totalExecutionTime: number; } /** * Hook execution options */ export interface HookExecutionOptions { /** Timeout in ms (overrides hook-specific timeout) */ timeout?: number; /** Whether to continue on error */ continueOnError?: boolean; /** Maximum parallel executions */ maxParallel?: number; /** Whether to collect results from all hooks */ collectResults?: boolean; } |