Class: RubyLLM::Toolbox::Tools::GitDiff

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

Overview

SAFE. Shows a unified diff of the repo at fs_root. Read-only.

External diff drivers and textconv filters are disabled so a malicious repo can’t turn a diff into command execution.

Constant Summary

Constants included from GitHelpers

RubyLLM::Toolbox::Tools::GitHelpers::GIT_ENV, RubyLLM::Toolbox::Tools::GitHelpers::REF_RE

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods included from GitHelpers

#git_result, #repo_relative, #run_git, #valid_ref?

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(staged: false, path: nil, ref: nil) ⇒ Object



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

def execute(staged: false, path: nil, ref: nil)
  return error("invalid ref: #{ref.inspect}", code: :bad_ref) if ref && !valid_ref?(ref)

  rel = repo_relative(path)
  args = ["diff", "--no-ext-diff", "--no-textconv", "--stat", "--patch"]
  args << "--cached" if staged
  args << ref if ref
  args += ["--", rel] if rel

  out, err, status = run_git(*args)
  result = git_result(out, err, status)
  return result if result.is_a?(Hash)

  truncate(result.strip.empty? ? "no changes" : result)
rescue Safety::PathJail::Jailbreak => e
  error(e.message, code: :path_denied)
end