/** * pi-dumb — Context Rot Indicator * * Shows actual token count with color-coded warning based on "context rot" research. * * Research shows LLM quality degrades based on ABSOLUTE token count, not percentage: * - Chroma (2025): All 18 frontier models degrade as context grows * - Liu et al. (Stanford): 30%+ accuracy drop from "lost-in-the-middle" effect * - Attention dilution is quadratic: 100k tokens = 10B pairwise relationships * * Thresholds (based on research): * 🧠 0–30k "fresh" — Dex Horthy/Chroma's "sweet spot," peak reliability * 🟡 30–60k "warm" — past recommended reset point * 🔥 60–100k "hot" — community consensus danger zone for coding * 💀 100k+ "rot" — broadly degraded (Huntley sees issues by ~150k) * * These thresholds apply regardless of context window size (200k or 1M). */ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent"; const THRESHOLDS = { fresh: 30_000, warm: 60_000, hot: 100_000, }; export default function (pi: ExtensionAPI) { function fmt(n: number): string { if (n < 1000) return `${n}`; if (n < 10_000) return `${(n / 1000).toFixed(1)}k`; if (n < 1_000_000) return `${Math.round(n / 1000)}k`; return `${(n / 1_000_000).toFixed(1)}M`; } function updateStatus(ctx: Parameters[1]>[1]) { const usage = ctx.getContextUsage(); if (!usage) return; const theme = ctx.ui.theme; const tokens = usage.tokens; let label: string; if (tokens < THRESHOLDS.fresh) { label = "🧠"; } else if (tokens < THRESHOLDS.warm) { label = "🟡"; } else if (tokens < THRESHOLDS.hot) { label = "🔥"; } else { label = "💀"; } const text = theme.fg("dim", `${label} ${fmt(tokens)}`); ctx.ui.setStatus("context-rot", text); } pi.on("turn_end", async (_event, ctx) => updateStatus(ctx)); pi.on("session_start", async (_event, ctx) => updateStatus(ctx)); pi.on("session_switch", async (_event, ctx) => updateStatus(ctx)); pi.on("session_compact", async (_event, ctx) => { setTimeout(() => updateStatus(ctx), 500); }); }