Class: RubynCode::Hooks::BuiltIn::LoggingHook

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

Overview

Logs tool calls and their results via the formatter.

Listens to :pre_tool_use and :post_tool_use events.

Instance Method Summary collapse

Constructor Details

#initialize(formatter:) ⇒ LoggingHook

Returns a new instance of LoggingHook.

Parameters:



53
54
55
# File 'lib/rubyn_code/hooks/built_in.rb', line 53

def initialize(formatter:)
  @formatter = formatter
end

Instance Method Details

#call(tool_name:, tool_input: {}, result: nil, **_kwargs) ⇒ nil

Handles both :pre_tool_use and :post_tool_use events.

For :pre_tool_use, logs the tool name and input arguments. For :post_tool_use, logs the tool result.

Parameters:

  • tool_name (String)

    name of the tool

  • tool_input (Hash) (defaults to: {})

    input arguments (for pre_tool_use)

  • result (String, nil) (defaults to: nil)

    tool output (for post_tool_use)

  • kwargs (Hash)

    remaining context

Returns:

  • (nil)


67
68
69
70
71
72
73
74
75
# File 'lib/rubyn_code/hooks/built_in.rb', line 67

def call(tool_name:, tool_input: {}, result: nil, **_kwargs)
  if result.nil?
    @formatter.tool_call(tool_name, tool_input)
  else
    @formatter.tool_result(tool_name, result, success: true)
  end

  nil
end