Skip to content

feat: display savings in tokens instead of KB/MB (v1.3.1)#15

Merged
ppgranger merged 35 commits into
mainfrom
feat/savings-in-tokens
Feb 21, 2026
Merged

feat: display savings in tokens instead of KB/MB (v1.3.1)#15
ppgranger merged 35 commits into
mainfrom
feat/savings-in-tokens

Conversation

@ppgranger

Copy link
Copy Markdown
Owner

Summary

Token-Saver previously displayed savings in KB/MB based on raw character counts, which didn't reflect the metric that actually matters to LLM users. Savings are now displayed in tokens (estimated at ~4 characters per token), giving a direct view of the real savings on the context window.

  • Replace _format_bytes() with _format_tokens() and _chars_to_tokens() in tracker.py and stats.py
  • Dry-run output in wrap.py now displays tokens
  • Compression audit (audit_compression.py) reports in tokens
  • Configurable chars_per_token ratio (default: 4) via config.json or TOKEN_SAVER_CHARS_PER_TOKEN
  • No database migration needed: the DB still stores character counts, conversion happens at display time
  • Add .claude/ to .gitignore

Changed files

File Change
src/config.py Add chars_per_token setting
src/tracker.py _format_bytes -> _format_tokens + _chars_to_tokens
src/stats.py Same, CLI display in tokens
claude/wrap.py Dry-run output in tokens
audit_compression.py Audit output in tokens
tests/test_tracker.py Updated tests
README.md Updated output examples
src/__init__.py Version bump -> 1.3.1

Before / After

# Before
[token-saver] Lifetime: 342 cmds, 1.2 MB saved (67.3%)

# After
[token-saver] Lifetime: 342 cmds, 307.2k tokens saved (67.3%)

Test plan

  • 373 tests passing
  • Ruff lint: no errors
  • Ruff format: compliant
  • Verify display in a live session (SessionStart hook)
  • Verify dry-run (wrap.py --dry-run)
  • Test with custom chars_per_token via env var

ppgranger and others added 30 commits February 18, 2026 14:16
Add 3 missing progress line detection patterns to _is_progress_line():
- Yarn Berry (v2+) step progress (Resolution/Fetch/Link step)
- pnpm resolution progress counter (Progress: resolved N, ...)
- pnpm content-addressable store messages (packages are hard linked)

Includes 2 new unit tests verifying these patterns are correctly stripped.
- Yarn berry: match ➤ YN0000: ┌ prefix before Resolution/Fetch/Link step
- pnpm: handle both Packages (capital P) and packages (lowercase)
- Tests now use actual output format from yarn 4.x and pnpm
- Tighten yarn berry pattern to require YN prefix, preventing false
  positives on error lines containing step keywords
- Add precision test verifying errors mentioning "Resolution step" or
  "Fetch step" are never stripped from output
Add yarn berry and pnpm progress line patterns to BuildOutputProcessor
The actual source file is src/platforms.py (plural) but three
references used the singular form, causing a "Source file missing"
warning during installation.
Fix platform.py → platforms.py filename references
…tterns

Commands like `git -C <path> status`, `kubectl -n <ns> get pods`, and
`docker --context <ctx> ps` were not matched by hook_patterns because
the regex expected the subcommand to immediately follow the command name.

This meant AI CLI tools that avoid `cd` (using `git -C` instead) would
never get their git output compressed — a significant gap in practice.

Changes:
- git: allow -C, --no-pager, -c, --git-dir, --work-tree before subcommand
- kubectl: allow -n, --namespace, --context, --kubeconfig, -A before subcommand
- docker: allow --context, -H, --host before subcommand
- Refactor process() routing to use _get_subcmd() helper (DRY)
- Add comprehensive tests for all three processors
…k-patterns

fix: support global options in hook patterns (git -C, kubectl -n, etc.)
- Single source of truth for version in src/__init__.py (v1.0.1)
- GitHub API update check at session start (fail-open, 3s timeout)
- CLI command: token-saver version|stats|update
- bin/token-saver executable + Windows .cmd wrapper
- Installer stamps version into plugin.json/gemini-extension.json
- install_cli/uninstall_cli for PATH integration (~/.local/bin)
Bump version to 1.0.1. Update all GitHub URLs, descriptions,
and comments to use token-saver consistently.
The project was renamed from "token-saving" to "token-saver" with
the introduction of the CLI (v1.0.1). The installer now detects and
removes old "token-saving" directories and hooks before installing,
so nothing is left behind under the former name.
- bin/token-saver: find src/ in plugin install dirs when repo is deleted
- cli.py: git merge --ff-only instead of checkout (no detached HEAD)
- cli.py: detect installed targets instead of hardcoding --target both
- cli.py: tarball overlay only known dirs (preserve .git, local config)
- cli.py: clear HTTP 404 message when no GitHub releases exist
- version_check.py: guard empty tag_name, reduce timeout to 2s
- install.py: run legacy migration on uninstall too
- Add tests/test_installers.py (15 tests: migration, stamping, CLI)
- Add edge case tests for empty/None version strings
Install core files to ~/.token-saver/ so the CLI and update command
work independently of which platform target was chosen. This ensures
token-saver continues to function after the repo/zip is deleted.

