"use strict";
/**
 * Cross-orchestrator constants, types, and small JSON helpers reused by
 * Cursor + Windsurf (they share the `{ mcpServers: ... }` JSON shape).
 */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEFAULT_DAEMON_URL = exports.CHORUS_TOOLS = exports.execFileAsync = void 0;
exports.hasMcpEntry = hasMcpEntry;
exports.writeMcpEntry = writeMcpEntry;
const node_child_process_1 = require("node:child_process");
const node_fs_1 = __importDefault(require("node:fs"));
const node_path_1 = __importDefault(require("node:path"));
const node_util_1 = require("node:util");
exports.execFileAsync = (0, node_util_1.promisify)(node_child_process_1.execFile);
exports.CHORUS_TOOLS = [
    'mcp__chorus__create_chat',
    'mcp__chorus__wait_for_chat',
    'mcp__chorus__get_chat_status',
    'mcp__chorus__list_blocked',
    'mcp__chorus__resume_chat',
    'mcp__chorus__cancel_chat',
    'mcp__chorus__list_templates',
];
exports.DEFAULT_DAEMON_URL = 'http://127.0.0.1:7707';
function readJsonOrEmpty(filePath) {
    if (!node_fs_1.default.existsSync(filePath))
        return {};
    try {
        return JSON.parse(node_fs_1.default.readFileSync(filePath, 'utf-8'));
    }
    catch {
        return {};
    }
}
function hasMcpEntry(filePath, expectedBinPath) {
    const cfg = readJsonOrEmpty(filePath);
    const chorus = cfg.mcpServers
        ?.chorus;
    if (!chorus)
        return false;
    if (!expectedBinPath)
        return true;
    return Array.isArray(chorus.args) && chorus.args.includes(expectedBinPath);
}
function writeMcpEntry(opts) {
    const cfg = readJsonOrEmpty(opts.filePath);
    const servers = (cfg.mcpServers ?? {});
    servers.chorus = {
        command: 'node',
        args: [opts.binPath, 'mcp'],
        env: { CHORUS_DAEMON_URL: opts.daemonUrl },
    };
    const next = { ...cfg, mcpServers: servers };
    node_fs_1.default.mkdirSync(node_path_1.default.dirname(opts.filePath), { recursive: true });
    node_fs_1.default.writeFileSync(opts.filePath, JSON.stringify(next, null, 2) + '\n', 'utf-8');
}
//# sourceMappingURL=shared.js.map