diff --git a/frontend/src/components/activity/ActivityList.tsx b/frontend/src/components/activity/ActivityList.tsx index 55cb5f85..127d3d55 100644 --- a/frontend/src/components/activity/ActivityList.tsx +++ b/frontend/src/components/activity/ActivityList.tsx @@ -64,7 +64,7 @@ function ActivityStateIcon({ item, iconClassName }: { item: ActiveWorkItem; icon return } if (item.state === 'running') { - return + return } if (item.outcome === 'failed') { return diff --git a/frontend/src/components/message/ComposerActivityBar.test.tsx b/frontend/src/components/message/ComposerActivityBar.test.tsx new file mode 100644 index 00000000..fa907fb0 --- /dev/null +++ b/frontend/src/components/message/ComposerActivityBar.test.tsx @@ -0,0 +1,228 @@ +import { act, render, screen } from '@testing-library/react' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { ComposerActivityBar } from './ComposerActivityBar' +import { useSessionStatus } from '@/stores/sessionStatusStore' +import { stubMatchMedia } from '@/test/test-utils' + +const originalMatchMedia = window.matchMedia +const originalResizeObserver = global.ResizeObserver + +class MockResizeObserver { + static instances: MockResizeObserver[] = [] + + readonly callback: ResizeObserverCallback + + constructor(callback: ResizeObserverCallback) { + this.callback = callback + MockResizeObserver.instances.push(this) + } + + observe() {} + + unobserve() {} + + disconnect() {} + + trigger(width: number) { + this.callback( + [{ contentRect: { width } } as ResizeObserverEntry], + this as unknown as ResizeObserver, + ) + } +} + +const resetStore = () => { + useSessionStatus.setState({ + statuses: new Map(), + statusCache: new Map(), + statusRevisions: new Map(), + knownSessions: new Set(), + outcomes: new Map(), + parents: new Map(), + directories: new Map(), + runningShells: new Map(), + revision: 0, + }) +} + +const segmentsOf = (bar: HTMLElement) => + Array.from(bar.firstElementChild?.children ?? []) as HTMLElement[] + +const measureWidth = (width: number) => { + act(() => { + MockResizeObserver.instances.forEach((instance) => instance.trigger(width)) + }) +} + +describe('ComposerActivityBar', () => { + beforeEach(() => { + resetStore() + MockResizeObserver.instances = [] + global.ResizeObserver = MockResizeObserver as unknown as typeof ResizeObserver + }) + + afterEach(() => { + vi.useRealTimers() + global.ResizeObserver = originalResizeObserver + Object.defineProperty(window, 'matchMedia', { + configurable: true, + writable: true, + value: originalMatchMedia, + }) + }) + + it('renders nothing when the session is idle without background activity', () => { + const { container } = render() + + expect(container).toBeEmptyDOMElement() + }) + + it('anchors a pointer-transparent progressbar in the gap below the composer', () => { + useSessionStatus.getState().setStatus('session-a', { type: 'busy' }) + + render() + + const bar = screen.getByRole('progressbar', { name: 'Session working' }) + expect(bar).toHaveClass('pointer-events-none') + expect(bar).toHaveClass('absolute') + expect(bar).toHaveClass('inset-x-3') + expect(bar).toHaveClass('-bottom-[13px]') + expect(bar).toHaveClass('md:-bottom-[11px]') + expect(bar).toHaveClass('flex') + }) + + it('fills the measured width with 4x8 segments', () => { + useSessionStatus.getState().setStatus('session-a', { type: 'busy' }) + + render() + + const bar = screen.getByRole('progressbar', { name: 'Session working' }) + expect(bar.firstElementChild).toHaveClass('gap-0.5') + + measureWidth(602) + + const segments = segmentsOf(bar) + expect(segments).toHaveLength(100) + expect(segments[0]).toHaveClass('w-1') + expect(segments[0]).toHaveClass('h-2') + expect(segments[0]).toHaveClass('rounded-[1px]') + expect(segments[0]).toHaveClass('transition-colors') + expect(segments[0]).toHaveClass('duration-75') + expect(segments[0]).not.toHaveClass('flex-1') + }) + + it('keeps the minimum segment count for narrow containers', () => { + useSessionStatus.getState().setStatus('session-a', { type: 'busy' }) + + render() + + const bar = screen.getByRole('progressbar', { name: 'Session working' }) + measureWidth(20) + + expect(segmentsOf(bar)).toHaveLength(12) + }) + + it('lights the info tiers around the scanner window', () => { + useSessionStatus.getState().setStatus('session-a', { type: 'busy' }) + + render() + + measureWidth(602) + + const segments = segmentsOf(screen.getByRole('progressbar', { name: 'Session working' })) + expect(segments[3]).toHaveClass('bg-info') + expect(segments[4]).toHaveClass('bg-info/70') + expect(segments[6]).toHaveClass('bg-info/40') + expect(segments[7]).toHaveClass('bg-info/20') + expect(segments[8]).toHaveClass('bg-muted/20') + expect(segments[99]).toHaveClass('bg-muted/20') + }) + + it('renders the compacting state with primary colors', () => { + useSessionStatus.getState().setStatus('session-a', { type: 'compact' }) + + render() + + measureWidth(602) + + const segments = segmentsOf(screen.getByRole('progressbar', { name: 'Compacting' })) + expect(segments[3]).toHaveClass('bg-primary') + expect(segments[4]).toHaveClass('bg-primary/70') + expect(segments[6]).toHaveClass('bg-primary/40') + expect(segments[7]).toHaveClass('bg-primary/20') + expect(segments[8]).toHaveClass('bg-muted/20') + }) + + it('reports the retry attempt in the label with warning colors', () => { + useSessionStatus.getState().setStatus('session-a', { + type: 'retry', + attempt: 2, + message: 'rate limited', + next: Date.now() + 5_000, + }) + + render() + + measureWidth(602) + + const segments = segmentsOf(screen.getByRole('progressbar', { name: 'Retrying (Retry #2)' })) + expect(segments[3]).toHaveClass('bg-warning') + expect(segments[4]).toHaveClass('bg-warning/70') + expect(segments[6]).toHaveClass('bg-warning/40') + expect(segments[7]).toHaveClass('bg-warning/20') + expect(segments[8]).toHaveClass('bg-muted/20') + }) + + it('renders the muted background activity state when idle with a running shell', () => { + useSessionStatus.getState().setShellRunning('shell-1', 'session-a', '/repo') + + render() + + measureWidth(602) + + const segments = segmentsOf(screen.getByRole('progressbar', { name: 'Background tasks running' })) + expect(segments[3]).toHaveClass('bg-muted-foreground') + expect(segments[4]).toHaveClass('bg-muted-foreground/70') + expect(segments[6]).toHaveClass('bg-muted-foreground/40') + expect(segments[7]).toHaveClass('bg-muted-foreground/20') + expect(segments[8]).toHaveClass('bg-muted/20') + }) + + it('sweeps the lit window on the step interval', () => { + vi.useFakeTimers() + useSessionStatus.getState().setStatus('session-a', { type: 'busy' }) + + render() + + const bar = screen.getByRole('progressbar', { name: 'Session working' }) + measureWidth(602) + expect(segmentsOf(bar)[3]).toHaveClass('bg-info') + + act(() => { + vi.advanceTimersByTime(120) + }) + + const segments = segmentsOf(bar) + expect(segments[7]).toHaveClass('bg-info') + expect(segments[4]).toHaveClass('bg-info/40') + }) + + it('renders every segment statically when reduced motion is requested', () => { + vi.useFakeTimers() + stubMatchMedia(true) + useSessionStatus.getState().setStatus('session-a', { type: 'busy' }) + + render() + + const bar = screen.getByRole('progressbar', { name: 'Session working' }) + measureWidth(602) + act(() => { + vi.advanceTimersByTime(600) + }) + + const segments = segmentsOf(bar) + expect(segments).toHaveLength(100) + expect(segments.every((segment) => segment.classList.contains('bg-info/60'))).toBe(true) + expect(segments.some((segment) => segment.classList.contains('bg-muted/20'))).toBe(false) + }) +}) diff --git a/frontend/src/components/message/ComposerActivityBar.tsx b/frontend/src/components/message/ComposerActivityBar.tsx new file mode 100644 index 00000000..7b7b05a9 --- /dev/null +++ b/frontend/src/components/message/ComposerActivityBar.tsx @@ -0,0 +1,62 @@ +import { ScannerBars, type ScannerTone } from '@/components/ui/scanner-bars' +import { useHasBackgroundActivity, useSessionStatusForSession } from '@/stores/sessionStatusStore' + +interface ComposerActivityBarProps { + sessionID: string +} + +const LIT_WIDTH = 6 +const STEP_INTERVAL_MS = 30 + +const ACTIVITY_PRESENTATION = { + background: { + label: 'Background tasks running', + tone: 'muted-foreground', + }, + busy: { + label: 'Session working', + tone: 'info', + }, + compact: { + label: 'Compacting', + tone: 'primary', + }, + retry: { + label: 'Retrying', + tone: 'warning', + }, +} as const satisfies Record + +/** + * Session activity scanner anchored in the gap below the composer frame. The strip uses the same + * 4x8px segments as the session status scanner and fills the composer width with as many segments + * as fit. Renders nothing while the session is idle and has no background activity; otherwise + * announces the current activity through an indeterminate progressbar. + */ +export function ComposerActivityBar({ sessionID }: ComposerActivityBarProps) { + const status = useSessionStatusForSession(sessionID) + const hasBackgroundActivity = useHasBackgroundActivity(sessionID) + + if (status.type === 'idle' && !hasBackgroundActivity) { + return null + } + + const activity = status.type === 'idle' + ? ACTIVITY_PRESENTATION.background + : ACTIVITY_PRESENTATION[status.type] + const label = status.type === 'retry' + ? `${ACTIVITY_PRESENTATION.retry.label} (Retry #${status.attempt})` + : activity.label + + return ( + + + + ) +} diff --git a/frontend/src/components/message/PromptInput.command.test.tsx b/frontend/src/components/message/PromptInput.command.test.tsx index 9115fe17..83f6380d 100644 --- a/frontend/src/components/message/PromptInput.command.test.tsx +++ b/frontend/src/components/message/PromptInput.command.test.tsx @@ -103,10 +103,6 @@ vi.mock('@/hooks/useSessionPermissionMode', () => ({ useSessionPermissionMode: () => ({ data: undefined }), })) -vi.mock('@/components/ui/session-status-indicator', () => ({ - SessionStatusIndicator: () => SessionStatus, -})) - vi.mock('./ComposerToolsMenu', () => ({ ComposerToolsMenu: () => null, })) @@ -274,6 +270,23 @@ describe('PromptInput command submission', () => { expect(screen.getByRole('status')).toHaveTextContent('Background tasks running') }) + it('keeps the model picker visible while the session is active', async () => { + const queryClient = createTestQueryClient() + queryClient.setQueryData(['opencode', 'session', 'test-session', '/test'], sessionInfo()) + const buildPrompt = (props: { isSessionActive?: boolean }) => ( + + + + ) + + const { rerender } = render(buildPrompt({})) + await screen.findByPlaceholderText('Send a message...') + expect(screen.getByTestId('model-quick-select').querySelector('button')).not.toBeNull() + + rerender(buildPrompt({ isSessionActive: true })) + expect(screen.getByTestId('model-quick-select').querySelector('button')).not.toBeNull() + }) + it('disables submit and does not run a command while the model is not ready', async () => { mocks.useModelSelection.mockReturnValue({ model: null, diff --git a/frontend/src/components/message/PromptInput.goal.test.tsx b/frontend/src/components/message/PromptInput.goal.test.tsx index 8b75ade5..55fdb8e1 100644 --- a/frontend/src/components/message/PromptInput.goal.test.tsx +++ b/frontend/src/components/message/PromptInput.goal.test.tsx @@ -122,10 +122,6 @@ vi.mock('@/components/session/SessionSandboxMenu', () => ({ SessionSandboxMenu: () => null, })) -vi.mock('@/components/ui/session-status-indicator', () => ({ - SessionStatusIndicator: () => SessionStatus, -})) - vi.mock('./PromptSuggestions', () => ({ PromptSuggestions: () => null, })) diff --git a/frontend/src/components/message/PromptInput.mention.test.tsx b/frontend/src/components/message/PromptInput.mention.test.tsx index 237b44fa..cfcc9bdd 100644 --- a/frontend/src/components/message/PromptInput.mention.test.tsx +++ b/frontend/src/components/message/PromptInput.mention.test.tsx @@ -89,10 +89,6 @@ vi.mock('@/hooks/useSessionPermissionMode', () => ({ useSessionPermissionMode: () => ({ data: undefined }), })) -vi.mock('@/components/ui/session-status-indicator', () => ({ - SessionStatusIndicator: () => SessionStatus, -})) - vi.mock('./PromptSuggestions', () => ({ PromptSuggestions: (props: { isOpen: boolean; selectedIndex: number }) => { if (props.isOpen) { diff --git a/frontend/src/components/message/PromptInput.stt.test.tsx b/frontend/src/components/message/PromptInput.stt.test.tsx index 7c316f9b..8dc7c1d9 100644 --- a/frontend/src/components/message/PromptInput.stt.test.tsx +++ b/frontend/src/components/message/PromptInput.stt.test.tsx @@ -121,10 +121,6 @@ vi.mock('@/hooks/useSessionPermissionMode', () => ({ useSessionPermissionMode: () => ({ data: undefined }), })) -vi.mock('@/components/ui/session-status-indicator', () => ({ - SessionStatusIndicator: () => SessionStatus, -})) - vi.mock('./PromptSuggestions', () => ({ PromptSuggestions: () => null, })) diff --git a/frontend/src/components/message/PromptInput.tsx b/frontend/src/components/message/PromptInput.tsx index fff193da..93327a63 100644 --- a/frontend/src/components/message/PromptInput.tsx +++ b/frontend/src/components/message/PromptInput.tsx @@ -25,7 +25,7 @@ import { SquareFill } from '@/components/ui/square-fill' import { IconToggleButton } from '@/components/ui/icon-toggle-button' import { PromptSuggestions, type PromptSuggestion } from './PromptSuggestions' -import { SessionStatusIndicator } from '@/components/ui/session-status-indicator' +import { ComposerActivityBar } from './ComposerActivityBar' import { ModelQuickSelect } from '@/components/model/ModelQuickSelect' import { AgentQuickSelect } from '@/components/agent/AgentQuickSelect' import { VoiceStatusOverlay, type VoiceStatusOverlayState } from './VoiceStatusOverlay' @@ -1488,10 +1488,11 @@ if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read) : '' return ( - + {sessionActivityAnnouncement} + {composerModeStyle && ( Latest - {(isSessionActive || hasBackgroundActivity) && ( - - - - )} > ) : null} - {(isSessionActive || hasBackgroundActivity) && ( - - - - )} - {!isSessionActive && !hideSecondaryButtons && ( + {!hideSecondaryButtons && ( diff --git a/frontend/src/components/navigation/RepoSessionNav.tsx b/frontend/src/components/navigation/RepoSessionNav.tsx index ff8656b3..261db78c 100644 --- a/frontend/src/components/navigation/RepoSessionNav.tsx +++ b/frontend/src/components/navigation/RepoSessionNav.tsx @@ -145,7 +145,7 @@ export function SessionNavRow({ item, isCurrent, onSelect, repoLabel }: SessionN {item.worktreeBranch} )} - + {hasPermission(item.session.id) && ( )} diff --git a/frontend/src/components/repo/MultiRunCard.tsx b/frontend/src/components/repo/MultiRunCard.tsx index 2df5404c..ebc18bcb 100644 --- a/frontend/src/components/repo/MultiRunCard.tsx +++ b/frontend/src/components/repo/MultiRunCard.tsx @@ -329,7 +329,7 @@ function EntryRow({ {entry.model} - {readiness.label === 'Running' && sessionId ? : null} + {readiness.label === 'Running' && sessionId ? : null} {isolationLabel} {detail ? ( @@ -389,7 +389,7 @@ function FusionRow({ fusion, onOpenSession, onWalkthrough }: FusionRowProps) { {fusion.model} - {fusion.status === 'started' && sessionId ? : null} + {fusion.status === 'started' && sessionId ? : null} from {fusion.sources.length} source{fusion.sources.length === 1 ? '' : 's'} diff --git a/frontend/src/components/session/SessionCard.tsx b/frontend/src/components/session/SessionCard.tsx index e8c4ff07..8ec24f89 100644 --- a/frontend/src/components/session/SessionCard.tsx +++ b/frontend/src/components/session/SessionCard.tsx @@ -95,7 +95,7 @@ export const SessionCard = ({ }} className="w-5 h-5 flex-shrink-0" /> - + @@ -130,7 +130,7 @@ export const SessionCard = ({ addSuffix: true, })} - + {onTogglePin && ( diff --git a/frontend/src/components/session/SessionPickerDialog.tsx b/frontend/src/components/session/SessionPickerDialog.tsx index fb4fb849..9f772d7d 100644 --- a/frontend/src/components/session/SessionPickerDialog.tsx +++ b/frontend/src/components/session/SessionPickerDialog.tsx @@ -181,7 +181,7 @@ function SessionPickerGutter({ sessionID, isActive }: { sessionID: string; isAct const status = useSessionStatusForSession(sessionID) if (status.type !== 'idle') { return ( - + ) } if (isActive) { diff --git a/frontend/src/components/ui/scanner-bars.tsx b/frontend/src/components/ui/scanner-bars.tsx new file mode 100644 index 00000000..f15aecc5 --- /dev/null +++ b/frontend/src/components/ui/scanner-bars.tsx @@ -0,0 +1,205 @@ +import { useLayoutEffect, useRef, useState, type RefObject } from 'react' +import { useMediaQuery } from '@/hooks/useMediaQuery' +import { cn } from '@/lib/utils' + +export type ScannerTone = 'info' | 'primary' | 'warning' | 'muted-foreground' + +export const SCANNER_REDUCED_MOTION_QUERY = '(prefers-reduced-motion: reduce)' + +const SCANNER_SEGMENT_WIDTH = 4 +const SCANNER_SEGMENT_GAP = 2 +const SCANNER_SEGMENT_PITCH = SCANNER_SEGMENT_WIDTH + SCANNER_SEGMENT_GAP +const SCANNER_MIN_SEGMENTS = 12 + +const SCANNER_SEGMENT_CLASS = 'w-1 h-2 rounded-[1px] transition-colors duration-75' + +const SCANNER_TONE_TIERS: Record = { + info: ['bg-info', 'bg-info/70', 'bg-info/40', 'bg-info/20'], + primary: ['bg-primary', 'bg-primary/70', 'bg-primary/40', 'bg-primary/20'], + warning: ['bg-warning', 'bg-warning/70', 'bg-warning/40', 'bg-warning/20'], + 'muted-foreground': ['bg-muted-foreground', 'bg-muted-foreground/70', 'bg-muted-foreground/40', 'bg-muted-foreground/20'], +} + +const SCANNER_STATIC_TONE_CLASS: Record = { + info: 'bg-info/60', + primary: 'bg-primary/60', + warning: 'bg-warning/60', + 'muted-foreground': 'bg-muted-foreground/60', +} + +const SCANNER_OFF_CLASS = 'bg-muted/20' +const SCANNER_INTENSITY_THRESHOLDS = [0.8, 0.5, 0.2] as const +const SCANNER_FAINTEST_TIER = SCANNER_INTENSITY_THRESHOLDS.length + +/** + * Returns how many fixed-width segments fit into `width`: each segment is 4px wide and the + * container adds a 2px gap between neighbors, so `n` segments occupy `6n - 2` pixels. Never + * drops below `SCANNER_MIN_SEGMENTS` so an unmeasured container still renders a usable scanner. + */ +export function scannerSegmentCountForWidth(width: number): number { + return Math.max(SCANNER_MIN_SEGMENTS, Math.floor((width + SCANNER_SEGMENT_GAP) / SCANNER_SEGMENT_PITCH)) +} + +/** + * Tracks the content width of a container across resizes. Returns 0 until the first measurement. + */ +function useContainerWidth(ref: RefObject): number { + const [width, setWidth] = useState(0) + + useLayoutEffect(() => { + const element = ref.current + if (!element) { + return + } + + const update = (next: number) => setWidth((previous) => (previous === next ? previous : next)) + update(element.getBoundingClientRect().width) + + if (typeof ResizeObserver === 'undefined') { + return + } + + const observer = new ResizeObserver((entries) => { + const entry = entries[0] + if (entry) { + update(entry.contentRect.width) + } + }) + observer.observe(element) + return () => observer.disconnect() + }, [ref]) + + return width +} + +interface ScannerSegmentClassOptions { + index: number + position: number + litWidth: number + tone: ScannerTone + static?: boolean +} + +/** + * Returns the background class for one scanner segment. Segments within the lit window fade out + * with distance from the window center across four intensity tiers; everything outside the window + * stays muted. `static` skips the window math and renders the uniform reduced-motion tint. + */ +export function scannerSegmentClass({ + index, + position, + litWidth, + tone, + static: isStatic = false, +}: ScannerSegmentClassOptions): string { + if (isStatic) { + return SCANNER_STATIC_TONE_CLASS[tone] + } + + const halfWidth = litWidth / 2 + const distance = Math.abs(index - (position + halfWidth)) + + if (distance > halfWidth + 1) { + return SCANNER_OFF_CLASS + } + + const intensity = Math.max(0, 1 - distance / (halfWidth + 2)) + const tier = SCANNER_INTENSITY_THRESHOLDS.findIndex((threshold) => intensity > threshold) + + return SCANNER_TONE_TIERS[tone][tier === -1 ? SCANNER_FAINTEST_TIER : tier] +} + +interface ScannerPositionOptions { + segmentCount: number + litWidth: number + intervalMs: number + paused: boolean +} + +function useScannerPosition({ + segmentCount, + litWidth, + intervalMs, + paused, +}: ScannerPositionOptions): number { + const [position, setPosition] = useState(0) + const direction = useRef(1) + const maxPosition = Math.max(0, segmentCount - litWidth) + + useLayoutEffect(() => { + setPosition((previous) => Math.min(previous, maxPosition)) + }, [maxPosition]) + + useLayoutEffect(() => { + if (paused || maxPosition === 0) { + return + } + + const interval = setInterval(() => { + setPosition((previous) => { + const next = previous + direction.current + if (next >= maxPosition) { + direction.current = -1 + return maxPosition + } + if (next <= 0) { + direction.current = 1 + return 0 + } + return next + }) + }, intervalMs) + + return () => clearInterval(interval) + }, [paused, maxPosition, intervalMs]) + + return position +} + +interface ScannerBarsProps { + tone: ScannerTone + segmentCount?: number + litWidth?: number + intervalMs?: number + className?: string +} + +/** + * Segmented scanner matching the session status scanner: 4x8px segments with a 2px gap and a lit + * window of `litWidth` segments that sweeps back and forth. Without an explicit `segmentCount` the + * count is measured from the container width so the strip spans the space it is given. Under + * `prefers-reduced-motion: reduce` the sweep is not started and every segment renders statically at + * 60% opacity. + */ +export function ScannerBars({ + tone, + segmentCount, + litWidth = 6, + intervalMs = 60, + className, +}: ScannerBarsProps) { + const containerRef = useRef(null) + const reducedMotion = useMediaQuery(SCANNER_REDUCED_MOTION_QUERY) + const measuredWidth = useContainerWidth(containerRef) + const resolvedCount = segmentCount ?? scannerSegmentCountForWidth(measuredWidth) + const position = useScannerPosition({ + segmentCount: resolvedCount, + litWidth, + intervalMs, + paused: reducedMotion, + }) + + return ( + + {Array.from({ length: resolvedCount }, (_, index) => ( + + ))} + + ) +} diff --git a/frontend/src/components/ui/session-status-indicator.test.tsx b/frontend/src/components/ui/session-status-indicator.test.tsx index b506b285..43b79b11 100644 --- a/frontend/src/components/ui/session-status-indicator.test.tsx +++ b/frontend/src/components/ui/session-status-indicator.test.tsx @@ -26,13 +26,13 @@ describe('SessionStatusIndicator background activity', () => { it('shows the background tasks label when idle with a running shell', () => { useSessionStatus.getState().setShellRunning('shell-1', 'session-a', '/repo') - render() + render() expect(screen.getByLabelText('Background tasks running')).toBeInTheDocument() }) it('renders nothing when idle without background activity', () => { - const { container } = render() + const { container } = render() expect(container).toBeEmptyDOMElement() }) @@ -40,7 +40,7 @@ describe('SessionStatusIndicator background activity', () => { it('renders the braille spinner with a running label for a busy session', () => { useSessionStatus.getState().setStatus('session-a', { type: 'busy' }) - const { container } = render() + const { container } = render() expect(screen.getByLabelText('Running')).toBeInTheDocument() const litDots = container.querySelectorAll('svg[aria-hidden="true"] circle[fill-opacity="1"]') diff --git a/frontend/src/components/ui/session-status-indicator.tsx b/frontend/src/components/ui/session-status-indicator.tsx index fc6c3960..4ea40a60 100644 --- a/frontend/src/components/ui/session-status-indicator.tsx +++ b/frontend/src/components/ui/session-status-indicator.tsx @@ -1,169 +1,51 @@ -import { memo, useEffect, useState } from 'react' +import { memo } from 'react' import { ActivitySpinner } from '@/components/ui/activity-spinner' -import { useHasBackgroundActivity, useSessionStatusForSession, type SessionStatusType } from '@/stores/sessionStatusStore' +import { useHasBackgroundActivity, useSessionStatusForSession } from '@/stores/sessionStatusStore' interface SessionStatusIndicatorProps { sessionID: string className?: string - size?: 'sm' | 'md' - showLabel?: boolean } -const SCANNER_WIDTH = 6 -const SCANNER_SEGMENTS = 12 - /** - * Shows a session's activity. `sm` renders the braille spinner sized for list rows; - * `md` renders the animated scanner used by the session composer. + * Shows a session's activity as the braille spinner sized for list rows. + * Renders nothing while the session is idle and has no background activity. */ -export const SessionStatusIndicator = memo(function SessionStatusIndicator({ - sessionID, +export const SessionStatusIndicator = memo(function SessionStatusIndicator({ + sessionID, className = '', - size = 'md', - showLabel = false }: SessionStatusIndicatorProps) { const status = useSessionStatusForSession(sessionID) const hasBackground = useHasBackgroundActivity(sessionID) - const [position, setPosition] = useState(0) - const [direction, setDirection] = useState(1) - const [retryCountdown, setRetryCountdown] = useState(0) const backgroundOnly = status.type === 'idle' && hasBackground - - useEffect(() => { - if (size !== 'md') { - return - } - if (status.type === 'idle' && !hasBackground) { - return - } - - const interval = setInterval(() => { - setPosition(prev => { - const next = prev + direction - if (next >= SCANNER_SEGMENTS - SCANNER_WIDTH) { - setDirection(-1) - return SCANNER_SEGMENTS - SCANNER_WIDTH - } - if (next <= 0) { - setDirection(1) - return 0 - } - return next - }) - }, 60) - - return () => clearInterval(interval) - }, [size, status.type, hasBackground, direction]) - - useEffect(() => { - if (!showLabel || status.type !== 'retry') { - setRetryCountdown(0) - return - } - - const remaining = Math.max(0, Math.ceil((status.next - Date.now()) / 1000)) - setRetryCountdown(remaining) - - const interval = setInterval(() => { - const newRemaining = Math.max(0, Math.ceil((status.next - Date.now()) / 1000)) - setRetryCountdown(newRemaining) - }, 1000) - - return () => clearInterval(interval) - }, [status, showLabel]) - + if (status.type === 'idle' && !hasBackground) { return null } - - if (size === 'sm') { - const colorClass = backgroundOnly - ? 'text-muted-foreground' - : status.type === 'retry' - ? 'text-warning' - : status.type === 'compact' - ? 'text-primary' - : 'text-info' - const label = backgroundOnly - ? 'Background tasks running' - : status.type === 'retry' - ? 'Retrying' - : status.type === 'compact' - ? 'Compacting' - : 'Running' - return ( - - - - ) - } - - const getSegmentColor = (index: number, statusType: SessionStatusType['type'], background: boolean) => { - const distance = Math.abs(index - (position + SCANNER_WIDTH / 2)) - const maxDistance = SCANNER_WIDTH / 2 - - if (distance > maxDistance + 1) { - return 'bg-muted/20' - } - - const intensity = Math.max(0, 1 - distance / (maxDistance + 2)) - - if (background) { - if (intensity > 0.8) return 'bg-muted-foreground' - if (intensity > 0.5) return 'bg-muted-foreground/70' - if (intensity > 0.2) return 'bg-muted-foreground/40' - return 'bg-muted-foreground/20' - } + const colorClass = backgroundOnly + ? 'text-muted-foreground' + : status.type === 'retry' + ? 'text-warning' + : status.type === 'compact' + ? 'text-primary' + : 'text-info' + const label = backgroundOnly + ? 'Background tasks running' + : status.type === 'retry' + ? 'Retrying' + : status.type === 'compact' + ? 'Compacting' + : 'Running' - if (statusType === 'retry') { - if (intensity > 0.8) return 'bg-warning' - if (intensity > 0.5) return 'bg-warning/70' - if (intensity > 0.2) return 'bg-warning/40' - return 'bg-warning/20' - } - - if (statusType === 'compact') { - if (intensity > 0.8) return 'bg-primary' - if (intensity > 0.5) return 'bg-primary/70' - if (intensity > 0.2) return 'bg-primary/40' - return 'bg-primary/20' - } - - if (intensity > 0.8) return 'bg-info' - if (intensity > 0.5) return 'bg-info/70' - if (intensity > 0.2) return 'bg-info/40' - return 'bg-info/20' - } - - const segmentClass = 'w-1 h-4' - const containerGap = showLabel ? 'gap-2' : '' - return ( - - - {Array.from({ length: SCANNER_SEGMENTS }).map((_, i) => ( - - ))} - - {showLabel && status.type === 'retry' && ( - - Retry #{status.attempt} - {retryCountdown > 0 && ({retryCountdown}s)} - - )} - + + ) })
{entry.model}
{fusion.model}