diff --git a/apps/desktop/src/app/chat/sidebar/index.tsx b/apps/desktop/src/app/chat/sidebar/index.tsx index 91f8abcdc4..46a150596f 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.ts deleted file mode 100644 index d1dbc31ae0..0000000000 --- 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.ts deleted file mode 100644 index 3b267b2b54..0000000000 --- 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.tsx index 59445080bf..6ce6304546 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() + + 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( + + ) + +// 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( { { { @@ -32,7 +31,6 @@ interface SidebarSessionRowProps extends React.ComponentProps<'div'> { branchStem?: string isPinned: boolean isSelected: boolean - isWorking: boolean onArchive: () => void onBranch?: () => void onDelete: () => 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 ( - {!isWorking && ( + {!liveTurn && ( {age} @@ -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 }) && ( -