import { readFile as nodeReadFile } from "node:fs/promises";
import { homedir, platform } from "node:os";
import { join } from "node:path";
function isObject(v) {
  return typeof v === "object" && v !== null;
}
async function detectAtPath(configPath, serverPath) {
  let raw;
  try {
    raw = await nodeReadFile(configPath, "utf-8");
  } catch (err) {
    const code = err.code;
    if (code === "ENOENT" || code === "ENOTDIR" || code === "EACCES") return false;
    return false;
  }
  let parsed;
  try {
    parsed = JSON.parse(raw);
  } catch {
    return false;
  }
  let cur = parsed;
  for (const key of serverPath) {
    if (!isObject(cur)) return false;
    cur = cur[key];
    if (cur === void 0) return false;
  }
  return cur !== void 0 && cur !== null;
}
function resolveVscodeMcpPath(home, plat, env) {
  const override = env.WIGOLO_VSCODE_MCP_PATH;
  if (override) return override;
  void plat;
  return join(home, ".vscode", "mcp.json");
}
function defaultAgentTargets(opts) {
  const home = opts.home ?? homedir();
  const plat = opts.platform ?? platform();
  const env = opts.env ?? process.env;
  const backupDir = join(opts.dataDir, "backups");
  const claudeCodePath = join(home, ".claude.json");
  const claudeCodeServer = ["mcpServers", "wigolo"];
  const vscodePath = resolveVscodeMcpPath(home, plat, env);
  const vscodeServer = ["servers", "wigolo"];
  const zedPath = join(home, ".config", "zed", "settings.json");
  const zedServer = ["context_servers", "wigolo"];
  const windsurfPath = join(home, ".codeium", "windsurf", "mcp_config.json");
  const windsurfServer = ["mcpServers", "wigolo"];
  const cursorPath = join(home, ".cursor", "mcp.json");
  const cursorServer = ["mcpServers", "wigolo"];
  return [
    {
      id: "claude-code",
      label: "Claude Code",
      configPath: claudeCodePath,
      serverPath: claudeCodeServer,
      envPath: [...claudeCodeServer, "env"],
      detect: () => detectAtPath(claudeCodePath, claudeCodeServer),
      backupDir: () => backupDir
    },
    {
      id: "vscode",
      label: "VS Code (Copilot)",
      configPath: vscodePath,
      serverPath: vscodeServer,
      envPath: [...vscodeServer, "env"],
      detect: () => detectAtPath(vscodePath, vscodeServer),
      backupDir: () => backupDir
    },
    {
      id: "zed",
      label: "Zed",
      configPath: zedPath,
      serverPath: zedServer,
      envPath: [...zedServer, "env"],
      detect: () => detectAtPath(zedPath, zedServer),
      backupDir: () => backupDir
    },
    {
      id: "windsurf",
      label: "Windsurf",
      configPath: windsurfPath,
      serverPath: windsurfServer,
      envPath: [...windsurfServer, "env"],
      detect: () => detectAtPath(windsurfPath, windsurfServer),
      backupDir: () => backupDir
    },
    {
      id: "cursor",
      label: "Cursor",
      configPath: cursorPath,
      serverPath: cursorServer,
      envPath: [...cursorServer, "env"],
      detect: () => detectAtPath(cursorPath, cursorServer),
      backupDir: () => backupDir
    }
  ];
}
export {
  defaultAgentTargets
};
//# sourceMappingURL=agent-targets.js.map