返回 DeepSeek-Reasonix
tool_match.go
根目录 / internal / hook / tool_match.go
1 package hook
2
3 import (
4 "regexp"
5 "slices"
6 )
7
8 // MatchesTool reports whether a hook applies to toolName. The match field is an
9 // anchored regex; non-tool events always match. A malformed regex never fires.
10 func MatchesTool(h ResolvedHook, toolName string) bool {
11 if !UsesToolMatcher(h.Event) {
12 return true
13 }
14 m := h.Match
15 if m == "" || m == "*" {
16 return true
17 }
18 re, err := regexp.Compile("^(?:" + m + ")$")
19 if err != nil {
20 return false
21 }
22 if h.PayloadFormat != "claude" {
23 if re.MatchString(toolName) {
24 return true
25 }
26 if toolName == "pwsh" {
27 return re.MatchString("bash") || re.MatchString("Bash") ||
28 re.MatchString("powershell") || re.MatchString("PowerShell")
29 }
30 return false
31 }
32 return slices.ContainsFunc(claudeMatchNames(toolName), re.MatchString)
33 }
34
34 lines GO