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
COMMAND_ENV =
{
  "GIT_EDITOR" => "true",
  "EDITOR" => "true",
  "VISUAL" => "true",
  "GIT_PAGER" => "cat",
  "PAGER" => "cat"
}.freeze

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



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ruby_coded/tools/run_command_tool.rb', line 27

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