Class: RubynCode::Tools::Executor

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.expand_path(project_root)
  @ide_client = ide_client
  @injections = {}
  @output_compressor = OutputCompressor.new
  @file_cache = FileCache.new
  Registry.load_all!
end

Instance Attribute Details

#ask_user_callbackObject

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_workerObject

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_indexObject

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

#dbObject

Returns the value of attribute db.



7
8
9
# File 'lib/rubyn_code/tools/executor.rb', line 7

def db
  @db
end

#file_cacheObject (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_clientObject

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_clientObject

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_statusObject

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_compressorObject (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_rootObject (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.message}")
rescue PermissionDeniedError => e
  error_result("Permission denied: #{e.message}")
rescue NotImplementedError => e
  error_result("Not implemented: #{e.message}")
rescue Error => e
  error_result("Error: #{e.message}")
rescue StandardError => e
  error_result("Unexpected error in #{tool_name}: #{e.class}: #{e.message}")
end

#tool_definitionsObject



42
43
44
# File 'lib/rubyn_code/tools/executor.rb', line 42

def tool_definitions
  Registry.tool_definitions
end