diff options
| author | zeejab <zahra.arch@gmail.com> | 2026-08-18 10:36:50 -0400 |
|---|---|---|
| committer | zeejab <zahra.arch@gmail.com> | 2026-08-18 10:36:50 -0400 |
| commit | 9da6e5ad92e7fd7292b779abf076bf5dbad783ac (patch) | |
| tree | 460483e099c480b51cf51bebba53f0564105cb0a /scripts | |
| parent | 050e24cd7b2d54cef2e9f2f6a39da152dd70fbb5 (diff) | |
Parse skill frontmatter with YAMLzeejab/agent-skills-discovery-index
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/build-discovery-index.mjs | 37 |
1 files changed, 14 insertions, 23 deletions
diff --git a/scripts/build-discovery-index.mjs b/scripts/build-discovery-index.mjs index 321df74..84a1e93 100644 --- a/scripts/build-discovery-index.mjs +++ b/scripts/build-discovery-index.mjs @@ -8,6 +8,7 @@ import { writeFileSync, } from 'node:fs'; import { join } from 'node:path'; +import { parse } from 'yaml'; const schema = 'https://schemas.agentskills.io/discovery/0.2.0/schema.json'; const baseUrl = process.argv[2]; @@ -36,34 +37,24 @@ const readMetadata = (directory) => { const frontmatter = source.match(/^---\r?\n([\s\S]*?)\r?\n---/)?.[1]; if (!frontmatter) throw new Error(`Missing frontmatter in ${path}`); - const lines = frontmatter.split(/\r?\n/); - const name = lines.find((line) => line.startsWith('name:'))?.slice(5).trim(); - const descriptionLine = lines.findIndex((line) => - line.startsWith('description:'), - ); - if (!name || descriptionLine === -1) { - throw new Error(`Missing name or description in ${path}`); + let metadata; + try { + metadata = parse(frontmatter); + } catch (error) { + throw new Error(`Invalid frontmatter in ${path}`, { cause: error }); } - const inlineDescription = lines[descriptionLine].slice(12).trim(); - const descriptionLines = []; - for ( - let index = descriptionLine + 1; - index < lines.length && /^\s/.test(lines[index]); - index++ - ) { - descriptionLines.push(lines[index].trim()); + if (!metadata || typeof metadata !== 'object') { + throw new Error(`Invalid frontmatter in ${path}`); + } + + const { name, description } = metadata; + if (typeof name !== 'string' || typeof description !== 'string') { + throw new Error(`Missing name or description in ${path}`); } - const blockStyle = inlineDescription.match(/^([>|])[-+]?$/)?.[1]; - const description = blockStyle - ? descriptionLines.join(blockStyle === '|' ? '\n' : ' ') - : inlineDescription.startsWith('"') - ? JSON.parse(inlineDescription) - : inlineDescription.startsWith("'") && inlineDescription.endsWith("'") - ? inlineDescription.slice(1, -1).replaceAll("''", "'") - : inlineDescription || descriptionLines.join(' '); if ( + name.length === 0 || name.length > 64 || !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(name) || !description || |
