Class: Legion::CLI::Chat::Tools::SearchFiles

Inherits:
Tools::Base
  • Object
show all
Defined in:
lib/legion/cli/chat/tools/search_files.rb

Class Method Summary collapse

Methods inherited from Tools::Base

deferred, deferred?, description, error_response, extension, handle_exception, input_schema, log, mcp_category, mcp_tier, runner, sticky, tags, text_response, tool_name, trigger_words

Class Method Details

.call(pattern:, directory: nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/legion/cli/chat/tools/search_files.rb', line 21

def self.call(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