Class: Girb::Tools::ReadFile
- Inherits:
-
Base
- Object
- Base
- Girb::Tools::ReadFile
show all
- Defined in:
- lib/girb/tools/read_file.rb
Constant Summary
collapse
- MAX_FILE_SIZE =
100_000
- MAX_LINES =
500
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
available?, to_gemini_tool, tool_name
Class Method Details
.description ⇒ Object
12
13
14
15
16
|
# File 'lib/girb/tools/read_file.rb', line 12
def description
"Read source code from a file in the application. " \
"Can read models, controllers, views, configs, or any Ruby/text file. " \
"Optionally specify line range to read specific sections."
end
|
.parameters ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/girb/tools/read_file.rb', line 18
def parameters
{
type: "object",
properties: {
path: {
type: "string",
description: "File path (relative to app root or absolute). Examples: 'app/models/user.rb', 'config/routes.rb'"
},
start_line: {
type: "integer",
description: "Start line number (1-indexed, optional)"
},
end_line: {
type: "integer",
description: "End line number (1-indexed, optional)"
}
},
required: ["path"]
}
end
|
Instance Method Details
#execute(binding, path:, start_line: nil, end_line: nil) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/girb/tools/read_file.rb', line 40
def execute(binding, path:, start_line: nil, end_line: nil)
full_path = resolve_path(path)
unless File.exist?(full_path)
return { error: "File not found: #{path}", searched_path: full_path }
end
unless File.readable?(full_path)
return { error: "File not readable: #{path}" }
end
if File.size(full_path) > MAX_FILE_SIZE
return { error: "File too large (max #{MAX_FILE_SIZE / 1000}KB): #{path}" }
end
read_file_content(full_path, path, start_line, end_line)
rescue StandardError => e
{ error: "#{e.class}: #{e.message}" }
end
|