Module: Agentilda::Frontmatter
- Defined in:
- lib/agentilda/frontmatter.rb
Overview
Splits a markdown file into its YAML frontmatter and its body.
The agent definitions and create --from both read frontmatter, and both
used to call YAML.safe_load on their own. Its defaults refuse to build a
Date, so an ordinary date: 2026-08-31 raised Psych::DisallowedClass and
create reported a missing title: on a file whose title was right there.
One parser, one list of permitted classes, so that cannot happen twice.
Constant Summary collapse
- PATTERN =
Frontmatter, then body.
/\A---\s*\n(.*?)\n---\s*\n(.*)\z/m- PERMITTED_CLASSES =
Dates and timestamps are ordinary frontmatter, so they load. Nothing else does: the point of
safe_loadis that a seed file cannot name a class. [Date, Time].freeze
Class Method Summary collapse
-
.split(content) ⇒ Array(Hash, String)
The frontmatter and the body.
Class Method Details
.split(content) ⇒ Array(Hash, String)
Returns the frontmatter and the body. A file with no frontmatter is all body, and frontmatter that is not a mapping — a bare list, a lone string — reads as no keys rather than raising.
28 29 30 31 32 33 |
# File 'lib/agentilda/frontmatter.rb', line 28 def split(content) match = PATTERN.match(content) or return [{}, content] = YAML.safe_load(match[1], permitted_classes: PERMITTED_CLASSES) [.is_a?(Hash) ? : {}, match[2]] end |