Class: RubyCoded::Tools::RunCommandTool

Inherits:
BaseTool
  • Object
show all
Defined in:
lib/ruby_coded/tools/run_command_tool.rb

Overview

Execute a shell command in the project directory and return its output

Constant Summary collapse

TIMEOUT_SECONDS =
30
MAX_OUTPUT_CHARS =
5000

Constants inherited from BaseTool

BaseTool::CONFIRM_RISK, BaseTool::DANGEROUS_RISK, BaseTool::SAFE_RISK

Instance Method Summary collapse

Methods inherited from BaseTool

#initialize

Constructor Details

This class inherits a constructor from RubyCoded::Tools::BaseTool

Instance Method Details

#execute(command:) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ruby_coded/tools/run_command_tool.rb', line 20

def execute(command:)
  stdout, stderr, status = run_with_timeout(command)

  output = String.new
  output << stdout unless stdout.empty?
  output << "\nSTDERR:\n#{stderr}" unless stderr.empty?
  output << "\nExit code: #{status.exitstatus}"

  truncate_output(output)
rescue Errno::ENOENT => e
  { error: "Command not found: #{e.message}" }
rescue StandardError => e
  { error: "Command failed: #{e.message}" }
end