feat(cli): add --stats flag to show token savings
#51
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Added
--statsflag to display token count comparison when encoding JSON to TOON.Usage
Output:
users[3]{id,name,role}:
1,Alice,admin
2,Bob,user
3,Charlie,user
ℹ Token estimate: 43 (JSON) → 18 (TOON)
✔ Saved ~25 tokens (58.1%)
Implementation
Uses simple approximation:
Math.ceil(text.length / 4)(GPT-style tokenizers average ~4 chars per token)
Why not use gpt-tokenizer:
If you prefer accuracy over simplicity, I can switch to gpt-tokenizer.
Screenshots
Added a small feature that seemed useful. Hope you can accept this PR if it looks good to you!