import { readFile } from "node:fs/promises";
import { existsSync, readdirSync, statSync } from "node:fs";
import { resolve, join } from "node:path";
function listSpecialistFiles(dir) {
    if (!existsSync(dir))
        return [];
    const out = [];
    for (const entry of readdirSync(dir)) {
        const full = join(dir, entry);
        const st = statSync(full);
        if (st.isFile() && entry.endsWith(".md")) {
            out.push(entry.replace(/\.md$/, ""));
        }
        else if (st.isDirectory() && existsSync(join(full, "IDENTITY.md"))) {
            out.push(entry);
        }
    }
    return out.sort();
}
function listAgentRegistry(dir) {
    if (!existsSync(dir))
        return [];
    const out = [];
    for (const entry of readdirSync(dir)) {
        if (entry.endsWith(".md"))
            out.push(entry.replace(/\.md$/, ""));
    }
    return out.sort();
}
export async function resolveCapabilitiesHere(input, nowIso) {
    const accountRaw = await readFile(input.accountConfigPath, "utf-8");
    const account = JSON.parse(accountRaw);
    const brandRaw = await readFile(input.brandConfigPath, "utf-8");
    const brand = JSON.parse(brandRaw);
    const enabledPlugins = Array.isArray(account.enabledPlugins)
        ? account.enabledPlugins.slice().sort()
        : [];
    const tier = typeof account.tier === "string" ? account.tier : null;
    const adminModel = typeof account.adminModel === "string" ? account.adminModel : null;
    const publicModel = typeof account.publicModel === "string" ? account.publicModel : null;
    const productName = typeof brand.productName === "string" ? brand.productName : null;
    const shipsPremiumBundles = Array.isArray(brand.shipsPremiumBundles)
        ? brand.shipsPremiumBundles.slice().sort()
        : [];
    const platformSpecialistsDir = resolve(input.platformRoot, "templates", "specialists", "agents");
    const installedPlatformSpecialists = listSpecialistFiles(platformSpecialistsDir);
    const installedPremiumSpecialists = [];
    for (const bundle of shipsPremiumBundles) {
        const bundleAgentsDir = resolve(input.premiumPluginsRoot, bundle, "agents");
        const names = listSpecialistFiles(bundleAgentsDir);
        for (const name of names)
            installedPremiumSpecialists.push({ bundle, name });
    }
    const registeredAgentTypes = listAgentRegistry(resolve(input.claudeConfigDir, "agents"));
    return {
        accountId: input.accountId,
        tier,
        adminModel,
        publicModel,
        enabledPlugins,
        installedPlatformSpecialists,
        installedPremiumSpecialists,
        registeredAgentTypes,
        brand: { productName, shipsPremiumBundles },
        capturedAt: nowIso,
    };
}
//# sourceMappingURL=capabilities-here.js.map