Class: Riffer::Skills::Frontmatter

Inherits:
Object
  • Object
show all
Defined in:
lib/riffer/skills/frontmatter.rb

Overview

Immutable value object holding parsed SKILL.md YAML frontmatter. Required fields: name and description; unrecognized top-level keys are merged into metadata.

Constant Summary collapse

NAME_PATTERN =

: Regexp

/\A[a-z0-9]+(-[a-z0-9]+)*\z/
MAX_NAME_LENGTH =

: Integer

64
MAX_DESCRIPTION_LENGTH =

: Integer

1024

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, description:, metadata: {}) ⇒ Frontmatter

Raises Riffer::ArgumentError if name or description is invalid. – : (name: String, description: String, ?metadata: Hash[Symbol, untyped]) -> void



63
64
65
66
67
68
69
# File 'lib/riffer/skills/frontmatter.rb', line 63

def initialize(name:, description:, metadata: {})
  validate_name!(name)
  validate_description!(description)
  @name = name.freeze
  @description = description.freeze
  @metadata = .freeze
end

Instance Attribute Details

#descriptionObject (readonly)

The skill description (1-1024 chars).



18
19
20
# File 'lib/riffer/skills/frontmatter.rb', line 18

def description
  @description
end

#metadataObject (readonly)

Metadata from the spec’s metadata field plus any unrecognized top-level keys.



22
23
24
# File 'lib/riffer/skills/frontmatter.rb', line 22

def 
  @metadata
end

#nameObject (readonly)

The skill name (1-64 chars, lowercase alphanumeric and hyphens).



15
16
17
# File 'lib/riffer/skills/frontmatter.rb', line 15

def name
  @name
end

Class Method Details

.parse(raw) ⇒ Object

Parses a raw SKILL.md string into a [Frontmatter, body] pair — public so custom backends needn’t reimplement parsing. Raises Riffer::ArgumentError if the frontmatter is invalid. – : (String) -> [Riffer::Skills::Frontmatter, String]



29
30
31
32
33
# File 'lib/riffer/skills/frontmatter.rb', line 29

def self.parse(raw)
  yaml, body = split_frontmatter(raw)
  raise Riffer::ArgumentError, "missing YAML frontmatter (expected --- delimiters)" if yaml.empty?
  [new(name: yaml.delete(:name), description: yaml.delete(:description), metadata: yaml), body]
end

.parse_frontmatter(raw) ⇒ Object

Parses only the frontmatter from a raw SKILL.md string, ignoring the body. Raises Riffer::ArgumentError if the frontmatter is invalid. – : (String) -> Riffer::Skills::Frontmatter



39
40
41
42
43
# File 'lib/riffer/skills/frontmatter.rb', line 39

def self.parse_frontmatter(raw)
  yaml, _ = split_frontmatter(raw)
  raise Riffer::ArgumentError, "missing YAML frontmatter (expected --- delimiters)" if yaml.empty?
  new(name: yaml.delete(:name), description: yaml.delete(:description), metadata: yaml)
end