Skip to content

fix: reduce gh diff / git diff / gh api truncation (#354)#370

Merged
pszymkowiak merged 9 commits intomasterfrom
fix/354-gh-diff-truncation
Mar 6, 2026
Merged

fix: reduce gh diff / git diff / gh api truncation (#354)#370
pszymkowiak merged 9 commits intomasterfrom
fix/354-gh-diff-truncation

Conversation

@FlorianBruniaux
Copy link
Collaborator

Problem

RTK was too aggressively truncating gh api, gh pr diff, and git diff outputs, forcing Claude to re-fetch multiple times and negating token savings. Two root causes:

  1. Hardcoded limits too low (100 total lines, 10 lines/hunk)
  2. gh api was converting JSON to a schema (types without values), destroying all data

Changes

src/git.rs

  • compact_diff: max_hunk_lines 10 → 30
  • compact_diff: default max_lines 100 → 500 (for git diff and git show)

src/gh_cmd.rs

  • gh api: replaced JSON→schema transformation with passthrough — gh api is an explicit/advanced command, user knows what they asked for
  • gh pr diff: increased limit 100 → 500; added --no-compact flag for full passthrough (gh CLI doesn't know this flag, it's stripped before forwarding)
  • gh pr view: passthrough when user provides --json, --jq, or --web (previously forced its own --json fields and ignored user-requested fields)

Testing

  • 664 tests pass (cargo test)
  • 7 new unit tests added (2 in git.rs, 5 in gh_cmd.rs)
  • All changes are either limit increases or passthrough patterns (already established in the codebase)

Verification

rtk git diff                          # increased limits
rtk git diff --no-compact             # passthrough (existing)
rtk gh pr diff <num>                  # increased limits
rtk gh pr diff <num> --no-compact     # new passthrough
rtk gh api repos/rtk-ai/rtk/pulls    # full JSON, no schema
rtk gh pr view <num> --json body      # passthrough, user fields respected

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings March 6, 2026 10:32
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces over-aggressive output truncation for git diff/git show and GitHub CLI (gh) integrations, and fixes gh api output handling by switching it to passthrough so returned JSON values are preserved.

Changes:

  • Increased git::compact_diff defaults/limits (total lines and per-hunk lines) to reduce unnecessary refetching.
  • Updated rtk gh api to passthrough (removing the JSON→schema transformation that dropped values).
  • Improved rtk gh pr diff and rtk gh pr view behavior: higher diff limit, new --no-compact passthrough for pr diff, and passthrough for pr view when users request --json/--jq/--web.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/git.rs Raises diff compaction limits and adds unit tests covering the new thresholds.
src/gh_cmd.rs Switches gh api to passthrough; adds gh pr diff --no-compact; respects user pr view flags by passthrough in those cases.
README.md Updates the expected rtk --version example to 0.27.1.
CLAUDE.md Updates the expected rtk --version example to 0.27.1.
ARCHITECTURE.md Updates the documented RTK version to 0.27.1.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

FlorianBruniaux and others added 6 commits March 6, 2026 12:02
- compact_diff: increase max_hunk_lines 10→30, max_lines default 100→500
- gh api: passthrough instead of JSON→schema destruction
- gh pr diff: add --no-compact flag + increase limit to 500
- gh pr view: passthrough when --json/--jq/--web provided by user

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@FlorianBruniaux FlorianBruniaux force-pushed the fix/354-gh-diff-truncation branch from bc730f9 to 5db3c39 Compare March 6, 2026 11:04
@pszymkowiak pszymkowiak merged commit e356c12 into master Mar 6, 2026
3 checks passed
navidemad pushed a commit to navidemad/rtk that referenced this pull request Mar 6, 2026
…ai#370)

* fix: reduce gh diff / git diff / gh api truncation (rtk-ai#354)

- compact_diff: increase max_hunk_lines 10→30, max_lines default 100→500
- gh api: passthrough instead of JSON→schema destruction
- gh pr diff: add --no-compact flag + increase limit to 500
- gh pr view: passthrough when --json/--jq/--web provided by user

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* docs: update version reference 0.26.0→0.27.1 in README

* docs: update version reference 0.26.0→0.27.1 in CLAUDE.md

* docs: update version reference 0.26.0→0.27.1 in ARCHITECTURE.md

* fix: resolve compile errors in gh_cmd.rs (type mismatches)

* fix: use explicit .iter() in pr_diff loop (avoids &&[String] ambiguity)

* docs: fix version reference 0.27.x→0.27.1 in README

* fix: remove shadowed extra_args in view_pr (was &&[String] not iterator)

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

3 participants