The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(desktop): let the sidebar row read its own status
Brooklyn Nicholsonb07ee44f1bbb
diff --git a/apps/desktop/src/app/chat/sidebar/index.tsx b/apps/desktop/src/app/chat/sidebar/index.tsxindex 91f8abcdc45..46a150596f7 100644--- a/apps/desktop/src/app/chat/sidebar/index.tsx+++ b/apps/desktop/src/app/chat/sidebar/index.tsx@@ -394,8 +394,6 @@ export function ChatSidebar({[visibleSessions])- const workingSessionIdSet = useMemo(() => new Set(workingSessionIds), [workingSessionIds])-// Index sessions by every id a pin might be stored under — recents, cron,// AND messaging, since all three can be pinned (see session-index.ts).const sessionByAnyId = useMemo(@@ -1281,7 +1279,6 @@ export function ChatSidebar({rootClassName="min-h-32 flex-1 overflow-hidden p-0"sessions={searchResults}showProfileTags={showAllProfiles}- workingSessionIdSet={workingSessionIdSet}/>)}@@ -1305,7 +1302,6 @@ export function ChatSidebar({sessions={pinnedSessions}showProfileTags={showAllProfiles}sortable={pinnedSessions.length > 1}- workingSessionIdSet={workingSessionIdSet}/>)}@@ -1467,7 +1463,6 @@ export function ChatSidebar({)}sessions={displayAgentSessions}sortable={!showAllProfiles && agentSessions.length > 1}- workingSessionIdSet={workingSessionIdSet}/>)}@@ -1512,7 +1507,6 @@ export function ChatSidebar({pinned={false}rootClassName="shrink-0 p-0"sessions={shownSessions}- workingSessionIdSet={workingSessionIdSet}/>)})}diff --git a/apps/desktop/src/app/chat/sidebar/session-row-state.test.ts b/apps/desktop/src/app/chat/sidebar/session-row-state.test.tsdeleted file mode 100644index d1dbc31ae04..00000000000--- a/apps/desktop/src/app/chat/sidebar/session-row-state.test.ts+++ /dev/null@@ -1,17 +0,0 @@-import { describe, expect, it } from 'vitest'--import { sessionShowsRunningArc } from './session-row-state'--describe('session row running appearance', () => {- it('keeps the running arc when an authoritative turn becomes quiet', () => {- expect(sessionShowsRunningArc({ isWorking: true, needsInput: false })).toBe(true)- })-- it('uses the needs-input treatment instead of the running arc', () => {- expect(sessionShowsRunningArc({ isWorking: true, needsInput: true })).toBe(false)- })-- it('shows no arc for a session that is not running', () => {- expect(sessionShowsRunningArc({ isWorking: false, needsInput: false })).toBe(false)- })-})diff --git a/apps/desktop/src/app/chat/sidebar/session-row-state.ts b/apps/desktop/src/app/chat/sidebar/session-row-state.tsdeleted file mode 100644index 3b267b2b541..00000000000--- a/apps/desktop/src/app/chat/sidebar/session-row-state.ts+++ /dev/null@@ -1,12 +0,0 @@-/** A quiet turn is still authoritatively running. Keep the unmistakable row- * arc until the gateway reports completion; only a blocking prompt suppresses- * it in favour of the needs-input treatment. */-export function sessionShowsRunningArc({- isWorking,- needsInput-}: {- isWorking: boolean- needsInput: boolean-}): boolean {- return isWorking && !needsInput-}diff --git a/apps/desktop/src/app/chat/sidebar/session-row.test.tsx b/apps/desktop/src/app/chat/sidebar/session-row.test.tsxindex 59445080bf8..6ce6304546f 100644--- a/apps/desktop/src/app/chat/sidebar/session-row.test.tsx+++ b/apps/desktop/src/app/chat/sidebar/session-row.test.tsx@@ -4,8 +4,11 @@ import type * as React from 'react'import { afterEach, describe, expect, it, vi } from 'vitest'import type { SessionInfo } from '@/hermes'+import { createClientSessionState } from '@/lib/chat-runtime'+import type * as ChatRuntime from '@/lib/chat-runtime'import type * as ComposerStatusStore from '@/store/composer-status'import type * as SessionStore from '@/store/session'+import { clearAllSessionStates, publishSessionState } from '@/store/session-states'import type * as SessionStatesStore from '@/store/session-states'import type * as WindowsStore from '@/store/windows'@@ -41,7 +44,14 @@ vi.mock('@/app/chat/session-drag', () => ({ startSessionDrag: vi.fn() }))// props itself only proves the MOCK forwards them, not that the real// component does. This file exercises the actual production component so a// regression in its ref/prop forwarding fails here again.-vi.mock('@/lib/chat-runtime', () => ({ sessionTitle: (s: SessionInfo) => (s as unknown as { title: string }).title }))+// Only `sessionTitle` is overridden (makeSession fakes a bare `title` the real+// one wouldn't read); the rest of the module is genuine so the arc test can+// build session state with the same factory the app uses.+vi.mock('@/lib/chat-runtime', async importOriginal => {+ const actual = await importOriginal<typeof ChatRuntime>()++ return { ...actual, sessionTitle: (s: SessionInfo) => (s as unknown as { title: string }).title }+})vi.mock('@/lib/haptics', () => ({ triggerHaptic: vi.fn() }))vi.mock('@/lib/session-source', () => ({handoffOriginSource: (state?: string, platform?: string) => (state && platform ? platform : null),@@ -124,13 +134,51 @@ const handoffAvatar = (container: HTMLElement) =>const noop = vi.fn()+const renderRow = (session: SessionInfo) =>+ render(+ <SidebarSessionRow+ isPinned={false}+ isSelected={false}+ onArchive={noop}+ onDelete={noop}+ onPin={noop}+ onResume={noop}+ session={session}+ />+ )++// The row no longer takes its running state as a prop, so this drives the real+// store the way the app does. $workingSessionIds is the actual computed here+// (the mock above only overrides its siblings), which is what makes this cover+// the wiring rather than the predicate — the arc has gone missing before.+describe('SidebarSessionRow running arc', () => {+ afterEach(() => {+ clearAllSessionStates()+ })++ const arc = (container: HTMLElement) => container.querySelector('.arc-row')++ it('paints no arc for a settled session', () => {+ const { container } = renderRow(makeSession({ title: 'Settled' }))++ expect(arc(container)).toBeNull()+ })++ it('paints the arc while the session is running', () => {+ publishSessionState('rt1', { ...createClientSessionState('s1'), busy: true })++ const { container } = renderRow(makeSession({ title: 'Running' }))++ expect(arc(container)).toBeTruthy()+ })+})+describe('SidebarSessionRow', () => {it('keeps an aria-label on the kebab without wrapping it in a Tip', () => {render(<SidebarSessionRowisPinned={false}isSelected={false}- isWorking={false}onArchive={noop}onDelete={noop}onPin={noop}@@ -148,7 +196,6 @@ describe('SidebarSessionRow', () => {<SidebarSessionRowisPinned={false}isSelected={false}- isWorking={false}onArchive={noop}onDelete={noop}onPin={noop}@@ -165,7 +212,6 @@ describe('SidebarSessionRow', () => {<SidebarSessionRowisPinned={false}isSelected={false}- isWorking={false}onArchive={noop}onDelete={noop}onPin={noop}diff --git a/apps/desktop/src/app/chat/sidebar/session-row.tsx b/apps/desktop/src/app/chat/sidebar/session-row.tsxindex 333e505a4fb..a02ddd01aa3 100644--- a/apps/desktop/src/app/chat/sidebar/session-row.tsx+++ b/apps/desktop/src/app/chat/sidebar/session-row.tsx@@ -1,4 +1,3 @@-import { useStore } from '@nanostores/react'import { memo } from 'react'import type * as React from 'react'@@ -16,14 +15,14 @@ import { triggerHaptic } from '@/lib/haptics'import { middleClickHandlers } from '@/lib/middle-click'import { handoffOriginSource, sessionSourceLabel } from '@/lib/session-source'import { coarseElapsed } from '@/lib/time'+import { useStoreSelector } from '@/lib/use-session-slice'import { cn } from '@/lib/utils'-import { $attentionSessionIds } from '@/store/session-states'+import { $sessionDotStateById, hasLiveTurn, showsRunningArc } from '@/store/session-dot-state'import { SessionStatusDot } from '../session-status-dot'import { SidebarRowBody, SidebarRowGrab, SidebarRowLabel, SidebarRowLead, SidebarRowShell } from './chrome'import { SessionActionsMenu, SessionContextMenu } from './session-actions-menu'-import { sessionShowsRunningArc } from './session-row-state'import { useProfilePrewarm } from './use-profile-prewarm'interface SidebarSessionRowProps extends React.ComponentProps<'div'> {@@ -32,7 +31,6 @@ interface SidebarSessionRowProps extends React.ComponentProps<'div'> {branchStem?: stringisPinned: booleanisSelected: boolean- isWorking: booleanonArchive: () => voidonBranch?: () => voidonDelete: () => void@@ -61,7 +59,6 @@ function SidebarSessionRowImpl({branchStem,isPinned,isSelected,- isWorking,onArchive,onBranch,onDelete,@@ -87,8 +84,11 @@ function SidebarSessionRowImpl({// Telegram thread continued here still reads as Telegram.const handoffSource = handoffOriginSource(session.handoff_state, session.handoff_platform)const handoffLabel = handoffSource ? (sessionSourceLabel(handoffSource) ?? handoffSource) : null- // True when a clarify prompt in this session is waiting on the user.- const needsInput = useStore($attentionSessionIds).includes(session.id)+ // The same resolved state the row's dot paints, so the arc and the dot cannot+ // contradict each other. A selector, not a plain useStore: the map is rebuilt+ // whenever any session's status changes, but a row only repaints on its own.+ const dotState = useStoreSelector($sessionDotStateById, states => states[session.id] ?? 'idle')+ const liveTurn = hasLiveTurn(dotState)return (<SessionContextMenu@@ -104,7 +104,7 @@ function SidebarSessionRowImpl({<SidebarRowShellactions={<div className="relative z-2 grid w-[1.375rem] place-items-center" data-row-actions>- {!isWorking && (+ {!liveTurn && (<span className="pointer-events-none absolute right-6 top-1/2 min-w-6 -translate-y-1/2 text-right text-[0.625rem] leading-none text-(--ui-text-tertiary) opacity-0 transition-opacity group-hover:opacity-100">{age}</span>@@ -133,13 +133,13 @@ function SidebarSessionRowImpl({className={cn('group row-hover relative',isSelected && 'bg-(--ui-row-active-background)',- isWorking && 'text-foreground',+ liveTurn && 'text-foreground',// Opaque surface while lifted so the dragged row erases what's under// it (translucency let the rows below bleed through).dragging && 'z-10 cursor-grabbing bg-(--ui-sidebar-surface-background)',className)}- data-working={isWorking ? 'true' : undefined}+ data-working={liveTurn ? 'true' : undefined}onPointerDown={event => {// Reorder drags belong to dnd-kit (the grab handle); the ⋯ actions// cluster keeps its own gestures. Everything else on the row —@@ -164,9 +164,7 @@ function SidebarSessionRowImpl({style={style}{...rest}>- {sessionShowsRunningArc({ isWorking, needsInput }) && (- <span aria-hidden="true" className="arc-border arc-row" />- )}+ {showsRunningArc(dotState) && <span aria-hidden="true" className="arc-border arc-row" />}<SidebarRowBodyclassName={cn('z-0 group-hover:pr-12', branchStem && 'pl-3.5')}// Middle-click = open in a new tab (browser muscle memory).@@ -252,14 +250,14 @@ function SidebarSessionRowImpl({// design (they close over the row's session id), so a default memo never bails.// They're pure id-forwarders, though — identical behavior for a given row — so// the comparator deliberately ignores them and compares only the DATA that-// changes what the row paints. A row whose session/selection/working/pin state-// is unchanged now bails out, even while a sibling session streams.+// changes what the row paints. A row whose session/selection/pin state is+// unchanged now bails out, even while a sibling session streams; its own status+// arrives through a store subscription, which re-renders it past this bail.function rowPropsEqual(a: SidebarSessionRowProps, b: SidebarSessionRowProps): boolean {return (a.session === b.session &&a.isPinned === b.isPinned &&a.isSelected === b.isSelected &&- a.isWorking === b.isWorking &&a.branchStem === b.branchStem &&a.reorderable === b.reorderable &&a.dragging === b.dragging &&diff --git a/apps/desktop/src/app/chat/sidebar/sessions-section.test.tsx b/apps/desktop/src/app/chat/sidebar/sessions-section.test.tsxindex 5fd286e8463..b9097e429a9 100644--- a/apps/desktop/src/app/chat/sidebar/sessions-section.test.tsx+++ b/apps/desktop/src/app/chat/sidebar/sessions-section.test.tsx@@ -78,7 +78,6 @@ describe('SidebarSessionsSection memoization & virtualizer stability', () => {open={true}pinned={false}sessions={sessions}- workingSessionIdSet={new Set()}/>)@@ -100,7 +99,6 @@ describe('SidebarSessionsSection memoization & virtualizer stability', () => {open={true}pinned={false}sessions={sessions}- workingSessionIdSet={new Set()}/>)@@ -130,7 +128,6 @@ describe('SidebarSessionsSection memoization & virtualizer stability', () => {open={true}pinned={false}sessions={initialSessions}- workingSessionIdSet={new Set()}/>)@@ -151,7 +148,6 @@ describe('SidebarSessionsSection memoization & virtualizer stability', () => {open={true}pinned={false}sessions={initialSessions}- workingSessionIdSet={new Set()}/>)@@ -174,7 +170,6 @@ describe('SidebarSessionsSection memoization & virtualizer stability', () => {open={true}pinned={false}sessions={updatedSessions}- workingSessionIdSet={new Set()}/>)diff --git a/apps/desktop/src/app/chat/sidebar/sessions-section.tsx b/apps/desktop/src/app/chat/sidebar/sessions-section.tsxindex c5bb1ad2b4b..4ab211f0373 100644--- a/apps/desktop/src/app/chat/sidebar/sessions-section.tsx+++ b/apps/desktop/src/app/chat/sidebar/sessions-section.tsx@@ -91,7 +91,6 @@ interface SidebarSessionsSectionProps {onToggle: () => voidsessions: SessionInfo[]activeSessionId: null | string- workingSessionIdSet: Set<string>onResumeSession: (sessionId: string) => voidonDeleteSession: (sessionId: string) => voidonArchiveSession: (sessionId: string) => void@@ -163,7 +162,6 @@ export function SidebarSessionsSection({onToggle,sessions,activeSessionId,- workingSessionIdSet,onResumeSession,onDeleteSession,onArchiveSession,@@ -236,7 +234,6 @@ export function SidebarSessionsSection({branchStem,isPinned: pinned,isSelected: session.id === activeSessionId,- isWorking: workingSessionIdSet.has(session.id),onArchive: () => onArchiveSession(session.id),onBranch: onBranchSession ? () => onBranchSession(session.id, session.profile) : undefined,onDelete: () => onDeleteSession(session.id),@@ -261,8 +258,7 @@ export function SidebarSessionsSection({onResumeSession,onTogglePin,pinned,- showProfileTags,- workingSessionIdSet+ showProfileTags])@@ -423,7 +419,6 @@ export function SidebarSessionsSection({rows={flatRows}showProfileTags={showProfileTags}sortable={sessionsDraggable}- workingSessionIdSet={workingSessionIdSet}/>)@@ -474,7 +469,6 @@ interface SortableSessionRowProps {session: SessionInfoisPinned: booleanisSelected: boolean- isWorking: booleanonArchive: () => voidonDelete: () => voidonPin: () => voiddiff --git a/apps/desktop/src/app/chat/sidebar/virtual-session-list.tsx b/apps/desktop/src/app/chat/sidebar/virtual-session-list.tsxindex 90e10ddc38d..68f0d74867d 100644--- a/apps/desktop/src/app/chat/sidebar/virtual-session-list.tsx+++ b/apps/desktop/src/app/chat/sidebar/virtual-session-list.tsx@@ -17,7 +17,6 @@ interface SessionRowCommonProps {branchStem?: stringisPinned: booleanisSelected: boolean- isWorking: booleanonArchive: () => voidonBranch?: () => voidonDelete: () => void@@ -39,7 +38,6 @@ export interface VirtualSessionListProps {pinned: booleanshowProfileTags?: booleansortable: boolean- workingSessionIdSet: Set<string>}const ROW_ESTIMATE_PX = 28@@ -56,8 +54,7 @@ export const VirtualSessionList: FC<VirtualSessionListProps> = ({onTogglePin,pinned,showProfileTags = false,- sortable,- workingSessionIdSet+ sortable}) => {const { t } = useI18n()const dividerLabels = t.sidebar.dateDivider@@ -108,7 +105,6 @@ export const VirtualSessionList: FC<VirtualSessionListProps> = ({branchStem,isPinned: pinned,isSelected: session.id === activeSessionId,- isWorking: workingSessionIdSet.has(session.id),onArchive: () => onArchiveSession(session.id),onBranch: onBranchSession ? () => onBranchSession(session.id, session.profile) : undefined,onDelete: () => onDeleteSession(session.id),diff --git a/apps/desktop/src/store/session-dot-state.test.ts b/apps/desktop/src/store/session-dot-state.test.tsnew file mode 100644index 00000000000..5e81c3201b1--- /dev/null+++ b/apps/desktop/src/store/session-dot-state.test.ts@@ -0,0 +1,37 @@+import { describe, expect, it } from 'vitest'++import { hasLiveTurn, showsRunningArc } from './session-dot-state'++describe('showsRunningArc', () => {+ it('keeps the arc when an authoritative turn goes quiet', () => {+ expect(showsRunningArc('working')).toBe(true)+ expect(showsRunningArc('stalled')).toBe(true)+ })++ it('yields to the needs-input treatment rather than running both', () => {+ expect(showsRunningArc('needs-input')).toBe(false)+ })++ it('leaves a session that is not running unmarked', () => {+ expect(showsRunningArc('background')).toBe(false)+ expect(showsRunningArc('idle')).toBe(false)+ expect(showsRunningArc('unread')).toBe(false)+ })+})++describe('hasLiveTurn', () => {+ it('counts a turn waiting on an answer as still live', () => {+ expect(hasLiveTurn('needs-input')).toBe(true)+ })++ it('covers everything the arc covers', () => {+ for (const state of ['background', 'idle', 'needs-input', 'stalled', 'unread', 'working'] as const) {+ expect(hasLiveTurn(state) || !showsRunningArc(state)).toBe(true)+ }+ })++ it('excludes work that outlived the turn', () => {+ expect(hasLiveTurn('background')).toBe(false)+ expect(hasLiveTurn('unread')).toBe(false)+ })+})diff --git a/apps/desktop/src/store/session-dot-state.ts b/apps/desktop/src/store/session-dot-state.tsindex c9a025484a4..3a27e411721 100644--- a/apps/desktop/src/store/session-dot-state.ts+++ b/apps/desktop/src/store/session-dot-state.ts@@ -27,6 +27,16 @@ import { $attentionSessionIds, $stalledSessionIds, $workingSessionIds } from './export type SessionDotState = 'background' | 'idle' | 'needs-input' | 'stalled' | 'unread' | 'working'+/** The sidebar row's arc. A quiet turn is still authoritatively running, so+ * `stalled` keeps it; a blocking prompt drops it, because the amber dot is the+ * louder cue and two treatments at once fight each other. */+export const showsRunningArc = (state: SessionDotState): boolean => state === 'stalled' || state === 'working'++/** Whether this turn is the session's own, live: brighter title, and the row's+ * age yields to the actions menu. Wider than the arc — a turn waiting on an+ * answer has not ended. */+export const hasLiveTurn = (state: SessionDotState): boolean => showsRunningArc(state) || state === 'needs-input'+let dotStates: Readonly<Record<string, SessionDotState>> = {}export const $sessionDotStateById = computed(