mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-16 20:02:45 +03:00
Integrated into release/v3.8.8. Applied review fixes: moved the SELECT 1 into a pingDb() db helper (no raw SQL in route, Hard Rule #5) + the 503 catch no longer leaks err.message (Hard Rule #12). Thanks @herjarsa!
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
/**
|
|
* GitHub Copilot installation detection.
|
|
*
|
|
* Detection strategy: look for the Copilot extension folder inside the user's
|
|
* VS Code (or fork) extensions directory. Purely filesystem-based — no shell
|
|
* interpolation (Hard Rule #13).
|
|
*/
|
|
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import type { DetectionResult } from "../types";
|
|
|
|
const HOME = os.homedir();
|
|
|
|
const EXTENSIONS_DIRS = [
|
|
path.join(HOME, ".vscode", "extensions"),
|
|
path.join(HOME, ".vscode-insiders", "extensions"),
|
|
path.join(HOME, ".cursor", "extensions"),
|
|
];
|
|
|
|
export function detectCopilot(): DetectionResult {
|
|
for (const dir of EXTENSIONS_DIRS) {
|
|
try {
|
|
if (!fs.existsSync(dir)) continue;
|
|
const entries = fs.readdirSync(dir);
|
|
for (const name of entries) {
|
|
// Copilot extensions are named like `github.copilot-1.x.x`,
|
|
// `github.copilot-chat-...`. Match by prefix only.
|
|
const lower = name.toLowerCase();
|
|
if (lower.startsWith("github.copilot")) {
|
|
return { installed: true, path: path.join(dir, name) };
|
|
}
|
|
}
|
|
} catch {
|
|
// Permission or transient fs error — skip this directory.
|
|
}
|
|
}
|
|
return { installed: false };
|
|
}
|