Skip to content

Commit 9552207

Browse files
authored
Implement waza tokens compare command (microsoft#111)
Adds a new `tokens compare` subcommand that compares token counts in a directory between git refs, enabling users to track how token usage changes across commits or between committed and uncommitted work. Closes microsoft#51 ## Usage ```bash # Compare HEAD to working tree waza tokens compare # Compare a specific ref to working tree waza tokens compare HEAD~3 # Compare two refs waza tokens compare main feature-branch # JSON output waza tokens compare --format json # Include unchanged files waza tokens compare --show-unchanged ``` ## Changes ### New files | File | Description | | -------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | | `cmd/waza/tokens/compare.go` | Command implementation: ref resolution, file diffing, token counting, table and JSON output | | `cmd/waza/tokens/compare_test.go` | Tests covering added/modified/removed files, multiple ref combinations, `--show-unchanged`, and JSON output | | `cmd/waza/tokens/internal/git/git.go` | Git helpers: `IsInRepo`, `GetFilesFromRef`, `GetFileFromRef`, `RefExists` | ## Design - **Ref handling:** With no args, compares `HEAD → WORKING` i.e., the working tree. One arg compares that ref to working tree. Two args compares first to second. - **File detection:** Uses `git ls-files` for the working tree and `git ls-tree` for committed refs, filtering to `.md`/`.mdx` files. - **Edge cases:** Handles empty repos (no HEAD), deleted working tree files, and files that exist in only one ref. - **Output formats:** Table (default) with emoji status indicators, or structured JSON with per-file and summary statistics. - **Per-file stats:** Token count, character count, line count, absolute diff, percent change, and status (`added`/`removed`/`modified`/`unchanged`). ## Example Output ``` 📊 Token Comparison: HEAD → WORKING File Before After Diff Status ------------------------------------------------------------------ README.md 11 14 +3 📈 references/spec.md 7 7 0 ➡️ unchanged.md 1 1 0 ➡️ ------------------------------------------------------------------ Total 19 22 +3 15.8% 📋 Summary: Added: 0, Removed: 0, Modified: 1 Increased: 1, Decreased: 0 ```
1 parent 0592077 commit 9552207

4 files changed

Lines changed: 877 additions & 3 deletions

File tree

0 commit comments

Comments
 (0)