class LittleGhost::Skills::Catalog
A Catalog lets an agent discover focused instructions without putting every skill in its prompt. The model sees short descriptions first and can load a skill’s full instructions when the task calls for them.
catalog = LittleGhost::Skills::Catalog.new(paths: ["app/skills"]) catalog.names # => ["refund_policy", "search_orders"] catalog.discovery_prompt.include?("refund_policy") # => true catalog.tool # a LittleGhost::Tool that loads full instructions on demand
Each immediate child directory may contain one SKILL.md with YAML front matter whose name matches the directory name. A symbolic link that escapes its root or an oversized file raises ConfigurationError. Linked skill directories and manifests, unsafe or mismatched names, and invalid UTF-8 or YAML are skipped before instructions reach a model, and each skip emits a little_ghost.skills.skill_skipped warning through Events with the directory name and a reason. Optional resource listings are limited by count and depth.
Layering skill roots
When several roots define the same skill name, precedence decides the result: :last (the default) lets a later root override an earlier one, :first keeps the earliest definition, and :error raises ConfigurationError. List roots so the one you trust most wins.
catalog = LittleGhost::Skills::Catalog.new( paths: [shared_skills, repository_skills, "app/skills"], precedence: :last ) catalog.materialize("/srv/run/skills") # => "/srv/run/skills"
materialize copies the resolved skills into one directory, so a Sandbox can expose a single read-only path instead of every source root.
Choosing skill sources
Skill files become model instructions, so keep configured roots under application control and non-user-writable. The allowed-tools field tells the model what a skill expects; the Agent’s Tool list and each Tool’s application checks still decide what can run. For a workspace:// resource root, the Catalog verifies the named read-only grant and rejects direct writable aliases it can identify. LittleGhost cannot identify every alias created by an outer container or mount namespace, so the application must not expose the same files through another writable bind mount.
Public Class Methods
# File lib/little_ghost/skills/catalog.rb, line 84 def initialize( paths:, precedence: :last, max_skills: DEFAULT_MAX_SKILLS, max_file_bytes: DEFAULT_MAX_FILE_BYTES, max_resource_files: DEFAULT_MAX_RESOURCE_FILES, only: nil, resource_root: nil, workspace: nil, sandbox: nil, prompt_renderer: nil ) @paths = PathSet.new(paths) @precedence = precedence unless PRECEDENCES.include?(@precedence) raise ArgumentError, "precedence must be one of: #{PRECEDENCES.join(", ")}" end @max_skills = positive_integer(max_skills, :max_skills) @max_file_bytes = positive_integer(max_file_bytes, :max_file_bytes) @max_resource_files = positive_integer(max_resource_files, :max_resource_files) @only = Array(only).map(&:to_s).freeze if only @resource_root = ResourceRoot.normalize(resource_root) @prompt_renderer = prompt_renderer @framework_prompts = FrameworkPrompts.new validate_workspace_resource_root!(workspace, sandbox) @skills = load_skills validate_workspace_resource_aliases!(sandbox) end
Loads valid skills immediately using the supplied safety limits. resource_root may be an absolute process-visible path. A workspace://name reference also requires workspace and sandbox; it must resolve to every configured skill root through a read-only file-tool grant. precedence is :last, :first, or :error and decides which root wins when several define one name.
Public Instance Methods
Source
# File lib/little_ghost/skills/catalog.rb, line 132 def discovery_prompt return "" if @skills.empty? framework_prompt( "skills/discovery/instructions", skills: @skills.each_value.map do |skill| {name: skill.name, description: skill.description, location: skill.path} end ) end
Produces the Markdown, metadata-only prompt used for discovery.
Source
# File lib/little_ghost/skills/catalog.rb, line 114 def each(&block) @skills.each_value(&block) end
Yields each Skill in lookup order.
Source
# File lib/little_ghost/skills/catalog.rb, line 120 def fetch(name) @skills.fetch(name.to_s) do raise ConfigurationError, framework_prompt("skills/feedback/unknown", name: name.to_s, available: names) end end
Finds the named Skill. When no Skill matches, the ConfigurationError names the available skills so the caller can correct the lookup.
Source
# File lib/little_ghost/skills/catalog.rb, line 169 def format(skill) framework_prompt( "skills/tools/activate/content", instructions: skill.instructions, allowed_tools: skill.allowed_tools, compatibility: skill.compatibility, location: skill.path, resources: skill_resources(skill) ) end
Formats one Skill, including allowed tools, compatibility, and bounded resource paths.
# File lib/little_ghost/skills/catalog.rb, line 199 def materialize( destination, max_bytes: DEFAULT_MAX_MATERIALIZED_BYTES, max_files: DEFAULT_MAX_MATERIALIZED_FILES ) budget = { max_bytes: positive_integer(max_bytes, :max_bytes), max_files: positive_integer(max_files, :max_files), bytes: 0, files: 0 } reject_overlapping_destination!(prospective_realpath(destination), destination) FileUtils.mkdir_p(destination, mode: 0o700) real_destination = File.realpath(destination) reject_overlapping_destination!(real_destination, destination) File.open(real_destination, File::RDONLY) do |lock| lock.flock(File::LOCK_EX) Dir.children(real_destination).each do |name| remove_quietly(File.join(real_destination, name)) if name.start_with?(STAGING_PREFIX) end @skills.each_value { |skill| materialize_skill(skill, real_destination, budget) } end real_destination rescue SystemCallError => error raise ConfigurationError, "Skills could not be materialized into #{destination}: #{error.message}" end
Copies each Skill in the catalog into destination and returns the destination’s real path. Each Skill lands in destination/name with its SKILL.md and its scripts, references, and assets directories; other files in the Skill directory are not copied. Regular files and directories are copied with group and world write permission removed. Symbolic links and special files are skipped, so a copied Skill never points outside its directory.
A complete copy replaces an entry with the same name by rename; other entries are left in place. Concurrent calls for one destination run one at a time, and each call removes entries whose names start with .little_ghost-staging- left by an interrupted earlier call.
max_bytes and max_files bound the whole copy, and resource directories may nest at most three levels. ConfigurationError is raised, leaving earlier entries in place, when a limit is exceeded, when the destination overlaps a configured skill root, when a file cannot be read or written, or when a Skill changed after it was loaded.
Source
# File lib/little_ghost/skills/catalog.rb, line 127 def names @skills.keys.freeze end
Lists immutable skill names in lookup order.
Source
# File lib/little_ghost/skills/catalog.rb, line 144 def tool catalog = self Tool.define( name: "skills", description: framework_prompt("skills/tools/activate/description"), input_schema: { type: "object", properties: { skill_name: { type: "string", description: framework_prompt("skills/tools/activate/inputs/name/description") } }, required: ["skill_name"], additionalProperties: false } ) do |input| catalog.format(catalog.fetch(input.fetch("skill_name"))) rescue ConfigurationError => error raise ToolError, error.message end end
Exposes full instructions on demand through a skills Tool.