15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/legion/cli/chat/tools/search_files.rb', line 15
def execute(pattern:, directory: nil)
dir = File.expand_path(directory || Dir.pwd)
return "Error: directory not found: #{dir}" unless Dir.exist?(dir)
matches = Dir.glob(File.join(dir, pattern))
return "No files matching #{pattern} in #{dir}" if matches.empty?
relative = matches.map { |f| f.sub("#{dir}/", '') }
"#{relative.length} files matching #{pattern}:\n#{relative.join("\n")}"
rescue StandardError => e
Legion::Logging.warn("SearchFiles#execute failed for pattern #{pattern}: #{e.message}") if defined?(Legion::Logging)
"Error searching: #{e.message}"
end
|