Class: Tools::Bash
Overview
Executes bash commands in a persistent ShellSession. Commands share working directory, environment variables, and shell history within a conversation. Output is truncated and timeouts are enforced by the underlying session.
Class Method Summary collapse
Instance Method Summary collapse
- #execute(input) ⇒ String, Hash
-
#initialize(shell_session:) ⇒ Bash
constructor
A new instance of Bash.
Methods inherited from Base
Constructor Details
#initialize(shell_session:) ⇒ Bash
Returns a new instance of Bash.
26 27 28 |
# File 'lib/tools/bash.rb', line 26 def initialize(shell_session:, **) @shell_session = shell_session end |
Class Method Details
.description ⇒ Object
13 |
# File 'lib/tools/bash.rb', line 13 def self.description = "Execute a bash command. Working directory and environment persist across calls within a conversation." |
.input_schema ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/tools/bash.rb', line 15 def self.input_schema { type: "object", properties: { command: {type: "string", description: "The bash command to execute"} }, required: ["command"] } end |
.tool_name ⇒ Object
11 |
# File 'lib/tools/bash.rb', line 11 def self.tool_name = "bash" |
Instance Method Details
#execute(input) ⇒ String, Hash
33 34 35 36 37 38 39 40 41 |
# File 'lib/tools/bash.rb', line 33 def execute(input) command = input["command"].to_s return {error: "Command cannot be blank"} if command.strip.empty? result = @shell_session.run(command) return result if result.key?(:error) format_result(result[:stdout], result[:stderr], result[:exit_code]) end |