// packages/plugin-awf/src/constants/ides.ts
// Unified IDE registry - Single Source of Truth
// Upgraded: 24 IDEs with tiers and global paths (Mar 2026)
// Deep Audit v2: 12 corrections applied (Feb 7, 2026)
// Deep Verification: 13 fixes verified from official docs (Feb 7, 2026)
// Official Docs Verification: 7 corrections from 13+ URLs (Feb 7, 2026)
// Platform Audit: Removed Bolt.new (web-only), Void (paused), Supermaven (sunset)
// Sources: docs.windsurf.com, docs.roocode.com, opencode.ai, zed.dev, aws docs, etc.
import { homedir } from "node:os";
import { join } from "node:path";
/**
 * Tier selection constants
 */
export const TIER_SELECTION = {
    ALL: "__ALL__",
    TIER0: "__TIER0__",
    TIER1: "__TIER1__",
    TIER2: "__TIER2__",
    TIER3: "__TIER3__",
};
/**
 * Master IDE registry - 24 IDEs in 4 tiers (Mar 2026)
 * Deep Audit v2: Codex path fix, VS Code+Copilot merge, Antigravity→Tier 1
 * Platform Audit: Removed Bolt.new (web-only), Void (paused), Supermaven (sunset)
 * P0: Added globalPath for global install support
 * P1: Skills, MCP, Rules support flags (verified research)
 */
