hooks

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package hooks loads and runs lifecycle hooks around agent actions.

Index

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 MessagesFromReport(report RunReport) []string

func NormalizeHookEvent

func NormalizeHookEvent(value string) (string, error)

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 PromptRequest struct {
	Type    string  `json:"type"`
	Prompt  string  `json:"prompt"`
	Model   string  `json:"model,omitempty"`
	Payload Payload `json:"payload"`
}

type PromptRunner

type PromptRunner func(context.Context, PromptRequest) (string, error)

type RunReport

type RunReport struct {
	Kind     string          `json:"kind"`
	Event    string          `json:"event"`
	Tool     string          `json:"tool,omitempty"`
	Status   string          `json:"status"`
	Count    int             `json:"count"`
	Disabled bool            `json:"disabled,omitempty"`
	Denied   bool            `json:"denied,omitempty"`
	Results  []CommandResult `json:"results"`
}

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 (r Runner) CwdChanged(ctx context.Context, oldCWD string, newCWD string, input string) error

func (Runner) CwdChangedReport

func (r Runner) CwdChangedReport(ctx context.Context, oldCWD string, newCWD string, input string) (RunReport, error)

func (Runner) FileChanged

func (r Runner) FileChanged(ctx context.Context, filePath string, operation string, input []byte) error

func (Runner) FileChangedReport

func (r Runner) FileChangedReport(ctx context.Context, filePath string, operation string, input []byte) (RunReport, error)

func (Runner) InstructionsLoaded

func (r Runner) InstructionsLoaded(ctx context.Context, filePath string, memoryType string, loadReason string, globs []string, triggerFilePath string, parentFilePath string) error

func (Runner) InstructionsLoadedReport

func (r Runner) InstructionsLoadedReport(ctx context.Context, filePath string, memoryType string, loadReason string, globs []string, triggerFilePath string, parentFilePath string) (RunReport, error)

func (Runner) Notification

func (r Runner) Notification(ctx context.Context, notificationType string, title string, message string) error

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 (r Runner) PermissionDenied(ctx context.Context, tool string, input []byte, reason string) error

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 (r Runner) PermissionRequest(ctx context.Context, tool string, input []byte) error

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) PostCompact

func (r Runner) PostCompact(ctx context.Context, input string) error

func (Runner) PostCompactReport

func (r Runner) PostCompactReport(ctx context.Context, input string) (RunReport, error)

PostCompactReport runs PostCompact hooks and returns parsed hook feedback.

func (Runner) PostToolUse

func (r Runner) PostToolUse(ctx context.Context, tool string, input []byte, output string, isError bool) error

func (Runner) PostToolUseFailure

func (r Runner) PostToolUseFailure(ctx context.Context, tool string, input []byte, output string) error

func (Runner) PostToolUseFailureReport

func (r Runner) PostToolUseFailureReport(ctx context.Context, tool string, input []byte, output string) (RunReport, error)

func (Runner) PostToolUseReport

func (r Runner) PostToolUseReport(ctx context.Context, tool string, input []byte, output string, isError bool) (RunReport, error)

func (Runner) PreCompact

func (r Runner) PreCompact(ctx context.Context, input string) error

func (Runner) PreCompactReport

func (r Runner) PreCompactReport(ctx context.Context, input string) (RunReport, error)

PreCompactReport runs PreCompact hooks and returns parsed hook feedback.

func (Runner) PreToolUse

func (r Runner) PreToolUse(ctx context.Context, tool string, input []byte) error

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) RunHooks

func (r Runner) RunHooks(ctx context.Context, hookList []config.HookCommand, payload Payload) (RunReport, error)

func (Runner) RunPayload

func (r Runner) RunPayload(ctx context.Context, commands []string, payload Payload) (RunReport, error)

func (Runner) SessionEnd

func (r Runner) SessionEnd(ctx context.Context, input string, reason string) error

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) SessionStart

func (r Runner) SessionStart(ctx context.Context, input string) error

func (Runner) SessionStartReport

func (r Runner) SessionStartReport(ctx context.Context, input string) (RunReport, error)

func (Runner) Setup

func (r Runner) Setup(ctx context.Context, input string) error

func (Runner) Stop

func (r Runner) Stop(ctx context.Context, output string, isError bool) error

func (Runner) StopFailure

func (r Runner) StopFailure(ctx context.Context, output string, reason string) error

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

func (r Runner) StopReport(ctx context.Context, output string, isError bool) (RunReport, error)

StopReport runs Stop hooks and returns parsed hook feedback.

func (Runner) SubagentStart

func (r Runner) SubagentStart(ctx context.Context, agentID string, agentType string) error

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 (r Runner) SubagentStop(ctx context.Context, agentID string, agentType string, transcriptPath string, lastAssistant string, stopHookActive bool) error

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 (r Runner) TaskCompleted(ctx context.Context, id string, kind string, status string, reason string, input string) error

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 (r Runner) TaskCreated(ctx context.Context, id string, kind string, status string, input string) error

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 (r Runner) UserPromptSubmit(ctx context.Context, input string) error

func (Runner) UserPromptSubmitReport

func (r Runner) UserPromptSubmitReport(ctx context.Context, input string) (RunReport, error)

UserPromptSubmitReport runs UserPromptSubmit hooks and returns parsed hook feedback that can be added to the next model request.

func (Runner) WorktreeCreate

func (r Runner) WorktreeCreate(ctx context.Context, id string, worktreePath string, ref string, input string) error

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

func (r Runner) WorktreeRemove(ctx context.Context, id string, worktreePath string, ref string, reason string, input string) error

func (Runner) WorktreeRemoveReport

func (r Runner) WorktreeRemoveReport(ctx context.Context, id string, worktreePath string, ref string, reason string, input string) (RunReport, error)

WorktreeRemoveReport runs WorktreeRemove hooks and returns parsed hook feedback.

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL