Holds an agent's hooks, finds the ones that match an event, and runs them.
Each agent has its own registry in agent$hooks; add hooks with
agent$add_hook().
Methods
HookRegistry$get_hooks()
Get the hooks that match an event.
Arguments
eventA HookEvent.
tool_nameOptional tool name to match against hook patterns.
Returns
A list of HookMatcher objects.
HookRegistry$fire()
Run the matching hooks in the order they were added and return the
first non-NULL result. Later hooks don't run. When a callback returns
a promise, later hooks wait for it, and the promise fire() returns
resolves to that result.
A failing callback is recorded in last_errors(). For PreToolUse the
failure denies the tool call; for other events it is reported and the
next hook runs.
Arguments
eventA HookEvent.
tool_nameOptional tool name, matched against hook patterns and passed to the callback.
...Other arguments for the callback.
HookRegistry$reserve_fire_id()
Reserve the ID of the next fire() call, so that its errors can be
found afterwards with errors_from(). Call it immediately before
fire().
HookRegistry$last_errors()
Get the errors hook callbacks have raised since the registry was created or last cleared. Use it to check logging hooks, whose failures don't stop the run.
HookRegistry$errors_from()
Get the errors raised by one fire() call, including those of promises
that settled later.