The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(desktop): limit recency previews at complete group boundaries
brooklyn!32f3c908ffb9
diff --git a/apps/desktop/src/lib/session-date-groups.test.ts b/apps/desktop/src/lib/session-date-groups.test.tsindex dc44190c906..b818b31648f 100644--- a/apps/desktop/src/lib/session-date-groups.test.ts+++ b/apps/desktop/src/lib/session-date-groups.test.ts@@ -27,6 +27,28 @@ const dividerKeys = (rows: ReturnType<typeof groupEntriesByRecency>): string[] =rows.flatMap(row => (row.kind === 'divider' ? [row.key] : []))describe('groupEntriesByRecency', () => {+ it('limits complete Updated groups without splitting bursts or branch clusters', () => {+ const burst = Array.from({ length: 11 }, (_, i) =>+ entry(session(`burst-${i}`, { last_active: at(2026, 5, 18, 11) - i * 120 }))+ )++ const entries = [+ ...burst,+ entry(session('yesterday', { last_active: at(2026, 5, 17, 15) })),+ entry(session('branch', { last_active: at(2026, 4, 1) }), '└'),+ entry(session('older', { last_active: at(2026, 5, 16, 15) }))+ ]++ const full = group(entries)+ const dividers = full.flatMap((row, index) => row.kind === 'divider' ? [index] : [])+ const limited = groupEntriesByRecency(entries, NOW, MONDAY, 2)++ expect(limited).toEqual(full.slice(0, dividers[1]))+ expect(limited.at(-1)).toMatchObject({ entry: { session: { id: 'branch' } } })+ expect(groupEntriesByRecency(burst, NOW, MONDAY, 2)).toEqual(group(burst))+ expect(groupEntriesByRecency([], NOW, MONDAY, 2)).toEqual([])+ })+it('cuts the head after the most recent handful, then divides by coarse ranges', () => {// The morning run (30m/30m/4h/30m gaps, then a 14h silence) is the// unlabelled head; each older group gets one divider, coarsening with age.diff --git a/apps/desktop/src/lib/session-date-groups.ts b/apps/desktop/src/lib/session-date-groups.tsindex 089502104c0..062cf52ff52 100644--- a/apps/desktop/src/lib/session-date-groups.ts+++ b/apps/desktop/src/lib/session-date-groups.ts@@ -97,12 +97,14 @@ function headRunCutoffMs(entries: readonly SidebarSessionEntry[], nowMs: number,export function groupEntriesByRecency(entries: readonly SidebarSessionEntry[],nowMs = Date.now(),- weekStartsOn = localeWeekStartDay()+ weekStartsOn = localeWeekStartDay(),+ maxGroups = Number.POSITIVE_INFINITY): SidebarListRow[] {const rows: SidebarListRow[] = []const emitted = new Set<string>()const cutoff = headRunCutoffMs(entries, nowMs, weekStartsOn)let lastKey: null | string = null+ let groups = 1for (const entry of entries) {// Nested branch rows travel with their parent cluster; they never open a new@@ -136,6 +138,11 @@ export function groupEntriesByRecency(// A divider only ever separates two groups — never label the very first// rendered row, whatever group it belongs to.if (rows.length > 0 && !alreadyEmitted) {+ if (groups >= maxGroups) {+ break+ }++ groups++rows.push({ bucket, key: bucket.key, kind: 'divider' })}}