Returns all hooks for an event (after matcher filtering when toolName is supplied).
(event: HookEvent, toolName?: string)
| 40 | |
| 41 | /** Returns all hooks for an event (after matcher filtering when toolName is supplied). */ |
| 42 | matching(event: HookEvent, toolName?: string): HookConfig[] { |
| 43 | const all = this.cfg[event] ?? []; |
| 44 | if (!toolName || (event !== 'PreToolUse' && event !== 'PostToolUse')) { |
| 45 | return all; |
| 46 | } |
| 47 | return all.filter(h => { |
| 48 | if (!h.matcher) return true; |
| 49 | try { |
| 50 | return new RegExp(h.matcher).test(toolName); |
| 51 | } catch { |
| 52 | // Invalid regex → literal substring match (forgiving) |
| 53 | return toolName.includes(h.matcher); |
| 54 | } |
| 55 | }); |
| 56 | } |
| 57 | |
| 58 | /** Convenience: how many hooks would dispatch for this event/tool combination. */ |
| 59 | countMatching(event: HookEvent, toolName?: string): number { |
no outgoing calls
no test coverage detected