Class: Tools::Read
Overview
Reads file contents with smart truncation and offset/limit paging. Returns plain text without line numbers, normalized to LF line endings.
Truncation limits: ‘MAX_LINES` lines or `MAX_BYTES` bytes, whichever hits first. When truncated, appends a continuation hint with the next offset value so the agent can page through large files.
Constant Summary collapse
- MAX_LINES =
2_000- MAX_BYTES =
50_000
Class Method Summary collapse
Instance Method Summary collapse
- #execute(input) ⇒ String, Hash
-
#initialize(shell_session: nil) ⇒ Read
constructor
A new instance of Read.
Methods inherited from Base
Constructor Details
#initialize(shell_session: nil) ⇒ Read
Returns a new instance of Read.
39 40 41 |
# File 'lib/tools/read.rb', line 39 def initialize(shell_session: nil, **) @working_directory = shell_session&.pwd end |
Class Method Details
.description ⇒ Object
24 |
# File 'lib/tools/read.rb', line 24 def self.description = "Read file contents. Returns plain text with smart truncation. Use offset/limit to page through large files." |
.input_schema ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/tools/read.rb', line 26 def self.input_schema { type: "object", properties: { path: {type: "string", description: "Absolute or relative file path (relative resolved against working directory)"}, offset: {type: "integer", description: "1-indexed line number to start from (default: 1)"}, limit: {type: "integer", description: "Maximum number of lines to read (default: 2000, also limited by #{MAX_BYTES} byte cap)"} }, required: ["path"] } end |
.tool_name ⇒ Object
22 |
# File 'lib/tools/read.rb', line 22 def self.tool_name = "read" |
Instance Method Details
#execute(input) ⇒ String, Hash
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/tools/read.rb', line 46 def execute(input) path, offset, limit = extract_params(input) return {error: "Path cannot be blank"} if path.empty? path = resolve_path(path) error = validate_file(path) return error if error read_file(path, offset, limit) end |