Skip to content

feat(read,git): add read diet mode and smarter git diff filtering#552

Open
bz00qa wants to merge 2 commits intortk-ai:developfrom
bz00qa:feat/read-git-enhancements
Open

feat(read,git): add read diet mode and smarter git diff filtering#552
bz00qa wants to merge 2 commits intortk-ai:developfrom
bz00qa:feat/read-git-enhancements

Conversation

@bz00qa
Copy link
Copy Markdown

@bz00qa bz00qa commented Mar 12, 2026

Summary

Read Diet Mode

  • rtk read --diet <file>: Markdown-aware filtering that strips verbose patterns while preserving essential content
    • Strips code block contents (replaces with "(code example omitted)")
    • Collapses tables (keeps header + separator, shows "(N rows omitted)")
    • Removes checklists (- [ ], - [x])
    • Strips HTML comments (single-line and multi-line)
    • Collapses consecutive blank lines
    • Strips decorative lines (===, ~~~)
  • Useful for reading CLAUDE.md and other config files with reduced token overhead

Smarter Git Diff

  • Auto stat-only for diffs >1000 lines — prevents token bloat on large changesets
  • Binary file detection — shows "(binary file)" instead of raw binary content
  • Context line stripping — only shows +/- changes, not surrounding unchanged lines (context is noise for LLMs)

Clippy Fixes

  • Replace deprecated map_or(false, ...) with is_some_and(...) in git.rs
  • Replace .last() with .next_back() in git.rs and container.rs

Changes

File Description
src/read.rs diet_markdown() + run_diet() + 7 tests
src/git.rs Large diff auto-stat, binary detection, context stripping, clippy fixes + 3 tests
src/container.rs Clippy next_back() fixes
src/main.rs --diet flag on Read command + routing

Test plan

  • All 897 tests pass (1 pre-existing binlog CRLF failure)
  • 10 new tests (7 read diet + 3 git diff)
  • cargo fmt --all --check passes
  • Manual: rtk read --diet CLAUDE.md — verify reduced output
  • Manual: rtk git diff on a repo with binary files

🤖 Generated with Claude Code

Read enhancements:
- Add `rtk read --diet` mode for markdown: strips code blocks, collapses
  tables, removes checklists/HTML comments, collapses blank lines
- 7 new tests for diet mode including token savings verification

Git diff improvements:
- Auto switch to stat-only for diffs >1000 lines (prevents token bloat)
- Binary file detection (shows "(binary file)" instead of raw content)
- Skip context lines in hunks (only show +/- changes, not surrounding code)
- 3 new tests for large diff, binary, and context stripping

Clippy fixes:
- Replace deprecated `map_or(false, ...)` with `is_some_and(...)` in git.rs
- Replace `.last()` with `.next_back()` in git.rs and container.rs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: bz00qa <bz00qa.hub@gmail.com>
@bz00qa bz00qa force-pushed the feat/read-git-enhancements branch from b55150d to 9da454d Compare March 13, 2026 16:34
@bz00qa bz00qa changed the base branch from master to develop March 13, 2026 16:34
Remove orthogonal clippy refactors (next_back, is_some_and) that belong
in a separate chore PR. Add CHANGELOG.md and README.md entries for
read --diet mode and smarter git diff.

Signed-off-by: bz00qa <bz00qa.hub@gmail.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: bz00qa <bz00qa.hub@gmail.com>
@bz00qa bz00qa changed the title feat: read diet mode, smarter git diff, clippy fixes feat(read,git): add read diet mode and smarter git diff filtering Mar 13, 2026
bz00qa added a commit to bz00qa/rtk_fork that referenced this pull request Mar 13, 2026
Apply clippy suggestions carved out from feature PRs rtk-ai#551 and rtk-ai#552:
- container.rs: .last() → .next_back() (2 instances)
- git.rs: .map_or(false, ...) → .is_some_and(...) (2 instances)
- git.rs: .last() → .next_back() (1 instance)
- init.rs: unnecessary format!() → .to_string() (1 instance)
- init.rs: unnecessary & on &str parameters (2 instances)

Signed-off-by: bZ00qa <167500396+bz00qa@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@pszymkowiak
Copy link
Copy Markdown
Collaborator

This PR has merge conflicts with develop. Please rebase:

git fetch upstream develop
git rebase upstream/develop
git push --force-with-lease

Labeling awaiting-changes until conflicts are resolved.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@aeppling
Copy link
Copy Markdown
Contributor

Hey

We are cleaning up the codebase and improving the project structure for better onboarding. As part of this effort, PR #826 reorganizes src/ from a flat layout into subfolders.

No logic changes — only file moves and import path updates.

What you need to do

Rebase your branch on develop when receiving this comment:

git fetch origin && git rebase origin/develop

Git detects renames automatically. If you get import conflicts, update the paths:

use crate::git;        // now: use crate::cmds::git::git;
use crate::tracking;   // now: use crate::core::tracking;
use crate::config;     // now: use crate::core::config;
use crate::init;       // now: use crate::hooks::init;
use crate::gain;       // now: use crate::analytics::gain;

Need help rebasing? Tag @aeppling

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants