Module: Roast::Tools::Bash

Extended by:
Bash
Included in:
Bash
Defined in:
lib/roast/tools/bash.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/roast/tools/bash.rb', line 13

def included(base)
  base.class_eval do
    function(
      :bash,
      "Execute any bash command without restrictions. ⚠️ WARNING: Use only in trusted environments!",
      command: { type: "string", description: "The bash command to execute" },
      timeout: { type: "integer", description: "Timeout in seconds (optional, default: 30)", required: false },
    ) do |params|
      Roast::Tools::Bash.call(params[:command], timeout: params[:timeout])
    end
  end
end

Instance Method Details

#call(command, timeout: 30) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/roast/tools/bash.rb', line 27

def call(command, timeout: 30)
  Roast::Helpers::Logger.info("🚀 Executing bash command: #{command}\n")

  # Show warning unless explicitly disabled
  if ENV["ROAST_BASH_WARNINGS"] != "false"
    Roast::Helpers::Logger.warn("⚠️  WARNING: Unrestricted bash execution - use with caution!\n")
  end

  result, exit_status = Roast::Helpers::TimeoutHandler.call(
    "#{command} 2>&1",
    timeout: timeout,
    working_directory: Dir.pwd,
  )

  format_output(command, result, exit_status)
rescue Timeout::Error => e
  Roast::Helpers::Logger.error(e.message + "\n")
  e.message
rescue StandardError => e
  handle_error(e)
end