Class: RubynCode::Skills::Matcher
- Inherits:
-
Object
- Object
- RubynCode::Skills::Matcher
- Defined in:
- lib/rubyn_code/skills/matcher.rb
Overview
Selects which skills to auto-load for a given user message.
A skill is selected when:
- its `triggers:` frontmatter list has at least one case-insensitive
substring hit against the user message, AND
- every gem in its `gems:` list is present in the project's Gemfile
(skills with no `gems:` are unrestricted; if there is no Gemfile,
gem gating is skipped entirely), AND
- it has not already been selected by this matcher in the current
session (per-instance dedup).
Match scope is the latest user turn only. There is no cap on the number of matches per turn.
Instance Method Summary collapse
-
#initialize(catalog:, project_root: nil) ⇒ Matcher
constructor
A new instance of Matcher.
-
#loaded ⇒ Object
Names of skills selected so far in this session.
-
#match(user_message) ⇒ Array<Hash>
Find skills whose triggers match ‘user_message`.
Constructor Details
#initialize(catalog:, project_root: nil) ⇒ Matcher
Returns a new instance of Matcher.
21 22 23 24 25 |
# File 'lib/rubyn_code/skills/matcher.rb', line 21 def initialize(catalog:, project_root: nil) @catalog = catalog @project_root = project_root @loaded = Set.new end |
Instance Method Details
#loaded ⇒ Object
Names of skills selected so far in this session.
45 46 47 |
# File 'lib/rubyn_code/skills/matcher.rb', line 45 def loaded @loaded.to_a end |
#match(user_message) ⇒ Array<Hash>
Find skills whose triggers match ‘user_message`.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rubyn_code/skills/matcher.rb', line 31 def match() text = .to_s.downcase return [] if text.empty? available_gems_set = available_gems @catalog.available.filter_map do |entry| next unless eligible?(entry, text, available_gems_set) @loaded << entry[:name] entry end end |