"use strict";
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2024-2026 Gracker (Chris)
// This file is part of SmartPerfetto. See LICENSE for details.
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;
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.listCommand = void 0;
/**
 * List Command
 *
 * Lists all available skills with their details.
 */
const commander_1 = require("commander");
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
// ANSI color codes
const colors = {
    green: (s) => `\x1b[32m${s}\x1b[0m`,
    red: (s) => `\x1b[31m${s}\x1b[0m`,
    yellow: (s) => `\x1b[33m${s}\x1b[0m`,
    blue: (s) => `\x1b[34m${s}\x1b[0m`,
    gray: (s) => `\x1b[90m${s}\x1b[0m`,
    bold: (s) => `\x1b[1m${s}\x1b[0m`,
    cyan: (s) => `\x1b[36m${s}\x1b[0m`,
};
const SKILLS_DIR = path_1.default.join(__dirname, '../../../skills');
/**
 * List command
 */
exports.listCommand = new commander_1.Command('list')
    .description('List all available skills')
    .option('-v, --verbose', 'Show detailed information')
    .option('--json', 'Output in JSON format')
    .action(async (options) => {
    try {
        // Dynamic import to avoid loading heavy dependencies
        const { skillRegistry, ensureSkillRegistryInitialized } = await Promise.resolve().then(() => __importStar(require('../../services/skillEngine/skillLoader')));
        // Initialize
        if (!options.json) {
            console.log(colors.gray('Loading skills...'));
        }
        await ensureSkillRegistryInitialized();
        const skills = skillRegistry.getAllSkills();
        if (options.json) {
            // JSON output
            const output = skills.map(skill => ({
                id: skill.name,
                name: skill.name,
                version: skill.version,
                displayName: skill.meta.display_name,
                description: skill.meta.description,
                category: skill.category,
                type: skill.type,
                stepsCount: skill.steps?.length || 0,
                tags: skill.meta.tags,
            }));
            console.log(JSON.stringify(output, null, 2));
            return;
        }
        // Human-readable output
        console.log(colors.bold('\nSmartPerfetto Skills\n'));
        console.log(`Found ${colors.cyan(String(skills.length))} skills\n`);
        // Group by type
        const byType = new Map();
        for (const skill of skills) {
            const type = skill.type || 'other';
            if (!byType.has(type)) {
                byType.set(type, []);
            }
            byType.get(type).push(skill);
        }
        // Print by type
        for (const [type, typeSkills] of byType.entries()) {
            console.log(colors.bold(`${type.toUpperCase()}:`));
            for (const skill of typeSkills) {
                // Skill header
                console.log(`\n  ${colors.cyan(skill.name)}`);
                console.log(`    ${skill.meta.display_name} v${skill.version}`);
                console.log(`    ${colors.gray(skill.meta.description)}`);
                if (options.verbose) {
                    // Steps
                    const steps = skill.steps || [];
                    console.log(`    Steps: ${steps.length}`);
                    for (const step of steps) {
                        console.log(`      - ${step.id}: ${step.name || step.type}`);
                    }
                    // Keywords
                    if (skill.triggers?.keywords) {
                        const keywords = Array.isArray(skill.triggers.keywords)
                            ? skill.triggers.keywords
                            : [...(skill.triggers.keywords.zh || []), ...(skill.triggers.keywords.en || [])];
                        console.log(`    Keywords: ${keywords.slice(0, 5).join(', ')}${keywords.length > 5 ? '...' : ''}`);
                    }
                    // Tags
                    if (skill.meta.tags) {
                        console.log(`    Tags: ${skill.meta.tags.join(', ')}`);
                    }
                }
            }
            console.log('');
        }
        // Vendor overrides summary
        const vendorsDir = path_1.default.join(SKILLS_DIR, 'vendors');
        if (fs_1.default.existsSync(vendorsDir)) {
            const vendors = fs_1.default.readdirSync(vendorsDir).filter(f => fs_1.default.statSync(path_1.default.join(vendorsDir, f)).isDirectory());
            if (vendors.length > 0) {
                console.log(colors.bold('Vendor Overrides:'));
                for (const vendor of vendors) {
                    const vendorPath = path_1.default.join(vendorsDir, vendor);
                    const overrideFiles = fs_1.default.readdirSync(vendorPath).filter(f => f.endsWith('.override.yaml'));
                    if (overrideFiles.length > 0) {
                        console.log(`  ${colors.cyan(vendor)}: ${overrideFiles.length} override(s)`);
                    }
                }
                console.log('');
            }
        }
        // Custom skills
        const customDir = path_1.default.join(SKILLS_DIR, 'custom');
        if (fs_1.default.existsSync(customDir)) {
            const customFiles = fs_1.default.readdirSync(customDir).filter(f => f.endsWith('.skill.yaml'));
            if (customFiles.length > 0) {
                console.log(colors.bold('Custom Skills:'));
                console.log(`  ${customFiles.length} custom skill(s)`);
                console.log('');
            }
        }
    }
    catch (error) {
        console.log(colors.red(`Error: ${error.message}`));
        process.exit(1);
    }
});
//# sourceMappingURL=list.js.map