Skip to content

feat(git): filter large git show blob dumps with recovery and Latin-1 decoding - #3064

Closed
breisnerlopez wants to merge 3 commits into
rtk-ai:developfrom
breisnerlopez:feat/git-show-blob-filter
Closed

breisnerlopez wants to merge 3 commits into
rtk-ai:developfrom
breisnerlopez:feat/git-show-blob-filter

Conversation

@breisnerlopez

@breisnerlopez breisnerlopez commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • feat(git): git show <rev>:<path> blob dumps (previously passed through at 0% savings) are now filtered — large text blobs are capped to an 8 KiB preview with a tail -n +N recovery pointer (the full blob is tee'd); small blobs, tree listings, binary, and blobs too large to recover intact pass through unchanged.
  • Encoding fix: blobs are captured as raw bytes and decoded encoding-aware — ISO-8859 / Latin-1 files (e.g. Oracle PL/SQL .pck) are transcoded losslessly instead of being corrupted into U+FFFD by lossy UTF-8, which also unblocks their compression. Ambiguous single-byte encodings (CP1252) and binary pass through raw. Measured on a real 77 KB Latin-1 blob: 0% → 89% savings with the É→� corruption removed. (Same class of fix as rtk curl http://....tar.gz | tar -xzf fails due rtk truncation, eg "(153 more lines, 94292 bytes total)" #1087.)
  • fix(tee): recovery-file slugs (an embedded path duplicating the command) are hashed when long, saving ~12 tokens per truncation hint and fixing a latent collision where sibling paths in the same second overwrote each other's recovery file.
  • refactor(output): dropped RTK-invented advisory hints ([hint] Run ruff/pip/black/dotnet/rubocop…) and the go-build decorative separator — the counts they restate are already shown, so no signal is lost.

Test plan

  • cargo fmt --all && cargo clippy --all-targets && cargo test — clippy 0 warnings; 2449 tests pass. (The one failing test, git_checkout_dirty_tree_error_keeps_file_list, is pre-existing and locale-dependent — it also fails on a clean develop, unrelated to this PR.)
  • Manual testing:
    • rtk git show HEAD:src/main.rs → 120 KB → 8 KB, tail -n +N recovery reconstructs byte-for-byte
    • rtk git show HEAD:<latin1.pck> → 89% savings, no �, recovery byte-identical to iconv -f ISO-8859-1
    • rtk git show HEAD:<cp1252.pck> → byte-exact passthrough (no wrong transcode)
    • rtk git show HEAD:<dir> (tree) and HEAD:<binary> → passthrough unchanged
    • 6 blobs from the same dir in the same second → 6 distinct recovery files (the old truncation collided them)

New unit + fixture tests cover decode (UTF-8 / Latin-1 / CP1252 / binary), byte-cap windowing, recovery-offset math, slug hashing/collision, and edge cases.

…tors

Remove RTK-invented text that carries no signal an agent needs: the
"[hint] Run `ruff check --fix` / `ruff format` / `pip install --upgrade`
/ `black .` / `dotnet format`" advisory lines (the fixable/formatted
counts are already shown) and the decorative box-drawing separator in the
go build failure header. Rubocop keeps the correctable count and drops the
"run `rubocop -A`" how-to.
… decoding

`git show <rev>:<path>` dumps raw file content that RTK previously passed
through unfiltered (0% savings). Large text blobs are now capped to an 8 KiB
byte budget with a `tail -n +N` recovery pointer (the full blob is tee'd),
mirroring the commit-diff path. Small blobs, tree listings, binary, and
blobs too large for the recovery file to store intact are passed through
unchanged.

Blobs are captured as raw bytes and decoded encoding-aware: ISO-8859 /
Latin-1 files (e.g. Oracle PL/SQL packages) are transcoded losslessly
instead of being corrupted into U+FFFD by lossy UTF-8 decoding, which also
unblocks their compression. Ambiguous single-byte encodings (CP1252 range)
and binary content are passed through raw rather than guessed.
@CLAassistant

CLAassistant commented Jul 19, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

…rten hints

The tee recovery filename embeds a command-derived slug (often a file path
that duplicates the command the LLM already issued), costing ~12 tokens in
every truncation hint. Long slugs (>24 chars) now collapse to a short
readable prefix plus a 6-hex SHA-256 tag.

This also fixes a latent collision in the old 40-char truncation: sibling
paths sharing a long common prefix (e.g. several `git show` blobs from the
same directory in the same second) truncated to an identical filename and
overwrote each other's recovery file. Hashing the full slug makes distinct
commands produce distinct filenames (~1-in-16M collision).
@breisnerlopez

breisnerlopez commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Gentle nudge for maintainer review when someone has a moment — no rush.

Status: targets develop, CI green, CLA signed, MERGEABLE. cargo clippy clean, 2449 tests pass (the one red test, git_checkout_dirty_tree_error_keeps_file_list, is pre-existing and locale-dependent — also fails on a clean develop).

The load-bearing change is the encoding fix: git show <rev>:<path> on an ISO-8859-1 blob (e.g. an Oracle PL/SQL .pck) was decoded lossily and corrupted É into U+FFFD, which also blocked compression. It now transcodes losslessly and the recovery file is byte-identical to iconv -f ISO-8859-1. Measured 0% → 89% on a real 77 KB Latin-1 blob.

On the single-focus rule in CONTRIBUTING: the PR also carries a fix(tee) recovery-slug hash and a refactor(output) that drops the invented advisory hints. If you'd rather review the feat(git) blob filter on its own, I'm happy to split those two out into their own PRs — just say the word.

@breisnerlopez

Copy link
Copy Markdown
Contributor Author

Closing in favor of smaller, focused PRs (per the single-focus PR guideline in CONTRIBUTING) rebased onto current develop:

The subjective advisory-hints refactor that was bundled here has been dropped. Splitting this way should make review much easier. Thanks!

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.

2 participants