Show section activity in worktree sidebar (#3419)
* Show section activity in worktree sidebar * Tighten section activity badge placement * Unify section count status badge * Separate section total and running counts * Hide empty running section count
This commit is contained in:
@@ -166,6 +166,12 @@ import {
|
||||
} from '../../../../shared/worktree-ownership'
|
||||
import { RepoIconGlyph } from '@/components/repo/repo-icon'
|
||||
import { RepoBadgeMark } from '@/components/repo/RepoBadgeLabel'
|
||||
import {
|
||||
buildWorktreeSectionActivitySummaries,
|
||||
EMPTY_WORKTREE_SECTION_ACTIVITY,
|
||||
type WorktreeSectionActivityState,
|
||||
type WorktreeSectionActivitySummary
|
||||
} from './worktree-section-activity'
|
||||
|
||||
type ProjectGroupNameDialogState =
|
||||
| { type: 'create-from-repo'; repo: Repo }
|
||||
@@ -388,6 +394,8 @@ type VirtualizedWorktreeViewportProps = {
|
||||
dropIndex: number
|
||||
}) => void
|
||||
showInlineAgentCards: boolean
|
||||
showSectionStatus: boolean
|
||||
sectionActivityByGroupKey: ReadonlyMap<string, WorktreeSectionActivitySummary>
|
||||
// Why: broad grouping changes still remount the viewport, while add/delete
|
||||
// stays mounted for row-key anchoring and layout animation. These refs bridge
|
||||
// both paths so the virtualizer never falls back to scrollTop 0.
|
||||
@@ -397,6 +405,63 @@ type VirtualizedWorktreeViewportProps = {
|
||||
|
||||
type WorktreeItemRow = Extract<Row, { type: 'item' }>
|
||||
|
||||
function formatSectionActivityLabel(count: number, label: string): string {
|
||||
return `${count} ${label}${count === 1 ? '' : 's'}`
|
||||
}
|
||||
|
||||
function SectionMetricsBadge({
|
||||
count,
|
||||
summary,
|
||||
showStatus
|
||||
}: {
|
||||
count: number
|
||||
summary: WorktreeSectionActivitySummary
|
||||
showStatus: boolean
|
||||
}): React.JSX.Element {
|
||||
const runningCount = showStatus ? summary.runningCount : 0
|
||||
const hasRunning = runningCount > 0
|
||||
const totalLabel = formatSectionActivityLabel(count, 'workspace')
|
||||
const runningLabel = hasRunning
|
||||
? formatSectionActivityLabel(runningCount, 'running workspace')
|
||||
: 'no running workspaces'
|
||||
const badgeLabel = showStatus ? `${totalLabel}; ${runningLabel}` : totalLabel
|
||||
const totalTooltipLabel = showStatus && !hasRunning ? badgeLabel : totalLabel
|
||||
|
||||
return (
|
||||
<span
|
||||
className="inline-flex h-4 shrink-0 overflow-hidden rounded-full border border-sidebar-border bg-sidebar-accent text-[9px] font-medium leading-none text-muted-foreground/90"
|
||||
aria-label={badgeLabel}
|
||||
>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<span className="inline-flex h-full min-w-4 items-center justify-center px-1.5">
|
||||
{count}
|
||||
</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="bottom" sideOffset={6}>
|
||||
{totalTooltipLabel}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
{showStatus && hasRunning ? (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<span className="inline-flex h-full min-w-4 items-center justify-center gap-1 border-l border-sidebar-border/80 bg-amber-500/10 px-1.5 text-amber-700 dark:bg-amber-500/15 dark:text-amber-300">
|
||||
<span
|
||||
className="block size-1.5 rounded-full bg-amber-500 animate-pulse"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<span>{runningCount}</span>
|
||||
</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="bottom" sideOffset={6}>
|
||||
{runningLabel}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
) : null}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
type WorktreeRowDragState = {
|
||||
draggingWorktreeId: string | null
|
||||
sourceGroupKey: string | null
|
||||
@@ -639,6 +704,8 @@ const VirtualizedWorktreeViewport = React.memo(function VirtualizedWorktreeViewp
|
||||
shouldShowWorkspaceBoardDropIndicator,
|
||||
onReorderWorktrees,
|
||||
showInlineAgentCards,
|
||||
showSectionStatus,
|
||||
sectionActivityByGroupKey,
|
||||
scrollOffsetRef,
|
||||
scrollAnchorRef
|
||||
}: VirtualizedWorktreeViewportProps) {
|
||||
@@ -2317,6 +2384,9 @@ const VirtualizedWorktreeViewport = React.memo(function VirtualizedWorktreeViewp
|
||||
})
|
||||
: null
|
||||
const projectGroupDepth = row.projectGroupDepth ?? 0
|
||||
const isCollapsed = collapsedGroups.has(row.key)
|
||||
const sectionActivity =
|
||||
sectionActivityByGroupKey.get(row.key) ?? EMPTY_WORKTREE_SECTION_ACTIVITY
|
||||
return (
|
||||
<div
|
||||
key={vItem.key}
|
||||
@@ -2419,13 +2489,15 @@ const VirtualizedWorktreeViewport = React.memo(function VirtualizedWorktreeViewp
|
||||
) : null}
|
||||
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<div className="truncate text-[13px] font-semibold leading-none">
|
||||
<div className="flex min-w-0 items-center gap-1.5">
|
||||
<div className="min-w-0 truncate text-[13px] font-semibold leading-none">
|
||||
{row.label}
|
||||
</div>
|
||||
<div className="rounded-full bg-black/12 px-1.5 py-0.5 text-[9px] font-medium leading-none text-muted-foreground/90">
|
||||
{row.count}
|
||||
</div>
|
||||
<SectionMetricsBadge
|
||||
count={row.count}
|
||||
summary={sectionActivity}
|
||||
showStatus={showSectionStatus}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -2433,7 +2505,7 @@ const VirtualizedWorktreeViewport = React.memo(function VirtualizedWorktreeViewp
|
||||
<ChevronDown
|
||||
className={cn(
|
||||
'size-3.5 cursor-pointer transition-transform [&_path]:cursor-pointer',
|
||||
collapsedGroups.has(row.key) && '-rotate-90'
|
||||
isCollapsed && '-rotate-90'
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
@@ -3030,6 +3102,15 @@ const WorktreeList = React.memo(function WorktreeList({
|
||||
groupBy === 'pr-status' || cardProps.includes('pr') ? s.prCache : null
|
||||
)
|
||||
const settings = useAppStore((s) => s.settings)
|
||||
const sectionActivityTabsByWorktree = useAppStore((s) => s.tabsByWorktree)
|
||||
const sectionActivityBrowserTabsByWorktree = useAppStore((s) => s.browserTabsByWorktree)
|
||||
const sectionActivityPtyIdsByTabId = useAppStore((s) => s.ptyIdsByTabId)
|
||||
const sectionActivityRuntimePaneTitlesByTabId = useAppStore((s) => s.runtimePaneTitlesByTabId)
|
||||
const sectionActivityAgentStatusEpoch = useAppStore((s) => s.agentStatusEpoch)
|
||||
const sectionActivityMigrationUnsupportedByPtyId = useAppStore(
|
||||
(s) => s.migrationUnsupportedByPtyId
|
||||
)
|
||||
const sectionActivityRetainedAgentsByPaneKey = useAppStore((s) => s.retainedAgentsByPaneKey)
|
||||
|
||||
const sortEpoch = useAppStore((s) => s.sortEpoch)
|
||||
|
||||
@@ -3326,6 +3407,57 @@ const WorktreeList = React.memo(function WorktreeList({
|
||||
const allRepoIds = useMemo(() => repos.map((r) => r.id), [repos])
|
||||
const reorderReposAction = useAppStore((s) => s.reorderRepos)
|
||||
const projectGroupOrdering = getProjectGroupOrdering(groupBy, sortBy)
|
||||
const showSectionStatus = cardProps.includes('status')
|
||||
const sectionActivityState: WorktreeSectionActivityState = useMemo(() => {
|
||||
const current = useAppStore.getState()
|
||||
return {
|
||||
tabsByWorktree: sectionActivityTabsByWorktree,
|
||||
browserTabsByWorktree: sectionActivityBrowserTabsByWorktree,
|
||||
ptyIdsByTabId: sectionActivityPtyIdsByTabId,
|
||||
runtimePaneTitlesByTabId: sectionActivityRuntimePaneTitlesByTabId,
|
||||
agentStatusEpoch: sectionActivityAgentStatusEpoch,
|
||||
// Why: agentStatusByPaneKey can tick for same-state tool details. The
|
||||
// section counts only need structural status transitions, tracked by
|
||||
// agentStatusEpoch, so read the current map without subscribing to it.
|
||||
agentStatusByPaneKey: current.agentStatusByPaneKey,
|
||||
migrationUnsupportedByPtyId: sectionActivityMigrationUnsupportedByPtyId,
|
||||
retainedAgentsByPaneKey: sectionActivityRetainedAgentsByPaneKey
|
||||
}
|
||||
}, [
|
||||
sectionActivityAgentStatusEpoch,
|
||||
sectionActivityBrowserTabsByWorktree,
|
||||
sectionActivityMigrationUnsupportedByPtyId,
|
||||
sectionActivityPtyIdsByTabId,
|
||||
sectionActivityRetainedAgentsByPaneKey,
|
||||
sectionActivityRuntimePaneTitlesByTabId,
|
||||
sectionActivityTabsByWorktree
|
||||
])
|
||||
const sectionActivityByGroupKey = useMemo(
|
||||
() =>
|
||||
showSectionStatus
|
||||
? buildWorktreeSectionActivitySummaries({
|
||||
groupBy,
|
||||
worktrees,
|
||||
repoMap,
|
||||
prCache,
|
||||
workspaceStatuses,
|
||||
projectGroups,
|
||||
settings,
|
||||
state: sectionActivityState
|
||||
})
|
||||
: new Map<string, WorktreeSectionActivitySummary>(),
|
||||
[
|
||||
groupBy,
|
||||
prCache,
|
||||
projectGroups,
|
||||
repoMap,
|
||||
sectionActivityState,
|
||||
settings,
|
||||
showSectionStatus,
|
||||
workspaceStatuses,
|
||||
worktrees
|
||||
]
|
||||
)
|
||||
|
||||
// Build flat row list for rendering
|
||||
const rows: Row[] = useMemo(
|
||||
@@ -3870,6 +4002,8 @@ const WorktreeList = React.memo(function WorktreeList({
|
||||
shouldShowWorkspaceBoardDropIndicator={shouldShowWorkspaceBoardDropIndicator}
|
||||
onReorderWorktrees={reorderWorktrees}
|
||||
showInlineAgentCards={cardProps.includes('inline-agents')}
|
||||
showSectionStatus={showSectionStatus}
|
||||
sectionActivityByGroupKey={sectionActivityByGroupKey}
|
||||
scrollOffsetRef={scrollOffsetRef}
|
||||
scrollAnchorRef={scrollAnchorRef}
|
||||
/>
|
||||
|
||||
@@ -0,0 +1,192 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import type { AgentStatusEntry } from '../../../../shared/agent-status-types'
|
||||
import type { ProjectGroup, Repo, TerminalTab, Worktree } from '../../../../shared/types'
|
||||
import {
|
||||
getProjectGroupHeaderKey,
|
||||
PINNED_GROUP_KEY,
|
||||
type WorktreeGroupBy
|
||||
} from './worktree-list-groups'
|
||||
import {
|
||||
buildWorktreeSectionActivitySummaries,
|
||||
type WorktreeSectionActivityState
|
||||
} from './worktree-section-activity'
|
||||
|
||||
function makeRepo(overrides: Partial<Repo> = {}): Repo {
|
||||
return {
|
||||
id: 'repo-1',
|
||||
path: '/tmp/repo-1',
|
||||
displayName: 'repo',
|
||||
badgeColor: '#000000',
|
||||
addedAt: 0,
|
||||
...overrides
|
||||
}
|
||||
}
|
||||
|
||||
function makeProjectGroup(overrides: Partial<ProjectGroup>): ProjectGroup {
|
||||
return {
|
||||
id: 'group-1',
|
||||
name: 'Group',
|
||||
parentPath: null,
|
||||
parentGroupId: null,
|
||||
createdFrom: 'manual',
|
||||
tabOrder: 0,
|
||||
isCollapsed: false,
|
||||
color: null,
|
||||
createdAt: 0,
|
||||
updatedAt: 0,
|
||||
...overrides
|
||||
}
|
||||
}
|
||||
|
||||
function makeWorktree(overrides: Partial<Worktree> = {}): Worktree {
|
||||
return {
|
||||
id: 'wt-1',
|
||||
repoId: 'repo-1',
|
||||
path: '/tmp/repo-1-feature',
|
||||
branch: 'refs/heads/feature',
|
||||
head: 'abc123',
|
||||
isBare: false,
|
||||
isMainWorktree: false,
|
||||
linkedIssue: null,
|
||||
linkedPR: null,
|
||||
linkedLinearIssue: null,
|
||||
isArchived: false,
|
||||
isUnread: false,
|
||||
isPinned: false,
|
||||
comment: '',
|
||||
displayName: 'feature',
|
||||
sortOrder: 0,
|
||||
lastActivityAt: 0,
|
||||
...overrides
|
||||
}
|
||||
}
|
||||
|
||||
function makeTerminalTab(overrides: Partial<TerminalTab> = {}): TerminalTab {
|
||||
return {
|
||||
id: 'tab-1',
|
||||
ptyId: null,
|
||||
worktreeId: 'wt-1',
|
||||
title: 'zsh',
|
||||
customTitle: null,
|
||||
color: null,
|
||||
sortOrder: 0,
|
||||
createdAt: 0,
|
||||
...overrides
|
||||
}
|
||||
}
|
||||
|
||||
function makeState(
|
||||
overrides: Partial<WorktreeSectionActivityState> = {}
|
||||
): WorktreeSectionActivityState {
|
||||
return {
|
||||
tabsByWorktree: {},
|
||||
browserTabsByWorktree: {},
|
||||
ptyIdsByTabId: {},
|
||||
runtimePaneTitlesByTabId: {},
|
||||
agentStatusEpoch: 0,
|
||||
agentStatusByPaneKey: {},
|
||||
migrationUnsupportedByPtyId: {},
|
||||
retainedAgentsByPaneKey: {},
|
||||
...overrides
|
||||
}
|
||||
}
|
||||
|
||||
function buildSummaries({
|
||||
groupBy = 'repo',
|
||||
worktrees,
|
||||
repos,
|
||||
projectGroups = [],
|
||||
state
|
||||
}: {
|
||||
groupBy?: WorktreeGroupBy
|
||||
worktrees: readonly Worktree[]
|
||||
repos: readonly Repo[]
|
||||
projectGroups?: readonly ProjectGroup[]
|
||||
state: WorktreeSectionActivityState
|
||||
}) {
|
||||
return buildWorktreeSectionActivitySummaries({
|
||||
groupBy,
|
||||
worktrees,
|
||||
repoMap: new Map(repos.map((repo) => [repo.id, repo])),
|
||||
prCache: null,
|
||||
workspaceStatuses: [],
|
||||
projectGroups,
|
||||
state
|
||||
})
|
||||
}
|
||||
|
||||
describe('buildWorktreeSectionActivitySummaries', () => {
|
||||
it('counts running worktrees across repo project-group ancestors', () => {
|
||||
const parent = makeProjectGroup({ id: 'parent', name: 'Parent' })
|
||||
const child = makeProjectGroup({
|
||||
id: 'child',
|
||||
name: 'Child',
|
||||
parentGroupId: parent.id
|
||||
})
|
||||
const repo = makeRepo({ projectGroupId: child.id })
|
||||
const worktree = makeWorktree({ repoId: repo.id })
|
||||
const state = makeState({
|
||||
tabsByWorktree: {
|
||||
[worktree.id]: [
|
||||
makeTerminalTab({ id: 'tab-1', worktreeId: worktree.id, title: 'Codex working' })
|
||||
]
|
||||
},
|
||||
ptyIdsByTabId: {
|
||||
'tab-1': ['pty-1']
|
||||
}
|
||||
})
|
||||
|
||||
const summaries = buildSummaries({
|
||||
worktrees: [worktree],
|
||||
repos: [repo],
|
||||
projectGroups: [parent, child],
|
||||
state
|
||||
})
|
||||
|
||||
expect(summaries.get(getProjectGroupHeaderKey(parent.id))).toEqual({
|
||||
runningCount: 1
|
||||
})
|
||||
expect(summaries.get(getProjectGroupHeaderKey(child.id))).toEqual({
|
||||
runningCount: 1
|
||||
})
|
||||
expect(summaries.get(`repo:${repo.id}`)).toEqual({
|
||||
runningCount: 1
|
||||
})
|
||||
})
|
||||
|
||||
it('keeps pinned workspace activity on the pinned header only', () => {
|
||||
const repo = makeRepo({ projectGroupId: 'group-1' })
|
||||
const worktree = makeWorktree({ repoId: repo.id, isPinned: true })
|
||||
const now = Date.now()
|
||||
const entry: AgentStatusEntry = {
|
||||
state: 'working',
|
||||
prompt: '',
|
||||
updatedAt: now,
|
||||
stateStartedAt: now,
|
||||
paneKey: 'tab-1:leaf-1',
|
||||
stateHistory: []
|
||||
}
|
||||
const state = makeState({
|
||||
tabsByWorktree: {
|
||||
[worktree.id]: [makeTerminalTab({ id: 'tab-1', worktreeId: worktree.id })]
|
||||
},
|
||||
agentStatusEpoch: 1,
|
||||
agentStatusByPaneKey: {
|
||||
[entry.paneKey]: entry
|
||||
}
|
||||
})
|
||||
|
||||
const summaries = buildSummaries({
|
||||
worktrees: [worktree],
|
||||
repos: [repo],
|
||||
projectGroups: [makeProjectGroup({ id: 'group-1' })],
|
||||
state
|
||||
})
|
||||
|
||||
expect(summaries.get(PINNED_GROUP_KEY)).toEqual({
|
||||
runningCount: 1
|
||||
})
|
||||
expect(summaries.get(`repo:${repo.id}`)).toBeUndefined()
|
||||
expect(summaries.get(getProjectGroupHeaderKey('group-1'))).toBeUndefined()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,108 @@
|
||||
import type { AppState } from '@/store/types'
|
||||
import { resolveWorktreeStatus } from '@/lib/worktree-status'
|
||||
import type {
|
||||
ProjectGroup,
|
||||
Repo,
|
||||
Worktree,
|
||||
WorkspaceStatusDefinition
|
||||
} from '../../../../shared/types'
|
||||
import {
|
||||
getGroupKeysForWorktree,
|
||||
type WorktreeGroupBy,
|
||||
PINNED_GROUP_KEY
|
||||
} from './worktree-list-groups'
|
||||
import {
|
||||
selectLivePtyIdsForWorktree,
|
||||
selectRuntimePaneTitlesForWorktree
|
||||
} from './worktree-card-status-inputs'
|
||||
import { selectWorktreeAgentActivitySummary } from './worktree-agent-activity-summary'
|
||||
|
||||
export type WorktreeSectionActivityState = Pick<
|
||||
AppState,
|
||||
| 'tabsByWorktree'
|
||||
| 'browserTabsByWorktree'
|
||||
| 'ptyIdsByTabId'
|
||||
| 'runtimePaneTitlesByTabId'
|
||||
| 'agentStatusEpoch'
|
||||
| 'agentStatusByPaneKey'
|
||||
| 'migrationUnsupportedByPtyId'
|
||||
| 'retainedAgentsByPaneKey'
|
||||
>
|
||||
|
||||
export type WorktreeSectionActivitySummary = {
|
||||
runningCount: number
|
||||
}
|
||||
|
||||
export const EMPTY_WORKTREE_SECTION_ACTIVITY: WorktreeSectionActivitySummary = {
|
||||
runningCount: 0
|
||||
}
|
||||
|
||||
export function buildWorktreeSectionActivitySummaries({
|
||||
groupBy,
|
||||
worktrees,
|
||||
repoMap,
|
||||
prCache,
|
||||
workspaceStatuses,
|
||||
settings,
|
||||
projectGroups,
|
||||
state
|
||||
}: {
|
||||
groupBy: WorktreeGroupBy
|
||||
worktrees: readonly Worktree[]
|
||||
repoMap: Map<string, Repo>
|
||||
prCache: Record<string, unknown> | null
|
||||
workspaceStatuses: readonly WorkspaceStatusDefinition[]
|
||||
settings?: AppState['settings']
|
||||
projectGroups: readonly ProjectGroup[]
|
||||
state: WorktreeSectionActivityState
|
||||
}): Map<string, WorktreeSectionActivitySummary> {
|
||||
const summaries = new Map<string, WorktreeSectionActivitySummary>()
|
||||
|
||||
for (const worktree of worktrees) {
|
||||
const groupKeys = worktree.isPinned
|
||||
? [PINNED_GROUP_KEY]
|
||||
: getGroupKeysForWorktree(
|
||||
groupBy,
|
||||
worktree,
|
||||
repoMap,
|
||||
prCache,
|
||||
workspaceStatuses,
|
||||
settings,
|
||||
projectGroups
|
||||
)
|
||||
if (groupKeys.length === 0) {
|
||||
continue
|
||||
}
|
||||
|
||||
const status = getSectionWorktreeStatus(state, worktree.id)
|
||||
for (const groupKey of groupKeys) {
|
||||
const summary = summaries.get(groupKey) ?? { ...EMPTY_WORKTREE_SECTION_ACTIVITY }
|
||||
if (status === 'working') {
|
||||
summary.runningCount++
|
||||
}
|
||||
summaries.set(groupKey, summary)
|
||||
}
|
||||
}
|
||||
|
||||
return summaries
|
||||
}
|
||||
|
||||
function getSectionWorktreeStatus(
|
||||
state: WorktreeSectionActivityState,
|
||||
worktreeId: string
|
||||
): ReturnType<typeof resolveWorktreeStatus> {
|
||||
const agentSummary = selectWorktreeAgentActivitySummary(state, worktreeId)
|
||||
|
||||
// Why: collapsed headers must mirror the card dot semantics exactly; otherwise
|
||||
// a hidden section can advertise different activity than its visible cards.
|
||||
return resolveWorktreeStatus({
|
||||
tabs: state.tabsByWorktree[worktreeId] ?? [],
|
||||
browserTabs: state.browserTabsByWorktree[worktreeId] ?? [],
|
||||
ptyIdsByTabId: selectLivePtyIdsForWorktree(state, worktreeId),
|
||||
runtimePaneTitlesByTabId: selectRuntimePaneTitlesForWorktree(state, worktreeId),
|
||||
hasPermission: agentSummary.hasPermission,
|
||||
hasLiveWorking: agentSummary.hasLiveWorking,
|
||||
hasLiveDone: agentSummary.hasLiveDone,
|
||||
hasRetainedDone: agentSummary.hasRetainedDone
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user