Class: Brute::Tools::FSSearch

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

Constant Summary collapse

MAX_OUTPUT =
40_000

Instance Method Summary collapse

Instance Method Details

#call(pattern:, path: nil, glob: nil, ignore_case: false) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/brute/tools/fs_search.rb', line 24

def call(pattern:, path: nil, glob: nil, ignore_case: false)
  dir = File.expand_path(path || Dir.pwd)
  raise "Directory not found: #{dir}" unless File.directory?(dir)

  cmd = ["rg", "--line-number", "--max-count=100", "--max-columns=200"]
  cmd << "--ignore-case" if ignore_case
  cmd += ["--glob", glob] if glob
  cmd << pattern
  cmd << dir

  stdout, stderr, status = Open3.capture3(*cmd)

  output = stdout.empty? ? stderr : stdout
  output = output[0...MAX_OUTPUT] + "\n...(truncated)" if output.size > MAX_OUTPUT

  {results: output, exit_code: status.exitstatus, truncated: output.size > MAX_OUTPUT}
end