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 ¶
Load reads .brocode/hooks.json (project) then ~/.config/brocode/hooks.json (global). Missing files are not errors — hooks are optional.