Class: Mildred::Tools::RunCommand

Inherits:
RubyLLM::Tool
  • Object
show all
Defined in:
lib/mildred/tools/run_command.rb

Instance Method Summary collapse

Instance Method Details

#execute(command:) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/mildred/tools/run_command.rb', line 13

def execute(command:)
  if Mildred::Current.noop
    Mildred.logger.log(command, "[noop]", "", 0)
    puts Gum.style("  → #{command}", foreground: "220")
    return { stdout: "[noop] would execute: #{command}", stderr: "", exit_code: 0 }
  end

  container_id = Mildred::Current.container_id

  stdout, stderr, status = if container_id
                             Open3.capture3("container", "exec", container_id, "bash", "-c", command)
                           else
                             Open3.capture3("bash", "-c", command)
                           end

  Mildred.logger.log(command, stdout, stderr, status.exitstatus)

  {
    stdout: stdout,
    stderr: stderr,
    exit_code: status.exitstatus
  }
end