Class: WritersRoom::ListDirectoryTool

Inherits:
ProjectTool
  • Object
show all
Defined in:
lib/writers_room/tools/list_directory_tool.rb

Overview

LLM tool that lists files and subdirectories within the project.

Instance Attribute Summary

Attributes inherited from ProjectTool

#project_path

Instance Method Summary collapse

Methods inherited from ProjectTool

#initialize

Constructor Details

This class inherits a constructor from WritersRoom::ProjectTool

Instance Method Details

#execute(path: ".") ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/writers_room/tools/list_directory_tool.rb', line 14

def execute(path: ".")
  full_path = resolve_path(path)

  return "Directory not found: #{path}" unless Dir.exist?(full_path)

  entries = Dir.children(full_path).sort.map { |name|
    entry_path = File.join(full_path, name)
    if File.directory?(entry_path)
      "[dir]  #{name}/"
    else
      "[file] #{name} (#{File.size(entry_path)} bytes)"
    end
  }

  if entries.empty?
    "Directory '#{path}' is empty."
  else
    entries.join("\n")
  end
rescue RuntimeError => e
  e.message
rescue StandardError => e
  "Error listing directory: #{e.message}"
end