Class: RubyLLM::Toolbox::Tools::Bundle

Inherits:
Base
  • Object
show all
Includes:
ToolchainHelpers
Defined in:
lib/ruby_llm/toolbox/tools/bundle.rb

Overview

EXEC. Runs Bundler operations in the project at fs_root. The mutating sibling of the read-only ‘gem` tool. install/update/add reach the network and change the project’s gems, so this is exec-gated.

Constant Summary collapse

ACTIONS =
%w[install update outdated check lock add].freeze
NAME_RE =
/\A[A-Za-z0-9_.-]+\z/

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods included from ToolchainHelpers

#gemfile?, #jail_relative, #run_in_project, #toolchain_output

Methods inherited from Base

#call, exec_tool!, exec_tool?, #initialize, #name

Constructor Details

This class inherits a constructor from RubyLLM::Toolbox::Base

Instance Method Details

#execute(action:, gem: nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ruby_llm/toolbox/tools/bundle.rb', line 30

def execute(action:, gem: nil)
  act = action.to_s.strip.downcase
  return error("unknown action: #{act} (use #{ACTIONS.join(', ')})", code: :bad_action) unless ACTIONS.include?(act)
  return error("a Gemfile is required (none at fs_root)", code: :no_gemfile) unless gemfile?

  args = build_args(act, gem)
  return args if args.is_a?(Hash) # validation error

  out, err, status = run_in_project(args, use_bundle: false)
  toolchain_output(out, err, status,
                   pass_label: "bundle #{act}: ok",
                   fail_label: "bundle #{act}: failed")
rescue CommandMissing
  error("bundler is not available (gem install bundler)", code: :unavailable)
end