/** * cleanup.ts * * Removes Pisces-owned files from ~/.pi/agent/ on uninstall. * Safe to run multiple times — will not touch files it didn't create. * * Run manually: pnpm cleanup * Auto-runs via: preuninstall lifecycle hook */ import * as fs from "fs"; import * as path from "path"; import * as os from "os"; const AGENT_DIR = path.join(os.homedir(), ".pi", "agent"); // ── Legacy APPEND_SYSTEM.md (written by pre-v0.2 installs) ─────────────────── const APPEND_PATH = path.join(AGENT_DIR, "APPEND_SYSTEM.md"); const SYSTEM_MD_PATH = path.join(__dirname, "..", "SYSTEM.md"); // ── Theme file (written by postinstall) ─────────────────────────────────────── const THEME_PATH = path.join(AGENT_DIR, "themes", "pisces-editorial-noir.json"); const PISCES_THEME_NAME = "pisces-editorial-noir"; function removeAppendSystemMd(): void { if (!fs.existsSync(APPEND_PATH)) return; let systemContent = ""; try { systemContent = fs.readFileSync(SYSTEM_MD_PATH, "utf-8").trim(); } catch { console.log("Could not read SYSTEM.md — skipping APPEND_SYSTEM.md cleanup to be safe."); return; } const existing = fs.readFileSync(APPEND_PATH, "utf-8").trim(); if (existing !== systemContent) { console.log( "~/.pi/agent/APPEND_SYSTEM.md exists but was not written by Pisces — leaving it untouched." ); return; } try { fs.unlinkSync(APPEND_PATH); console.log("Pisces: removed ~/.pi/agent/APPEND_SYSTEM.md"); } catch (err) { console.error("Failed to remove APPEND_SYSTEM.md:", err); } } function removeTheme(): void { if (!fs.existsSync(THEME_PATH)) return; try { const json = JSON.parse(fs.readFileSync(THEME_PATH, "utf-8")) as { name?: string }; if (json.name !== PISCES_THEME_NAME) { console.log(`~/.pi/agent/themes/pisces-editorial-noir.json has unexpected name "${json.name}" — leaving it untouched.`); return; } fs.unlinkSync(THEME_PATH); console.log("Pisces: removed ~/.pi/agent/themes/pisces-editorial-noir.json"); } catch (err) { console.error("Failed to remove theme file:", err); } } function main(): void { removeAppendSystemMd(); removeTheme(); } main();