/**
 * AGENTS.md Generator
 *
 * Generates a universal AGENTS.md file for ALL AI coding tools EXCEPT Claude Code.
 * Follows the agents.md standard: https://agents.md/
 *
 * IMPORTANT:
 * - Claude Code does NOT read this file - it only reads CLAUDE.md
 * - This file is for: Cursor, GitHub Copilot, ChatGPT, Gemini, and ANY other AI tool
 *
 * This ONE file replaces:
 * - .cursorrules (Cursor - legacy)
 * - .github/copilot/instructions.md (Copilot - no longer needed, Copilot reads AGENTS.md)
 * - Any other tool-specific configuration files
 */
import { DocGenerator } from './doc-generator.js';
import * as fs from '../utils/fs-native.js';
import { getDirname } from '../utils/esm-helpers.js';
import { findTemplateFile } from './template-utils.js';
const __dirname = getDirname(import.meta.url);
/**
 * Generate universal AGENTS.md file
 */
export class AgentsMdGenerator {
    constructor(skillsDir, agentsDir, commandsDir) {
        this.docGen = new DocGenerator(skillsDir, agentsDir, commandsDir);
    }
    /**
     * Generate complete AGENTS.md content
     */
    async generate(options) {
        // Read template - use provided path or find it via package root
        let templatePath = options.templatePath;
        if (!templatePath || !await fs.pathExists(templatePath)) {
            const foundPath = findTemplateFile('AGENTS.md.template', __dirname);
            if (foundPath) {
                templatePath = foundPath;
            }
            else {
                throw new Error('AGENTS.md template not found');
            }
        }
        let content = await fs.readFile(templatePath, 'utf-8');
        // Extract agents and skills
        const skills = await this.docGen.extractSkills();
        const agents = await this.docGen.extractAgents();
        // Replace placeholders
        content = content.replace(/\{PROJECT_NAME\}/g, options.projectName);
        content = content.replace('{AGENTS_SECTION}', this.generateAgentsSection(agents));
        content = content.replace('{SKILLS_SECTION}', this.generateSkillsSection(skills));
        content = content.replace('{TIMESTAMP}', new Date().toISOString().split('T')[0]);
        return content;
    }
    /**
     * Generate agents section as simple Markdown
     */
    generateAgentsSection(agents) {
        let section = '';
        for (const agent of agents) {
            section += `### ${agent.role}\n`;
            section += `**Purpose**: ${agent.description}\n`;
            section += `**When to use**: ${this.getAgentActivation(agent.name)}\n`;
            section += `**Location**: \`.claude/agents/${agent.name}/AGENT.md\`\n\n`;
        }
        return section;
    }
    /**
     * Get agent activation guidance
     */
    getAgentActivation(agentName) {
        const activations = {
            'pm': 'Creating requirements, user stories, product specs (WHAT/WHY)',
            'architect': 'System design, architecture decisions, technical plans (HOW)',
            'devops': 'Infrastructure, deployment, CI/CD pipelines',
            'qa-engineer': 'Test strategy, test cases, quality assurance',
            'security': 'Threat modeling, security review, vulnerability assessment',
            'nodejs-backend': 'Node.js/Express/NestJS backend APIs',
            'python-backend': 'FastAPI/Django backend APIs',
            'nextjs': 'Next.js App Router applications',
            'dotnet-backend': 'ASP.NET Core backend APIs',
            'sre': 'Incident response, troubleshooting, runbooks',
            'docs-writer': 'Technical documentation, API docs, guides',
            'performance': 'Performance optimization, profiling, benchmarking'
        };
        return activations[agentName] || 'Specialized tasks requiring this expertise';
    }
    /**
     * Generate skills section as simple Markdown
     */
    generateSkillsSection(skills) {
        let section = '';
        for (const skill of skills) {
            section += `### ${skill.name}\n`;
            section += `**Purpose**: ${skill.description}\n`;
            section += `**When to use**: ${this.getSkillActivation(skill.name)}\n`;
            section += `**Location**: \`.claude/skills/${skill.name}/SKILL.md\`\n\n`;
        }
        return section;
    }
    /**
     * Get skill activation guidance
     */
    getSkillActivation(skillName) {
        const activations = {
            'specweave-detector': 'User asks about SpecWeave commands or workflows',
            'increment': 'Creating new feature increments (sw:increment command)',
            'context-loader': 'Working on increments, need to load relevant context',
            'skill-router': 'Ambiguous requests that need routing to specific skills',
            'spec-driven-debugging': 'Bug investigation, test failures, unexpected behavior',
            'brainstorm': 'Multi-perspective ideation, brainstorming, design thinking, tree of thought exploration',
            'nodejs-backend': 'Node.js/Express/NestJS backend development',
            'python-backend': 'Python/FastAPI/Django backend development',
            'nextjs': 'Next.js App Router application development',
            'dotnet-backend': 'ASP.NET Core backend development',
            'e2e-playwright': 'End-to-end testing with Playwright',
            'jira-sync': 'JIRA integration and synchronization',
            'github-sync': 'GitHub issues/milestones synchronization',
            'ado-sync': 'Azure DevOps synchronization',
            'hetzner-provisioner': 'Hetzner Cloud infrastructure provisioning',
            'cost-optimizer': 'Cloud cost optimization and platform comparison',
            'figma': 'Figma design-to-code, design tokens, Code Connect, design system rules',
            'design-system-architect': 'Design system and Atomic Design methodology',
            'role-orchestrator': 'Multi-agent orchestration for complex tasks',
            'increment-quality-judge': 'AI-powered quality assessment of specs and plans'
        };
        return activations[skillName] || 'Specialized tasks';
    }
}
//# sourceMappingURL=agents-md-generator.js.map