* Parses YAML frontmatter from a SKILL.md file using gray-matter. * Frontmatter is expected to be between --- markers at the start of the file.
(content: string)
| 22 | * Frontmatter is expected to be between --- markers at the start of the file. |
| 23 | */ |
| 24 | function parseFrontmatter(content: string): { |
| 25 | frontmatter: Record<string, unknown> |
| 26 | body: string |
| 27 | } | null { |
| 28 | try { |
| 29 | const parsed = matter(content) |
| 30 | if (!parsed.data || Object.keys(parsed.data).length === 0) { |
| 31 | return null |
| 32 | } |
| 33 | return { |
| 34 | frontmatter: parsed.data as Record<string, unknown>, |
| 35 | body: parsed.content, |
| 36 | } |
| 37 | } catch { |
| 38 | return null |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Loads a single skill from a SKILL.md file. |