Merge pull request #436 from chriswritescode-dev/feat/activity-switcher

feat(activity): surface active work across the session picker, tool rail and mobile
This commit is contained in:
Chris Scott authored and GitHub committed 2026-10-16 12:48:52 -04:00
commit 33d9523666
60 files changed
+3992 -491

No files matched your search

@@ -0,0 +1,98 @@
import { cleanup, render } from '@testing-library/react'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { ActivitySpinner, SPINNER_FRAMES, brailleDots } from './activity-spinner'
const circles = (root: ParentNode) => Array.from(root.querySelectorAll('circle'))
const litIndexes = (root: ParentNode) =>
circles(root)
.map((circle, index) => (circle.getAttribute('fill-opacity') === '1' ? index : -1))
.filter((index) => index >= 0)
const litIndexesFor = (frame: string) =>
brailleDots(frame)
.map((lit, index) => (lit ? index : -1))
.filter((index) => index >= 0)
describe('brailleDots', () => {
it('lights dots 1, 2 and 4 for the first frame', () => {
expect(brailleDots('⠋')).toEqual([true, true, false, true, false, false, false, false])
})
it('lights dots 1 through 4 for the last frame', () => {
expect(brailleDots('⠏')).toEqual([true, true, true, true, false, false, false, false])
})
})
describe('ActivitySpinner', () => {
afterEach(() => {
cleanup()
vi.useRealTimers()
})
it('renders eight dots with the first frame lit and hidden from assistive technology', () => {
const { container } = render(<ActivitySpinner />)
expect(circles(container)).toHaveLength(8)
expect(litIndexes(container)).toEqual(litIndexesFor(SPINNER_FRAMES[0]))
expect(container.querySelector('svg')).toHaveAttribute('aria-hidden', 'true')
})
it('steps every dot through all frames in order with a discrete, endless 80ms-per-frame animation', () => {
const { container } = render(<ActivitySpinner />)
circles(container).forEach((circle, dotIndex) => {
const animate = circle.querySelector('animate')
expect(animate).toHaveAttribute('attributeName', 'fill-opacity')
expect(animate).toHaveAttribute('calcMode', 'discrete')
expect(animate).toHaveAttribute('repeatCount', 'indefinite')
expect(animate).toHaveAttribute('dur', `${80 * SPINNER_FRAMES.length}ms`)
const values = animate?.getAttribute('values')?.split(';')
expect(values).toEqual(SPINNER_FRAMES.map((frame) => (brailleDots(frame)[dotIndex] ? '1' : '0.25')))
})
})
it('schedules no JavaScript timers however many spinners are mounted', () => {
vi.useFakeTimers()
render(
<>
<ActivitySpinner />
<ActivitySpinner />
<ActivitySpinner />
</>,
)
expect(vi.getTimerCount()).toBe(0)
})
it('keeps every dot inside the cell and clear of its neighbours', () => {
const { container } = render(<ActivitySpinner />)
const svg = container.querySelector('svg')
expect(svg).toHaveAttribute('viewBox', '0 0 9 16')
const dots = circles(container).map((circle) => ({
cx: Number(circle.getAttribute('cx')),
cy: Number(circle.getAttribute('cy')),
r: Number(circle.getAttribute('r')),
}))
expect(dots).toHaveLength(8)
for (const dot of dots) {
expect(dot.cx - dot.r).toBeGreaterThan(0)
expect(dot.cx + dot.r).toBeLessThan(9)
expect(dot.cy - dot.r).toBeGreaterThan(0)
expect(dot.cy + dot.r).toBeLessThan(16)
}
for (let i = 0; i < dots.length; i += 1) {
for (let j = i + 1; j < dots.length; j += 1) {
const distance = Math.hypot(dots[i].cx - dots[j].cx, dots[i].cy - dots[j].cy)
expect(distance).toBeGreaterThanOrEqual(dots[i].r + dots[j].r)
}
}
})
})
@@ -0,0 +1,76 @@
import { cn } from '@/lib/utils'
export const SPINNER_FRAMES = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'] as const
const FRAME_INTERVAL_MS = 80
const CYCLE_DURATION = `${FRAME_INTERVAL_MS * SPINNER_FRAMES.length}ms`
const BRAILLE_BASE = 0x2800
const DOT_GRID: ReadonlyArray<readonly [number, number]> = [
[0, 0],
[0, 1],
[0, 2],
[1, 0],
[1, 1],
[1, 2],
[0, 3],
[1, 3],
]
const COLUMN_X = [2.25, 6.75] as const
const ROW_Y = [2.25, 6, 9.75, 13.5] as const
const DOT_RADIUS = 1.6
const LIT_DOT_OPACITY = 1
const UNLIT_DOT_OPACITY = 0.25
/**
* Decodes one braille frame into its eight dot positions, ordered by braille dot numbering:
* dot1, dot2 and dot3 are the left column top-to-bottom, dot4, dot5 and dot6 the right column
* top-to-bottom, and dot7 and dot8 the bottom-left and bottom-right cells.
*/
export function brailleDots(frame: string): boolean[] {
const bits = (frame.codePointAt(0) ?? BRAILLE_BASE) - BRAILLE_BASE
return DOT_GRID.map((_, index) => (bits & (1 << index)) !== 0)
}
const FRAME_DOTS = SPINNER_FRAMES.map(brailleDots)
const DOT_OPACITY_TIMELINES = DOT_GRID.map((_, index) =>
FRAME_DOTS.map((dots) => (dots[index] ? LIT_DOT_OPACITY : UNLIT_DOT_OPACITY)),
)
/**
* Braille spinner mirroring the OpenCode TUI activity spinner as an inline SVG cell so the dots
* stay visible at small text sizes. Each dot steps through its opacity for every frame with a
* declarative SVG `<animate>` derived from `SPINNER_FRAMES`, so frames advance in the browser
* with no JavaScript or React render per frame. It animates regardless of
* `prefers-reduced-motion`: a still frame is indistinguishable from a stalled spinner, and the
* motion is a small in-place status cue like the platform activity indicators.
*/
export function ActivitySpinner({ className }: { className?: string }) {
return (
<svg
aria-hidden="true"
viewBox="0 0 9 16"
className={cn('inline-block h-4 w-[9px] shrink-0', className)}
>
{DOT_GRID.map(([column, row], index) => (
<circle
key={index}
cx={COLUMN_X[column]}
cy={ROW_Y[row]}
r={DOT_RADIUS}
fill="currentColor"
fillOpacity={DOT_OPACITY_TIMELINES[index][0]}
>
<animate
attributeName="fill-opacity"
values={DOT_OPACITY_TIMELINES[index].join(';')}
dur={CYCLE_DURATION}
calcMode="discrete"
repeatCount="indefinite"
/>
</circle>
))}
</svg>
)
}
@@ -1,6 +1,7 @@
import { render, screen } from '@testing-library/react'
import { beforeEach, describe, expect, it } from 'vitest'
import { SessionStatusIndicator } from './session-status-indicator'
import { SPINNER_FRAMES, brailleDots } from './activity-spinner'
import { useSessionStatus } from '@/stores/sessionStatusStore'
const resetStore = () => {
@@ -11,6 +12,7 @@ const resetStore = () => {
knownSessions: new Set(),
outcomes: new Map(),
parents: new Map(),
directories: new Map(),
runningShells: new Map(),
revision: 0,
})
@@ -34,4 +36,14 @@ describe('SessionStatusIndicator background activity', () => {
expect(container).toBeEmptyDOMElement()
})
it('renders the braille spinner with a running label for a busy session', () => {
useSessionStatus.getState().setStatus('session-a', { type: 'busy' })
const { container } = render(<SessionStatusIndicator sessionID="session-a" size="sm" />)
expect(screen.getByLabelText('Running')).toBeInTheDocument()
const litDots = container.querySelectorAll('svg[aria-hidden="true"] circle[fill-opacity="1"]')
expect(litDots).toHaveLength(brailleDots(SPINNER_FRAMES[0]).filter(Boolean).length)
})
})
@@ -1,4 +1,5 @@
import { memo, useEffect, useState } from 'react'
import { ActivitySpinner } from '@/components/ui/activity-spinner'
import { useHasBackgroundActivity, useSessionStatusForSession, type SessionStatusType } from '@/stores/sessionStatusStore'
interface SessionStatusIndicatorProps {
@@ -11,6 +12,10 @@ interface SessionStatusIndicatorProps {
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.
*/
export const SessionStatusIndicator = memo(function SessionStatusIndicator({
sessionID,
className = '',
@@ -25,6 +30,9 @@ export const SessionStatusIndicator = memo(function SessionStatusIndicator({
const backgroundOnly = status.type === 'idle' && hasBackground
useEffect(() => {
if (size !== 'md') {
return
}
if (status.type === 'idle' && !hasBackground) {
return
}
@@ -45,7 +53,7 @@ export const SessionStatusIndicator = memo(function SessionStatusIndicator({
}, 60)
return () => clearInterval(interval)
}, [status.type, hasBackground, direction])
}, [size, status.type, hasBackground, direction])
useEffect(() => {
if (!showLabel || status.type !== 'retry') {
@@ -68,6 +76,34 @@ export const SessionStatusIndicator = memo(function SessionStatusIndicator({
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 (
<span
role="img"
aria-label={label}
title={backgroundOnly ? label : undefined}
className={`inline-flex items-center ${colorClass} ${className}`}
>
<ActivitySpinner />
</span>
)
}
const getSegmentColor = (index: number, statusType: SessionStatusType['type'], background: boolean) => {
const distance = Math.abs(index - (position + SCANNER_WIDTH / 2))
const maxDistance = SCANNER_WIDTH / 2
@@ -105,7 +141,7 @@ export const SessionStatusIndicator = memo(function SessionStatusIndicator({
return 'bg-info/20'
}
const segmentClass = size === 'sm' ? 'w-0.5 h-2' : 'w-1 h-4'
const segmentClass = 'w-1 h-4'
const containerGap = showLabel ? 'gap-2' : ''
return (