Skip to content

feat(tui): add last-commit diff view option - #13257

Merged
johnnyeric merged 2 commits into
Kilo-Org:mainfrom
IamCoder18:last-commit-diff-viewer
Aug 31, 2026
Merged

johnnyeric merged 2 commits into
Kilo-Org:mainfrom
IamCoder18:last-commit-diff-viewer

Conversation

@IamCoder18

@IamCoder18 IamCoder18 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Issue

Fixes #13258

Context

The TUI diff viewer offers three sources: working tree, main branch, and last assistant turn. There was no way to inspect only the changes introduced by the most recent git commit (HEAD vs HEAD~1) without mixing in working tree noise. This adds a new "Last commit" entry to the Switch source dialog that drives a new last-commit mode on the existing Vcs.diff route.

Implementation

A new last-commit mode on Vcs.diff that resolves HEAD~1 via git rev-parse and returns the diff between the two refs. The ref-to-ref helpers (diffRefs, statsRefs, patchAllRefs) live in a Kilo-only module (packages/opencode/src/kilocode/git-refs.ts) so the shared Git.Interface is not widened. The result is built directly to FileDiff[] instead of going through the shared files() helper, so a missing batched patch can never fall through to the working-tree-vs-/dev/null untracked diff path. The TUI diff viewer adds the new mode to its DiffMode type, Switch source dialog, header label, and help dialog. SDK and OpenAPI spec are regenerated.

How to Test

Manual/local verification

Manually tested end-to-end in the TUI (bun dev) against a git repo with multiple commits and uncommitted working tree changes. Confirmed the "Last commit" option appears in the Switch source dialog, shows only the files changed in the most recent commit with correct patch content, and excludes uncommitted working tree edits.

Checklist

  • Issue linked above, or exception explained
  • Tests/verification described
  • Screenshots/video included for visual changes, or marked N/A
  • Changeset considered for user-facing changes
  • I personally reviewed the diff and can explain the changes, including any AI-assisted work.

@kilo-code-bot

kilo-code-bot Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/opencode/test/project/vcs.test.ts 399 timeout is on the instance-options object, so Bun never receives it
Files Reviewed (1 files)
  • .changeset/last-commit-diff-batch-recovery.md - 0 issues

Fix these issues in Kilo Cloud

Previous Review Summaries (3 snapshots, latest commit 7400444)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 7400444)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/opencode/test/project/vcs.test.ts 399 timeout is on the instance-options object, so Bun never receives it
Files Reviewed (3 files)
  • .changeset/last-commit-diff-batch-recovery.md - 0 issues
  • packages/opencode/src/project/vcs.ts - 0 issues
  • packages/opencode/test/project/vcs.test.ts - 1 issue

Fix these issues in Kilo Cloud

Previous review (commit 24a68cf)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (3 files)
  • packages/opencode/src/git/index.ts
  • packages/opencode/src/kilocode/git-refs.ts
  • packages/opencode/src/project/vcs.ts

Previous review (commit 55ce8ec)

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 1
Issue Details (click to expand)

WARNING

File Line Issue
packages/opencode/src/project/vcs.ts 257 lastCommitDiff passes undefined as the fallback ref, so a missing batched patch can be replaced by a working-tree /dev/null untracked diff instead of the last-commit patch.

SUGGESTION

File Line Issue
packages/opencode/src/git/index.ts 88 New diffRefs/statsRefs/patchAllRefs helpers duplicate existing git.diff/stats/patchAll and widen the shared Git interface; a range string into the existing helpers (or a Kilo-only wrapper) would shrink the upstream fork.
Files Reviewed (8 files)
  • .changeset/last-commit-diff-viewer.md - 0 issues
  • packages/opencode/src/git/index.ts - 1 issue
  • packages/opencode/src/project/vcs.ts - 1 issue
  • packages/opencode/test/project/vcs.test.ts - 0 issues
  • packages/sdk/js/src/v2/gen/sdk.gen.ts - 0 issues
  • packages/sdk/js/src/v2/gen/types.gen.ts - 0 issues
  • packages/sdk/openapi.json - 0 issues
  • packages/tui/src/feature-plugins/system/diff-viewer.tsx - 0 issues

Fix these issues in Kilo Cloud


Reviewed by grok-4.6 · Input: 160.1K · Output: 10.6K · Cached: 265.1K

Review guidance: REVIEW.md from base branch main

Adds a new diff source to the TUI diff viewer that shows only the
changes introduced by the most recent git commit (HEAD vs HEAD~1),
independent of working tree state.

- Extend Vcs.Mode with "last-commit" and implement lastCommitDiff
  using new Git helpers (diffRefs, statsRefs, patchAllRefs) that
  compare two arbitrary refs. Build a batched patch from HEAD~1..HEAD
  so each file gets the correct ref-to-ref patch instead of falling
  through to the patchUntracked path.
- Regenerate SDK and OpenAPI spec for the new mode.
- Expose the option in the diff viewer's Switch source dialog.
@IamCoder18
IamCoder18 force-pushed the last-commit-diff-viewer branch from 55ce8ec to 24a68cf Compare August 20, 2026 01:08
@IamCoder18

Copy link
Copy Markdown
Contributor Author

Ready for review!

Comment thread packages/opencode/src/project/vcs.ts Outdated
@IamCoder18
IamCoder18 force-pushed the last-commit-diff-viewer branch 2 times, most recently from 7400444 to 0f2f2e8 Compare August 30, 2026 15:58
When a single oversized file in a commit pushed the unified batch
patch over MAX_TOTAL_PATCH_BYTES, lastCommitDiff discarded the
batched patches of every smaller file and returned empty stubs. It
also silently dropped any chunk whose filename could not be parsed
back from the patch header.

Route the lastCommitDiff loop through the existing patchForItem +
totalPatch helpers used by diffAgainstRef: files present in the
batch map use the batched patch, files missing from it (truncated
tail or failed filename match) fall back to a per-file
`git diff <parent>..HEAD -- <file>` call, and the running byte
total still caps the overall output so behavior matches diff('branch').
@IamCoder18
IamCoder18 force-pushed the last-commit-diff-viewer branch from 0f2f2e8 to e846360 Compare August 30, 2026 16:01
@IamCoder18

Copy link
Copy Markdown
Contributor Author

Fixed. diff("last-commit") now falls back to per-file fetches when the batch is truncated or a chunk's filename can't be parsed, so an oversized file can't wipe out the smaller diffs in the same commit.

@IamCoder18
IamCoder18 requested a review from johnnyeric August 30, 2026 16:30
@johnnyeric
johnnyeric merged commit d638418 into Kilo-Org:main Aug 31, 2026
32 checks passed
@johnnyeric

Copy link
Copy Markdown
Contributor

Thanks @IamCoder18 for the contribution! just merged it.

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.

[FEATURE]: Add last-commit diff view option to TUI diff viewer

2 participants