Class: RubyLLM::Toolbox::Tools::Tree
- Defined in:
- lib/ruby_llm/toolbox/tools/tree.rb
Overview
SAFE. Renders a depth-limited directory tree under fs_root — a quick way to see project structure without walking it one level at a time with list_directory. Read-only; ignored directories are skipped, symlinks are not followed, and the listing is capped.
Constant Summary collapse
- DEFAULT_DEPTH =
3- MAX_ENTRIES =
500
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: nil, max_depth: DEFAULT_DEPTH, show_hidden: false) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ruby_llm/toolbox/tools/tree.rb', line 31 def execute(path: nil, max_depth: DEFAULT_DEPTH, show_hidden: false) jail = Safety::PathJail.new(config.fs_root) root = jail.resolve(path.to_s.empty? ? "." : path) return error("not a directory: #{path || '.'}", code: :not_a_directory) unless File.directory?(root) depth = max_depth.to_i depth = DEFAULT_DEPTH if depth <= 0 @count = 0 @truncated = false lines = ["#{File.basename(root)}/"] walk(root, depth, show_hidden, "", lines) lines << "... (truncated at #{MAX_ENTRIES} entries)" if @truncated truncate(lines.join("\n")) rescue Safety::PathJail::Jailbreak => e error(e., code: :path_denied) end |