Avoid duplicate unread dots on workspace cards (#42810)

* Avoid duplicate unread dots on workspace cards

* Skip unread agent counting for read workspaces
This commit is contained in:
Jinjing
2026-11-15 18:09:50 -08:00
committed by GitHub
parent bf0af4d026
commit 11cfa85f63
8 changed files with 143 additions and 32 deletions
@@ -59,6 +59,8 @@ type Props = {
progress?: number
/** Unread completion swaps the check for the workspace unread dot; live and needs-you glyphs keep precedence. */
unread?: boolean
/** 'label' keeps the check and only speaks unread, for rows whose card already draws the one dot. */
unreadDisplay?: 'dot' | 'label'
}
type ProgressRing = { tone: AgentProgressRingTone; percent: number }
@@ -97,15 +99,17 @@ export const AgentStateDot = React.memo(function AgentStateDot({
title,
tooltipSide,
progress,
unread = false
unread = false,
unreadDisplay = 'dot'
}: Props): React.JSX.Element {
const t = useTranslate()
const box = size === 'md' ? 'h-3 w-3' : 'h-2.5 w-2.5'
const inner = size === 'md' ? 'size-2' : 'size-1.5'
const icon = size === 'md' ? 'size-3' : 'size-2.5'
const ring = progressRing(state, progress)
const showUnreadDot = unread && state === 'done'
const label = showUnreadDot
const announceUnread = unread && state === 'done'
const showUnreadDot = announceUnread && unreadDisplay === 'dot'
const label = announceUnread
? t('workspace.activity.unreadLabel', '{{status}} · Unread', {
status: agentStateLabel(state)
})
@@ -154,7 +158,7 @@ export const AgentStateDot = React.memo(function AgentStateDot({
indicator = (
<span
className={cn('inline-flex shrink-0 items-center justify-center', box, className)}
aria-label={agentStateLabel(state)}
aria-label={label}
>
<CircleCheck className={cn('text-emerald-500', icon)} aria-hidden="true" />
</span>
@@ -48,6 +48,7 @@ import {
import { translate } from '@/i18n/i18n'
import { useTranslate, type Translate } from '@/i18n/use-translate'
import { useUiLanguageRevision } from '@/i18n/use-ui-language-revision'
import { useHasWorktreeCardUnreadRollup } from '@/components/sidebar/workspace-card/surface/worktree-card-title-status'
function formatTimeAgo(ts: number, now: number, t: Translate = translate): string {
const delta = now - ts
@@ -130,6 +131,7 @@ const DashboardAgentRow = React.memo(function DashboardAgentRow({
onSendTargetClick
}: Props) {
const t = useTranslate()
const hasUnreadRollup = useHasWorktreeCardUnreadRollup()
useUiLanguageRevision()
const view = useClaudeAgentRowView(agent)
const highlighted = view ? view.current && view.focused : isFocusedPane
@@ -318,6 +320,7 @@ const DashboardAgentRow = React.memo(function DashboardAgentRow({
title={null}
progress={presentation.progress}
unread={isUnvisited}
unreadDisplay={hasUnreadRollup ? 'label' : 'dot'}
/>
</span>
</TooltipTrigger>
@@ -179,6 +179,58 @@ const NESTED: WorkspaceSeed[] = [
}
]
const UNREAD_DOTS: WorkspaceSeed[] = [
{
id: 'wt-dots-folded',
name: 'experimental-v2-sidebar',
agents: [
{
agentType: 'claude',
state: 'done',
minutesAgo: 1,
unread: true,
message: 'Finished the card spacing pass'
},
{ agentType: 'codex', state: 'done', minutesAgo: 9, message: 'Ran the fixture suite' }
]
},
{
id: 'wt-dots-row',
name: 'docs-typo-sweep',
agents: [
{
agentType: 'claude',
state: 'done',
minutesAgo: 6,
unread: true,
message: 'Fixed 14 typos across docs/ and opened PR #36955'
}
]
},
{
// A live agent owns the lane glyph; the unread dot must still ride its corner.
id: 'wt-dots-mixed',
name: 'terminal-resize-fix',
agents: [
{ agentType: 'codex', state: 'working', minutesAgo: 0, message: 'Running the resize suite' },
{
agentType: 'claude',
state: 'done',
minutesAgo: 4,
unread: true,
message: 'Traced the reflow bug to the scrollback trim'
}
]
},
{
id: 'wt-dots-manual',
name: 'release-1.4-notes',
agents: [{ agentType: 'codex', state: 'done', minutesAgo: 30, message: 'Drafted the notes' }],
manualUnread: true,
lastActivityMinutesAgo: 27
}
]
const FOLDER_WORKSPACE = folderWorkspaceToWorktree({
id: 'design-notes',
projectGroupId: 'notes',
@@ -253,19 +305,18 @@ function worktreesFor(seeds: readonly WorkspaceSeed[], now: number): Map<string,
}
function seedOpenCards(ids: readonly string[]): void {
const none = new Set<string>()
ids.forEach((id) =>
agentExpansion.seedWorktreeAgentExpansionStateForTests(id, {
expandedLineageParents: none,
expandedIdleChildGroups: none,
compactRootListExpanded: true
})
)
const state = {
expandedLineageParents: new Set<string>(),
expandedIdleChildGroups: new Set<string>(),
compactRootListExpanded: true
}
ids.forEach((id) => agentExpansion.seedWorktreeAgentExpansionStateForTests(id, state))
}
const now = Date.now()
const flatWorktrees = worktreesFor(FLAT, now)
const nestedWorktrees = worktreesFor(NESTED, now)
const unreadDotWorktrees = worktreesFor(UNREAD_DOTS, now)
FOLDER_WORKSPACE.isUnread = false
FOLDER_WORKSPACE.lastActivityAt = now - 9 * MINUTE
@@ -334,13 +385,37 @@ export const agentsExpanded = defineFixture({
width: SIDEBAR_WIDTH,
setup: () => {
seedWorkspaces(FLAT, now)
const none = new Set<string>()
const state = {
expandedLineageParents: none,
expandedIdleChildGroups: none,
compactRootListExpanded: true
}
FLAT.forEach((seed) => agentExpansion.seedWorktreeAgentExpansionStateForTests(seed.id, state))
seedOpenCards(FLAT.map((seed) => seed.id))
},
render: () => <FlatList />
})
export const unreadDots = defineFixture({
width: SIDEBAR_WIDTH,
setup: () => seedWorkspaces(UNREAD_DOTS, now),
render: () => (
<SidebarFrame>
{UNREAD_DOTS.map((seed) => (
<Card key={seed.id} worktree={unreadDotWorktrees.get(seed.id)!} />
))}
</SidebarFrame>
)
})
export const classicUnreadDotsExpanded = defineFixture({
...unreadDots,
setup: () => {
seedWorkspaces(UNREAD_DOTS, now)
seedOpenCards(UNREAD_DOTS.map((seed) => seed.id))
useAppStore.setState((state) => ({
settings: state.settings
? { ...state.settings, experimentalNewWorktreeCardStyle: false }
: state.settings
}))
}
})
export const classicUnreadDotsDetailed = defineFixture({
...classicUnreadDotsExpanded,
store: { agentActivityDisplayMode: 'full' }
})
@@ -7,7 +7,7 @@ import type { Translate } from '@/i18n/use-translate'
export type SummaryAgentGroup = {
state: AgentDotState
/** Done agents the user has not read yet; drawn as the unread dot ahead of every other group. */
/** Unread completions, split out only for cards without a status-lane unread rollup. */
unread?: boolean
agents: DashboardAgentRowData[]
}
@@ -193,6 +193,18 @@ export function formatAllAgentsInState(
}
}
/** Unread means an acknowledged-pending completion; live agents are never announced as unread. */
export function isUnreadDoneAgent(
agent: DashboardAgentRowData,
isUnread: ((agent: DashboardAgentRowData) => boolean) | undefined
): boolean {
return isUnread !== undefined && getAgentDotState(agent) === 'done' && isUnread(agent)
}
/**
* One group per state for the folded pill. Pass `isUnread` only when the card has no status-lane
* unread rollup: then unread completions lead as their own group so the folded pill still shows it.
*/
export function buildSummaryAgentGroups(
agents: DashboardAgentRowData[],
isUnread?: (agent: DashboardAgentRowData) => boolean
@@ -200,12 +212,11 @@ export function buildSummaryAgentGroups(
const groups = new Map<AgentDotState, DashboardAgentRowData[]>()
const unreadDone: DashboardAgentRowData[] = []
for (const agent of agents) {
const dotState = getAgentDotState(agent)
// Split unread completions out so the collapsed pill names which agent holds the card's unread.
if (dotState === 'done' && isUnread?.(agent)) {
if (isUnreadDoneAgent(agent, isUnread)) {
unreadDone.push(agent)
continue
}
const dotState = getAgentDotState(agent)
const group = groups.get(dotState)
if (group) {
group.push(agent)
@@ -28,6 +28,7 @@ import {
} from '../../../../../../shared/program-status/presentation'
import { resolveRowProgramStatus } from '@/lib/program-status/agent-row-presentation'
import { useTranslate, type Translate } from '@/i18n/use-translate'
import { useHasWorktreeCardUnreadRollup } from '../surface/worktree-card-title-status'
function getCompactAgentPrimary(
agent: DashboardAgentRowData,
@@ -132,6 +133,7 @@ export const CompactAgentRow = React.memo(function CompactAgentRow({
isUnvisited = false
}: CompactAgentRowProps) {
const t = useTranslate()
const hasUnreadRollup = useHasWorktreeCardUnreadRollup()
const view = useClaudeAgentRowView(agent)
const highlighted = view ? view.current && view.focused : isFocusedPane
const hasChildDisclosure =
@@ -242,6 +244,7 @@ export const CompactAgentRow = React.memo(function CompactAgentRow({
tooltipSide="right"
progress={presentation.progress}
unread={isUnvisited}
unreadDisplay={hasUnreadRollup ? 'label' : 'dot'}
/>
{!hideIcon && (
<span className="inline-flex shrink-0" title={formatAgentTypeLabel(agent.agentType)}>
@@ -11,11 +11,13 @@ import {
formatAllAgentsInState,
formatStateCount,
formatSummaryStateLabel,
isUnreadDoneAgent,
selectSummaryGroupIconAgents,
summarizeAgentIdentities,
summarizeAgents
} from './worktree-card-agent-summary'
import { useTranslate } from '@/i18n/use-translate'
import { useHasWorktreeCardUnreadRollup } from '../surface/worktree-card-title-status'
import './worktree-card-compact-agent-row'
@@ -90,12 +92,13 @@ export function CompactAgentSummaryButton({
unreadByPaneKey
}: CompactAgentSummaryButtonProps): React.JSX.Element {
const t = useTranslate()
const hasUnreadRollup = useHasWorktreeCardUnreadRollup()
const isUnread = unreadByPaneKey
? (agent: DashboardAgentRowData) => unreadByPaneKey[agent.paneKey] ?? false
: undefined
const groups: readonly (AgentGroupSummary & { unread?: boolean })[] =
precomputedGroups ??
buildSummaryAgentGroups(
agents,
unreadByPaneKey ? (agent) => unreadByPaneKey[agent.paneKey] ?? false : undefined
).map((group) => ({
buildSummaryAgentGroups(agents, hasUnreadRollup ? undefined : isUnread).map((group) => ({
state: group.state,
unread: group.unread,
count: group.agents.length,
@@ -110,7 +113,9 @@ export function CompactAgentSummaryButton({
subject: subjectLabel,
states: groups.map((group) => formatStateCount(group.state, group.count, t)).join(', ')
})
const unreadCount = groups.find((group) => group.unread)?.count ?? 0
const unreadCount = isUnread
? agents.reduce((count, agent) => count + (isUnreadDoneAgent(agent, isUnread) ? 1 : 0), 0)
: 0
const unreadSummary =
unreadCount > 0
? t('auto.components.activity.ActivityTitlebarControls.unreadCount', '{{count}} unread', {
@@ -187,9 +187,9 @@ export function WorktreeCardStatusSlot({
newCardStyle && isUnread
? t('workspace.activity.unreadLabel', '{{status}} · Unread', { status: reviewLabel })
: reviewLabel
// Working/permission own the lane; retain unread in accessible copy and restore its dot afterward.
const showNewCardUnreadAlert =
newCardStyle && isUnread && showStatus && status !== 'working' && status !== 'permission'
// The lane holds the card's only unread dot (agent rows and the folded pill draw none), so it
// stays on over working/permission glyphs; the corner ring keeps it legible against them.
const showNewCardUnreadAlert = newCardStyle && isUnread && showStatus
const reviewStaleRef = isReviewStale ? observeOffscreenAnimation : undefined
const reviewStatusIconClassName = cn(
compactReviewAndBranchStatusIconClassName,
@@ -51,6 +51,7 @@ type TitleStatus = {
}
const TitleStatusContext = createContext<TitleStatus | null>(null)
const UnreadRollupPresenceContext = createContext(false)
function useSlotAgentSignals(agents: DashboardAgentRow[]): SlotAgentSignals {
// Same acknowledgement records the agent rows read, so unread means the same in both places.
@@ -150,7 +151,16 @@ export function WorktreeCardTitleStatusProvider({
() => ({ offline, exceptions, unread, lineageStatus, at, resolveTargets }),
[at, exceptions, lineageStatus, offline, resolveTargets, unread]
)
return <TitleStatusContext.Provider value={value}>{children}</TitleStatusContext.Provider>
return (
<UnreadRollupPresenceContext.Provider value={true}>
<TitleStatusContext.Provider value={value}>{children}</TitleStatusContext.Provider>
</UnreadRollupPresenceContext.Provider>
)
}
/** False on classic cards, which mount no rollup and so draw no status-lane unread dot. */
export function useHasWorktreeCardUnreadRollup(): boolean {
return useContext(UnreadRollupPresenceContext)
}
/** True while the card holds an unread result: its own, any of its agents' or a collapsed child's. */