Class: Brute::Providers::Shell
- Inherits:
-
Object
- Object
- Brute::Providers::Shell
- Defined in:
- lib/brute/providers/shell.rb
Overview
A pseudo-LLM provider that executes user input as code via the existing Brute::Tools::Shell tool.
Models correspond to interpreters:
bash - pass-through (default)
ruby - ruby -e '...'
python - python3 -c '...'
nix - nix eval --expr '...'
The provider’s #complete method returns a synthetic response containing a single “shell” tool call. The orchestrator executes it through the normal pipeline — all middleware (message tracking, session persistence, token tracking, etc.) fires as usual.
Defined Under Namespace
Classes: ModelList
Constant Summary collapse
- MODELS =
%w[bash ruby python nix].freeze
- INTERPRETERS =
{ "bash" => ->(cmd) { cmd }, "ruby" => ->(cmd) { "ruby -e #{Shellwords.escape(cmd)}" }, "python" => ->(cmd) { "python3 -c #{Shellwords.escape(cmd)}" }, "nix" => ->(cmd) { "nix eval --expr #{Shellwords.escape(cmd)}" }, }.freeze
Instance Method Summary collapse
- #assistant_role ⇒ Object
- #complete(prompt, params = {}) ⇒ Object
- #default_model ⇒ Object
-
#models ⇒ Object
For the REPL model picker: provider.models.all.select(&:chat?).
-
#name ⇒ Object
── LLM::Provider duck-type interface ──────────────────────────.
- #system_role ⇒ Object
- #tool_role ⇒ Object
- #tracer ⇒ Object
- #user_role ⇒ Object
Instance Method Details
#assistant_role ⇒ Object
38 |
# File 'lib/brute/providers/shell.rb', line 38 def assistant_role = :assistant |
#complete(prompt, params = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/brute/providers/shell.rb', line 42 def complete(prompt, params = {}) model = params[:model]&.to_s || default_model text = extract_text(prompt) tools = params[:tools] || [] # nil text means we received tool results (second call) — # return an empty assistant response so the orchestrator exits. return ShellResponse.new(model: model, tools: tools) if text.nil? wrap = INTERPRETERS.fetch(model, INTERPRETERS["bash"]) command = wrap.call(text) ShellResponse.new(command: command, model: model, tools: tools) end |
#default_model ⇒ Object
35 |
# File 'lib/brute/providers/shell.rb', line 35 def default_model = "bash" |
#models ⇒ Object
For the REPL model picker: provider.models.all.select(&:chat?)
58 59 60 |
# File 'lib/brute/providers/shell.rb', line 58 def models ModelList.new(MODELS) end |
#name ⇒ Object
── LLM::Provider duck-type interface ──────────────────────────
34 |
# File 'lib/brute/providers/shell.rb', line 34 def name = :shell |
#system_role ⇒ Object
39 |
# File 'lib/brute/providers/shell.rb', line 39 def system_role = :system |
#tool_role ⇒ Object
37 |
# File 'lib/brute/providers/shell.rb', line 37 def tool_role = :tool |
#tracer ⇒ Object
40 |
# File 'lib/brute/providers/shell.rb', line 40 def tracer = LLM::Tracer::Null.new(self) |
#user_role ⇒ Object
36 |
# File 'lib/brute/providers/shell.rb', line 36 def user_role = :user |