feat(sessions): move the session picker into the desktop right tool panel

Replace the tool rail's Activity tool with a Sessions tool that renders the
full session picker (Activity, This project and Projects tabs, linked-server
selector, add repository), shared with the mobile sheet via RouteSessionPicker.

- A docked panel stays open and follows navigation (picker navigation mode
  'panel'); the floating overlay closes on select (mode 'replace').
- The session page's sessions shortcut and /sessions open the panel; the
  collapsed sidebar opens it when a tool rail is mounted and falls back to
  the modal dialog otherwise.
- useToolPanelToggle is the single panel toggle for the rail, shortcuts and
  sidebar.
- Remove ActivityList, the fixed activity panel width and the window label.
This commit is contained in:
Chris Scott committed 2026-10-25 17:16:36 -04:00
1 parent 82c46bbdb2
commit d26ab578f0
25 files changed
+639 -695

No files matched your search

@@ -1,212 +0,0 @@
import { render, screen, fireEvent } from '@testing-library/react'
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { MemoryRouter } from 'react-router-dom'
import type { Repo, Session } from '@/api/types'
import type { ActiveWorkItem } from '@/lib/activeWork'
import { ActivityList } from './ActivityList'
const mocks = vi.hoisted(() => ({
useActiveWork: vi.fn(),
}))
vi.mock('@/hooks/useActiveWork', () => ({
useActiveWork: mocks.useActiveWork,
}))
const WINDOW_MINUTES = 30
const NOW = Date.now()
function createSession(id: string, title: string, updated = NOW - 60_000): Session {
return {
id,
projectID: 'proj-1',
title,
time: { created: updated - 10000, updated },
location: { directory: `/repos/${id}` },
cost: 0,
tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } },
}
}
function createRepo(id: number, name: string): Repo {
return {
id,
name,
fullPath: `/repos/${id}`,
localPath: `/repos/${id}`,
defaultBranch: 'main',
currentBranch: 'feature/x',
cloneStatus: 'ready',
clonedAt: 0,
}
}
function createItem(
overrides: Partial<ActiveWorkItem> & Pick<ActiveWorkItem, 'state' | 'session' | 'repo'>,
): ActiveWorkItem {
const repoId = overrides.repo?.id ?? 0
return {
key: `${repoId}:${overrides.session.id}`,
serverId: null,
serverName: null,
path: `/repos/${repoId}/sessions/${overrides.session.id}`,
updatedAt: overrides.session.time.updated,
...overrides,
}
}
function setGroups(groups: {
needsInput?: ActiveWorkItem[]
running?: ActiveWorkItem[]
recent?: ActiveWorkItem[]
}) {
mocks.useActiveWork.mockReturnValue({
groups: {
needsInput: groups.needsInput ?? [],
running: groups.running ?? [],
recent: groups.recent ?? [],
},
isLoading: false,
isError: false,
})
}
const renderList = (onNavigate = vi.fn(), path = '/', minutes = WINDOW_MINUTES) =>
render(
<MemoryRouter initialEntries={[path]}>
<ActivityList minutes={minutes} onNavigate={onNavigate} />
</MemoryRouter>,
)
describe('ActivityList', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('renders non-empty groups in needs-input, running, recent order', () => {
setGroups({
needsInput: [createItem({ state: 'needs-input', session: createSession('n1', 'Needs'), repo: createRepo(1, 'Alpha') })],
running: [createItem({ state: 'running', session: createSession('r1', 'Running'), repo: createRepo(2, 'Beta') })],
recent: [createItem({ state: 'recent', session: createSession('c1', 'Recent'), repo: createRepo(3, 'Gamma') })],
})
renderList()
const headings = screen.getAllByRole('heading').map((node) => node.textContent)
expect(headings).toEqual(['Needs input', 'Running', 'Recent'])
})
it('hides empty groups', () => {
setGroups({
running: [createItem({ state: 'running', session: createSession('r1', 'Running'), repo: createRepo(2, 'Beta') })],
})
renderList()
const headings = screen.getAllByRole('heading').map((node) => node.textContent)
expect(headings).toEqual(['Running'])
expect(screen.queryByText('Needs input')).not.toBeInTheDocument()
expect(screen.queryByText('Recent')).not.toBeInTheDocument()
})
it('renders the empty state with the window minutes', () => {
setGroups({})
renderList()
expect(screen.getByText('No active or recent sessions in the last 30 minutes')).toBeInTheDocument()
})
it('renders the empty state with an hour-scale window', () => {
setGroups({})
renderList(vi.fn(), '/', 1440)
expect(screen.getByText('No active or recent sessions in the last 24 hours')).toBeInTheDocument()
})
it('calls onNavigate with the item when a row is clicked', () => {
const onNavigate = vi.fn()
const item = createItem({ state: 'recent', session: createSession('c1', 'Recent'), repo: createRepo(3, 'Gamma') })
setGroups({ recent: [item] })
renderList(onNavigate)
fireEvent.click(screen.getByRole('button', { name: /Recent/ }))
expect(onNavigate).toHaveBeenCalledWith(item)
})
it('labels a worktree session with its worktree branch', () => {
setGroups({
recent: [
createItem({
state: 'recent',
session: createSession('c1', 'Worktree'),
repo: createRepo(3, 'Gamma'),
worktreeBranch: 'feature/wt',
}),
],
})
renderList()
expect(screen.getByRole('button', { name: /Worktree/ })).toHaveTextContent('Gamma · feature/wt')
})
it('marks the currently open session with aria-current', () => {
setGroups({
recent: [
createItem({ state: 'recent', session: createSession('open', 'Open session'), repo: createRepo(7, 'Gamma') }),
createItem({ state: 'recent', session: createSession('other', 'Other session'), repo: createRepo(7, 'Gamma') }),
],
})
renderList(vi.fn(), '/repos/7/sessions/open')
expect(screen.getByRole('button', { name: /Open session/ })).toHaveAttribute('aria-current', 'true')
expect(screen.getByRole('button', { name: /Other session/ })).not.toHaveAttribute('aria-current')
})
it('labels a remote row with its server name and marks it current on its server route', () => {
const item = createItem({
state: 'needs-input',
session: createSession('s1', 'Remote session'),
repo: null,
serverId: 'srv_kitchen',
serverName: 'Kitchen',
path: '/servers/srv_kitchen/sessions/s1',
})
setGroups({ needsInput: [item] })
renderList(vi.fn(), '/servers/srv_kitchen/sessions/s1')
const row = screen.getByRole('button', { name: /Remote session/ })
expect(row).toHaveTextContent('Kitchen')
expect(row).toHaveAttribute('aria-current', 'true')
})
it('shows a loading state', () => {
mocks.useActiveWork.mockReturnValue({
groups: { needsInput: [], running: [], recent: [] },
isLoading: true,
isError: false,
})
renderList()
expect(screen.getByText('Loading activity...')).toBeInTheDocument()
})
it('shows an error state', () => {
mocks.useActiveWork.mockReturnValue({
groups: { needsInput: [], running: [], recent: [] },
isLoading: false,
isError: true,
})
renderList()
expect(screen.getByText("Couldn't load activity.")).toBeInTheDocument()
})
})
@@ -1,175 +0,0 @@
import { useLocation } from 'react-router-dom'
import { CircleAlert, CircleCheck, CircleX } from 'lucide-react'
import { useActiveWork } from '@/hooks/useActiveWork'
import { SessionStatusIndicator } from '@/components/ui/session-status-indicator'
import { parseRepoRoute, parseServerSessionRoute } from '@/lib/navigation'
import { cn, formatShortRelativeTime, getRepoBranchLabel, getRepoDisplayName } from '@/lib/utils'
import {
ACTIVE_WORK_GROUPS,
MS_PER_MINUTE,
formatActivityEmptyMessage,
type ActiveWorkItem,
} from '@/lib/activeWork'
const UNTITLED_SESSION_TITLE = 'Untitled Session'
const FULL_ICON_CLASS = 'h-4 w-4'
interface ActivityListProps {
/** Activity window in minutes. */
minutes: number
/** Called when a row is chosen; the caller owns navigation so each surface can apply its own history and close rules. */
onNavigate: (item: ActiveWorkItem) => void
}
function isCurrentItem(
item: ActiveWorkItem,
sessionID: string | null,
repoID: number | null,
serverID: string | null,
) {
if (item.session.id !== sessionID) return false
if (item.serverId) return item.serverId === serverID
return item.repo?.id === repoID
}
/** The row's short label: the local repo's name or the owning linked server's name. */
function activityItemLabel(item: ActiveWorkItem): string {
return item.repo ? getRepoDisplayName(item.repo) : item.serverName ?? item.serverId ?? ''
}
/** The row's identifying line: a local repo with its branch, or the owning linked server's name. */
function activityItemLine(item: ActiveWorkItem): string {
if (!item.repo) return activityItemLabel(item)
const branch = item.worktreeBranch ?? getRepoBranchLabel(item.repo)
return branch ? `${getRepoDisplayName(item.repo)} · ${branch}` : getRepoDisplayName(item.repo)
}
function activityRowClass(isCurrent: boolean) {
return cn(
'flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors hover:bg-accent focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring',
isCurrent && 'bg-accent',
)
}
function ActivityStateIcon({ item, iconClassName }: { item: ActiveWorkItem; iconClassName: string }) {
if (item.state === 'needs-input') {
return <CircleAlert className={cn(iconClassName, 'text-warning')} aria-hidden="true" />
}
if (item.state === 'running') {
return <SessionStatusIndicator sessionID={item.session.id} />
}
if (item.outcome === 'failed') {
return <CircleX className={cn(iconClassName, 'text-destructive')} aria-hidden="true" />
}
if (item.outcome === 'succeeded') {
return <CircleCheck className={cn(iconClassName, 'text-success')} aria-hidden="true" />
}
return null
}
interface ActivityRowProps {
item: ActiveWorkItem
isCurrent: boolean
onSelect: (item: ActiveWorkItem) => void
}
function ActivityRow({ item, isCurrent, onSelect }: ActivityRowProps) {
return (
<button
type="button"
onClick={() => onSelect(item)}
aria-current={isCurrent ? 'true' : undefined}
className={activityRowClass(isCurrent)}
>
<span className="flex w-5 shrink-0 items-center justify-center">
<ActivityStateIcon item={item} iconClassName={FULL_ICON_CLASS} />
</span>
<span className="min-w-0 flex-1">
<span className="block truncate text-foreground">
{item.session.title || UNTITLED_SESSION_TITLE}
</span>
<span className="block truncate text-xs text-muted-foreground">{activityItemLine(item)}</span>
</span>
<span className="shrink-0 text-xs text-muted-foreground">
{formatShortRelativeTime(new Date(item.updatedAt))}
</span>
</button>
)
}
interface ActivityGroupProps {
heading: string
items: ActiveWorkItem[]
currentSessionID: string | null
currentRepoId: number | null
currentServerId: string | null
onSelect: (item: ActiveWorkItem) => void
}
function ActivityGroup({
heading,
items,
currentSessionID,
currentRepoId,
currentServerId,
onSelect,
}: ActivityGroupProps) {
if (items.length === 0) return null
return (
<div className="flex flex-col gap-0.5">
<h3 className="px-2 pt-2 pb-1 text-xs font-semibold text-muted-foreground">{heading}</h3>
{items.map((item) => (
<ActivityRow
key={item.key}
item={item}
isCurrent={isCurrentItem(item, currentSessionID, currentRepoId, currentServerId)}
onSelect={onSelect}
/>
))}
</div>
)
}
export function ActivityList({ minutes, onNavigate }: ActivityListProps) {
const location = useLocation()
const { groups, isLoading, isError } = useActiveWork(minutes * MS_PER_MINUTE)
const route = parseRepoRoute(location.pathname)
const serverRoute = parseServerSessionRoute(location.pathname)
const currentSessionID = route.sessionId ?? serverRoute?.sessionId ?? null
if (isLoading) {
return <p className="p-4 text-sm text-muted-foreground">Loading activity...</p>
}
if (isError) {
return <p className="p-4 text-sm text-destructive">Couldn&apos;t load activity.</p>
}
const isEmpty =
groups.needsInput.length === 0 && groups.running.length === 0 && groups.recent.length === 0
if (isEmpty) {
return (
<p className="p-4 text-sm text-muted-foreground">{formatActivityEmptyMessage(minutes)}</p>
)
}
return (
<section className="flex flex-col pb-2">
{ACTIVE_WORK_GROUPS.map((group) => (
<ActivityGroup
key={group.key}
heading={group.heading}
items={groups[group.key]}
currentSessionID={currentSessionID}
currentRepoId={route.repoId}
currentServerId={serverRoute?.serverId ?? null}
onSelect={onNavigate}
/>
))}
</section>
)
}