// packages/plugin-awf/src/commands/info.ts
// AWF Info Command - Show project info and detected stack
import * as fs from "node:fs";
import * as path from "node:path";
import pc from "picocolors";
const DISPLAY_SKILL_LIMIT = 10;
export async function infoCommand(_args, _flags) {
    const cwd = process.cwd();
    const agentDir = path.join(cwd, ".agent");
    console.log(pc.bold("\n📊 DOMYH Project Info"));
    console.log(pc.gray("─".repeat(60)));
    // Status
    const isInitialized = fs.existsSync(agentDir);
    console.log(`\n  ${pc.bold("Status:")} ${isInitialized ? pc.green("Initialized") : pc.yellow("Not initialized")}`);
    console.log(`  ${pc.bold("Path:")} ${cwd}`);
    // Detect project type
    const projectType = detectProjectType(cwd);
    console.log(`\n  ${pc.bold("Detected Stack:")}`);
    console.log(`    Type: ${pc.cyan(projectType.type)}`);
    console.log(`    Language: ${pc.cyan(projectType.language)}`);
    if (projectType.framework) {
        console.log(`    Framework: ${pc.cyan(projectType.framework)}`);
    }
    // Recommended skills
    if (projectType.skills.length > 0) {
        console.log(`\n  ${pc.bold("Recommended Skills:")}`);
        for (const skill of projectType.skills) {
            console.log(`    ${pc.green("→")} ${skill}`);
        }
    }
    // Installed skills
    if (isInitialized) {
        const stateFile = path.join(agentDir, "memory/state.json");
        if (fs.existsSync(stateFile)) {
            try {
                const state = JSON.parse(fs.readFileSync(stateFile, "utf-8"));
                const skills = state.skills || [];
                console.log(`\n  ${pc.bold("Installed Skills:")} ${pc.cyan(skills.length.toString())}`);
                if (skills.length > 0 && skills.length <= DISPLAY_SKILL_LIMIT) {
                    for (const skill of skills) {
                        console.log(`    ${pc.green("✓")} ${skill}`);
                    }
                }
                else if (skills.length > DISPLAY_SKILL_LIMIT) {
                    for (const skill of skills.slice(0, DISPLAY_SKILL_LIMIT)) {
                        console.log(`    ${pc.green("✓")} ${skill}`);
                    }
                    console.log(pc.dim(`    ... and ${skills.length - DISPLAY_SKILL_LIMIT} more`));
                }
            }
            catch {
                // Ignore parse errors
            }
        }
        // Workflows
        const workflowsDir = path.join(agentDir, "workflows");
        if (fs.existsSync(workflowsDir)) {
            try {
                const workflows = fs.readdirSync(workflowsDir).filter(f => f.endsWith(".md"));
                console.log(`\n  ${pc.bold("Installed Workflows:")} ${pc.cyan(workflows.length.toString())}`);
            }
            catch {
                // Ignore
            }
        }
    }
    // Quick actions
    console.log("\n" + pc.gray("─".repeat(60)));
    console.log(pc.bold("Quick Actions:"));
    if (!isInitialized) {
        console.log(`  ${pc.cyan("nock awf init")}        - Initialize DOMYH in this project`);
    }
    else {
        console.log(`  ${pc.cyan("nock awf list")}        - List available skills and workflows`);
        console.log(`  ${pc.cyan("nock awf add <skill>")} - Add a specific skill`);
        console.log(`  ${pc.cyan("nock awf update")}      - Update to latest version`);
    }
    console.log();
}
function detectProjectType(cwd) {
    const skills = [];
    let type = "Generic";
    let language = "Unknown";
    let framework;
    // Check for package.json (Node.js)
    if (fs.existsSync(path.join(cwd, "package.json"))) {
        type = "Node.js";
        language = "JavaScript";
        skills.push("javascript");
        try {
            const pkg = JSON.parse(fs.readFileSync(path.join(cwd, "package.json"), "utf-8"));
            const deps = { ...pkg.dependencies, ...pkg.devDependencies };
            if (deps.typescript) {
                language = "TypeScript";
                skills.push("typescript");
            }
            if (deps.react || deps["react-dom"]) {
                framework = "React";
                skills.push("react");
            }
            if (deps.next) {
                framework = "Next.js";
                skills.push("nextjs");
            }
            if (deps.vue) {
                framework = "Vue";
                skills.push("vue");
            }
            if (deps["@angular/core"]) {
                framework = "Angular";
                skills.push("angular");
            }
            if (deps.svelte) {
                framework = "Svelte";
                skills.push("svelte");
            }
        }
        catch {
            // Ignore parse errors
        }
    }
    // Check for Python
    if (fs.existsSync(path.join(cwd, "requirements.txt")) ||
        fs.existsSync(path.join(cwd, "pyproject.toml"))) {
        type = "Python";
        language = "Python";
        skills.push("python");
    }
    // Check for Go
    if (fs.existsSync(path.join(cwd, "go.mod"))) {
        type = "Go";
        language = "Go";
        skills.push("go");
    }
    // Check for Rust
    if (fs.existsSync(path.join(cwd, "Cargo.toml"))) {
        type = "Rust";
        language = "Rust";
        skills.push("rust");
    }
    // Check for .NET
    if (fs.readdirSync(cwd).some(f => f.endsWith(".csproj") || f.endsWith(".sln"))) {
        type = ".NET";
        language = "C#";
        skills.push("csharp");
    }
    return { type, language, framework, skills };
}
