Class: RubyLLM::Toolbox::Tools::GitBlame

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

Overview

SAFE. Shows line-by-line authorship (commit, author, date) for a file in the repo at fs_root. Read-only.

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(path:, start_line: nil, end_line: nil) ⇒ Object



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

def execute(path:, start_line: nil, end_line: nil)
  rel = repo_relative(path)
  return error("path must be provided", code: :bad_path) if rel.nil?

  args = ["blame", "--date=short"]
  if (range = line_range(start_line, end_line))
    args += ["-L", range]
  end
  args += ["--", 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 blame output (empty file?)" : result)
rescue Safety::PathJail::Jailbreak => e
  error(e.message, code: :path_denied)
end