export const IDE_REGISTRY = [
    // ══════════════════════════════════════════════════════════════
    // TIER 0: Just Launched (Feb 2026) - Priority Integration
    // ══════════════════════════════════════════════════════════════
    {
        value: "codex",
        label: "OpenAI Codex",
        displayName: "OpenAI Codex CLI/Desktop",
        rulePath: ".agents",
        globalPath: join(homedir(), ".codex"),
        rootConfigFile: "AGENTS.md",
        tier: 0,
        extension: ".md",
        mcp: { supported: true, configPath: "~/.codex/config.toml", format: "toml" },
        skills: { supported: true, path: ".agents/skills/" },
    },
    // ══════════════════════════════════════════════════════════════
    // TIER 1: Major IDEs (6)
    // ══════════════════════════════════════════════════════════════
    {
        value: "cursor",
        label: "Cursor",
        displayName: "Cursor",
        rulePath: ".cursor/rules",
        globalPath: join(homedir(), ".cursor"),
        configFile: ".cursorrules",
        tier: 1,
        extension: ".mdc",
        mcp: { supported: true, configPath: ".cursor/mcp.json", format: "json" }, // Deep Audit v5: cursor.com/docs
        skills: { supported: true, path: ".cursor/skills/" },
    },
    {
        value: "claude",
        label: "Claude Code",
        displayName: "Claude Code",
        rulePath: ".claude",
        globalPath: join(homedir(), ".claude"),
        rootConfigFile: "CLAUDE.md",
        tier: 1,
        extension: ".md",
        // Deep Verification: Desktop = OS-specific path, CLI = ~/.claude.json + .mcp.json
        mcp: { supported: true, configPath: ".mcp.json", format: "json" },
    },
    {
        value: "gemini",
        label: "Gemini CLI",
        displayName: "Gemini CLI / Antigravity",
        rulePath: ".gemini",
        globalPath: join(homedir(), ".gemini"),
        rootConfigFile: "GEMINI.md",
        tier: 1,
        extension: ".md",
        mcp: { supported: true, configPath: "~/.gemini/settings.json", format: "json" }, // Deep Audit v5: Gemini CLI MCP config
    },
    {
        // Deep Audit v2: Merged VS Code + GitHub Copilot into single entry
        // Copilot IS the agent in VS Code — same config paths
        value: "vscode",
        label: "VS Code + Copilot",
        displayName: "VS Code + GitHub Copilot",
        rulePath: ".github",
        // v6.4.12: Global install → VS Code user profile (prompts, agents, instructions)
        // Insiders: %APPDATA%/Code - Insiders/User/, Stable: %APPDATA%/Code/User/
        globalPath: join(process.env.APPDATA || homedir(), "Code - Insiders", "User"),
        configFile: ".github/copilot-instructions.md",
        tier: 1,
        extension: ".md",
        mcp: { supported: true, configPath: ".vscode/mcp.json", format: "json" },
        // Deep Verification v3: VS Code v1.108 (Dec 2025) added Agent Skills (.github/skills/SKILL.md)
        // Also recognizes .claude/skills/ for backward compat. Setting: chat.useAgentSkills
        skills: { supported: true, path: ".github/skills/" },
    },
    {
        // Official Docs Verification: Windsurf HAS Skills (docs.windsurf.com/windsurf/cascade/skills)
        // Project: .windsurf/skills/<name>/SKILL.md, Global: ~/.codeium/windsurf/skills/<name>/SKILL.md
        value: "windsurf",
        label: "Windsurf",
        displayName: "Windsurf (Codeium)",
        rulePath: ".windsurf/rules",
        globalPath: join(homedir(), ".codeium", "windsurf"),
        configFile: ".windsurfrules",
        tier: 1,
        extension: ".md",
        mcp: { supported: true, configPath: "~/.codeium/windsurf/mcp_config.json", format: "json" }, // Deep Audit v5: docs.windsurf.com
        skills: { supported: true, path: ".windsurf/skills/" },
    },
    // ══════════════════════════════════════════════════════════════
    // TIER 2: Popular Agents (12) - Updated Feb 2026
    // ══════════════════════════════════════════════════════════════
    {
        value: "cline",
        label: "Cline",
        displayName: "Cline (VS Code)",
        rulePath: ".clinerules",
        globalPath: join(homedir(), "Documents", "Cline", "Rules"),
        configFile: ".clinerules",
        tier: 2,
        extension: ".md",
        mcp: { supported: true, format: "json" },
        skills: { supported: true, path: ".cline/skills/" },
    },
    {
        value: "continue",
        label: "Continue.dev",
        displayName: "Continue.dev",
        rulePath: ".continue/rules",
        globalPath: join(homedir(), ".continue"),
        tier: 2,
        extension: ".md",
        mcp: { supported: true, configPath: "~/.continue/config.yaml", format: "yaml" }, // Global: mcpServers key in config.yaml
    },
    {
        // Official Docs Verification: Roo Code HAS Skills (docs.roocode.com/features/skills)
        // Project: .roo/skills/, Global: ~/.roo/skills/, Mode-specific: .roo/skills-{mode}/
        // 4-level override: Project mode > Project generic > Global mode > Global generic
        value: "roo",
        label: "Roo Code",
        displayName: "Roo Code (VS Code)",
        rulePath: ".roo/rules",
        globalPath: join(homedir(), ".roo"),
        configFile: ".roorules",
        tier: 2,
        extension: ".md",
        mcp: { supported: true, configPath: ".roo/mcp.json", format: "json" },
        skills: { supported: true, path: ".roo/skills/" },
    },
    {
        value: "jetbrains",
        label: "JetBrains AI",
        displayName: "JetBrains AI (Junie)",
        rulePath: ".junie/guidelines",
        globalPath: join(homedir(), ".junie"), // Deep Audit v5: global MCP at ~/.junie/mcp.json
        rootConfigFile: ".junie/guidelines.md",
        tier: 2,
        extension: ".md",
        // Deep Verification: filename is mcp.json, not servers.json
        mcp: { supported: true, configPath: ".junie/mcp/mcp.json", format: "json" },
        skills: { supported: true, path: ".junie/skills/" },
    },
    {
        // Official Docs Verification: Amazon Q HAS MCP (aws.com/blogs, mid-2025)
        // Project: .amazonq/mcp.json, Global: ~/.aws/amazonq/mcp.json
        value: "amazonq",
        label: "Amazon Q",
        displayName: "Amazon Q Developer",
        rulePath: ".amazonq/rules",
        globalPath: join(homedir(), ".aws", "amazonq"),
        tier: 2,
        extension: ".md",
        mcp: { supported: true, configPath: ".amazonq/mcp.json", format: "json" },
    },
    {
        value: "kiro",
        label: "Kiro",
        displayName: "Kiro (AWS)",
        rulePath: ".kiro/steering", // Deep Audit v5: aligned with ide-install-specs.ts rules.target
        globalPath: join(homedir(), ".kiro"), // Deep Audit v5: kiro.dev global steering + skills
        tier: 2,
        extension: ".md",
        mcp: { supported: true, configPath: ".kiro/settings/mcp.json", format: "json" },
        skills: { supported: true, path: ".kiro/skills/" },
    },
    {
        // Official Docs Verification: Zed HAS MCP (zed.dev/docs/ai/mcp) via context_servers in settings.json
        // Also HAS Rules (zed.dev/docs/ai/rules): .rules file + compat (.cursorrules, CLAUDE.md, GEMINI.md etc.)
        value: "zed",
        label: "Zed",
        displayName: "Zed Editor",
        rulePath: ".zed",
        configFile: ".rules",
        tier: 2,
        extension: ".json",
        mcp: { supported: true, configPath: "settings.json", format: "json" },
    },
    {
        value: "aider",
        label: "Aider",
        displayName: "Aider AI",
        rulePath: "CONVENTIONS.md",
        globalPath: join(homedir(), ".aider.conf.yml"),
        tier: 2,
        extension: ".md",
    },
    {
        value: "coderabbit",
        label: "CodeRabbit",
        displayName: "CodeRabbit",
        rulePath: ".coderabbit",
        tier: 2,
        extension: ".yaml",
    },
    {
        // Deep Audit v3: MCP added May 27, 2025 (agentic context gathering)
        // Config: ~/.config/cody/mcp_servers.json (macOS/Linux), %USERPROFILE%\.config\cody\mcp_servers.json (Windows)
        value: "cody",
        label: "Cody",
        displayName: "Sourcegraph Cody",
        rulePath: ".cody",
        configFile: ".cody/commands.json",
        tier: 2,
        extension: ".json",
        mcp: { supported: true, configPath: "~/.config/cody/mcp_servers.json", format: "json" },
    },
    {
        value: "tabnine",
        label: "Tabnine",
        displayName: "Tabnine Enterprise",
        rulePath: ".tabnine/guidelines",
        globalPath: join(homedir(), ".tabnine"),
        tier: 2,
        extension: ".md",
        mcp: { supported: true, configPath: ".tabnine/mcp_servers.json", format: "json" },
    },
    {
        value: "trae",
        label: "Trae AI",
        displayName: "Trae AI",
        rulePath: ".trae",
        globalPath: join(homedir(), ".trae"),
        configFile: ".rules",
        tier: 2,
        extension: ".md",
        mcp: { supported: true, configPath: ".trae/mcp.json", format: "json" },
        skills: { supported: true, path: ".trae/skills/" },
    },
    {
        // Blackbox AI — IDE + VS Code extension
        // Skills: .blackbox/skills/{name}/SKILL.md (flat, 1-level scan)
        // MCP: VS Code globalStorage → blackboxapp.blackboxagent/settings/blackbox_mcp_settings.json
        // No project-local MCP — only global via VS Code extension globalStorage
        value: "blackbox",
        label: "Blackbox AI",
        displayName: "Blackbox AI",
        rulePath: ".blackbox",
        globalPath: join(homedir(), ".blackbox"),
        tier: 2,
        extension: ".md",
        mcp: { supported: true, configPath: ".blackbox/mcp.json", format: "json" },
        skills: { supported: true, path: ".blackbox/skills/" },
    },
    // ══════════════════════════════════════════════════════════════
    // TIER 3: Extended Agents (4) + Antigravity (tier:1, placed here for code organization)
    // ══════════════════════════════════════════════════════════════
    {
        // Deep Audit v2: Amp migrated custom commands → skills (Jan 2026)
        value: "amp",
        label: "Amp",
        displayName: "Amp AI (Sourcegraph)",
        rulePath: ".agents",
        rootConfigFile: "AGENTS.md",
        tier: 3,
        extension: ".md",
        mcp: { supported: true, configPath: ".vscode/mcp.json", format: "json" },
        skills: { supported: true, path: ".agents/skills/" },
    },
    {
        // Deep Audit v4: Antigravity has SEPARATE paths from Gemini CLI
        // Workspace: .agent/skills/, .agent/workflows/, .agent/rules/
        // Global: ~/.gemini/antigravity/skills/, ~/.gemini/antigravity/global_workflows/
        value: "antigravity",
        label: "Antigravity",
        displayName: "Antigravity (Google Official IDE)",
        rulePath: ".agent/rules", // Official: workspace rules at .agent/rules/
        globalPath: join(homedir(), ".gemini", "antigravity"),
        rootConfigFile: "GEMINI.md",
        tier: 1,
        extension: ".md",
        mcp: { supported: true, configPath: "~/.gemini/antigravity/mcp_config.json", format: "json" },
        skills: { supported: true, path: ".agent/skills/" },
    },
    {
        // Official Docs Verification (Mar 2026): opencode.ai/docs/
        // MCP via opencode.json "mcp" section: { type:"local", command:[], environment:{} }
        // Skills: .opencode/skills/<name>/SKILL.md, global: ~/.config/opencode/skills/
        // Commands: .opencode/commands/*.md, global: ~/.config/opencode/commands/
        // Rules: AGENTS.md at project root, global: ~/.config/opencode/AGENTS.md
        value: "opencode",
        label: "OpenCode",
        displayName: "OpenCode",
        rulePath: ".opencode",
        globalPath: join(homedir(), ".config", "opencode"),
        tier: 3,
        extension: ".md",
        mcp: { supported: true, configPath: "opencode.json", format: "json" },
        skills: { supported: true, path: ".opencode/skills/" },
    },
    // Removed: Bolt.new (web-only, no file system), Void (paused Jan 2026), Supermaven (sunset→Cursor)
    {
        // OpenClaw (openclaw.ai) — Autonomous AI agent
        // MCP: ~/.openclaw/openclaw.json { mcp: { name: { type:"local", command:[], environment:{} } } }
        // Skills: ~/.openclaw/skills/{name}/SKILL.md (flat, ClawHub format)
        // Config: ~/.openclaw/openclaw.json (global only — chat-based agent)
        value: "openclaw",
        label: "OpenClaw",
        displayName: "OpenClaw",
        rulePath: ".openclaw",
        globalPath: join(homedir(), ".openclaw"),
        tier: 3,
        extension: ".md",
        mcp: { supported: true, configPath: "openclaw.json", format: "json" },
        skills: { supported: true, path: ".openclaw/skills/" },
    },
    {
        // Deep Verification: Skills at 3 compatible locations
        // .augment/skills/, .claude/skills/, .agents/skills/ (+ global equivalents)
        // Hierarchical rules via AGENTS.md + CLAUDE.md at any directory level
        value: "augment",
        label: "Augment",
        displayName: "Augment Code",
        rulePath: ".augment",
        globalPath: join(homedir(), ".augment"),
        tier: 3,
        extension: ".md",
        mcp: { supported: true, configPath: "~/.augment/settings.json", format: "json" },
        skills: { supported: true, path: ".augment/skills/" },
    },
];
// ══════════════════════════════════════════════════════════════
// Helper Functions
// ══════════════════════════════════════════════════════════════
/**
 * Get IDEs by tier
 */
