{"_id":"@baggiiiie/pi-context-chart","_rev":"5-ced7098d65b153867576e583229e1ea0","name":"@baggiiiie/pi-context-chart","dist-tags":{"latest":"0.0.5"},"versions":{"0.0.1":{"name":"@baggiiiie/pi-context-chart","version":"0.0.1","keywords":["pi-package"],"_id":"@baggiiiie/pi-context-chart@0.0.1","maintainers":[{"name":"baggiiiie","email":"yc@yingchao.dev"}],"pi":{"extensions":["./src/index.ts"]},"dist":{"shasum":"6c5c0858fb461188da22436dde3eed3d2e100e77","tarball":"https://registry.npmjs.org/@baggiiiie/pi-context-chart/-/pi-context-chart-0.0.1.tgz","fileCount":6,"integrity":"sha512-rlPSgB4kCIhX1RU8I2oxjUNKt3LKaZ55y6bPP/JZZlnzzVnDRlt/NhPNpd9t7PKr80Be058N1zCPGoXiGNSJmQ==","signatures":[{"sig":"MEQCIBCzxnBcSN0ExS8sHkHIf+7ULPgl+MTEsww1uXGlvdbMAiAuzwmEArVX863bVfGpQTBA2TNZ2AHlByfRHTChLAdZ9A==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":29212},"type":"module","gitHead":"2496417d8cb95413f45a8539f4f41a12951cf209","_npmUser":{"name":"baggiiiie","email":"yc@yingchao.dev"},"_npmVersion":"11.12.1","description":"A pi package that adds the `/context-chart` command.","directories":{},"_nodeVersion":"25.5.0","_hasShrinkwrap":false,"peerDependencies":{"@mariozechner/pi-ai":"*","@mariozechner/pi-coding-agent":"*"},"_npmOperationalInternal":{"tmp":"tmp/pi-context-chart_0.0.1_1776241163956_0.5875605948029285","host":"s3://npm-registry-packages-npm-production"}},"0.0.2":{"name":"@baggiiiie/pi-context-chart","version":"0.0.2","keywords":["pi-package"],"_id":"@baggiiiie/pi-context-chart@0.0.2","maintainers":[{"name":"baggiiiie","email":"yc@yingchao.dev"}],"pi":{"extensions":["./src/index.ts"]},"dist":{"shasum":"687aa949da5bf1daa1a81ec1188398bf89aaaeba","tarball":"https://registry.npmjs.org/@baggiiiie/pi-context-chart/-/pi-context-chart-0.0.2.tgz","fileCount":6,"integrity":"sha512-2vLR34acbTcK294LnM+LsVQddNrVcvHUsVm4DHnGPAo7uUgVabaKfpqLy/O3Wn+GXx2AeWzG6CQS/OkqK4B7ew==","signatures":[{"sig":"MEYCIQDDqszLeAV2warrxmXsJq/gWNma4VPTLvgll1vlRqh9kgIhANQjkD3PRHB5nGz//UpD37kUBbrbeX8sWCiIq0G0f0ru","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":30140},"type":"module","gitHead":"6950b34280de2f7ba32c7bf279a1679c9a127a2b","_npmUser":{"name":"baggiiiie","email":"yc@yingchao.dev"},"_npmVersion":"11.12.1","description":"A pi package that adds the `/context-chart` command.","directories":{},"_nodeVersion":"25.5.0","_hasShrinkwrap":false,"peerDependencies":{"@mariozechner/pi-ai":"*","@mariozechner/pi-coding-agent":"*"},"_npmOperationalInternal":{"tmp":"tmp/pi-context-chart_0.0.2_1776279903834_0.40612058782095417","host":"s3://npm-registry-packages-npm-production"}},"0.0.3":{"name":"@baggiiiie/pi-context-chart","version":"0.0.3","keywords":["pi-package"],"_id":"@baggiiiie/pi-context-chart@0.0.3","maintainers":[{"name":"baggiiiie","email":"yc@yingchao.dev"}],"pi":{"extensions":["./src/index.ts"]},"dist":{"shasum":"f940d7988e1cd22ddd6ea6c5be6331420e676ca7","tarball":"https://registry.npmjs.org/@baggiiiie/pi-context-chart/-/pi-context-chart-0.0.3.tgz","fileCount":6,"integrity":"sha512-oEzhrc5sAJplWXhnRyLpx72PhVnAtAct6jIIlg3wCS6tPUz8Pgrck4WuuBspHeY83rrKGlAa4Ibbj4Sr6gECgw==","signatures":[{"sig":"MEYCIQCen9M+9nAfLBZBYvuRPD6YHAIPZ7eBq2b157Q7vkVnQAIhANZe9+Gv3wNwWqK89+ZcEpcYFHYTx7JaILavnjar5Z/w","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":35935},"type":"module","gitHead":"b063c783dd57551ada7ef149c69b411555a02bee","_npmUser":{"name":"baggiiiie","email":"yc@yingchao.dev"},"_npmVersion":"11.12.1","description":"A pi package that adds the `/context-chart` command.","directories":{},"_nodeVersion":"25.5.0","_hasShrinkwrap":false,"peerDependencies":{"@mariozechner/pi-ai":"*","@mariozechner/pi-coding-agent":"*"},"_npmOperationalInternal":{"tmp":"tmp/pi-context-chart_0.0.3_1777869389498_0.05553817351078272","host":"s3://npm-registry-packages-npm-production"}},"0.0.4":{"name":"@baggiiiie/pi-context-chart","version":"0.0.4","keywords":["pi-package"],"_id":"@baggiiiie/pi-context-chart@0.0.4","maintainers":[{"name":"baggiiiie","email":"yc@yingchao.dev"}],"pi":{"extensions":["./src/index.ts"]},"dist":{"shasum":"c6f2234a4ffb6e0fc163d104b0d9a9a9baf12c85","tarball":"https://registry.npmjs.org/@baggiiiie/pi-context-chart/-/pi-context-chart-0.0.4.tgz","fileCount":8,"integrity":"sha512-A9lqdnKNrzdl3zPs7nG9ePIaQPdldBAQ0Xl2SwYdvvGNGsclF4aRrrIGILa4q/Sb6yva/++5sVmVDZL5EkDnPQ==","signatures":[{"sig":"MEUCIQDFnKGWZWsUu3ocgio2Js55iYm5hySUMXjVZiMYC8QN5QIgDF7piemM9qKbmB3N79w+mOqWiXhXFrbiQZ769FLYZ3A=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":51698},"type":"module","gitHead":"271ac28a41dc151f95d6c6582e88bd7f741eee5d","_npmUser":{"name":"baggiiiie","email":"yc@yingchao.dev"},"_npmVersion":"11.14.1","description":"A pi package that visualises context usage two ways:","directories":{},"_nodeVersion":"25.5.0","_hasShrinkwrap":false,"peerDependencies":{"@mariozechner/pi-ai":"*","@mariozechner/pi-tui":"*","@mariozechner/pi-coding-agent":"*"},"_npmOperationalInternal":{"tmp":"tmp/pi-context-chart_0.0.4_1779451788267_0.6559344768077062","host":"s3://npm-registry-packages-npm-production"}},"0.0.5":{"name":"@baggiiiie/pi-context-chart","version":"0.0.5","type":"module","keywords":["pi-package"],"pi":{"extensions":["./src/index.ts"]},"peerDependencies":{"@mariozechner/pi-ai":"*","@mariozechner/pi-coding-agent":"*","@mariozechner/pi-tui":"*"},"gitHead":"2f3725d1fef2457c954003d71f5655068646ee3a","_id":"@baggiiiie/pi-context-chart@0.0.5","description":"A pi package that visualises context usage two ways:","_nodeVersion":"25.5.0","_npmVersion":"11.14.1","dist":{"integrity":"sha512-/A0udkHVfVO6MVikt8OWqaCLChw64Z7Uu+7nqHodJEJSzFgWe5inxeEtNUBAIBHsyn5SFmxkuu0tcNlhneS8gw==","shasum":"2d418f639579c35260035ca851daa2cd6caaf108","tarball":"https://registry.npmjs.org/@baggiiiie/pi-context-chart/-/pi-context-chart-0.0.5.tgz","fileCount":8,"unpackedSize":57493,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIDARCWh2mdU8FYyTDcgSLCPtNGkhntZM4BHerbsE+48eAiEAwISvMs1k3WAwIQSvkwck3SbC7xZKzQ7UTVZHS03WqV0="}]},"_npmUser":{"name":"baggiiiie","email":"yc@yingchao.dev"},"directories":{},"maintainers":[{"name":"baggiiiie","email":"yc@yingchao.dev"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/pi-context-chart_0.0.5_1779813540874_0.91230581912575"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-15T08:19:23.821Z","modified":"2026-05-26T16:39:01.457Z","0.0.1":"2026-04-15T08:19:24.097Z","0.0.2":"2026-04-15T19:05:03.984Z","0.0.3":"2026-05-04T04:36:29.645Z","0.0.4":"2026-05-22T12:09:48.407Z","0.0.5":"2026-05-26T16:39:01.043Z"},"keywords":["pi-package"],"description":"A pi package that visualises context usage two ways:","maintainers":[{"name":"baggiiiie","email":"yc@yingchao.dev"}],"readme":"# @baggiiiie/pi-context-chart\n\nA pi package that visualises context usage two ways:\n\n- A live **chart** rendered in a Glimpse window.\n- A live **footer** showing the current context-window mix and totals.\n\nBoth surfaces share a single computation, so they stay consistent and only recompute once per session event.\n\n## Install\n\n```bash\npi install npm:@baggiiiie/pi-context-chart\n```\n\n## Usage\n\n```text\n/context-chart           Open the live context usage chart\n/context-chart close     Close the chart window\n/context-chart footer    Toggle the context footer on/off\n/context-chart refresh   Recompute context state (updates chart + footer)\n/context-chart help      Show the in-app help widget\n/context-chart clear     Hide the help widget\n```\n\nThe footer is on by default. Override the startup behavior with:\n\n```bash\nexport PI_CONTEXT_CHART_FOOTER=off   # disable footer on launch (default: on)\n```\n\n## How tokens are calculated\n\n### Estimation method\n\nToken counts are estimated locally — no tokenizer or API call is involved at estimation time. The primary method is `estimateTokens(message)` exported by `@mariozechner/pi-coding-agent`. If that throws (e.g. for an unrecognized message shape), the fallback is `Math.ceil(textContent.length / 4)` (a rough chars-to-tokens heuristic).\n\n### Message categorization\n\nEach message in the reconstructed context array is classified into one of five buckets based on its `role`:\n\n| Role | Category | Description |\n|------|----------|-------------|\n| `user` | **User input** | User prompts and follow-ups |\n| `assistant` | **Agent output** | Model responses, tool-call blocks, thinking |\n| `toolResult`, `bashExecution` | **Tools** | Tool/command outputs returned to the model |\n| `compactionSummary`, `branchSummary`, `custom` | **Memory** | Carried context from compaction or branch summaries |\n| *(system prompt)* | **System instructions** | Estimated separately from the resolved system prompt string |\n\nThe snapshot total is the sum of all five categories:\n\n```\ntotal = systemInstructions + userInput + agentOutput + tools + memory\n```\n\n### Reconciliation with actual usage\n\nWhen pi reports real token counts via `ctx.getContextUsage()` (returned by the provider after a request), the footer uses the **actual** `tokens` value as the authoritative total. The category breakdown is then **scaled proportionally** to match that real total using the largest-remainder method (each category keeps its relative share, with rounding residuals distributed to the largest fractional remainders). This avoids the breakdown summing to a different number than what the provider reported.\n\nIf `getContextUsage()` is unavailable (e.g. right after compaction, or for live in-flight snapshots), the local estimate is used and marked as \"approximate\" (`~` prefix in the footer).\n\n### Per-turn history\n\nFor the chart, each historical turn's snapshot is built by calling `buildSessionContext(entries, parentId, byId)` which reconstructs the full message array that was sent to the model for that specific turn. This means each data point reflects the **cumulative** context size at that moment, not just the incremental addition.\n\n### Cache hit rate\n\nThe footer displays a prompt cache hit rate after the context breakdown. It is calculated as:\n\n```\nhitRate = cacheRead / (input + cacheRead + cacheWrite)\n```\n\nValues are taken from the model's reported usage metadata accumulated across all assistant turns in the current branch. The rate is color-coded: green (≥70%), yellow (≥30%), or dim (<30%). Shows `--` if no prompt tokens have been reported yet.\n\n## Notes\n\n- Requires pi\n- The chart requires Glimpse to be installed where Node can resolve it, or `GLIMPSE_PATH` set to `.../glimpseui/src/glimpse.mjs`\n- Footer uses pi's `ctx.getContextUsage()` when available, with a local estimate fallback (e.g. right after compaction)\n","readmeFilename":"README.md"}