Repository navigation
Conversation
Next Release
…master--components--rtk chore(master): release 0.37.0
fix(docs): user facing docs
…master--components--rtk chore(master): release 0.37.1
Next Release
…master--components--rtk chore(master): release 0.37.2
Closes rtk-ai#1561. `rtk git diff` and `rtk git show` previously called compact_diff(stdout, max_lines.unwrap_or(500)) and tracked savings against the resulting (possibly truncated) output. `compact_diff` does both real RTK compression *and* the early-break truncation at `result.len() >= max_lines`. When the user passed `--max-lines N`, the truncated tail counted as RTK savings — exactly the inflation pattern fixed for `rtk read` in rtk-ai#1045 / rtk-ai#1076. Apply the same shape here: * Add a fixed `RTK_DIFF_BUDGET = 500` constant. compact_diff is always called with this budget so its early-break is a real RTK compression decision. * Add a `truncate_to_lines(&str, Option<usize>)` post-step that honors the user's `--max-lines`. Returns `Cow::Borrowed` when no truncation is requested, so the no-flag path is zero-alloc. * In `run_diff` and `run_show`, display the user-truncated slice but track against the RTK-compressed (pre-user-truncation) string. When `max_lines` is None, behavior is unchanged. Tests: * truncate_to_lines: no-op fast path, under-limit body, over-limit breadcrumb. * End-to-end shape: when user passes --max-lines 5 against a 200-line compacted diff, displayed has <= 6 lines + breadcrumb and tracking sees the full 200-line text without breadcrumb.
Collaborator
📊 Automated PR Analysis
SummaryFixes inflated RTK token savings tracking when users pass --max-lines to Review Checklist
Linked issues: #1561 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
Contributor
Author
|
Closing per the triage feedback — thanks! |
This was referenced May 26, 2026
maxmilian
added a commit
to maxmilian/rtk
that referenced
this pull request
May 26, 2026
Follow-up to rtk-ai#1045's fix in `rtk read`. `rtk git diff` and `rtk git show` were doing the same thing: passing the user's `--max-lines N` straight into `compact_diff`, which both compresses and truncates in the same pass. The post-truncation text was then handed to `timer.track`, so any bytes the user themselves asked to hide were recorded as RTK token savings. The fix splits the two concerns: * `RTK_DIFF_BUDGET = 500` — RTK's standard compression budget, used by both `run_diff` and `run_show` regardless of user flags. This is real RTK compression and counts as savings. * `truncate_to_lines(text, n)` — applies the user's `--max-lines` cap on top of an already-compacted diff. Display-only, never tracked. * `prepare_diff_section(raw, user_max_lines) -> (displayed, tracked)` — central helper called by both `run_diff` and `run_show`. `tracked` is always `compact_diff(raw, RTK_DIFF_BUDGET)` so the routing invariant is unit-testable and an accidental refactor that re-introduces the bug fails CI. User-facing: when `--max-lines N` is passed and the RTK-budget output exceeds N lines, the trailing hint becomes `... (M lines hidden by --max-lines)` (terse, matches the existing `[full diff: rtk git diff --no-compact]` style emitted by `compact_diff` itself). Out of scope (per the issue): - Polluted historical data in the local tracking DB. - Pre-existing `verbose`-gated "--- Changes ---" header divergence between `run_diff` (unconditional) and `run_show` (gated). - CLI parser hardening for `--max-lines 0` (helper is panic-safe; defensive rejection at the parser is a separate concern). Avoids the procedural issues that closed prior attempt rtk-ai#1573: branched cleanly from `upstream/develop`, no CHANGELOG / Cargo.toml / release-please-manifest edits (release-please owns those).
maxmilian
added a commit
to maxmilian/rtk
that referenced
this pull request
Jun 6, 2026
Follow-up to rtk-ai#1045's fix in `rtk read`. `rtk git diff` and `rtk git show` were doing the same thing: passing the user's `--max-lines N` straight into `compact_diff`, which both compresses and truncates in the same pass. The post-truncation text was then handed to `timer.track`, so any bytes the user themselves asked to hide were recorded as RTK token savings. The fix splits the two concerns: * `RTK_DIFF_BUDGET = 500` — RTK's standard compression budget, used by both `run_diff` and `run_show` regardless of user flags. This is real RTK compression and counts as savings. * `truncate_to_lines(text, n)` — applies the user's `--max-lines` cap on top of an already-compacted diff. Display-only, never tracked. * `prepare_diff_section(raw, user_max_lines) -> (displayed, tracked)` — central helper called by both `run_diff` and `run_show`. `tracked` is always `compact_diff(raw, RTK_DIFF_BUDGET)` so the routing invariant is unit-testable and an accidental refactor that re-introduces the bug fails CI. User-facing: when `--max-lines N` is passed and the RTK-budget output exceeds N lines, the trailing hint becomes `... (M lines hidden by --max-lines)` (terse, matches the existing `[full diff: rtk git diff --no-compact]` style emitted by `compact_diff` itself). Out of scope (per the issue): - Polluted historical data in the local tracking DB. - Pre-existing `verbose`-gated "--- Changes ---" header divergence between `run_diff` (unconditional) and `run_show` (gated). - CLI parser hardening for `--max-lines 0` (helper is panic-safe; defensive rejection at the parser is a separate concern). Avoids the procedural issues that closed prior attempt rtk-ai#1573: branched cleanly from `upstream/develop`, no CHANGELOG / Cargo.toml / release-please-manifest edits (release-please owns those).
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.
Closes #1561.
Background
Sibling of #1045 (already addressed for `rtk read` in #1076). `rtk git diff` and `rtk git show` previously called:
and then tracked savings against the resulting (possibly truncated) output. `compact_diff` performs both real RTK compression and the early-break truncation at `result.len() >= max_lines`. When the user passed `--max-lines N`, the truncated tail was counted as RTK savings — the same inflation pattern as #1045.
Fix
Apply the same shape #1076 used for read:
Behavior
Test plan
Four regression tests under `cmds::git::git::tests`:
Results:
Notes