Class: RailsAiBridge::Registry::Resolver

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_ai_bridge/registry/resolver.rb

Overview

Core resolver that aggregates active packs and resolves queries.

Provides priority-based resolution of skills and agents, handles deprecation redirects, validates dependencies, and guards against path traversal attacks.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(loaded_packs) ⇒ Resolver

Builds a new RegistryResolver from a list of loaded packs.

Packs are sorted by priority ascending (highest priority first). Deprecated skills are indexed in reverse priority order so higher priority deprecations overwrite lower priority ones.

Parameters:

  • loaded_packs (Array<LoadedPack>)

    list of loaded packs



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rails_ai_bridge/registry/resolver.rb', line 53

def initialize(loaded_packs)
  # Sort active packs by priority ascending (highest priority first)
  @active_packs = loaded_packs.sort_by(&:priority)

  # Pre-compute the reverse order once; used by list_skills, list_agents,
  # and build_deprecated_index so they don't each sort independently.
  @active_packs_reverse = @active_packs.reverse

  # Gather deprecated skills in reverse order so higher priority overwrites
  @deprecated_index = build_deprecated_index
end

Instance Attribute Details

#active_packsArray<LoadedPack> (readonly)

Direct access to loaded packs (useful for tool lists/status).

Returns:

  • (Array<LoadedPack>)

    list of loaded packs sorted by priority



137
138
139
# File 'lib/rails_ai_bridge/registry/resolver.rb', line 137

def active_packs
  @active_packs
end

Instance Method Details

#check_deprecated(name) ⇒ String?

Check if a skill name is deprecated, returning the warning message if so.

Parameters:

  • name (String)

    name of the skill to check

Returns:

  • (String, nil)

    warning message if deprecated, nil otherwise



123
124
125
126
127
128
129
130
131
132
# File 'lib/rails_ai_bridge/registry/resolver.rb', line 123

def check_deprecated(name)
  dep = @deprecated_index[name]
  return nil unless dep

  if dep.removed_in?
    "Skill '#{name}' is deprecated: #{dep.message}. It will be removed in version #{dep.removed_in}."
  else
    "Skill '#{name}' is deprecated: #{dep.message}."
  end
end

#get_agent_dependencies(name) ⇒ Array<String>?

Gets dependency list for a specific agent.

Parameters:

  • name (String)

    name of the agent

Returns:

  • (Array<String>, nil)

    list of skill dependencies or nil if agent not found



143
144
145
146
147
148
149
150
# File 'lib/rails_ai_bridge/registry/resolver.rb', line 143

def get_agent_dependencies(name)
  @active_packs.each do |pack|
    entry = pack.tile.agents[name]
    return entry.depends_on.dup if entry
  end

  nil
end

#list_agentsArray<SkillSummary>

Returns a list of all unique agents across active packs, deduplicated by priority.

Agents from higher priority packs overwrite agents from lower priority packs. Results are sorted alphabetically by agent name.

Returns:



99
100
101
# File 'lib/rails_ai_bridge/registry/resolver.rb', line 99

def list_agents
  build_summary_map(:agents).values.sort_by(&:name)
end

#list_skillsArray<SkillSummary>

Returns a list of all unique skills across active packs, deduplicated by priority.

Skills from higher priority packs overwrite skills from lower priority packs. Results are sorted alphabetically by skill name.

Returns:



89
90
91
# File 'lib/rails_ai_bridge/registry/resolver.rb', line 89

def list_skills
  build_summary_map(:skills).values.sort_by(&:name)
end

#resolve_agent(name) ⇒ ResolvedSkill?

Resolves an agent by name, handling priority tiers.

Parameters:

  • name (String)

    name of the agent to resolve

Returns:



79
80
81
# File 'lib/rails_ai_bridge/registry/resolver.rb', line 79

def resolve_agent(name)
  resolve_entry(name, collection: :agents)
end

#resolve_skill(name) ⇒ ResolvedSkill?

Resolves a skill by name, handling priority tiers and deprecation redirects.

Parameters:

  • name (String)

    name of the skill to resolve

Returns:



69
70
71
72
73
# File 'lib/rails_ai_bridge/registry/resolver.rb', line 69

def resolve_skill(name)
  # Handle deprecation redirects transparently
  target_name = (dep = @deprecated_index[name]) ? dep.moved_to : name
  resolve_entry(target_name, collection: :skills)
end

#validate_dependenciesArray<String>

Validates that all pack dependencies are satisfied among active packs.

Returns:

  • (Array<String>)

    list of warning strings for missing dependencies



106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/rails_ai_bridge/registry/resolver.rb', line 106

def validate_dependencies
  warnings = []
  loaded_names = @active_packs.to_set(&:name)

  @active_packs.each do |pack|
    pack.tile.depends_on.each do |dep|
      warnings << "Pack '#{pack.name}' depends on '#{dep}', which is not loaded." unless loaded_names.include?(dep)
    end
  end

  warnings
end