Class: RubyLLM::Skills::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_llm/skills/parser.rb

Overview

Parses SKILL.md files with YAML frontmatter.

A valid SKILL.md has the format:

name: skill-name description: What the skill does

Skill content here

Constant Summary collapse

FRONTMATTER_REGEX =

Regex to match YAML frontmatter between --- delimiters

/\A---\n(.*?)\n---\n?(.*)/m

Class Method Summary collapse

Class Method Details

.extract_body(content) ⇒ String

Extract the body content (everything after frontmatter).

Parameters:

  • content (String) —

    full SKILL.md content

Returns:

  • (String) —

    body content without frontmatter



55
56
57
58
59
60
# File 'lib/ruby_llm/skills/parser.rb', line 55

def extract_body(content)
  match = content.match(FRONTMATTER_REGEX)
  return "" unless match

  match[2].to_s.strip
end

.parse_file(path) ⇒ Hash

Parse a SKILL.md file and extract frontmatter metadata.

Parameters:

  • path (String, Pathname) —

    path to SKILL.md file

Returns:

  • (Hash) —

    parsed frontmatter as hash

Raises:

  • (ParseError) —

    if frontmatter is missing or invalid



26
27
28
29
30
31
32
33
# File 'lib/ruby_llm/skills/parser.rb', line 26

def parse_file(path)
  content = File.read(path)
  parse_string(content)
rescue Errno::ENOENT
  raise ParseError, "File not found: #{path}"
rescue Errno::EACCES
  raise ParseError, "Permission denied: #{path}"
end

.parse_string(content) ⇒ Hash

Parse SKILL.md content string and extract frontmatter.

Parameters:

  • content (String) —

    full SKILL.md content

Returns:

  • (Hash) —

    parsed frontmatter as hash

Raises:

  • (ParseError) —

    if frontmatter is missing or invalid



40
41
42
43
44
45
46
47
48
49
# File 'lib/ruby_llm/skills/parser.rb', line 40

def parse_string(content)
  match = content.match(FRONTMATTER_REGEX)

  unless match
    raise ParseError, "Missing YAML frontmatter (must start with ---)"
  end

  yaml_content = match[1]
  parse_yaml(yaml_content)
end