feat: enhance /context with detailed token usage breakdown - #53
Conversation
Fixes KlaatAI#27 - Export shared estimateTokensFromChars/Text helpers from compaction.ts - Add context-breakdown module for system/conversation/tool schema split - Show progress bar, compaction state, and ledger size in /context output - Base breakdown on compacted send payload (matches API window) - Count assistant tool_calls in token estimates
|
🤖 KlaatAI Review Bot (powered by Klaatu, advisory only — a maintainer makes the real call) Issue match Test coverage Correctness concerns Verdict This is an automated review to help triage faster, not a gate. Nothing here blocks merging. |
Summary
Enhances the
/contextslash command with a detailed token usage breakdown as described in #27.Motivation
Long agentic sessions consume significant context. Users need visibility into where tokens go — system prompt, conversation history, tool results, and tool schemas — not just a total count.
Changes
estimateTokensFromChars/estimateTokensFromTextfromcompaction.tsas the shared estimation helper (chars÷4)context-breakdown.tsmodule withcomputeContextBreakdown()for categorized estimates/contextoutput:compactMessagesForApiapplied)tool_callsJSON in assistant message token estimatesTests
bun test— 255 pass (7 new tests incontext-breakdown.test.ts)bun run typecheck— passbun run build— passNotes
prompt_tokensdiffers from the estimate by >2% of the window, both values are shown/init-style project rules (Project rules (from …)) are classified under Project rulesFixes #27