Skip to content

The agent that grows with you

feat(desktop): show messages below the thread viewport

brooklyn!342f76a7c263
diff --git a/apps/desktop/DESIGN.md b/apps/desktop/DESIGN.md
index a1c33275b9b..499d836b4d5 100644
--- a/apps/desktop/DESIGN.md
+++ b/apps/desktop/DESIGN.md
@@ -277,6 +277,8 @@ Sizes: `default`, `xs`, `overlay` (titlebar glyph counts).
- Visible windows keep animating when another app takes focus. Hidden/minimized
windows and inactive panes may pause; background polling stays focus-gated.
+- Animated integer counts reuse `AnimatedInt` in `src/components/ui/diff-count.tsx`.
+ Its spring updates the DOM directly without per-frame React renders.
- Quick, functional transitions (~100ms on controls). Respect
`prefers-reduced-motion` for anything beyond a fade.
- Choreographed exits (e.g. onboarding's "matrix" fade-down) stagger per-element
diff --git a/apps/desktop/src/app/chat/scroll-to-bottom-button.tsx b/apps/desktop/src/app/chat/scroll-to-bottom-button.tsx
index 85d01cb7008..ca12ef0e424 100644
--- a/apps/desktop/src/app/chat/scroll-to-bottom-button.tsx
+++ b/apps/desktop/src/app/chat/scroll-to-bottom-button.tsx
@@ -1,12 +1,14 @@
import { useStore } from '@nanostores/react'
+import { useReducedMotion } from 'motion/react'
import { useRef } from 'react'
import { Codicon } from '@/components/ui/codicon'
+import { AnimatedInt } from '@/components/ui/diff-count'
import { useI18n } from '@/i18n'
import { triggerHaptic } from '@/lib/haptics'
import { cn } from '@/lib/utils'
import { $approvalRequest } from '@/store/prompts'
-import { $threadJumpButtonVisible, requestScrollToBottom } from '@/store/thread-scroll'
+import { $threadJumpButtonVisible, $threadMessagesBelow, requestScrollToBottom } from '@/store/thread-scroll'
/**
* Floating "jump to bottom" control. Sits centered just above the composer,
@@ -14,7 +16,8 @@ import { $threadJumpButtonVisible, requestScrollToBottom } from '@/store/thread-
* the thread's bottom clearance uses (`--composer-measured-height`, which
* covers the whole dock), so it never overlaps the queue / subagent
* / background cards. Visible only while the user has scrolled meaningfully
- * away from the bottom; clicking re-arms sticky-bottom and pins the viewport.
+ * away from the bottom, with an animated count of messages below the viewport.
+ * Clicking re-arms sticky-bottom and pins the viewport.
*
* When the turn is BLOCKED on an approval, this same control morphs into an
* "Approval needed" pill — the only response surface is the inline Run/Reject
@@ -31,6 +34,8 @@ import { $threadJumpButtonVisible, requestScrollToBottom } from '@/store/thread-
export function ScrollToBottomButton({ sessionId }: { sessionId: string | null }) {
const { t } = useI18n()
const visible = useStore($threadJumpButtonVisible)
+ const count = useStore($threadMessagesBelow)
+ const reducedMotion = useReducedMotion()
const request = useStore($approvalRequest)
// Scrolled away while an approval is pending → the inline Run/Reject bar is
// below the fold. Relabel so the user knows the session needs them, not just
@@ -43,17 +48,22 @@ export function ScrollToBottomButton({ sessionId }: { sessionId: string | null }
}
const state = visible ? 'in' : hasShownRef.current ? 'out' : 'idle'
- const label = approval ? t.assistant.approval.jumpToApproval : t.assistant.thread.scrollToBottom
+ const countLabel = t.sidebar.messageCount(count)
+ const [beforeCount, afterCount] = countLabel.split(String(count))
+
+ const label = approval
+ ? t.assistant.approval.jumpToApproval
+ : `${t.assistant.thread.scrollToBottom} · ${countLabel}`
return (
<button
aria-hidden={!visible}
aria-label={label}
className={cn(
- 'thread-jump-button absolute left-1/2 z-20 grid place-items-center backdrop-blur-[0.75rem] [-webkit-backdrop-filter:blur(0.75rem)]',
+ 'thread-jump-button absolute left-1/2 z-20 flex h-8 items-center gap-1.5 rounded-full border bg-(--composer-fill) px-3 text-xs font-medium backdrop-blur-[0.75rem] [-webkit-backdrop-filter:blur(0.75rem)]',
approval
- ? 'h-8 grid-flow-col gap-1.5 rounded-full border border-primary/40 bg-(--composer-fill) px-3 text-primary hover:bg-primary/10'
- : 'size-8 rounded-full border border-border/65 bg-(--composer-fill) text-muted-foreground hover:text-foreground',
+ ? 'border-primary/40 text-primary hover:bg-primary/10'
+ : 'border-border/65 text-muted-foreground hover:text-foreground',
!visible && 'pointer-events-none'
)}
data-state={state}
@@ -62,13 +72,21 @@ export function ScrollToBottomButton({ sessionId }: { sessionId: string | null }
requestScrollToBottom(sessionId)
}}
style={{
- bottom: 'calc(var(--composer-measured-height) + 0.625rem)'
+ bottom: 'calc(var(--composer-measured-height) + 1rem)'
}}
tabIndex={visible ? 0 : -1}
type="button"
>
- <Codicon name="arrow-down" size={approval ? '0.875rem' : '1rem'} />
- {approval && <span className="text-xs font-medium">{label}</span>}
+ <Codicon name="arrow-down" size="0.875rem" />
+ {approval ? (
+ <span>{label}</span>
+ ) : (
+ <span aria-hidden className="whitespace-nowrap tabular-nums">
+ {beforeCount}
+ {!visible || reducedMotion ? count : <AnimatedInt key={sessionId} value={count} />}
+ {afterCount}
+ </span>
+ )}
</button>
)
}
diff --git a/apps/desktop/src/components/assistant-ui/thread/list.tsx b/apps/desktop/src/components/assistant-ui/thread/list.tsx
index e43f10e8646..7aa58a339af 100644
--- a/apps/desktop/src/components/assistant-ui/thread/list.tsx
+++ b/apps/desktop/src/components/assistant-ui/thread/list.tsx
@@ -41,6 +41,7 @@ import { isSecondaryWindow } from '@/store/windows'
import { MessageRenderBoundary } from '../message-render-boundary'
import { resolveShowEarlierAction, useTranscriptWindow } from './transcript-window'
+import { useMessagesBelow } from './use-messages-below'
type ThreadMessageComponents = ComponentProps<typeof ThreadPrimitive.MessageByIndex>['components']
@@ -376,6 +377,7 @@ const TurnRow = memo(function TurnRow({ components, group, resetKey, virtualized
'flex min-w-0 flex-col gap-(--conversation-turn-gap) pb-(--conversation-turn-gap)',
virtualized && '[contain-intrinsic-size:auto_37.5rem] [content-visibility:auto]'
)}
+ data-slot="aui_message-group"
>
<MessageRenderBoundary resetKey={resetKey}>
{group.kind === 'turn' ? (
@@ -990,6 +992,8 @@ const ThreadMessageListInner: FC<ThreadMessageListProps> = ({
[visibleGroups, components, structuralSignature, tailStart]
)
+ useMessagesBelow({ contentRef, scrollRef, isAtBottom, paneVisible, rows, sessionKey })
+
return (
<div
className="relative min-h-0 max-w-full overflow-hidden contain-[layout_paint]"
diff --git a/apps/desktop/src/components/assistant-ui/thread/use-messages-below.ts b/apps/desktop/src/components/assistant-ui/thread/use-messages-below.ts
new file mode 100644
index 00000000000..11571b5bb3e
--- /dev/null
+++ b/apps/desktop/src/components/assistant-ui/thread/use-messages-below.ts
@@ -0,0 +1,100 @@
+import { type ReactNode, type RefObject, useEffect } from 'react'
+
+import { publishThreadMessagesBelow } from '@/store/thread-scroll'
+
+const MESSAGE_ROOTS =
+ '[data-slot="aui_user-message-root"], [data-slot="aui_assistant-message-root"], [data-slot="aui_system-message-root"]'
+
+interface MessagesBelowOptions {
+ contentRef: RefObject<HTMLElement | null>
+ scrollRef: RefObject<HTMLElement | null>
+ isAtBottom: boolean
+ paneVisible: boolean
+ rows: ReactNode
+ sessionKey: string | null | undefined
+}
+
+/** Only measure inside the viewport's turn; leave skipped off-screen content asleep. */
+export function countMessagesBelow(viewport: HTMLElement, content: HTMLElement): number {
+ const bottom = viewport.getBoundingClientRect().bottom
+ let count = 0
+
+ for (const group of content.querySelectorAll<HTMLElement>('[data-slot="aui_message-group"]')) {
+ const rect = group.getBoundingClientRect()
+
+ if (rect.bottom <= bottom + 1) {
+ continue
+ }
+
+ const messages = group.querySelectorAll<HTMLElement>(MESSAGE_ROOTS)
+
+ if (rect.top >= bottom) {
+ count += messages.length
+
+ continue
+ }
+
+ for (const message of messages) {
+ const messageRect = message.getBoundingClientRect()
+
+ if (messageRect.height > 0 && messageRect.bottom > bottom + 1) {
+ count++
+ }
+ }
+ }
+
+ return count
+}
+
+export function useMessagesBelow({
+ contentRef,
+ scrollRef,
+ isAtBottom,
+ paneVisible,
+ rows,
+ sessionKey
+}: MessagesBelowOptions) {
+ useEffect(() => {
+ if (!paneVisible) {
+ return
+ }
+
+ if (isAtBottom) {
+ publishThreadMessagesBelow(0, { paneVisible })
+
+ return
+ }
+
+ const viewport = scrollRef.current
+ const content = contentRef.current
+
+ if (!viewport || !content) {
+ return
+ }
+
+ let frame = 0
+
+ const measure = () => {
+ frame = 0
+ publishThreadMessagesBelow(countMessagesBelow(viewport, content), { paneVisible })
+ }
+
+ const schedule = () => {
+ if (!frame) {
+ frame = requestAnimationFrame(measure)
+ }
+ }
+
+ schedule()
+ viewport.addEventListener('scroll', schedule, { passive: true })
+ const observer = new ResizeObserver(schedule)
+ observer.observe(viewport)
+ observer.observe(content)
+
+ return () => {
+ cancelAnimationFrame(frame)
+ viewport.removeEventListener('scroll', schedule)
+ observer.disconnect()
+ }
+ }, [contentRef, scrollRef, isAtBottom, paneVisible, rows, sessionKey])
+}
diff --git a/apps/desktop/src/components/ui/diff-count.tsx b/apps/desktop/src/components/ui/diff-count.tsx
index 8dc10b72d59..196b70da0ed 100644
--- a/apps/desktop/src/components/ui/diff-count.tsx
+++ b/apps/desktop/src/components/ui/diff-count.tsx
@@ -11,7 +11,7 @@ const SPRING = { stiffness: 320, damping: 30, mass: 0.5 } as const
// its value, so mounting/navigating shows it instantly — only a real change to
// the number (a live edit) springs it up/down. Switching threads in the same
// worktree (same numbers) therefore doesn't animate.
-function AnimatedInt({ value }: { value: number }) {
+export function AnimatedInt({ value }: { value: number }) {
const spring = useSpring(value, SPRING)
const text = useTransform(spring, latest => Math.round(latest).toString())
diff --git a/apps/desktop/src/store/thread-scroll.ts b/apps/desktop/src/store/thread-scroll.ts
index f7d22e87f38..41397f1c6d7 100644
--- a/apps/desktop/src/store/thread-scroll.ts
+++ b/apps/desktop/src/store/thread-scroll.ts
@@ -19,6 +19,13 @@ import { $activeProfile, normalizeProfileKey } from '@/store/profile'
// scroll every mounted transcript.
export const $threadScrolledUp = atom(false)
export const $threadJumpButtonVisible = atom(false)
+export const $threadMessagesBelow = atom(0)
+
+export const publishThreadMessagesBelow = (count: number, publisher: { paneVisible: boolean }): void => {
+ if (publisher.paneVisible && $threadMessagesBelow.get() !== count) {
+ $threadMessagesBelow.set(count)
+ }
+}
// Skip no-op writes so subscribers don't churn on every scroll tick.
const setter = (target: WritableAtom<boolean>) => (value: boolean) => {
@@ -35,7 +42,10 @@ export const setThreadAtBottom = (isAtBottom: boolean) => {
setJumpButtonVisible(!isAtBottom)
}
-export const resetThreadScroll = () => setThreadAtBottom(true)
+export const resetThreadScroll = () => {
+ setThreadAtBottom(true)
+ $threadMessagesBelow.set(0)
+}
export const publishThreadAtBottom = (isAtBottom: boolean, publisher: { paneVisible: boolean }): void => {
if (!publisher.paneVisible) {