| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- 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
- };
|