Skip to content

The agent that grows with you

fix(desktop): every project session is reachable from the sidebar

brooklyn!0397efef87ce
diff --git a/apps/desktop/src/app/chat/sidebar/projects/entered-content.tsx b/apps/desktop/src/app/chat/sidebar/projects/entered-content.tsx
index ad970ec0ddd..0aea206e356 100644
--- a/apps/desktop/src/app/chat/sidebar/projects/entered-content.tsx
+++ b/apps/desktop/src/app/chat/sidebar/projects/entered-content.tsx
@@ -15,7 +15,7 @@ import { removeWorktreePath } from '@/store/projects'
import { SidebarRowStack } from '../chrome'
-import { useWorkspaceNodeOpen } from './model'
+import { PROJECT_SESSION_PAGE, useRevealedRows, useWorkspaceNodeOpen } from './model'
import { SidebarWorkspaceGroup } from './workspace-group'
import {
mergeRepoWorktreeGroups,
@@ -24,7 +24,7 @@ import {
type SidebarSessionGroup,
type SidebarWorkspaceTree
} from './workspace-groups'
-import { WorkspaceAddButton, WorkspaceHeader } from './workspace-header'
+import { WorkspaceAddButton, WorkspaceHeader, WorkspaceShowMoreRow } from './workspace-header'
// The entered project's body. Main-checkout sessions render directly — no
// redundant repo/branch header (the breadcrumb already names the project). Only
@@ -52,9 +52,9 @@ export function EnteredProjectContent({
}
// Home's rows aren't anchored to a folder, so there's no repo or worktree
- // structure to show — just the chats.
+ // structure to show — just the chats, paged so a huge Home stays cheap.
if (project.isNoProject) {
- return <>{renderRows(project.repos.flatMap(repo => repo.groups.flatMap(group => group.sessions)))}</>
+ return <HomeSessions project={project} renderRows={renderRows} />
}
const single = project.repos.length === 1
@@ -78,6 +78,27 @@ export function EnteredProjectContent({
)
}
+function HomeSessions({
+ project,
+ renderRows
+}: {
+ project: SidebarProjectTree
+ renderRows: (sessions: SessionInfo[]) => React.ReactNode
+}) {
+ const { t } = useI18n()
+ const sessions = useMemo(() => project.repos.flatMap(repo => repo.groups.flatMap(group => group.sessions)), [project])
+ const home = useRevealedRows(sessions, PROJECT_SESSION_PAGE)
+
+ return (
+ <>
+ {renderRows(home.shown)}
+ {home.more > 0 && (
+ <WorkspaceShowMoreRow label={t.sidebar.showMoreIn(home.more, project.label)} onClick={home.showMore} />
+ )}
+ </>
+ )
+}
+
function RepoFlatSection({
repo,
showHeader,
diff --git a/apps/desktop/src/app/chat/sidebar/projects/model.ts b/apps/desktop/src/app/chat/sidebar/projects/model.ts
index 2d4561ad590..5c68ec0afb9 100644
--- a/apps/desktop/src/app/chat/sidebar/projects/model.ts
+++ b/apps/desktop/src/app/chat/sidebar/projects/model.ts
@@ -16,6 +16,25 @@ export const SIDEBAR_GROUP_PAGE = 5
// Recent sessions previewed under each project in the overview.
export const PROJECT_PREVIEW_COUNT = 3
+// Rows each "Show more" adds once a project's full list is open (an expanded
+// overview row, an entered lane, entered Home). Large enough that 50+ sessions
+// are a click or two away, small enough that a 5000-chat Home never mounts
+// every row at once.
+export const PROJECT_SESSION_PAGE = 50
+
+// Reveal `rows` a page at a time: the first `first`, then PROJECT_SESSION_PAGE
+// per `showMore()`. `more` is the next step's size (0 once everything shows).
+export function useRevealedRows<T>(rows: T[], first: number): { more: number; shown: T[]; showMore: () => void } {
+ const [count, setCount] = useState(first)
+ const shown = rows.length > count ? rows.slice(0, count) : rows
+
+ return {
+ more: Math.min(PROJECT_SESSION_PAGE, rows.length - shown.length),
+ shown,
+ showMore: () => setCount(current => current + PROJECT_SESSION_PAGE)
+ }
+}
+
// Max concurrent `git worktree list` probes when a project spans many repos.
const WORKTREE_PROBE_CONCURRENCY = 4
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 ff60c943643..a9fd771b8e9 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
@@ -30,7 +30,8 @@ vi.mock('@/i18n', () => ({
toggle: (label: string, open: boolean) => `${open ? 'Show' : 'Hide'} ${label} sessions`,
showAllCount: (count: number) => `Show all ${count} sessions`,
autoDiscovered: 'Auto-discovered'
- }
+ },
+ showMoreIn: (count: number, label: string) => `Show ${count} more in ${label}`
}
}
})
@@ -103,6 +104,38 @@ describe('ProjectOverviewRow', () => {
expect(screen.queryByRole('button', { name: 'Show all 5 sessions' })).toBeNull()
})
+ // A project with hundreds of chats hydrates them all, but the overview must
+ // not mount every row at once: it reveals them a page at a time, with a
+ // labeled row to the next page, until every session is on screen (#70421).
+ it('pages a large hydrated project instead of mounting every session at once', async () => {
+ workspaceOpen.value = true
+ const all = Array.from({ length: 120 }, (_, index) => session(`s${index + 1}`, 1000 - index))
+ const busy = { ...project, sessionCount: 120 } as SidebarProjectTree
+ projectsStore.fetchProjectSessions.mockResolvedValue({
+ ...busy,
+ repos: [{ groups: [{ sessions: all }] }]
+ } as unknown as SidebarProjectTree)
+
+ render(
+ <ProjectOverviewRow
+ previewSessions={all.slice(0, 3)}
+ project={busy}
+ renderRows={items => <div data-testid="rows">{items.map(item => item.id).join(',')}</div>}
+ />
+ )
+
+ const shown = () => screen.getByTestId('rows').textContent?.split(',').length
+
+ fireEvent.click(screen.getByText('Show all 120 sessions'))
+
+ await waitFor(() => expect(shown()).toBe(50))
+ fireEvent.click(screen.getByText('Show 50 more in Test D'))
+ expect(shown()).toBe(100)
+ fireEvent.click(screen.getByText('Show 20 more in Test D'))
+ expect(shown()).toBe(120)
+ expect(screen.queryByText(/Show .* more in Test D/)).toBeNull()
+ })
+
// The hydrated lanes are the raw backend payload: pinned, filtered-out and
// just-deleted sessions must go through the same exclusion the previews did,
// and N must not promise rows the view hides.
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 e005d00b006..25f9ee205b5 100644
--- a/apps/desktop/src/app/chat/sidebar/projects/overview-row.tsx
+++ b/apps/desktop/src/app/chat/sidebar/projects/overview-row.tsx
@@ -25,10 +25,17 @@ import {
} from '../chrome'
import { shellOwnsPress } from '../reorderable-list'
-import { expandedProjectSessions, latestProjectSessions, PROJECT_PREVIEW_COUNT, useWorkspaceNodeOpen } from './model'
+import {
+ expandedProjectSessions,
+ latestProjectSessions,
+ PROJECT_PREVIEW_COUNT,
+ PROJECT_SESSION_PAGE,
+ useRevealedRows,
+ useWorkspaceNodeOpen
+} from './model'
import { ProjectContextMenu, ProjectMenu } from './project-menu'
import { excludeProjectSessions, type SidebarProjectTree } from './workspace-groups'
-import { WorkspaceAddButton } from './workspace-header'
+import { WorkspaceAddButton, WorkspaceShowMoreRow } from './workspace-header'
// A bare color dot (no icon) or an icon glyph — tinted by `color` when set, else
// the lead's default tertiary. The glyph wrapper centers + caps size either way.
@@ -132,6 +139,10 @@ export function ProjectOverviewRow({
// (index.tsx) — they haven't been through the tree's exclusion filter yet.
const visible = expanded && isSessionHidden ? excludeProjectSessions(expanded, isSessionHidden) : expanded
const preview = renderRows ? (visible ? expandedProjectSessions(recent, visible) : recent) : []
+ // Once hydrated, the whole project is reachable but mounts a page at a time
+ // (a project can hold thousands of chats; the collapsed preview stays 3).
+ const page = useRevealedRows(preview, PROJECT_SESSION_PAGE)
+ const rows = expanded ? page.shown : preview
const total = project.sessionCount - hiddenSessionCount
const hiddenCount = total - preview.length
const offerShowAll = !showAllSessions && !expanded && preview.length > 0 && hiddenCount > 0
@@ -268,24 +279,12 @@ export function ProjectOverviewRow({
)}
{open && preview.length > 0 && (
<SidebarRowNest>
- {renderRows?.(preview)}
+ {renderRows?.(rows)}
{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(total)}
- </SidebarRowLabel>
- </SidebarRowBody>
- </SidebarRowShell>
+ <WorkspaceShowMoreRow disabled={expanding} label={s.projects.showAllCount(total)} onClick={showAll} />
+ )}
+ {expanded && page.more > 0 && (
+ <WorkspaceShowMoreRow label={s.showMoreIn(page.more, project.label)} onClick={page.showMore} />
)}
</SidebarRowNest>
)}
diff --git a/apps/desktop/src/app/chat/sidebar/projects/workspace-group.tsx b/apps/desktop/src/app/chat/sidebar/projects/workspace-group.tsx
index 2d03d01f315..b367c89b34d 100644
--- a/apps/desktop/src/app/chat/sidebar/projects/workspace-group.tsx
+++ b/apps/desktop/src/app/chat/sidebar/projects/workspace-group.tsx
@@ -1,6 +1,5 @@
import { useStore } from '@nanostores/react'
import type * as React from 'react'
-import { useState } from 'react'
import { type NewSessionPlacement, type NewSessionSplitHandler, startNewSessionDrag } from '@/app/chat/new-session-drag'
import { Codicon } from '@/components/ui/codicon'
@@ -19,14 +18,14 @@ import { $sidebarSessionRankIds } from '@/store/sidebar-sort'
import { SidebarGroupRow, SidebarRowLead, SidebarRowLink, SidebarRowStack } from '../chrome'
import { rankSessions } from '../order'
-import { PROJECT_PREVIEW_COUNT, SIDEBAR_GROUP_PAGE, useWorkspaceNodeOpen } from './model'
+import { PROJECT_PREVIEW_COUNT, SIDEBAR_GROUP_PAGE, useRevealedRows, useWorkspaceNodeOpen } from './model'
import type { SidebarSessionGroup } from './workspace-groups'
import {
WorkspaceAddButton,
WorkspaceContextMenu,
WorkspaceHeader,
WorkspaceMenu,
- WorkspaceShowMoreButton
+ WorkspaceShowMoreRow
} from './workspace-header'
interface SidebarWorkspaceGroupProps {
@@ -62,18 +61,23 @@ export function SidebarWorkspaceGroup({
// lanes that already hold sessions default open.
const defaultOpen = isProfileGroup || group.sessions.length > 0
const [open, toggleOpen] = useWorkspaceNodeOpen(group.id, defaultOpen)
- const [visibleCount, setVisibleCount] = useState(SIDEBAR_GROUP_PAGE)
// A lane ranks by whatever the sort key says before it trims itself, so the
// rows it hides are the ones the sort ranked last.
const sessions = rankSessions(group.sessions, rankIds)
+ // A lane opens on its first few rows and pages the rest in on demand.
+ const lane = useRevealedRows(sessions, SIDEBAR_GROUP_PAGE)
+
// A profile previews the same handful a project does, and clicking its label
// is how you see the rest. Workspace groups page within what's loaded unless
// the user asked for everything.
- const laneCap = showAllSessions ? sessions.length : visibleCount
- const visibleSessions = sessions.slice(0, isProfileGroup ? PROJECT_PREVIEW_COUNT : laneCap)
- const hiddenCount = isProfileGroup ? 0 : sessions.length - visibleSessions.length
- const nextCount = Math.min(SIDEBAR_GROUP_PAGE, hiddenCount)
+ const visibleSessions = isProfileGroup
+ ? sessions.slice(0, PROJECT_PREVIEW_COUNT)
+ : showAllSessions
+ ? sessions
+ : lane.shown
+
+ const nextCount = isProfileGroup || showAllSessions ? 0 : lane.more
// Leading glyph: a home mark for the repo's primary checkout (labeled by its
// live branch), a branch/kanban mark otherwise.
@@ -227,12 +231,8 @@ export function SidebarWorkspaceGroup({
) : (
renderRows(visibleSessions)
)}
- {hiddenCount > 0 && (
- <WorkspaceShowMoreButton
- count={nextCount}
- label={group.label}
- onClick={() => setVisibleCount(count => count + SIDEBAR_GROUP_PAGE)}
- />
+ {nextCount > 0 && (
+ <WorkspaceShowMoreRow label={s.showMoreIn(nextCount, group.label)} onClick={lane.showMore} />
)}
</>
)}
diff --git a/apps/desktop/src/app/chat/sidebar/projects/workspace-header.tsx b/apps/desktop/src/app/chat/sidebar/projects/workspace-header.tsx
index 6ec08d4155a..9b0bf7ac1e6 100644
--- a/apps/desktop/src/app/chat/sidebar/projects/workspace-header.tsx
+++ b/apps/desktop/src/app/chat/sidebar/projects/workspace-header.tsx
@@ -10,7 +10,14 @@ import { cn } from '@/lib/utils'
import { openWorktreeDialog } from '@/store/coding-status'
import { copyPath, revealPath } from '@/store/projects'
-import { SidebarRowLead } from '../chrome'
+import {
+ SIDEBAR_LEAD_ICON_SIZE,
+ SidebarRowBody,
+ SidebarRowLabel,
+ SidebarRowLead,
+ SidebarRowLeadGlyph,
+ SidebarRowShell
+} from '../chrome'
// Branch/worktree labels routinely share a long prefix (`bb/coding-context-…`),
// so plain end-truncation (`truncate`) hides exactly the suffix that tells two
@@ -60,6 +67,38 @@ export function WorkspaceAddButton({
)
}
+// Row-shaped "show more" — the ellipsis lead + a labeled link, the same shape
+// as the Back row — for project lists that can run long (expanded overview
+// rows, entered lanes, entered Home). A labeled row, not the icon-only glyph
+// below, because it's the only way to reach the rest of a project's sessions
+// and a hover-only tooltip read as "there are only five" (#83157, #93878).
+export function WorkspaceShowMoreRow({
+ disabled,
+ label,
+ onClick
+}: {
+ disabled?: boolean
+ label: string
+ onClick: () => void
+}) {
+ return (
+ <SidebarRowShell>
+ <SidebarRowBody
+ className="group/more w-full text-(--ui-text-tertiary) hover:text-foreground"
+ disabled={disabled}
+ onClick={onClick}
+ >
+ <SidebarRowLead>
+ <SidebarRowLeadGlyph>
+ <Codicon name="ellipsis" size={SIDEBAR_LEAD_ICON_SIZE} />
+ </SidebarRowLeadGlyph>
+ </SidebarRowLead>
+ <SidebarRowLabel className="text-xs underline-offset-4 group-hover/more:underline">{label}</SidebarRowLabel>
+ </SidebarRowBody>
+ </SidebarRowShell>
+ )
+}
+
// Reveals the next page of already-loaded rows within a workspace/worktree.
// Hangs off the lane instead of sitting in a row, so it repeats the row's
// trailing inset (SidebarRowShell's `pr-2`) to stay on the edge the rows stop at.
diff --git a/apps/desktop/src/app/chat/sidebar/sessions-section-new-session-drag.test.tsx b/apps/desktop/src/app/chat/sidebar/sessions-section-new-session-drag.test.tsx
index bc8bfa75cbf..d3fdc4d4f4e 100644
--- a/apps/desktop/src/app/chat/sidebar/sessions-section-new-session-drag.test.tsx
+++ b/apps/desktop/src/app/chat/sidebar/sessions-section-new-session-drag.test.tsx
@@ -12,6 +12,7 @@ import {
type SidebarSessionGroup,
SidebarWorkspaceGroup
} from './projects'
+import type * as ProjectsModel from './projects/model'
import { SidebarSessionsSection, VIRTUALIZE_THRESHOLD } from './sessions-section'
import type { VirtualSessionListProps } from './virtual-session-list'
@@ -82,9 +83,8 @@ vi.mock('@/i18n', () => ({
})
}))
-vi.mock('./projects/model', () => ({
- PROJECT_PREVIEW_COUNT: 3,
- SIDEBAR_GROUP_PAGE: 5,
+vi.mock('./projects/model', async () => ({
+ ...(await vi.importActual<typeof ProjectsModel>('./projects/model')),
latestProjectSessions: () => [],
useWorkspaceNodeOpen: () => [workspaceOpen.value, vi.fn()]
}))
@@ -227,6 +227,64 @@ describe('Show all sessions', () => {
})
})
+// An entered project/Home must reach every session it holds (#70421, #83157,
+// #93878): the lane's first page stays short, but the way to the rest is a
+// labeled row, not a hover-only glyph, and it pages in real steps.
+describe('entered project reaches every session', () => {
+ const many = (count: number, prefix = 'session') =>
+ Array.from({ length: count }, (_, index) => ({ id: `${prefix}-${index + 1}` }) as SessionInfo)
+
+ const renderRows = (items: SessionInfo[]) => <div data-testid="rows">{items.map(item => item.id).join(',')}</div>
+ const shownCount = () => screen.getByTestId('rows').textContent?.split(',').filter(Boolean).length ?? 0
+
+ it('labels the lane "show more" row with visible text, not just a tooltip', () => {
+ workspaceOpen.value = true
+
+ render(<SidebarWorkspaceGroup group={group({ sessions: many(12) })} renderRows={renderRows} />)
+
+ expect(shownCount()).toBe(5)
+ fireEvent.click(screen.getByText('Show 7 more in feature'))
+ expect(shownCount()).toBe(12)
+ expect(screen.queryByText(/Show .* more in feature/)).toBeNull()
+ })
+
+ it('pages a long lane in PROJECT_SESSION_PAGE steps past the first five', () => {
+ workspaceOpen.value = true
+
+ render(<SidebarWorkspaceGroup group={group({ sessions: many(60) })} renderRows={renderRows} />)
+
+ fireEvent.click(screen.getByText('Show 50 more in feature'))
+ expect(shownCount()).toBe(55)
+ fireEvent.click(screen.getByText('Show 5 more in feature'))
+ expect(shownCount()).toBe(60)
+ })
+
+ it('pages an entered Home instead of rendering every chat at once', () => {
+ const home = project({
+ id: '__no_project__',
+ isNoProject: true,
+ label: 'Home',
+ path: null,
+ repos: [
+ {
+ groups: [group({ id: '__no_project__', sessions: many(60) })],
+ id: '__no_project__',
+ label: 'Home',
+ path: null,
+ sessionCount: 60
+ }
+ ],
+ sessionCount: 60
+ })
+
+ render(<EnteredProjectContent project={home} renderRows={renderRows} />)
+
+ expect(shownCount()).toBe(50)
+ fireEvent.click(screen.getByText('Show 10 more in Home'))
+ expect(shownCount()).toBe(60)
+ })
+})
+
describe('project-associated new-session drag sources', () => {
it('drags from the project overview + with the project cwd', () => {
const onNewSessionSplit = vi.fn()