import type { ExtensionAPI } from "@earendil-works/pi-coding-agent"; import { saveToken } from "../auth/token.js"; const SETUP_HELP = [ "TickTick API Token setup:", "1. Open https://ticktick.com and log in", "2. Avatar → Settings → Account → API Token", "3. Create and copy your token", "4. Paste it below, or set TICKTICK_ACCESS_TOKEN in your environment", ].join("\n"); export function registerSetupCommand(pi: ExtensionAPI): void { pi.registerCommand("ticktick-setup", { description: "Configure TickTick API Token for MCP access", handler: async (_args, ctx) => { ctx.ui.notify(SETUP_HELP, "info"); if (!ctx.hasUI) { ctx.ui.notify( "Set TICKTICK_ACCESS_TOKEN in your environment (non-interactive mode).", "warning", ); return; } const token = await ctx.ui.input("TickTick API Token:", "paste token here"); if (!token?.trim()) { ctx.ui.notify("Setup cancelled — no token entered.", "warning"); return; } try { await saveToken(token); ctx.ui.notify("Token saved. Reloading to connect MCP…", "info"); await ctx.reload(); } catch (error) { const message = error instanceof Error ? error.message : String(error); ctx.ui.notify(`Failed to save token: ${message}`, "error"); } }, }); }