Class: Brute::Providers::Shell

Inherits:
Object
  • Object
show all
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

Instance Method Details

#assistant_roleObject



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_modelObject



35
# File 'lib/brute/providers/shell.rb', line 35

def default_model  = "bash"

#modelsObject

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

#nameObject

── LLM::Provider duck-type interface ──────────────────────────



34
# File 'lib/brute/providers/shell.rb', line 34

def name           = :shell

#system_roleObject



39
# File 'lib/brute/providers/shell.rb', line 39

def system_role    = :system

#tool_roleObject



37
# File 'lib/brute/providers/shell.rb', line 37

def tool_role      = :tool

#tracerObject



40
# File 'lib/brute/providers/shell.rb', line 40

def tracer         = LLM::Tracer::Null.new(self)

#user_roleObject



36
# File 'lib/brute/providers/shell.rb', line 36

def user_role      = :user