Class: Brute::Tools::FSRead

Inherits:
LLM::Tool
  • Object
show all
Defined in:
lib/brute/tools/fs_read.rb

Instance Method Summary collapse

Instance Method Details

#call(file_path:, start_line: nil, end_line: nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/brute/tools/fs_read.rb', line 19

def call(file_path:, start_line: nil, end_line: nil)
  path = File.expand_path(file_path)
  raise "File not found: #{path}" unless File.exist?(path)
  raise "Not a file: #{path}" unless File.file?(path)

  lines = File.readlines(path)
  first = start_line ? [start_line - 1, 0].max : 0
  last = end_line ? [end_line - 1, lines.size - 1].min : lines.size - 1

  selected = lines[first..last] || []
  numbered = selected.each_with_index.map do |line, i|
    "#{first + i + 1}\t#{line}"
  end

  {
    file_path: path,
    total_lines: lines.size,
    showing: "#{first + 1}-#{last + 1}",
    content: numbered.join,
  }
end