Skip to content

armgit / avibe

Public Imported from GitHub
0

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.

feat(pet): show Vibey's bubble only while active, and open the history from Vibey (#2852)

Max1f8d600784e6
diff --git a/docs/plans/2026-10-12-desktop-mini-main-agent.md b/docs/plans/2026-10-12-desktop-mini-main-agent.md
index d3354ede3..766604b79 100644
--- a/docs/plans/2026-10-12-desktop-mini-main-agent.md
+++ b/docs/plans/2026-10-12-desktop-mini-main-agent.md
@@ -28,7 +28,7 @@ Status: ready for implementation, v2 (2026-10-12). Supersedes v1 of this file.
stack**. The front card is the **main agent card**: the user's last message
to the main agent, and below it what the agent is doing ("Thinking").
Thin layers under it show that more cards exist.
-2. The user clicks Vibey or the stack. The stack **expands upward** into a
+2. The user clicks the stack. The stack **expands upward** into a
fixed-height, scrollable list. Under the main agent card are the main
agent's **sub-task cards**: delegated runs, watches and scheduled tasks.
Vibey does not move.
@@ -119,10 +119,8 @@ the main agent; there is no Follow up on cards.
A stack needs at least **two** visible cards. **Exactly one** visible card is
never collapsed: it is always drawn in its full expanded form (stop or
authorize, Open in Avibe, × on hover, click to reference) at its own height,
-whatever the panel state. Clicking Vibey does not change it, so Vibey's button
-carries no `aria-expanded` then. With a lone card a Vibey click toggles no
-panel state at all, so nothing waits to appear when a second card arrives: it
-closes an open history (and the panel with it) and otherwise does nothing. All of the card's controls are hit regions in
+whatever the panel state. A Vibey click (§5.1) opens or closes the history
+beside it and never changes the card. All of the card's controls are hit regions in
every panel state. Opening the history keeps the card in full beside it, and
the history's height bound uses the card's measured height. Going between one
and two cards follows the data with the ordinary swap transition.
@@ -144,7 +142,10 @@ and two cards follows the data with the ordinary swap transition.
- When there are at least two cards, the front card's eyebrow row shows a
muted count chip: `N items` in English or `共 N 项` in Chinese. Counts above
99 display as `99+`.
-- The whole stack is one button: a click expands it.
+- The whole stack is one button: a click expands it. It is the only way to
+ expand the cards; Vibey collapses an expanded list but never expands one
+ (§5.1). The expanded list and the open history never show together: opening
+ either closes the other.
## 4. Cards
@@ -168,6 +169,18 @@ slot above the avatar: thinking, delegated-to (only when provenance is known),
then the latest reply. The bubble names Vibey in its existing localized spelling.
It remains available with either the collapsed or expanded stack.
+**When it shows.** Only while Vibey's conversation is active: the turn is
+running or thinking, or a send is pending; Vibey needs the user (a pending
+Vault handoff, a failure notice, an uncertain-send notice, or a queued
+notice); or the history is open. Composing and dictating take the slot as
+before (§5.2). The moment none of these holds, the turn's result arriving
+included, the bubble hides with the speech slot's transition (instant under
+reduced motion), taking no space and no clicks: there is no linger. Unread
+replies only light Vibey's badge, and quick replies stay in the history; to
+read a reply, click Vibey (§5.1). On first load an old, finished exchange
+starts hidden. A new running turn, a new needs-you state or a Vibey click
+that opens the history shows it at once.
+
Click the bubble to expand recent turns from the loaded tail. Preserve all
previous main detail behavior:
@@ -264,7 +277,21 @@ Known data limitations for P1:
### 5.1 Vibey and the dock
-- **Click Vibey:** toggle the stack between collapsed and expanded.
+- **Click Vibey** (a pointer click without hold or drag, or keyboard
+ activation): one step about Vibey's own conversation, in order:
+ - an expanded card list collapses, and nothing else happens;
+ - else an open history closes, and the bubble hides with it unless something
+ else keeps it shown (§4.2);
+ - else, if there is any exchange, the bubble shows with the history open,
+ scrolled to the bottom;
+ - with no messages yet, or while typing or dictating, the click does nothing
+ (the input and its draft are left as they are).
+
+ Every branch leaves the shell's panel state matching what is drawn, so
+ nothing stays expanded out of sight. Vibey's button is labelled "Recent
+ turns", with `aria-expanded` reflecting the open history. It has no tooltip:
+ hovering Vibey already shows the dock, and a tooltip on every hover of the
+ pet would be noise.
- **Press and hold Vibey (≥ 320ms):** start dictation; release to stop.
- A press shorter than 320ms is a click.
- Leaving Vibey before the hold fires cancels the hold.
@@ -310,8 +337,8 @@ Known data limitations for P1:
progress, history, a notice, quick replies or a pending authorization.
Only the highest-priority content is interactive or eligible for mark-read.
- **Mutually exclusive expansion.** Opening "Recent turns" collapses the cards
- into their layered stack. Opening the card stack or clicking Vibey expands
- the cards and closes history. Closing history returns to the collapsed mini.
+ into their layered stack. Opening the card stack expands the cards and closes
+ history. Closing history returns to the collapsed mini.
Both transitions reuse the v2 height/content motion (§7.1, §7.4); reduced
motion switches directly. There is no separate 48–120px history cap.
- **No margin of its own.** The last card's row spacing plus the panel's 6px
@@ -665,7 +692,7 @@ GET /api/sessions/main
are at most three layers, with 9px steps, a `18+6+3i` inset and the
same opacity as the front card. Two or more cards show the count chip,
capped at `99+`.
-- [ ] Clicking Vibey or the stack expands upward (360ms settle, height plus
+- [ ] Clicking the stack expands upward (360ms settle, height plus
content fade); clicking Vibey again collapses.
- [ ] Expanded: fixed 3.5-card box; cards bottom-aligned; overflow scrolls;
scrollbar hidden; 10px top padding.
diff --git a/ui/e2e/pet-mini/fixture.tsx b/ui/e2e/pet-mini/fixture.tsx
index a492f9218..c6921212d 100644
--- a/ui/e2e/pet-mini/fixture.tsx
+++ b/ui/e2e/pet-mini/fixture.tsx
@@ -40,6 +40,7 @@ declare global {
petFixtureConnection: (connected: boolean) => void;
petFixtureMessage: (message: Record<string, unknown>) => void;
petFixtureAddActivity: () => void;
+ petFixtureFinishTurn: (result: Record<string, unknown>) => void;
}
}
window.petLayoutHitRegions = [];
@@ -102,6 +103,7 @@ const unread = personal ? { ses_fixture_2: 1 } : {};
// A legacy file must not steer reads or sends away from main.
localStorage.setItem('avibe.pet.devBinding', JSON.stringify({ binding: 'legacy-session', revision: 1 }));
let mainAvailable = params.get('offline') !== 'true';
+let mainRunning = params.get('running') === '1';
window.petFixtureMainReads = 0;
window.setPetMainAvailable = (available) => { mainAvailable = available; };
@@ -137,11 +139,16 @@ window.fetch = async (input, init) => {
'/api/sessions/ses_main': session,
'/api/sessions/ses_main/messages': { messages, next_after_id: null, next_before_id: null },
'/api/sessions/ses_main/turn-state': {
- foreground: 'idle', in_flight: false, native_turn_started: false, pending_input_count: 0,
+ // `running=1`: Vibey's own turn is in progress until `petFixtureFinishTurn`.
+ foreground: mainRunning ? 'running' : 'idle', in_flight: mainRunning, native_turn_started: false,
+ // `queued=1`: an input waits behind the turn, which keeps Vibey's bubble
+ // shown with the latest reply's summary (the state layout tests draw in).
+ pending_input_count: params.get('queued') === '1' ? 1 : 0,
background_activities: [], pending_activity_output_count: 0, connection: 'connected',
},
'/api/vault/requests': { ok: true, requests: requests.filter((request) => !url.searchParams.get('session') || request.session.id === url.searchParams.get('session')) },
- '/api/asr/status': { available: false },
+ // `asr=1`: voice input is available, so the dock shows its mic.
+ '/api/asr/status': { available: params.get('asr') === '1' },
'/api/running-agents': { ok: true, agents, counts: { total: agents.length, active: agents.length, idle: 0, orphan: 0, by_backend: {} } },
'/api/sessions': { sessions: [session], next_before_id: null },
'/api/inbox': { ok: true, sessions: [], unread_by_session: unread, total_unread: Object.values(unread).reduce((a, b) => a + b, 0), next_before_id: null },
@@ -183,6 +190,20 @@ window.petFixtureAddActivity = () => {
stream.dispatchEvent(new MessageEvent('runs.updated', { data: JSON.stringify({ type: 'runs.updated', data: { run_id: `run_${agents.length}`, status: 'running' } }) }));
}
};
+// End Vibey's running turn with its result, as the event stream reports it.
+window.petFixtureFinishTurn = (result) => {
+ const data = {
+ session_id: session.id, scope_id: session.scope_id, metadata: {}, content: {},
+ created_at: '2026-10-12T00:00:02Z', updated_at: '2026-10-12T00:00:02Z', read_at: '2026-10-12T00:00:03Z',
+ ...result,
+ };
+ mainRunning = false;
+ messages.push(data as unknown as (typeof messages)[number]);
+ for (const stream of streams) {
+ stream.dispatchEvent(new MessageEvent('message.new', { data: JSON.stringify({ type: 'message.new', data }) }));
+ stream.dispatchEvent(new MessageEvent('turn.end', { data: JSON.stringify({ type: 'turn.end', data: { session_id: session.id } }) }));
+ }
+};
const root = createRoot(document.getElementById('root')!);
window.setPetLayoutVisible = (visible) => root.render(
diff --git a/ui/e2e/pet-mini/layout.spec.ts b/ui/e2e/pet-mini/layout.spec.ts
index 433c8c5b6..e1edd723e 100644
--- a/ui/e2e/pet-mini/layout.spec.ts
+++ b/ui/e2e/pet-mini/layout.spec.ts
@@ -3,7 +3,7 @@ import { expect, test } from '@playwright/test';
for (const theme of ['light', 'dark']) {
for (const lang of ['en', 'zh']) {
test(`collapsed bubble spacing and action copy (${theme}, ${lang})`, async ({ page }) => {
- await page.goto(`/e2e/pet-mini/fixture.html?scenario=personal&lang=${lang}`);
+ await page.goto(`/e2e/pet-mini/fixture.html?scenario=personal&lang=${lang}&queued=1`);
await page.evaluate((theme) => { document.documentElement.dataset.theme = theme; }, theme);
await expect(page.locator('.pet-mini-collapsed')).toBeVisible();
await expect(page.locator('.pet-mini-stage')).toHaveCSS('color', theme === 'dark' ? 'rgb(255, 255, 255)' : 'rgb(23, 23, 28)');
@@ -62,7 +62,7 @@ for (const main of [true, false]) {
test(`collapsed layers follow the front height (main=${main}, layers=${layers})`, async ({ page }) => {
const errors: string[] = [];
page.on('pageerror', (error) => errors.push(error.message));
- await page.goto(`/e2e/pet-mini/fixture.html?main=${main}&layers=${layers}`);
+ await page.goto(`/e2e/pet-mini/fixture.html?main=${main}&layers=${layers}&queued=1`);
const renderedLayers = Math.min(layers, 3);
await expect(page.locator('.pet-mini-layer')).toHaveCount(renderedLayers);
// Wait for the real CSS entrance before measuring its transformed bounds.
@@ -150,7 +150,7 @@ for (const theme of ['light', 'dark']) {
}
test('no mini surface casts a shadow the transparent window would clip', async ({ page }) => {
- await page.goto('/e2e/pet-mini/fixture.html?main=true&layers=2&sessions=4');
+ await page.goto('/e2e/pet-mini/fixture.html?main=true&layers=2&sessions=4&queued=1');
await expect(page.locator('.pet-mini-collapsed')).toBeVisible();
// Every mini rule, rendered or not (input bubble, marquee, setup card): the
// window clips a shadow to a visible box while content moves.
@@ -324,7 +324,7 @@ test('attention leads the list and referencing sends only through the main compo
test('reply history and input remain within the fixed window with reduced motion', async ({ page }) => {
await page.emulateMedia({ reducedMotion: 'reduce' });
- await page.goto('/e2e/pet-mini/fixture.html?scenario=personal');
+ await page.goto('/e2e/pet-mini/fixture.html?scenario=personal&queued=1');
await page.locator('.pet-mini-collapsed').click();
const avatar = await page.locator('.pet-mini-avatar-button').boundingBox();
await page.locator('.pet-mini-reply-toggle').click();
@@ -340,7 +340,7 @@ for (const theme of ['light', 'dark']) {
for (const reduced of [false, true]) {
test(`history and cards share expansion with reachable actions (${theme}, reduced=${reduced})`, async ({ page }) => {
await page.emulateMedia({ reducedMotion: reduced ? 'reduce' : 'no-preference' });
- await page.goto('/e2e/pet-mini/fixture.html?scenario=personal&lang=zh&history=actions');
+ await page.goto('/e2e/pet-mini/fixture.html?scenario=personal&lang=zh&history=actions&queued=1');
await page.evaluate((theme) => { document.documentElement.dataset.theme = theme; }, theme);
const avatar = page.locator('.pet-mini-avatar-button');
await expect(avatar).toBeVisible();
@@ -374,9 +374,21 @@ for (const theme of ['light', 'dark']) {
await expect(page.locator('.pet-mini-detail')).not.toHaveClass(/is-open/);
await page.locator('.pet-mini-reply-toggle').click();
await expect(page.locator('.pet-mini-collapsed')).toBeVisible();
+ await expect(page.locator('.pet-mini-detail')).toHaveClass(/is-open/);
+ // Vibey closes the open history, then opens it again with the stack
+ // still collapsed; the stack expands the list and closes the history;
+ // Vibey then collapses the list.
await avatar.click();
+ await expect(page.locator('.pet-mini-detail')).not.toHaveClass(/is-open/);
+ await avatar.click();
+ await expect(page.locator('.pet-mini-detail')).toHaveClass(/is-open/);
+ await expect(page.locator('.pet-mini-collapsed')).toBeVisible();
+ await page.locator('.pet-mini-collapsed').click();
await expect(page.locator('.pet-mini-scroll')).toBeVisible();
await expect(page.locator('.pet-mini-detail')).not.toHaveClass(/is-open/);
+ await avatar.click();
+ await expect(page.locator('.pet-mini-collapsed')).toBeVisible();
+ await expect(page.locator('.pet-mini-detail')).not.toHaveClass(/is-open/);
expect(await avatar.boundingBox()).toEqual(anchor);
});
}
@@ -384,13 +396,13 @@ for (const theme of ['light', 'dark']) {
test('an empty activity stack takes no space while history remains usable without a switcher', async ({ page }) => {
- await page.goto('/e2e/pet-mini/fixture.html?scenario=personal&activities=0');
+ await page.goto('/e2e/pet-mini/fixture.html?scenario=personal&activities=0&queued=1');
await page.locator('.pet-mini-reply-toggle').waitFor();
const avatar = await page.locator('.pet-mini-avatar-button').boundingBox();
+ // With no cards, a Vibey click opens the history straight away.
await page.locator('.pet-mini-avatar-button').click();
await expect(page.locator('.pet-mini-cards')).toHaveCSS('height', '0px');
await expect(page.locator('.pet-mini-panel')).toHaveCount(0);
- await page.locator('.pet-mini-reply-toggle').click();
await expect(page.getByRole('button', { name: 'Switch session' })).toHaveCount(0);
await expect(page.locator('.pet-mini-session-option')).toHaveCount(0);
await expect(page.locator('.pet-mini-detail')).toHaveClass(/is-open/);
@@ -512,7 +524,7 @@ test('the reply bubble tail starts on the bubble border instead of poking above
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.goto('/e2e/pet-mini/fixture.html?scenario=personal&lang=zh&history=long&queued=1');
await page.evaluate((theme) => { document.documentElement.dataset.theme = theme; }, theme);
const settle = () => page.evaluate(async () => {
await Promise.all(document.getAnimations()
@@ -563,7 +575,7 @@ for (const theme of ['light', 'dark']) {
for (const theme of ['light', 'dark']) {
test(`Open in Avibe is an icon pinned to the open history's corner (${theme})`, async ({ page, browserName }) => {
- await page.goto('/e2e/pet-mini/fixture.html?scenario=personal&lang=zh&history=long');
+ await page.goto('/e2e/pet-mini/fixture.html?scenario=personal&lang=zh&history=long&queued=1');
await page.evaluate((theme) => { document.documentElement.dataset.theme = theme; }, theme);
const settle = () => page.evaluate(async () => {
await Promise.all(document.getAnimations()
@@ -627,7 +639,7 @@ for (const theme of ['light', 'dark']) {
}
test('the history fades over a taller, darker band than the card list', async ({ page }) => {
- await page.goto('/e2e/pet-mini/fixture.html?scenario=personal&lang=zh&history=long&activities=8');
+ await page.goto('/e2e/pet-mini/fixture.html?scenario=personal&lang=zh&history=long&activities=8&queued=1');
const mask = (selector: string) => page.locator(selector).evaluate((node) => (node as HTMLElement).style.maskImage || (node as HTMLElement).style.webkitMaskImage);
const scrollTo = (selector: string, where: 'top' | 'middle') => page.locator(selector).evaluate((node, where) => {
node.scrollTop = where === 'top' ? 0 : (node.scrollHeight - node.clientHeight) / 2;
@@ -658,7 +670,7 @@ test('the history fades over a taller, darker band than the card list', async ({
test('the history opens at the bottom and stays pinned there only while the reader is', async ({ page }) => {
// Everything is read, so each live reply replaces the shown one and nothing
// here is about mark-read; the open-once mark-read is covered above.
- await page.goto('/e2e/pet-mini/fixture.html?scenario=personal&lang=zh&history=long&unread=0');
+ await page.goto('/e2e/pet-mini/fixture.html?scenario=personal&lang=zh&history=long&unread=0&queued=1');
const history = page.locator('.pet-mini-bubble-history');
const gap = () => history.evaluate((node) => node.scrollHeight - node.clientHeight - node.scrollTop);
const height = () => history.evaluate((node) => node.scrollHeight);
@@ -689,7 +701,7 @@ test('the history opens at the bottom and stays pinned there only while the read
});
test('a latest reply taller than the history opens at its end', async ({ page }) => {
- await page.goto('/e2e/pet-mini/fixture.html?scenario=personal&lang=zh&reply=long');
+ await page.goto('/e2e/pet-mini/fixture.html?scenario=personal&lang=zh&reply=long&queued=1');
const history = page.locator('.pet-mini-bubble-history');
await page.locator('.pet-mini-reply-toggle').click();
await expect(page.locator('.pet-mini-reply-bubble .pet-mini-detail')).toHaveClass(/is-open/);
@@ -702,7 +714,7 @@ test('a latest reply taller than the history opens at its end', async ({ page })
for (const theme of ['light', 'dark']) {
test(`the open buttons show a pet tooltip on hover and keyboard focus (${theme})`, async ({ page, browserName }) => {
- await page.goto('/e2e/pet-mini/fixture.html?scenario=personal&lang=zh&history=long');
+ await page.goto('/e2e/pet-mini/fixture.html?scenario=personal&lang=zh&history=long&queued=1');
await page.evaluate((theme) => { document.documentElement.dataset.theme = theme; }, theme);
const tooltip = page.getByRole('tooltip');
// Fully on screen and on top: nothing (clip, mask, scroll box) covers it.
@@ -776,8 +788,8 @@ for (const theme of ['light', 'dark']) {
}
for (const theme of ['light', 'dark']) {
- test(`one card is always drawn in full and Vibey does not toggle it (${theme})`, async ({ page }) => {
- await page.goto('/e2e/pet-mini/fixture.html?activities=1');
+ test(`one card is always drawn in full and a Vibey click does not change it (${theme})`, async ({ page }) => {
+ await page.goto('/e2e/pet-mini/fixture.html?activities=1&queued=1');
await page.evaluate((theme) => { document.documentElement.dataset.theme = theme; }, theme);
const settle = () => page.evaluate(async () => {
await Promise.all(document.getAnimations()
@@ -793,18 +805,23 @@ for (const theme of ['light', 'dark']) {
await expect(open).toBeVisible();
await expect(page.locator('.pet-mini-collapsed')).toHaveCount(0);
await expect(page.locator('.pet-mini-stack-count')).toHaveCount(0);
- expect(await avatar.getAttribute('aria-expanded')).toBeNull();
+ await expect(avatar).toHaveAttribute('aria-expanded', 'false');
+ // The fixture's reply lands just after load and opens the bubble below.
+ await expect(page.locator('.pet-mini-slot.is-open .pet-mini-reply-bubble')).toBeVisible();
await settle();
- const box = await card.boundingBox();
+ const size = async () => { const box = (await card.boundingBox())!; return { width: box.width, height: box.height }; };
+ const before = await size();
- for (let click = 0; click < 2; click += 1) {
+ // A Vibey click opens and closes the history; the card moves with the
+ // bubble beneath it but keeps its full form.
+ for (const historyOpen of [true, false]) {
await avatar.click();
await settle();
- expect(await card.boundingBox()).toEqual(box);
+ expect(await size()).toEqual(before);
await expect(stop).toBeVisible();
await expect(open).toBeVisible();
await expect(page.locator('.pet-mini-collapsed')).toHaveCount(0);
- expect(await avatar.getAttribute('aria-expanded')).toBeNull();
+ await expect(avatar).toHaveAttribute('aria-expanded', String(historyOpen));
}
// The window passes clicks through except over hit regions, so every
@@ -836,7 +853,7 @@ for (const theme of ['light', 'dark']) {
});
test(`one card stays in full beside the open history and everything fits (${theme})`, async ({ page }) => {
- await page.goto('/e2e/pet-mini/fixture.html?scenario=personal&lang=zh&activities=1&history=long');
+ await page.goto('/e2e/pet-mini/fixture.html?scenario=personal&lang=zh&activities=1&history=long&queued=1');
await page.evaluate((theme) => { document.documentElement.dataset.theme = theme; }, theme);
const card = page.locator('.pet-mini-card');
await expect(card.locator('.pet-mini-open')).toBeVisible();
@@ -865,9 +882,11 @@ test('Vibey clicks with a lone card leave no hidden expansion for a second card'
await page.goto('/e2e/pet-mini/fixture.html?activities=1');
const avatar = page.locator('.pet-mini-avatar-button');
await expect(page.locator('.pet-mini-card')).toHaveCount(1);
+ // Open, then close, the history: nothing is left expanded behind it.
await avatar.click();
+ await expect(avatar).toHaveAttribute('aria-expanded', 'true');
await avatar.click();
- await avatar.click();
+ await expect(avatar).toHaveAttribute('aria-expanded', 'false');
await page.evaluate(() => window.petFixtureAddActivity());
await expect(page.locator('.pet-mini-collapsed')).toBeVisible();
await expect(page.locator('.pet-mini-stack-count')).toHaveText('2 items');
@@ -876,7 +895,7 @@ test('Vibey clicks with a lone card leave no hidden expansion for a second card'
});
test('with a lone card, Vibey closes the open history and leaves the card alone', async ({ page }) => {
- await page.goto('/e2e/pet-mini/fixture.html?scenario=personal&activities=1');
+ await page.goto('/e2e/pet-mini/fixture.html?scenario=personal&activities=1&queued=1');
const card = page.locator('.pet-mini-card');
const avatar = page.locator('.pet-mini-avatar-button');
await expect(card.locator('.pet-mini-open')).toBeVisible();
@@ -904,17 +923,182 @@ test('with a lone card, Vibey closes the open history and leaves the card alone'
await expect(page.locator('.pet-mini-scroll')).toHaveCount(0);
});
-test('two or more cards keep the collapsed stack that Vibey toggles', async ({ page }) => {
+test('two or more cards expand from the stack, and a Vibey click collapses them', async ({ page }) => {
await page.goto('/e2e/pet-mini/fixture.html?activities=2');
const avatar = page.locator('.pet-mini-avatar-button');
await expect(page.locator('.pet-mini-collapsed')).toBeVisible();
await expect(page.locator('.pet-mini-stack-count')).toBeVisible();
+ // The stack is the way to expand the cards.
+ await page.locator('.pet-mini-collapsed').click();
+ await expect(page.locator('.pet-mini-scroll')).toBeVisible();
+ await expect(page.locator('.pet-mini-card')).toHaveCount(2);
await expect(avatar).toHaveAttribute('aria-expanded', 'false');
+ // Vibey collapses the expanded list and does nothing else.
await avatar.click();
+ await expect(page.locator('.pet-mini-collapsed')).toBeVisible();
+ await expect(page.locator('.pet-mini-reply-bubble .pet-mini-detail')).not.toHaveClass(/is-open/);
+ // The next click is about Vibey: it opens the history, and the stack stays collapsed.
+ await avatar.click();
+ await expect(page.locator('.pet-mini-reply-bubble .pet-mini-detail')).toHaveClass(/is-open/);
+ await expect(page.locator('.pet-mini-collapsed')).toBeVisible();
+ await expect(avatar).toHaveAttribute('aria-expanded', 'true');
+ // Expanding the list closes the history: the two never share the space.
+ await page.locator('.pet-mini-collapsed').click();
await expect(page.locator('.pet-mini-scroll')).toBeVisible();
- await expect(page.locator('.pet-mini-card')).toHaveCount(2);
+ await expect(page.locator('.pet-mini-reply-bubble .pet-mini-detail')).not.toHaveClass(/is-open/);
+ await expect(avatar).toHaveAttribute('aria-expanded', 'false');
+});
+
+// Vibey's bubble: shown only while the main session is active, hidden the
+// moment it is not (spec §4.2).
+const bubbleShown = (page: import('@playwright/test').Page) => page.locator('.pet-mini-slot.is-open .pet-mini-reply-bubble');
+const bubbleSlot = (page: import('@playwright/test').Page) => page.locator('.pet-mini-slot:has(.pet-mini-reply-bubble)');
+// Whether the bubble itself is reported as a region (a card moving into its old
+// place is, rightly, a region of its own).
+const bubbleIsRegion = (page: import('@playwright/test').Page) => page.evaluate(() => {
+ const box = document.querySelector('.pet-mini-reply-bubble')!.getBoundingClientRect();
+ return window.petLayoutHitRegions.some((rect) => Math.abs(rect.x - box.left) <= 1 && Math.abs(rect.width - box.width) <= 1 && rect.height > 1
+ && Math.abs(rect.y + rect.height - box.bottom) <= 1);
+});
+const settleMotion = (page: import('@playwright/test').Page) => page.evaluate(async () => {
+ await Promise.all(document.getAnimations()
+ .filter((animation) => animation.effect?.getTiming().iterations !== Infinity)
+ .map((animation) => animation.finished.catch(() => {})));
+});
+
+test('an old, finished exchange starts with the bubble hidden, and takes no space or clicks', async ({ page }) => {
+ await page.goto('/e2e/pet-mini/fixture.html?scenario=personal&lang=zh');
+ await expect(page.locator('.pet-mini-avatar-button')).toBeVisible();
+ await expect(page.locator('.pet-mini-reply-bubble')).toHaveCount(1);
+ await expect(bubbleShown(page)).toHaveCount(0);
+ await settleMotion(page);
+ expect(await bubbleSlot(page).evaluate((node) => node.getBoundingClientRect().height)).toBeLessThan(1);
+ await expect.poll(() => bubbleIsRegion(page)).toBe(false);
+});
+
+test('a running turn shows the bubble, and it hides as soon as the result arrives', async ({ page }) => {
+ await page.goto('/e2e/pet-mini/fixture.html?scenario=personal&lang=zh&running=1');
+ await expect(bubbleShown(page)).toBeVisible();
+ await expect.poll(() => bubbleIsRegion(page)).toBe(true);
+ // The turn ends with its result, announced the way the event stream does.
+ await page.evaluate(() => window.petFixtureFinishTurn({ id: 'live_reply', author: 'agent', type: 'result', text: '做完了。', read_at: null }));
+ await expect(page.locator('.pet-mini-reply-bubble')).toContainText('做完了。');
+ await expect(bubbleShown(page)).toHaveCount(0);
+ await expect.poll(() => bubbleIsRegion(page)).toBe(false);
+});
+
+for (const [name, query] of [['a running turn', 'running=1'], ['a pending Vault handoff', 'history=actions']] as const) {
+ test(`${name} keeps the bubble shown`, async ({ page }) => {
+ await page.goto(`/e2e/pet-mini/fixture.html?scenario=personal&lang=zh&${query}`);
+ await expect(bubbleShown(page)).toBeVisible();
+ await page.waitForTimeout(500);
+ await expect(bubbleShown(page)).toBeVisible();
+ });
+}
+
+for (const theme of ['light', 'dark']) {
+ test(`a Vibey click opens the history from a hidden bubble, and a second hides it again (${theme})`, async ({ page }) => {
+ await page.goto('/e2e/pet-mini/fixture.html?scenario=personal&lang=zh&history=long&asr=1');
+ await page.evaluate((theme) => { document.documentElement.dataset.theme = theme; }, theme);
+ const avatar = page.locator('.pet-mini-avatar-button');
+ await expect(avatar).toBeVisible();
+ await expect(bubbleShown(page)).toHaveCount(0);
+ await expect(avatar).toHaveAttribute('aria-label', '最近几轮');
+ await expect(avatar).toHaveAttribute('aria-expanded', 'false');
+
+ await avatar.click();
+ await expect(bubbleShown(page)).toBeVisible();
+ await expect(page.locator('.pet-mini-reply-bubble .pet-mini-detail')).toHaveClass(/is-open/);
+ await expect(avatar).toHaveAttribute('aria-expanded', 'true');
+ await expect.poll(() => page.locator('.pet-mini-bubble-history').evaluate((node) => Math.abs(node.scrollHeight - node.clientHeight - node.scrollTop))).toBeLessThanOrEqual(1);
+
+ // Closing the history leaves nothing active, so the bubble hides at once.
+ await avatar.click();
+ await expect(page.locator('.pet-mini-reply-bubble .pet-mini-detail')).not.toHaveClass(/is-open/);
+ await expect(bubbleShown(page)).toHaveCount(0);
+ await expect(avatar).toHaveAttribute('aria-expanded', 'false');
+ });
+}
+
+test('keyboard activation of Vibey toggles the history like a click', async ({ page }) => {
+ await page.goto('/e2e/pet-mini/fixture.html?scenario=personal&lang=zh');
+ const avatar = page.locator('.pet-mini-avatar-button');
+ await avatar.focus();
+ await page.keyboard.press('Enter');
+ await expect(page.locator('.pet-mini-reply-bubble .pet-mini-detail')).toHaveClass(/is-open/);
await expect(avatar).toHaveAttribute('aria-expanded', 'true');
+ await page.keyboard.press('Enter');
+ await expect(page.locator('.pet-mini-reply-bubble .pet-mini-detail')).not.toHaveClass(/is-open/);
+ await expect(avatar).toHaveAttribute('aria-expanded', 'false');
+});
+
+test('a Vibey click with no conversation yet does nothing', async ({ page }) => {
+ await page.goto('/e2e/pet-mini/fixture.html?main=false&activities=0');
+ const avatar = page.locator('.pet-mini-avatar-button');
+ await expect(avatar).toBeVisible();
await avatar.click();
- await expect(page.locator('.pet-mini-collapsed')).toBeVisible();
+ await expect(page.locator('.pet-mini-reply-bubble .pet-mini-detail.is-open')).toHaveCount(0);
await expect(avatar).toHaveAttribute('aria-expanded', 'false');
});
+
+test('holding Vibey still starts input, not the history', async ({ page }) => {
+ // Voice is unavailable here, so a hold opens the text input instead of
+ // dictation: the same hold path, without a microphone in the test browser.
+ await page.goto('/e2e/pet-mini/fixture.html?scenario=personal&lang=zh');
+ const avatar = page.locator('.pet-mini-avatar-button');
+ const box = (await avatar.boundingBox())!;
+ await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
+ await page.mouse.down();
+ await page.waitForTimeout(500);
+ await page.mouse.up();
+ await expect(page.getByRole('textbox')).toBeVisible();
+ await expect(page.locator('.pet-mini-reply-bubble .pet-mini-detail.is-open')).toHaveCount(0);
+ // While typing, a Vibey click leaves the input, and its draft, alone.
+ await page.getByRole('textbox').fill('a draft');
+ await avatar.click();
+ await expect(page.getByRole('textbox')).toHaveValue('a draft');
+ await expect(page.locator('.pet-mini-reply-bubble .pet-mini-detail.is-open')).toHaveCount(0);
+});
+
+for (const cards of [1, 3]) {
+ test(`with ${cards} card${cards > 1 ? 's' : ''}, the bubble hidden, shown or open fits without overlap`, async ({ page }) => {
+ const fits = async () => {
+ await settleMotion(page);
+ const cardsBox = (await page.locator('.pet-mini-cards').boundingBox())!;
+ const avatar = (await page.locator('.pet-mini-avatar-button').boundingBox())!;
+ expect(cardsBox.y).toBeGreaterThanOrEqual(0);
+ expect(avatar.y + avatar.height).toBeLessThanOrEqual(600);
+ if (await bubbleShown(page).count()) {
+ const bubble = (await page.locator('.pet-mini-reply-bubble').boundingBox())!;
+ expect(cardsBox.y + cardsBox.height).toBeLessThanOrEqual(bubble.y + 1);
+ expect(bubble.y + bubble.height).toBeLessThanOrEqual(600);
+ } else {
+ expect(cardsBox.y + cardsBox.height).toBeLessThanOrEqual(avatar.y + avatar.height);
+ }
+ };
+ // Hidden, then opened by a Vibey click.
+ await page.goto(`/e2e/pet-mini/fixture.html?scenario=personal&lang=zh&activities=${cards}&history=long`);
+ await expect(page.locator('.pet-mini-avatar-button')).toBeVisible();
+ await expect(bubbleShown(page)).toHaveCount(0);
+ await fits();
+ await page.locator('.pet-mini-avatar-button').click();
+ await expect(page.locator('.pet-mini-reply-bubble .pet-mini-detail')).toHaveClass(/is-open/);
+ await fits();
+ // Shown with its summary while Vibey works.
+ await page.goto(`/e2e/pet-mini/fixture.html?scenario=personal&lang=zh&activities=${cards}&history=long&running=1`);
+ await expect(bubbleShown(page)).toBeVisible();
+ await fits();
+ });
+}
+
+for (const asr of [true, false]) {
+ test(`the dock holds ${asr ? 'mic and keyboard' : 'the keyboard alone'} (voice ${asr ? 'available' : 'unavailable'})`, async ({ page }) => {
+ await page.goto(`/e2e/pet-mini/fixture.html?scenario=personal&lang=zh${asr ? '&asr=1' : ''}`);
+ await page.locator('.pet-mini-avatar-button').hover();
+ const dock = page.locator('.pet-mini-dock');
+ await expect(dock).toHaveCSS('opacity', '1');
+ if (asr) await expect(dock.getByRole('button', { name: '语音输入', exact: true })).toBeVisible();
+ const order = await dock.evaluate((node) => [...node.children].map((child) => child.tagName === 'BUTTON' ? child.getAttribute('aria-label') : child.classList.contains('pet-mini-dock-divider') ? '|' : null).filter(Boolean));
+ expect(order).toEqual(asr ? ['语音输入', '|', '输入消息'] : ['输入消息']);
+ });
+}
diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.json
index 99c6a6671..b3cd0799b 100644
--- a/ui/src/i18n/en.json
+++ b/ui/src/i18n/en.json
@@ -5924,7 +5924,6 @@
"unreadBadge_other": "{{count}} unread replies",
"setupPending": "Finish setting up in Avibe to talk to your agent here.",
"openAvibe": "Open Avibe",
- "toggle": "Show or hide the pet panel",
"panel": "Pet panel",
"untitled": "Untitled session",
"openInAvibe": "Open in Avibe",
diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.json
index 686f8886a..a45e407e7 100644
--- a/ui/src/i18n/zh.json
+++ b/ui/src/i18n/zh.json
@@ -5924,7 +5924,6 @@
"unreadBadge_other": "{{count}} 条未读回复",
"setupPending": "先在 Avibe 里完成设置,就可以在这里和 agent 对话了。",
"openAvibe": "打开 Avibe",
- "toggle": "展开或收起宠物面板",
"panel": "宠物面板",
"untitled": "未命名会话",
"openInAvibe": "在 Avibe 中打开",
diff --git a/ui/src/pet/PetPage.test.tsx b/ui/src/pet/PetPage.test.tsx
index 1105da2e1..5888924e5 100644
--- a/ui/src/pet/PetPage.test.tsx
+++ b/ui/src/pet/PetPage.test.tsx
@@ -631,7 +631,7 @@ describe('PetPage review fixes', () => {
Object.defineProperty(window, '__TAURI_INTERNALS__', { value: { invoke }, configurable: true });
render(<PetPage />);
// The surface is mounted and subscribed before the shell answers.
- await screen.findByLabelText('pet.toggle');
+ await screen.findByLabelText('pet.recentTurns');
await act(async () => ready.resolve({ binding: 'legacy', revision: 1, summon_pending: { intent: 'listen' } }));
// The summon opens the resolved main's input.
expect(await screen.findByLabelText('pet.inputPlaceholder')).toBeTruthy();
@@ -818,11 +818,12 @@ describe('PetPage review fixes, round 7', () => {
Object.defineProperty(window, '__TAURI_INTERNALS__', { value: { invoke }, configurable: true });
tails.S = [];
render(<PetPage />);
- await screen.findByLabelText('pet.toggle');
+ await screen.findByLabelText('pet.recentTurns');
// The live summon is newer than the pending one pet_ready still carries.
await shellBound('S', 1);
await showDetail();
- expect(screen.getByLabelText('pet.toggle').getAttribute('aria-expanded')).toBe('true');
+ // The summon expanded the panel (Vibey's aria-expanded now speaks for the history).
+ expect(screen.getByLabelText('pet.panel')).toBeTruthy();
act(() => {
window.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }));
});
@@ -900,7 +901,7 @@ describe('PetPage review fixes, round 9', () => {
try {
mainSession('S');
render(<PetPage />);
- await screen.findByLabelText('pet.toggle');
+ await screen.findByLabelText('pet.recentTurns');
await act(async () => {});
expect(pose()).toBe('idle');
} finally {
@@ -939,10 +940,10 @@ describe('PetPage review fixes, round 12', () => {
Object.defineProperty(window, '__AVIBE_DESKTOP_SHELL__', { value: true, configurable: true });
Object.defineProperty(window, '__TAURI_INTERNALS__', { value: { invoke }, configurable: true });
render(<PetPage />);
- await userEvent.click(await screen.findByLabelText('pet.toggle'));
+ await userEvent.click(await screen.findByLabelText('pet.recentTurns'));
await waitFor(() => expect(invoke).toHaveBeenCalledWith('pet_set_expanded', { expanded: true }));
await waitFor(() => expect(screen.queryByLabelText('pet.panel')).toBeNull());
- expect(screen.getByLabelText('pet.toggle').getAttribute('aria-expanded')).toBe('false');
+ expect(screen.getByLabelText('pet.recentTurns').getAttribute('aria-expanded')).toBe('false');
});
});
@@ -1315,13 +1316,13 @@ describe('PetPage review fixes, round 14', () => {
summon('show');
await waitFor(() => expect(invoke).toHaveBeenCalledWith('pet_set_expanded', { expanded: true }));
expect(order).toEqual([true]);
- // Collapse while expand is still in flight: Esc is not listening yet
- // (the panel is hidden until the frame grows), so the avatar toggle is
- // the overlapping command. The native collapse waits its turn.
- await userEvent.click(screen.getByLabelText('pet.toggle'));
+ // A second panel command while the expand is still in flight: a Vibey
+ // click, which opens the history (the panel is not confirmed open, so
+ // nothing is open to close). It waits its turn behind the first.
+ await userEvent.click(screen.getByLabelText('pet.recentTurns'));
expect(order).toEqual([true]);
await act(async () => first.resolve({ panel_side: 'left', panel_edge: 'bottom' }));
- await waitFor(() => expect(order).toEqual([true, false]));
+ await waitFor(() => expect(order).toEqual([true, true]));
await act(async () => second.resolve({ panel_side: 'left', panel_edge: 'bottom' }));
});
@@ -1600,7 +1601,7 @@ describe('desktop mini v2 interaction contract', () => {
await withVoiceEnv(() => true, Dictation, async () => {
vi.stubGlobal('fetch', vi.fn(() => status.promise));
mainSession('S'); render(<PetPage />); await screen.findByText('Session S');
- const avatar = screen.getByLabelText('pet.toggle');
+ const avatar = screen.getByLabelText('pet.recentTurns');
vi.useFakeTimers();
try {
fireEvent.pointerDown(avatar, { button: 0, pointerId: 1 });
@@ -1816,7 +1817,7 @@ describe('desktop mini v2 interaction contract', () => {
it('shows the dock while the shell reports hover over Vibey, and reports that zone', async () => {
mainSession('S'); render(<PetPage />);
- const wrap = (await screen.findByLabelText('pet.toggle')).closest('.pet-mini-avatar-wrap')!;
+ const wrap = (await screen.findByLabelText('pet.recentTurns')).closest('.pet-mini-avatar-wrap')!;
expect(wrap.hasAttribute('data-pet-hover')).toBe(true);
expect(wrap.classList.contains('is-hovered')).toBe(false);
act(() => { window.dispatchEvent(new CustomEvent(PET_HOVER_EVENT, { detail: { hover: true } })); });
@@ -1855,7 +1856,7 @@ describe('desktop mini v2 interaction contract', () => {
expect(markRead).not.toHaveBeenCalled();
fireEvent.click(document.querySelector('.pet-mini-reply-toggle')!);
await waitFor(() => expect(markRead).toHaveBeenCalledWith('S', 'r'));
- fireEvent.click(screen.getByLabelText('pet.toggle'));
+ fireEvent.click(screen.getByLabelText('pet.recentTurns'));
await waitFor(() => expect(document.querySelector('.pet-mini-detail.is-open')).toBeNull());
});
@@ -1926,7 +1927,7 @@ describe('desktop mini v2 interaction contract', () => {
it('holds for exactly 320ms, cancels a departed press, and falls back to text without voice support', async () => {
mainSession('S'); render(<PetPage />); await screen.findByText('Session S');
- const avatar = screen.getByLabelText('pet.toggle');
+ const avatar = screen.getByLabelText('pet.recentTurns');
vi.useFakeTimers();
fireEvent.pointerDown(avatar, { button: 0, pointerId: 1 });
fireEvent.pointerLeave(avatar);
@@ -2450,3 +2451,85 @@ describe('PetPage IME composition', () => {
await waitFor(() => expect(screen.queryByLabelText('pet.inputPlaceholder')).toBeNull());
});
});
+
+describe('Vibey bubble visibility (spec §4.2)', () => {
+ const bubbleOpen = () => document.querySelector('.pet-mini-reply-bubble')?.closest('.pet-mini-slot')?.classList.contains('is-open') ?? false;
+
+ it('starts hidden for an old, finished exchange, quick replies and unread included', async () => {
+ tails.S = [
+ message('u', 'S', { author: 'user', type: 'user', text: 'hello' }),
+ message('r', 'S', { text: 'Done already', read_at: null, content: { quick_replies: ['Yes', 'No'] } }),
+ ];
+ mainSession('S');
+ render(<PetPage />);
+ await waitFor(() => expect(document.querySelector('.pet-mini-reply-bubble')?.textContent).toContain('Done already'));
+ expect(bubbleOpen()).toBe(false);
+ });
+
+ it('shows while Vibey works, and hides as soon as the result arrives', async () => {
+ tails.S = [message('u', 'S', { author: 'user', type: 'user', text: 'hello' })];
+ let running = true;
+ api.getTurnState.mockImplementation(async () => (running ? { ...idleTurn, in_flight: true, foreground: 'running' as const } : idleTurn));
+ try {
+ mainSession('S');
+ render(<PetPage />);
+ await waitFor(() => expect(bubbleOpen()).toBe(true));
+ // The turn ends with its result: the server tail now holds it.
+ const result = message('r', 'S', { text: 'All done', read_at: null });
+ tails.S = [...tails.S, result];
+ running = false;
+ await emit((h) => {
+ h.onMessageNew?.(result);
+ h.onTurnEnd?.({ session_id: 'S' });
+ });
+ await waitFor(() => expect(document.querySelector('.pet-mini-reply-bubble')?.textContent).toContain('All done'));
+ await waitFor(() => expect(bubbleOpen()).toBe(false));
+ } finally {
+ api.getTurnState.mockImplementation(async () => idleTurn);
+ }
+ });
+
+ it('stays shown while a failure needs the user', async () => {
+ tails.S = [
+ message('u', 'S', { author: 'user', type: 'user', text: 'hello' }),
+ message('n', 'S', {
+ type: 'notify',
+ text: 'No model source yet.',
+ metadata: { event: 'backend_failure', failure_id: 'f', turn_id: 't', failure_next_step: 'models' },
+ }),
+ ];
+ mainSession('S');
+ render(<PetPage />);
+ expect(await screen.findByText('pet.failedPrefix No model source yet.')).toBeTruthy();
+ expect(bubbleOpen()).toBe(true);
+ });
+
+ it('stays shown while a send may have been admitted', async () => {
+ tails.S = [message('u', 'S', { author: 'user', type: 'user' }), message('q', 'S')];
+ api.sendSessionMessage.mockRejectedValueOnce(new ApiError('dispatch pending', 504, null));
+ mainSession('S');
+ render(<PetPage />);
+ summon('listen');
+ const input = await screen.findByLabelText('pet.inputPlaceholder') as HTMLTextAreaElement;
+ await waitFor(() => expect(api.getSessionResult).toHaveBeenCalledWith('S'));
+ await act(async () => new Promise((resolve) => setTimeout(resolve, 10)));
+ await userEvent.type(input, 'deploy{Enter}');
+ expect(await screen.findByText('newSession.sendUncertain')).toBeTruthy();
+ expect(bubbleOpen()).toBe(true);
+ });
+
+ it('opens with a Vibey click and hides again when that history closes', async () => {
+ tails.S = [message('u', 'S', { author: 'user', type: 'user', text: 'hello' }), message('r', 'S', { text: 'Old reply' })];
+ mainSession('S');
+ render(<PetPage />);
+ await waitFor(() => expect(document.querySelector('.pet-mini-reply-bubble')?.textContent).toContain('Old reply'));
+ expect(bubbleOpen()).toBe(false);
+ await userEvent.click(screen.getByLabelText('pet.recentTurns'));
+ await waitFor(() => expect(bubbleOpen()).toBe(true));
+ expect(document.querySelector('.pet-mini-detail.is-open')).not.toBeNull();
+ expect(screen.getByLabelText('pet.recentTurns').getAttribute('aria-expanded')).toBe('true');
+ await userEvent.click(screen.getByLabelText('pet.recentTurns'));
+ await waitFor(() => expect(bubbleOpen()).toBe(false));
+ expect(screen.getByLabelText('pet.recentTurns').getAttribute('aria-expanded')).toBe('false');
+ });
+});
diff --git a/ui/src/pet/PetPage.tsx b/ui/src/pet/PetPage.tsx
index 27e472f16..1e9a8231f 100644
--- a/ui/src/pet/PetPage.tsx
+++ b/ui/src/pet/PetPage.tsx
@@ -21,7 +21,7 @@ import { VoiceTranscriptionError } from '@/lib/voiceTranscription';
import { PetAvatar, type PetPose } from './PetAvatar';
import { PetOpenButton } from './PetOpenButton';
import { onPetHover, petBridge, sessionLink, vaultRequestLink } from './petBridge';
-import { petPanel, usePetPanel } from './petPanel';
+import { usePetPanel } from './petPanel';
import { petComposer, usePetComposer } from './petComposer';
import { petShell, useOnSummon, usePetBinding, usePetDismissed } from './petShell';
import { derivePetPose, derivePetState, latestExchange, latestFailureNotice, openQuickReplies } from './petState';
@@ -266,19 +266,18 @@ const PetSurface: React.FC = () => {
setDetailOpen(false);
void setPanel(true);
}, [setPanel]);
- const togglePanel = () => {
- // A lone card has no stack to open (§3.3). Vibey still closes an open
- // history, but otherwise toggles nothing: flipping the panel state here
- // would be invisible until a second card arrived and opened the list.
- if (singleCard) {
- if (detailOpen) {
- setDetailOpen(false);
- void setPanel(false);
- }
- return;
- }
- if (detailOpen) openCards();
- else void setPanel(!petPanel.want());
+ // A Vibey click (§5.1) is about Vibey's own conversation: it collapses an
+ // expanded card list, else closes an open history, else opens the history.
+ // The collapsed stack is the only way to expand the cards (§3.3). Every
+ // branch leaves the shell's panel state matching what is drawn.
+ const toggleVibey = () => {
+ if (cardsListed) { void setPanel(false); return; }
+ if (historyOpen) { setDetailOpen(false); void setPanel(false); return; }
+ // Typing and dictation keep the speech slot, and the draft, as they are.
+ if (composing || voice.listening) return;
+ if (!binding || resolvingMain || (data.messages.length === 0 && !optimisticTitle)) return;
+ setDetailOpen(true);
+ void setPanel(true);
};
const [composing, setComposing] = useState(false);
const [presentations, setPresentations] = useState<Record<string, CardPresentation>>({});
@@ -642,11 +641,22 @@ const PetSurface: React.FC = () => {
const queued = (data.turn?.pending_input_count ?? 0) > 0;
const resolvingMain = data.canChat === null;
- const showReplyBubble = Boolean(
+ const historyOpen = detailOpen && expanded;
+ // What the bubble would draw: any exchange, or a state worth a word.
+ const hasBubbleContent = Boolean(
binding && !resolvingMain
- && (data.running || optimisticTitle || exchange.user || exchange.results.length > 0 || failure || uncertain
+ && (historyOpen || data.running || optimisticTitle || exchange.user || exchange.results.length > 0 || failure || uncertain
|| queued || vaultRequests.length > 0 || quickReplies),
);
+ // Whether it is drawn (spec §4.2): only while the main session is active —
+ // Vibey is working, a send is pending, Vibey needs the user, or the history
+ // is open — and hidden the moment none holds, the turn's result included.
+ // Unread replies only light Vibey's badge; a Vibey click opens the history.
+ // Every input is the current epoch's own state, so nothing carries a bubble
+ // over from a previous session.
+ const needsYou = Boolean((!data.running && failure) || uncertain || queued || vaultRequests.length > 0);
+ const showReplyBubble = hasBubbleContent && Boolean(data.running || optimisticTitle || needsYou || historyOpen);
+ const toggleHistory = () => { setDetailOpen(!detailOpen); void setPanel(!detailOpen); };
const avatar = (
<div className={clsx('pet-mini-avatar-wrap', voice.listening && 'is-listening', hovered && 'is-hovered')} data-pet-hover>
@@ -654,11 +664,11 @@ const PetSurface: React.FC = () => {
<button
type="button"
className="pet-mini-avatar-button"
- aria-label={t('pet.toggle')}
- // A lone card is always drawn in full, so Vibey expands nothing there.
- aria-expanded={singleCard ? undefined : expanded}
+ // A click opens or closes Vibey's recent turns (§5.1).
+ aria-label={t('pet.recentTurns')}
+ aria-expanded={historyOpen}
data-pet-hit
- onClick={(event) => { if (event.detail === 0) togglePanel(); }}
+ onClick={(event) => { if (event.detail === 0) toggleVibey(); }}
onPointerDown={(event) => {
if (event.button !== 0) return;
const target = event.currentTarget;
@@ -695,7 +705,7 @@ const PetSurface: React.FC = () => {
if (!press) return;
window.clearTimeout(press.timer);
if (press.held) voice.stop(true);
- else if (!press.dragged) togglePanel();
+ else if (!press.dragged) toggleVibey();
}}
onPointerLeave={() => {
const press = pressRef.current;
@@ -779,10 +789,11 @@ const PetSurface: React.FC = () => {
</div>
</form>
</>
- ) : showReplyBubble && binding ? (
+ ) : hasBubbleContent && binding ? (
+ // Still drawn while the slot closes, so it fades out rather than vanishing.
<MainReplyBubble
- open={detailOpen && expanded}
- onToggle={() => { setDetailOpen(!detailOpen); void setPanel(!detailOpen); }}
+ open={historyOpen}
+ onToggle={toggleHistory}
epoch={epoch}
voiceNeedsCloud={voice.cloudRequired}
canChat={canChat}