Class: Zephira::Tools::ListDirectory
- Inherits:
-
BaseTool
- Object
- BaseTool
- Zephira::Tools::ListDirectory
show all
- Defined in:
- lib/zephira/tools/list_directory.rb
Instance Attribute Summary
Attributes inherited from BaseTool
#agent, #args
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from BaseTool
announces_intent?, #arg, #error_result, #initialize, run, #success_result, #validate
Class Method Details
.description ⇒ Object
11
12
13
|
# File 'lib/zephira/tools/list_directory.rb', line 11
def description
"List the contents of a directory."
end
|
.name ⇒ Object
7
8
9
|
# File 'lib/zephira/tools/list_directory.rb', line 7
def name
"list_directory"
end
|
.parameters ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/zephira/tools/list_directory.rb', line 19
def parameters
{
type: "object",
properties: {
intent: {
type: "string",
description: "Brief summary of intent of the operation, meant to be used for context compaction and presentation to the user. Use active voice (e.g., 'Reading X to do Y')."
},
directory_path: {
type: "string",
description: "Path to the directory to list"
}
},
required: ["directory_path", "intent"]
}
end
|
.read_only? ⇒ Boolean
15
16
17
|
# File 'lib/zephira/tools/list_directory.rb', line 15
def read_only?
true
end
|
Instance Method Details
#run ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/zephira/tools/list_directory.rb', line 37
def run
dir_path = arg(:directory_path)
if dir_path.nil? || dir_path.strip.empty?
return error_result(message: "`directory_path` was empty or missing")
end
agent.status.verbose(" • Listing directory contents: '#{dir_path}'")
expanded_path = ::File.expand_path(dir_path)
entries = Dir.children(expanded_path)
agent.status.verbose(" • Directory contents listed: #{entries.size} entries in '#{dir_path}'")
agent.logger.info("Listing directory contents: '#{dir_path}'")
success_result(entries)
rescue Errno::ENOENT
error_result(message: "Directory not found: '#{dir_path}'")
rescue Errno::EACCES
error_result(message: "Permission denied: #{dir_path}")
end
|