1package config
2
3// HookEventType represents the lifecycle event when a hook should run.
4type HookEventType string
5
6const (
7 // PreToolUse runs before tool calls and can block them.
8 PreToolUse HookEventType = "PreToolUse"
9 // PostToolUse runs after tool calls complete.
10 PostToolUse HookEventType = "PostToolUse"
11 // UserPromptSubmit runs when the user submits a prompt, before processing.
12 UserPromptSubmit HookEventType = "UserPromptSubmit"
13 // Notification runs when Crush sends notifications.
14 Notification HookEventType = "Notification"
15 // Stop runs when Crush finishes responding.
16 Stop HookEventType = "Stop"
17 // SubagentStop runs when subagent tasks complete.
18 SubagentStop HookEventType = "SubagentStop"
19 // PreCompact runs before running a compact operation.
20 PreCompact HookEventType = "PreCompact"
21 // SessionStart runs when a session starts or resumes.
22 SessionStart HookEventType = "SessionStart"
23 // SessionEnd runs when a session ends.
24 SessionEnd HookEventType = "SessionEnd"
25)
26
27// Hook represents a single hook command configuration.
28type Hook struct {
29 // Type is the hook type, currently only "command" is supported.
30 Type string `json:"type" jsonschema:"description=Hook type,enum=command,default=command"`
31 // Command is the shell command to execute.
32 Command string `json:"command" jsonschema:"required,description=Shell command to execute for this hook,example=echo 'Hook executed'"`
33 // Timeout is the maximum time in seconds to wait for the hook to complete.
34 // Default is 30 seconds.
35 Timeout *int `json:"timeout,omitempty" jsonschema:"description=Maximum time in seconds to wait for hook completion,default=30,minimum=1,maximum=300"`
36}
37
38// HookMatcher represents a matcher for a specific event type.
39type HookMatcher struct {
40 // Matcher is the tool name or pattern to match (for tool events).
41 // For non-tool events, this can be empty or "*" to match all.
42 Matcher string `json:"matcher,omitempty" jsonschema:"description=Tool name or pattern to match (e.g. 'bash' or '*' for all),example=bash,example=edit,example=*"`
43 // Hooks is the list of hooks to execute when the matcher matches.
44 Hooks []Hook `json:"hooks" jsonschema:"required,description=List of hooks to execute when matcher matches"`
45}
46
47// HookConfig holds the complete hook configuration.
48type HookConfig map[HookEventType][]HookMatcher