# `Nous.Hook.Registry`
[🔗](https://github.com/nyo16/nous/blob/v0.17.1/lib/nous/hook/registry.ex#L1)

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"})

# `t`

```elixir
@type t() :: %Nous.Hook.Registry{
  hooks: %{required(Nous.Hook.event()) =&gt; [Nous.Hook.t()]}
}
```

# `count`

```elixir
@spec count(t()) :: non_neg_integer()
```

Return the total number of registered hooks.

# `from_hooks`

```elixir
@spec from_hooks([Nous.Hook.t()]) :: t()
```

Create a registry from a list of hooks.

# `has_hooks?`

```elixir
@spec has_hooks?(t(), Nous.Hook.event()) :: boolean()
```

Check if the registry has any hooks for a given event.

# `hooks_for`

```elixir
@spec hooks_for(t(), Nous.Hook.event()) :: [Nous.Hook.t()]
```

Get all hooks for a given event type.

# `hooks_for`

```elixir
@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.

# `new`

```elixir
@spec new() :: t()
```

Create an empty registry.

# `register`

```elixir
@spec register(t(), Nous.Hook.t()) :: t()
```

Register a hook in the registry.

Hooks are stored sorted by priority (lower = earlier execution).

# `register_all`

```elixir
@spec register_all(t(), [Nous.Hook.t()]) :: t()
```

Register multiple hooks at once.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
