summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJesse Vincent <jesse@fsck.com>2025-11-22 12:02:15 -0800
committerJesse Vincent <jesse@fsck.com>2025-11-22 12:02:15 -0800
commit536fd24603bd2641e8b0fa0708826d83d2828c64 (patch)
tree5cea5aa317da3ee0b2e18e776c6627b00790c79e /lib
parent85effaaedb357ffc3fef4fabdeb279eaf4c4b09e (diff)
feat: add skill discovery function to core module
Diffstat (limited to 'lib')
-rw-r--r--lib/skills-core.js49
1 files changed, 48 insertions, 1 deletions
diff --git a/lib/skills-core.js b/lib/skills-core.js
index 8862943..113627a 100644
--- a/lib/skills-core.js
+++ b/lib/skills-core.js
@@ -1,4 +1,5 @@
const fs = require('fs');
+const path = require('path');
/**
* Extract YAML frontmatter from a skill file.
@@ -49,6 +50,52 @@ function extractFrontmatter(filePath) {
}
}
+/**
+ * Find all SKILL.md files in a directory recursively.
+ *
+ * @param {string} dir - Directory to search
+ * @param {string} sourceType - 'personal' or 'superpowers' for namespacing
+ * @param {number} maxDepth - Maximum recursion depth (default: 3)
+ * @returns {Array<{path: string, name: string, description: string, sourceType: string}>}
+ */
+function findSkillsInDir(dir, sourceType, maxDepth = 3) {
+ const skills = [];
+
+ if (!fs.existsSync(dir)) return skills;
+
+ function recurse(currentDir, depth) {
+ if (depth > maxDepth) return;
+
+ const entries = fs.readdirSync(currentDir, { withFileTypes: true });
+
+ for (const entry of entries) {
+ const fullPath = path.join(currentDir, entry.name);
+
+ if (entry.isDirectory()) {
+ // Check for SKILL.md in this directory
+ const skillFile = path.join(fullPath, 'SKILL.md');
+ if (fs.existsSync(skillFile)) {
+ const { name, description } = extractFrontmatter(skillFile);
+ skills.push({
+ path: fullPath,
+ skillFile: skillFile,
+ name: name || entry.name,
+ description: description || '',
+ sourceType: sourceType
+ });
+ }
+
+ // Recurse into subdirectories
+ recurse(fullPath, depth + 1);
+ }
+ }
+ }
+
+ recurse(dir, 0);
+ return skills;
+}
+
module.exports = {
- extractFrontmatter
+ extractFrontmatter,
+ findSkillsInDir
};