Class: Ask::Ruby::Harness::Tool
- Inherits:
-
Tool
- Object
- Tool
- Ask::Ruby::Harness::Tool
- 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).
Direct Known Subclasses
Ask::Ruby::Harness::Tools::QueryDatabase, Ask::Ruby::Harness::Tools::ReadLog, Ask::Ruby::Harness::Tools::ReadModel, Ask::Ruby::Harness::Tools::RunCommand, Ask::Ruby::Harness::Tools::RunTests, Ask::Ruby::Harness::Tools::SchemaGraph
Class Method Summary collapse
- .session_id ⇒ Object
-
.session_id=(id) ⇒ Object
Allow the session to set its ID for audit log correlation.
Instance Method Summary collapse
- #app_root ⇒ Object
-
#call(args = {}, abort_controller = nil) ⇒ Object
Override call to add audit logging around every tool execution.
Class Method Details
.session_id ⇒ Object
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_root ⇒ Object
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 |