/** * Shared queue storage layout for pi extensions (HUD + pi-queue). * * One file per session, keyed by sha1(sessionFile). The legacy `queue.json` * is read once on first load in a new session and emptied; new writes go to * the per-session file. * * ponytail: session id is sha1(sessionFile). Upgrade path: switch to a stable * id (e.g. homedir-relative basename) if we ever need cross-device resolution. */ import { createHash } from "node:crypto"; import { homedir } from "node:os"; import { join } from "node:path"; const PI_ROOT = process.env.PI_HOME || join(homedir(), ".pi"); /** Directory that holds per-session queue files plus the legacy queue.json. */ export const QUEUE_STATE_DIR = join(PI_ROOT, "agent", "pi-queue"); /** Pre-refactor single-file path. Read once then emptied. */ export const QUEUE_LEGACY_FILE = join(QUEUE_STATE_DIR, "queue.json"); export function queueFileFor(sessionFile: string | undefined): string { const seed = sessionFile || process.cwd() || "global"; const hash = createHash("sha1").update(seed).digest("hex").slice(0, 16); return join(QUEUE_STATE_DIR, `${hash}.json`); }