Class: Skills::Registry
- Inherits:
-
Object
- Object
- Skills::Registry
- Defined in:
- lib/skills/registry.rb
Overview
Loads skill definitions from Markdown files and provides lookup. Supports two formats:
- Flat file: skills/skill-name.md
- Directory: skills/skill-name/SKILL.md (with optional references/ and examples/)
Scans two directories:
1. Built-in skills shipped with Anima (skills/ in the gem root)
2. User-defined skills (~/.anima/skills/)
User skills override built-in ones when names collide.
Constant Summary collapse
- BUILTIN_DIR =
File.("../../skills", __dir__).freeze
- USER_DIR =
File.("~/.anima/skills").freeze
Instance Attribute Summary collapse
-
#skills ⇒ Hash{String => Definition}
readonly
Loaded definitions keyed by name.
Class Method Summary collapse
-
.instance ⇒ Registry
Returns the global registry, lazily loaded on first access.
-
.reload! ⇒ Registry
Reloads the global registry from disk.
Instance Method Summary collapse
- #any? ⇒ Boolean
-
#available_names ⇒ Array<String>
Registered skill names.
-
#catalog ⇒ Hash{String => String}
Skill names and descriptions for inclusion in the analytical brain’s context.
-
#find(name) ⇒ Definition?
Looks up a named skill definition.
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
-
#load_all ⇒ self
Loads definitions from both built-in and user directories.
-
#load_directory(dir) ⇒ void
Loads skill definitions from a single directory.
- #size ⇒ Integer
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
19 20 21 |
# File 'lib/skills/registry.rb', line 19 def initialize @skills = {} end |
Instance Attribute Details
#skills ⇒ Hash{String => Definition} (readonly)
Returns loaded definitions keyed by name.
14 15 16 |
# File 'lib/skills/registry.rb', line 14 def skills @skills end |
Class Method Details
.instance ⇒ Registry
Returns the global registry, lazily loaded on first access.
26 27 28 |
# File 'lib/skills/registry.rb', line 26 def self.instance @instance ||= new.load_all end |
.reload! ⇒ Registry
Reloads the global registry from disk.
33 34 35 |
# File 'lib/skills/registry.rb', line 33 def self.reload! @instance = new.load_all end |
Instance Method Details
#any? ⇒ Boolean
85 86 87 |
# File 'lib/skills/registry.rb', line 85 def any? @skills.any? end |
#available_names ⇒ Array<String>
Returns registered skill names.
80 81 82 |
# File 'lib/skills/registry.rb', line 80 def available_names @skills.keys end |
#catalog ⇒ Hash{String => String}
Skill names and descriptions for inclusion in the analytical brain’s context.
75 76 77 |
# File 'lib/skills/registry.rb', line 75 def catalog @skills.transform_values(&:description) end |
#find(name) ⇒ Definition?
Looks up a named skill definition.
68 69 70 |
# File 'lib/skills/registry.rb', line 68 def find(name) @skills[name] end |
#load_all ⇒ self
Loads definitions from both built-in and user directories. User definitions override built-in ones with the same name.
41 42 43 44 45 |
# File 'lib/skills/registry.rb', line 41 def load_all load_directory(BUILTIN_DIR) load_directory(USER_DIR) unless Rails.env.test? self end |
#load_directory(dir) ⇒ void
This method returns an undefined value.
Loads skill definitions from a single directory. Supports flat files (*.md) and directory-based skills (*/SKILL.md).
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/skills/registry.rb', line 53 def load_directory(dir) return unless Dir.exist?(dir) skill_files(dir).each do |path| definition = Definition.from_file(path) @skills[definition.name] = definition rescue InvalidDefinitionError => error Rails.logger.warn("Skipping invalid skill definition #{path}: #{error.}") end end |
#size ⇒ Integer
90 91 92 |
# File 'lib/skills/registry.rb', line 90 def size @skills.size end |