Documentation
¶
Overview ¶
Package hook runs shell hooks at agent lifecycle points (pre/post tool call, pre/post user turn) so users can attach gofmt, audit logging, lint gates etc. without rebuilding ub.
The runner is intentionally minimal:
- hook commands are argv slices, not shell strings, so quoting bugs surface in the config not in execution
- stdout/stderr each cap at outputCap; oversized output is dropped
- env passed to children is restricted to an explicit whitelist plus five UB_HOOK_* variables this package always sets
- block semantics live ONLY on pre_tool_call; all other phases treat a non-zero exit as warn so a misbehaving hook can never wedge the agent loop
Index ¶
Constants ¶
const ( // OnFailureWarn means a non-zero hook exit is reported but never blocks // the underlying tool call. OnFailureWarn = "warn" // OnFailureBlock means a non-zero hook exit on a pre_tool_call hook makes // the agent skip Execute and surface the hook stderr as an IsError tool // result. It has no effect on the other three trigger kinds. OnFailureBlock = "block" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Decision ¶
Decision is the aggregated effect of all matched hooks for one event. Block is only ever true for KindPreToolCall when at least one matched hook had OnFailure=block AND exited non-zero.
type Event ¶
type Event struct {
Kind Kind
SessionID string
Turn int
ToolName string
ToolUseID string
ToolArgs json.RawMessage
// Result is only populated on post_tool_call events. The runner
// serializes a tiny slice of fields (Content / IsError) into the
// stdin JSON; full Result.Files etc. are deliberately omitted to keep
// hook payloads small.
Result *tool.Result
}
Event carries the contextual data a hook can see via stdin JSON and the UB_HOOK_* env variables.
type NopRunner ¶
type NopRunner struct{}
NopRunner is a Runner that returns an empty Decision for every event. The agent uses it whenever no hooks are configured.
type Outcome ¶
type Outcome struct {
HookIndex int
Command []string
ExitCode int
Stdout string
Stderr string
Duration time.Duration
Err error
}
Outcome captures the result of one hook process.
type Runner ¶
Runner is the contract the agent uses. A nil Runner is treated as no-op at the call site.
func New ¶
func New(cfg config.HooksConfig) Runner
New returns a Runner constructed from the merged config. When no hook entries are configured for any kind, NopRunner is returned so callers pay zero runtime cost.