export function getIDEsByTier(tier) {
    return IDE_REGISTRY.filter((ide) => ide.tier === tier);
}
/**
 * Get tier 0 IDEs only (just launched)
 */
export function getTier0IDEs() {
    return getIDEsByTier(0);
}
/**
 * Get tier 1 IDEs only
 */
export function getTier1IDEs() {
    return getIDEsByTier(1);
}
/**
 * Get IDE options for multiselect prompts with tier grouping
 */
export function getIDEOptions() {
    return IDE_REGISTRY.map((ide) => ({
        value: ide.value,
        label: ide.label,
        hint: ide.tier === 0 ? "🆕 New" : ide.tier === 1 ? "Major" : ide.tier === 2 ? "Popular" : undefined,
    }));
}
/**
 * Get IDE options with tier headers for advanced selection
 */
export function getIDEOptionsWithTiers() {
    const tier0 = getIDEsByTier(0);
    const tier1 = getIDEsByTier(1);
    const tier2 = getIDEsByTier(2);
    const tier3 = getIDEsByTier(3);
    return [
        // Select All
        { value: TIER_SELECTION.ALL, label: "✅ Select All", hint: `${IDE_REGISTRY.length} IDEs` },
        // Tier 0
        ...(tier0.length > 0 ? [
            { value: TIER_SELECTION.TIER0, label: "🆕 Tier 0: Just Launched", hint: `${tier0.length} items` },
            ...tier0.map((ide) => ({ value: ide.value, label: `   ${ide.displayName}` })),
        ] : []),
        // Tier 1
        { value: TIER_SELECTION.TIER1, label: "⭐ Tier 1: Major IDEs", hint: `${tier1.length} items` },
        ...tier1.map((ide) => ({ value: ide.value, label: `   ${ide.displayName}` })),
        // Tier 2
        { value: TIER_SELECTION.TIER2, label: "📦 Tier 2: Popular Agents", hint: `${tier2.length} items` },
        ...tier2.map((ide) => ({ value: ide.value, label: `   ${ide.displayName}` })),
        // Tier 3
        { value: TIER_SELECTION.TIER3, label: "🔧 Tier 3: Extended", hint: `${tier3.length} items` },
        ...tier3.map((ide) => ({ value: ide.value, label: `   ${ide.displayName}` })),
    ];
}
/**
 * Resolve selected IDEs from tier selection
 */
