"use strict";
/**
 * Cursor + Windsurf are IDE forks of VSCode that share the
 * `{ mcpServers: { ... } }` JSON shape (same as Gemini/Kimi). Neither
 * ships an `mcp add` CLI — direct JSON edit. Detection looks for the
 * config dir (Cursor/Windsurf is installed); the mcp.json itself
 * usually doesn't exist until first registration.
 */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.windsurfOrchestrator = exports.cursorOrchestrator = void 0;
const node_fs_1 = __importDefault(require("node:fs"));
const node_os_1 = __importDefault(require("node:os"));
const node_path_1 = __importDefault(require("node:path"));
const shared_js_1 = require("./shared.js");
const CURSOR_CONFIG_DIR = node_path_1.default.join(node_os_1.default.homedir(), '.cursor');
const CURSOR_MCP_PATH = node_path_1.default.join(CURSOR_CONFIG_DIR, 'mcp.json');
const WINDSURF_CONFIG_DIR = node_path_1.default.join(node_os_1.default.homedir(), '.codeium', 'windsurf');
const WINDSURF_MCP_PATH = node_path_1.default.join(WINDSURF_CONFIG_DIR, 'mcp_config.json');
function getCursorStatus() {
    const detected = node_fs_1.default.existsSync(CURSOR_CONFIG_DIR);
    const connected = detected && (0, shared_js_1.hasMcpEntry)(CURSOR_MCP_PATH);
    return {
        name: 'cursor',
        label: 'Cursor',
        connected,
        approvedTools: connected ? 1 : 0,
        totalTools: 1,
        note: 'Registers Chorus in ~/.cursor/mcp.json. Cursor will prompt on first tool call — choose "Always allow" to make it stick.',
        supported: detected,
        firstCallBehavior: 'prompts_once',
    };
}
async function connectCursor(opts) {
    if ((0, shared_js_1.hasMcpEntry)(CURSOR_MCP_PATH, opts.binPath)) {
        return {
            added: [],
            alreadyPresent: ['mcpServers.chorus'],
            configPath: CURSOR_MCP_PATH,
            slashCommand: 'skipped',
            slashCommandPath: '',
        };
    }
    (0, shared_js_1.writeMcpEntry)({
        filePath: CURSOR_MCP_PATH,
        binPath: opts.binPath,
        daemonUrl: opts.daemonUrl ?? shared_js_1.DEFAULT_DAEMON_URL,
    });
    return {
        added: ['mcpServers.chorus'],
        alreadyPresent: [],
        configPath: CURSOR_MCP_PATH,
        slashCommand: 'skipped',
        slashCommandPath: '',
    };
}
function getWindsurfStatus() {
    const detected = node_fs_1.default.existsSync(WINDSURF_CONFIG_DIR);
    const connected = detected && (0, shared_js_1.hasMcpEntry)(WINDSURF_MCP_PATH);
    return {
        name: 'windsurf',
        label: 'Windsurf',
        connected,
        approvedTools: connected ? 1 : 0,
        totalTools: 1,
        note: 'Registers Chorus in ~/.codeium/windsurf/mcp_config.json. Windsurf will prompt on first tool call — choose "Always allow".',
        supported: detected,
        firstCallBehavior: 'prompts_once',
    };
}
async function connectWindsurf(opts) {
    if ((0, shared_js_1.hasMcpEntry)(WINDSURF_MCP_PATH, opts.binPath)) {
        return {
            added: [],
            alreadyPresent: ['mcpServers.chorus'],
            configPath: WINDSURF_MCP_PATH,
            slashCommand: 'skipped',
            slashCommandPath: '',
        };
    }
    (0, shared_js_1.writeMcpEntry)({
        filePath: WINDSURF_MCP_PATH,
        binPath: opts.binPath,
        daemonUrl: opts.daemonUrl ?? shared_js_1.DEFAULT_DAEMON_URL,
    });
    return {
        added: ['mcpServers.chorus'],
        alreadyPresent: [],
        configPath: WINDSURF_MCP_PATH,
        slashCommand: 'skipped',
        slashCommandPath: '',
    };
}
exports.cursorOrchestrator = {
    name: 'cursor',
    label: 'Cursor',
    getStatus: getCursorStatus,
    detect: () => node_fs_1.default.existsSync(CURSOR_CONFIG_DIR),
    connect: async (opts) => {
        const before = (0, shared_js_1.hasMcpEntry)(CURSOR_MCP_PATH, opts.binPath);
        const full = await connectCursor(opts);
        return { registered: !before, toolsAdded: 0, full };
    },
};
exports.windsurfOrchestrator = {
    name: 'windsurf',
    label: 'Windsurf',
    getStatus: getWindsurfStatus,
    detect: () => node_fs_1.default.existsSync(WINDSURF_CONFIG_DIR),
    connect: async (opts) => {
        const before = (0, shared_js_1.hasMcpEntry)(WINDSURF_MCP_PATH, opts.binPath);
        const full = await connectWindsurf(opts);
        return { registered: !before, toolsAdded: 0, full };
    },
};
//# sourceMappingURL=cursor-windsurf.js.map