Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
feat(pet): open the reply history above a toggle that keeps its place (#2814)
Max418b85153bdb
diff --git a/docs/plans/2026-10-12-desktop-mini-main-agent.md b/docs/plans/2026-10-12-desktop-mini-main-agent.mdindex 951850c40..2c2aff683 100644--- a/docs/plans/2026-10-12-desktop-mini-main-agent.md+++ b/docs/plans/2026-10-12-desktop-mini-main-agent.md@@ -167,6 +167,16 @@ previous main detail behavior:uncertain-send notices, and Open in Avibe;- the document-wide send lock and authorization/session epoch fencing.+The detail opens **above** the toggle row (speaker row and summary line) and+grows upward. The toggle row stays at the bubble's bottom and keeps its screen+position in both states, so collapsing needs no mouse travel; the bubble's+bottom edge and tail never move. The toggle stays first in the DOM, so focus+order is unchanged; CSS places the detail above it, and the toggle's+`aria-controls` names the detail. The divider sits between the history and the+toggle row. On open the history shows the newest result, which is closest to+the toggle row, with the §7.5 edge fades. Quick replies, Vault handoffs, notices and Open in+Avibe follow it at the end of the detail, right above the toggle row. Collapsed shows an up chevron and expanded a down chevron.+Detail retains the 280ms grid / 200ms opacity transition and closes on stackcollapse. Its own scroll region fits the existing window; opening it neverresizes the avatar or the 292px activity scroll box. Input and dictation hidediff --git a/ui/e2e/pet-mini/fixture.tsx b/ui/e2e/pet-mini/fixture.tsxindex f876c8a86..59f84566b 100644--- a/ui/e2e/pet-mini/fixture.tsx+++ b/ui/e2e/pet-mini/fixture.tsx@@ -34,6 +34,7 @@ declare global {petFixtureSends: { sessionId: string; payload: unknown }[];petFixtureOpens: string[];petFixtureStops: unknown[];+ petFixtureMarkReads: string[];petFixtureMainReads: number;setPetMainAvailable: (available: boolean) => void;petFixtureConnection: (connected: boolean) => void;@@ -44,18 +45,27 @@ petBridge.setHitRegions = async (rects) => { window.petLayoutHitRegions = rects;window.petFixtureSends = [];window.petFixtureOpens = [];window.petFixtureStops = [];+window.petFixtureMarkReads = [];petBridge.open = async (link) => { window.petFixtureOpens.push(link); };const hasMain = params.get('main') !== 'false';const layers = Number(params.get('layers') ?? 3);const personal = params.get('scenario') === 'personal';const historyActions = params.get('history') === 'actions';+// Earlier turns that overflow the history box, with the latest reply unread.+const historyLong = params.get('history') === 'long';const title = personal ? '检查桌宠 mini 的交互' : 'A long unbroken title '.repeat(40);const session = {id: 'ses_main', scope_id: 'fixture', title, agent_backend: 'codex',capabilities: { can_chat: true },status: 'active', visibility: 'foreground', agent_status: 'idle', metadata: {},};-const messages = hasMain ? [{+const earlier = historyLong ? Array.from({ length: 6 }, (_, i) => ({+ id: `earlier_${i}`, session_id: session.id, scope_id: session.scope_id,+ author: i % 2 ? 'agent' : 'user', type: i % 2 ? 'result' : 'user',+ text: i % 2 ? `第 ${i} 轮的回复。`.repeat(6) : `第 ${i} 轮的问题`, metadata: {}, content: {},+ created_at: `2026-10-11T00:00:0${i}Z`, updated_at: `2026-10-11T00:00:0${i}Z`, read_at: '2026-10-11T00:00:09Z',+})) : [];+const messages = hasMain ? [...earlier, {id: 'user', session_id: session.id, scope_id: session.scope_id,author: 'user', type: 'user', text: title, metadata: {}, content: {},created_at: '2026-10-12T00:00:00Z', updated_at: '2026-10-12T00:00:00Z',@@ -63,7 +73,7 @@ const messages = hasMain ? [{id: 'result', session_id: session.id, scope_id: session.scope_id,author: 'agent', type: 'result',text: personal ? '我会帮你跟进各个项目。需要授权的事已经排在前面。' : 'Ready to help with your next task.',- metadata: {}, content: historyActions ? { quick_replies: ['继续', '稍后'] } : {}, read_at: '2026-10-12T00:00:01Z',+ metadata: {}, content: historyActions ? { quick_replies: ['继续', '稍后'] } : {}, read_at: historyLong ? null : '2026-10-12T00:00:01Z',created_at: '2026-10-12T00:00:01Z', updated_at: '2026-10-12T00:00:01Z',}] : [];const agents = Array.from({ length: Number(params.get('activities') ?? layers + 1) }, (_, i) => ({@@ -111,7 +121,10 @@ window.fetch = async (input, init) => {return json({ ok: true });}if (path.endsWith('/turn-state') && !path.includes('ses_main')) return json({ in_flight: true, foreground: 'running' });- if (path.endsWith('/mark-read')) return json({ updated: 1, unread_by_session: unread });+ if (path.endsWith('/mark-read')) {+ window.petFixtureMarkReads.push(path.split('/')[3]);+ return json({ updated: 1, unread_by_session: unread });+ }const payloads: Record<string, unknown> = {'/api/csrf-token': { csrf_token: 'fixture-only-token' },'/api/config': { mode: 'self_host', setup_state: { needs_setup: false } },diff --git a/ui/e2e/pet-mini/layout.spec.ts b/ui/e2e/pet-mini/layout.spec.tsindex f081e6159..f897c64fc 100644--- a/ui/e2e/pet-mini/layout.spec.ts+++ b/ui/e2e/pet-mini/layout.spec.ts@@ -514,3 +514,56 @@ test('the reply bubble tail starts on the bubble border instead of poking aboveexpect(tail.bottom).toBe(-tail.height / 2);expect(tail.clip).toBe('polygon(100% 0px, 100% 100%, 0px 100%)');});++for (const theme of ['light', 'dark']) {+ test(`history opens above a toggle that keeps its place (${theme})`, async ({ page }) => {+ await page.goto('/e2e/pet-mini/fixture.html?scenario=personal&lang=zh&history=long');+ await page.evaluate((theme) => { document.documentElement.dataset.theme = theme; }, theme);+ const settle = () => page.evaluate(async () => {+ await Promise.all(document.getAnimations()+ .filter((animation) => animation.effect?.getTiming().iterations !== Infinity)+ .map((animation) => animation.finished.catch(() => {})));+ });+ const toggle = page.locator('.pet-mini-reply-toggle');+ const detail = page.locator('.pet-mini-reply-bubble .pet-mini-detail');+ const history = page.locator('.pet-mini-bubble-history');+ const near = (a: { x: number; y: number; width: number; height: number } | null, b: typeof a) => {+ for (const key of ['x', 'y', 'width', 'height'] as const) expect(Math.abs(a![key] - b![key])).toBeLessThanOrEqual(1);+ };+ await expect(toggle).toBeVisible();+ await settle();+ const collapsed = await toggle.boundingBox();+ expect(await toggle.getAttribute('aria-controls')).toBe(await detail.getAttribute('id'));+ await expect(toggle.locator('svg')).toHaveClass(/lucide-chevron-up/);+ await expect(toggle.locator('svg')).toHaveCSS('transform', 'none');+ expect(await page.evaluate(() => window.petFixtureMarkReads)).toEqual([]);++ await toggle.click();+ await expect(detail).toHaveClass(/is-open/);+ await settle();+ near(await toggle.boundingBox(), collapsed);+ // Opening upward: the history sits entirely above the toggle row.+ const box = (await history.boundingBox())!;+ expect(box.y + box.height).toBeLessThanOrEqual(collapsed!.y + 1);+ expect(box.y).toBeGreaterThanOrEqual(0);+ // The newest result is shown on open, so the earlier turns sit scrolled+ // away under the top edge fade.+ // It must also sit clear of both edge fades, not merely inside the box.+ const last = (await history.locator('.pet-mini-detail-result').last().boundingBox())!;+ const fades = await history.evaluate((node) => ({+ top: Math.min(32, node.scrollTop),+ bottom: Math.min(32, node.scrollHeight - node.clientHeight - node.scrollTop),+ }));+ expect(fades.top).toBeGreaterThan(0);+ expect(last.y).toBeGreaterThanOrEqual(box.y + fades.top - 1);+ expect(last.y + last.height).toBeLessThanOrEqual(box.y + box.height - fades.bottom + 1);+ expect(await history.evaluate((node) => /#000 [1-9]\d*px|rgb\(0, 0, 0\) [1-9]\d*px/.test(node.style.maskImage || node.style.webkitMaskImage))).toBe(true);+ await expect(toggle.locator('svg')).not.toHaveCSS('transform', 'none');+ await expect.poll(() => page.evaluate(() => window.petFixtureMarkReads)).toEqual(['ses_main']);++ await toggle.click();+ await expect(detail).not.toHaveClass(/is-open/);+ await settle();+ near(await toggle.boundingBox(), collapsed);+ });+}diff --git a/ui/src/pet/PetPage.tsx b/ui/src/pet/PetPage.tsxindex 6ec20bfa2..5eafa57c5 100644--- a/ui/src/pet/PetPage.tsx+++ b/ui/src/pet/PetPage.tsx@@ -1,7 +1,7 @@-import { useCallback, useEffect, useMemo, useRef, useState, useLayoutEffect, type CSSProperties, type ReactNode } from 'react';+import { useCallback, useEffect, useId, useMemo, useRef, useState, useLayoutEffect, type CSSProperties, type ReactNode } from 'react';import { useTranslation } from 'react-i18next';import clsx from 'clsx';-import { ChevronRight, ExternalLink, KeyRound, X } from 'lucide-react';+import { ChevronUp, ExternalLink, KeyRound, X } from 'lucide-react';import { ApiError, useApi, type InboxSession, type RunningAgent, type VaultRequest, type WorkbenchMessage } from '@/context/ApiContext';import { useInstanceAuthorization } from '@/context/InstanceAuthorizationContext';@@ -1016,29 +1016,37 @@ const CollapsedCards: React.FC<{ cards: PetCard[]; onOpen: () => void; t: (key:);};-const ExpandedCards: React.FC<{ cards: PetCard[]; leaving: string[]; onReference: (card: PetCard) => void; onDismiss: (card: PetCard) => void; stops: Record<string, StopPhase>; onStop: (card: PetCard) => void; t: (key: string, options?: Record<string, unknown>) => string }> = ({ cards, leaving, onReference, onDismiss, stops, onStop, t }) => {- const scrollRef = useRef<HTMLDivElement>(null);+/**+ * Scroll edge fades (spec §7.5): each edge fades only once there is content+ * past it. Recomputed on scroll and whenever the box or its content resizes.+ */+function useScrollEdgeFade(contentKey: unknown) {+ const ref = useRef<HTMLDivElement>(null);const [edges, setEdges] = useState({ top: 0, bottom: 0 });const measure = useCallback(() => {- const node = scrollRef.current;+ const node = ref.current;if (!node) return;setEdges({ top: Math.min(FADE_PX, Math.max(0, node.scrollTop)), bottom: Math.min(FADE_PX, Math.max(0, node.scrollHeight - node.clientHeight - node.scrollTop)) });}, []);useEffect(() => {- const node = scrollRef.current;+ const node = ref.current;if (!node) return undefined;measure();if (typeof ResizeObserver === 'undefined') return undefined;const observer = new ResizeObserver(measure);observer.observe(node);- const list = node.querySelector('.pet-mini-list');- if (list) observer.observe(list);+ for (const child of node.children) observer.observe(child);return () => observer.disconnect();- }, [measure, cards.length]);+ }, [measure, contentKey]);const mask = `linear-gradient(to bottom, transparent 0, #000 ${edges.top}px, #000 calc(100% - ${edges.bottom}px), transparent 100%)`;+ return { ref, measure, style: { maskImage: mask, WebkitMaskImage: mask } satisfies CSSProperties };+}++const ExpandedCards: React.FC<{ cards: PetCard[]; leaving: string[]; onReference: (card: PetCard) => void; onDismiss: (card: PetCard) => void; stops: Record<string, StopPhase>; onStop: (card: PetCard) => void; t: (key: string, options?: Record<string, unknown>) => string }> = ({ cards, leaving, onReference, onDismiss, stops, onStop, t }) => {+ const { ref: fadeRef, measure: measureFade, style: fadeStyle } = useScrollEdgeFade(cards.length);return (<div className="pet-mini-panel">- <div ref={scrollRef} onScroll={measure} className="pet-mini-scroll" style={{ maskImage: mask, WebkitMaskImage: mask }}>+ <div ref={fadeRef} onScroll={measureFade} className="pet-mini-scroll" style={fadeStyle}><ul className="pet-mini-list">{cards.map((card) => {const phase = stops[card.id];@@ -1103,15 +1111,20 @@ const MainReplyBubble: React.FC<Omit<MainDetailProps, 'visible'> & { open: boole: props.failure ? `${t('pet.failedPrefix')} ${props.failure.text.trim()}`: last?.text?.trim() ? t('pet.repliedPrefix', { text: last.text.trim() }): t('pet.waiting');+ const detailId = useId();+ const { ref: fadeRef, measure: measureFade, style: fadeStyle } = useScrollEdgeFade(open);+ // The toggle stays first in the DOM, so focus order is unchanged, but the+ // bubble lays out bottom-up: the toggle keeps its place at the bottom and+ // the history opens above it, so expanding never moves what was clicked.return (- <div className="pet-mini-reply-bubble" data-pet-hit>- <button type="button" className="pet-mini-reply-toggle" onClick={onToggle} aria-expanded={open}>- <span className="pet-mini-bubble-speaker">{t('pet.mainAgent')}<span>{t(open ? 'pet.collapseHistory' : 'pet.recentTurns')}<ChevronRight size={11} /></span></span>+ <div className="pet-mini-reply-bubble is-main" data-pet-hit>+ <button type="button" className="pet-mini-reply-toggle" onClick={onToggle} aria-expanded={open} aria-controls={detailId}>+ <span className="pet-mini-bubble-speaker">{t('pet.mainAgent')}<span>{t(open ? 'pet.collapseHistory' : 'pet.recentTurns')}<ChevronUp size={11} /></span></span><p title={summary}>{props.running && <span className="pet-mini-running-dot" aria-hidden />}<span className="pet-mini-reply-summary">{summary}</span></p></button>- <div className={clsx('pet-mini-detail', open && 'is-open')}>+ <div id={detailId} className={clsx('pet-mini-detail', open && 'is-open')}><div className="pet-mini-detail-clip" inert={!open || undefined}>- <div className="pet-mini-bubble-history"><MainDetail {...props} visible={open} /></div>+ <div ref={fadeRef} onScroll={measureFade} className="pet-mini-bubble-history" style={fadeStyle}><MainDetail {...props} visible={open} /></div></div></div></div>@@ -1127,7 +1140,11 @@ const MainDetail: React.FC<MainDetailProps> = (props) => {if (!props.visible) return;const result = lastResultRef.current;const history = result?.closest<HTMLElement>('.pet-mini-bubble-history');- if (result && history) history.scrollTop = result.offsetTop + result.offsetHeight - history.clientHeight;+ // Open at the end, where the newest result sits right above its actions and+ // the toggle row. If the result and its actions do not fit, start at the+ // result instead, just past the top edge fade, so it is read from its first+ // line rather than from under the fade.+ if (result && history) history.scrollTop = Math.max(0, Math.min(history.scrollHeight - history.clientHeight, result.offsetTop - FADE_PX));}, [props.visible, resultKey]);useEffect(() => {const node = lastResultRef.current;diff --git a/ui/src/pet/pet-mini.css b/ui/src/pet/pet-mini.cssindex 0f2271880..a0d248efa 100644--- a/ui/src/pet/pet-mini.css+++ b/ui/src/pet/pet-mini.css@@ -781,6 +781,25 @@ to {clip-path:polygon(100% 0,100% 100%,0 100%);transform:rotate(45deg);pointer-events:none}+/* The main bubble lays out bottom-up (the toggle is first in the DOM for focus+ order): the toggle row holds its place at the bottom and the history opens+ above it. The divider sits on the clip, outside the history's edge-fade+ mask, so it stays crisp and collapses away with the detail. */+.pet-mini-reply-bubble.is-main {+ display:flex;+ flex-direction:column-reverse}+.pet-mini-reply-bubble.is-main .pet-mini-detail-clip {+ position:relative}+.pet-mini-reply-bubble.is-main .pet-mini-detail-clip:after {+ position:absolute;+ z-index:2;+ right:0;+ bottom:0;+ left:0;+ height:1px;+ background:color-mix(in srgb,var(--pet-ink) 8%,transparent);+ content:"";+ pointer-events:none}.pet-mini-reply-toggle {display:block;width:100%;@@ -803,7 +822,7 @@ to {color:color-mix(in srgb,var(--pet-ink) 60%,transparent);font-size:10px;font-weight:400}-.pet-mini-reply-toggle[aria-expanded=true] svg { transform:rotate(90deg) }+.pet-mini-reply-toggle[aria-expanded=true] svg { transform:rotate(180deg) }.pet-mini-reply-toggle p {display:flex;align-items:center;@@ -822,12 +841,14 @@ to {.pet-mini-bubble-history {position:relative;z-index:1;+ border-radius:21px 21px 0 0;/* Share the list's 292px box, bounded by the fixed avatar/dock reservation(147px), bubble header (62px), top inset (16px), and measured stack. */max-height:min(292px,max(0px,calc(100dvh - 225px - var(--pet-collapsed-height,0px))));overflow:auto;overscroll-behavior:contain;- border-top:1px solid color-mix(in srgb,var(--pet-ink) 8%,transparent);scrollbar-width:thin}-.pet-mini-bubble-history .pet-mini-detail-inner { padding:8px 14px }+/* The history's top edge is now the bubble's rounded top, so it gets more room+ than the bottom edge, which meets the divider. */+.pet-mini-bubble-history .pet-mini-detail-inner { padding:12px 14px 8px }.pet-mini-swap:has(.pet-mini-collapsed) { padding-bottom:14px }