// engine/ide-config/generators.ts — Per-IDE config generators (SPEC-080 AC-02..AC-08)
import { resolveConfigPath, buildServerEntry, getNpxCommand } from './path-resolver.js';
/**
 * Generate JSON-based config for IDEs that use a standard mcpServers/servers wrapper.
 */
function generateJsonConfig(ide, scope, platform, projectPath) {
    const filePath = resolveConfigPath(ide, scope, platform, projectPath);
    const entry = buildServerEntry(platform);
    const wrapper = {
        [ide.wrapperKey]: {
            planu: entry,
        },
    };
    return {
        filePath,
        content: JSON.stringify(wrapper, null, 2),
        instructions: `Config generated for ${ide.name}. File: ${filePath}`,
    };
}
/**
 * Generate VS Code specific config (AC-02).
 * VS Code 1.102+ uses { "servers": { ... } } with a "type" field.
 */
function generateVscodeConfig(ide, scope, platform, projectPath) {
    const filePath = resolveConfigPath(ide, scope, platform, projectPath);
    const entry = buildServerEntry(platform);
    const config = {
        servers: {
            planu: entry,
        },
    };
    return {
        filePath,
        content: JSON.stringify(config, null, 2),
        instructions: `VS Code MCP config generated at ${filePath}. ` +
            `Requires VS Code 1.102+ with GitHub Copilot extension. ` +
            `Restart VS Code after adding the configuration.`,
    };
}
/**
 * Generate JetBrains specific config (AC-05).
 */
function generateJetbrainsConfig(ide, scope, platform, projectPath) {
    const base = generateJsonConfig(ide, scope, platform, projectPath);
    return {
        ...base,
        instructions: `JetBrains MCP config generated at ${base.filePath}. ` +
            `Enable MCP in Settings > Tools > AI Assistant > Model Context Protocol. ` +
            `Requires JetBrains IDE 2025.1+ with AI Assistant plugin.`,
    };
}
/**
 * Generate Claude Desktop config (AC-06).
 */
function generateClaudeDesktopConfig(ide, _scope, platform, _projectPath) {
    // Claude Desktop always uses global config
    const base = generateJsonConfig(ide, 'global', platform, '');
    return {
        ...base,
        instructions: `Claude Desktop config generated at ${base.filePath}. ` +
            `Restart Claude Desktop to activate the MCP server.`,
    };
}
/**
 * Generate Claude Code config (AC-07).
 */
function generateClaudeCodeConfig(ide, scope, platform, projectPath) {
    const base = generateJsonConfig(ide, scope, platform, projectPath);
    const cliCommand = `claude mcp add planu -- npx -y @anthropic/planu-mcp-server`;
    return {
        ...base,
        instructions: `Claude Code config generated at ${base.filePath}. ` + `Alternatively, run: ${cliCommand}`,
    };
}
/**
 * Generate Neovim Lua config (AC-08).
 */
function generateNeovimConfig(ide, scope, platform, projectPath) {
    const filePath = resolveConfigPath(ide, scope, platform, projectPath);
    const npx = platform === 'win32' ? 'npx.cmd' : 'npx';
    const luaContent = [
        '-- Planu MCP Server configuration for Neovim',
        '-- Compatible with: avante.nvim, codecompanion.nvim, mcphub.nvim',
        '',
        '-- For mcphub.nvim (recommended):',
        '-- Add to your mcphub setup:',
        'return {',
        '  planu = {',
        `    command = "${npx}",`,
        '    args = { "-y", "@anthropic/planu-mcp-server" },',
        '  },',
        '}',
        '',
        '-- For avante.nvim:',
        '-- Add to your avante.nvim config in the mcp_servers table:',
        '-- require("avante").setup({',
        '--   mcp_servers = {',
        '--     planu = {',
        `--       command = "${npx}",`,
        '--       args = { "-y", "@anthropic/planu-mcp-server" },',
        '--     },',
        '--   },',
        '-- })',
        '',
        '-- For codecompanion.nvim:',
        '-- Add to your codecompanion.nvim config:',
        '-- require("codecompanion").setup({',
        '--   adapters = {',
        '--     mcp = {',
        '--       servers = {',
        '--         planu = {',
        `--           command = "${npx}",`,
        '--           args = { "-y", "@anthropic/planu-mcp-server" },',
        '--         },',
        '--       },',
        '--     },',
        '--   },',
        '-- })',
    ].join('\n');
    return {
        filePath,
        content: luaContent,
        instructions: `Neovim MCP config generated at ${filePath}. ` +
            `Integrate with your preferred MCP plugin (mcphub.nvim, avante.nvim, or codecompanion.nvim). ` +
            `See comments in the generated file for integration instructions.`,
    };
}
/**
 * Generate OpenCode config (SPEC-277).
 * opencode.json uses { "mcp": { "planu": { "type": "local", "command": [...] } } }
 * Also notes that .claude/skills/ are natively compatible (opencode searches that path too).
 */
function generateOpencodeConfig(ide, scope, platform, projectPath) {
    const filePath = resolveConfigPath(ide, scope, platform, projectPath);
    const npx = getNpxCommand(platform);
    const config = {
        $schema: 'https://opencode.ai/config.json',
        mcp: {
            planu: {
                type: 'local',
                command: [npx, '-y', '@planu/cli'],
                enabled: true,
            },
        },
    };
    return {
        filePath,
        content: JSON.stringify(config, null, 2),
        instructions: `OpenCode config generated at ${filePath}. ` +
            `Run 'opencode' in your project directory to start. ` +
            `Your existing .claude/skills/ are automatically compatible with OpenCode — no duplication needed.`,
    };
}
/** Map of IDE-specific generators */
const IDE_GENERATORS = {
    vscode: generateVscodeConfig,
    cursor: generateJsonConfig,
    windsurf: generateJsonConfig,
    jetbrains: generateJetbrainsConfig,
    'claude-desktop': generateClaudeDesktopConfig,
    'claude-code': generateClaudeCodeConfig,
    neovim: generateNeovimConfig,
    chatgpt: generateJsonConfig,
    opencode: generateOpencodeConfig,
};
/**
 * Generate config for a specific IDE.
 */
export function generateIdeConfig(ide, scope, platform, projectPath) {
    const generator = IDE_GENERATORS[ide.id];
    return generator(ide, scope, platform, projectPath);
}
//# sourceMappingURL=generators.js.map