1
0

skills-core.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const fs = require('fs');
  2. /**
  3. * Extract YAML frontmatter from a skill file.
  4. * Current format:
  5. * ---
  6. * name: skill-name
  7. * description: Use when [condition] - [what it does]
  8. * ---
  9. *
  10. * @param {string} filePath - Path to SKILL.md file
  11. * @returns {{name: string, description: string}}
  12. */
  13. function extractFrontmatter(filePath) {
  14. try {
  15. const content = fs.readFileSync(filePath, 'utf8');
  16. const lines = content.split('\n');
  17. let inFrontmatter = false;
  18. let name = '';
  19. let description = '';
  20. for (const line of lines) {
  21. if (line.trim() === '---') {
  22. if (inFrontmatter) break;
  23. inFrontmatter = true;
  24. continue;
  25. }
  26. if (inFrontmatter) {
  27. const match = line.match(/^(\w+):\s*(.*)$/);
  28. if (match) {
  29. const [, key, value] = match;
  30. switch (key) {
  31. case 'name':
  32. name = value.trim();
  33. break;
  34. case 'description':
  35. description = value.trim();
  36. break;
  37. }
  38. }
  39. }
  40. }
  41. return { name, description };
  42. } catch (error) {
  43. return { name: '', description: '' };
  44. }
  45. }
  46. module.exports = {
  47. extractFrontmatter
  48. };