Class: Ask::Ruby::Harness::Tool

Inherits:
Tool
  • Object
show all
Defined in:
lib/ask/ruby/harness/tool.rb

Overview

Base class for harness tools. Provides the app root and audit-logged execution with session correlation. Framework editions subclass this to pin the app root (ask-rails-harness overrides app_root to ::Rails.root via the railtie).

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.session_idObject



40
41
42
# File 'lib/ask/ruby/harness/tool.rb', line 40

def self.session_id
  Thread.current[:ask_session_id]
end

.session_id=(id) ⇒ Object

Allow the session to set its ID for audit log correlation. Called by the agent loop before executing a tool.



36
37
38
# File 'lib/ask/ruby/harness/tool.rb', line 36

def self.session_id=(id)
  Thread.current[:ask_session_id] = id
end

Instance Method Details

#app_rootObject



11
12
13
# File 'lib/ask/ruby/harness/tool.rb', line 11

def app_root
  Ask::Ruby::Harness.app_root
end

#call(args = {}, abort_controller = nil) ⇒ Object

Override call to add audit logging around every tool execution. Logs the intent (sanitized params) and outcome (status, timing), but not the returned data.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ask/ruby/harness/tool.rb', line 18

def call(args = {}, abort_controller = nil)
  start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  result = super
  duration_ms = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time) * 1000).round

  AuditLog.log(
    session_id: Thread.current[:ask_session_id],
    tool_name: name,
    params: args,
    result: result,
    duration_ms: duration_ms
  )

  result
end