Class: AgentsSkillVault::SkillScanner

Inherits:
Object
  • Object
show all
Defined in:
lib/agents_skill_vault/skill_scanner.rb

Overview

Scans directories for SKILL.md files.

Recursively searches for SKILL.md files and extracts metadata including the skill name and folder path.

Examples:

Scan a directory for skills

skills = SkillScanner.scan_directory("/path/to/repo")
skills.each do |skill|
  puts "Found skill: #{skill[:skill_name]} at #{skill[:relative_path]}"
end

Constant Summary collapse

SKILL_FILE_NAME =
"SKILL.md"

Class Method Summary collapse

Class Method Details

.extract_skill_metadata(skill_file_path, base_path) ⇒ Hash

Extracts skill metadata from a SKILL.md file path.

Parameters:

  • skill_file_path (String)

    Full path to SKILL.md file

  • base_path (String)

    Base path for calculating relative paths

Returns:

  • (Hash)

    Skill metadata



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/agents_skill_vault/skill_scanner.rb', line 61

def self.(skill_file_path, base_path)
  skill_dir = File.dirname(skill_file_path)
  skill_name = File.basename(skill_dir)
  relative_path = Pathname.new(skill_dir).relative_path_from(Pathname.new(base_path)).to_s

  {
    relative_path:,
    skill_folder: relative_path,
    skill_name:,
    folder_path: relative_path
  }
end

.scan_directory(base_path) ⇒ Array<Hash>

Scans a directory for all SKILL.md files.

Parameters:

  • base_path (String)

    The base directory to scan

Returns:

  • (Array<Hash>)

    Array of skill metadata with keys:

    • :relative_path [String] Path relative to base_path
    • :skill_folder [String] Full folder path containing SKILL.md
    • :skill_name [String] The name of the skill (parent folder name)
    • :folder_path [String] Alias for skill_folder

Raises:

  • (ArgumentError)

    if base_path is nil or doesn't exist



29
30
31
32
33
34
35
36
# File 'lib/agents_skill_vault/skill_scanner.rb', line 29

def self.scan_directory(base_path)
  raise ArgumentError, "base_path cannot be nil" if base_path.nil?
  raise ArgumentError, "base_path does not exist: #{base_path}" unless Dir.exist?(base_path)

  skills = []
  scan_recursive(base_path, base_path, skills)
  skills
end

.scan_recursive(current_dir, base_path, skills) ⇒ Object

Recursively scans directory for SKILL.md files.

Parameters:

  • current_dir (String)

    Current directory being scanned

  • base_path (String)

    Original base path for relative path calculation

  • skills (Array)

    Array to collect found skills



44
45
46
47
48
49
50
51
52
53
# File 'lib/agents_skill_vault/skill_scanner.rb', line 44

def self.scan_recursive(current_dir, base_path, skills)
  # Check if current directory has a SKILL.md file
  skill_file = File.join(current_dir, SKILL_FILE_NAME)
  skills << (skill_file, base_path) if File.exist?(skill_file)

  # Scan subdirectories
  Dir.glob(File.join(current_dir, "*")).each do |entry|
    scan_recursive(entry, base_path, skills) if File.directory?(entry)
  end
end