import fs from "fs"; import os from "os"; import path from "path"; export function projectRoot(): string { const fromDir = path.resolve(__dirname, ".."); if (fs.existsSync(path.join(fromDir, "package.json"))) { return fromDir; } return process.cwd(); } export function binDir(): string { return path.join(projectRoot(), "bin"); } export function exeName(base: string): string { return process.platform === "win32" ? `${base}.exe` : base; } export function runnerPath(kind: "cpu" | "metal" | "cuda"): string | null { const names: Record = { cpu: "med_cpu", metal: "med_gpu", cuda: "med_cuda", }; const p = path.join(binDir(), exeName(names[kind])); return fs.existsSync(p) ? p : null; } export function metalShaderPath(): string { return path.join(projectRoot(), "native", "metal", "des_bruteforce.metal"); } export function defaultMedPath(): string { const root = projectRoot(); try { const match = fs.readdirSync(root).find((name) => name.toLowerCase().endsWith(".med")); if (match) { return path.join(root, match); } } catch { /* ignore */ } return ""; } export function defaultOutDir(): string { return path.join(projectRoot(), "decoded", "bruteforce"); } export function cpuCoreCount(): number { return Math.max(1, os.cpus().length); }