Skip to content

The agent that grows with you

fix(desktop): offer "Show all N sessions" under project rows capped at 3 previews

teknium1534c93f9e7f0
diff --git a/apps/desktop/src/app/chat/sidebar/projects/model.ts b/apps/desktop/src/app/chat/sidebar/projects/model.ts
index 0836a089b31..2d4561ad590 100644
--- a/apps/desktop/src/app/chat/sidebar/projects/model.ts
+++ b/apps/desktop/src/app/chat/sidebar/projects/model.ts
@@ -45,6 +45,16 @@ const projectActivityTime = (project: SidebarProjectTree): number =>
export const latestProjectSessions = (project: SidebarProjectTree, limit: number): SessionInfo[] =>
[...projectSessions(project)].sort((a, b) => sessionRecency(b) - sessionRecency(a)).slice(0, limit)
+// The overview payload carries only the most-recent preview rows per project.
+// Once the user asks for the rest, the project's full lanes are fetched on
+// demand; fold them under the (live-overlaid) preview so a just-created
+// session keeps its place and nothing renders twice.
+export const expandedProjectSessions = (preview: SessionInfo[], hydrated: SidebarProjectTree): SessionInfo[] => {
+ const seen = new Set(preview.map(session => session.id))
+
+ return [...preview, ...latestProjectSessions(hydrated, Infinity).filter(session => !seen.has(session.id))]
+}
+
// Home is a fixture, not a project: it always leads the overview, above the
// active project and outside any hand-picked order.
const homeFirst = (projects: SidebarProjectTree[]): SidebarProjectTree[] =>
diff --git a/apps/desktop/src/app/chat/sidebar/projects/overview-row.test.tsx b/apps/desktop/src/app/chat/sidebar/projects/overview-row.test.tsx
index baf7ef1fabe..f8d38ef6b1f 100644
--- a/apps/desktop/src/app/chat/sidebar/projects/overview-row.test.tsx
+++ b/apps/desktop/src/app/chat/sidebar/projects/overview-row.test.tsx
@@ -1,14 +1,23 @@
-import { cleanup, fireEvent, render, screen } from '@testing-library/react'
+import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
import type { ReactNode } from 'react'
import { afterEach, describe, expect, it, vi } from 'vitest'
import type { SessionInfo } from '@/hermes'
+import type * as ProjectsStore from '@/store/projects'
+import type * as Model from './model'
import { ProjectOverviewRow } from './overview-row'
import type { SidebarProjectTree } from './workspace-groups'
afterEach(cleanup)
+const workspaceOpen = vi.hoisted(() => ({ value: false }))
+
+const projectsStore = vi.hoisted(() => ({
+ fetchProjectSessions: vi.fn<(id: string) => Promise<null | SidebarProjectTree>>(),
+ projectProfile: vi.fn<() => null | string>(() => 'default')
+}))
+
vi.mock('@/i18n', () => ({
useI18n: () => ({
t: {
@@ -18,6 +27,7 @@ vi.mock('@/i18n', () => ({
enter: (label: string) => `Enter ${label}`,
reorder: (label: string) => `Reorder ${label}`,
toggle: (label: string, open: boolean) => `${open ? 'Show' : 'Hide'} ${label} sessions`,
+ showAllCount: (count: number) => `Show all ${count} sessions`,
autoDiscovered: 'Auto-discovered'
}
}
@@ -25,10 +35,17 @@ vi.mock('@/i18n', () => ({
})
}))
-vi.mock('./model', () => ({
- PROJECT_PREVIEW_COUNT: 3,
+vi.mock('@/store/projects', async importOriginal => ({
+ ...(await importOriginal<typeof ProjectsStore>()),
+ ...projectsStore
+}))
+
+// Keep the pure helpers real (they are the logic under test); stub only the
+// persisted open/collapse hook and the in-memory fallback preview.
+vi.mock('./model', async () => ({
+ ...(await vi.importActual<typeof Model>('./model')),
latestProjectSessions: () => [],
- useWorkspaceNodeOpen: () => [false, vi.fn()]
+ useWorkspaceNodeOpen: () => [workspaceOpen.value, vi.fn()]
}))
// ProjectMenu (the kebab) has its own dedicated test file — stub it here so
@@ -44,7 +61,15 @@ const project = { id: 'p1', label: 'Test D' } as unknown as SidebarProjectTree
const tipTrigger = (el: HTMLElement) => el.closest('[data-slot="tooltip-trigger"]')
+const session = (id: string, updated: number): SessionInfo => ({ id, updated_at: updated }) as unknown as SessionInfo
+
describe('ProjectOverviewRow', () => {
+ afterEach(() => {
+ workspaceOpen.value = false
+ projectsStore.fetchProjectSessions.mockReset()
+ projectsStore.projectProfile.mockReset().mockReturnValue('default')
+ })
+
it('wraps the "new session" add button in a Tip with the project-scoped label', () => {
render(<ProjectOverviewRow onNewSession={vi.fn()} project={project} />)
@@ -72,6 +97,34 @@ describe('ProjectOverviewRow', () => {
expect(screen.queryByRole('button', { name: 'Show Test D sessions' })).toBeNull()
})
+ // Group by → Projects previews only the 3 most-recent sessions per project;
+ // sessions 4+ need a visible, in-place way to be reached (#112406).
+ it('offers "Show all N sessions" past the preview cap and reveals the rest of the project inline', async () => {
+ workspaceOpen.value = true
+ const five = Array.from({ length: 5 }, (_, index) => session(`s${index + 1}`, 500 - index))
+ const busy = { ...project, sessionCount: 5 } as SidebarProjectTree
+ projectsStore.fetchProjectSessions.mockResolvedValue({
+ ...busy,
+ repos: [{ groups: [{ sessions: five }] }]
+ } as unknown as SidebarProjectTree)
+
+ render(
+ <ProjectOverviewRow
+ previewSessions={five.slice(0, 3)}
+ project={busy}
+ renderRows={items => <div data-testid="rows">{items.map(item => item.id).join(',')}</div>}
+ />
+ )
+
+ expect(screen.getByTestId('rows').textContent).toBe('s1,s2,s3')
+
+ fireEvent.click(screen.getByRole('button', { name: 'Show all 5 sessions' }))
+
+ await waitFor(() => expect(screen.getByTestId('rows').textContent).toBe('s1,s2,s3,s4,s5'))
+ expect(projectsStore.fetchProjectSessions).toHaveBeenCalledWith('p1')
+ expect(screen.queryByRole('button', { name: 'Show all 5 sessions' })).toBeNull()
+ })
+
it('offers the "new session" add button on Home, which starts one with no folder', () => {
const home = {
id: '__no_project__',
diff --git a/apps/desktop/src/app/chat/sidebar/projects/overview-row.tsx b/apps/desktop/src/app/chat/sidebar/projects/overview-row.tsx
index bb0612fe4f0..2a4c1a8c1ca 100644
--- a/apps/desktop/src/app/chat/sidebar/projects/overview-row.tsx
+++ b/apps/desktop/src/app/chat/sidebar/projects/overview-row.tsx
@@ -1,6 +1,6 @@
import { useStore } from '@nanostores/react'
import type * as React from 'react'
-import { useRef } from 'react'
+import { useRef, useState } from 'react'
import { type NewSessionSplitHandler, startNewSessionDrag } from '@/app/chat/new-session-drag'
import { Codicon } from '@/components/ui/codicon'
@@ -9,6 +9,7 @@ import type { SessionInfo } from '@/hermes'
import { useI18n } from '@/i18n'
import { cn } from '@/lib/utils'
import { $sidebarShowAllSessions } from '@/store/layout'
+import { fetchProjectSessions, projectProfile } from '@/store/projects'
import {
SIDEBAR_LEAD_ICON_SIZE,
@@ -23,7 +24,7 @@ import {
SidebarRowShell
} from '../chrome'
-import { latestProjectSessions, PROJECT_PREVIEW_COUNT, useWorkspaceNodeOpen } from './model'
+import { expandedProjectSessions, latestProjectSessions, PROJECT_PREVIEW_COUNT, useWorkspaceNodeOpen } from './model'
import { ProjectContextMenu, ProjectMenu } from './project-menu'
import type { SidebarProjectTree } from './workspace-groups'
import { WorkspaceAddButton } from './workspace-header'
@@ -109,9 +110,33 @@ export function ProjectOverviewRow({
// the sidebar's content edge regardless of which side the sidebar is on.
const rowRef = useRef<HTMLDivElement>(null)
const showAllSessions = useStore($sidebarShowAllSessions)
- const limit = showAllSessions ? Infinity : PROJECT_PREVIEW_COUNT
+ // The tree payload previews only the most-recent few sessions per project
+ // (kept light on purpose); "Show all" hydrates THIS project's lanes on demand
+ // rather than widening every project's preview window.
+ const [expanded, setExpanded] = useState<SidebarProjectTree | null>(null)
+ const [expanding, setExpanding] = useState(false)
+ const limit = showAllSessions || expanded ? Infinity : PROJECT_PREVIEW_COUNT
const fetched = (previewSessions ?? []).slice(0, limit)
- const preview = renderRows ? (fetched.length ? fetched : latestProjectSessions(project, limit)) : []
+ const recent = fetched.length ? fetched : latestProjectSessions(project, limit)
+ const preview = renderRows ? (expanded ? expandedProjectSessions(recent, expanded) : recent) : []
+ const hiddenCount = project.sessionCount - preview.length
+ const offerShowAll = !showAllSessions && !expanded && preview.length > 0 && hiddenCount > 0
+
+ const showAll = () => {
+ // All-profiles view has no single backend to ask for one project's lanes;
+ // drilling in is the reach there.
+ if (!projectProfile()) {
+ onEnter?.(project.id)
+
+ return
+ }
+
+ setExpanding(true)
+ fetchProjectSessions(project.id)
+ .then(tree => void (tree && setExpanded(tree)))
+ .catch(() => onEnter?.(project.id))
+ .finally(() => setExpanding(false))
+ }
const lead = reorderable ? (
<SidebarRowGrab
@@ -220,7 +245,29 @@ export function ProjectOverviewRow({
{shell}
</ProjectContextMenu>
)}
- {open && preview.length > 0 && <SidebarRowNest>{renderRows?.(preview)}</SidebarRowNest>}
+ {open && preview.length > 0 && (
+ <SidebarRowNest>
+ {renderRows?.(preview)}
+ {offerShowAll && (
+ <SidebarRowShell>
+ <SidebarRowBody
+ className="group/more w-full text-(--ui-text-tertiary) hover:text-foreground"
+ disabled={expanding}
+ onClick={showAll}
+ >
+ <SidebarRowLead>
+ <SidebarRowLeadGlyph>
+ <Codicon name="ellipsis" size={SIDEBAR_LEAD_ICON_SIZE} />
+ </SidebarRowLeadGlyph>
+ </SidebarRowLead>
+ <SidebarRowLabel className="text-xs underline-offset-4 group-hover/more:underline">
+ {s.projects.showAllCount(project.sessionCount)}
+ </SidebarRowLabel>
+ </SidebarRowBody>
+ </SidebarRowShell>
+ )}
+ </SidebarRowNest>
+ )}
</div>
)
}
diff --git a/apps/desktop/src/i18n/ar.ts b/apps/desktop/src/i18n/ar.ts
index a66272dce12..36ca2afbaf0 100644
--- a/apps/desktop/src/i18n/ar.ts
+++ b/apps/desktop/src/i18n/ar.ts
@@ -2042,6 +2042,7 @@ export const ar = defineLocale({
enter: label => `فتح ${label}`,
reorder: label => `إعادة ترتيب ${label}`,
toggle: (label, open) => `${open ? 'إظهار' : 'إخفاء'} جلسات ${label}`,
+ showAllCount: count => `إظهار كل الجلسات (${count})`,
back: 'كل المشاريع'
},
newSessionIn: label => `جلسة جديدة في ${label}`,
diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.ts
index 1431a1bc505..ec101c86bfa 100644
--- a/apps/desktop/src/i18n/en.ts
+++ b/apps/desktop/src/i18n/en.ts
@@ -2860,6 +2860,7 @@ export const en: Translations = {
enter: label => `Open ${label}`,
reorder: label => `Reorder ${label}`,
toggle: (label, open) => `${open ? 'Show' : 'Hide'} ${label} sessions`,
+ showAllCount: count => `Show all ${count} sessions`,
back: 'All projects'
},
newSessionIn: label => `New session in ${label}`,
diff --git a/apps/desktop/src/i18n/ja.ts b/apps/desktop/src/i18n/ja.ts
index 797fe7ff9e9..91efc4db084 100644
--- a/apps/desktop/src/i18n/ja.ts
+++ b/apps/desktop/src/i18n/ja.ts
@@ -2298,6 +2298,7 @@ export const ja = defineLocale({
sectionLabel: 'プロジェクト',
home: 'ホーム',
autoDiscovered: '自動検出',
+ showAllCount: count => `${count} 件のセッションをすべて表示`,
newButton: '新規プロジェクト',
createTitle: '新規プロジェクト',
createDesc: 'ワークスペースに名前を付け、1つ以上のフォルダを追加します。',
diff --git a/apps/desktop/src/i18n/ru.ts b/apps/desktop/src/i18n/ru.ts
index 5fcff28fd9c..1b6f9f3d593 100644
--- a/apps/desktop/src/i18n/ru.ts
+++ b/apps/desktop/src/i18n/ru.ts
@@ -2630,6 +2630,7 @@ export const ru = defineLocale({
enter: label => `Открыть ${label}`,
reorder: label => `Изменить порядок ${label}`,
toggle: (label, open) => `${open ? 'Показать' : 'Скрыть'} сеансы ${label}`,
+ showAllCount: count => `Показать все сессии (${count})`,
back: 'Все проекты'
},
newSessionIn: label => `Новый сеанс в ${label}`,
diff --git a/apps/desktop/src/i18n/types.ts b/apps/desktop/src/i18n/types.ts
index 963eb547594..33f70765042 100644
--- a/apps/desktop/src/i18n/types.ts
+++ b/apps/desktop/src/i18n/types.ts
@@ -2477,6 +2477,7 @@ export interface Translations {
enter: (label: string) => string
reorder: (label: string) => string
toggle: (label: string, open: boolean) => string
+ showAllCount: (count: number) => string
back: string
}
newSessionIn: (label: string) => string
diff --git a/apps/desktop/src/i18n/zh-hant.ts b/apps/desktop/src/i18n/zh-hant.ts
index f485672b680..4ba4a0551cf 100644
--- a/apps/desktop/src/i18n/zh-hant.ts
+++ b/apps/desktop/src/i18n/zh-hant.ts
@@ -2288,6 +2288,7 @@ export const zhHant = defineLocale({
sectionLabel: '專案',
home: '主頁',
autoDiscovered: '自動探索',
+ showAllCount: count => `顯示全部 ${count} 個工作階段`,
newButton: '新增專案',
createTitle: '新增專案',
createDesc: '為工作區命名並新增一個或多個資料夾。',
diff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.ts
index aa9eb6da0a0..f760066a643 100644
--- a/apps/desktop/src/i18n/zh.ts
+++ b/apps/desktop/src/i18n/zh.ts
@@ -3001,6 +3001,7 @@ export const zh = defineLocale({
enter: label => `打开 ${label}`,
reorder: label => `重新排序 ${label}`,
toggle: (label, open) => `${open ? '展开' : '收起'} ${label} 会话`,
+ showAllCount: count => `显示全部 ${count} 个会话`,
back: '全部项目'
},
newSessionIn: label => `在 ${label} 中新建会话`,