hooks

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

AllEvents lists every valid lifecycle event for documentation and validation.

Functions

This section is empty.

Types

type Event

type Event string

Event is a lifecycle event that can trigger hooks.

const (
	PreEdit             Event = "pre-edit"
	PostEdit            Event = "post-edit"
	PreCommand          Event = "pre-command"
	PostCommand         Event = "post-command"
	PreSession          Event = "pre-session"
	PostSession         Event = "post-session"
	PreCommit           Event = "pre-commit"
	PostCommit          Event = "post-commit"
	OnError             Event = "on-error"
	OnToolCall          Event = "on-tool-call"
	OnPermissionRequest Event = "on-permission-request"

	// Plan lifecycle
	PrePlan  Event = "pre-plan"
	PostPlan Event = "post-plan"

	// Fleet lifecycle
	PreFleet  Event = "pre-fleet"
	PostFleet Event = "post-fleet"

	// Agent lifecycle
	OnAgentSpawn    Event = "on-agent-spawn"
	OnAgentComplete Event = "on-agent-complete"

	// Token and cron events
	OnTokenLimit Event = "on-token-limit"
	OnCronTick   Event = "on-cron-tick"
)

type Hook

type Hook struct {
	Command string `yaml:"command"`
	Glob    string `yaml:"glob,omitempty"`
}

Hook defines a single hook command with an optional glob pattern.

type HookConfig

type HookConfig struct {
	Hooks map[Event][]Hook `yaml:"hooks"`
}

HookConfig holds the full hooks configuration.

func Load

func Load(workingDir string) (*HookConfig, error)

Load reads hook configs from ~/.ratchet/hooks.yaml and .ratchet/hooks.yaml. Project-level hooks (.ratchet/hooks.yaml) override global ones.

func (*HookConfig) Run

func (hc *HookConfig) Run(event Event, data map[string]string) error

Run executes all hooks for the given event, expanding templates with data. data keys include: "file", "command", "error", "tool", "session_id", "plan_id", "fleet_id", "agent_name", "agent_role", "cron_id", "tokens_used", "tokens_limit"

Jump to

Keyboard shortcuts

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