Class: Rubino::Tools::GlobTool
- Inherits:
-
Base
- Object
- Base
- Rubino::Tools::GlobTool
show all
- Defined in:
- lib/rubino/tools/glob_tool.rb
Overview
Tool for finding files by glob patterns. Returns matching file paths sorted by modification time.
Instance Attribute Summary
Attributes inherited from Base
#cancel_token, #read_tracker, #stream_chunk
Instance Method Summary
collapse
Methods inherited from Base
#cancellation_requested?, #config_key, #emit_chunk, #risky?, #to_tool_definition, workspace_root, workspace_roots
Instance Method Details
#call(arguments) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/rubino/tools/glob_tool.rb', line 42
def call(arguments)
pattern = arguments["pattern"] || arguments[:pattern]
path = arguments["path"] || arguments[:path] || "."
max_results = arguments["max_results"] || arguments[:max_results] || 100
expanded_path = File.expand_path(path)
return "Error: Directory not found: #{path}" unless File.directory?(expanded_path)
full_pattern = File.join(expanded_path, pattern)
files = Dir.glob(full_pattern)
.select { |f| File.file?(f) }
.sort_by { |f| -File.mtime(f).to_i }
.first(max_results)
if files.empty?
"No files matched pattern: #{pattern}"
else
relative_files = files.map { |f| f.sub("#{expanded_path}/", "") }
full = "#{relative_files.size} file(s) found:\n\n#{relative_files.join("\n")}"
{ output: full,
metrics: "#{relative_files.size} file#{"s" if relative_files.size != 1}",
body: Util::Output.preview(full),
body_kind: :plain }
end
end
|
#description ⇒ Object
12
13
14
15
|
# File 'lib/rubino/tools/glob_tool.rb', line 12
def description
"Find files by glob pattern (e.g., '**/*.rb', 'src/**/*.ts'). " \
"Returns matching file paths sorted by modification time."
end
|
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/rubino/tools/glob_tool.rb', line 17
def input_schema
{
type: "object",
properties: {
pattern: {
type: "string",
description: "The glob pattern to match files against (e.g., '**/*.rb')"
},
path: {
type: "string",
description: "Base directory to search in (defaults to current directory)"
},
max_results: {
type: "integer",
description: "Maximum number of results (default: 100)"
}
},
required: %w[pattern]
}
end
|
#name ⇒ Object
8
9
10
|
# File 'lib/rubino/tools/glob_tool.rb', line 8
def name
"glob"
end
|
#risk_level ⇒ Object
38
39
40
|
# File 'lib/rubino/tools/glob_tool.rb', line 38
def risk_level
:low
end
|