import { access } from "node:fs/promises";
import path from "node:path";
import os from "node:os";

//#region src/detectAgent.ts
/**
* Detect which AI coding agents are installed on the system.
* Returns an array of detected agent names.
*/
async function detectInstalledAgents() {
	const detected = [];
	try {
		await access(path.join(process.cwd(), ".cursor"));
		detected.push("cursor");
	} catch {}
	try {
		await access(path.join(process.cwd(), ".vscode"));
		detected.push("vscode");
	} catch {
		try {
			await access(path.join(process.cwd(), ".github/copilot"));
			detected.push("vscode");
		} catch {}
	}
	try {
		await access(path.join(os.homedir(), ".claude"));
		detected.push("claude");
	} catch {}
	try {
		await access(path.join(process.cwd(), ".opencode"));
		detected.push("opencode");
	} catch {
		try {
			await access(path.join(process.cwd(), "AGENTS.md"));
			detected.push("opencode");
		} catch {}
	}
	try {
		await access(path.join(os.homedir(), ".windsurf"));
		detected.push("windsurf");
	} catch {}
	return detected;
}
/**
* Get agent choices sorted by detection (detected agents first, then others).
*/
async function getAgentChoices() {
	const detected = await detectInstalledAgents();
	return [
		{
			title: "Cursor",
			value: "cursor"
		},
		{
			title: "VS Code Copilot",
			value: "vscode"
		},
		{
			title: "Claude Code",
			value: "claude"
		},
		{
			title: "OpenCode",
			value: "opencode"
		},
		{
			title: "Windsurf",
			value: "windsurf"
		},
		{
			title: "All agents",
			value: "all"
		},
		{
			title: "Skip",
			value: "skip"
		}
	].sort((a, b) => {
		const aDetected = detected.includes(a.value);
		const bDetected = detected.includes(b.value);
		if (aDetected && !bDetected) return -1;
		if (!aDetected && bDetected) return 1;
		return 0;
	});
}

//#endregion
export { getAgentChoices };
//# sourceMappingURL=detectAgent.js.map