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.
Supports two modes:
-
Single command via
command(string) — backward compatible -
Batch via
commands(array) withmodecontrolling error handling
Class Method Summary collapse
Instance Method Summary collapse
- #execute(input) ⇒ String, Hash
-
#initialize(shell_session:, session:) ⇒ Bash
constructor
A new instance of Bash.
Methods inherited from Base
Constructor Details
#initialize(shell_session:, session:) ⇒ Bash
Returns a new instance of Bash.
42 43 44 45 |
# File 'lib/tools/bash.rb', line 42 def initialize(shell_session:, session:, **) @shell_session = shell_session @session = session end |
Class Method Details
.description ⇒ Object
17 |
# File 'lib/tools/bash.rb', line 17 def self.description = "Execute shell commands. Working directory and environment persist between calls." |
.input_schema ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/tools/bash.rb', line 19 def self.input_schema { type: "object", properties: { command: { type: "string" }, commands: { type: "array", items: {type: "string"}, description: "Each command gets its own timeout and result." }, mode: { type: "string", enum: ["sequential", "parallel"], description: "sequential (default) stops on first failure." } } } end |
.tool_name ⇒ Object
15 |
# File 'lib/tools/bash.rb', line 15 def self.tool_name = "bash" |
Instance Method Details
#execute(input) ⇒ String, Hash
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/tools/bash.rb', line 52 def execute(input) timeout = input["timeout"] has_command = input.key?("command") has_commands = input.key?("commands") if has_command && has_commands {error: "Provide either 'command' or 'commands', not both"} elsif has_commands execute_batch(input["commands"], mode: input.fetch("mode", "sequential"), timeout: timeout) elsif has_command execute_single(input["command"], timeout: timeout) else {error: "Either 'command' (string) or 'commands' (array of strings) is required"} end end |