Class: RubyLLM::Toolbox::Tools::ListDirectory
- Defined in:
- lib/ruby_llm/toolbox/tools/list_directory.rb
Overview
SAFE. Lists the entries of a directory within fs_root, with type and size. Symlinked directories are listed but not traversed, so a link can’t be used to walk out of the jail.
Constant Summary collapse
- MAX_ENTRIES =
1_000
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#call, exec_tool!, exec_tool?, #initialize, #name
Constructor Details
This class inherits a constructor from RubyLLM::Toolbox::Base
Instance Method Details
#execute(path: ".", recursive: false, include_hidden: false) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ruby_llm/toolbox/tools/list_directory.rb', line 30 def execute(path: ".", recursive: false, include_hidden: false) jail = Safety::PathJail.new(config.fs_root) root = jail.resolve(path) return error("not a directory: #{path}", code: :not_a_directory) unless File.directory?(root) entries = collect(root, recursive: recursive, include_hidden: include_hidden) capped = entries.first(MAX_ENTRIES) body = +"#{entries.size} entr#{entries.size == 1 ? 'y' : 'ies'}" body << " (showing first #{MAX_ENTRIES}; narrow the path)" if entries.size > MAX_ENTRIES body << " in #{display(path)}:\n" capped.each { |line| body << line << "\n" } truncate(body) rescue Safety::PathJail::Jailbreak => e error(e., code: :path_denied) end |