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 in DiffPanel.tsx to switch between session checkpoint diffs and the current git working tree diff.
  • Introduces a readWorkingTreeDiff method in GitCore.ts that diffs against HEAD when commits exist, or against staged changes when there are none; output is capped at 512KB.
  • Exposes the diff via a new git.workingTreeDiff WebSocket RPC, wired through contracts, the WS server, and the native API client.
  • The diffScope query param is parsed and validated in diffRouteSearch.ts; it is stripped when the diff panel is closed or the value is invalid.
  • The working tree diff query is invalidated automatically when git status changes.

Macroscope summarized 37ac2f5.

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
@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: 624233d9-1201-432e-8bcf-e00b154b069a

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 adds a new user-facing feature: a toggle to switch between session checkpoint diffs and git working tree diffs in the diff panel. It introduces new backend functionality, a new RPC endpoint, and new UI controls. New features with user-facing behavior changes warrant human review regardless of implementation quality.

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

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