Repository navigation
fix(parser/analytics): byte-correct JSON extraction + accurate savings metrics (#111 G7) - #116
Merged
Merged
Conversation
…; adoption + branding (#111 G7) Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…#111 G7 follow-up) compute_totals derived rtk_avg_savings_pct = saved / (saved + cc_input + cc_output). With no ccusage data the denominator collapses to saved alone, so saved / saved reported a meaningless 100% savings. The savings_denom > 0 guard caught divide-by-zero but not this semantic mismatch. Gate the metric on the ccusage baseline component being present and make the field Option<f64> — None when there is no baseline to compare against. This serialises to JSON null and matches the codebase's pervasive Option + "—" missing-data pattern. The weighted formula (when ccusage IS present) is unchanged; the divide-by-zero guard is kept. Adds test_compute_totals_no_ccusage_baseline_not_100pct: RTK saved tokens with zero ccusage input/output yields None, never 100%. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Closed
8 tasks done
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.
Summary
Fixes the G7 findings from the independent Claude review (#111). Codex-reviewed across two passes — final: mergeable.
Findings fixed
extract_json_object(parser/mod.rs) used a char index as a byte offset — panic / corrupt JSON on any non-ASCII input. Now tracks byte offsets viachar_indices()+ch.len_utf8(); the CRLF line-offset reconstruction accounts for actual line-ending bytes. Byte-correct for all UTF-8 input; thein_stringguard (a}inside a string value doesn't mis-terminate) is preserved.count_rtk_commandsmatched only legacyrtk, notcontextcrawler. The current hook emitscontextcrawler <cmd>, so adoption was understated for every user on the current binary. Now matches both.compute_totalsreported an unweighted mean of per-period savings percentages. Now volume-weighted (saved / (saved + input + output)), consistent withset_rtk_from_month.ccusagebaseline was present.rtk_avg_savings_pctis nowOption<f64>—None(JSONnull) when there is no baseline to compare against.RTK→Contextcrawlerinsession_cmd.rsheaders andlearn/report.rsreport labels + generated rules-file text.Test plan
cargo test --workspace— 2350 lib + integration suites, 0 failcontextcrawler-prefix adoption, weighted-pct, no-baseline →Nonecargo build --releasecleanPart of the #111 audit.
🤖 Generated with Claude Code