Class: RubynCode::Tools::Executor
- Inherits:
-
Object
- Object
- RubynCode::Tools::Executor
- Defined in:
- lib/rubyn_code/tools/executor.rb
Constant Summary collapse
- BASH_WRITE_PATTERNS =
Patterns that indicate a bash command writes to a file.
[ /(?:>>?)\s*(\S+)/, # > file or >> file /\btee\s+(?:-a\s+)?(\S+)/, # tee file or tee -a file /\bsed\s+-i\S*\s+.*\s(\S+)$/, # sed -i 's/...' file /\bsed\s+-i\S*\s+.*\s(\S+)\s/ # sed -i 's/...' file (mid-command) ].freeze
Instance Attribute Summary collapse
-
#ask_user_callback ⇒ Object
Returns the value of attribute ask_user_callback.
-
#background_worker ⇒ Object
Returns the value of attribute background_worker.
-
#codebase_index ⇒ Object
Returns the value of attribute codebase_index.
-
#db ⇒ Object
Returns the value of attribute db.
-
#file_cache ⇒ Object
readonly
Returns the value of attribute file_cache.
-
#ide_client ⇒ Object
Returns the value of attribute ide_client.
-
#llm_client ⇒ Object
Returns the value of attribute llm_client.
-
#on_agent_status ⇒ Object
Returns the value of attribute on_agent_status.
-
#output_compressor ⇒ Object
readonly
Returns the value of attribute output_compressor.
-
#project_root ⇒ Object
readonly
Returns the value of attribute project_root.
Instance Method Summary collapse
-
#execute(tool_name, params) ⇒ Object
rubocop:disable Metrics/AbcSize – maps tool errors to results.
-
#initialize(project_root:, ide_client: nil) ⇒ Executor
constructor
A new instance of Executor.
- #tool_definitions ⇒ Object
Constructor Details
#initialize(project_root:, ide_client: nil) ⇒ Executor
Returns a new instance of Executor.
10 11 12 13 14 15 16 17 |
# File 'lib/rubyn_code/tools/executor.rb', line 10 def initialize(project_root:, ide_client: nil) @project_root = File.(project_root) @ide_client = ide_client @injections = {} @output_compressor = OutputCompressor.new @file_cache = FileCache.new Registry.load_all! end |
Instance Attribute Details
#ask_user_callback ⇒ Object
Returns the value of attribute ask_user_callback.
7 8 9 |
# File 'lib/rubyn_code/tools/executor.rb', line 7 def ask_user_callback @ask_user_callback end |
#background_worker ⇒ Object
Returns the value of attribute background_worker.
7 8 9 |
# File 'lib/rubyn_code/tools/executor.rb', line 7 def background_worker @background_worker end |
#codebase_index ⇒ Object
Returns the value of attribute codebase_index.
7 8 9 |
# File 'lib/rubyn_code/tools/executor.rb', line 7 def codebase_index @codebase_index end |
#db ⇒ Object
Returns the value of attribute db.
7 8 9 |
# File 'lib/rubyn_code/tools/executor.rb', line 7 def db @db end |
#file_cache ⇒ Object (readonly)
Returns the value of attribute file_cache.
6 7 8 |
# File 'lib/rubyn_code/tools/executor.rb', line 6 def file_cache @file_cache end |
#ide_client ⇒ Object
Returns the value of attribute ide_client.
7 8 9 |
# File 'lib/rubyn_code/tools/executor.rb', line 7 def ide_client @ide_client end |
#llm_client ⇒ Object
Returns the value of attribute llm_client.
7 8 9 |
# File 'lib/rubyn_code/tools/executor.rb', line 7 def llm_client @llm_client end |
#on_agent_status ⇒ Object
Returns the value of attribute on_agent_status.
7 8 9 |
# File 'lib/rubyn_code/tools/executor.rb', line 7 def on_agent_status @on_agent_status end |
#output_compressor ⇒ Object (readonly)
Returns the value of attribute output_compressor.
6 7 8 |
# File 'lib/rubyn_code/tools/executor.rb', line 6 def output_compressor @output_compressor end |
#project_root ⇒ Object (readonly)
Returns the value of attribute project_root.
6 7 8 |
# File 'lib/rubyn_code/tools/executor.rb', line 6 def project_root @project_root end |
Instance Method Details
#execute(tool_name, params) ⇒ Object
rubocop:disable Metrics/AbcSize – maps tool errors to results
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rubyn_code/tools/executor.rb', line 19 def execute(tool_name, params) # rubocop:disable Metrics/AbcSize -- maps tool errors to results # File cache intercept: serve cached reads, invalidate on writes cached = try_file_cache(tool_name, params) return cached if cached tool = build_tool(tool_name) filtered = filter_params(tool, params) raw = tool.truncate(tool.execute(**filtered).to_s) update_file_cache(tool_name, filtered, raw) maybe_update_codebase_index(tool_name, filtered) @output_compressor.compress(tool_name, raw) rescue ToolNotFoundError => e error_result("Tool error: #{e.}") rescue PermissionDeniedError => e error_result("Permission denied: #{e.}") rescue NotImplementedError => e error_result("Not implemented: #{e.}") rescue Error => e error_result("Error: #{e.}") rescue StandardError => e error_result("Unexpected error in #{tool_name}: #{e.class}: #{e.}") end |
#tool_definitions ⇒ Object
42 43 44 |
# File 'lib/rubyn_code/tools/executor.rb', line 42 def tool_definitions Registry.tool_definitions end |