Class: Nanobot::Agent::Tools::ReadFile
- Inherits:
-
RubyLLM::Tool
- Object
- RubyLLM::Tool
- Nanobot::Agent::Tools::ReadFile
- Includes:
- WorkspaceSandbox
- Defined in:
- lib/nanobot/agent/tools/filesystem.rb
Overview
Tool for reading file contents
Constant Summary
Constants included from WorkspaceSandbox
WorkspaceSandbox::PROTECTED_FILENAMES
Instance Method Summary collapse
-
#execute(path:) ⇒ String
Read file contents from the given path.
-
#initialize(allowed_dir: nil) ⇒ ReadFile
constructor
A new instance of ReadFile.
Constructor Details
#initialize(allowed_dir: nil) ⇒ ReadFile
Returns a new instance of ReadFile.
74 75 76 77 |
# File 'lib/nanobot/agent/tools/filesystem.rb', line 74 def initialize(allowed_dir: nil) super() @allowed_dir = allowed_dir ? Pathname.new(allowed_dir). : nil end |
Instance Method Details
#execute(path:) ⇒ String
Read file contents from the given path.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/nanobot/agent/tools/filesystem.rb', line 82 def execute(path:) file_path = Pathname.new(path). # Security check if @allowed_dir && !within_allowed_dir?(file_path) return "Error: Access denied. Path is outside allowed directory: #{@allowed_dir}" end return "Error: File not found: #{path}" unless file_path.exist? return "Error: Path is not a file: #{path}" unless file_path.file? begin file_path.read rescue StandardError => e "Error reading file: #{e.}" end end |