Task 2: Extract Skill Discovery Logic
**Files:** - Modify: `lib/skills-core.js` - Reference: `.codex/superpowers-codex` (lines 97-136) **Step 1: Add findSkillsInDir function to skills-core.js** Add before `module.exports`: ```javascript /** * 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; } ``` **Step 2: Update module.exports** Replace the exports line with: ```javascript module.exports = { extractFrontmatter, findSkillsInDir }; ``` **Step 3: Verify syntax** Run: `node -c lib/skills-core.js` Expected: No output (success) **Step 4: Commit** ```bash git add lib/skills-core.js git commit -m "feat: add skill discovery function to core module" ``` ---