Add token_json_paths: sum engine token stats from JSON worker output - #78
Open
chriscfellows wants to merge 1 commit into
Open
chriscfellows wants to merge 1 commit into
chriscfellows wants to merge 1 commit into
Conversation
Engines whose CLIs report usage only inside a JSON document (gemini CLI --output-format json) record worker_tokens=null today: the stats carry SEVERAL models (utility router + main), each duplicating its totals under nested roles, so a single-capture token_regex either grabs one arbitrary number or double-counts — and a wrong number on the scoreboard is worse than none. New optional [engines.<name>] field token_json_paths (e.g. ["stats.models.*.tokens.total"]): parse_token_stats_json extracts the LAST parseable JSON object from noisy worker output (pretty-printed or compact), resolves dot-paths with * dict wildcards, and sums integer leaves (bools excluded); resolve_worker_tokens falls back to the existing token_regex whenever JSON yields nothing. Engines without the field keep byte-identical behavior. Stdlib only. 11 new tests in tests/test_token_json_paths.py (fixture is a real gemini CLI capture); full suite shows no new failures vs local baseline. Sample config documents the field on a gemini example. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
chriscfellows
force-pushed
the
feat/token-json-paths
branch
from
September 8, 2026 05:16
0ed0223 to
6260093
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Purpose: allow for token counting and cost estimation for workers to help with LLM comparisons.
Engines whose CLIs report usage only inside a JSON document (gemini CLI --output-format json) record worker_tokens=null today: the stats carry SEVERAL models (utility router + main), each duplicating its totals under nested roles, so a single-capture token_regex either grabs one arbitrary number or double-counts — and a wrong number on the scoreboard is worse than none.
New optional [engines.] field token_json_paths (e.g. ["stats.models.*.tokens.total"]): parse_token_stats_json extracts the LAST parseable JSON object from noisy worker output (pretty-printed or compact), resolves dot-paths with * dict wildcards, and sums integer leaves (bools excluded); resolve_worker_tokens falls back to the existing token_regex whenever JSON yields nothing. Engines without the field keep byte-identical behavior.
Stdlib only. 11 new tests in tests/test_token_json_paths.py (fixture is a real gemini CLI capture); full suite shows no new failures vs local baseline. Sample config documents the field on a gemini example.