Module: Crimson::Tools::ListDirectory

Defined in:
lib/crimson/tools/list_directory.rb

Overview

List files and directories at a given path, with trailing / for directories.

Constant Summary collapse

TOOL_NAME =
"list_directory"
PARAMS =

Tool parameter definitions.

{
  path: { type: "string", description: "The directory path to list. 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



20
21
22
# File 'lib/crimson/tools/list_directory.rb', line 20

def self.anthropic_definition
  Schema.build_anthropic(name: TOOL_NAME, description: "List files and directories at the given path.", parameters: PARAMS, required: ["path"])
end

.call(path: ".") ⇒ String

Execute the tool.

Parameters:

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

    directory path (defaults to “.”)

Returns:

  • (String)

    sorted listing or error



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/crimson/tools/list_directory.rb', line 27

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

  entries = Dir.entries(expanded).sort - [".", ".."]

  entries.map do |entry|
    full_path = File.join(expanded, entry)
    File.directory?(full_path) ? "#{entry}/" : entry
  end.join("\n")
rescue => e
  "Error listing directory: #{e.message}"
end

.definitionHash

Returns OpenAI-compatible tool definition.

Returns:

  • (Hash)

    OpenAI-compatible tool definition



15
16
17
# File 'lib/crimson/tools/list_directory.rb', line 15

def self.definition
  Schema.build(name: TOOL_NAME, description: "List files and directories at the given path.", parameters: PARAMS, required: ["path"])
end