import { existsSync } from "node:fs"; import { homedir } from "node:os"; import { join } from "node:path"; import { execFileSync } from "node:child_process"; /** Candidate locations for the HSP release binary. */ export function hspCandidates(): string[] { const home = homedir(); const env = process.env.HSP_BIN?.trim(); const out: string[] = []; if (env) out.push(env); out.push( join(home, ".local", "bin", "hsp"), "/usr/local/bin/hsp", join(home, "github-clone", "HSP", "hsp-rs", "target", "release", "hsp"), join(home, "Projects", "HSP", "hsp-rs", "target", "release", "hsp"), ); return out; } export function resolveHspBin(): string | null { for (const p of hspCandidates()) { if (p && existsSync(p)) return p; } try { const which = execFileSync("which", ["hsp"], { encoding: "utf8" }).trim(); if (which && existsSync(which)) return which; } catch { /* not on PATH */ } return null; } export function hspStateDir(): string { return join(homedir(), ".local", "state", "hsp-pi"); } export function hspPidPath(): string { return join(hspStateDir(), "hsp-run.pid"); } export function hspLogPath(): string { return join(hspStateDir(), "hsp-run.log"); }