hooks

package
v0.3.20 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package hooks implements the lifecycle hooks system for automation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventData

type EventData map[string]interface{}

EventData contains context passed to hooks

type Executor

type Executor struct{}

Executor runs hook commands

func NewExecutor

func NewExecutor() *Executor

NewExecutor creates a new hook executor

func (*Executor) Run

func (e *Executor) Run(ctx context.Context, event HookEvent, config HookConfig, data EventData) (*HookResult, error)

Run executes a hook command with timeout

type HookConfig

type HookConfig struct {
	Command string            `yaml:"command" json:"command"`
	Matcher map[string]string `yaml:"matcher,omitempty" json:"matcher,omitempty"`
	Timeout int               `yaml:"timeout,omitempty" json:"timeout,omitempty"` // seconds
}

HookConfig defines a single hook's configuration

func (*HookConfig) Validate

func (h *HookConfig) Validate() error

Validate checks if the hook configuration is valid

type HookEvent

type HookEvent string

HookEvent represents a lifecycle event that can trigger hooks

const (
	SessionStart      HookEvent = "SessionStart"
	SessionEnd        HookEvent = "SessionEnd"
	UserPromptSubmit  HookEvent = "UserPromptSubmit"
	ModelResponseDone HookEvent = "ModelResponseDone"
	PreToolUse        HookEvent = "PreToolUse"
	PostToolUse       HookEvent = "PostToolUse"
	PreCommit         HookEvent = "PreCommit"
	PostCommit        HookEvent = "PostCommit"
	OnError           HookEvent = "OnError"
	PlanModeEnter     HookEvent = "PlanModeEnter"
)

Lifecycle hook events that can trigger hook execution

type HookResult

type HookResult struct {
	Success  bool
	Output   string
	Error    string
	Duration time.Duration
}

HookResult contains the result of hook execution

type HooksConfig

type HooksConfig map[HookEvent][]HookConfig

HooksConfig maps hook events to their configurations

type Manager

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

Manager manages hook execution for lifecycle events

func NewManager

func NewManager(config HooksConfig) *Manager

NewManager creates a new hook manager

func (*Manager) Trigger

func (m *Manager) Trigger(ctx context.Context, event HookEvent, data EventData) ([]*HookResult, error)

Trigger executes all hooks for a given event

func (*Manager) TriggerAsync

func (m *Manager) TriggerAsync(event HookEvent, data EventData)

TriggerAsync executes hooks without blocking

func (*Manager) Wait

func (m *Manager) Wait()

Wait waits for all async hooks to complete

Jump to

Keyboard shortcuts

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