Documentation
¶
Overview ¶
Package hooks loads and runs lifecycle hooks around agent actions.
Index ¶
- func CommandsForEvent(cfg config.HookConfig, event string, tool string) []string
- func HooksForPayload(cfg config.HookConfig, payload Payload) []config.HookCommand
- func MessagesFromReport(report RunReport) []string
- func NormalizeHookEvent(value string) (string, error)
- type CommandResult
- type Payload
- type PreToolUseOutput
- type PromptRequest
- type PromptRunner
- type RunReport
- type Runner
- func (r Runner) CwdChanged(ctx context.Context, oldCWD string, newCWD string, input string) error
- func (r Runner) CwdChangedReport(ctx context.Context, oldCWD string, newCWD string, input string) (RunReport, error)
- func (r Runner) FileChanged(ctx context.Context, filePath string, operation string, input []byte) error
- func (r Runner) FileChangedReport(ctx context.Context, filePath string, operation string, input []byte) (RunReport, error)
- func (r Runner) InstructionsLoaded(ctx context.Context, filePath string, memoryType string, loadReason string, ...) error
- func (r Runner) InstructionsLoadedReport(ctx context.Context, filePath string, memoryType string, loadReason string, ...) (RunReport, error)
- func (r Runner) Notification(ctx context.Context, notificationType string, title string, message string) error
- func (r Runner) NotificationReport(ctx context.Context, notificationType string, title string, message string) (RunReport, error)
- func (r Runner) PermissionDenied(ctx context.Context, tool string, input []byte, reason string) error
- func (r Runner) PermissionDeniedReport(ctx context.Context, tool string, input []byte, reason string) (RunReport, error)
- func (r Runner) PermissionRequest(ctx context.Context, tool string, input []byte) error
- func (r Runner) PermissionRequestReport(ctx context.Context, tool string, input []byte) (RunReport, error)
- func (r Runner) PostCompact(ctx context.Context, input string) error
- func (r Runner) PostCompactReport(ctx context.Context, input string) (RunReport, error)
- func (r Runner) PostToolUse(ctx context.Context, tool string, input []byte, output string, isError bool) error
- func (r Runner) PostToolUseFailure(ctx context.Context, tool string, input []byte, output string) error
- func (r Runner) PostToolUseFailureReport(ctx context.Context, tool string, input []byte, output string) (RunReport, error)
- func (r Runner) PostToolUseReport(ctx context.Context, tool string, input []byte, output string, isError bool) (RunReport, error)
- func (r Runner) PreCompact(ctx context.Context, input string) error
- func (r Runner) PreCompactReport(ctx context.Context, input string) (RunReport, error)
- func (r Runner) PreToolUse(ctx context.Context, tool string, input []byte) error
- func (r Runner) PreToolUseReport(ctx context.Context, tool string, input []byte) (RunReport, PreToolUseOutput, error)
- func (r Runner) RunHooks(ctx context.Context, hookList []config.HookCommand, payload Payload) (RunReport, error)
- func (r Runner) RunPayload(ctx context.Context, commands []string, payload Payload) (RunReport, error)
- func (r Runner) SessionEnd(ctx context.Context, input string, reason string) error
- func (r Runner) SessionEndReport(ctx context.Context, input string, reason string) (RunReport, error)
- func (r Runner) SessionStart(ctx context.Context, input string) error
- func (r Runner) SessionStartReport(ctx context.Context, input string) (RunReport, error)
- func (r Runner) Setup(ctx context.Context, input string) error
- func (r Runner) Stop(ctx context.Context, output string, isError bool) error
- func (r Runner) StopFailure(ctx context.Context, output string, reason string) error
- func (r Runner) StopFailureReport(ctx context.Context, output string, reason string) (RunReport, error)
- func (r Runner) StopReport(ctx context.Context, output string, isError bool) (RunReport, error)
- func (r Runner) SubagentStart(ctx context.Context, agentID string, agentType string) error
- func (r Runner) SubagentStartReport(ctx context.Context, agentID string, agentType string) (RunReport, error)
- func (r Runner) SubagentStop(ctx context.Context, agentID string, agentType string, transcriptPath string, ...) error
- func (r Runner) SubagentStopReport(ctx context.Context, agentID string, agentType string, transcriptPath string, ...) (RunReport, error)
- func (r Runner) TaskCompleted(ctx context.Context, id string, kind string, status string, reason string, ...) error
- func (r Runner) TaskCompletedReport(ctx context.Context, id string, kind string, status string, reason string, ...) (RunReport, error)
- func (r Runner) TaskCreated(ctx context.Context, id string, kind string, status string, input string) error
- func (r Runner) TaskCreatedReport(ctx context.Context, id string, kind string, status string, input string) (RunReport, error)
- func (r Runner) UserPromptSubmit(ctx context.Context, input string) error
- func (r Runner) UserPromptSubmitReport(ctx context.Context, input string) (RunReport, error)
- func (r Runner) WorktreeCreate(ctx context.Context, id string, worktreePath string, ref string, input string) error
- func (r Runner) WorktreeCreateReport(ctx context.Context, id string, worktreePath string, ref string, input string) (RunReport, error)
- func (r Runner) WorktreeRemove(ctx context.Context, id string, worktreePath string, ref string, reason string, ...) error
- func (r Runner) WorktreeRemoveReport(ctx context.Context, id string, worktreePath string, ref string, reason string, ...) (RunReport, error)
- type SessionStartOutput
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CommandsForEvent ¶
func CommandsForEvent(cfg config.HookConfig, event string, tool string) []string
func HooksForPayload ¶
func HooksForPayload(cfg config.HookConfig, payload Payload) []config.HookCommand
func MessagesFromReport ¶
func NormalizeHookEvent ¶
NormalizeHookEvent returns the canonical hook event for a CLI/API alias.
Types ¶
type CommandResult ¶
type CommandResult struct {
Command string `json:"command"`
Type string `json:"type,omitempty"`
URL string `json:"url,omitempty"`
StatusCode int `json:"status_code,omitempty"`
Stdout string `json:"stdout,omitempty"`
Stderr string `json:"stderr,omitempty"`
Messages []string `json:"messages,omitempty"`
Denied bool `json:"denied,omitempty"`
ExitCode int `json:"exit_code"`
DurationMS int64 `json:"duration_ms"`
Success bool `json:"success"`
Error string `json:"error,omitempty"`
}
type Payload ¶
type Payload struct {
Event string `json:"event"`
Tool string `json:"tool,omitempty"`
ToolName string `json:"tool_name,omitempty"`
ToolInput json.RawMessage `json:"tool_input,omitempty"`
ToolUseID string `json:"tool_use_id,omitempty"`
Input string `json:"input,omitempty"`
Output string `json:"output,omitempty"`
IsError bool `json:"is_error,omitempty"`
Reason string `json:"reason,omitempty"`
Message string `json:"message,omitempty"`
Title string `json:"title,omitempty"`
NotificationType string `json:"notification_type,omitempty"`
AgentID string `json:"agent_id,omitempty"`
AgentType string `json:"agent_type,omitempty"`
TranscriptPath string `json:"agent_transcript_path,omitempty"`
StopHookActive bool `json:"stop_hook_active,omitempty"`
LastAssistant string `json:"last_assistant_message,omitempty"`
WorktreeID string `json:"worktree_id,omitempty"`
WorktreePath string `json:"worktree_path,omitempty"`
Ref string `json:"ref,omitempty"`
OldCWD string `json:"old_cwd,omitempty"`
NewCWD string `json:"new_cwd,omitempty"`
TaskID string `json:"task_id,omitempty"`
TaskKind string `json:"task_kind,omitempty"`
TaskStatus string `json:"task_status,omitempty"`
FilePath string `json:"file_path,omitempty"`
Operation string `json:"operation,omitempty"`
MemoryType string `json:"memory_type,omitempty"`
LoadReason string `json:"load_reason,omitempty"`
Globs []string `json:"globs,omitempty"`
TriggerFilePath string `json:"trigger_file_path,omitempty"`
ParentFilePath string `json:"parent_file_path,omitempty"`
}
type PreToolUseOutput ¶
type PreToolUseOutput struct {
Messages []string `json:"messages,omitempty"`
Denied bool `json:"denied,omitempty"`
PermissionDecision string `json:"permission_decision,omitempty"`
PermissionReason string `json:"permission_reason,omitempty"`
UpdatedInput json.RawMessage `json:"updated_input,omitempty"`
UpdatedInputProvided bool `json:"-"`
}
PreToolUseOutput is the Claude-compatible structured stdout emitted by PreToolUse hooks after all successful hooks have been merged.
func PreToolUseOutputFromReport ¶
func PreToolUseOutputFromReport(report RunReport) PreToolUseOutput
PreToolUseOutputFromReport extracts structured PreToolUse hook stdout from a report while preserving the last permission decision and updated input.
type PromptRequest ¶
type PromptRunner ¶
type PromptRunner func(context.Context, PromptRequest) (string, error)
type Runner ¶
type Runner struct {
Config config.HookConfig
Workspace string
ConfigHome string
SessionID string
Timeout time.Duration
Disabled bool
AllowedHTTPHookURLs *[]string
HTTPHookAllowedEnvVars *[]string
PromptRunner PromptRunner
}
func (Runner) CwdChanged ¶
func (Runner) CwdChangedReport ¶
func (Runner) FileChanged ¶
func (Runner) FileChangedReport ¶
func (Runner) InstructionsLoaded ¶
func (Runner) InstructionsLoadedReport ¶
func (Runner) Notification ¶
func (Runner) NotificationReport ¶
func (r Runner) NotificationReport(ctx context.Context, notificationType string, title string, message string) (RunReport, error)
NotificationReport runs Notification hooks and returns parsed hook feedback.
func (Runner) PermissionDenied ¶
func (Runner) PermissionDeniedReport ¶
func (r Runner) PermissionDeniedReport(ctx context.Context, tool string, input []byte, reason string) (RunReport, error)
PermissionDeniedReport runs PermissionDenied hooks and returns parsed hook feedback.
func (Runner) PermissionRequest ¶
func (Runner) PermissionRequestReport ¶
func (r Runner) PermissionRequestReport(ctx context.Context, tool string, input []byte) (RunReport, error)
PermissionRequestReport runs PermissionRequest hooks and returns parsed hook feedback.
func (Runner) PostCompactReport ¶
PostCompactReport runs PostCompact hooks and returns parsed hook feedback.
func (Runner) PostToolUse ¶
func (Runner) PostToolUseFailure ¶
func (Runner) PostToolUseFailureReport ¶
func (Runner) PostToolUseReport ¶
func (Runner) PreCompactReport ¶
PreCompactReport runs PreCompact hooks and returns parsed hook feedback.
func (Runner) PreToolUse ¶
func (Runner) PreToolUseReport ¶
func (r Runner) PreToolUseReport(ctx context.Context, tool string, input []byte) (RunReport, PreToolUseOutput, error)
PreToolUseReport runs PreToolUse hooks and returns both the raw hook report and parsed hookSpecificOutput fields such as permissionDecision and updatedInput.
func (Runner) RunPayload ¶
func (Runner) SessionEnd ¶
func (Runner) SessionEndReport ¶
func (r Runner) SessionEndReport(ctx context.Context, input string, reason string) (RunReport, error)
SessionEndReport runs SessionEnd hooks and returns parsed hook feedback.
func (Runner) SessionStartReport ¶
func (Runner) StopFailure ¶
func (Runner) StopFailureReport ¶
func (r Runner) StopFailureReport(ctx context.Context, output string, reason string) (RunReport, error)
StopFailureReport runs StopFailure hooks and returns parsed hook feedback.
func (Runner) StopReport ¶
StopReport runs Stop hooks and returns parsed hook feedback.
func (Runner) SubagentStart ¶
func (Runner) SubagentStartReport ¶
func (r Runner) SubagentStartReport(ctx context.Context, agentID string, agentType string) (RunReport, error)
SubagentStartReport runs SubagentStart hooks and returns parsed hook feedback.
func (Runner) SubagentStop ¶
func (Runner) SubagentStopReport ¶
func (r Runner) SubagentStopReport(ctx context.Context, agentID string, agentType string, transcriptPath string, lastAssistant string, stopHookActive bool) (RunReport, error)
SubagentStopReport runs SubagentStop hooks and returns parsed hook feedback.
func (Runner) TaskCompleted ¶
func (Runner) TaskCompletedReport ¶
func (r Runner) TaskCompletedReport(ctx context.Context, id string, kind string, status string, reason string, input string) (RunReport, error)
TaskCompletedReport runs TaskCompleted hooks and returns parsed hook feedback.
func (Runner) TaskCreated ¶
func (Runner) TaskCreatedReport ¶
func (r Runner) TaskCreatedReport(ctx context.Context, id string, kind string, status string, input string) (RunReport, error)
TaskCreatedReport runs TaskCreated hooks and returns parsed hook feedback.
func (Runner) UserPromptSubmit ¶
func (Runner) UserPromptSubmitReport ¶
UserPromptSubmitReport runs UserPromptSubmit hooks and returns parsed hook feedback that can be added to the next model request.
func (Runner) WorktreeCreate ¶
func (Runner) WorktreeCreateReport ¶
func (r Runner) WorktreeCreateReport(ctx context.Context, id string, worktreePath string, ref string, input string) (RunReport, error)
WorktreeCreateReport runs WorktreeCreate hooks and returns parsed hook feedback.
func (Runner) WorktreeRemove ¶
type SessionStartOutput ¶
type SessionStartOutput struct {
AdditionalContexts []string `json:"additional_contexts,omitempty"`
InitialMessages []string `json:"initial_messages,omitempty"`
WatchPaths []string `json:"watch_paths,omitempty"`
}
func SessionStartOutputFromReport ¶
func SessionStartOutputFromReport(report RunReport) SessionStartOutput