hooks

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute(ctx context.Context, event EventType, data map[string]interface{}) error

Execute runs all hooks for an event on the global registry.

func ExecuteAsync

func ExecuteAsync(ctx context.Context, event EventType, data map[string]interface{})

ExecuteAsync runs hooks asynchronously on the global registry.

func LoadHooksDir

func LoadHooksDir(dir string) error

LoadHooksDir loads hooks from a directory.

func Register

func Register(h Hook)

Register adds a hook to the global registry.

func RegisterDecisionHook

func RegisterDecisionHook(fn DecisionHookFn)

RegisterDecisionHook adds a decision hook to the global list.

func ResetDecisionHooks

func ResetDecisionHooks()

ResetDecisionHooks clears all registered decision hooks. Intended for testing.

Types

type DecisionHookFn

type DecisionHookFn func(event string, data map[string]interface{}) *HookDecision

DecisionHookFn is a function that inspects an event and optionally returns a decision. Returning nil means "no opinion" (proceed normally).

type EventType

type EventType string

EventType represents a hook event.

const (
	EventPreQuery      EventType = "pre_query"
	EventPostQuery     EventType = "post_query"
	EventPreTool       EventType = "pre_tool"
	EventPostTool      EventType = "post_tool"
	EventPreCompact    EventType = "pre_compact"
	EventPostCompact   EventType = "post_compact"
	EventFileChanged   EventType = "file_changed"
	EventSessionStart  EventType = "session_start"
	EventSessionEnd    EventType = "session_end"
	EventPermissionAsk EventType = "permission_ask"
	EventError         EventType = "error"
)

type Hook

type Hook struct {
	Name     string
	Event    EventType
	Priority int // lower = earlier
	Fn       func(ctx context.Context, data map[string]interface{}) error
}

Hook is a registered hook function.

func BuiltinHooks

func BuiltinHooks() []Hook

BuiltinHooks returns the default set of built-in hooks.

type HookDecision

type HookDecision struct {
	Action        string          `json:"action"` // "allow", "deny", "modify"
	Reason        string          `json:"reason,omitempty"`
	ModifiedInput json.RawMessage `json:"modified_input,omitempty"`
}

HookDecision represents the outcome of a decision hook.

func ExecuteDecisionHooks

func ExecuteDecisionHooks(event string, data map[string]interface{}) *HookDecision

ExecuteDecisionHooks runs all registered decision hooks for the given event. It returns the first non-nil decision. If all hooks return nil, the result is nil (meaning no opinion, proceed normally).

type Registry

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

Registry stores and executes hooks.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new hook registry.

func (*Registry) Execute

func (r *Registry) Execute(ctx context.Context, event EventType, data map[string]interface{}) error

Execute runs all hooks for an event.

func (*Registry) ExecuteAsync

func (r *Registry) ExecuteAsync(ctx context.Context, event EventType, data map[string]interface{})

ExecuteAsync runs hooks asynchronously (fire and forget).

func (*Registry) Register

func (r *Registry) Register(h Hook)

Register adds a hook to the registry.

Jump to

Keyboard shortcuts

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