hooks

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package hooks runs shell-command hooks bound to lifecycle events. Each hook receives the event payload as JSON on stdin and may return a JSON Decision on stdout; PreToolUse decisions gate tool execution.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decision

type Decision struct {
	Approved   *bool  `json:"approved"`
	Block      bool   `json:"block"`
	Adjustment string `json:"adjustment"`
	Reason     string `json:"reason"`
}

Decision is a hook's JSON stdout response.

type Dispatcher

type Dispatcher struct {
	// contains filtered or unexported fields
}

Dispatcher fires hooks for events.

func New

func New(hooks []types.HookConfig) *Dispatcher

New builds a dispatcher over the given hooks (a nil/empty slice is a no-op).

func (*Dispatcher) Fire

func (d *Dispatcher) Fire(ctx context.Context, event Event, name string, payload any) []Decision

Fire runs every hook whose Event matches and whose Matcher matches name (empty matcher matches all), passing payload as JSON on stdin, and returns each hook's Decision in order.

type Event

type Event string

Event identifies a lifecycle hook point.

const (
	EventSessionStart     Event = "SessionStart"
	EventUserPromptSubmit Event = "UserPromptSubmit"
	EventPreToolUse       Event = "PreToolUse"
	EventPostToolUse      Event = "PostToolUse"
	EventAgentEvent       Event = "AgentEvent"
	EventStop             Event = "Stop"
)

type ToolDecision

type ToolDecision struct {
	Decided    bool
	Approve    bool
	Adjustment string
	Reason     string
}

ToolDecision is the combined PreToolUse verdict.

func CombineToolDecisions

func CombineToolDecisions(ds []Decision) ToolDecision

CombineToolDecisions reduces PreToolUse decisions: any block / explicit approved:false denies (first one wins); otherwise any explicit approved:true approves (carrying its adjustment); otherwise undecided.

Jump to

Keyboard shortcuts

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