export function resolveIDESelection(selected) {
    if (selected.includes(TIER_SELECTION.ALL)) {
        return IDE_REGISTRY;
    }
    const resolved = [];
    if (selected.includes(TIER_SELECTION.TIER0)) {
        resolved.push(...getIDEsByTier(0));
    }
    if (selected.includes(TIER_SELECTION.TIER1)) {
        resolved.push(...getIDEsByTier(1));
    }
    if (selected.includes(TIER_SELECTION.TIER2)) {
        resolved.push(...getIDEsByTier(2));
    }
    if (selected.includes(TIER_SELECTION.TIER3)) {
        resolved.push(...getIDEsByTier(3));
    }
    // Add individual selections
    const individual = selected.filter((s) => !s.startsWith("__"));
    for (const id of individual) {
        const ide = getIDEByValue(id);
        if (ide && !resolved.some((r) => r.value === ide.value)) {
            resolved.push(ide);
        }
    }
    return resolved;
}
/**
 * Get IDE by value/key
 */
export function getIDEByValue(value) {
    return IDE_REGISTRY.find((ide) => ide.value === value);
}
/**
 * Get all IDE values/keys
 */
export function getIDEValues() {
    return IDE_REGISTRY.map((ide) => ide.value);
}
/**
 * Get IDEs that support global installation
 */
export function getGlobalSupportedIDEs() {
    return IDE_REGISTRY.filter((ide) => ide.globalPath);
}
