hooksFor returns the deduplicated list of hooks that should run for (event, toolName). Dedup by (type, command, args) catches the common case of an explicit YAML hook overlapping a runtime auto-injected one (e.g. WithAddDate plus a user-authored add_date entry).
(event EventType, toolName string)
| 280 | // case of an explicit YAML hook overlapping a runtime auto-injected |
| 281 | // one (e.g. WithAddDate plus a user-authored add_date entry). |
| 282 | func (e *Executor) hooksFor(event EventType, toolName string) []Hook { |
| 283 | seen := make(map[string]bool) |
| 284 | var hooks []Hook |
| 285 | for _, m := range e.events[event] { |
| 286 | if !m.matches(toolName) { |
| 287 | continue |
| 288 | } |
| 289 | for _, h := range m.hooks { |
| 290 | key := dedupKey(h) |
| 291 | if seen[key] { |
| 292 | continue |
| 293 | } |
| 294 | seen[key] = true |
| 295 | hooks = append(hooks, h) |
| 296 | } |
| 297 | } |
| 298 | return hooks |
| 299 | } |
| 300 | |
| 301 | // dedupKey returns a deterministic key identifying a hook by (type, command, args). |
| 302 | func dedupKey(h Hook) string { |