Class: SwarmSDK::V3::Tools::Glob
- Defined in:
- lib/swarm_sdk/v3/tools/glob.rb
Overview
Glob tool for fast file pattern matching
Finds files and directories matching glob patterns, sorted by modification time.
Class Method Summary collapse
-
.creation_requirements ⇒ Array<Symbol>
Constructor requirements.
Instance Method Summary collapse
-
#execute(pattern:, path: nil) ⇒ String
Execute glob search.
-
#initialize(directory:) ⇒ Glob
constructor
A new instance of Glob.
Methods inherited from Base
Constructor Details
#initialize(directory:) ⇒ Glob
Returns a new instance of Glob.
35 36 37 38 |
# File 'lib/swarm_sdk/v3/tools/glob.rb', line 35 def initialize(directory:) super() @directory = File.(directory) end |
Class Method Details
.creation_requirements ⇒ Array<Symbol>
Returns Constructor requirements.
12 13 14 |
# File 'lib/swarm_sdk/v3/tools/glob.rb', line 12 def creation_requirements [:directory] end |
Instance Method Details
#execute(pattern:, path: nil) ⇒ String
Execute glob search
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/swarm_sdk/v3/tools/glob.rb', line 45 def execute(pattern:, path: nil) return validation_error("pattern is required") if pattern.nil? || pattern.to_s.strip.empty? search_path = resolve_search_path(path) return search_path if search_path.start_with?("<tool_use_error>") full_pattern = pattern.start_with?("/") ? pattern : File.join(search_path, pattern) matches = Dir.glob(full_pattern, File::FNM_DOTMATCH) matches.reject! do |f| basename = File.basename(f.chomp("/")) basename == "." || basename == ".." end return "No matches found for pattern: #{pattern}" if matches.empty? matches.sort_by! { |f| -File.mtime(f).to_i } max_results = Configuration.instance.glob_result_limit truncated = matches.count > max_results matches = matches.take(max_results) if truncated output = matches.join("\n") output += "\n\n<system-reminder>Results limited to first #{max_results} matches.</system-reminder>" if truncated output rescue Errno::EACCES => e error("Permission denied: #{e.}") rescue StandardError => e error("Failed to execute glob: #{e.class.name} - #{e.}") end |