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
Methods inherited from Base
prompt_guidelines, schema
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
22
|
# File 'lib/tools/read.rb', line 22
def self.description = "Read file. Relative paths resolve against working directory."
|
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"},
offset: {type: "integer", description: "1-indexed line number (default: 1)."},
limit: {type: "integer", description: "Max lines to return."}
},
required: ["path"]
}
end
|
.prompt_snippet ⇒ Object
24
|
# File 'lib/tools/read.rb', line 24
def self.prompt_snippet = "Read a file."
|
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
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/tools/read.rb', line 46
def execute(input)
path, offset, limit = (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
|