|
@@ -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
|
|
|
|
|
+};
|