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
-
.anthropic_definition ⇒ Hash
Anthropic-compatible tool definition.
-
.call(path: ".") ⇒ String
Execute the tool.
-
.definition ⇒ Hash
OpenAI-compatible tool definition.
Class Method Details
.anthropic_definition ⇒ Hash
Returns 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.
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: ".") = File.(path) return "Error: Directory not found: #{path}" unless Dir.exist?() entries = Dir.entries().sort - [".", ".."] entries.map do |entry| full_path = File.join(, entry) File.directory?(full_path) ? "#{entry}/" : entry end.join("\n") rescue => e "Error listing directory: #{e.}" end |