Module: Omakase::Skills

Defined in:
lib/omakase/skills.rb

Overview

A skill is a directory with a SKILL.md: YAML front matter says what it is, the body is the guidance. The description is listed with the agent's other capabilities; the body only arrives when the model calls the method — which is all "loaded on demand" has to mean.

Constant Summary collapse

CORE =
File.expand_path("skills/how_to_act", __dir__)

Class Method Summary collapse

Class Method Details

.attach(agent_class, path) ⇒ Object

Raises:



18
19
20
21
22
23
24
25
26
27
# File 'lib/omakase/skills.rb', line 18

def attach(agent_class, path)
  directory = File.expand_path(path)
  front_matter, body = parse(File.read(File.join(directory, "SKILL.md"), encoding: "UTF-8"))
  name = (front_matter["name"] || File.basename(directory)).tr("-", "_").to_sym
  raise Error, "#{agent_class} already has ##{name}" if Capabilities.names(agent_class).include?(name)

  agent_class.describe(front_matter["description"].to_s)
  agent_class.define_method(name) { "#{body}\n\nFiles for this skill are in #{directory}." }
  name
end

.attach_core(agent_class) ⇒ Object

Every agent gets the how-to. Skip when a parent already defined it.



14
15
16
# File 'lib/omakase/skills.rb', line 14

def attach_core(agent_class)
  attach(agent_class, CORE) unless Capabilities.names(agent_class).include?(:how_to_act)
end

.front_matter(text) ⇒ Object

Claude Code style hints like argument-hint: "<x>" [-p] are not YAML; read those line by line.



38
39
40
41
42
# File 'lib/omakase/skills.rb', line 38

def front_matter(text)
  YAML.safe_load(text)
rescue Psych::SyntaxError
  text.scan(/^([\w-]+):[ \t]*(.*?)\r?$/).to_h
end

.parse(text) ⇒ Object

The front matter every SKILL.md in the wild is written with — CRLF too.



30
31
32
33
34
35
# File 'lib/omakase/skills.rb', line 30

def parse(text)
  match = text.match(/\A---\r?\n(.*?)\r?\n---\r?\n(.*)\z/m)
  return [{}, text.strip] unless match

  [front_matter(match[1]), match[2].strip]
end