Class: RubynCode::Skills::RegistryAutoload

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyn_code/skills/registry_autoload.rb

Overview

Web fallback for trigger-based skill autoload.

When the user message matches a skill pack in the registry that the user hasn’t installed locally, fetch the pack, install it under ~/.rubyn-code/skill-packs/, refresh the loader’s catalog, and let the local matcher pick up the freshly-available skills.

Pack-level matching (decided up front): substring-match the user message against each pack’s :name and :tags. Skill-level triggers aren’t in the registry catalog yet, so we pull packs at the coarser grain and let the local matcher take over once files land on disk.

Failure modes are silent: a registry error returns no matches so the turn proceeds as if the web fallback weren’t there.

Instance Method Summary collapse

Constructor Details

#initialize(loader:, matcher:, registry_client: nil, pack_manager: nil, on_fetching: nil) ⇒ RegistryAutoload

Returns a new instance of RegistryAutoload.

Parameters:

  • loader (Skills::Loader)

    supplies the live catalog to refresh after install

  • matcher (Skills::Matcher)

    re-run after install to extract real skill matches

  • registry_client (Skills::RegistryClient, nil) (defaults to: nil)

    defaults to a new client

  • pack_manager (Skills::PackManager, nil) (defaults to: nil)

    defaults to a new manager

  • on_fetching (Proc, nil) (defaults to: nil)

    called as on_fetching.call(pack_name) before each fetch



25
26
27
28
29
30
31
32
33
34
# File 'lib/rubyn_code/skills/registry_autoload.rb', line 25

def initialize(loader:, matcher:, registry_client: nil, pack_manager: nil, on_fetching: nil)
  @loader = loader
  @matcher = matcher
  @client = registry_client || RegistryClient.new
  @pack_manager = pack_manager || PackManager.new
  @on_fetching = on_fetching || ->(_name) {}
  @attempted = Set.new
  @catalog_cache = nil
  @catalog_fetch_failed = false
end

Instance Method Details

#try(user_input) ⇒ Array<Hash>

Attempt to install and match uninstalled packs whose name or tags appear in the user message.

Parameters:

  • user_input (String)

Returns:

  • (Array<Hash>)

    catalog entries (from the local matcher) that became matchable after install. Empty if nothing fetched or the registry is unreachable.



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rubyn_code/skills/registry_autoload.rb', line 43

def try(user_input)
  text = user_input.to_s.downcase
  return [] if text.empty?

  candidates = uninstalled_packs_matching(text)
  return [] if candidates.empty?

  installed_any = candidates.any? { |pack| attempt_install(pack) }
  return [] unless installed_any

  @loader.catalog.refresh!
  @matcher.match(user_input)
end