mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
feat(frontend): move session activity scanner under the composer
- Keep the model picker visible while a session is active - Render a full-width segmented scanner below the composer via shared ScannerBars - Reduce SessionStatusIndicator to the list-row spinner
This commit is contained in:
1 parent
e8adbb3e65
commit
332fb07f45
15 files changed
+554
-185
No files matched your search
@@ -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(<ComposerActivityBar sessionID="session-a" />)
|
||||
|
||||
expect(container).toBeEmptyDOMElement()
|
||||
})
|
||||
|
||||
it('anchors a pointer-transparent progressbar in the gap below the composer', () => {
|
||||
useSessionStatus.getState().setStatus('session-a', { type: 'busy' })
|
||||
|
||||
render(<ComposerActivityBar sessionID="session-a" />)
|
||||
|
||||
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(<ComposerActivityBar sessionID="session-a" />)
|
||||
|
||||
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(<ComposerActivityBar sessionID="session-a" />)
|
||||
|
||||
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(<ComposerActivityBar sessionID="session-a" />)
|
||||
|
||||
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(<ComposerActivityBar sessionID="session-a" />)
|
||||
|
||||
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(<ComposerActivityBar sessionID="session-a" />)
|
||||
|
||||
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(<ComposerActivityBar sessionID="session-a" />)
|
||||
|
||||
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(<ComposerActivityBar sessionID="session-a" />)
|
||||
|
||||
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(<ComposerActivityBar sessionID="session-a" />)
|
||||
|
||||
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)
|
||||
})
|
||||
})
|
||||
@@ -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<string, { label: string; tone: ScannerTone }>
|
||||
|
||||
/**
|
||||
* 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 (
|
||||
<div
|
||||
role="progressbar"
|
||||
aria-label={label}
|
||||
aria-valuemin={0}
|
||||
aria-valuemax={100}
|
||||
className="pointer-events-none absolute inset-x-3 -bottom-[13px] md:-bottom-[11px] flex"
|
||||
>
|
||||
<ScannerBars tone={activity.tone} litWidth={LIT_WIDTH} intervalMs={STEP_INTERVAL_MS} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -103,10 +103,6 @@ vi.mock('@/hooks/useSessionPermissionMode', () => ({
|
||||
useSessionPermissionMode: () => ({ data: undefined }),
|
||||
}))
|
||||
|
||||
vi.mock('@/components/ui/session-status-indicator', () => ({
|
||||
SessionStatusIndicator: () => <div>SessionStatus</div>,
|
||||
}))
|
||||
|
||||
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 }) => (
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<PromptInput {...defaultProps} {...props} />
|
||||
</QueryClientProvider>
|
||||
)
|
||||
|
||||
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,
|
||||
|
||||
@@ -122,10 +122,6 @@ vi.mock('@/components/session/SessionSandboxMenu', () => ({
|
||||
SessionSandboxMenu: () => null,
|
||||
}))
|
||||
|
||||
vi.mock('@/components/ui/session-status-indicator', () => ({
|
||||
SessionStatusIndicator: () => <div>SessionStatus</div>,
|
||||
}))
|
||||
|
||||
vi.mock('./PromptSuggestions', () => ({
|
||||
PromptSuggestions: () => null,
|
||||
}))
|
||||
|
||||
@@ -89,10 +89,6 @@ vi.mock('@/hooks/useSessionPermissionMode', () => ({
|
||||
useSessionPermissionMode: () => ({ data: undefined }),
|
||||
}))
|
||||
|
||||
vi.mock('@/components/ui/session-status-indicator', () => ({
|
||||
SessionStatusIndicator: () => <div>SessionStatus</div>,
|
||||
}))
|
||||
|
||||
vi.mock('./PromptSuggestions', () => ({
|
||||
PromptSuggestions: (props: { isOpen: boolean; selectedIndex: number }) => {
|
||||
if (props.isOpen) {
|
||||
|
||||
@@ -121,10 +121,6 @@ vi.mock('@/hooks/useSessionPermissionMode', () => ({
|
||||
useSessionPermissionMode: () => ({ data: undefined }),
|
||||
}))
|
||||
|
||||
vi.mock('@/components/ui/session-status-indicator', () => ({
|
||||
SessionStatusIndicator: () => <div>SessionStatus</div>,
|
||||
}))
|
||||
|
||||
vi.mock('./PromptSuggestions', () => ({
|
||||
PromptSuggestions: () => null,
|
||||
}))
|
||||
|
||||
@@ -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 (
|
||||
<div className={`relative isolate border border-border dark:border-border/30 rounded-xl p-2 md:p-3 mb-4 md:mb-1 w-full before:pointer-events-none before:absolute before:-inset-px before:-z-10 before:rounded-xl before:bg-background/95 before:backdrop-blur-md before:content-[''] ${hasPendingPermissionForSession ? 'border-highlight/50 ring-1 ring-highlight/30' : composerModeStyle?.frame ?? ''} ${isTakeoverOpen ? 'z-[60]' : ''}`}>
|
||||
<div className={`relative isolate border border-border dark:border-border/30 rounded-xl p-2 md:p-3 mb-4 md:mb-3 w-full before:pointer-events-none before:absolute before:-inset-px before:-z-10 before:rounded-xl before:bg-background/95 before:backdrop-blur-md before:content-[''] ${hasPendingPermissionForSession ? 'border-highlight/50 ring-1 ring-highlight/30' : composerModeStyle?.frame ?? ''} ${isTakeoverOpen ? 'z-[60]' : ''}`}>
|
||||
<div role="status" aria-live="polite" className="sr-only">
|
||||
{sessionActivityAnnouncement}
|
||||
</div>
|
||||
<ComposerActivityBar sessionID={sessionID} />
|
||||
{composerModeStyle && (
|
||||
<span
|
||||
data-testid="composer-mode-badge"
|
||||
@@ -1559,11 +1560,6 @@ return (
|
||||
<ArrowDown className="w-4 h-4" />
|
||||
<span>Latest</span>
|
||||
</button>
|
||||
{(isSessionActive || hasBackgroundActivity) && (
|
||||
<div className="px-2.5 py-1.5 rounded-lg text-xs font-medium text-muted-foreground max-w-[120px]">
|
||||
<SessionStatusIndicator sessionID={sessionID} showLabel />
|
||||
</div>
|
||||
)}
|
||||
<ModelQuickSelect
|
||||
directory={directory}
|
||||
open={isModelPickerOpen}
|
||||
@@ -1593,18 +1589,13 @@ return (
|
||||
</IconToggleButton>
|
||||
</>
|
||||
) : null}
|
||||
{(isSessionActive || hasBackgroundActivity) && (
|
||||
<div className="px-2.5 py-1.5 md:px-3 md:py-2 rounded-lg text-xs md:text-sm font-medium text-muted-foreground max-w-[120px] md:max-w-[180px]">
|
||||
<SessionStatusIndicator sessionID={sessionID} showLabel />
|
||||
</div>
|
||||
)}
|
||||
<ModelQuickSelect
|
||||
directory={directory}
|
||||
open={isModelPickerOpen}
|
||||
onOpenChange={setIsModelPickerOpen}
|
||||
session={modelSelectionSession}
|
||||
>
|
||||
{!isSessionActive && !hideSecondaryButtons && (
|
||||
{!hideSecondaryButtons && (
|
||||
<button
|
||||
className="px-2.5 py-0.5 md:px-3 min-h-[44px] md:min-h-[36px] min-w-0 rounded-lg text-xs md:text-sm font-medium border bg-muted border-border text-muted-foreground hover:bg-muted-foreground/10 hover:border-foreground/30 transition-colors cursor-pointer flex-1 md:flex-initial md:w-auto md:max-w-[220px] dark:border-border/30 flex flex-col items-start justify-center overflow-hidden"
|
||||
>
|
||||
|
||||
Reference in new issue
Block a user