Documentation
¶
Overview ¶
Package hook provides hook types for intercepting CLI events.
Index ¶
- type AsyncJSONOutput
- type BaseInput
- type Callback
- type Context
- type Event
- type Input
- type JSONOutput
- type Matcher
- type NotificationInput
- type NotificationSpecificOutput
- type PermissionRequestInput
- type PermissionRequestSpecificOutput
- type PostToolUseFailureInput
- type PostToolUseFailureSpecificOutput
- type PostToolUseInput
- type PostToolUseSpecificOutput
- type PreCompactInput
- type PreToolUseInput
- type PreToolUseSpecificOutput
- type SpecificOutput
- type StopInput
- type SubagentStartInput
- type SubagentStartSpecificOutput
- type SubagentStopInput
- type SyncJSONOutput
- type UserPromptSubmitInput
- type UserPromptSubmitSpecificOutput
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AsyncJSONOutput ¶
type AsyncJSONOutput struct {
Async bool `json:"async"`
AsyncTimeout *int `json:"asyncTimeout,omitempty"` // milliseconds
}
AsyncJSONOutput represents an async hook output.
type BaseInput ¶
type BaseInput struct {
SessionID string `json:"session_id"`
TranscriptPath string `json:"transcript_path"`
Cwd string `json:"cwd"`
PermissionMode *string `json:"permission_mode,omitempty"`
}
BaseInput contains common fields for all hook inputs.
func (*BaseInput) GetPermissionMode ¶
GetPermissionMode implements Input.
func (*BaseInput) GetSessionID ¶
GetSessionID implements Input.
func (*BaseInput) GetTranscriptPath ¶
GetTranscriptPath implements Input.
type Callback ¶
type Callback func( ctx context.Context, input Input, toolUseID *string, hookCtx *Context, ) (JSONOutput, error)
Callback is the function signature for hook callbacks.
type Event ¶
type Event string
Event represents the type of event that triggers a hook.
const ( // EventPreToolUse is triggered before a tool is used. EventPreToolUse Event = "PreToolUse" // EventPostToolUse is triggered after a tool is used. EventPostToolUse Event = "PostToolUse" // EventUserPromptSubmit is triggered when a user submits a prompt. EventUserPromptSubmit Event = "UserPromptSubmit" // EventStop is triggered when a session stops. EventStop Event = "Stop" // EventSubagentStop is triggered when a subagent stops. EventSubagentStop Event = "SubagentStop" // EventPreCompact is triggered before compaction. EventPreCompact Event = "PreCompact" // EventPostToolUseFailure is triggered after a tool use fails. EventPostToolUseFailure Event = "PostToolUseFailure" // EventNotification is triggered when a notification is sent. EventNotification Event = "Notification" // EventSubagentStart is triggered when a subagent starts. EventSubagentStart Event = "SubagentStart" // EventPermissionRequest is triggered when a permission is requested. EventPermissionRequest Event = "PermissionRequest" )
type Input ¶
type Input interface {
GetHookEventName() Event
GetSessionID() string
GetTranscriptPath() string
GetCwd() string
GetPermissionMode() *string
}
Input is the interface for all hook input types.
type JSONOutput ¶
type JSONOutput any
JSONOutput is the interface for hook output types. This is a marker interface for type safety; use type switches to distinguish between AsyncJSONOutput and SyncJSONOutput.
type Matcher ¶
type Matcher struct {
// Matcher is a tool name like "Bash" or a pipe-separated combination like "Write|Edit".
// When nil, the hook matches all tools/events.
// This is NOT regex - pipe (|) separates multiple tool names to match.
Matcher *string
Hooks []Callback
Timeout *float64 // seconds (default 60)
}
Matcher configures which tools/events a hook applies to.
type NotificationInput ¶
type NotificationInput struct {
BaseInput
HookEventName string `json:"hook_event_name"`
Message string `json:"message"`
Title *string `json:"title,omitempty"`
NotificationType string `json:"notification_type"`
}
NotificationInput is the input for Notification hooks.
func (*NotificationInput) GetHookEventName ¶
func (n *NotificationInput) GetHookEventName() Event
GetHookEventName implements Input.
type NotificationSpecificOutput ¶
type NotificationSpecificOutput struct {
HookEventName string `json:"hookEventName"` // "Notification"
AdditionalContext *string `json:"additionalContext,omitempty"`
}
NotificationSpecificOutput is the hook-specific output for Notification.
func (*NotificationSpecificOutput) GetHookEventName ¶
func (n *NotificationSpecificOutput) GetHookEventName() string
GetHookEventName implements SpecificOutput.
type PermissionRequestInput ¶
type PermissionRequestInput struct {
BaseInput
HookEventName string `json:"hook_event_name"`
ToolName string `json:"tool_name"`
ToolInput map[string]any `json:"tool_input"`
PermissionSuggestions []any `json:"permission_suggestions"`
}
PermissionRequestInput is the input for PermissionRequest hooks.
func (*PermissionRequestInput) GetHookEventName ¶
func (p *PermissionRequestInput) GetHookEventName() Event
GetHookEventName implements Input.
type PermissionRequestSpecificOutput ¶
type PermissionRequestSpecificOutput struct {
HookEventName string `json:"hookEventName"` // "PermissionRequest"
Decision map[string]any `json:"decision,omitempty"`
}
PermissionRequestSpecificOutput is the hook-specific output for PermissionRequest.
func (*PermissionRequestSpecificOutput) GetHookEventName ¶
func (p *PermissionRequestSpecificOutput) GetHookEventName() string
GetHookEventName implements SpecificOutput.
type PostToolUseFailureInput ¶
type PostToolUseFailureInput struct {
BaseInput
HookEventName string `json:"hook_event_name"`
ToolName string `json:"tool_name"`
ToolInput map[string]any `json:"tool_input"`
ToolUseID string `json:"tool_use_id"`
Error string `json:"error"`
IsInterrupt *bool `json:"is_interrupt,omitempty"`
}
PostToolUseFailureInput is the input for PostToolUseFailure hooks.
func (*PostToolUseFailureInput) GetHookEventName ¶
func (p *PostToolUseFailureInput) GetHookEventName() Event
GetHookEventName implements Input.
type PostToolUseFailureSpecificOutput ¶
type PostToolUseFailureSpecificOutput struct {
HookEventName string `json:"hookEventName"` // "PostToolUseFailure"
AdditionalContext *string `json:"additionalContext,omitempty"`
}
PostToolUseFailureSpecificOutput is the hook-specific output for PostToolUseFailure.
func (*PostToolUseFailureSpecificOutput) GetHookEventName ¶
func (p *PostToolUseFailureSpecificOutput) GetHookEventName() string
GetHookEventName implements SpecificOutput.
type PostToolUseInput ¶
type PostToolUseInput struct {
BaseInput
HookEventName string `json:"hook_event_name"`
ToolName string `json:"tool_name"`
ToolInput map[string]any `json:"tool_input"`
ToolUseID string `json:"tool_use_id"`
ToolResponse any `json:"tool_response"`
}
PostToolUseInput is the input for PostToolUse hooks.
func (*PostToolUseInput) GetHookEventName ¶
func (p *PostToolUseInput) GetHookEventName() Event
GetHookEventName implements Input.
type PostToolUseSpecificOutput ¶
type PostToolUseSpecificOutput struct {
HookEventName string `json:"hookEventName"` // "PostToolUse"
AdditionalContext *string `json:"additionalContext,omitempty"`
UpdatedMCPToolOutput any `json:"updatedMCPToolOutput,omitempty"` //nolint:tagliatelle // CLI protocol uses MCP acronym
}
PostToolUseSpecificOutput is the hook-specific output for PostToolUse.
func (*PostToolUseSpecificOutput) GetHookEventName ¶
func (p *PostToolUseSpecificOutput) GetHookEventName() string
GetHookEventName implements SpecificOutput.
type PreCompactInput ¶
type PreCompactInput struct {
BaseInput
HookEventName string `json:"hook_event_name"`
Trigger string `json:"trigger"` // "manual" or "auto"
CustomInstructions *string `json:"custom_instructions,omitempty"`
}
PreCompactInput is the input for PreCompact hooks.
func (*PreCompactInput) GetHookEventName ¶
func (p *PreCompactInput) GetHookEventName() Event
GetHookEventName implements Input.
type PreToolUseInput ¶
type PreToolUseInput struct {
BaseInput
HookEventName string `json:"hook_event_name"`
ToolName string `json:"tool_name"`
ToolInput map[string]any `json:"tool_input"`
ToolUseID string `json:"tool_use_id"`
}
PreToolUseInput is the input for PreToolUse hooks.
func (*PreToolUseInput) GetHookEventName ¶
func (p *PreToolUseInput) GetHookEventName() Event
GetHookEventName implements Input.
type PreToolUseSpecificOutput ¶
type PreToolUseSpecificOutput struct {
HookEventName string `json:"hookEventName"` // "PreToolUse"
PermissionDecision *string `json:"permissionDecision,omitempty"`
PermissionDecisionReason *string `json:"permissionDecisionReason,omitempty"`
UpdatedInput map[string]any `json:"updatedInput,omitempty"`
AdditionalContext *string `json:"additionalContext,omitempty"`
}
PreToolUseSpecificOutput is the hook-specific output for PreToolUse.
func (*PreToolUseSpecificOutput) GetHookEventName ¶
func (p *PreToolUseSpecificOutput) GetHookEventName() string
GetHookEventName implements SpecificOutput.
type SpecificOutput ¶
type SpecificOutput interface {
GetHookEventName() string
}
SpecificOutput is the interface for hook-specific outputs.
type StopInput ¶
type StopInput struct {
BaseInput
HookEventName string `json:"hook_event_name"`
StopHookActive bool `json:"stop_hook_active"`
}
StopInput is the input for Stop hooks.
func (*StopInput) GetHookEventName ¶
GetHookEventName implements Input.
type SubagentStartInput ¶
type SubagentStartInput struct {
BaseInput
HookEventName string `json:"hook_event_name"`
AgentID string `json:"agent_id"`
AgentType string `json:"agent_type"`
}
SubagentStartInput is the input for SubagentStart hooks.
func (*SubagentStartInput) GetHookEventName ¶
func (s *SubagentStartInput) GetHookEventName() Event
GetHookEventName implements Input.
type SubagentStartSpecificOutput ¶
type SubagentStartSpecificOutput struct {
HookEventName string `json:"hookEventName"` // "SubagentStart"
AdditionalContext *string `json:"additionalContext,omitempty"`
}
SubagentStartSpecificOutput is the hook-specific output for SubagentStart.
func (*SubagentStartSpecificOutput) GetHookEventName ¶
func (s *SubagentStartSpecificOutput) GetHookEventName() string
GetHookEventName implements SpecificOutput.
type SubagentStopInput ¶
type SubagentStopInput struct {
BaseInput
HookEventName string `json:"hook_event_name"`
StopHookActive bool `json:"stop_hook_active"`
AgentID string `json:"agent_id"`
AgentTranscriptPath string `json:"agent_transcript_path"`
AgentType string `json:"agent_type"`
}
SubagentStopInput is the input for SubagentStop hooks.
func (*SubagentStopInput) GetHookEventName ¶
func (s *SubagentStopInput) GetHookEventName() Event
GetHookEventName implements Input.
type SyncJSONOutput ¶
type SyncJSONOutput struct {
Continue *bool `json:"continue,omitempty"`
SuppressOutput *bool `json:"suppressOutput,omitempty"`
StopReason *string `json:"stopReason,omitempty"`
Decision *string `json:"decision,omitempty"` // "block"
SystemMessage *string `json:"systemMessage,omitempty"`
Reason *string `json:"reason,omitempty"`
HookSpecificOutput SpecificOutput `json:"hookSpecificOutput,omitempty"`
}
SyncJSONOutput represents a sync hook output.
type UserPromptSubmitInput ¶
type UserPromptSubmitInput struct {
BaseInput
HookEventName string `json:"hook_event_name"`
Prompt string `json:"prompt"`
}
UserPromptSubmitInput is the input for UserPromptSubmit hooks.
func (*UserPromptSubmitInput) GetHookEventName ¶
func (u *UserPromptSubmitInput) GetHookEventName() Event
GetHookEventName implements Input.
type UserPromptSubmitSpecificOutput ¶
type UserPromptSubmitSpecificOutput struct {
HookEventName string `json:"hookEventName"` // "UserPromptSubmit"
AdditionalContext *string `json:"additionalContext,omitempty"`
}
UserPromptSubmitSpecificOutput is the hook-specific output for UserPromptSubmit.
func (*UserPromptSubmitSpecificOutput) GetHookEventName ¶
func (u *UserPromptSubmitSpecificOutput) GetHookEventName() string
GetHookEventName implements SpecificOutput.