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: ‘Anima::Settings.max_read_lines` lines or `Anima::Settings.max_read_bytes` bytes, whichever hits first. When truncated, appends a continuation hint with the next offset value so the agent can page through large files.
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.
37 38 39 |
# File 'lib/tools/read.rb', line 37 def initialize(shell_session: nil, **) @working_directory = shell_session&.pwd end |
Class Method Details
.description ⇒ Object
22 |
# File 'lib/tools/read.rb', line 22 def self.description = "Read file. Relative paths resolve against working directory." |
.input_schema ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/tools/read.rb', line 24 def self.input_schema { type: "object", properties: { path: {type: "string"}, offset: {type: "integer", description: "1-indexed line number (default: 1)."}, limit: {type: "integer", description: "Max lines to return."} }, required: ["path"] } end |
.tool_name ⇒ Object
19 |
# File 'lib/tools/read.rb', line 19 def self.tool_name = "read_file" |
.truncation_threshold ⇒ Object
20 |
# File 'lib/tools/read.rb', line 20 def self.truncation_threshold = nil |
Instance Method Details
#execute(input) ⇒ String, Hash
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/tools/read.rb', line 44 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 |