Skip to content

feat: add git working tree diff toggle in diff panel#1809

Open
D3OXY wants to merge 1 commit intopingdotgg:mainfrom
D3OXY:feat/git-diff-toggle
Open

feat: add git working tree diff toggle in diff panel#1809
D3OXY wants to merge 1 commit intopingdotgg:mainfrom
D3OXY:feat/git-diff-toggle

Conversation

@D3OXY
Copy link
Copy Markdown
Contributor

@D3OXY D3OXY commented Apr 7, 2026

Closes #1590

Summary

Adds a toggle in the diff panel header that switches between two modes:

  • Session mode (default) — existing checkpoint-based turn-by-turn diffs, unchanged behavior.
  • Git mode — live git diff HEAD output showing all staged + unstaged changes on tracked files.

This gives visibility into changes made outside the agent (manual edits, IDE refactors, other tools) and provides a reliability fallback when checkpoint-based diffs are incomplete or unavailable.

What changed

Contracts (packages/contracts)

  • Added GitWorkingTreeDiffInput / GitWorkingTreeDiffResult schemas in git.ts
  • Added git.workingTreeDiff RPC method definition in rpc.ts
  • Added workingTreeDiff to the NativeApi.git interface in ipc.ts

Server (apps/server)

  • Added readWorkingTreeDiff to the GitCoreShape service interface
  • Implemented it in the GitCore layer: runs git diff HEAD --patch --minimal --no-color, with a fallback to git diff --cached for repos with no commits yet. Output capped at 512KB with truncation.
  • Wired the git.workingTreeDiff RPC handler in ws.ts

Web (apps/web)

  • Added gitWorkingTreeDiffQueryOptions React Query helper in gitReactQuery.ts
  • Added workingTreeDiff to the RPC client and NativeApi wiring
  • Added diffScope: "session" | "git" URL search param in diffRouteSearch.ts
  • Updated DiffPanel.tsx:
    • New session/git toggle group in the header (list icon / git branch icon), placed before the existing stacked/split toggle
    • In session mode: existing turn chip strip (unchanged)
    • In git mode: turn strip hidden, replaced with a "Working tree changes" label
    • Both modes share the same diff renderer, word-wrap, and stacked/split controls
    • Live refresh: the git diff query is automatically invalidated whenever the existing git status subscription detects working tree changes — no polling needed

Tests

  • Added 3 test cases for diffScope parsing in diffRouteSearch.test.ts

UI

image

Design decisions

  • Refresh strategy: piggybacks on the existing subscribeGitStatus stream. When the server broadcasts a git status change, the diff query is invalidated and refetches. Zero polling overhead.
  • Output cap: 512KB max patch output, truncated with [truncated] marker. Larger than readRangeContext's 59KB cap since working tree diffs tend to be bigger, but still bounded.
  • No-commit repos: falls back to git diff --cached to handle initial-add scenarios gracefully.
  • Tracked files only: git diff HEAD covers staged + unstaged changes on tracked files. Untracked files are excluded (consistent with checkpoint diffs).
  • URL-persisted scope: diffScope is stored in the URL search params so the mode survives navigation and can be deep-linked.

Test plan

  • Open diff panel → verify session mode works exactly as before (turn chips, all turns, per-turn diffs)
  • Toggle to git mode → verify working tree diff appears
  • Make a manual file edit → verify git diff panel updates automatically (via status subscription)
  • Run an agent turn → verify git diff updates as changes are written
  • Toggle back to session mode → verify turn diffs are still intact
  • Test on a repo with no commits → verify no crash (cached diff fallback)
  • Test stacked/split and word-wrap toggles work in both modes
  • Verify diffScope=git persists in URL across navigation

Note

Add git working tree diff toggle to the diff panel

  • Adds a scope toggle (session / git) to the diff panel in DiffPanel.tsx, letting users switch between checkpoint diffs and the current working tree diff.
  • The working tree diff is fetched via a new git.workingTreeDiff WebSocket RPC endpoint, backed by readWorkingTreeDiff in GitCore.ts, which runs git diff HEAD or git diff --cached depending on whether commits exist.
  • Output is truncated at 512 KB (WORKING_TREE_DIFF_MAX_OUTPUT_BYTES). The diff is automatically re-fetched on git status changes.
  • The selected scope is encoded in the URL via a new diffScope search param, parsed and validated in diffRouteSearch.ts.

Macroscope summarized a17b919.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 7, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 131fed11-2105-442d-8e75-fb90660be9bc

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Apr 7, 2026
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp bot commented Apr 7, 2026

Approvability

Verdict: Needs human review

This PR introduces a new user-facing feature: a toggle in the diff panel allowing users to switch between session-based diffs and git working tree diffs. While well-structured and self-contained, new features with user-facing behavior changes warrant human review. The author is also new to the primary files being modified.

You can customize Macroscope's approvability policy. Learn more.

Add a toggle in the diff panel header that switches between session
(checkpoint-based turn diffs) and git (live working tree diff) modes.

Closes pingdotgg#1590
@D3OXY D3OXY force-pushed the feat/git-diff-toggle branch from 37ac2f5 to a17b919 Compare April 16, 2026 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Add git diff mode toggle in the diff panel

1 participant