Class: Ask::Rails::Harness::Tool

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.session_idObject



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

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.



32
33
34
# File 'lib/ask/rails/harness/tool.rb', line 32

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

Instance Method Details

#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.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ask/rails/harness/tool.rb', line 14

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

#rails_rootObject



7
8
9
# File 'lib/ask/rails/harness/tool.rb', line 7

def rails_root
  ::Rails.root
end