- Add install_core()/uninstall_core() and CORE_FILES to installers/common.py
- Update bin/token-saver to search repo -> ~/.token-saver/ -> plugin dirs
- Make _detect_installed_targets() Windows-aware with %APPDATA% paths
- Update install.py to call install_core() and uninstall_core()
- Update README with CLI docs, project structure, and test counts
- Add 3 new tests for core install/uninstall behavior
- Fix uninstall_core leaving empty parent dirs (os.walk stale dirnames)
- Fix _parse_version crash on pre-release tags (e.g. "1.0.0-beta")
- Fix migrate_from_legacy crash on malformed settings.json hooks
- Reduce version check HTTP timeout from 2s to 1s for safer hook margin
- Add error handling around version comparison in cmd_update
- Add tests for pre-release parsing, dir cleanup, malformed settings
- Quote hook command paths for directories with spaces (Claude + Gemini)
- Fix install_files/install_cli overwriting through existing symlinks
  when switching from --link to copy mode (corrupted source files)
- Try both v-prefixed and bare tag names in tarball download URL
- Use 10s HTTP timeout for interactive CLI update (vs 1s for hooks)
- Add test for symlink-to-copy transition safety
- Add data_dir() to src/__init__.py as single source of truth for the
  data directory path (%APPDATA%/token-saver on Windows, ~/.token-saver
  on Unix)
- Update config.py, tracker.py, hook_pretool.py, and wrap.py to use
  data_dir() instead of hardcoding ~/.token-saver
- Fix hook_pretool.py using python3 on Windows where only python exists
- Fix test_default_values failing when TOKEN_SAVER_DEBUG is set in env
feat: add version management, update notification and token-saver CLI
…ntation

Expand processor coverage with 20+ new command handlers:
- Git: blame, cherry-pick, rebase, merge, stash list, diff --name-only/--name-status, conflict markers
- Docker: inspect, stats, compose up/down/build, Dead container status
- Kubectl: apply, delete, create with multi-container ready detection fix
- Terraform: init, output, state list/show with proper subcommand extraction
- Network: httpie (http/https), JSON response compression
- Test: dotnet test, swift test, mix test, pnpm routing, traceback truncation
- Lint: shellcheck, hadolint, biome parsers, clippy false positive fix
- Search: fd/fdfind grouping
- File listing: exa/eza support

Add engine generic fallback when specialized processor doesn't compress enough.
Externalize 9 new config thresholds. Add .gitignore, remove .DS_Store from tracking.
Add docs/processors/ with per-processor documentation. Update README with doc links.

336 tests (was 267), all passing.
Combine if/elif branches (SIM114), fix line length (E501),
rename ambiguous variable (E741), collapse nested ifs (SIM102),
replace 0.0.0.0 with 127.0.0.1 in tests (S104).
When token-saver update runs from ~/.token-saver/ (tarball mode),
install_core copies files from ~/.token-saver/ to ~/.token-saver/.
The old code deleted dst before copying, but src and dst were the
same file, causing FileNotFoundError on the subsequent copy.

Uses realpath (symlinks) + normcase (Windows case-insensitivity)
for robust cross-platform same-file detection.
fix: prevent self-delete during core install when src == dst
3 new processors (15 → 18):
- gh: compress gh pr/issue/run list/view/diff/checks output
- db_query: compress psql/mysql/sqlite3 table results (head+tail)
- cloud_cli: compress aws/gcloud/az JSON/table/text output

Audit fixes on existing processors:
- git: add remote subcommand handler, typechange status prefix
- env: add set to hook_patterns
- system_info: fix hook pattern to match bare df/du/wc
- file_listing/file_content: simplify can_handle regex

Tests: 336 → 372, ruff lint clean.
ppgranger and others added 5 commits February 21, 2026 19:09
feat: add gh, db_query, cloud_cli processors + audit fixes (v1.2.0)
Replace byte-based display (KB/MB) with token-based display using
a configurable chars_per_token ratio (default: 4). The DB still
stores character counts; conversion happens at display time so
existing data remains valid.
@ppgranger ppgranger merged commit f8c924f into main Feb 21, 2026
4 checks passed
@ppgranger ppgranger deleted the feat/savings-in-tokens branch February 21, 2026 18:32
ppgranger added a commit that referenced this pull request Feb 21, 2026
feat: display savings in tokens instead of KB/MB (v1.3.1)
ppgranger added a commit that referenced this pull request Mar 10, 2026
feat: display savings in tokens instead of KB/MB (v1.3.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants