:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(today): show desktop's hover cards on sidebar sessions and spaces (#109604)
Shy Alter5c36b851dce0
diff --git a/frontend/src/layout/today/TodayPreviewCardProvider.tsx b/frontend/src/layout/today/TodayPreviewCardProvider.tsxnew file mode 100644index 000000000000..090e26ba0243--- /dev/null+++ b/frontend/src/layout/today/TodayPreviewCardProvider.tsx@@ -0,0 +1,66 @@+import { PreviewCard } from '@base-ui/react/preview-card'+import { ReactNode, useMemo, useRef, useState } from 'react'++import { Card } from '@posthog/quill'++import { TodayPreviewCard, TodayPreviewCardContext } from './todayPreviewCardContext'+import { TodayPreviewPayload } from './todayPreviewCards'+import { TodaySessionHoverCard } from './TodaySessionHoverCard'+import { TodaySpaceHoverCard } from './TodaySpaceHoverCard'++/**+ * One hover card for every row in the sidebar, like PostHog Desktop. The rows are only triggers on a shared handle,+ * and Base UI skips the open delay when the pointer moves to another trigger of an open card,+ * so sliding down the list swaps the card's contents instead of waiting again on every row.+ */+export function TodayPreviewCardProvider({ children }: { children: ReactNode }): JSX.Element {+ const [handle] = useState(() => PreviewCard.createHandle<TodayPreviewPayload>())+ const [open, setOpen] = useState(false)+ // A ref, so a hover that lands while a menu is open is refused on the same event.+ const menuOpen = useRef(false)+ const card = useMemo<TodayPreviewCard>(+ () => ({+ handle,+ setMenuOpen: (next) => {+ menuOpen.current = next+ if (next) {+ setOpen(false)+ }+ },+ }),+ [handle]+ )++ return (+ <TodayPreviewCardContext.Provider value={card}>+ {children}+ <PreviewCard.Root handle={handle} open={open} onOpenChange={(next) => setOpen(next && !menuOpen.current)}>+ {({ payload }) =>+ payload ? (+ <PreviewCard.Portal>+ {/* Centered on the row, so the path to a tall card is short from any row. */}+ <PreviewCard.Positioner+ data-quill+ data-quill-portal="popover"+ side="right"+ align="center"+ sideOffset={10}+ >+ {/* Inside the popup, not its `render`: on React 18 quill's Card takes no ref. */}+ <PreviewCard.Popup className="outline-none">+ <Card size="sm" className="w-72 gap-0 border border-border py-0 shadow-md">+ {payload.kind === 'space' ? (+ <TodaySpaceHoverCard preview={payload} />+ ) : (+ <TodaySessionHoverCard preview={payload} />+ )}+ </Card>+ </PreviewCard.Popup>+ </PreviewCard.Positioner>+ </PreviewCard.Portal>+ ) : null+ }+ </PreviewCard.Root>+ </TodayPreviewCardContext.Provider>+ )+}diff --git a/frontend/src/layout/today/TodayPreviewTrigger.tsx b/frontend/src/layout/today/TodayPreviewTrigger.tsxnew file mode 100644index 000000000000..33325c3501f4--- /dev/null+++ b/frontend/src/layout/today/TodayPreviewTrigger.tsx@@ -0,0 +1,37 @@+import { PreviewCard } from '@base-ui/react/preview-card'+import { ReactNode, useContext } from 'react'++import { TodayPreviewCardContext } from './todayPreviewCardContext'+import { TodayPreviewPayload } from './todayPreviewCards'++// Desktop's timings: the first card waits for the pointer to rest, and a short close delay lets it cross to the card.+const OPEN_DELAY_MS = 400+const CLOSE_DELAY_MS = 100++/**+ * Makes a sidebar row show the shared hover card. The card reads `payload` from the active trigger,+ * so keep it referentially stable: a new object writes it to the card's store again.+ */+export function TodayPreviewTrigger({+ payload,+ children,+}: {+ payload: TodayPreviewPayload+ children: ReactNode+}): JSX.Element {+ const card = useContext(TodayPreviewCardContext)+ if (!card) {+ return <>{children}</>+ }+ return (+ <PreviewCard.Trigger+ handle={card.handle}+ payload={payload}+ delay={OPEN_DELAY_MS}+ closeDelay={CLOSE_DELAY_MS}+ render={<div className="min-w-0" />}+ >+ {children}+ </PreviewCard.Trigger>+ )+}diff --git a/frontend/src/layout/today/TodaySessionHoverCard.tsx b/frontend/src/layout/today/TodaySessionHoverCard.tsxnew file mode 100644index 000000000000..dea762548eb3--- /dev/null+++ b/frontend/src/layout/today/TodaySessionHoverCard.tsx@@ -0,0 +1,96 @@+import { IconPinFilled, IconPullRequest } from '@posthog/icons'+import { Item, ItemContent, ItemSeparator, ItemTitle, Text, cn } from '@posthog/quill'++import { dayjs } from 'lib/dayjs'+import { LinkPrimitive } from 'lib/lemon-ui/Link'++import { pullRequestStateMeta } from 'products/tasks/frontend/spaces/TaskPullRequestChip'+import { TaskUserAvatar, taskUserName } from 'products/tasks/frontend/spaces/TaskUserAvatar'++import { TodaySessionPreview } from './todayPreviewCards'+import { TodaySessionStatusDot } from './TodaySessionStatusDot'++function Fact({ label, children }: { label: string; children: JSX.Element | string }): JSX.Element {+ return (+ <div className="flex min-w-0 items-center gap-2 text-xs">+ <Text size="xs" variant="muted" render={<span />} className="w-16 shrink-0">+ {label}+ </Text>+ <span className="min-w-0 flex-1 truncate">{children}</span>+ </div>+ )+}++/** A session row's hover card: what the row's marks mean in words, where the work sits, and what the agent said last. */+export function TodaySessionHoverCard({ preview }: { preview: TodaySessionPreview }): JSX.Element {+ const { dot, pullRequest, author } = preview+ const pullRequestState = pullRequestStateMeta(preview.pullRequestState)+ return (+ <div className="flex flex-col" data-attr="today-session-hover-card">+ <Item size="xs" className="items-start">+ <ItemContent className="min-w-0 gap-2">+ {/* `wrap-anywhere`: the title sizes to its content, so a long URL in it would widen the card. */}+ <ItemTitle className="flex items-start gap-2 wrap-anywhere">+ <span className="flex h-lh w-4 shrink-0 items-center justify-center">+ <TodaySessionStatusDot dot={dot} />+ </span>+ <span className="min-w-0 font-semibold">{preview.title}</span>+ </ItemTitle>+ <div className="flex flex-col gap-1 pl-6">+ {preview.repository && <Fact label="Repo">{preview.repository}</Fact>}+ {preview.spaceName && <Fact label="Space">{preview.spaceName}</Fact>}+ {author && (+ <Fact label="Created by">+ <span className="flex min-w-0 items-center gap-1.5">+ <TaskUserAvatar user={author} />+ <span className="truncate">{taskUserName(author)}</span>+ </span>+ </Fact>+ )}+ {preview.timestamp && <Fact label="Updated">{dayjs(preview.timestamp).fromNow()}</Fact>}+ </div>+ </ItemContent>+ </Item>+ <ItemSeparator className="my-0" />+ <Item size="xs" className="items-start">+ <ItemContent className="min-w-0 gap-1.5">+ <Text size="xs" render={<span />}>+ {dot.label}+ </Text>+ {(preview.pinned || pullRequest) && (+ <div className="flex flex-wrap items-center gap-x-3 gap-y-1">+ {preview.pinned && (+ <span className="flex items-center gap-1 text-xs text-muted-foreground">+ <IconPinFilled className="size-3 shrink-0" />+ Pinned+ </span>+ )}+ {pullRequest && (+ <LinkPrimitive+ to={pullRequest.url}+ target="_blank"+ data-attr="today-session-hover-card-pr"+ // Dotted at rest, so the one mark that opens something reads as a link.+ className="flex min-w-0 items-center gap-1 text-xs font-normal text-muted-foreground underline decoration-dotted underline-offset-2 hover:text-foreground"+ >+ <IconPullRequest+ className={cn('size-3 shrink-0', pullRequestState?.iconClassName)}+ />+ <span className="truncate">+ {`${pullRequestState?.label ?? 'Pull request'} · ${pullRequest.repository}#${pullRequest.number}`}+ </span>+ </LinkPrimitive>+ )}+ </div>+ )}+ {preview.message && (+ // Three lines hold the agent's closing sentence without turning the card into a transcript.+ <Text size="xs" variant="muted" className="line-clamp-3 leading-snug break-words">+ {preview.message}+ </Text>+ )}+ </ItemContent>+ </Item>+ </div>+ )+}diff --git a/frontend/src/layout/today/TodaySessionMenu.tsx b/frontend/src/layout/today/TodaySessionMenu.tsxindex 5f2723c0a093..30b1171c88f7 100644--- a/frontend/src/layout/today/TodaySessionMenu.tsx+++ b/frontend/src/layout/today/TodaySessionMenu.tsx@@ -37,6 +37,7 @@ import {import { FEATURE_FLAGS } from 'lib/constants'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'+import { useTodayPreviewMenuReport } from './todayPreviewCardContext'import { TodaySessionArchiveDialog } from './TodaySessionArchiveDialog'import { TodaySessionHandoffDialog } from './TodaySessionHandoffDialog'import { TodaySessionSurface, todaySessionMenuLogic } from './todaySessionMenuLogic'@@ -82,6 +83,7 @@ export function TodaySessionMenu({copySessionLink,stopSession,} = useActions(todaySessionMenuLogic)+ const reportMenuOpen = useTodayPreviewMenuReport()const [spaceSearch, setSpaceSearch] = useState('')const runId = featureFlags[FEATURE_FLAGS.POSTHOG_CODE_TASK_ANALYSIS] ? analysisRunId : nullconst saving = pendingSessionIds.includes(sessionId)@@ -90,7 +92,7 @@ export function TodaySessionMenu({return (<>- <DropdownMenu>+ <DropdownMenu onOpenChange={reportMenuOpen}><Tooltip><TooltipTriggerdelay={0}diff --git a/frontend/src/layout/today/TodaySessionRow.tsx b/frontend/src/layout/today/TodaySessionRow.tsxindex fdca181bd0ff..197e52c31b3d 100644--- a/frontend/src/layout/today/TodaySessionRow.tsx+++ b/frontend/src/layout/today/TodaySessionRow.tsx@@ -1,11 +1,13 @@import { useValues } from 'kea'import { router } from 'kea-router'+import { useMemo } from 'react'import { urls } from 'scenes/urls'import { userLogic } from 'scenes/userLogic'+import { sessionPreview } from './todayPreviewCards'+import { TodayPreviewTrigger } from './TodayPreviewTrigger'import { TodaySessionBadges } from './TodaySessionBadges'-import { todaySessionDot } from './todaySessionDot'import { TodaySessionMenu } from './TodaySessionMenu'import { TodaySessionSurface, todaySessionMenuLogic } from './todaySessionMenuLogic'import { TodaySessionRenameInput } from './TodaySessionRenameInput'@@ -35,7 +37,11 @@ export function TodaySessionRow({const { renaming } = useValues(todaySessionMenuLogic)const { location, searchParams } = useValues(router)const { user } = useValues(userLogic)- const { pullRequestStates } = useValues(todaySpacesLogic)+ const { pullRequestStates, spaceNames } = useValues(todaySpacesLogic)+ const preview = useMemo(+ () => sessionPreview(item, { unread, pinned, pullRequestStates, spaceNames }),+ [item, unread, pinned, pullRequestStates, spaceNames]+ )const [pullRequest] = item.pullRequestsconst pinBadge = pinned && showPinBadge@@ -44,11 +50,11 @@ export function TodaySessionRow({if (renaming?.sessionId === item.id && renaming.surface === surface) {return <TodaySessionRenameInput sessionId={item.id} title={item.title} />}- return (+ const row = (<TodaySpacesRowlabel={item.title || 'Untitled session'}// Unread shows only as a solid status dot; the title keeps its resting weight, like desktop.- icon={<TodaySessionStatusDot dot={todaySessionDot(item, unread)} />}+ icon={<TodaySessionStatusDot dot={preview.dot} />}to={urls.aiTask(item.id)}active={location.pathname.endsWith('/ai') && searchParams.task === item.id}dataAttr={dataAttr}@@ -77,4 +83,5 @@ export function TodaySessionRow({}/>)+ return <TodayPreviewTrigger payload={preview}>{row}</TodayPreviewTrigger>}diff --git a/frontend/src/layout/today/TodayShell.tsx b/frontend/src/layout/today/TodayShell.tsxindex 2b7d2bcede17..75730bf49378 100644--- a/frontend/src/layout/today/TodayShell.tsx+++ b/frontend/src/layout/today/TodayShell.tsx@@ -14,6 +14,7 @@ import { TodayHomeSidebar } from 'scenes/project-homepage/today/TodayHomeSidebarimport { NewSpaceDialog } from 'products/tasks/frontend/spaces/NewSpaceDialog'import { TodayLibrarySidebar } from './TodayLibrarySidebar'+import { TodayPreviewCardProvider } from './TodayPreviewCardProvider'import { TodayRail } from './TodayRail'import { TODAY_RAIL_WIDTH, TODAY_SIDEBAR_CLOSE_THRESHOLD, clampSidebarWidth, todayShellLogic } from './todayShellLogic'import { TodaySidebarFooter } from './TodaySidebarFooter'@@ -67,7 +68,9 @@ export function TodayShell({ className }: { className?: string }): JSX.Element {{activePane === 'home' ? (<TodayHomeSidebar />) : activePane === 'spaces' ? (- <TodaySpacesSidebar />+ <TodayPreviewCardProvider>+ <TodaySpacesSidebar />+ </TodayPreviewCardProvider>) : activePane === 'library' ? (<TodayLibrarySidebar />) : (diff --git a/frontend/src/layout/today/TodaySpaceActions.tsx b/frontend/src/layout/today/TodaySpaceActions.tsxindex 478c16fc25b7..5479c8b9b112 100644--- a/frontend/src/layout/today/TodaySpaceActions.tsx+++ b/frontend/src/layout/today/TodaySpaceActions.tsx@@ -18,11 +18,13 @@ import { urls } from 'scenes/urls'import { ChannelDTOApi } from 'products/tasks/frontend/generated/api.schemas'+import { useTodayPreviewMenuReport } from './todayPreviewCardContext'import { spaceLabel, spaceNewSessionUrl, todaySpacesLogic } from './todaySpacesLogic'export function TodaySpaceActions({ space }: { space: ChannelDTOApi }): JSX.Element {const { pendingSpaceIds } = useValues(todaySpacesLogic)const { toggleStar, copySpaceLink } = useActions(todaySpacesLogic)+ const reportMenuOpen = useTodayPreviewMenuReport()const saving = pendingSpaceIds.includes(space.id)const newSessionLabel = `New session in ${spaceLabel(space)}`const menuLabel = saving ? 'Saving your last change' : 'More actions'@@ -45,7 +47,7 @@ export function TodaySpaceActions({ space }: { space: ChannelDTOApi }): JSX.Elem</TooltipTrigger><TooltipContent>{newSessionLabel}</TooltipContent></Tooltip>- <DropdownMenu>+ <DropdownMenu onOpenChange={reportMenuOpen}><Tooltip><TooltipTriggerdelay={0}diff --git a/frontend/src/layout/today/TodaySpaceGlyph.tsx b/frontend/src/layout/today/TodaySpaceGlyph.tsxnew file mode 100644index 000000000000..13b80cf04ec0--- /dev/null+++ b/frontend/src/layout/today/TodaySpaceGlyph.tsx@@ -0,0 +1,13 @@+import { IconLock } from '@posthog/icons'+import { cn } from '@posthog/quill'++/** A lock for a space only some people can see, a `#` for the rest. */+export function TodaySpaceGlyph({ locked, className }: { locked: boolean; className?: string }): JSX.Element {+ return locked ? (+ <IconLock className={className} />+ ) : (+ <span aria-hidden className={cn('font-mono', className)}>+ #+ </span>+ )+}diff --git a/frontend/src/layout/today/TodaySpaceHoverCard.tsx b/frontend/src/layout/today/TodaySpaceHoverCard.tsxnew file mode 100644index 000000000000..9aa04a406203--- /dev/null+++ b/frontend/src/layout/today/TodaySpaceHoverCard.tsx@@ -0,0 +1,72 @@+import { IconGitRepository } from '@posthog/icons'+import { Item, ItemActions, ItemContent, ItemDescription, ItemSeparator, ItemTitle, Text } from '@posthog/quill'++import { dayjs } from 'lib/dayjs'++import { SpacePresenceAvatars } from 'products/tasks/frontend/spaces/SpacePresenceAvatars'++import { TodaySpaceKind, TodaySpacePreview } from './todayPreviewCards'+import { TodaySpaceGlyph } from './TodaySpaceGlyph'++const KIND_LABELS: Record<TodaySpaceKind, string> = {+ public: 'Space',+ private: 'Private space',+ personal: 'Personal space',+}++/** A space row's hover card: what kind of space it is, who works in it, and which repositories it uses. */+export function TodaySpaceHoverCard({ preview }: { preview: TodaySpacePreview }): JSX.Element {+ return (+ <div className="flex flex-col" data-attr="today-space-hover-card">+ {/* `flex-nowrap` keeps the faces beside a long name. */}+ <Item size="xs" className="flex-nowrap items-start">+ <ItemContent className="min-w-0">+ {/* `wrap-anywhere`: the title sizes to its content, so a long name would widen the card. */}+ <ItemTitle className="flex items-center gap-2 wrap-anywhere">+ <span className="flex size-3.5 shrink-0 items-center justify-center text-muted-foreground">+ <TodaySpaceGlyph locked={preview.spaceKind !== 'public'} />+ </span>+ <span className="min-w-0 font-semibold">{preview.name}</span>+ </ItemTitle>+ <ItemDescription className="pl-5.5">+ <span className="block">{KIND_LABELS[preview.spaceKind]}</span>+ {preview.lastActivityAt && (+ <span className="block">{`Active ${dayjs(preview.lastActivityAt).fromNow()}`}</span>+ )}+ </ItemDescription>+ </ItemContent>+ <ItemActions className="self-start">+ <SpacePresenceAvatars+ presence={{ people: preview.people, liveUuids: preview.liveUuids }}+ creatorUuid={preview.creatorUuid}+ />+ </ItemActions>+ </Item>+ {preview.repositories.length > 0 && (+ <>+ <ItemSeparator className="my-0" />+ <Item size="xs">+ <ItemContent className="min-w-0">+ <div className="flex flex-wrap items-center gap-x-3 gap-y-1">+ {preview.repositories.map((repository) => (+ <span+ key={repository}+ className="flex min-w-0 items-center gap-1 text-xs text-muted-foreground"+ >+ <IconGitRepository className="size-3 shrink-0" />+ <span className="truncate">{repository}</span>+ </span>+ ))}+ {preview.hiddenRepositoryCount > 0 && (+ <Text size="xs" variant="muted" render={<span />}>+ {`+${preview.hiddenRepositoryCount} more`}+ </Text>+ )}+ </div>+ </ItemContent>+ </Item>+ </>+ )}+ </div>+ )+}diff --git a/frontend/src/layout/today/TodaySpacesSidebar.tsx b/frontend/src/layout/today/TodaySpacesSidebar.tsxindex 8c3edac71dd9..0e9281e07105 100644--- a/frontend/src/layout/today/TodaySpacesSidebar.tsx+++ b/frontend/src/layout/today/TodaySpacesSidebar.tsx@@ -2,7 +2,7 @@ import { useActions, useValues } from 'kea'import { router } from 'kea-router'import { Fragment } from 'react'-import { IconChat, IconLock, IconPlus, IconSearch, IconTableOfContents } from '@posthog/icons'+import { IconChat, IconPlus, IconSearch, IconTableOfContents } from '@posthog/icons'import { Button, Skeleton, Text, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, cn } from '@posthog/quill'import { LinkPrimitive } from 'lib/lemon-ui/Link'@@ -12,10 +12,12 @@ import { newSpaceLogic } from 'products/tasks/frontend/spaces/newSpaceLogic'import { SpacePresenceAvatars } from 'products/tasks/frontend/spaces/SpacePresenceAvatars'import { TodayPaneSection, TodayPaneSectionProps } from './TodayPaneSection'+import { TodayPreviewTrigger } from './TodayPreviewTrigger'import { TodayRecentFilterMenu } from './TodayRecentFilterMenu'import { TodayRecentSearchField } from './TodayRecentSearchField'import { TodaySessionRow } from './TodaySessionRow'import { TodaySpaceActions } from './TodaySpaceActions'+import { TodaySpaceGlyph } from './TodaySpaceGlyph'import { TodayWorkSectionId, isLockedSpace, spaceLabel, todaySpacesLogic } from './todaySpacesLogic'import { TodaySpacesRow } from './TodaySpacesRow'import { TodayWorkItem } from './todayWorkItems'@@ -37,6 +39,7 @@ export function TodaySpacesSidebar(): JSX.Element {unreadSessionIds,unreadSpaceIds,spacePresence,+ spacePreviews,} = useValues(todaySpacesLogic)const { loadSpaces, loadRecentTasks, toggleSection, setRecentSearchOpen, clearRecentSearchAndFilters } =useActions(todaySpacesLogic)@@ -272,27 +275,25 @@ export function TodaySpacesSidebar(): JSX.Element {{visibleSpaces.map((space) => {const presence = spacePresence[space.id]return (- <TodaySpacesRow- key={space.id}- label={spaceLabel(space)}- icon={- isLockedSpace(space) ? (- <IconLock className="text-muted-foreground" />- ) : (- <span aria-hidden className="font-mono text-muted-foreground">- #- </span>- )- }- to={urls.taskSpace(space.id)}- active={location.pathname.includes(urls.taskSpace(space.id))}- dataAttr="today-space-row"- action={<TodaySpaceActions space={space} />}- actionCount={2}- badge={presence ? <SpacePresenceAvatars presence={presence} /> : null}- badgeCount={Math.min(presence?.people.length ?? 1, 3) as 1 | 2 | 3}- unread={unreadSpaceIds.has(space.id)}- />+ <TodayPreviewTrigger key={space.id} payload={spacePreviews[space.id]}>+ <TodaySpacesRow+ label={spaceLabel(space)}+ icon={+ <TodaySpaceGlyph+ locked={isLockedSpace(space)}+ className="text-muted-foreground"+ />+ }+ to={urls.taskSpace(space.id)}+ active={location.pathname.includes(urls.taskSpace(space.id))}+ dataAttr="today-space-row"+ action={<TodaySpaceActions space={space} />}+ actionCount={2}+ badge={presence ? <SpacePresenceAvatars presence={presence} /> : null}+ badgeCount={Math.min(presence?.people.length ?? 1, 3) as 1 | 2 | 3}+ unread={unreadSpaceIds.has(space.id)}+ />+ </TodayPreviewTrigger>)})}{visibleSpaces.length <= 1 && (diff --git a/frontend/src/layout/today/todayPreviewCardContext.ts b/frontend/src/layout/today/todayPreviewCardContext.tsnew file mode 100644index 000000000000..ab3a95d8decf--- /dev/null+++ b/frontend/src/layout/today/todayPreviewCardContext.ts@@ -0,0 +1,34 @@+import { PreviewCard } from '@base-ui/react/preview-card'+import { createContext, useCallback, useContext, useEffect, useRef } from 'react'++import { TodayPreviewPayload } from './todayPreviewCards'++export interface TodayPreviewCard {+ handle: PreviewCard.Handle<TodayPreviewPayload>+ /** A row's menu reports here, so the card closes while the menu is open and stays shut until it closes. */+ setMenuOpen: (open: boolean) => void+}++export const TodayPreviewCardContext = createContext<TodayPreviewCard | null>(null)++/** For a row menu's `onOpenChange`. Outside the sidebar there is no card, so the report goes nowhere. */+export function useTodayPreviewMenuReport(): (open: boolean) => void {+ const setMenuOpen = useContext(TodayPreviewCardContext)?.setMenuOpen+ const reportedOpen = useRef(false)+ // A menu that unmounts while open reports no close, which would keep the card shut for good.+ useEffect(+ () => () => {+ if (reportedOpen.current) {+ setMenuOpen?.(false)+ }+ },+ [setMenuOpen]+ )+ return useCallback(+ (open: boolean) => {+ reportedOpen.current = open+ setMenuOpen?.(open)+ },+ [setMenuOpen]+ )+}diff --git a/frontend/src/layout/today/todayPreviewCards.test.ts b/frontend/src/layout/today/todayPreviewCards.test.tsnew file mode 100644index 000000000000..b03332d27992--- /dev/null+++ b/frontend/src/layout/today/todayPreviewCards.test.ts@@ -0,0 +1,73 @@+import { ChannelDTOApi, TaskListItemApi, TaskUserBasicInfoApi } from 'products/tasks/frontend/generated/api.schemas'++import { sessionPreview, spaceKind, spacePreview } from './todayPreviewCards'+import { sessionItem } from './todayWorkItems'++const person = (uuid: string): TaskUserBasicInfoApi => ({+ id: uuid.length,+ uuid,+ distinct_id: uuid,+ first_name: uuid,+ last_name: '',+ email: `${uuid}@example.com`,+})++const space = (overrides: Partial<ChannelDTOApi>): ChannelDTOApi =>+ ({ id: 'space-a', name: 'checkout', channel_type: 'public', repositories: [], ...overrides }) as ChannelDTOApi++describe('todayPreviewCards', () => {+ it.each<[string, Partial<ChannelDTOApi>, ReturnType<typeof spaceKind>]>([+ [+ 'the personal space, whatever its channel type',+ { system_role: 'personal', channel_type: 'public' },+ 'personal',+ ],+ ['a private space', { channel_type: 'private', system_role: null }, 'private'],+ ['the general space', { channel_type: 'public', system_role: 'general' }, 'public'],+ ])('names %s', (_name, identity, kind) => {+ expect(spaceKind(space(identity))).toBe(kind)+ })++ it.each<[string, TaskUserBasicInfoApi | null, string[], string[]]>([+ ['leads with a creator who was not active lately', person('ada'), ['grace'], ['ada', 'grace']],+ ['lists a creator who was also active once', person('ada'), ['grace', 'ada'], ['ada', 'grace']],+ ['shows only recent people when the creator is unknown', null, ['grace'], ['grace']],+ ])('space people %s', (_name, creator, recent, expected) => {+ const preview = spacePreview(+ space({ created_by: creator }),+ 'checkout',+ { people: recent.map(person), liveUuids: [] },+ undefined+ )+ expect(preview.people.map((p) => p.uuid)).toEqual(expected)+ })++ it('names three repositories and counts the rest', () => {+ const preview = spacePreview(+ space({ repositories: ['a/1', 'a/2', 'a/3', 'a/4', 'a/5'] }),+ 'checkout',+ undefined,+ undefined+ )+ expect([preview.repositories, preview.hiddenRepositoryCount]).toEqual([['a/1', 'a/2', 'a/3'], 2])+ })++ it.each<[string, string | null, Record<string, string>, string | null]>([+ ['names the space the session is in', 'space-a', { 'space-a': 'checkout' }, 'checkout'],+ ['leaves out a space the rail has not loaded', 'space-gone', { 'space-a': 'checkout' }, null],+ ])('session card %s', (_name, channel, spaceNames, expected) => {+ const item = sessionItem({+ id: 's',+ title: 'Session',+ channel,+ latest_run: { output: { pr_url: 'https://github.com/example-org/web/pull/7' } },+ } as unknown as TaskListItemApi)+ const preview = sessionPreview(item, {+ unread: false,+ pinned: false,+ pullRequestStates: { 'https://github.com/example-org/web/pull/7': 'merged' },+ spaceNames,+ })+ expect([preview.spaceName, preview.pullRequestState]).toEqual([expected, 'merged'])+ })+})diff --git a/frontend/src/layout/today/todayPreviewCards.ts b/frontend/src/layout/today/todayPreviewCards.tsnew file mode 100644index 000000000000..ecf60eb309cb--- /dev/null+++ b/frontend/src/layout/today/todayPreviewCards.ts@@ -0,0 +1,116 @@+import { ChannelDTOApi, PrStateEnumApi, TaskUserBasicInfoApi } from 'products/tasks/frontend/generated/api.schemas'+import { SpacePresence } from 'products/tasks/frontend/spaces/spacePresence'+import { TaskPullRequest } from 'products/tasks/frontend/spaces/taskPullRequests'++import { TodaySessionDot, todaySessionDot } from './todaySessionDot'+import { TodayWorkItem } from './todayWorkItems'++/** Repositories past this are counted rather than named, so the card stays a glance. */+const SPACE_PREVIEW_REPOSITORY_LIMIT = 3++export type TodaySpaceKind = 'public' | 'private' | 'personal'++/** What a session row's hover card says, built once per row so the shared card gets a stable payload. */+export interface TodaySessionPreview {+ kind: 'session'+ title: string+ dot: TodaySessionDot+ pinned: boolean+ pullRequest: TaskPullRequest | null+ pullRequestState: PrStateEnumApi | null+ spaceName: string | null+ repository: string | null+ author: TaskUserBasicInfoApi | null+ timestamp: string | null+ message: string | null+}++/** What a space row's hover card says. */+export interface TodaySpacePreview {+ kind: 'space'+ name: string+ spaceKind: TodaySpaceKind+ /** The creator first, then whoever worked in the space most recently. */+ people: TaskUserBasicInfoApi[]+ liveUuids: string[]+ creatorUuid: string | null+ lastActivityAt: string | null+ repositories: string[]+ hiddenRepositoryCount: number+}++export type TodayPreviewPayload = TodaySessionPreview | TodaySpacePreview++export function spaceKind(space: Pick<ChannelDTOApi, 'channel_type' | 'system_role'>): TodaySpaceKind {+ if (space.system_role === 'personal' || space.channel_type === 'personal') {+ return 'personal'+ }+ return space.channel_type === 'private' ? 'private' : 'public'+}++export function sessionPreview(+ item: TodayWorkItem,+ {+ unread,+ pinned,+ pullRequestStates,+ spaceNames,+ }: {+ unread: boolean+ pinned: boolean+ pullRequestStates: Record<string, PrStateEnumApi>+ spaceNames: Record<string, string>+ }+): TodaySessionPreview {+ // The row shows only the first pull request, so the card names the same one.+ const [pullRequest] = item.pullRequests+ return {+ kind: 'session',+ title: item.title || 'Untitled session',+ dot: todaySessionDot(item, unread),+ pinned,+ pullRequest: pullRequest ?? null,+ pullRequestState: pullRequest ? (pullRequestStates[pullRequest.url] ?? null) : null,+ spaceName: item.channel ? (spaceNames[item.channel] ?? null) : null,+ repository: item.repository,+ author: item.author,+ timestamp: item.timestamp,+ message: item.finalMessage,+ }+}++/**+ * The creator leads whether or not they worked here lately, so the crown always sits on the first face.+ * They are not listed twice when they are also in the recent people.+ */+function spacePeople(+ creator: TaskUserBasicInfoApi | null | undefined,+ presence: SpacePresence | undefined+): TaskUserBasicInfoApi[] {+ const people = creator ? [creator] : []+ for (const person of presence?.people ?? []) {+ if (!people.some((existing) => existing.uuid === person.uuid)) {+ people.push(person)+ }+ }+ return people+}++export function spacePreview(+ space: ChannelDTOApi,+ name: string,+ presence: SpacePresence | undefined,+ lastActivityAt: string | undefined+): TodaySpacePreview {+ return {+ kind: 'space',+ name,+ spaceKind: spaceKind(space),+ people: spacePeople(space.created_by, presence),+ liveUuids: presence?.liveUuids ?? [],+ creatorUuid: space.created_by?.uuid ?? null,+ lastActivityAt: lastActivityAt ?? null,+ repositories: space.repositories.slice(0, SPACE_PREVIEW_REPOSITORY_LIMIT),+ hiddenRepositoryCount: Math.max(0, space.repositories.length - SPACE_PREVIEW_REPOSITORY_LIMIT),+ }+}diff --git a/frontend/src/layout/today/todaySessionIcon.test.ts b/frontend/src/layout/today/todaySessionIcon.test.tsindex d26572620a95..0f99f7f057e9 100644--- a/frontend/src/layout/today/todaySessionIcon.test.ts+++ b/frontend/src/layout/today/todaySessionIcon.test.ts@@ -10,12 +10,14 @@ const item = (kind: TodayWorkItem['kind'], status: string | null): TodayWorkItemstatus,channel: null,createdById: null,+ author: null,latestRunId: null,runEnvironment: null,originProduct: null,source: null,repository: null,pullRequests: [],+ finalMessage: null,})describe('todaySessionIcon', () => {diff --git a/frontend/src/layout/today/todaySpacesLogic.ts b/frontend/src/layout/today/todaySpacesLogic.tsindex b395b477529b..adf6b22b4638 100644--- a/frontend/src/layout/today/todaySpacesLogic.ts+++ b/frontend/src/layout/today/todaySpacesLogic.ts@@ -28,9 +28,15 @@ import {TaskActivityReadMarkerApi,TaskListItemApi,} from 'products/tasks/frontend/generated/api.schemas'-import { SpacePresence, presenceBySpace } from 'products/tasks/frontend/spaces/spacePresence'+import {+ SpaceActivity,+ SpacePresence,+ lastActivityBySpace,+ presenceBySpace,+} from 'products/tasks/frontend/spaces/spacePresence'import { pullRequestStates, sessionIdsWithPullRequests } from 'products/tasks/frontend/spaces/taskPullRequests'+import { TodaySpacePreview, spacePreview } from './todayPreviewCards'import {DEFAULT_RECENT_FILTERS,TodayRecentFilters,@@ -146,9 +152,11 @@ export interface todaySpacesLogicValues {recentTasksUnavailable: booleansectionHeights: Partial<Record<TodayWorkSectionId, number>>sortedSpaces: ChannelDTOApi[]+ spaceActivity: SpaceActivity+ spaceActivityLoading: booleanspaceNames: Record<string, string>spacePresence: Record<string, SpacePresence>- spacePresenceLoading: boolean+ spacePreviews: Record<string, TodaySpacePreview>spaces: ChannelDTOApi[]spacesLoading: booleanspacesUnavailable: boolean@@ -224,19 +232,25 @@ export interface todaySpacesLogicActions {recentTasks: TaskListItemApi[]payload?: any}- loadSpacePresence: () => any- loadSpacePresenceFailure: (+ loadSpaceActivity: () => any+ loadSpaceActivityFailure: (error: string,errorObject?: any) => {error: stringerrorObject?: any}- loadSpacePresenceSuccess: (- spacePresence: Record<string, SpacePresence>,+ loadSpaceActivitySuccess: (+ spaceActivity: {+ lastActivityAt: Record<string, string>+ presence: Record<string, SpacePresence>+ },payload?: any) => {- spacePresence: Record<string, SpacePresence>+ spaceActivity: {+ lastActivityAt: Record<string, string>+ presence: Record<string, SpacePresence>+ }payload?: any}loadSpaces: () => any@@ -353,6 +367,11 @@ export interface todaySpacesLogicMeta {recentLoading: (recentTasksLoading: boolean, conversationHistoryLoading: boolean) => booleanunreadSessionIds: (taskActivity: TaskActivityDTOApi[]) => Set<string>unreadSpaceIds: (taskActivity: TaskActivityDTOApi[]) => Set<string>+ spacePresence: (spaceActivity: SpaceActivity) => Record<string, SpacePresence>+ spacePreviews: (+ visibleSpaces: ChannelDTOApi[],+ spaceActivity: SpaceActivity+ ) => Record<string, TodaySpacePreview>}}@@ -442,19 +461,22 @@ export const todaySpacesLogic = kea<todaySpacesLogicType>([},},],- spacePresence: [- {} as Record<string, SpacePresence>,+ spaceActivity: [+ { presence: {}, lastActivityAt: {} } as SpaceActivity,{- loadSpacePresence: async () => {+ loadSpaceActivity: async () => {if (!values.currentTeamId) {- return {}+ return { presence: {}, lastActivityAt: {} }}const response = await tasksList(String(values.currentTeamId), {ordering: '-last_activity_at',basic: true,limit: SPACE_PRESENCE_FETCH_LIMIT,})- return presenceBySpace(response.results, Date.now())+ return {+ presence: presenceBySpace(response.results, Date.now()),+ lastActivityAt: lastActivityBySpace(response.results),+ }},},],@@ -617,6 +639,26 @@ export const todaySpacesLogic = kea<todaySpacesLogicType>([(s) => [s.taskActivity],(taskActivity: TaskActivityDTOApi[]): Set<string> => unreadSpaceIds(taskActivity),],+ spacePresence: [+ (s) => [s.spaceActivity],+ (spaceActivity: SpaceActivity): Record<string, SpacePresence> => spaceActivity.presence,+ ],+ // One object per space that changes only when its inputs do, so the hover card's payload stays stable.+ spacePreviews: [+ (s) => [s.visibleSpaces, s.spaceActivity],+ (visibleSpaces: ChannelDTOApi[], spaceActivity: SpaceActivity): Record<string, TodaySpacePreview> =>+ Object.fromEntries(+ visibleSpaces.map((space) => [+ space.id,+ spacePreview(+ space,+ spaceLabel(space),+ spaceActivity.presence[space.id],+ spaceActivity.lastActivityAt[space.id]+ ),+ ])+ ),+ ],}),listeners(({ actions, values }) => {// Reading a session anywhere in the app clears it, so the rail follows the open session rather than clicks.@@ -683,8 +725,8 @@ export const todaySpacesLogic = kea<todaySpacesLogicType>([actions.loadRecentTasks()// Setup runs now and again whenever the tab comes back, so the faces refresh on return.cache.disposables.add(() => {- actions.loadSpacePresence()- const pollTimer = window.setInterval(() => actions.loadSpacePresence(), SPACE_PRESENCE_POLL_INTERVAL_MS)+ actions.loadSpaceActivity()+ const pollTimer = window.setInterval(() => actions.loadSpaceActivity(), SPACE_PRESENCE_POLL_INTERVAL_MS)return () => clearInterval(pollTimer)}, 'spacePresencePoll')}),diff --git a/frontend/src/layout/today/todayWorkItems.test.ts b/frontend/src/layout/today/todayWorkItems.test.tsindex 806db4935c99..0fba857f9248 100644--- a/frontend/src/layout/today/todayWorkItems.test.ts+++ b/frontend/src/layout/today/todayWorkItems.test.ts@@ -193,4 +193,15 @@ describe('todayWorkItems', () => {expect(activeCloudRunId(item)).toBe(runId)})++ it.each([+ ['the closing message, trimmed', { final_message: ' Opened the pull request.\n' }, 'Opened the pull request.'],+ ['nothing when the run saved no message', { pr_url: 'https://github.com/a/b/pull/1' }, null],+ ['nothing for a blank message', { final_message: ' ' }, null],+ ['nothing for a message that is not text', { final_message: { text: 'hi' } }, null],+ ])('reads %s from the latest run', (_name, output, message) => {+ const item = sessionItem({ id: 's', title: 'Session', latest_run: { output } } as unknown as TaskListItemApi)++ expect(item.finalMessage).toBe(message)+ })})diff --git a/frontend/src/layout/today/todayWorkItems.ts b/frontend/src/layout/today/todayWorkItems.tsindex e7199282098e..55b777e82986 100644--- a/frontend/src/layout/today/todayWorkItems.ts+++ b/frontend/src/layout/today/todayWorkItems.ts@@ -6,6 +6,8 @@ import {TaskActivityDTOApi,TaskActivityReadMarkerApi,TaskListItemApi,+ TaskRunDetailDTOApi,+ TaskUserBasicInfoApi,} from 'products/tasks/frontend/generated/api.schemas'import { TaskPullRequest, taskPullRequests } from 'products/tasks/frontend/spaces/taskPullRequests'@@ -20,6 +22,7 @@ export interface TodayWorkItem {status: string | nullchannel: string | nullcreatedById: number | null+ author: TaskUserBasicInfoApi | nulllatestRunId: string | nullrunEnvironment: string | nulloriginProduct: string | null@@ -27,6 +30,8 @@ export interface TodayWorkItem {source: string | nullrepository: string | nullpullRequests: TaskPullRequest[]+ /** The closing prose a cloud run saves when it finishes. */+ finalMessage: string | null}export interface TodayWorkGroup {@@ -58,6 +63,11 @@ export function activeCloudRunId(item: TodayWorkItem): string | null {: null}+function finalMessage(output: TaskRunDetailDTOApi['output'] | undefined): string | null {+ const message = output?.final_message+ return typeof message === 'string' && message.trim() ? message.trim() : null+}+export function sessionItem(task: TaskListItemApi): TodayWorkItem {return {kind: 'session',@@ -68,12 +78,14 @@ export function sessionItem(task: TaskListItemApi): TodayWorkItem {status: task.latest_run?.status ?? null,channel: task.channel ?? null,createdById: task.created_by?.id ?? null,+ author: task.created_by ?? null,latestRunId: task.latest_run?.id ?? null,runEnvironment: task.latest_run?.environment ?? null,originProduct: task.origin_product ?? null,source: task.origin_product || null,repository: task.repository || null,pullRequests: taskPullRequests(task.latest_run?.output),+ finalMessage: finalMessage(task.latest_run?.output),}}@@ -87,12 +99,14 @@ export function chatItem(conversation: ConversationDetail): TodayWorkItem {status: null,channel: null,createdById: conversation.user?.id ?? null,+ author: null,latestRunId: null,runEnvironment: null,originProduct: null,source: 'posthog_ai',repository: null,pullRequests: [],+ finalMessage: null,}}diff --git a/frontend/src/scenes/project-homepage/today/Today.stories.tsx b/frontend/src/scenes/project-homepage/today/Today.stories.tsxindex 6fb57a1df742..2c11e019fa58 100644--- a/frontend/src/scenes/project-homepage/today/Today.stories.tsx+++ b/frontend/src/scenes/project-homepage/today/Today.stories.tsx@@ -1,16 +1,41 @@import type { Meta, StoryObj } from '@storybook/react'import { within } from '@testing-library/dom'import userEvent from '@testing-library/user-event'+import { ReactNode } from 'react'++import { Card } from '@posthog/quill'import { FEATURE_FLAGS } from 'lib/constants'import { App } from 'scenes/App'import { urls } from 'scenes/urls'+import { sessionPreview, spacePreview } from '~/layout/today/todayPreviewCards'+import { TodaySessionHoverCard } from '~/layout/today/TodaySessionHoverCard'+import { TodaySpaceHoverCard } from '~/layout/today/TodaySpaceHoverCard'+import { sessionItem } from '~/layout/today/todayWorkItems'import { mswDecorator } from '~/mocks/browser'import { EMPTY_PAGINATED_RESPONSE } from '~/mocks/handlers'import { makeReport, mockSignals } from 'products/signals/frontend/inbox/__mocks__/inboxMocks'import { SignalReportStatus } from 'products/signals/frontend/inbox/types'+import { ChannelDTOApi, TaskListItemApi } from 'products/tasks/frontend/generated/api.schemas'++const ADA = {+ id: 1,+ uuid: 'user-ada',+ distinct_id: 'user-ada',+ first_name: 'Ada',+ last_name: 'Lovelace',+ email: '[email protected]',+}+const GRACE = {+ id: 7,+ uuid: 'user-grace',+ distinct_id: 'user-grace',+ first_name: 'Grace',+ last_name: 'Hopper',+ email: '[email protected]',+}const SPACES = [{@@ -43,6 +68,7 @@ const SPACES = [repositories: ['example-org/web', 'example-org/billing'],auto_archive_after_days: null,created_at: '2026-09-02T09:00:00Z',+ created_by: ADA,starred: true,system_role: null,},@@ -374,3 +400,60 @@ export const NarrowWindowWithSidebar: Story = {await userEvent.click(await within(canvasElement).findByLabelText('Home'))},}++// The card opens on hover, which a static story can't hold, so these render its contents in the same frame.+function HoverCardFrame({ children }: { children: ReactNode }): JSX.Element {+ return (+ <div className="p-4">+ <Card size="sm" className="w-72 gap-0 border border-border py-0 shadow-md">+ {children}+ </Card>+ </div>+ )+}++export const SessionHoverCard: Story = {+ render: () => (+ <HoverCardFrame>+ <TodaySessionHoverCard+ preview={sessionPreview(+ sessionItem({+ ...RECENT_SESSIONS[1],+ latest_run: {+ ...RECENT_SESSIONS[1].latest_run,+ output: {+ pr_url: 'https://github.com/example-org/webapp/pull/421',+ final_message:+ 'The webhook now retries three times with a backoff. I opened a pull request with the change and a test for the failure case.',+ },+ },+ } as unknown as TaskListItemApi),+ {+ unread: false,+ pinned: true,+ pullRequestStates: { 'https://github.com/example-org/webapp/pull/421': 'merged' },+ spaceNames: { 'space-checkout': 'checkout' },+ }+ )}+ />+ </HoverCardFrame>+ ),+}++export const SpaceHoverCard: Story = {+ render: () => (+ <HoverCardFrame>+ <TodaySpaceHoverCard+ preview={spacePreview(+ {+ ...SPACES[2],+ repositories: ['example-org/web', 'example-org/billing', 'example-org/api', 'example-org/docs'],+ } as ChannelDTOApi,+ 'checkout',+ { people: [GRACE, ADA], liveUuids: [GRACE.uuid] },+ '2026-09-28T18:28:00Z'+ )}+ />+ </HoverCardFrame>+ ),+}diff --git a/products/tasks/frontend/spaces/SpacePresenceAvatars.tsx b/products/tasks/frontend/spaces/SpacePresenceAvatars.tsxindex 1cb8137e8179..9e8b99c20d52 100644--- a/products/tasks/frontend/spaces/SpacePresenceAvatars.tsx+++ b/products/tasks/frontend/spaces/SpacePresenceAvatars.tsx@@ -1,13 +1,28 @@+import { IconCrown } from '@posthog/icons'import { AvatarGroup, Tooltip, TooltipContent, TooltipTrigger } from '@posthog/quill'import { SpacePresence } from './spacePresence'import { TaskUserAvatar, taskUserName } from './TaskUserAvatar'+function personLabel(name: string, creator: boolean, live: boolean): string {+ if (creator) {+ return live ? `${name} created this space and is working here now` : `${name} created this space`+ }+ return live ? `${name} is working here now` : name+}+/**- * Who has been active in a space lately, like PostHog Desktop. A pulsing dot marks who is working right now.+ * Who has been active in a space lately, like PostHog Desktop. A pulsing dot marks who is working right now,+ * and a crown marks the creator when `creatorUuid` is given.* The newest person sits on top at the right, so their dot shows; the stack tucks the others behind them.*/-export function SpacePresenceAvatars({ presence }: { presence: SpacePresence }): JSX.Element | null {+export function SpacePresenceAvatars({+ presence,+ creatorUuid = null,+}: {+ presence: SpacePresence+ creatorUuid?: string | null+}): JSX.Element | null {if (!presence.people.length) {return null}@@ -15,13 +30,20 @@ export function SpacePresenceAvatars({ presence }: { presence: SpacePresence }):<AvatarGroup stacked reverse size="xs" data-attr="today-space-presence">{[...presence.people].reverse().map((person) => {const live = presence.liveUuids.includes(person.uuid)- const label = live ? `${taskUserName(person)} is working here now` : taskUserName(person)+ const creator = person.uuid === creatorUuid+ const label = personLabel(taskUserName(person), creator, live)return (<Tooltip key={person.uuid}><TooltipTriggerrender={<span role="img" aria-label={label} className="relative flex shrink-0" />}><TaskUserAvatar user={person} />+ {creator && (+ // Top left: the stack covers each face's right side, and the live dot takes the bottom right.+ <span className="absolute -top-1 -left-1 flex rounded-full bg-card p-px">+ <IconCrown className="size-2 text-foreground" />+ </span>+ )}{live && (<span className="absolute right-0 bottom-0 flex size-2 items-center justify-center"><span className="absolute inline-flex size-full animate-ping rounded-full bg-primary opacity-75" />diff --git a/products/tasks/frontend/spaces/SpacesIndexRow.tsx b/products/tasks/frontend/spaces/SpacesIndexRow.tsxindex 1e8ef2612474..7ae2a888aa47 100644--- a/products/tasks/frontend/spaces/SpacesIndexRow.tsx+++ b/products/tasks/frontend/spaces/SpacesIndexRow.tsx@@ -1,11 +1,12 @@import { useActions, useValues } from 'kea'-import { IconLock, IconStar, IconStarFilled } from '@posthog/icons'+import { IconStar, IconStarFilled } from '@posthog/icons'import { Button, Text, Tooltip, TooltipContent, TooltipTrigger } from '@posthog/quill'import { LinkPrimitive } from 'lib/lemon-ui/Link'import { urls } from 'scenes/urls'+import { TodaySpaceGlyph } from '~/layout/today/TodaySpaceGlyph'import { isLockedSpace, spaceLabel } from '~/layout/today/todaySpacesLogic'import { ChannelDTOApi } from '../generated/api.schemas'@@ -28,7 +29,7 @@ export function SpacesIndexRow({ space }: { space: ChannelDTOApi }): JSX.Elementdata-attr="today-spaces-index-row"><span className="flex size-4 shrink-0 items-center justify-center text-muted-foreground" aria-hidden>- {isLockedSpace(space) ? <IconLock /> : <span className="font-mono">#</span>}+ <TodaySpaceGlyph locked={isLockedSpace(space)} /></span><span className="shrink-0 truncate font-medium">{spaceLabel(space)}</span><Text render={<span />} size="xs" variant="muted" className="min-w-0 flex-1 truncate">diff --git a/products/tasks/frontend/spaces/spacePresence.test.ts b/products/tasks/frontend/spaces/spacePresence.test.tsindex fc11964a2d17..58f20fcc7c76 100644--- a/products/tasks/frontend/spaces/spacePresence.test.ts+++ b/products/tasks/frontend/spaces/spacePresence.test.ts@@ -1,5 +1,5 @@import { TaskUserBasicInfoApi } from '../generated/api.schemas'-import { presenceBySpace } from './spacePresence'+import { lastActivityBySpace, presenceBySpace } from './spacePresence'const NOW = Date.parse('2026-09-28T18:30:00Z')@@ -24,7 +24,7 @@ const task = (archived,})-describe('presenceBySpace', () => {+describe('spacePresence', () => {test.each([{name: 'orders people newest first and marks only those active in the last 3 minutes as live',@@ -54,7 +54,7 @@ describe('presenceBySpace', () => {'space-b': { people: ['grace'], liveUuids: [] },},},- ])('$name', ({ tasks, expected }) => {+ ])('presenceBySpace $name', ({ tasks, expected }) => {const result = presenceBySpace(tasks, NOW)const simplified = Object.fromEntries(Object.entries(result).map(([space, presence]) => [@@ -64,4 +64,22 @@ describe('presenceBySpace', () => {)expect(simplified).toEqual(expected)})++ test.each([+ {+ name: 'keeps the newest activity per space, whatever the page order',+ tasks: [task('ada', 300), task('grace', 5), task('ada', 60, 'space-b')],+ expected: { 'space-a': 5, 'space-b': 60 },+ },+ {+ name: 'counts old activity and tasks without an author, but not archived or loose tasks',+ tasks: [task(null, 600), task('gone', 1, 'space-a', true), task('loose', 1, null)],+ expected: { 'space-a': 600 },+ },+ ])('lastActivityBySpace $name', ({ tasks, expected }) => {+ const minutesAgo = Object.fromEntries(+ Object.entries(lastActivityBySpace(tasks)).map(([space, at]) => [space, (NOW - Date.parse(at)) / 60_000])+ )+ expect(minutesAgo).toEqual(expected)+ })})diff --git a/products/tasks/frontend/spaces/spacePresence.ts b/products/tasks/frontend/spaces/spacePresence.tsindex 56f543d2a470..cc05b8db1e11 100644--- a/products/tasks/frontend/spaces/spacePresence.ts+++ b/products/tasks/frontend/spaces/spacePresence.ts@@ -25,6 +25,29 @@ export interface SpacePresence {type PresenceTask = Pick<TaskListItemApi, 'created_by' | 'last_activity_at' | 'channel' | 'archived'>+/** What one page of the team's newest tasks says about each space. */+export interface SpaceActivity {+ presence: Record<string, SpacePresence>+ /** When someone last worked in each space. A space with no task on the page has no entry. */+ lastActivityAt: Record<string, string>+}++/** The newest activity in each space, keyed by space id. Archived sessions don't count. */+export function lastActivityBySpace(tasks: readonly PresenceTask[]): Record<string, string> {+ const result: Record<string, string> = {}+ for (const task of tasks) {+ const ts = task.last_activity_at ? Date.parse(task.last_activity_at) : Number.NaN+ if (!task.channel || task.archived || Number.isNaN(ts)) {+ continue+ }+ const current = result[task.channel]+ if (!current || Date.parse(current) < ts) {+ result[task.channel] = task.last_activity_at as string+ }+ }+ return result+}+/*** The recently active people in each space, keyed by space id, from one page of the team's tasks.* A space with nobody recent has no entry.