You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Shared token-estimation module: CHARS_PER_TOKEN is independently defined in 7 files #644
The content-length token heuristic is copy-pasted across the codebase: CHARS_PER_TOKEN is defined independently in src/context-tree.ts, src/context-budget.ts, src/providers/kiro.ts, src/providers/cursor.ts, src/providers/warp.ts, src/providers/codex.ts, and src/providers/cursor-agent.ts, with Math.ceil(len / CHARS_PER_TOKEN) re-derived at each site. If the heuristic is ever refined (different ratio for code vs prose, per-tokenizer), it will silently apply to some providers and not others, skewing exactly the cross-provider comparisons the product exists for.
One exported estimateTokensFromChars(chars: number): number in a shared leaf module; delete the local constants. Mechanical change, no behavior difference today, and it gives estimated-token provenance a single home (pairs well with #639).
Working on this. Approach as proposed: add a shared estimateTokensFromChars() in a new leaf module, migrate all 7 call sites, delete the local CHARS_PER_TOKEN constants, and add a test pinning the heuristic so the ratio can only change in one place. No behavior change intended.
Activity
avs-io commentedon Jul 16, 2026
Working on this. Approach as proposed: add a shared
estimateTokensFromChars()in a new leaf module, migrate all 7 call sites, delete the localCHARS_PER_TOKENconstants, and add a test pinning the heuristic so the ratio can only change in one place. No behavior change intended.Extract shared token estimation helper, migrate all CHARS_PER_TOKEN s…