"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileSquadProvider = void 0;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
class FileSquadProvider {
    root;
    constructor(root) {
        this.root = root;
    }
    load() {
        if (!this.root || !fs.existsSync(this.root))
            return [];
        const files = this.walk(this.root).filter(f => f.endsWith('.md'));
        return files.map(file => this.parse(file, fs.readFileSync(file, 'utf-8')));
    }
    walk(dir) {
        const out = [];
        for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
            const full = path.join(dir, entry.name);
            if (entry.isDirectory())
                out.push(...this.walk(full));
            else
                out.push(full);
        }
        return out;
    }
    parse(filePath, content) {
        const id = path.basename(filePath) === 'SQUAD.md' ? path.basename(path.dirname(filePath)) : path.basename(filePath, '.md');
        const title = content.split('\n').find(l => l.trim().startsWith('# '))?.replace(/^#\s*/, '') || id;
        const capabilities = content.split(/[\n,.]/).map(s => s.trim()).filter(Boolean).slice(0, 20);
        const domain = filePath.split('/squads/')[1]?.split('/')[0] || filePath.split('/Squads/')[1]?.split('/')[0] || 'general';
        return { id, name: title, sourcePath: filePath, domain, capabilities };
    }
}
exports.FileSquadProvider = FileSquadProvider;
