hooks

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package hooks provides lifecycle hooks for the agent loop, mirroring the pattern of Claude Code / opencode: the user defines shell commands that run at specific points in the turn (start, end, on error, before/after tool calls). Hooks let users enforce policies (git pull before each turn, notify on completion, deny certain tools, capture context) without touching code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Hooks []Hook `json:"hooks"`
}

Config is the hooks file format: {"hooks": [...]}.

type Event

type Event string

Event is a lifecycle point where hooks can run.

const (
	// EventTurnStart runs once when a turn begins (before the LLM call).
	EventTurnStart Event = "on-turn-start"
	// EventTurnEnd runs once when a turn finishes (answer produced).
	EventTurnEnd Event = "on-turn-end"
	// EventTurnError runs when a turn fails or is aborted.
	EventTurnError Event = "on-turn-error"
	// EventToolCall runs before each tool execution. Returning non-empty
	// output REPLACES the tool result (policy hooks can veto/override).
	EventToolCall Event = "on-tool-call"
	// EventToolResult runs after each tool execution with its output.
	EventToolResult Event = "on-tool-result"
)

type Hook

type Hook struct {
	Event    Event    `json:"event"`
	Command  string   `json:"command"`
	Timeout  int      `json:"timeout,omitempty"`  // seconds, default 30
	Async    bool     `json:"async,omitempty"`    // fire-and-forget
	Blocking bool     `json:"blocking,omitempty"` // if false, run and continue
	Env      []string `json:"env,omitempty"`      // extra KEY=value
}

Hook is one configured command for an event.

type Manager

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

Manager loads and runs hooks.

func Load

func Load(projectRoot string) *Manager

Load reads .brocode/hooks.json (project) then ~/.config/brocode/hooks.json (global). Missing files are not errors — hooks are optional.

func (*Manager) ForEvent

func (m *Manager) ForEvent(ev Event) []Hook

ForEvent returns the hooks configured for a given event.

func (*Manager) Run

func (m *Manager) Run(ctx context.Context, ev Event, data map[string]string) string

Run executes all hooks for an event. For on-tool-call hooks, the returned string (from the last hook that produced output) can override the tool result; for other events the output is discarded.

Jump to

Keyboard shortcuts

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