Skip to content

The agent that grows with you

feat(desktop): add review-pane diff scope selector (Uncommitted / Branch / Last turn)

Chukuwebuka-2003b27d9eb7c00b
diff --git a/apps/desktop/src/app/right-sidebar/review/index.test.tsx b/apps/desktop/src/app/right-sidebar/review/index.test.tsx
new file mode 100644
index 00000000000..554aadddc37
--- /dev/null
+++ b/apps/desktop/src/app/right-sidebar/review/index.test.tsx
@@ -0,0 +1,66 @@
+import { cleanup, fireEvent, render, screen } from '@testing-library/react'
+import { afterEach, beforeEach, describe, expect, it } from 'vitest'
+
+import type { HermesReviewFile } from '@/global'
+import { I18nProvider } from '@/i18n'
+import { $panesFlipped } from '@/store/layout'
+import { $reviewDiff, $reviewDiffLoading, $reviewFiles, $reviewIsRepo, $reviewLoading, $reviewScope, $reviewSelectedPath } from '@/store/review'
+
+import { ReviewPane } from './index'
+
+const file = (path: string): HermesReviewFile => ({ added: 1, path, removed: 0, staged: false, status: 'M' })
+
+function renderPane() {
+ return render(
+ <I18nProvider configClient={null} initialLocale="en">
+ <ReviewPane />
+ </I18nProvider>
+ )
+}
+
+describe('ReviewPane header gating', () => {
+ beforeEach(() => {
+ $panesFlipped.set(false)
+ $reviewFiles.set([file('a.ts')])
+ $reviewIsRepo.set(true)
+ $reviewLoading.set(false)
+ $reviewDiff.set(null)
+ $reviewDiffLoading.set(false)
+ $reviewSelectedPath.set(null)
+ $reviewScope.set('uncommitted')
+ })
+
+ afterEach(() => {
+ cleanup()
+ $reviewFiles.set([])
+ $reviewScope.set('uncommitted')
+ })
+
+ it('enables stage-all / revert-all under the uncommitted scope', () => {
+ renderPane()
+
+ expect((screen.getByLabelText('Stage all') as HTMLButtonElement).disabled).toBe(false)
+ expect((screen.getByLabelText('Revert all') as HTMLButtonElement).disabled).toBe(false)
+ })
+
+ it('disables stage-all / revert-all under the branch scope (read-only)', () => {
+ $reviewScope.set('branch')
+
+ renderPane()
+
+ expect((screen.getByLabelText('Stage all') as HTMLButtonElement).disabled).toBe(true)
+ expect((screen.getByLabelText('Revert all') as HTMLButtonElement).disabled).toBe(true)
+ })
+
+ it('renders the three scope options and switches scope on selection', () => {
+ renderPane()
+
+ expect(screen.getByText('Uncommitted')).toBeTruthy()
+ expect(screen.getByText('Branch')).toBeTruthy()
+ expect(screen.getByText('Last turn')).toBeTruthy()
+
+ fireEvent.click(screen.getByText('Branch'))
+
+ expect($reviewScope.get()).toBe('branch')
+ })
+})
diff --git a/apps/desktop/src/app/right-sidebar/review/index.tsx b/apps/desktop/src/app/right-sidebar/review/index.tsx
index 08c82fb466a..d9bf29a7971 100644
--- a/apps/desktop/src/app/right-sidebar/review/index.tsx
+++ b/apps/desktop/src/app/right-sidebar/review/index.tsx
@@ -6,7 +6,9 @@ import { Button } from '@/components/ui/button'
import { Codicon } from '@/components/ui/codicon'
import { ConfirmDialog } from '@/components/ui/confirm-dialog'
import { DiffCount } from '@/components/ui/diff-count'
+import { SegmentedControl } from '@/components/ui/segmented-control'
import { Tip } from '@/components/ui/tooltip'
+import type { HermesReviewScope } from '@/global'
import { useDelayedTrue } from '@/hooks/use-delayed-true'
import { useI18n } from '@/i18n'
import { displayPath } from '@/lib/display-path'
@@ -20,6 +22,7 @@ import {
$reviewIsRepo,
$reviewLoading,
$reviewRevertTarget,
+ $reviewScope,
$reviewSelectedPath,
$reviewTreeMode,
cancelRevert,
@@ -55,6 +58,10 @@ export function ReviewPane() {
const diffLoading = useStore($reviewDiffLoading)
const revertTarget = useStore($reviewRevertTarget)
const treeMode = useStore($reviewTreeMode)
+ const scope = useStore($reviewScope)
+ // Stage / unstage / revert and the ship bar act on the working tree, so they
+ // only apply to the uncommitted scope; branch / last-turn are read-only.
+ const isUncommitted = scope === 'uncommitted'
const selectedFile = files.find(file => file.path === selectedPath)
const hasFiles = files.length > 0
@@ -82,6 +89,20 @@ export function ReviewPane() {
says "review", so the zone header hides it (styles.css). */}
<SidebarPanelLabel data-pane-self-label="">{c.review}</SidebarPanelLabel>
</div>
+ <SegmentedControl<HermesReviewScope>
+ className="mr-1"
+ onChange={id => {
+ $reviewScope.set(id)
+ clearReviewSelection()
+ void refreshReview()
+ }}
+ options={[
+ { id: 'uncommitted', label: c.scopeUncommitted },
+ { id: 'branch', label: c.scopeBranch },
+ { id: 'lastTurn', label: c.scopeLastTurn }
+ ]}
+ value={scope}
+ />
<Tip label={treeMode === 'tree' ? c.viewAsList : c.viewAsTree}>
<Button
aria-label={treeMode === 'tree' ? c.viewAsList : c.viewAsTree}
@@ -98,7 +119,7 @@ export function ReviewPane() {
<Button
aria-label={c.stageAll}
className={ACTION_BTN}
- disabled={!hasFiles}
+ disabled={!hasFiles || !isUncommitted}
onClick={() => void stageReviewFile(null).catch(err => notifyError(err, c.stageAll))}
size="icon-xs"
variant="ghost"
@@ -110,7 +131,7 @@ export function ReviewPane() {
<Button
aria-label={c.revertAll}
className={ACTION_BTN}
- disabled={!hasFiles}
+ disabled={!hasFiles || !isUncommitted}
onClick={() => requestRevert(null)}
size="icon-xs"
variant="ghost"
@@ -161,21 +182,23 @@ export function ReviewPane() {
{displayPath(selectedFile.path)}
</span>
<DiffCount added={selectedFile.added} className="text-[0.64rem] leading-4" removed={selectedFile.removed} />
- <Tip label={selectedFile.staged ? c.unstage : c.stage}>
- <Button
- aria-label={selectedFile.staged ? c.unstage : c.stage}
- className={ACTION_BTN}
- onClick={() =>
- void (
- selectedFile.staged ? unstageReviewFile(selectedFile.path) : stageReviewFile(selectedFile.path)
- ).catch(err => notifyError(err, c.stage))
- }
- size="icon-xs"
- variant="ghost"
- >
- <Codicon name={selectedFile.staged ? 'remove' : 'add'} size="0.8rem" />
- </Button>
- </Tip>
+ {isUncommitted && (
+ <Tip label={selectedFile.staged ? c.unstage : c.stage}>
+ <Button
+ aria-label={selectedFile.staged ? c.unstage : c.stage}
+ className={ACTION_BTN}
+ onClick={() =>
+ void (
+ selectedFile.staged ? unstageReviewFile(selectedFile.path) : stageReviewFile(selectedFile.path)
+ ).catch(err => notifyError(err, c.stage))
+ }
+ size="icon-xs"
+ variant="ghost"
+ >
+ <Codicon name={selectedFile.staged ? 'remove' : 'add'} size="0.8rem" />
+ </Button>
+ </Tip>
+ )}
<Button
aria-label={c.close}
className={ACTION_BTN}
diff --git a/apps/desktop/src/app/right-sidebar/review/ship-bar.test.tsx b/apps/desktop/src/app/right-sidebar/review/ship-bar.test.tsx
new file mode 100644
index 00000000000..5f503dff2a4
--- /dev/null
+++ b/apps/desktop/src/app/right-sidebar/review/ship-bar.test.tsx
@@ -0,0 +1,52 @@
+import { cleanup, render, screen } from '@testing-library/react'
+import { afterEach, beforeEach, describe, expect, it } from 'vitest'
+
+import type { HermesReviewFile } from '@/global'
+import { I18nProvider } from '@/i18n'
+import { $reviewFiles, $reviewScope, $reviewShipInfo } from '@/store/review'
+
+import { ReviewShipBar } from './ship-bar'
+
+const file = (path: string): HermesReviewFile => ({
+ added: 1,
+ path,
+ removed: 0,
+ staged: false,
+ status: 'M'
+})
+
+function renderBar() {
+ return render(
+ <I18nProvider configClient={null} initialLocale="en">
+ <ReviewShipBar />
+ </I18nProvider>
+ )
+}
+
+describe('ReviewShipBar', () => {
+ beforeEach(() => {
+ $reviewFiles.set([file('a.ts')])
+ $reviewShipInfo.set({ ghReady: false, pr: null })
+ $reviewScope.set('uncommitted')
+ })
+
+ afterEach(() => {
+ cleanup()
+ $reviewFiles.set([])
+ $reviewScope.set('uncommitted')
+ })
+
+ it('renders the commit bar for the uncommitted scope', () => {
+ renderBar()
+
+ expect(screen.getByText('Commit')).toBeTruthy()
+ })
+
+ it('renders nothing for the branch scope (committed work has no working-tree actions)', () => {
+ $reviewScope.set('branch')
+
+ const { container } = renderBar()
+
+ expect(container.firstChild).toBeNull()
+ })
+})
diff --git a/apps/desktop/src/app/right-sidebar/review/ship-bar.tsx b/apps/desktop/src/app/right-sidebar/review/ship-bar.tsx
index 22fb94d9bba..2007c3cbb93 100644
--- a/apps/desktop/src/app/right-sidebar/review/ship-bar.tsx
+++ b/apps/desktop/src/app/right-sidebar/review/ship-bar.tsx
@@ -16,6 +16,7 @@ import {
$reviewCommitDefault,
$reviewCommitMsgBusy,
$reviewFiles,
+ $reviewScope,
$reviewScopeTarget,
$reviewShipBusy,
$reviewShipInfo,
@@ -36,6 +37,7 @@ export function ReviewShipBar() {
const { t } = useI18n()
const c = t.statusStack.coding
const files = useStore($reviewFiles)
+ const scope = useStore($reviewScope)
const ship = useStore($reviewShipInfo)
const scopeTarget = useStore($reviewScopeTarget)
const busy = useStore($reviewShipBusy)
@@ -48,9 +50,9 @@ export function ReviewShipBar() {
const canCommit = hasFiles && message.trim().length > 0 && !busy
const canGenerate = hasFiles && !generating && !busy
- // Nothing to commit → no ship bar at all; the pane just shows the tree /
- // "No changes" state.
- if (!hasFiles) {
+ // Commit / push / PR operate on the working tree, so they only make sense for
+ // the uncommitted scope — the branch / last-turn scopes are read-only views.
+ if (scope !== 'uncommitted' || !hasFiles) {
return null
}
diff --git a/apps/desktop/src/store/review.test.ts b/apps/desktop/src/store/review.test.ts
index 29cc93eeb45..9e56b07019c 100644
--- a/apps/desktop/src/store/review.test.ts
+++ b/apps/desktop/src/store/review.test.ts
@@ -1,8 +1,10 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import type { ClientSessionState } from '@/app/types'
import type { HermesReviewFile, HermesReviewShipInfo } from '@/global'
import {
+ $reviewCommitDefault,
$reviewCommitMsgBusy,
$reviewDiff,
$reviewDiffLoading,
@@ -12,11 +14,16 @@ import {
$reviewMaxChurn,
$reviewOpen,
$reviewRevertTarget,
+ $reviewScope,
$reviewScopeCwd,
$reviewScopeTarget,
$reviewSelectedPath,
$reviewShipBusy,
$reviewShipInfo,
+ $reviewTreeMode,
+ $reviewTurnBase,
+ cancelRevert,
+ clearReviewSelection,
closeReview,
commitChanges,
confirmRevert,
@@ -29,9 +36,12 @@ import {
revealReview,
selectReviewFile,
stageReviewFile,
- toggleReview
+ toggleReview,
+ unstageReviewFile,
+ revertReviewFile
} from './review'
-import { $currentCwd } from './session'
+import { $busy, $currentCwd } from './session'
+import { $sessionStates } from './session-states'
// requestOneShot is the only cross-module dependency that must be faked (it
// reaches the gateway); everything else routes through window.hermesDesktop.git,
@@ -59,6 +69,7 @@ function stubReview(over: ReviewStub = {}) {
stage: vi.fn(async () => undefined),
unstage: vi.fn(async () => undefined),
revert: vi.fn(async () => undefined),
+ revParse: vi.fn(async () => null),
commit: vi.fn(async () => undefined),
commitContext: vi.fn(async () => ({ diff: 'd', recent: 'r' })),
push: vi.fn(async () => undefined),
@@ -90,9 +101,13 @@ beforeEach(() => {
$reviewShipBusy.set(false)
$reviewCommitMsgBusy.set(false)
$reviewRevertTarget.set(undefined)
+ $reviewScope.set('uncommitted')
+ $reviewTurnBase.set({})
$reviewScopeCwd.set(null)
$reviewScopeTarget.set('main')
$currentCwd.set('/repo')
+ $busy.set(false)
+ $sessionStates.set({})
})
afterEach(() => {
@@ -170,6 +185,20 @@ describe('refreshReview', () => {
expect($reviewIsRepo.get()).toBe(true)
expect($reviewLoading.get()).toBe(false)
})
+
+ it('passes the selected scope (and last-turn base) to the bridge', async () => {
+ const review = stubReview({ list: vi.fn(async () => ({ files: [] })) })
+ $reviewOpen.set(true)
+ $reviewScope.set('branch')
+
+ await refreshReview()
+ expect(review.list).toHaveBeenCalledWith('/repo', 'branch', null)
+
+ $reviewScope.set('lastTurn')
+ $reviewTurnBase.set({ '/repo': 'abc123' })
+ await refreshReview()
+ expect(review.list).toHaveBeenCalledWith('/repo', 'lastTurn', 'abc123')
+ })
})
describe('$reviewMaxChurn', () => {
@@ -196,6 +225,27 @@ describe('selectReviewFile', () => {
expect(review.diff).toHaveBeenCalledWith('/repo', 'a.ts', 'uncommitted', null, false)
})
+ it('fetches the diff for the selected scope and base', async () => {
+ const review = stubReview({ diff: vi.fn(async () => 'd') })
+ $reviewScope.set('branch')
+
+ await selectReviewFile(file('a.ts'))
+ expect(review.diff).toHaveBeenCalledWith('/repo', 'a.ts', 'branch', null, false)
+
+ $reviewScope.set('lastTurn')
+ $reviewTurnBase.set({ '/repo': 'abc123' })
+ await selectReviewFile(file('a.ts'))
+ expect(review.diff).toHaveBeenCalledWith('/repo', 'a.ts', 'lastTurn', 'abc123', false)
+ })
+
+ it('coerces a falsy diff to empty string (not null)', async () => {
+ stubReview({ diff: vi.fn(async () => '') })
+
+ await selectReviewFile(file('a.ts'))
+
+ expect($reviewDiff.get()).toBe('')
+ })
+
it('sets diff null when there is no bridge', async () => {
delete (window as unknown as { hermesDesktop?: unknown }).hermesDesktop
@@ -436,3 +486,87 @@ describe('generateCommitMessage', () => {
expect(msg).toBe('')
})
})
+
+describe('$reviewCommitDefault', () => {
+ it('remembers the split-button default action', () => {
+ $reviewCommitDefault.set('commitPush')
+ expect($reviewCommitDefault.get()).toBe('commitPush')
+ $reviewCommitDefault.set('commit')
+ expect($reviewCommitDefault.get()).toBe('commit')
+ })
+})
+
+describe('$reviewScope', () => {
+ it('round-trips the three diff scopes', () => {
+ expect($reviewScope.get()).toBe('uncommitted')
+ $reviewScope.set('branch')
+ expect($reviewScope.get()).toBe('branch')
+ $reviewScope.set('lastTurn')
+ expect($reviewScope.get()).toBe('lastTurn')
+ $reviewScope.set('uncommitted')
+ expect($reviewScope.get()).toBe('uncommitted')
+ })
+})
+
+describe('$reviewTurnBase', () => {
+ it('maps each repo cwd to its last-turn HEAD baseline', () => {
+ expect($reviewTurnBase.get()).toEqual({})
+ $reviewTurnBase.set({ '/repo': 'abc123' })
+ expect($reviewTurnBase.get()).toEqual({ '/repo': 'abc123' })
+ })
+})
+
+// Minimal session state: the baseline capture only reads `busy` and `cwd`.
+const sessionState = (busy: boolean, cwd = '/repo'): ClientSessionState => ({ busy, cwd }) as ClientSessionState
+
+describe('turn baseline capture', () => {
+ it('captures HEAD per-cwd when a session turn starts', async () => {
+ stubReview({ revParse: vi.fn(async () => 'deadbeef') })
+
+ $sessionStates.set({ rt_capture: sessionState(true, '/repo') })
+
+ await new Promise(resolve => setTimeout(resolve, 0))
+ expect($reviewTurnBase.get()).toEqual({ '/repo': 'deadbeef' })
+ })
+
+ it('keys baselines by cwd so background / tile worktrees get their own', async () => {
+ stubReview({ revParse: vi.fn(async (cwd: string) => (cwd === '/tile' ? 'tile-sha' : 'main-sha')) })
+
+ $sessionStates.set({ rt_main: sessionState(true, '/repo'), rt_tile: sessionState(true, '/tile') })
+
+ await new Promise(resolve => setTimeout(resolve, 0))
+ expect($reviewTurnBase.get()).toEqual({ '/repo': 'main-sha', '/tile': 'tile-sha' })
+ })
+
+ it('leaves the baseline empty when there is no git bridge', async () => {
+ delete (window as unknown as { hermesDesktop?: unknown }).hermesDesktop
+
+ $sessionStates.set({ rt_nobridge: sessionState(true, '/repo') })
+
+ await new Promise(resolve => setTimeout(resolve, 0))
+ expect($reviewTurnBase.get()).toEqual({})
+ })
+})
+
+describe('mutation gating', () => {
+ it('skips stage/unstage/revert when the scope is not uncommitted', async () => {
+ const review = stubReview()
+ $reviewScope.set('branch')
+
+ await stageReviewFile('a.ts')
+ await unstageReviewFile('a.ts')
+ await revertReviewFile('a.ts')
+
+ expect(review.stage).not.toHaveBeenCalled()
+ expect(review.unstage).not.toHaveBeenCalled()
+ expect(review.revert).not.toHaveBeenCalled()
+ })
+
+ it('still mutates under the default uncommitted scope', async () => {
+ const review = stubReview()
+
+ await stageReviewFile('a.ts')
+
+ expect(review.stage).toHaveBeenCalledWith('/repo', 'a.ts')
+ })
+})
diff --git a/apps/desktop/src/store/review.ts b/apps/desktop/src/store/review.ts
index b2985a45ef3..9cfd9853b6d 100644
--- a/apps/desktop/src/store/review.ts
+++ b/apps/desktop/src/store/review.ts
@@ -3,7 +3,7 @@ import { atom, computed } from 'nanostores'
import { SIDEBAR_COLLAPSE_MEDIA_QUERY } from '@/app/layout-constants'
import { PANE_TOGGLE_REVEAL_EVENT } from '@/components/pane-shell'
import { isPaneVisible, revealTreePane } from '@/components/pane-shell/tree/store'
-import type { HermesReviewFile, HermesReviewShipInfo } from '@/global'
+import type { HermesReviewFile, HermesReviewScope, HermesReviewShipInfo } from '@/global'
import { matchesQuery } from '@/hooks/use-media-query'
import { desktopGit } from '@/lib/desktop-git'
import { isExcludedPath } from '@/lib/excluded-paths'
@@ -15,6 +15,7 @@ import { refreshRepoStatus, repoStatusForCwd } from './coding-status'
import { noteAreaClosed, recordFeatureUse } from './desktop-metrics'
import { stampSessionPrBranch } from './pull-requests'
import { $busy, $currentCwd, $selectedStoredSessionId, $sessions } from './session'
+import { $sessionStates } from './session-states'
import { $workspaceChangeTick } from './workspace-events'
// State for the review pane: the working-tree changed-file list, the selected
@@ -22,9 +23,10 @@ import { $workspaceChangeTick } from './workspace-events'
// session's cwd is the repo; the pane reads git as the source of truth, the
// same bounded "re-probe on structural edges" model as the coding rail.
//
-// Scope is always "uncommitted" — Hermes' flow is agent edits you review BEFORE
-// committing, so branch/last-turn scopes are almost always empty here (unlike
-// Codex, which commits per turn). We show the one view that's always populated.
+// Diff scope is selectable: 'uncommitted' (the review-before-commit default),
+// 'branch' (committed work vs the trunk merge-base), and 'lastTurn' (everything
+// since the current turn began, driven by the $reviewTurnBase HEAD capture).
+// Mutations and the commit/PR ship bar are uncommitted-only.
// Must match the review <Pane id> in desktop-controller (the forced-reveal
// event is addressed by pane id).
@@ -33,6 +35,7 @@ export const REVIEW_PANE_ID = 'review'
const OPEN_KEY = 'hermes.desktop.reviewOpen'
const COMMIT_DEFAULT_KEY = 'hermes.desktop.reviewCommitDefault'
const TREE_MODE_KEY = 'hermes.desktop.reviewTreeMode'
+const SCOPE_KEY = 'hermes.desktop.reviewScope'
const SELECTED_KEY = 'hermes.desktop.reviewSelectedPath'
const REVIEW_REFRESH_DEBOUNCE_MS = 100
const SHIP_INFO_STALE_MS = 30_000
@@ -64,6 +67,21 @@ export function toggleReviewTreeMode(): void {
$reviewTreeMode.set($reviewTreeMode.get() === 'tree' ? 'list' : 'tree')
}
+// Diff scope for the review pane. 'uncommitted' (staged+unstaged+untracked) is
+// the review-before-commit default; 'branch' shows committed work vs the trunk
+// merge-base; 'lastTurn' shows everything (committed + uncommitted) since the
+// most recent turn began. Persisted like the tree-mode toggle.
+export const $reviewScope = persistentAtom<HermesReviewScope>(SCOPE_KEY, 'uncommitted', {
+ decode: raw => (raw === 'branch' || raw === 'lastTurn' ? raw : 'uncommitted'),
+ encode: value => value
+})
+
+// HEAD sha per repo cwd, captured when the most recent turn started in that
+// repo — the baseRef for the 'lastTurn' scope. Keyed by cwd so a pinned tile
+// worktree or a background session gets its own baseline instead of inheriting
+// the foreground cwd's. Empty until a turn has been observed for a given cwd.
+export const $reviewTurnBase = atom<Record<string, string>>({})
+
export const $reviewFiles = atom<HermesReviewFile[]>([])
export const $reviewLoading = atom(false)
// False when the active session isn't in a local git repo (detached/fresh chat,
@@ -122,6 +140,21 @@ function reviewCtx(): { cwd: string; review: ReviewBridge } | null {
return cwd && review ? { cwd, review } : null
}
+// The scope + base ref for the current read. 'lastTurn' diffing is baseRef-
+// driven (Electron recomputes the merge-base itself for 'branch'), so only the
+// last-turn baseline — looked up for the pane's own repo cwd — is passed.
+function reviewReadParams(): { scope: HermesReviewScope; baseRef: null | string } {
+ const scope = $reviewScope.get()
+
+ if (scope !== 'lastTurn') {
+ return { scope, baseRef: null }
+ }
+
+ const cwd = repoCwd()
+
+ return { scope, baseRef: cwd ? ($reviewTurnBase.get()[cwd] ?? null) : null }
+}
+
// ── Reads ────────────────────────────────────────────────────────────────────
export async function refreshReview(): Promise<void> {
@@ -148,7 +181,8 @@ export async function refreshReview(): Promise<void> {
$reviewLoading.set(true)
try {
- const result = await review.list(cwd, 'uncommitted', null)
+ const { scope, baseRef } = reviewReadParams()
+ const result = await review.list(cwd, scope, baseRef)
// Ignore a result that resolved after the cwd moved on.
if (seq !== reviewRefreshSeq || repoCwd() !== cwd) {
@@ -212,7 +246,8 @@ export async function selectReviewFile(file: HermesReviewFile): Promise<void> {
$reviewDiffLoading.set(true)
try {
- const diff = await ctx.review.diff(ctx.cwd, file.path, 'uncommitted', null, file.staged)
+ const { scope, baseRef } = reviewReadParams()
+ const diff = await ctx.review.diff(ctx.cwd, file.path, scope, baseRef, file.staged)
if ($reviewSelectedPath.get() === file.path) {
$reviewDiff.set(diff || '')
@@ -402,16 +437,28 @@ async function afterMutation(): Promise<void> {
}
export async function stageReviewFile(path: null | string): Promise<void> {
+ if ($reviewScope.get() !== 'uncommitted') {
+ return
+ }
+
await desktopGit()?.review?.stage(repoCwd() ?? '', path)
await afterMutation()
}
export async function unstageReviewFile(path: null | string): Promise<void> {
+ if ($reviewScope.get() !== 'uncommitted') {
+ return
+ }
+
await desktopGit()?.review?.unstage(repoCwd() ?? '', path)
await afterMutation()
}
export async function revertReviewFile(path: null | string): Promise<void> {
+ if ($reviewScope.get() !== 'uncommitted') {
+ return
+ }
+
await desktopGit()?.review?.revert(repoCwd() ?? '', path)
await afterMutation()
}
@@ -581,7 +628,8 @@ $workspaceChangeTick.subscribe(() => {
}
})
-// Turn settled: final list refresh + the slower gh/PR re-check.
+// Turn settled: final list refresh + the slower gh/PR re-check. `$busy` is the
+// ACTIVE session's flag, so this settle edge only fires for the foreground turn.
let prevBusy = $busy.get()
$busy.subscribe(busy => {
@@ -593,6 +641,39 @@ $busy.subscribe(busy => {
prevBusy = busy
})
+// Last-turn baseline capture: HEAD per repo cwd at the moment a turn started in
+// that repo. Driven off $sessionStates (every session — tiles and background
+// sessions included) rather than $busy, which only mirrors the foreground: a
+// pinned tile worktree or a background turn would otherwise inherit the wrong
+// (or no) baseline. Best-effort — a non-repo / remote backend resolves null and
+// lastTurn simply shows empty for that cwd.
+let prevBusyByRuntime: Record<string, boolean> = Object.fromEntries(
+ Object.entries($sessionStates.get()).map(([runtimeId, state]) => [runtimeId, state.busy])
+)
+
+$sessionStates.subscribe(states => {
+ const nextBusy: Record<string, boolean> = {}
+
+ for (const [runtimeId, state] of Object.entries(states)) {
+ nextBusy[runtimeId] = state.busy
+ const wasBusy = prevBusyByRuntime[runtimeId] ?? false
+
+ if (state.busy && !wasBusy) {
+ const cwd = state.cwd?.trim()
+
+ if (cwd) {
+ void desktopGit()?.review?.revParse(cwd, 'HEAD').then(sha => {
+ if (sha) {
+ $reviewTurnBase.set({ ...$reviewTurnBase.get(), [cwd]: sha })
+ }
+ })
+ }
+ }
+ }
+
+ prevBusyByRuntime = nextBusy
+})
+
// The pane's repo moved under it. For the classic (unscoped) pane that's the
// active session's cwd changing; for a scoped pane it's a re-home to another
// tile's worktree — and a main-pane cwd change is deliberately IGNORED while
diff --git a/website/docs/user-guide/desktop.md b/website/docs/user-guide/desktop.md
index 9db262b70cc..55bebc20115 100644
--- a/website/docs/user-guide/desktop.md
+++ b/website/docs/user-guide/desktop.md
@@ -168,7 +168,7 @@ While delegated workers are live, a **Subagents** frame appears above the compos
For sessions running inside a Git repository, the app has a built-in source-control surface:
-- **Review pane** — **Cmd/Ctrl+G** toggles the working-tree review pane: branch and ahead/behind status, changed files (list or tree view), and diffs scoped to **Uncommitted**, **Branch**, or **Last turn** (just what the agent changed in its most recent turn). Stage/unstage files, revert changes, write a commit message (or **Generate commit message**), then **Commit** or **Commit & Push** — and **Create PR** via the GitHub CLI (`gh`), or hand the whole thing to the agent with **Ask Hermes to open PR**. You can also create and switch branches from here.
+- **Review pane** — **Cmd/Ctrl+G** toggles the working-tree review pane: branch and ahead/behind status, changed files (list or tree view), and diffs scoped to **Uncommitted**, **Branch**, or **Last turn** (just what the agent changed in its most recent turn). Stage/unstage files, revert changes, write a commit message (or **Generate commit message**), then **Commit** or **Commit & Push** — and **Create PR** via the GitHub CLI (`gh`), or hand the whole thing to the agent with **Ask Hermes to open PR**. You can also create and switch branches from here. The **Last turn** scope shows everything changed since the most recent turn in this repo began (including any commits the agent made mid-turn); it is empty until a turn has run here. The **Branch** and **Last turn** scopes are read-only — stage, revert, and commit only apply to uncommitted changes.
- **Worktrees** — **Cmd/Ctrl+Shift+B** (or **New worktree** on a project in the sidebar) creates a Git worktree on a new branch so an agent can work on a parallel copy of the repo without touching your checkout. Worktrees show up as their own lanes under the project; removing one offers to delete the worktree directory (the branch stays) or just hide the lane and leave it on disk, with a force option when it has uncommitted changes. A chat also **follows the agent**: when you ask it to make a worktree and work in it, the chat moves to that lane at the end of the turn and the sidebar re-scopes with it. Only a workspace you deliberately switched the chat to (the folder picker, or a project switch) stays put.
### Memory Graph