( appState: AppState, toolNames: string[], )
| 269 | |
| 270 | // Group hooks by event and matcher |
| 271 | export function groupHooksByEventAndMatcher( |
| 272 | appState: AppState, |
| 273 | toolNames: string[], |
| 274 | ): Record<HookEvent, Record<string, IndividualHookConfig[]>> { |
| 275 | const grouped: Record<HookEvent, Record<string, IndividualHookConfig[]>> = { |
| 276 | PreToolUse: {}, |
| 277 | PostToolUse: {}, |
| 278 | PostToolUseFailure: {}, |
| 279 | PermissionDenied: {}, |
| 280 | Notification: {}, |
| 281 | UserPromptSubmit: {}, |
| 282 | SessionStart: {}, |
| 283 | SessionEnd: {}, |
| 284 | Stop: {}, |
| 285 | StopFailure: {}, |
| 286 | SubagentStart: {}, |
| 287 | SubagentStop: {}, |
| 288 | PreCompact: {}, |
| 289 | PostCompact: {}, |
| 290 | PermissionRequest: {}, |
| 291 | Setup: {}, |
| 292 | TeammateIdle: {}, |
| 293 | TaskCreated: {}, |
| 294 | TaskCompleted: {}, |
| 295 | Elicitation: {}, |
| 296 | ElicitationResult: {}, |
| 297 | ConfigChange: {}, |
| 298 | WorktreeCreate: {}, |
| 299 | WorktreeRemove: {}, |
| 300 | InstructionsLoaded: {}, |
| 301 | CwdChanged: {}, |
| 302 | FileChanged: {}, |
| 303 | } |
| 304 | |
| 305 | const metadata = getHookEventMetadata(toolNames) |
| 306 | |
| 307 | // Include hooks from settings files |
| 308 | getAllHooks(appState).forEach(hook => { |
| 309 | const eventGroup = grouped[hook.event] |
| 310 | if (eventGroup) { |
| 311 | // For events without matchers, use empty string as key |
| 312 | const matcherKey = |
| 313 | metadata[hook.event].matcherMetadata !== undefined |
| 314 | ? hook.matcher || '' |
| 315 | : '' |
| 316 | if (!eventGroup[matcherKey]) { |
| 317 | eventGroup[matcherKey] = [] |
| 318 | } |
| 319 | eventGroup[matcherKey].push(hook) |
| 320 | } |
| 321 | }) |
| 322 | |
| 323 | // Include registered hooks (e.g., plugin hooks) |
| 324 | const registeredHooks = getRegisteredHooks() |
| 325 | if (registeredHooks) { |
| 326 | for (const [event, matchers] of Object.entries(registeredHooks)) { |
| 327 | const hookEvent = event as HookEvent |
| 328 | const eventGroup = grouped[hookEvent] |
no test coverage detected