Class: Kreator::Tools::Bash

Inherits:
Object
  • Object
show all
Defined in:
lib/kreator/tools/bash.rb

Constant Summary collapse

DEFAULT_MAX_OUTPUT_BYTES =
20_000

Instance Method Summary collapse

Constructor Details

#initialize(default_timeout: ToolContext::DEFAULT_BASH_TIMEOUT) ⇒ Bash

Returns a new instance of Bash.



11
12
13
# File 'lib/kreator/tools/bash.rb', line 11

def initialize(default_timeout: ToolContext::DEFAULT_BASH_TIMEOUT)
  @default_timeout = Integer(default_timeout)
end

Instance Method Details

#call(args:, context:, signal:) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/kreator/tools/bash.rb', line 36

def call(args:, context:, signal:)
  command, timeout, max_output_bytes = bash_arguments(args, context)
  prepare_bash_call(context, command, timeout, signal)
  execution = run_bash_command(context, command, signal, timeout)

  output, truncated = truncate_output(execution.fetch(:stdout), execution.fetch(:stderr), max_output_bytes)
  ToolResult.new(
    tool_call_id: "",
    name: name,
    content: output,
    status: bash_status(execution),
    metadata: (execution, truncated),
    error: bash_error(execution.fetch(:status), execution.fetch(:timed_out), execution.fetch(:cancelled))
  )
end

#descriptionObject



19
20
21
# File 'lib/kreator/tools/bash.rb', line 19

def description
  "Run a shell command in the current workspace with timeout and output truncation."
end

#nameObject



15
16
17
# File 'lib/kreator/tools/bash.rb', line 15

def name
  "bash"
end

#schemaObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/kreator/tools/bash.rb', line 23

def schema
  {
    "type" => "object",
    "additionalProperties" => false,
    "required" => ["command"],
    "properties" => {
      "command" => { "type" => "string", "minLength" => 1 },
      "timeout" => { "type" => "integer", "minimum" => 1 },
      "max_output_bytes" => { "type" => "integer", "minimum" => 1 }
    }
  }
end