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 = "pre_tool_use"
9 // PostToolUse runs after tool calls complete.
10 PostToolUse HookEventType = "post_tool_use"
11 // UserPromptSubmit runs when the user submits a prompt, before processing.
12 UserPromptSubmit HookEventType = "user_prompt_submit"
13 // Stop runs when Crush finishes responding.
14 Stop HookEventType = "stop"
15 // SubagentStop runs when subagent tasks complete.
16 SubagentStop HookEventType = "subagent_stop"
17 // PreCompact runs before running a compact operation.
18 PreCompact HookEventType = "pre_compact"
19 // PermissionRequested runs when a permission is requested from the user.
20 PermissionRequested HookEventType = "permission_requested"
21)
22
23// Hook represents a single hook command configuration.
24type Hook struct {
25 // Type is the hook type, currently only "command" is supported.
26 Type string `json:"type" jsonschema:"description=Hook type,enum=command,default=command"`
27 // Command is the shell command to execute.
28 // WARNING: Hook commands execute with Crush's full permissions. Only use trusted commands.
29 Command string `json:"command" jsonschema:"required,description=Shell command to execute for this hook (executes with Crush's permissions),example=echo 'Hook executed'"`
30 // Timeout is the maximum time in seconds to wait for the hook to complete.
31 // Default is 30 seconds.
32 Timeout *int `json:"timeout,omitempty" jsonschema:"description=Maximum time in seconds to wait for hook completion,default=30,minimum=1,maximum=300"`
33}
34
35// HookMatcher represents a matcher for a specific event type.
36type HookMatcher struct {
37 // Matcher is the tool name or pattern to match (for tool events).
38 // For non-tool events, this can be empty or "*" to match all.
39 // Supports pipe-separated tool names like "edit|write|multiedit".
40 Matcher string `json:"matcher,omitempty" jsonschema:"description=Tool name or pattern to match (e.g. 'bash' 'edit|write' for multiple or '*' for all),example=bash,example=edit|write|multiedit,example=*"`
41 // Hooks is the list of hooks to execute when the matcher matches.
42 Hooks []Hook `json:"hooks" jsonschema:"required,description=List of hooks to execute when matcher matches"`
43}
44
45// HookConfig holds the complete hook configuration.
46type HookConfig map[HookEventType][]HookMatcher