Storage and lookup for hooks, indexed by event type.
The registry maintains hooks sorted by priority within each event type.
It provides efficient lookup with optional tool name matching for
:pre_tool_use and :post_tool_use events.
Example
registry = Nous.Hook.Registry.new()
|> Nous.Hook.Registry.register(%Nous.Hook{
event: :pre_tool_use,
matcher: "delete_file",
type: :function,
handler: fn _, _ -> :deny end
})
hooks = Nous.Hook.Registry.hooks_for(registry, :pre_tool_use, %{tool_name: "delete_file"})
Summary
Functions
Return the total number of registered hooks.
Create a registry from a list of hooks.
Check if the registry has any hooks for a given event.
Get all hooks for a given event type.
Get hooks for a given event type that match the payload.
Create an empty registry.
Register a hook in the registry.
Register multiple hooks at once.
Types
@type t() :: %Nous.Hook.Registry{ hooks: %{required(Nous.Hook.event()) => [Nous.Hook.t()]} }
Functions
@spec count(t()) :: non_neg_integer()
Return the total number of registered hooks.
@spec from_hooks([Nous.Hook.t()]) :: t()
Create a registry from a list of hooks.
@spec has_hooks?(t(), Nous.Hook.event()) :: boolean()
Check if the registry has any hooks for a given event.
@spec hooks_for(t(), Nous.Hook.event()) :: [Nous.Hook.t()]
Get all hooks for a given event type.
@spec hooks_for(t(), Nous.Hook.event(), map()) :: [Nous.Hook.t()]
Get hooks for a given event type that match the payload.
For :pre_tool_use and :post_tool_use, filters by tool name matching.
For other events, returns all hooks for that event.
@spec new() :: t()
Create an empty registry.
@spec register(t(), Nous.Hook.t()) :: t()
Register a hook in the registry.
Hooks are stored sorted by priority (lower = earlier execution).
@spec register_all(t(), [Nous.Hook.t()]) :: t()
Register multiple hooks at once.