hooks

package
v0.22.145 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package hooks — user-defined shell-command hooks for clawtool lifecycle events (ADR-014 F3, Claude Code parity).

Pattern: every clawtool call site that wants to expose a hook emits one event; hooks.Emit fans the event out to every configured HookEntry under the matching event name. Events carry structured JSON metadata that lands on the script's stdin, so user scripts stay free of argv parsing. Failures default to log-and-continue; `block_on_error = true` flips that for guard-rail hooks.

Per ADR-007 we wrap stdlib (`os/exec` + `encoding/json`); we don't invent an event-bus or RPC.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetGlobal

func SetGlobal(m *Manager)

SetGlobal registers the process-wide manager. Idempotent.

Types

type Event

type Event string

Event is the canonical name string. Locked at v0.15; new events are additive, never renamed.

const (
	EventPreSend         Event = "pre_send"
	EventPostSend        Event = "post_send"
	EventOnTaskComplete  Event = "on_task_complete"
	EventPreEdit         Event = "pre_edit"
	EventPostEdit        Event = "post_edit"
	EventPreBridgeAdd    Event = "pre_bridge_add"
	EventPostRecipeApply Event = "post_recipe_apply"
	EventOnServerStart   Event = "on_server_start"
	EventOnServerStop    Event = "on_server_stop"
)

type Manager

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

Manager is the process-wide hooks dispatcher. One per clawtool process; SetGlobal registers it. Nil manager → Emit is a no-op.

func Get

func Get() *Manager

Get returns the process-wide manager (or nil when none set).

func New

func New(cfg config.HooksConfig) *Manager

New wires a Manager from the config block. Nil-safe; an empty HooksConfig yields a Manager whose Emit is a no-op.

func (*Manager) Emit

func (m *Manager) Emit(ctx context.Context, event Event, payload map[string]any) error

Emit fires `event` against every configured HookEntry. Returns nil for non-blocking hooks; only block_on_error entries propagate failure. Safe to call with a nil manager (no-op) and with unregistered events (no-op).

func (*Manager) EmitCount

func (m *Manager) EmitCount() uint64

EmitCount reports how many events have fired (regardless of per-entry success). Useful for tests and the future `clawtool hooks status` subcommand.

Jump to

Keyboard shortcuts

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