The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): bound review turn baselines and label the read-only scopes
Chukwuebuka-2003b1b968ad098b
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.tsxindex 5f503dff2a4..d83955cdac6 100644--- a/apps/desktop/src/app/right-sidebar/review/ship-bar.test.tsx+++ b/apps/desktop/src/app/right-sidebar/review/ship-bar.test.tsx@@ -42,11 +42,23 @@ describe('ReviewShipBar', () => {expect(screen.getByText('Commit')).toBeTruthy()})- it('renders nothing for the branch scope (committed work has no working-tree actions)', () => {+ it('renders a read-only note for the branch scope (no working-tree actions)', () => {$reviewScope.set('branch')const { container } = renderBar()+ // The bar itself must be gone (no Commit button), replaced by the note+ // explaining why — not silently vanishing.+ expect(screen.queryByText('Commit')).toBeNull()+ expect(screen.getByText(/Read-only view/)).toBeTruthy()+ expect(container.firstChild).not.toBeNull()+ })++ it('renders nothing for the uncommitted scope when there are no files', () => {+ $reviewFiles.set([])++ 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.tsxindex 2007c3cbb93..1f8d56d731d 100644--- a/apps/desktop/src/app/right-sidebar/review/ship-bar.tsx+++ b/apps/desktop/src/app/right-sidebar/review/ship-bar.tsx@@ -52,7 +52,21 @@ export function ReviewShipBar() {// 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) {+ if (scope !== 'uncommitted') {+ // Don't just vanish: say why. A user who reopened the pane on a persisted+ // non-uncommitted scope would otherwise find no ship bar and no hint that+ // it's a deliberate read-only view, not a broken pane.+ return (+ <div+ className="shrink-0 px-2 pb-1.5 text-center text-[0.64rem] text-(--ui-text-tertiary)"+ data-suppress-pane-reveal-side=""+ >+ {c.readOnlyScope}+ </div>+ )+ }++ if (!hasFiles) {return null}diff --git a/apps/desktop/src/i18n/ar_chat.ts b/apps/desktop/src/i18n/ar_chat.tsindex 603302e5191..fa35b4fed05 100644--- a/apps/desktop/src/i18n/ar_chat.ts+++ b/apps/desktop/src/i18n/ar_chat.ts@@ -321,6 +321,7 @@ export const arChat = {scopeUncommitted: 'غير مُودَع',scopeBranch: 'فرع',scopeLastTurn: 'آخر دور',+ readOnlyScope: 'عرض للقراءة فقط — التخزين المؤقت والاستعادة والإيداع تنطبق على غير المُودَع',commit: 'إيداع',commitAndPush: 'إيداع ودفع',commitPlaceholder: shortcut => `رسالة (${shortcut} للإيداع)`,diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.tsindex 0c2432cf619..a5f1a26eaf5 100644--- a/apps/desktop/src/i18n/en.ts+++ b/apps/desktop/src/i18n/en.ts@@ -4173,6 +4173,7 @@ export const en: Translations = {scopeUncommitted: 'Uncommitted',scopeBranch: 'Branch',scopeLastTurn: 'Last turn',+ readOnlyScope: 'Read-only view — stage, revert, and commit apply to Uncommitted',commit: 'Commit',commitAndPush: 'Commit & Push',commitPlaceholder: shortcut => `Message (${shortcut} to commit)`,diff --git a/apps/desktop/src/i18n/ja.ts b/apps/desktop/src/i18n/ja.tsindex 4652e562cf6..ca9ed62284e 100644--- a/apps/desktop/src/i18n/ja.ts+++ b/apps/desktop/src/i18n/ja.ts@@ -3033,6 +3033,7 @@ export const ja = defineLocale({scopeUncommitted: '未コミット',scopeBranch: 'ブランチ',scopeLastTurn: '前のターン',+ readOnlyScope: '読み取り専用ビュー — ステージ・復元・コミットは「未コミット」のみ対象です',commit: 'コミット',commitAndPush: 'コミットしてプッシュ',commitPlaceholder: shortcut => `メッセージ(${shortcut} でコミット)`,diff --git a/apps/desktop/src/i18n/types.ts b/apps/desktop/src/i18n/types.tsindex 98c441858fe..e5d451f5c51 100644--- a/apps/desktop/src/i18n/types.ts+++ b/apps/desktop/src/i18n/types.ts@@ -3478,6 +3478,7 @@ export interface Translations {scopeUncommitted: stringscopeBranch: stringscopeLastTurn: string+ readOnlyScope: stringcommit: stringcommitAndPush: stringcommitPlaceholder: (shortcut: string) => stringdiff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.tsindex 5fa5aeadcd6..074b9542f10 100644--- a/apps/desktop/src/i18n/zh.ts+++ b/apps/desktop/src/i18n/zh.ts@@ -3937,6 +3937,7 @@ export const zh = defineLocale({scopeUncommitted: '未提交',scopeBranch: '分支',scopeLastTurn: '上一轮',+ readOnlyScope: '只读视图 — 暂存、还原和提交操作仅适用于“未提交”',commit: '提交',commitAndPush: '提交并推送',commitPlaceholder: shortcut => `信息(${shortcut} 提交)`,diff --git a/apps/desktop/src/store/review.test.ts b/apps/desktop/src/store/review.test.tsindex 9e56b07019c..335d3934fb8 100644--- a/apps/desktop/src/store/review.test.ts+++ b/apps/desktop/src/store/review.test.ts@@ -514,6 +514,32 @@ describe('$reviewTurnBase', () => {$reviewTurnBase.set({ '/repo': 'abc123' })expect($reviewTurnBase.get()).toEqual({ '/repo': 'abc123' })})++ it('caps tracked baselines at MAX_TURN_BASES, evicting the least-recently captured', async () => {+ stubReview({ revParse: vi.fn(async (cwd: string) => `sha-${cwd}`) })++ // Start with the map already full of older baselines.+ $reviewTurnBase.set(Object.fromEntries(Array.from({ length: 8 }, (_, i) => [`/old-${i}`, `sha-${i}`])))++ // A fresh turn in a ninth repo must evict the oldest (/old-0), not grow.+ $sessionStates.set({ rt_cap: sessionState(true, '/new-repo') })++ await new Promise(resolve => setTimeout(resolve, 0))++ const bases = $reviewTurnBase.get()+ expect(Object.keys(bases)).toHaveLength(8)+ expect(bases['/new-repo']).toBe('sha-/new-repo')+ expect(bases['/old-0']).toBeUndefined()+ expect(bases['/old-7']).toBeDefined()++ // Re-capturing an existing cwd refreshes it without growing the map.+ $sessionStates.set({ rt_recapture: sessionState(true, '/old-1') })++ await new Promise(resolve => setTimeout(resolve, 0))++ expect($reviewTurnBase.get()['/old-1']).toBe('sha-/old-1')+ expect(Object.keys($reviewTurnBase.get())).toHaveLength(8)+ })})// Minimal session state: the baseline capture only reads `busy` and `cwd`.diff --git a/apps/desktop/src/store/review.ts b/apps/desktop/src/store/review.tsindex 9cfd9853b6d..7908f93e350 100644--- a/apps/desktop/src/store/review.ts+++ b/apps/desktop/src/store/review.ts@@ -80,8 +80,44 @@ export const $reviewScope = persistentAtom<HermesReviewScope>(SCOPE_KEY, 'uncomm// 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.+//+// Normalization contract: keys are written from `state.cwd.trim()` at capture+// and read through `repoCwd()` (which trims too). Both sides ultimately carry+// the same gateway-reported absolute path for a given repo, so they match+// byte-for-byte; any other divergence (trailing slash, symlink, case) would+// silently miss and degrade lastTurn to empty rather than mislead.+//+// Capture is best-effort and inherently racy: HEAD is resolved asynchronously+// after `busy` flips, so a turn that commits immediately can beat the reply+// and bake its own commits into the baseline (lastTurn then shows slightly+// less than the turn changed). Accepted — the alternative is blocking turn+// start on a git probe.export const $reviewTurnBase = atom<Record<string, string>>({})+// Cap on tracked baselines. Bounded by repos-worked-in in practice, but a+// long-lived session shouldn't hoard stale entries for abandoned worktrees:+// beyond the cap, the least-recently-captured cwd is evicted.+const MAX_TURN_BASES = 8++function recordTurnBase(cwd: string, sha: string): void {+ const prev = $reviewTurnBase.get()++ if (prev[cwd] === sha) {+ return+ }++ // Re-insert the cwd so object key order tracks recency (oldest first),+ // then evict from the front beyond the cap.+ const rest = Object.entries(prev).filter(([key]) => key !== cwd)++ while (rest.length >= MAX_TURN_BASES) {+ rest.shift()+ }++ rest.push([cwd, sha])+ $reviewTurnBase.set(Object.fromEntries(rest))+}+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,@@ -662,11 +698,13 @@ $sessionStates.subscribe(states => {const cwd = state.cwd?.trim()if (cwd) {- void desktopGit()?.review?.revParse(cwd, 'HEAD').then(sha => {- if (sha) {- $reviewTurnBase.set({ ...$reviewTurnBase.get(), [cwd]: sha })- }- })+ void desktopGit()+ ?.review?.revParse(cwd, 'HEAD')+ .then(sha => {+ if (sha) {+ recordTurnBase(cwd, sha)+ }+ })}}}