diff options
| author | Jesse Vincent <jesse@fsck.com> | 2025-11-22 11:59:03 -0800 |
|---|---|---|
| committer | Jesse Vincent <jesse@fsck.com> | 2025-11-22 12:01:15 -0800 |
| commit | 85effaaedb357ffc3fef4fabdeb279eaf4c4b09e (patch) | |
| tree | c76b40a2d488fe6894f061553e1a9c50917c5da6 | |
| parent | 6cec629cf31cb7cee3cbcb50820b99b38aa3ffa5 (diff) | |
feat: create shared skills core module with frontmatter parser
Extract frontmatter parsing logic into lib/skills-core.js to enable
code reuse between Codex and OpenCode implementations.
| -rw-r--r-- | lib/skills-core.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/skills-core.js b/lib/skills-core.js new file mode 100644 index 0000000..8862943 --- /dev/null +++ b/lib/skills-core.js @@ -0,0 +1,54 @@ +const fs = require('fs'); + +/** + * Extract YAML frontmatter from a skill file. + * Current format: + * --- + * name: skill-name + * description: Use when [condition] - [what it does] + * --- + * + * @param {string} filePath - Path to SKILL.md file + * @returns {{name: string, description: string}} + */ +function extractFrontmatter(filePath) { + try { + const content = fs.readFileSync(filePath, 'utf8'); + const lines = content.split('\n'); + + let inFrontmatter = false; + let name = ''; + let description = ''; + + for (const line of lines) { + if (line.trim() === '---') { + if (inFrontmatter) break; + inFrontmatter = true; + continue; + } + + if (inFrontmatter) { + const match = line.match(/^(\w+):\s*(.*)$/); + if (match) { + const [, key, value] = match; + switch (key) { + case 'name': + name = value.trim(); + break; + case 'description': + description = value.trim(); + break; + } + } + } + } + + return { name, description }; + } catch (error) { + return { name: '', description: '' }; + } +} + +module.exports = { + extractFrontmatter +}; |
