The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): preserve file git change tints across multi-cwd sessions and sidebar refreshes
Mohammad4c9cd25d96f8
diff --git a/apps/desktop/src/app/right-sidebar/index.test.tsx b/apps/desktop/src/app/right-sidebar/index.test.tsxindex fd0484694ce..6c81291e6cb 100644--- a/apps/desktop/src/app/right-sidebar/index.test.tsx+++ b/apps/desktop/src/app/right-sidebar/index.test.tsx@@ -11,9 +11,13 @@ import { resetProjectTreeState } from './files/use-project-tree'import { RightSidebarPane } from './index'const readDir = vi.fn<(path: string) => Promise<HermesReadDirResult>>()+const repoStatus = vi.fn<(cwd: string) => Promise<null>>()function installBridge() {- ;(window as unknown as { hermesDesktop: { readDir: typeof readDir } }).hermesDesktop = { readDir }+ ;(window as unknown as { hermesDesktop: { git: { repoStatus: typeof repoStatus }; readDir: typeof readDir } }).hermesDesktop = {+ git: { repoStatus },+ readDir+ }}describe('RightSidebarPane', () => {@@ -24,6 +28,8 @@ describe('RightSidebarPane', () => {resetProjectTreeState()readDir.mockReset()readDir.mockResolvedValue({ entries: [{ isDirectory: false, name: 'README.md', path: '/repo/README.md' }] })+ repoStatus.mockReset()+ repoStatus.mockResolvedValue(null)installBridge()})@@ -95,8 +101,12 @@ describe('RightSidebarPane', () => {const refresh = await screen.findByRole('button', { name: 'Refresh tree' })readDir.mockClear()+ repoStatus.mockClear()fireEvent.click(refresh)- await waitFor(() => expect(readDir).toHaveBeenCalledWith('/repo-tile'))+ await waitFor(() => {+ expect(readDir).toHaveBeenCalledWith('/repo-tile')+ expect(repoStatus).toHaveBeenCalledWith('/repo-tile')+ })})it('keeps the focused tile workspace cwd even when clicking into the sidebar group', async () => {@@ -123,7 +133,11 @@ describe('RightSidebarPane', () => {const refresh = await screen.findByRole('button', { name: 'Refresh tree' })readDir.mockClear()+ repoStatus.mockClear()fireEvent.click(refresh)- await waitFor(() => expect(readDir).toHaveBeenCalledWith('/repo-tile'))+ await waitFor(() => {+ expect(readDir).toHaveBeenCalledWith('/repo-tile')+ expect(repoStatus).toHaveBeenCalledWith('/repo-tile')+ })})})diff --git a/apps/desktop/src/app/right-sidebar/index.tsx b/apps/desktop/src/app/right-sidebar/index.tsxindex 4822ed25dc0..85f0a6c4556 100644--- a/apps/desktop/src/app/right-sidebar/index.tsx+++ b/apps/desktop/src/app/right-sidebar/index.tsx@@ -1,5 +1,5 @@import { useStore } from '@nanostores/react'-import type { ComponentProps } from 'react'+import { type ComponentProps, useCallback, useEffect } from 'react'import { TreeSkeleton } from '@/components/chat/skeletons'import { ErrorBoundary } from '@/components/error-boundary'@@ -10,6 +10,7 @@ import { useDelayedTrue } from '@/hooks/use-delayed-true'import { useI18n } from '@/i18n'import { normalizeOrLocalPreviewTarget } from '@/lib/local-preview'import { cn } from '@/lib/utils'+import { refreshRepoStatus, registerRepoStatusCwd } from '@/store/coding-status'import { $panesFlipped } from '@/store/layout'import { notifyError } from '@/store/notifications'import { openPreview } from '@/store/preview'@@ -48,6 +49,25 @@ export function RightSidebarPane({ onActivateFile, onActivateFolder }: RightSideshowIgnored} = useProjectTree(hasWorkspace ? targetCwd : '')+ useEffect(() => {+ const activeCwd = effectiveCwd || (hasWorkspace ? targetCwd : '')++ if (!activeCwd) {+ return+ }++ return registerRepoStatusCwd(activeCwd)+ }, [effectiveCwd, hasWorkspace, targetCwd])++ const handleRefresh = useCallback(() => {+ void refreshRoot()+ const activeCwd = effectiveCwd || (hasWorkspace ? targetCwd : '')++ if (activeCwd) {+ void refreshRepoStatus(activeCwd)+ }+ }, [effectiveCwd, hasWorkspace, refreshRoot, targetCwd])+const cwdName =effectiveCwd.split(/[\\/]+/)@@ -95,7 +115,7 @@ export function RightSidebarPane({ onActivateFile, onActivateFolder }: RightSideonLoadChildren={loadChildren}onNodeOpenChange={setNodeOpen}onPreviewFile={previewFile}- onRefresh={() => void refreshRoot()}+ onRefresh={handleRefresh}onToggleShowIgnored={() => setShowIgnored(!showIgnored)}openState={openState}showIgnored={showIgnored}diff --git a/apps/desktop/src/store/coding-status.test.ts b/apps/desktop/src/store/coding-status.test.tsindex d5a67e58982..2c9382fab5a 100644--- a/apps/desktop/src/store/coding-status.test.ts+++ b/apps/desktop/src/store/coding-status.test.ts@@ -284,4 +284,35 @@ describe('repoChangeKindForPath', () => {unsubscribe()})++ it('maps changes across multiple probed CWDs independently of active session ownership', () => {+ $repoStatusByCwd.set({+ '/repo-a': {+ ...sampleStatus,+ files: [{ path: 'src/file1.ts', untracked: false, conflicted: false } as HermesRepoStatus['files'][number]]+ },+ '/repo-b': {+ ...otherStatus,+ files: [{ path: 'src/file2.ts', untracked: true, conflicted: false } as HermesRepoStatus['files'][number]]+ }+ })++ expect(repoChangeKindForPath('/repo-a/src/file1.ts').get()).toBe('modified')+ expect(repoChangeKindForPath('/repo-b/src/file2.ts').get()).toBe('added')+ expect(repoChangeKindForPath('/repo-a/src/clean.ts').get()).toBeUndefined()+ })++ it('inherits added kind for nested files inside untracked directories', () => {+ $repoStatusByCwd.set({+ '/repo': {+ ...sampleStatus,+ files: [{ path: 'brand_new_dir', untracked: true, conflicted: false } as HermesRepoStatus['files'][number]]+ }+ })++ expect(repoChangeKindForPath('/repo/brand_new_dir').get()).toBe('added')+ expect(repoChangeKindForPath('/repo/brand_new_dir/nested.ts').get()).toBe('added')+ expect(repoChangeKindForPath('/repo/brand_new_dir/deep/nested/sub.ts').get()).toBe('added')+ expect(repoChangeKindForPath('/repo/other_dir/file.ts').get()).toBeUndefined()+ })})diff --git a/apps/desktop/src/store/coding-status.ts b/apps/desktop/src/store/coding-status.tsindex c5819943c37..fec3b344880 100644--- a/apps/desktop/src/store/coding-status.ts+++ b/apps/desktop/src/store/coding-status.ts@@ -133,20 +133,24 @@ export function repoWorktreesForCwd(cwd?: null | string): ReadableAtom<HermesGitexport type RepoChangeKind = 'added' | 'conflicted' | 'modified'// Absolute file path → its git change kind, for VS Code-style file-tree tinting.-// Reuses the same bounded $repoStatus probe (capped file list); git reports-// repo-root-relative paths, so we join them onto the active cwd. Deletions never-// appear — the file is gone from disk, so there's no tree row to tint.-export const $repoChangeByPath = computed([$repoStatus, $currentCwd], (status, cwd) => {+// Reuses the bounded per-CWD repo-status probes (capped file list); git reports+// repo-root-relative paths, so we join them onto their corresponding probed cwd.+// Deletions never appear — the file is gone from disk, so there's no tree row to tint.+export const $repoChangeByPath = computed([$repoStatusByCwd], byCwd => {const map = new Map<string, RepoChangeKind>()- const root = (cwd || '').replace(/[/\\]+$/, '')- if (!status || !root) {- return map- }+ for (const [cwd, status] of Object.entries(byCwd)) {+ const root = (cwd || '').trim().replace(/[/\\]+$/, '')++ if (!status || !root) {+ continue+ }- for (const file of status.files) {- const kind: RepoChangeKind = file.conflicted ? 'conflicted' : file.untracked ? 'added' : 'modified'- map.set(`${root}/${file.path}`, kind)+ for (const file of status.files) {+ const cleanPath = (file.path || '').replace(/^[/\\]+/, '')+ const kind: RepoChangeKind = file.conflicted ? 'conflicted' : file.untracked ? 'added' : 'modified'+ map.set(`${root}/${cleanPath}`, kind)+ }}return map@@ -155,9 +159,36 @@ export const $repoChangeByPath = computed([$repoStatus, $currentCwd], (status, c/*** Per-row Git decoration subscription. A visible file row reads one scalar, so* a fresh repo-status map only re-renders that row when its own kind changed.+ * Supports directory inheritance for untracked folders under `--untracked-files=normal`.*/export function repoChangeKindForPath(path: string): ReadableAtom<RepoChangeKind | undefined> {- return computed($repoChangeByPath, changes => changes.get(path))+ return computed($repoChangeByPath, changes => {+ const direct = changes.get(path)++ if (direct) {+ return direct+ }++ // Check if an ancestor directory is marked 'added' (untracked directory).+ let parent = path.replace(/[/\\]+$/, '')++ while (true) {+ const lastSlash = Math.max(parent.lastIndexOf('/'), parent.lastIndexOf('\\'))++ if (lastSlash <= 0) {+ break+ }++ parent = parent.slice(0, lastSlash)+ const parentKind = changes.get(parent)++ if (parentKind === 'added') {+ return 'added'+ }+ }++ return undefined+ })}// Cwds whose rails are on screen right now (refcounted — two tiles in one