/ extensions / reverse-thinking.ts
reverse-thinking.ts
 1  import { supportsXhigh } from "@mariozechner/pi-ai";
 2  import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
 3  
 4  const LEVELS = ["off", "minimal", "low", "medium", "high"] as const;
 5  const LEVELS_XHIGH = ["off", "minimal", "low", "medium", "high", "xhigh"] as const;
 6  
 7  type ThinkingLevel = (typeof LEVELS_XHIGH)[number];
 8  
 9  export default function reverseThinkingShortcut(pi: ExtensionAPI) {
10    pi.registerShortcut("shift+alt+tab", {
11      description: "Cycle thinking level backward",
12      handler: (ctx) => {
13        const model = ctx.model;
14        const levels: ThinkingLevel[] = !model?.reasoning
15          ? ["off"]
16          : supportsXhigh(model)
17            ? [...LEVELS_XHIGH]
18            : [...LEVELS];
19  
20        const current = pi.getThinkingLevel() as ThinkingLevel;
21        const currentIndex = Math.max(0, levels.indexOf(current));
22        const previousIndex = (currentIndex - 1 + levels.length) % levels.length;
23  
24        pi.setThinkingLevel(levels[previousIndex]);
25        ctx.ui.notify(`Thinking: ${levels[previousIndex]}`);
26      },
27    });
28  }