Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | 1x 1x 1x 1x 1x 24x 24x 22x 24x 1x 24x 1x 24x 24x 1x 1x 24x 24x 24x 1x 1x 1x 1x 1x 1x 1x 1x 23x 23x 23x 23x 21x 23x 1x 23x 1x 23x 23x 23x 23x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 23x 23x 23x 23x 23x 253x 253x 322x 322x 322x 322x 322x 116x 116x 116x 8x 116x 94x 94x 94x 116x 27x 116x 322x 322x 322x 322x 322x 322x 322x 322x 322x 253x 23x 23x 23x 23x 1x 2x 2x 2x 1x 1x 1x 1x 81x 81x 81x 81x 81x 81x 81x 81x 81x 81x 58x 58x 20x 20x 58x 11x 11x 11x 47x 81x 6x 1x 1x 1x 5x 81x 81x 12x 12x 1x 1x 12x 1x 1x 1x 11x 11x 5x 5x 12x 3x 3x 3x 8x 81x 5x 5x 1x 1x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 81x 81x 81x 81x 1x 4x 4x 1x 1x 3x 3x 3x 1x 1x | /**
* AI Client Detection Module
*
* Detects installed AI assistants (Claude Desktop, Cursor, Windsurf, Continue)
* and checks their MCP configuration status.
*
* @packageDocumentation
*/
import { existsSync, readFileSync } from "node:fs";
import { homedir, platform } from "node:os";
import { join } from "node:path";
import type { AIClientConfig, AIClientFormat, DetectionResult, MCPConfig } from "./types.js";
// =============================================================================
// CLIENT PATH CONFIGURATION
// =============================================================================
/**
* Platform-specific config path resolvers for each AI client
* Note: User preference is project-level configs where supported
*/
const CLIENT_CONFIGS: Record<string, (home: string, cwd?: string) => string[]> = {
claude: (home) => {
switch (platform()) {
case "darwin":
return [join(home, "Library/Application Support/Claude/claude_desktop_config.json")];
case "win32":
return [join(process.env.APPDATA || "", "Claude/claude_desktop_config.json")];
default:
return [join(home, ".config/Claude/claude_desktop_config.json")];
}
},
// Project-level first (user preference), then global fallback
cursor: (_home, cwd) => [...(cwd ? [join(cwd, ".cursor/mcp.json")] : []), join(_home, ".cursor/mcp.json")],
windsurf: (home, cwd) => [
...(cwd ? [join(cwd, ".windsurf/mcp.json")] : []),
join(home, ".codeium/windsurf/mcp_config.json"),
],
continue: (home) => [join(home, ".continue/config.json")],
// New clients
vscode: (_home, cwd) => [...(cwd ? [join(cwd, ".vscode/mcp.json")] : [])],
zed: (home) => [join(home, ".config/zed/settings.json")],
cline: (home) => [join(home, ".cline/mcp.json")],
gemini: (home) => [join(home, ".gemini/settings.json")],
aider: (home) => [join(home, ".aider/mcp.yaml")],
"roo-code": (home) => [join(home, ".roo-code/mcp.json")],
// Qoder (VS Code fork) - supports both project-level and global configs
qoder: (home, cwd) => {
const workspaceConfig = cwd ? [join(cwd, ".qoder-mcp-config.json")] : [];
const globalConfig = (() => {
switch (platform()) {
case "darwin":
return join(home, "Library/Application Support/Qoder/SharedClientCache/extension/local/mcp.json");
case "win32":
return join(process.env.APPDATA || "", "Qoder/mcp.json");
default:
return join(home, ".config/Qoder/mcp.json");
}
})();
return [...workspaceConfig, globalConfig];
},
};
/**
* Display names for AI clients
*/
const CLIENT_DISPLAY_NAMES: Record<string, string> = {
claude: "Claude Desktop",
cursor: "Cursor",
windsurf: "Windsurf",
continue: "Continue",
vscode: "VS Code",
zed: "Zed",
cline: "Cline",
gemini: "Gemini/Antigravity",
aider: "Aider",
"roo-code": "Roo Code",
qoder: "Qoder",
};
// =============================================================================
// DETECTION FUNCTIONS
// =============================================================================
/**
* Detect all AI clients and their configuration status
*
* @param options - Detection options
* @param options.cwd - Current working directory for project-level configs
* @returns Detection result with all clients, detected clients, and clients needing setup
*
* @example
* ```ts
* const result = detectAIClients();
* console.log(`Found ${result.detected.length} AI assistants`);
*
* for (const client of result.needsSetup) {
* console.log(`${client.displayName} needs SnapBack configuration`);
* }
* ```
*/
export function detectAIClients(options: { cwd?: string } = {}): DetectionResult {
const home = homedir();
const cwd = options.cwd || process.cwd();
const clients: AIClientConfig[] = [];
const seenPaths = new Set<string>();
for (const [name, getPaths] of Object.entries(CLIENT_CONFIGS)) {
const paths = getPaths(home, cwd);
for (const configPath of paths) {
// Avoid duplicate entries for same path
if (seenPaths.has(configPath)) {
continue;
}
seenPaths.add(configPath);
const exists = existsSync(configPath);
let hasSnapback = false;
if (exists) {
try {
const content = readFileSync(configPath, "utf-8");
// Handle YAML for aider
if (configPath.endsWith(".yaml") || configPath.endsWith(".yml")) {
hasSnapback = content.includes("snapback");
} else {
const parsed = JSON.parse(content) as unknown;
hasSnapback = checkForSnapback(parsed, name as AIClientFormat);
}
} catch {
// Invalid JSON/YAML or read error - treat as no snapback
}
}
clients.push({
name,
displayName: CLIENT_DISPLAY_NAMES[name] || name,
configPath,
exists,
hasSnapback,
format: name as AIClientFormat,
});
}
}
const detected = clients.filter((c) => c.exists);
const needsSetup = detected.filter((c) => !c.hasSnapback);
return { clients, detected, needsSetup };
}
/**
* Check if a specific AI client is installed
*
* @param clientName - Name of the client to check (claude, cursor, windsurf, continue)
* @returns The client config if found, undefined otherwise
*/
export function getClient(clientName: string): AIClientConfig | undefined {
const result = detectAIClients();
return result.clients.find((c) => c.name === clientName && c.exists);
}
/**
* Get all clients that have SnapBack configured
*
* @returns Array of configured clients
*/
export function getConfiguredClients(): AIClientConfig[] {
const result = detectAIClients();
return result.detected.filter((c) => c.hasSnapback);
}
// =============================================================================
// HELPER FUNCTIONS
// =============================================================================
/**
* Check if SnapBack is configured in a config object
*/
function checkForSnapback(config: unknown, format: AIClientFormat): boolean {
if (!config || typeof config !== "object") {
return false;
}
const configObj = config as Record<string, unknown>;
switch (format) {
case "claude":
case "cursor":
case "windsurf":
case "cline":
case "roo-code":
case "qoder":
// These use mcpServers.snapback format
if (
"mcpServers" in configObj &&
typeof configObj.mcpServers === "object" &&
configObj.mcpServers !== null
) {
const servers = configObj.mcpServers as Record<string, unknown>;
// Check for namespaced key or legacy "snapback" key
return "snapback" in servers || `snapback-${format}` in servers;
}
return false;
case "vscode":
// VS Code uses "servers" not "mcpServers"
if ("servers" in configObj && typeof configObj.servers === "object" && configObj.servers !== null) {
const servers = configObj.servers as Record<string, unknown>;
// Check for namespaced key or legacy "snapback" key
return "snapback" in servers || "snapback-vscode" in servers;
}
return false;
case "gemini":
case "zed":
// Zed uses "context_servers" not "mcpServers"
if (
"context_servers" in configObj &&
typeof configObj.context_servers === "object" &&
configObj.context_servers !== null
) {
const servers = configObj.context_servers as Record<string, unknown>;
// Check for namespaced key or legacy "snapback" key
return "snapback" in servers || "snapback-zed" in servers;
}
// Fallback: also check mcpServers for gemini
if (
"mcpServers" in configObj &&
typeof configObj.mcpServers === "object" &&
configObj.mcpServers !== null
) {
const servers = configObj.mcpServers as Record<string, unknown>;
return "snapback" in servers || `snapback-${format}` in servers;
}
return false;
case "continue":
// Continue uses a different structure - check for experimental.modelContextProtocolServers
if (
"experimental" in configObj &&
typeof configObj.experimental === "object" &&
configObj.experimental !== null
) {
const experimental = configObj.experimental as Record<string, unknown>;
if (
"modelContextProtocolServers" in experimental &&
Array.isArray(experimental.modelContextProtocolServers)
) {
return experimental.modelContextProtocolServers.some(
(server: unknown) =>
typeof server === "object" &&
server !== null &&
(server as Record<string, unknown>).name === "snapback",
);
}
}
return false;
case "aider":
// Aider uses YAML - handled separately in detectAIClients
return false;
default:
return false;
}
}
/**
* Get the expected config path for a client on the current platform
*
* @param clientName - Name of the client
* @returns The config path or undefined if unknown client
*/
export function getClientConfigPath(clientName: string): string | undefined {
const getPaths = CLIENT_CONFIGS[clientName];
if (!getPaths) {
return undefined;
}
const paths = getPaths(homedir());
return paths[0];
}
/**
* Read and parse a client's MCP config file
*
* @param client - The client to read config for
* @returns Parsed config or undefined if not found/invalid
*/
export function readClientConfig(client: AIClientConfig): MCPConfig | undefined {
try {
const content = readFileSync(client.configPath, "utf-8");
return JSON.parse(content) as MCPConfig;
} catch {
return undefined;
}
}
/**
* Detect workspace-specific MCP configurations
* Checks for project-level configs that take precedence over global ones
*
* @param workspaceRoot - Workspace root directory (defaults to cwd)
* @returns Config info if found, null otherwise
*
* @example
* ```ts
* const wsConfig = detectWorkspaceConfig();
* if (wsConfig) {
* console.log(`Found workspace config: ${wsConfig.path}`);
* // Skip adding global config to prevent conflicts
* }
* ```
*/
export function detectWorkspaceConfig(
workspaceRoot?: string,
): { path: string; type: "qoder" | "vscode" | "cursor" | "windsurf" } | null {
const root = workspaceRoot || process.cwd();
// Check Qoder workspace config (.qoder-mcp-config.json)
const qoderConfig = join(root, ".qoder-mcp-config.json");
if (existsSync(qoderConfig)) {
try {
const content = readFileSync(qoderConfig, "utf-8");
if (content.includes("snapback")) {
return { path: qoderConfig, type: "qoder" };
}
} catch {
// Invalid JSON or read error
}
}
// Check Cursor project config (.cursor/mcp.json)
const cursorConfig = join(root, ".cursor", "mcp.json");
if (existsSync(cursorConfig)) {
try {
const content = readFileSync(cursorConfig, "utf-8");
if (content.includes("snapback")) {
return { path: cursorConfig, type: "cursor" };
}
} catch {
// Invalid JSON or read error
}
}
// Check VS Code project config (.vscode/mcp.json)
const vscodeConfig = join(root, ".vscode", "mcp.json");
if (existsSync(vscodeConfig)) {
try {
const content = readFileSync(vscodeConfig, "utf-8");
if (content.includes("snapback")) {
return { path: vscodeConfig, type: "vscode" };
}
} catch {
// Invalid JSON or read error
}
}
// Check Windsurf project config (.windsurf/mcp.json)
const windsurfConfig = join(root, ".windsurf", "mcp.json");
if (existsSync(windsurfConfig)) {
try {
const content = readFileSync(windsurfConfig, "utf-8");
if (content.includes("snapback")) {
return { path: windsurfConfig, type: "windsurf" };
}
} catch {
// Invalid JSON or read error
}
}
return null;
}
|