From 832c5922f21a9c05a0cb66aa2b5bf8348e0fcbb8 Mon Sep 17 00:00:00 2001 From: weishu Date: Sun, 1 Nov 2026 16:00:56 +0800 Subject: [PATCH] feat(web): align session rows and connection banners with native apps - Agent icon spans both lines with a presence badge (pulsing while a turn or background work runs); no dimmed rows or row spinners - Unread is a semibold title plus accent time instead of a dot; pending requests are amber hand/bubble symbols, keeping one dot per row - Reconnecting/syncing banners appear after 2s; reconnecting is neutral, amber stays for offline --- web/src/App.tsx | 14 +- web/src/components/ReconnectingBanner.tsx | 9 +- .../components/SessionAttentionIndicator.tsx | 37 ++- web/src/components/SessionRowSummary.test.tsx | 86 ++++-- web/src/components/SessionRowSummary.tsx | 270 +++++++++--------- web/src/components/icons.tsx | 23 ++ web/src/hooks/useDelayedFlag.test.ts | 36 +++ web/src/hooks/useDelayedFlag.ts | 21 ++ 8 files changed, 318 insertions(+), 178 deletions(-) create mode 100644 web/src/hooks/useDelayedFlag.test.ts create mode 100644 web/src/hooks/useDelayedFlag.ts diff --git a/web/src/App.tsx b/web/src/App.tsx index fde5e489..ad8e72f8 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -9,6 +9,7 @@ import { useAuth } from '@/hooks/useAuth' import { useAuthSource } from '@/hooks/useAuthSource' import { useServerUrl } from '@/hooks/useServerUrl' import { useSSE } from '@/hooks/useSSE' +import { useDelayedFlag } from '@/hooks/useDelayedFlag' import { useSessions } from '@/hooks/queries/useSessions' import { useReconnectingState } from '@/hooks/useReconnectingState' import { useSyncingState } from '@/hooks/useSyncingState' @@ -45,6 +46,8 @@ import type { SyncEvent } from '@/types/api' type ToastEvent = Extract const REQUIRE_SERVER_URL = requireHubUrlForLogin() +/** Matches the native apps: transient connection states show after 2s. */ +const CONNECTION_STATUS_DELAY_MS = 2_000 function withPwaBanner(content: ReactNode) { return ( @@ -398,6 +401,9 @@ function AppInner() { ) const sseEnabled = Boolean(api && token) const showReconnectingBanner = sseDisconnected && !isSyncing + // Transient states wait before showing; quick reconnects never flash. + const revealReconnecting = useDelayedFlag(showReconnectingBanner, CONNECTION_STATUS_DELAY_MS) + const revealSyncing = useDelayedFlag(isSyncing, CONNECTION_STATUS_DELAY_MS) const { subscriptionId: globalSubscriptionId } = useSSE({ enabled: sseEnabled, @@ -515,12 +521,12 @@ function AppInner() { - + diff --git a/web/src/components/ReconnectingBanner.tsx b/web/src/components/ReconnectingBanner.tsx index 6d5c4b4a..23453886 100644 --- a/web/src/components/ReconnectingBanner.tsx +++ b/web/src/components/ReconnectingBanner.tsx @@ -1,3 +1,4 @@ +import { Spinner } from '@/components/Spinner' import { useTranslation } from '@/lib/use-translation' function getReasonLabel(reason: string, t: (key: string) => string): string { @@ -36,11 +37,13 @@ export function ReconnectingBanner({ return null } + // Neutral like SyncingBanner: reconnecting is routine. Amber is reserved + // for being offline (OfflineBanner). App delays this by 2s. return ( -
- +
+ {t('reconnecting.message')} - {reasonLabel ? ({reasonLabel}) : null} + {reasonLabel ? ({reasonLabel}) : null}
) } diff --git a/web/src/components/SessionAttentionIndicator.tsx b/web/src/components/SessionAttentionIndicator.tsx index 0968ff94..7d70dbbd 100644 --- a/web/src/components/SessionAttentionIndicator.tsx +++ b/web/src/components/SessionAttentionIndicator.tsx @@ -1,14 +1,26 @@ +import type { ReactNode } from 'react' import type { PendingRequest, SessionSummary } from '@/types/api' import type { SessionAttention } from '@/lib/sessionAttention' import { getSessionAttentionLabelKey } from '@/lib/sessionAttention' import { useTranslation } from '@/lib/use-translation' import { HoverTooltip, SESSION_ROW_TOOLTIP_FOCUS_CLASS } from '@/components/HoverTooltip' -import { LoaderIcon } from '@/components/icons' +import { HandIcon, LoaderIcon, MessageIcon } from '@/components/icons' -const ATTENTION_DOT_CLASS: Record, string> = { - permission: 'bg-amber-500 animate-pulse', - input: 'bg-blue-500', - unread: 'bg-[var(--app-link)]' +/** + * Pending-request symbol: amber hand (permission) or bubble (input). Symbols, + * not dots, so the row's presence badge stays its only dot. + */ +export function SessionRequestIcon(props: { kind: 'permission' | 'input'; label?: string }) { + const Icon = props.kind === 'permission' ? HandIcon : MessageIcon + return ( + + + + ) } /** Row spinner: green while a turn runs, blue while only background work runs. */ @@ -18,7 +30,8 @@ export function SessionSpinner(props: { background?: boolean }) { } /** - * Visible attention dot + hover tooltip explaining the indicator. + * Visible attention symbol (or a caller-provided `target`, e.g. the row's + * agent icon) + hover tooltip explaining the indicator. * * The tooltip body composes from `summary.pendingRequests` (capped oldest-first; * see `PENDING_REQUEST_SUMMARY_CAP` in `@hapi/protocol`) for permission / input @@ -29,15 +42,17 @@ export function SessionAttentionIndicator(props: { summary: SessionSummary label: string tooltipId: string + target?: ReactNode }) { const { t } = useTranslation() - const dot = props.attention.kind === 'background' ? ( + const kind = props.attention.kind + const dot = props.target ?? (kind === 'background' ? ( + ) : kind === 'unread' ? ( + ) : ( - - ) + + )) return ( { localStorage.clear() }) - it('draws the background spinner with the thinking spinner markup, only in blue', () => { - const background = renderSummary(false).container.querySelector('svg.animate-spin-slow') + it('marks running and background work on the presence badge, without spinners', () => { + const background = renderSummary(false).container + const backgroundBadge = background.querySelector('[data-testid="session-presence"]') + expect(backgroundBadge).toHaveClass('bg-blue-400', 'animate-pulse') + expect(background.querySelector('svg.animate-spin-slow')).toBeNull() cleanup() + const thinking = render( - ).container.querySelector('svg.animate-spin-slow') - + ).container + expect(thinking.querySelector('[data-testid="session-presence"]')) + .toHaveClass('bg-[var(--app-badge-success-text)]', 'animate-pulse') expect(screen.queryByText('Running', { exact: true })).not.toBeInTheDocument() - expect(background?.outerHTML.replace('text-blue-400', 'text-[var(--app-badge-success-text)]')) - .toBe(thinking?.outerHTML) + cleanup() + + const idle = render( + + + + ).container + expect(idle.querySelector('[data-testid="session-presence"]')).not.toHaveClass('animate-pulse') }) - it('shows a detailed background dot with the task-count tooltip in Extended mode', () => { + it('does not dim disconnected rows or show them a presence badge', () => { + const { container } = render( + + + + ) + expect(container.querySelector('.opacity-50')).toBeNull() + expect(container.querySelector('[data-testid="session-presence"]')).toBeNull() + }) + + it('shows a detailed background tooltip on the agent icon in Extended mode', () => { renderSummary(true) expect(screen.queryByText('Running', { exact: true })).not.toBeInTheDocument() @@ -89,7 +110,8 @@ describe('SessionRowSummary background status', () => { ) - expect(screen.queryByRole('tooltip', { hidden: true })).not.toBeInTheDocument() + expect(screen.queryByText('New activity')).not.toBeInTheDocument() + expect(screen.getByText('Background demo')).toHaveClass('font-normal') markSessionUnread(session.id) view.rerender( @@ -102,10 +124,10 @@ describe('SessionRowSummary background status', () => { ) - expect(screen.getByRole('tooltip', { hidden: true })).toHaveTextContent('New activity') + expectUnread() }) - it('keeps an explicit unread dot across newer activity', () => { + it('keeps an explicit unread mark across newer activity', () => { const session = makeSummary({ id: 'selected-unread', active: false, @@ -126,7 +148,7 @@ describe('SessionRowSummary background status', () => { ) - expect(screen.getByRole('tooltip', { hidden: true })).toHaveTextContent('New activity') + expectUnread() view.rerender( @@ -139,10 +161,10 @@ describe('SessionRowSummary background status', () => { ) - expect(screen.getByRole('tooltip', { hidden: true })).toHaveTextContent('New activity') + expectUnread() }) - it('keeps the thinking spinner beside an explicit unread dot', () => { + it('marks unread without a dot while the presence badge keeps pulsing', () => { const session = makeSummary({ id: 'selected-thinking-unread', thinking: true, @@ -162,11 +184,14 @@ describe('SessionRowSummary background status', () => { ) - expect(screen.getByRole('tooltip', { hidden: true })).toHaveTextContent('New activity') - expect(container.querySelector('svg.animate-spin-slow.text-\\[var\\(--app-badge-success-text\\)\\]')).not.toBeNull() + expectUnread() + const dots = container.querySelectorAll('.rounded-full') + expect(dots).toHaveLength(1) + expect(dots[0]).toHaveAttribute('data-testid', 'session-presence') + expect(dots[0]).toHaveClass('animate-pulse') }) - it('shows unseen output from a running session without hiding its spinner', () => { + it('shows unseen output from a running session', () => { const session = makeSummary({ id: 'running-unread', backgroundTaskCount: 1, updatedAt: 2_000 }) markSessionSeen(session.id, 1_000) @@ -176,11 +201,36 @@ describe('SessionRowSummary background status', () => { ) - expect(screen.getByRole('tooltip', { hidden: true })).toHaveTextContent('New activity') - expect(container.querySelector('svg.animate-spin-slow.text-blue-400')).not.toBeNull() + expectUnread() + expect(container.querySelector('[data-testid="session-presence"]')).toHaveClass('bg-blue-400', 'animate-pulse') + }) + + it('shows pending requests as an amber symbol, not a dot', () => { + const { container } = render( + + + + ) + + expect(screen.getByRole('tooltip', { hidden: true })).toHaveTextContent('Bash') + expect(container.querySelector('.text-\\[var\\(--app-badge-warning-text\\)\\] svg')).not.toBeNull() + expect(container.querySelectorAll('.rounded-full')).toHaveLength(1) }) }) +function expectUnread() { + expect(screen.getByText('New activity')).toHaveClass('sr-only') + expect(screen.getByText(/demo|Background/, { selector: '[title]' })).toHaveClass('font-semibold') +} + describe('SessionRowSummary time label', () => { beforeEach(() => { localStorage.clear() diff --git a/web/src/components/SessionRowSummary.tsx b/web/src/components/SessionRowSummary.tsx index 881d3f6e..d442dc19 100644 --- a/web/src/components/SessionRowSummary.tsx +++ b/web/src/components/SessionRowSummary.tsx @@ -3,7 +3,7 @@ import type { SessionSummary } from '@/types/api' import { AgentFlavorIcon } from '@/components/AgentFlavorIcon' import { ScheduleIcon } from '@/components/icons' import { HoverTooltip, SESSION_ROW_TOOLTIP_FOCUS_CLASS, useSessionRowTooltipIds } from '@/components/HoverTooltip' -import { getAttentionLabel, SessionAttentionIndicator, SessionSpinner } from '@/components/SessionAttentionIndicator' +import { getAttentionLabel, SessionAttentionIndicator, SessionRequestIcon } from '@/components/SessionAttentionIndicator' import { classifySessionAttention } from '@/lib/sessionAttention' import { getSessionLastSeenAt, getSessionManualUnreadAt } from '@/lib/sessionLastSeen' import { formatRelativeTime } from '@/lib/relativeTime' @@ -35,13 +35,6 @@ function BulbIcon(props: { className?: string }) { ) } -const ATTENTION_DOT_CLASS = { - permission: 'bg-amber-500 animate-pulse', - input: 'bg-blue-500', - background: 'bg-blue-400', - unread: 'bg-[var(--app-link)]', -} as const - function getTodoProgress(session: SessionSummary): { completed: number; total: number } | null { if (!session.todoProgress) return null if (session.todoProgress.completed === session.todoProgress.total) return null @@ -78,7 +71,9 @@ function getSessionTimeLabel( /** * Presentational session row — same chrome as the sidebar SessionItem body - * (flavor, title, thinking/attention, schedule, todos, relative time, path). + * (flavor icon with presence badge, title, request/schedule symbols, todos, + * relative time, path). Visual language matches the native apps: no dimmed + * rows or spinners; unread is a semibold title + accent time, not a dot. * Used by the session list and by rich-composer mention chip tooltips. */ export function SessionRowSummary(props: { @@ -151,140 +146,131 @@ export function SessionRowSummary(props: { const importedAt = useSyncExternalStore(subscribeCodexImportedSessions, () => getCodexImportedAt(codexSessionId)) const timeLabel = getSessionTimeLabel(s, importedAt, t) - return ( -
-
-
- -
- {sessionName} -
- {attention?.kind === 'unread' ? ( - <> - {s.active && s.thinking ? ( - - ) : s.active && (s.backgroundTaskCount ?? 0) > 0 ? ( - - ) : null} - {nestedTooltips && attentionId ? ( - - ) : ( - - )} - - ) : s.active && s.thinking ? ( - - ) : urgentAttention && nestedTooltips && attentionId ? ( - - ) : urgentAttention ? ( - - ) : showDetailedStatus && attention?.kind === 'background' && nestedTooltips && attentionId ? ( - - ) : (showDetailedStatus && attention?.kind === 'background') || (s.active && (s.backgroundTaskCount ?? 0) > 0) ? ( - - ) : s.active && (s.pendingRequestsCount ?? 0) > 0 ? ( - - - ) : attention && nestedTooltips && attentionId ? ( - - ) : attention ? ( - - ) : null} - {hasScheduleTooltip && nestedTooltips && scheduleId ? ( - } - side="bottom" - align="start" - className="shrink-0" - revealOnParentFocusClass={SESSION_ROW_TOOLTIP_FOCUS_CLASS} - > - - {scheduledLabel} - - {formatScheduledTooltipDetail(s, t)} - - - - ) : hasScheduleTooltip ? ( - - - - ) : null} -
-
- {todoProgress ? ( - - - {todoProgress.completed}/{todoProgress.total} - - ) : null} - {!attention && s.active && s.pendingRequestsCount > 0 ? ( - - {t('session.item.pending')} {s.pendingRequestsCount} - - ) : null} - {timeLabel ? ( - {timeLabel} - ) : null} -
-
- {projectLabel || machineLabel ? ( -
- {[projectLabel, machineLabel].filter(Boolean).join(' · ')} -
- ) : showPath || worktreeLabel ? ( -
- {worktreeLabel ?? s.metadata?.path ?? s.id} -
+ // Presence lives on the agent icon (pulsing while a turn or background + // work runs) instead of dimming disconnected rows or adding spinners. + const isRunning = s.active && s.thinking + const isBackgroundOnly = s.active && !s.thinking && (s.backgroundTaskCount ?? 0) > 0 + // Unread is a semibold title plus accent time — no dot, so the presence + // badge stays the row's only dot. The label stays for screen readers. + const isUnread = attention?.kind === 'unread' + const requestKind = urgentAttention + ? attention.kind as 'permission' | 'input' + : s.active && (s.pendingRequestsCount ?? 0) > 0 + ? (s.pendingRequestKinds?.length && !s.pendingRequestKinds.includes('permission') ? 'input' : 'permission') + : null + const agentIcon = ( + + + {s.active ? ( + ) : null} + + ) + + return ( +
+ {attention?.kind === 'background' && nestedTooltips && attentionId ? ( + + ) : agentIcon} +
+
+
+
+ {sessionName} +
+ {isUnread ? ( + + {attentionLabel} + + ) : null} + {requestKind && urgentAttention && nestedTooltips && attentionId ? ( + + ) : requestKind ? ( + + + {!urgentAttention && !inRunningSection ? ( + {t('session.item.pending')} + ) : null} + + ) : null} + {hasScheduleTooltip && nestedTooltips && scheduleId ? ( + } + side="bottom" + align="start" + className="shrink-0" + revealOnParentFocusClass={SESSION_ROW_TOOLTIP_FOCUS_CLASS} + > + + {scheduledLabel} + + {formatScheduledTooltipDetail(s, t)} + + + + ) : hasScheduleTooltip ? ( + + + + ) : null} +
+
+ {todoProgress ? ( + + + {todoProgress.completed}/{todoProgress.total} + + ) : null} + {!attention && s.active && s.pendingRequestsCount > 0 ? ( + + {t('session.item.pending')} {s.pendingRequestsCount} + + ) : null} + {timeLabel ? ( + {timeLabel} + ) : null} +
+
+ {projectLabel || machineLabel ? ( +
+ {[projectLabel, machineLabel].filter(Boolean).join(' · ')} +
+ ) : showPath || worktreeLabel ? ( +
+ {worktreeLabel ?? s.metadata?.path ?? s.id} +
+ ) : null} +
) } diff --git a/web/src/components/icons.tsx b/web/src/components/icons.tsx index ff031c80..f924008b 100644 --- a/web/src/components/icons.tsx +++ b/web/src/components/icons.tsx @@ -157,6 +157,29 @@ export function ScheduleIcon(props: IconProps) { ) } +/** Raised hand — a session waiting for permission approval. */ +export function HandIcon(props: IconProps) { + return createIcon( + <> + + + + + , + props, + 2 + ) +} + +/** Speech bubble — a session waiting for the user's reply. */ +export function MessageIcon(props: IconProps) { + return createIcon( + , + props, + 2 + ) +} + /** Spinner spokes; callers add the spin animation and color. */ export function LoaderIcon(props: IconProps) { return createIcon( diff --git a/web/src/hooks/useDelayedFlag.test.ts b/web/src/hooks/useDelayedFlag.test.ts new file mode 100644 index 00000000..472aa5ad --- /dev/null +++ b/web/src/hooks/useDelayedFlag.test.ts @@ -0,0 +1,36 @@ +import { act, renderHook } from '@testing-library/react' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { useDelayedFlag } from './useDelayedFlag' + +describe('useDelayedFlag', () => { + beforeEach(() => vi.useFakeTimers()) + afterEach(() => vi.useRealTimers()) + + it('reveals only after the value stays true for the delay', () => { + const { result, rerender } = renderHook(({ value }) => useDelayedFlag(value, 2_000), { + initialProps: { value: true }, + }) + expect(result.current).toBe(false) + act(() => { vi.advanceTimersByTime(1_999) }) + expect(result.current).toBe(false) + act(() => { vi.advanceTimersByTime(1) }) + expect(result.current).toBe(true) + + rerender({ value: false }) + expect(result.current).toBe(false) + }) + + it('never reveals a value that clears before the delay', () => { + const { result, rerender } = renderHook(({ value }) => useDelayedFlag(value, 2_000), { + initialProps: { value: true }, + }) + act(() => { vi.advanceTimersByTime(1_500) }) + rerender({ value: false }) + act(() => { vi.advanceTimersByTime(5_000) }) + expect(result.current).toBe(false) + + rerender({ value: true }) + act(() => { vi.advanceTimersByTime(1_500) }) + expect(result.current).toBe(false) + }) +}) diff --git a/web/src/hooks/useDelayedFlag.ts b/web/src/hooks/useDelayedFlag.ts new file mode 100644 index 00000000..ff456911 --- /dev/null +++ b/web/src/hooks/useDelayedFlag.ts @@ -0,0 +1,21 @@ +import { useEffect, useState } from 'react' + +/** + * True only once `value` has stayed true for `delayMs`; false immediately. + * Transient connection states use it so a quick reconnect (tab refocus, + * network handoff) never flashes a banner. + */ +export function useDelayedFlag(value: boolean, delayMs: number): boolean { + const [revealed, setRevealed] = useState(false) + + useEffect(() => { + if (!value) { + setRevealed(false) + return + } + const timer = setTimeout(() => setRevealed(true), delayMs) + return () => clearTimeout(timer) + }, [value, delayMs]) + + return value && revealed +}