class Installer

Discovers and installs skills provided by Ruby gems.

Nested Classes and Modules

class Error

Base error for skill discovery and installation failures.

class InvalidSkill

Raised when a provider contains an invalid skill.

class Conflict

Raised when a skill would overwrite content owned by another source.

Definitions

def initialize(root: Dir.pwd, specifications: ::Gem::Specification)

Initialize a skill installer.

Signature

parameter root String

The consuming project root.

parameter specifications Gem::Specification

The gem specifications to scan.

Implementation

def initialize(root: Dir.pwd, specifications: ::Gem::Specification)
	@root = File.expand_path(root)
	@skills_path = File.join(@root, ".agents", "skills")
	@specifications = specifications
end

def find_gems_with_skills(skip_local: true)

Find installed gems which provide one or more valid skills.

Signature

parameter skip_local Boolean

Whether to skip a gem loaded from the consuming project root.

Implementation

def find_gems_with_skills(skip_local: true)
	@specifications.filter_map do |specification|
		next if skip_local && same_path?(specification.full_gem_path, @root)
		
		build_gem_information(specification)
	end
end

def find_gem_with_skills(gem_name)

Find a named gem which provides skills.

Signature

parameter gem_name String

The gem name to find.

Implementation

def find_gem_with_skills(gem_name)
	specification = @specifications.find {|candidate| candidate.name == gem_name}
	return unless specification
	
	build_gem_information(specification)
end

def list_skills(gem_name)

List skills provided by a named gem.

Signature

parameter gem_name String

The gem name.

Implementation

def list_skills(gem_name)
	gem = find_gem_with_skills(gem_name)
	gem && gem[:skills]
end

def show_skill(gem_name, skill_name)

Read the instruction file for a skill provided by a gem.

Signature

parameter gem_name String

The provider gem name.

parameter skill_name String

The declared skill name.

Implementation

def show_skill(gem_name, skill_name)
	skills = list_skills(gem_name)
	return unless skills
	
	definition = skills.find {|skill| skill.name == skill_name}
	File.read(definition.skill_file) if definition
end

def install_gem_skills(gem_name)

Install all skills provided by a named gem.

Signature

parameter gem_name String

The provider gem name.

returns Array(String), nil

Installed skill names, or nil if the gem provides no skills.

Implementation

def install_gem_skills(gem_name)
	gem = find_gem_with_skills(gem_name)
	return unless gem
	
	install_gems([gem])
end

def install_all_skills(skip_local: true)

Install skills from every discovered gem.

Signature

parameter skip_local Boolean

Whether to skip a gem loaded from the consuming project root.

returns Array(String)

Installed skill names.

Implementation

def install_all_skills(skip_local: true)
	install_gems(find_gems_with_skills(skip_local: skip_local))
end