hooks

package
v0.11.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0, MIT Imports: 15 Imported by: 0

Documentation

Overview

Package hooks — user-defined hooks loaded from disk (master plan §6.3).

Layout: ~/.overkill/hooks/<point>/<name>.sh on Unix, or .ps1/.exe on Windows.

point ∈ {before_tool_call, after_tool_call, on_session_start,
         on_session_end, on_error, before_compaction, after_compaction,
         after_turn}

Each script is invoked with the JSON-serialized Event piped to stdin. Scripts have 5 seconds to finish; non-zero exit codes are logged but do NOT block the agent (hooks are observability, not gating). Make scripts executable (`chmod +x`) on Unix. Windows hooks must be owned by the current user, with modification rights limited to that user, Administrators and SYSTEM. PowerShell hooks run without profiles and retain the machine execution policy. Unsafe or unsupported files are skipped. Timeout cancellation kills the hook process group on Unix and its entire Job Object on Windows.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadFromDir

func LoadFromDir(reg *Registry, dir string) (int, error)

LoadFromDir walks dir/<point>/ and registers every safe executable hook as a Hook. Returns the count of hooks registered. Missing dir is fine (returns 0, nil).

Types

type Event

type Event struct {
	Point      HookPoint       `json:"point"`
	ToolName   string          `json:"tool_name,omitempty"`
	ToolInput  json.RawMessage `json:"tool_input,omitempty"`
	ToolOutput json.RawMessage `json:"tool_output,omitempty"`
	Error      error           `json:"-"`
	SessionID  string          `json:"session_id,omitempty"`
	Metadata   map[string]any  `json:"metadata,omitempty"`
}

type Hook

type Hook struct {
	Name     string
	Point    HookPoint
	Fn       HookFunc
	Priority int
}

func NewLoggingHook

func NewLoggingHook() Hook

func NewRateLimitHook

func NewRateLimitHook(maxPerMinute int) Hook

type HookFunc

type HookFunc func(ctx context.Context, event Event) (context.Context, error)

type HookPoint

type HookPoint string
const (
	BeforeToolCall   HookPoint = "before_tool_call"
	AfterToolCall    HookPoint = "after_tool_call"
	AfterTurn        HookPoint = "after_turn"
	OnSessionStart   HookPoint = "on_session_start"
	OnSessionEnd     HookPoint = "on_session_end"
	OnError          HookPoint = "on_error"
	BeforeCompaction HookPoint = "before_compaction"
	AfterCompaction  HookPoint = "after_compaction"
)

type MetricsHook

type MetricsHook struct {
	Hook
	// contains filtered or unexported fields
}

func NewMetricsHook

func NewMetricsHook() *MetricsHook

func (*MetricsHook) Counts

func (m *MetricsHook) Counts() map[HookPoint]int64

type Registry

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

func NewRegistry

func NewRegistry() *Registry

func NewRegistryFromDir

func NewRegistryFromDir(dir string) (*Registry, error)

NewRegistryFromDir loads only the application owner's hooks directory, never scripts from a workspace supplied by an agent or remote peer. Each session receives its own registry; changes take effect for newly constructed sessions.

func (*Registry) Fire

func (r *Registry) Fire(ctx context.Context, point HookPoint, event Event) (context.Context, error)

func (*Registry) List

func (r *Registry) List(point HookPoint) []Hook

func (*Registry) ListAll

func (r *Registry) ListAll() map[HookPoint][]Hook

func (*Registry) Register

func (r *Registry) Register(hook Hook) error

func (*Registry) Unregister

func (r *Registry) Unregister(name string) bool

Jump to

Keyboard shortcuts

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