Class: Yorishiro::Tools::ListFiles

Inherits:
Yorishiro::Tool show all
Defined in:
lib/yorishiro/tools/list_files.rb

Instance Method Summary collapse

Methods inherited from Yorishiro::Tool

#configure, #definition, #permission_check, #preview

Instance Method Details

#descriptionObject



14
15
16
# File 'lib/yorishiro/tools/list_files.rb', line 14

def description
  "List files in a directory. Optionally filter with a glob pattern."
end

#execute(**params) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/yorishiro/tools/list_files.rb', line 29

def execute(**params)
  path = params[:path] || params["path"] || "."
  pattern = params[:pattern] || params["pattern"]

  raise "Directory not found: #{path}" unless Dir.exist?(path)

  entries = if pattern
              # Glob results already carry the path prefix.
              Dir.glob(File.join(path, pattern)).map { |f| [f, f] }
            else
              # Dir.children returns bare names — resolve them against
              # +path+, not the process cwd, when checking for directories.
              Dir.children(path).sort.map { |name| [name, File.join(path, name)] }
            end

  entries.map { |display, full| File.directory?(full) ? "#{display}/" : display }.join("\n")
end

#nameObject



10
11
12
# File 'lib/yorishiro/tools/list_files.rb', line 10

def name
  "list_files"
end

#parametersObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/yorishiro/tools/list_files.rb', line 18

def parameters
  {
    type: "object",
    properties: {
      path: { type: "string", description: "The directory path to list (default: current directory)" },
      pattern: { type: "string", description: "Glob pattern to filter files (e.g., '**/*.rb')" }
    },
    required: []
  }
end

#read_only?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/yorishiro/tools/list_files.rb', line 6

def read_only?
  true
end