Class: Aidp::Skills::Loader
- Inherits:
-
Object
- Object
- Aidp::Skills::Loader
- Defined in:
- lib/aidp/skills/loader.rb
Overview
Loads skills from SKILL.md files with YAML frontmatter
Parses skill files in the format:
---
id: skill_id
name: Skill Name
...
---
# Skill content in markdown
Class Method Summary collapse
-
.load_from_directory(directory, provider: nil) ⇒ Array<Skill>
Load all skills from a directory.
-
.load_from_file(file_path, provider: nil) ⇒ Skill?
Load a skill from a file path.
-
.load_from_string(content, source_path:, provider: nil) ⇒ Skill?
Load a skill from a string.
Class Method Details
.load_from_directory(directory, provider: nil) ⇒ Array<Skill>
Load all skills from a directory
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/aidp/skills/loader.rb', line 96 def self.load_from_directory(directory, provider: nil) Aidp.log_debug("skills", "Loading skills from directory", directory: directory, provider: provider) unless Dir.exist?(directory) Aidp.log_warn("skills", "Skills directory not found", directory: directory) return [] end skills = [] skill_dirs = Dir.glob(File.join(directory, "*")).select { |path| File.directory?(path) } skill_dirs.each do |skill_dir| skill_file = File.join(skill_dir, "SKILL.md") next unless File.exist?(skill_file) begin skill = load_from_file(skill_file, provider: provider) skills << skill if skill # nil if incompatible with provider rescue Aidp::Errors::ValidationError => e Aidp.log_warn( "skills", "Failed to load skill", file: skill_file, error: e. ) # Continue loading other skills even if one fails end end Aidp.log_info( "skills", "Loaded skills from directory", directory: directory, count: skills.size ) skills end |
.load_from_file(file_path, provider: nil) ⇒ Skill?
Load a skill from a file path
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/aidp/skills/loader.rb', line 30 def self.load_from_file(file_path, provider: nil) Aidp.log_debug("skills", "Loading skill from file", file: file_path, provider: provider) unless File.exist?(file_path) raise Aidp::Errors::ValidationError, "Skill file not found: #{file_path}" end content = File.read(file_path, encoding: "UTF-8") load_from_string(content, source_path: file_path, provider: provider) end |
.load_from_string(content, source_path:, provider: nil) ⇒ Skill?
Load a skill from a string
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/aidp/skills/loader.rb', line 48 def self.load_from_string(content, source_path:, provider: nil) , markdown = parse_frontmatter(content, source_path: source_path) skill = Skill.new( id: ["id"], name: ["name"], description: ["description"], version: ["version"], expertise: ["expertise"] || [], keywords: ["keywords"] || [], when_to_use: ["when_to_use"] || [], when_not_to_use: ["when_not_to_use"] || [], compatible_providers: ["compatible_providers"] || [], content: markdown, source_path: source_path ) # Filter by provider compatibility if specified if provider && !skill.compatible_with?(provider) Aidp.log_debug( "skills", "Skipping incompatible skill", skill_id: skill.id, provider: provider, compatible: skill.compatible_providers ) return nil end Aidp.log_debug( "skills", "Loaded skill", skill_id: skill.id, version: skill.version, source: source_path ) skill rescue Aidp::Errors::ValidationError => e Aidp.log_error("skills", "Skill validation failed", error: e., file: source_path) raise end |