import { existsSync, readFileSync } from "node:fs";
import { homedir } from "node:os";
import { join } from "node:path";
import TOML from "@iarna/toml";
const SPECS = [
  { id: "claude-code", displayName: "Claude Code", format: "cli", relPath: "", keyPath: [] },
  { id: "cursor", displayName: "Cursor", format: "json", relPath: ".cursor/mcp.json", keyPath: ["mcpServers", "wigolo"] },
  { id: "vscode", displayName: "VS Code", format: "json", relPath: ".vscode/mcp.json", keyPath: ["servers", "wigolo"] },
  { id: "zed", displayName: "Zed", format: "json", relPath: ".config/zed/settings.json", keyPath: ["context_servers", "wigolo"] },
  { id: "gemini-cli", displayName: "Gemini CLI", format: "json", relPath: ".gemini/settings.json", keyPath: ["mcpServers", "wigolo"] },
  { id: "windsurf", displayName: "Windsurf", format: "json", relPath: ".codeium/windsurf/mcp_config.json", keyPath: ["mcpServers", "wigolo"] },
  { id: "opencode", displayName: "OpenCode", format: "json", relPath: ".config/opencode/config.json", keyPath: ["mcp", "wigolo"] },
  { id: "codex", displayName: "Codex", format: "toml", relPath: ".codex/config.toml", keyPath: ["mcp_servers", "wigolo"] }
];
function readConnectedAgents(opts = {}) {
  const home = opts.home ?? homedir();
  const out = [];
  for (const spec of SPECS) {
    if (spec.format === "cli") {
      out.push({ id: spec.id, displayName: spec.displayName, configured: false, path: "(use `claude mcp list`)" });
      continue;
    }
    const abs = join(home, spec.relPath);
    if (!existsSync(abs)) {
      out.push({ id: spec.id, displayName: spec.displayName, configured: false, path: abs });
      continue;
    }
    let parsed;
    try {
      const raw = readFileSync(abs, "utf-8");
      parsed = spec.format === "toml" ? TOML.parse(raw) : JSON.parse(raw);
    } catch {
      out.push({ id: spec.id, displayName: spec.displayName, configured: false, path: abs });
      continue;
    }
    const configured = hasKeyPath(parsed, spec.keyPath);
    out.push({ id: spec.id, displayName: spec.displayName, configured, path: abs });
  }
  return out;
}
function hasKeyPath(node, keyPath) {
  let cursor = node;
  for (const key of keyPath) {
    if (typeof cursor !== "object" || cursor === null) return false;
    if (!(key in cursor)) return false;
    cursor = cursor[key];
  }
  return cursor !== void 0 && cursor !== null;
}
export {
  readConnectedAgents
};
//# sourceMappingURL=status-agents.js.map