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 agent loop 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

#complete(prompt, params = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/brute/providers/shell.rb', line 37

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 agent loop 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?)



53
54
55
# File 'lib/brute/providers/shell.rb', line 53

def models
  ModelList.new(MODELS)
end

#nameObject

── Provider interface ─────────────────────────────────────────



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

def name           = :shell