fix(activity): surface worktree sessions in active work, the sidebar and repo badges

- Resolve sessions in repo worktrees to the owning repo in the activity list; show the worktree branch and open the Workspaces tab
- Look up worktrees only for unmatched sessions in the window or under an active root, and hold the loading state until it settles
- Show schedule-worktree sessions only while running or needing input
- Light repo badges for worktree sessions through one app-wide worktree lookup
- List worktree sessions under the expanded repo in the sidebar
- Subscribe the event stream to active session directories so worktree permissions and forms arrive
- Keep the worktree tab when navigating from the desktop Activity panel
- Remove the braille spinner's always-dim bottom row
This commit is contained in:
Chris Scott committed 2026-10-16 20:36:56 +00:00
1 parent 1d31286904
commit bfbbbf08ef
23 files changed
+932 -81

No files matched your search

@@ -144,6 +144,23 @@ describe('ActivityList', () => {
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: [
@@ -63,7 +63,7 @@ interface ActivityRowProps {
}
function ActivityRow({ item, isCurrent, onSelect }: ActivityRowProps) {
const branch = getRepoBranchLabel(item.repo)
const branch = item.worktreeBranch ?? getRepoBranchLabel(item.repo)
const repoLine = branch
? `${getRepoDisplayName(item.repo)} · ${branch}`
: getRepoDisplayName(item.repo)
@@ -25,6 +25,7 @@ type SessionPinFixture = { sessionId: string; directory: string; pinnedAt: numbe
const {
listReposMock,
getRepoSiblingsMock,
sessionsData,
sessionsHookCalls,
createSessionCalls,
@@ -37,6 +38,7 @@ const {
searchError,
} = vi.hoisted(() => ({
listReposMock: vi.fn(),
getRepoSiblingsMock: vi.fn(),
sessionsData: [] as SessionFixture[],
sessionsHookCalls: [] as SessionsHookCall[],
createSessionCalls: [] as Array<{ directory?: string; vars?: unknown }>,
@@ -51,7 +53,7 @@ const {
vi.mock('@/api/repos', async (importOriginal) => {
const actual = await importOriginal<typeof import('@/api/repos')>()
return { ...actual, listRepos: listReposMock }
return { ...actual, listRepos: listReposMock, getRepoSiblings: getRepoSiblingsMock }
})
vi.mock('@/api/opencode', async (importOriginal) => {
@@ -156,6 +158,8 @@ describe('DesktopSessionTree', () => {
beforeEach(() => {
listReposMock.mockReset()
listReposMock.mockResolvedValue([repoA, repoB, repoC])
getRepoSiblingsMock.mockReset()
getRepoSiblingsMock.mockResolvedValue([])
sessionsData.splice(
0,
sessionsData.length,
@@ -197,6 +201,18 @@ describe('DesktopSessionTree', () => {
expect(fetchedDirectories()).toEqual(new Set(['/repos/a']))
})
it('shows a worktree session under its repo with the worktree branch tag', async () => {
getRepoSiblingsMock.mockResolvedValue([
{ fullPath: '/repos/a/.worktrees/feat', currentBranch: 'feat/x', worktreeSource: 'git' },
])
sessionsData.push(createSession('w1', '/repos/a/.worktrees/feat', Date.now() - 1000))
render(<DesktopSessionTree />, { wrapper: createWrapper(['/repos/1']) })
const row = await screen.findByRole('button', { name: /^Session w1/ })
expect(row).toHaveTextContent('feat/x')
})
it('opens nothing outside a repo', async () => {
render(<DesktopSessionTree />, { wrapper: createWrapper(['/']) })
@@ -3,7 +3,7 @@ import { beforeEach, describe, it, expect, vi } from 'vitest'
import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { RepoQuickSwitchSheet } from './RepoQuickSwitchSheet'
import { listRepos } from '@/api/repos'
import { getRepoSiblings, listRepos } from '@/api/repos'
import { useMobileTabBar } from '@/hooks/useMobileTabBar'
import { ASSISTANT_REPO_ID } from '@opencode-manager/shared/utils'
import type { ActiveWorkItem } from '@/lib/activeWork'
@@ -167,6 +167,7 @@ function MobileSheetHarness() {
describe('RepoQuickSwitchSheet', () => {
beforeEach(() => {
vi.clearAllMocks()
vi.mocked(getRepoSiblings).mockResolvedValue([])
sessionsData.splice(0, sessionsData.length)
sessionsHookCalls.splice(0, sessionsHookCalls.length)
permissionSessions.current.clear()
@@ -5,7 +5,9 @@ import { SessionStatusIndicator } from '@/components/ui/session-status-indicator
import { RepoActivityIndicator } from '@/components/activity/RepoActivityIndicator'
import { useForms, usePermissions } from '@/contexts/EventContext'
import { useCreateSession } from '@/hooks/useOpenCode'
import { useRepoSiblings } from '@/hooks/useRepoSiblings'
import { useSidebarRepoGroups } from '@/hooks/useSidebarRepoGroups'
import { buildWorktreeActivity, type ActiveWorktree } from '@/lib/activeWork'
import { cn, formatShortRelativeTime, getRepoBranchLabel, getRepoDisplayName } from '@/lib/utils'
import { getRepoPath, getSessionPath } from '@/lib/navigation'
import {
@@ -118,13 +120,14 @@ interface SessionNavRowProps {
export function SessionNavRow({ item, isCurrent, onSelect, repoLabel }: SessionNavRowProps) {
const { hasForSession: hasPermission } = usePermissions()
const { hasForSession: hasForm } = useForms()
const branchLabel = item.worktreeBranch ?? item.branchLabel
return (
<button
type="button"
onClick={() => onSelect(item.path)}
aria-current={isCurrent ? 'page' : undefined}
title={item.branchLabel ? `${item.repoLabel} · ${item.branchLabel}` : item.repoLabel}
title={branchLabel ? `${item.repoLabel} · ${branchLabel}` : item.repoLabel}
className={cn(
'flex h-9 w-full items-center gap-2 pl-4 pr-3.5 text-left text-[13.5px] text-foreground hover:bg-accent/50',
isCurrent && 'bg-primary/25 font-semibold',
@@ -137,6 +140,11 @@ export function SessionNavRow({ item, isCurrent, onSelect, repoLabel }: SessionN
{repoLabel && (
<span className="max-w-24 shrink-0 truncate text-xs text-highlight">{repoLabel}</span>
)}
{item.worktreeBranch && (
<span className="max-w-24 shrink-0 truncate font-mono text-[11px] text-primary">
{item.worktreeBranch}
</span>
)}
<SessionStatusIndicator sessionID={item.session.id} size="sm" />
{hasPermission(item.session.id) && (
<Bell className="h-3 w-3 shrink-0 text-highlight" aria-label="Pending permission" />
@@ -186,9 +194,32 @@ interface RepoSessionListProps {
}
function RepoSessionList({ repo, onSelectSession }: RepoSessionListProps) {
const siblings = useRepoSiblings(repo.isWorktree ? undefined : repo.id)
const worktrees = useMemo(
() =>
repo.isWorktree
? undefined
: buildWorktreeActivity([repo], [{ data: siblings.data }]).filter(
(worktree) => !worktree.isSchedule,
),
[repo, siblings.data],
)
if (siblings.isLoading) return <SessionNavStatus>Loading sessions...</SessionNavStatus>
return <RepoSessionListItems repo={repo} worktrees={worktrees} onSelectSession={onSelectSession} />
}
interface RepoSessionListItemsProps {
repo: Repo
worktrees?: ActiveWorktree[]
onSelectSession: (path: string) => void
}
function RepoSessionListItems({ repo, worktrees, onSelectSession }: RepoSessionListItemsProps) {
const location = useLocation()
const repos = useMemo(() => [repo], [repo])
const { groups, isLoading, isError, hasMore } = useSidebarRepoGroups({ repos })
const { groups, isLoading, isError, hasMore } = useSidebarRepoGroups({ repos, worktrees })
const items = groups[0]?.items ?? []
if (isLoading) return <SessionNavStatus>Loading sessions...</SessionNavStatus>
@@ -355,6 +355,24 @@ describe('ToolSidePanel', () => {
expect(search().get('panel')).toBe('activity')
})
it('keeps a worktree session tab when navigating from the Activity panel', async () => {
const user = userEvent.setup()
setActivityGroups([
{
...createActivityItem('wt', 'Worktree Session', 2, 'Beta'),
path: '/repos/2/sessions/wt?repoTab=workspaces',
},
])
renderAt('')
await user.click(screen.getByRole('button', { name: 'Activity' }))
await user.click(await screen.findByRole('button', { name: /Worktree Session/ }))
await waitFor(() => expect(screen.getByTestId('pathname').textContent).toBe('/repos/2/sessions/wt'))
expect(search().get('repoTab')).toBe('workspaces')
expect(search().get('panel')).toBe('activity')
})
it('shows an Activity count pill and extends the accessible name', () => {
activityMocks.useActiveWorkCounts.mockReturnValue({ needsInput: 1, running: 2 })
renderAt('')
@@ -25,6 +25,7 @@ import { isPanelTool, type ToolPanelState, type PanelTool } from '@/hooks/useToo
import { useOpenNavItem } from '@/hooks/useOpenNavItem'
import { ActivityList } from '@/components/activity/ActivityList'
import { ActivityCountPill } from '@/components/activity/ActivityCountPill'
import { withQueryParam } from '@/lib/navigation'
import { useActiveWorkCounts, useActivityWindowMinutes } from '@/hooks/useActiveWork'
import { formatActivityWindow } from '@/lib/activeWork'
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
@@ -52,7 +53,7 @@ function ActivityPanelBody() {
<div className="min-h-0 flex-1 overflow-y-auto">
<ActivityList
minutes={minutes}
onNavigate={(item) => navigate({ pathname: item.path, search: '?panel=activity' })}
onNavigate={(item) => navigate(withQueryParam(item.path, 'panel', 'activity'))}
/>
</div>
)
@@ -191,6 +191,60 @@ describe('buildSidebarRepoGroups', () => {
expect(item.path).toBe('/repos/3/sessions/w1')
})
it('groups a session in a worktree of a repo under that repo with the worktree branch', () => {
const worktree = {
directory: '/repos/a/.worktrees/feat',
ownerRepo: repoA,
branch: 'feat/x',
isSchedule: false,
}
const sessions = [createSession('w1', atStartOfDay(2000), '/repos/a/.worktrees/feat')]
const groups = buildSidebarRepoGroups({
repos: [repoA],
sessions,
pinnedKeys: new Set(),
now: NOW,
worktrees: [worktree],
})
expect(groups).toHaveLength(1)
const item = groups[0].items[0]
expect(item.session.id).toBe('w1')
expect(item.repoId).toBe(1)
expect(item.worktreeBranch).toBe('feat/x')
expect(item.path).toBe('/repos/1/sessions/w1?repoTab=workspaces')
})
it('matches a worktree session directory with a trailing slash', () => {
const worktree = {
directory: '/repos/a/.worktrees/feat',
ownerRepo: repoA,
branch: 'feat/x',
isSchedule: false,
}
const sessions = [createSession('w1', atStartOfDay(2000), '/repos/a/.worktrees/feat/')]
const groups = buildSidebarRepoGroups({
repos: [repoA],
sessions,
pinnedKeys: new Set(),
now: NOW,
worktrees: [worktree],
})
expect(groups[0].items.map((item) => item.session.id)).toEqual(['w1'])
expect(groups[0].items[0].worktreeBranch).toBe('feat/x')
})
it('excludes a worktree session when no worktrees are provided', () => {
const sessions = [createSession('w1', atStartOfDay(2000), '/repos/a/.worktrees/feat')]
const groups = buildSidebarRepoGroups({ repos: [repoA], sessions, pinnedKeys: new Set(), now: NOW })
expect(groups[0].items).toEqual([])
})
it('labels assistant sessions and links them in assistant mode', () => {
const assistant = createRepo({ id: 0, fullPath: '/assistant', localPath: 'assistant' })
const sessions = [createSession('s1', atStartOfDay(1000), '/assistant')]
@@ -4,6 +4,7 @@ import { getRepoBranchLabel, getRepoDisplayName } from '@/lib/utils'
import { getSessionKey } from '@/lib/sessionKey'
import { getSessionPath, isAssistantPath, parseRepoRoute } from '@/lib/navigation'
import { partitionSessions, selectRootSessions } from '@/components/session/session-partition'
import type { ActiveWorktree } from '@/lib/activeWork'
export const SIDEBAR_SESSIONS_PER_REPO = 10
@@ -30,6 +31,8 @@ export interface SidebarSessionItem {
repoId: number
repoLabel: string
branchLabel: string | null
/** Branch of the worktree the session runs in, when it runs in a worktree of the group's repo. */
worktreeBranch?: string | null
isWorktree: boolean
isPinned: boolean
path: string
@@ -88,16 +91,33 @@ export function buildSidebarRepoGroups(input: {
sessions: Session[]
pinnedKeys: ReadonlySet<string>
now: number
worktrees?: ReadonlyArray<ActiveWorktree>
}): SidebarRepoGroup[] {
const { repos, sessions, pinnedKeys, now } = input
const { repos, sessions, pinnedKeys, now, worktrees } = input
const keyFn = getSessionKey
const repoByDirectory = buildRepoByDirectory(repos)
const roots = selectRootSessions(sessions, {
directories: new Set(repos.map((repo) => repo.fullPath)),
keyFn,
}).flatMap((session) => {
const worktreeByDirectory = new Map<string, ActiveWorktree>()
for (const worktree of worktrees ?? []) {
worktreeByDirectory.set(worktree.directory, worktree)
}
const directories = new Set(repos.map((repo) => repo.fullPath))
for (const worktree of worktrees ?? []) {
directories.add(worktree.directory)
}
for (const session of sessions) {
const directory = normalizeDirectory(session.location.directory)
if (directory && worktreeByDirectory.has(directory)) {
directories.add(session.location.directory)
}
}
const roots = selectRootSessions(sessions, { directories, keyFn }).flatMap((session) => {
if (session.time.archived) return []
const directory = normalizeDirectory(session.location.directory)
const worktree = directory ? worktreeByDirectory.get(directory) : undefined
if (worktree) return [{ session, repo: worktree.ownerRepo }]
const repo = repoByDirectory.get(session.location.directory)
if (!repo) return []
return [{ session, repo }]
@@ -115,15 +135,20 @@ export function buildSidebarRepoGroups(input: {
const createItem = (session: Session, repo: Repo): SidebarSessionItem => {
const key = keyFn(session)
const directory = normalizeDirectory(session.location.directory)
const worktree = directory ? worktreeByDirectory.get(directory) : undefined
return {
key,
session,
repoId: repo.id,
repoLabel: getRepoDisplayName(repo),
branchLabel: getRepoBranchLabel(repo),
worktreeBranch: worktree ? worktree.branch : null,
isWorktree: Boolean(repo.isWorktree),
isPinned: pinnedKeys.has(key),
path: getSessionPath(repo.id, session.id),
path: worktree
? getSessionPath(repo.id, session.id, { repoTab: 'workspaces' })
: getSessionPath(repo.id, session.id),
}
}
@@ -16,11 +16,11 @@ const litIndexesFor = (frame: string) =>
describe('brailleDots', () => {
it('lights dots 1, 2 and 4 for the first frame', () => {
expect(brailleDots('⠋')).toEqual([true, true, false, true, false, false, false, false])
expect(brailleDots('⠋')).toEqual([true, true, false, true, false, false])
})
it('lights dots 1 through 4 for the last frame', () => {
expect(brailleDots('⠏')).toEqual([true, true, true, true, false, false, false, false])
expect(brailleDots('⠏')).toEqual([true, true, true, true, false, false])
})
})
@@ -30,10 +30,10 @@ describe('ActivitySpinner', () => {
vi.useRealTimers()
})
it('renders eight dots with the first frame lit and hidden from assistive technology', () => {
it('renders six dots with the first frame lit and hidden from assistive technology', () => {
const { container } = render(<ActivitySpinner />)
expect(circles(container)).toHaveLength(8)
expect(circles(container)).toHaveLength(6)
expect(litIndexes(container)).toEqual(litIndexesFor(SPINNER_FRAMES[0]))
expect(container.querySelector('svg')).toHaveAttribute('aria-hidden', 'true')
})
@@ -79,7 +79,7 @@ describe('ActivitySpinner', () => {
r: Number(circle.getAttribute('r')),
}))
expect(dots).toHaveLength(8)
expect(dots).toHaveLength(6)
for (const dot of dots) {
expect(dot.cx - dot.r).toBeGreaterThan(0)
@@ -13,19 +13,17 @@ const DOT_GRID: ReadonlyArray<readonly [number, number]> = [
[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 ROW_Y = [4.25, 8, 11.75] 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:
* Decodes one braille frame into its six 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.
* top-to-bottom.
*/
export function brailleDots(frame: string): boolean[] {
const bits = (frame.codePointAt(0) ?? BRAILLE_BASE) - BRAILLE_BASE