Class: PromptObjects::Primitives::ListFiles
Overview
Primitive capability to list files in a directory.
Instance Attribute Summary
Attributes inherited from Capability
#state
Instance Method Summary
collapse
#initialize
Methods inherited from Capability
#descriptor, execution_policy, execution_policy_definition, #execution_policy_definition, #execution_policy_signature, #initialize, #resolved_execution_policy
Instance Method Details
#description ⇒ Object
13
14
15
|
# File 'lib/prompt_objects/primitives/list_files.rb', line 13
def description
"List files and directories in a given path"
end
|
#name ⇒ Object
9
10
11
|
# File 'lib/prompt_objects/primitives/list_files.rb', line 9
def name
"list_files"
end
|
#parameters ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/prompt_objects/primitives/list_files.rb', line 17
def parameters
{
type: "object",
properties: {
path: {
type: "string",
description: "The directory path to list (defaults to current directory)"
}
}
}
end
|
#receive(message, context:) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/prompt_objects/primitives/list_files.rb', line 29
def receive(message, context:)
path = (message)
path = "." if path.nil? || path.empty?
safe_path = File.expand_path(path)
unless File.exist?(safe_path)
return "Error: Path not found: #{path}"
end
unless File.directory?(safe_path)
return "Error: Not a directory: #{path}"
end
entries = Dir.entries(safe_path)
.reject { |e| e.start_with?(".") } .sort
.map { |entry| format_entry(safe_path, entry) }
if entries.empty?
"Directory is empty: #{path}"
else
entries.join("\n")
end
rescue Errno::EACCES
"Error: Permission denied: #{path}"
rescue StandardError => e
"Error listing directory: #{e.message}"
end
|