Class: RubynCode::Skills::Matcher

Inherits:
Object
  • Object
show all
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

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

#loadedObject

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`.

Parameters:

  • user_message (String)

Returns:

  • (Array<Hash>)

    catalog entries to load



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rubyn_code/skills/matcher.rb', line 31

def match(user_message)
  text = user_message.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