Class: RubynCode::Tools::ReadFile

Inherits:
Base
  • Object
show all
Defined in:
lib/rubyn_code/tools/read_file.rb

Constant Summary collapse

TOOL_NAME =
'read_file'
DESCRIPTION =
'Reads a file from the filesystem. Returns file content with line numbers prepended.'
PARAMETERS =
{
  path: { type: :string, required: true,
          description: 'Path to the file to read (relative to project root or absolute)' },
  offset: { type: :integer, required: false, description: 'Line number to start reading from (1-based)' },
  limit: { type: :integer, required: false, description: 'Number of lines to read' }
}.freeze
RISK_LEVEL =
:read
REQUIRES_CONFIRMATION =
false

Instance Attribute Summary

Attributes inherited from Base

#project_root

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

description, #initialize, parameters, requires_confirmation?, risk_level, #safe_path, to_schema, tool_name, #truncate

Constructor Details

This class inherits a constructor from RubynCode::Tools::Base

Class Method Details

.summarize(output, args) ⇒ Object



20
21
22
23
24
# File 'lib/rubyn_code/tools/read_file.rb', line 20

def self.summarize(output, args)
  path = args['path'] || args[:path] || ''
  line_count = output.to_s.lines.count
  "Read #{path} (#{line_count} lines)"
end

Instance Method Details

#execute(path:, offset: nil, limit: nil) ⇒ Object



26
27
28
29
30
31
# File 'lib/rubyn_code/tools/read_file.rb', line 26

def execute(path:, offset: nil, limit: nil)
  resolved = read_file_safely(path)
  lines = File.readlines(resolved)
  start_line, end_line = compute_range(offset, limit, lines.length)
  format_lines(lines[start_line...end_line] || [], start_line)
end