import type { ExtensionAPI } from "@earendil-works/pi-coding-agent"; import { clearToken } from "../auth/token.js"; export function registerLogoutCommand(pi: ExtensionAPI): void { pi.registerCommand("ticktick-logout", { description: "Remove saved TickTick API Token", handler: async (_args, ctx) => { const envToken = Boolean( process.env.TICKTICK_ACCESS_TOKEN?.trim() || process.env.TICKTICK_API_KEY?.trim(), ); if (envToken) { ctx.ui.notify( "TICKTICK_ACCESS_TOKEN is set in your shell environment. /ticktick-logout only removes the saved file (~/.pi/agent/ticktick/token). To fully disconnect, unset the env var and restart Pi, or run: unset TICKTICK_ACCESS_TOKEN", "warning", ); } const ok = ctx.hasUI ? await ctx.ui.confirm( "Remove saved token?", "This deletes ~/.pi/agent/ticktick/token", ) : true; if (!ok) return; await clearToken(); ctx.ui.notify("Saved token removed. Reloading…", "info"); await ctx.reload(); }, }); }