Class: Yorishiro::Tools::ReadFile
Constant Summary
collapse
- MAX_LINES =
Cap how much of a file one call can return. Small local-model
context windows (e.g. Ollama with num_ctx 8192) are exhausted by a
single whole-file dump, so large files must be paged instead.
200
- MAX_LINE_LENGTH =
500
Instance Method Summary
collapse
#configure, #definition, #permission_check, #preview
Instance Method Details
#description ⇒ Object
20
21
22
23
|
# File 'lib/yorishiro/tools/read_file.rb', line 20
def description
"Read the contents of a file at the specified path. Returns at most #{MAX_LINES} lines per call; " \
"use offset and limit to page through larger files."
end
|
#execute(**params) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/yorishiro/tools/read_file.rb', line 37
def execute(**params)
path = params[:path] || params["path"]
offset = (params[:offset] || params["offset"]).to_i
limit = (params[:limit] || params["limit"])&.to_i
limit = limit.nil? ? MAX_LINES : [limit, MAX_LINES].min
raise "File not found: #{path}" unless File.exist?(path)
raise "Not a file: #{path}" unless File.file?(path)
lines = File.readlines(path)
selected = lines[offset, limit] || []
output = selected.each_with_index.map { |line, i| "#{offset + i + 1}: #{truncate_line(line)}" }.join
output + paging_notice(lines.length, offset, selected.length)
end
|
#name ⇒ Object
16
17
18
|
# File 'lib/yorishiro/tools/read_file.rb', line 16
def name
"read_file"
end
|
#parameters ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/yorishiro/tools/read_file.rb', line 25
def parameters
{
type: "object",
properties: {
path: { type: "string", description: "The file path to read" },
offset: { type: "integer", description: "Line number to start reading from (0-based)" },
limit: { type: "integer", description: "Maximum number of lines to read (capped at #{MAX_LINES})" }
},
required: ["path"]
}
end
|
#read_only? ⇒ Boolean
12
13
14
|
# File 'lib/yorishiro/tools/read_file.rb', line 12
def read_only?
true
end
|