Class: RubynCode::Hooks::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyn_code/hooks/runner.rb

Overview

Executes registered hooks for a given event in priority order.

Hook execution is defensive: exceptions raised by individual hooks are caught and logged rather than allowed to crash the agent. Special semantics apply to :pre_tool_use (deny gating) and :post_tool_use (output transformation).

Instance Method Summary collapse

Constructor Details

#initialize(registry: Registry.new) ⇒ Runner

Returns a new instance of Runner.

Parameters:

  • registry (Hooks::Registry) (defaults to: Registry.new)

    the hook registry to draw from



13
14
15
# File 'lib/rubyn_code/hooks/runner.rb', line 13

def initialize(registry: Registry.new)
  @registry = registry
end

Instance Method Details

#fire(event, **context) ⇒ Hash, ...

Fires all hooks for the given event with the supplied context.

Parameters:

  • event (Symbol)

    the event type

  • context (Hash)

    keyword arguments passed to each hook

Returns:

  • (Hash, Object, nil)

    depends on event semantics:

    • :pre_tool_use => { deny: true, reason: “…” } if any hook denies, else nil

    • :post_tool_use => the (possibly transformed) output

    • all others => nil



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rubyn_code/hooks/runner.rb', line 25

def fire(event, **context)
  hooks = @registry.hooks_for(event)
  return if hooks.empty?

  case event
  when :pre_tool_use
    fire_pre_tool_use(hooks, context)
  when :post_tool_use
    fire_post_tool_use(hooks, context)
  else
    fire_generic(hooks, event, context)
  end
end