Class: Aiko::Tools::ReadFile
- Inherits:
-
Base
- Object
- Base
- Aiko::Tools::ReadFile
show all
- Defined in:
- lib/aiko/tools/read_file.rb
Constant Summary
Constants inherited
from Base
Base::OUTPUT_LIMIT
Instance Method Summary
collapse
Methods inherited from Base
#approval_message, #initialize, #requires_approval?
Instance Method Details
#call(arguments) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/aiko/tools/read_file.rb', line 28
def call(arguments)
path = resolve_path(arguments.fetch("path"))
return "Error: no such file: #{arguments["path"]}" unless File.exist?(path)
return "Error: is a directory: #{arguments["path"]}" if File.directory?(path)
return "Error: binary file: #{arguments["path"]}" if binary?(path)
numbered = File.read(path).each_line.with_index(1).map do |line, i|
format("%d: %s", i, line)
end.join
truncate(numbered)
end
|
#description ⇒ Object
10
11
12
13
|
# File 'lib/aiko/tools/read_file.rb', line 10
def description
"Read the contents of a text file. Returns the content with line numbers " \
"(e.g. \"1: ...\"). Use this before editing a file."
end
|
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/aiko/tools/read_file.rb', line 15
def input_schema
{
"type" => "object",
"properties" => {
"path" => {
"type" => "string",
"description" => "File path relative to the working directory"
}
},
"required" => ["path"]
}
end
|
#name ⇒ Object
6
7
8
|
# File 'lib/aiko/tools/read_file.rb', line 6
def name
"read_file"
end
|