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 | |
| parent | 050e24cd7b2d54cef2e9f2f6a39da152dd70fbb5 (diff) | |
Parse skill frontmatter with YAMLzeejab/agent-skills-discovery-index
| -rw-r--r-- | .github/workflows/agent-skills-discovery.yml | 2 | ||||
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | README.md | 1 | ||||
| -rw-r--r-- | package-lock.json | 27 | ||||
| -rw-r--r-- | package.json | 8 | ||||
| -rw-r--r-- | scripts/build-discovery-index.mjs | 37 |
6 files changed, 53 insertions, 23 deletions
diff --git a/.github/workflows/agent-skills-discovery.yml b/.github/workflows/agent-skills-discovery.yml index b99cf2e..8a76c89 100644 --- a/.github/workflows/agent-skills-discovery.yml +++ b/.github/workflows/agent-skills-discovery.yml @@ -21,6 +21,7 @@ jobs: contents: read steps: - uses: actions/checkout@v4 + - run: npm ci --ignore-scripts - run: node scripts/build-discovery-index.mjs https://example.com/skills publish: @@ -37,6 +38,7 @@ jobs: RELEASE_TAG: agent-skills-${{ github.sha }} steps: - uses: actions/checkout@v4 + - run: npm ci --ignore-scripts - run: node scripts/build-discovery-index.mjs "https://github.com/${{ github.repository }}/releases/download/${RELEASE_TAG}" - run: | gh release view "$RELEASE_TAG" >/dev/null 2>&1 || @@ -2,3 +2,4 @@ .vercel .env*.local dist +node_modules @@ -222,6 +222,7 @@ an Agent Skills discovery index and one artifact per skill. Build the same artifacts locally with: ```bash +npm ci --ignore-scripts node scripts/build-discovery-index.mjs https://example.com/skills ``` diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..bf6a642 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,27 @@ +{ + "name": "@vercel-labs/agent-skills", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@vercel-labs/agent-skills", + "dependencies": { + "yaml": "2.9.0" + } + }, + "node_modules/yaml": { + "version": "2.9.0", + "integrity": "sha512-2AvhNX3mb8zd6Zy7INTtSpl1F15HW6Wnqj0srWlkKLcpYl/gMIMJiyuGq2KeI2YFxUPjdlB+3Lc10seMLtL4cA==", + "license": "ISC", + "bin": { + "yaml": "bin.mjs" + }, + "engines": { + "node": ">= 14.6" + }, + "funding": { + "url": "https://github.com/sponsors/eemeli" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..8ca4be2 --- /dev/null +++ b/package.json @@ -0,0 +1,8 @@ +{ + "name": "@vercel-labs/agent-skills", + "private": true, + "type": "module", + "dependencies": { + "yaml": "2.9.0" + } +} 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 || |
