Class: WritersRoom::ReadFileTool

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

Overview

LLM tool that reads file contents within the project directory.

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
# File 'lib/writers_room/tools/read_file_tool.rb', line 14

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

  return "File not found: #{path}" unless File.exist?(full_path)
  return "Not a file: #{path}" unless File.file?(full_path)

  File.read(full_path)
rescue RuntimeError => e
  e.message
rescue StandardError => e
  "Error reading file: #{e.message}"
end