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

Class Method Details

.anthropic_definitionHash

Returns Anthropic-compatible tool definition.

Returns:

  • (Hash)

    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.

Parameters:

  • pattern (String)

    glob pattern

  • path (String) (defaults to: ".")

    search root (default “.”)

Returns:

  • (String)

    sorted file paths or error



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?

  expanded = File.expand_path(path)
  return "Error: Directory not found: #{path}" unless Dir.exist?(expanded)

  files = Dir.glob(File.join(expanded, 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.message}"
end

.definitionHash

Returns OpenAI-compatible tool definition.

Returns:

  • (Hash)

    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