Module: Crimson::Tools::Glob
- Defined in:
- lib/crimson/tools/glob.rb
Overview
Find files matching a glob pattern with configurable search root.
Constant Summary collapse
- TOOL_NAME =
"glob"- PARAMS =
Tool parameter definitions.
{ pattern: { type: "string", description: "The glob pattern to match files against" }, path: { type: "string", description: "The directory to search in. Defaults to current directory." } }.freeze
Class Method Summary collapse
-
.anthropic_definition ⇒ Hash
Anthropic-compatible tool definition.
-
.call(pattern:, path: ".") ⇒ String
Execute the tool.
-
.definition ⇒ Hash
OpenAI-compatible tool definition.
Class Method Details
.anthropic_definition ⇒ Hash
Returns Anthropic-compatible tool definition.
21 22 23 |
# File 'lib/crimson/tools/glob.rb', line 21 def self.anthropic_definition Schema.build_anthropic(name: TOOL_NAME, description: "Find files matching a glob pattern (e.g. '**/*.rb', 'src/**/*.ts'). Returns sorted file paths.", parameters: PARAMS, required: ["pattern"]) end |
.call(pattern:, path: ".") ⇒ String
Execute the tool.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/crimson/tools/glob.rb', line 29 def self.call(pattern:, path: ".") return "Error: No pattern provided" if pattern.nil? || pattern.strip.empty? = File.(path) return "Error: Directory not found: #{path}" unless Dir.exist?() files = Dir.glob(File.join(, pattern)).sort if files.empty? "No files found matching pattern: #{pattern}" elsif files.length > 200 "#{files.first(200).join("\n")}\n... (truncated, #{files.length - 200} more files)" else files.join("\n") end rescue => e "Error searching files: #{e.}" end |
.definition ⇒ Hash
Returns OpenAI-compatible tool definition.
16 17 18 |
# File 'lib/crimson/tools/glob.rb', line 16 def self.definition Schema.build(name: TOOL_NAME, description: "Find files matching a glob pattern (e.g. '**/*.rb', 'src/**/*.ts'). Returns sorted file paths.", parameters: PARAMS, required: ["pattern"]) end |