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
fix(pet): prevent double-click flashes and hide the idle dock (#3004)
Max01c1d1d3fd50
diff --git a/docs/plans/2026-10-12-desktop-mini-main-agent.md b/docs/plans/2026-10-12-desktop-mini-main-agent.mdindex 424e45aa8..c9874cb04 100644--- a/docs/plans/2026-10-12-desktop-mini-main-agent.md+++ b/docs/plans/2026-10-12-desktop-mini-main-agent.md@@ -355,14 +355,31 @@ Known data limitations for P1:history opens and closes above the input or the marquee, which keep theirdraft, focus, caret and capture. A click on Vibey is not leaving the input:the input keeps the focus (Vibey's press does not take it).-- **Double-click Vibey** (owner decision, 2026-10-23) opens Vibey's+- **Double-click Vibey** (owner decision, 2026-10-26) opens Vibey'sconversation in the Avibe main window (`avibe://session/<main>`, routed to- `/chat/<id>`). A single click is never delayed: the first click of a- double-click acts at once like any click, and the second puts the history- and the card list back as they were before the first, then opens the window.- The double-click is the platform's own (the press's click count), so its- speed follows the system setting. A hold or a drag is never a click, and- keyboard activation is always a single click.+ `/chat/<id>`). A pointer click waits for the double-click window before it+ toggles Vibey's history, so the first press of a double-click has no visible+ effect and cannot collapse the card list. A second press inside the+ double-click window cancels that pending single click and opens the window,+ leaving history and cards exactly as they were before the gesture. The page+ pairs the platform click count with the elapsed time between presses, and+ also honours a native `dblclick` event without opening the session twice.+ This v1 uses a 450ms page interval; matching the native macOS+ `NSEvent.doubleClickInterval` remains a known gap. Keyboard activation+ (`event.detail === 0`) toggles immediately. A hold or a drag is never a+ click, and a pointer cancel or leaving Vibey before release cancels any+ pending click.++ Opening the session, or losing the pet window's key while neither dictating+ nor typing, clears the hover state and blurs Vibey. The page suppresses the+ dock while the shell still reports the pointer over Vibey; the next+ `hover: false` arms it again, and a later `hover: true` shows it. If the+ shell already reported `hover: false` before suppression, the first new+ `hover: true` restores the dock without requiring another leave. CSS+ `:hover` and focus cannot bypass this suppression. The dock remains visible+ while dictation, finishing, or typing is active. A double-click's first+ press does not open history, so it does not mark a lingering reply as seen;+ “looked at means done” still requires a history the user actually opened.Every branch leaves the shell's panel state matching what is drawn, sonothing stays expanded out of sight. Vibey's button is labelled "Recent@@ -402,7 +419,11 @@ Known data limitations for P1:the rects of Vibey and the dock `hover: true` in `pet_hit_regions`; thecursor poller (§9.2) sends `avibe:pet-hover { hover }` when the cursorenters or leaves them, and the page shows the dock while it is set. CSS- `:hover` still applies where the webview does see hover.+ `:hover` still applies where the webview does see hover, except while the+ idle dock is suppressed after opening Avibe or losing key. In that case+ it stays hidden until the shell reports a leave followed by a new enter+ (or just a new enter if the pointer was already outside),+ even while the pet window remains unfocused.- It stays visible while dictating or typing, and is always visible ondevices without hover (`@media (hover: none)`).@@ -910,6 +931,7 @@ GET /api/sessions/main- [ ] Vibey's bubble is content-sized and centred while it only saysthinking/waiting, and widens from the centre when the reply arrives.- [ ] A double-click on Vibey opens its conversation in Avibe and leaves the- history and cards as they were; single clicks are not delayed.+ history and cards as they were; pointer single clicks take the+ double-click window to confirm.- [ ] Reduced motion turns everything above into instant switches.- [ ] Icons are SVG. All copy is localized in en and zh.diff --git a/ui/e2e/pet-mini/layout.spec.ts b/ui/e2e/pet-mini/layout.spec.tsindex d02b0b349..7aa9b800f 100644--- a/ui/e2e/pet-mini/layout.spec.ts+++ b/ui/e2e/pet-mini/layout.spec.ts@@ -288,6 +288,9 @@ test.describe('expanded dismiss controls on touch', () => {await expect(dismiss).toHaveCSS('opacity', '1');await expect(dismiss).toHaveCSS('pointer-events', 'auto');}+ await page.evaluate(() => window.dispatchEvent(new Event('blur')));+ await expect(page.locator('.pet-mini-dock')).toHaveCSS('opacity', '1');+ await expect(page.locator('.pet-mini-dock')).toHaveCSS('pointer-events', 'auto');});});@@ -1240,32 +1243,106 @@ for (const theme of ['light', 'dark']) {}}-test('a double-click opens the conversation in Avibe and leaves the history as it was', async ({ page }) => {- await page.goto('/e2e/pet-mini/fixture.html?scenario=personal&lang=zh&history=long');+for (const initiallyOpen of [false, true]) {+ test(`a double-click never toggles history (initially open=${initiallyOpen})`, async ({ page }) => {+ await page.goto('/e2e/pet-mini/fixture.html?scenario=personal&lang=zh&history=long');+ const avatar = page.locator('.pet-mini-avatar-button');+ await expect(avatar).toBeVisible();+ await page.clock.install();+ if (initiallyOpen) {+ await avatar.click();+ await page.clock.runFor(450);+ await expect(avatar).toHaveAttribute('aria-expanded', 'true');+ }+ // Record every committed aria-expanded value, including transient states+ // that could otherwise disappear before Playwright's final assertion.+ await avatar.evaluate((node, initial) => {+ node.setAttribute('data-history-changed', 'false');+ new MutationObserver((records) => {+ if (records.some((record) => record.oldValue !== String(initial))+ || node.getAttribute('aria-expanded') !== String(initial)) {+ node.setAttribute('data-history-changed', 'true');+ }+ }).observe(node, { attributes: true, attributeOldValue: true, attributeFilter: ['aria-expanded'] });+ }, initiallyOpen);+ await avatar.dblclick();+ await page.clock.runFor(600);+ await expect.poll(() => page.evaluate(() => window.petFixtureOpens.length)).toBe(1);+ await expect(avatar).toHaveAttribute('aria-expanded', String(initiallyOpen));+ await expect(avatar).toHaveAttribute('data-history-changed', 'false');+ if (!initiallyOpen) expect(await page.evaluate(() => window.petFixtureMarkReads)).toEqual([]);+ // The OS transfers key to the main window during pet_open.+ await page.evaluate(() => window.dispatchEvent(new Event('blur')));+ await expect(avatar).toHaveAttribute('aria-expanded', String(initiallyOpen));+ 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.mouse.move(box.x + box.width / 2 + 20, box.y + box.height / 2 + 5, { steps: 4 });+ await page.mouse.up();+ await page.clock.runFor(600);+ expect(await page.evaluate(() => window.petFixtureOpens.length)).toBe(1);+ });+}++test('idle dock recovers on the first shell enter when the pointer left before blur', async ({ page }) => {+ await page.goto('/e2e/pet-mini/fixture.html?main=false&activities=0&asr=1');const avatar = page.locator('.pet-mini-avatar-button');- await expect(avatar).toBeVisible();- await avatar.dblclick();- await expect.poll(() => page.evaluate(() => window.petFixtureOpens)).toEqual(['avibe://session/ses_main']);- await page.waitForTimeout(100);- await expect(avatar).toHaveAttribute('aria-expanded', 'false');- await expect(page.locator('.pet-mini-detail.is-open')).toHaveCount(0);- await avatar.click();- await expect(page.locator('.pet-mini-detail.is-open')).toHaveCount(1);- await avatar.dblclick();- await expect.poll(() => page.evaluate(() => window.petFixtureOpens.length)).toBe(2);- await page.waitForTimeout(100);- await expect(avatar).toHaveAttribute('aria-expanded', 'true');- await expect(page.locator('.pet-mini-detail.is-open')).toHaveCount(1);- // A drag never opens it.- 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.mouse.move(box.x + box.width / 2 + 20, box.y + box.height / 2 + 5, { steps: 4 });- await page.mouse.up();- await page.waitForTimeout(100);- expect(await page.evaluate(() => window.petFixtureOpens.length)).toBe(2);+ const dock = page.locator('.pet-mini-dock');+ await avatar.hover();+ await avatar.focus();+ await page.evaluate(() => window.dispatchEvent(new CustomEvent('avibe:pet-hover', { detail: { hover: true } })));+ await expect(dock).toHaveCSS('opacity', '1');+ await page.mouse.move(0, 0);+ await page.evaluate(() => {+ window.dispatchEvent(new CustomEvent('avibe:pet-hover', { detail: { hover: false } }));+ window.dispatchEvent(new Event('blur'));+ });+ await expect(dock).toHaveCSS('opacity', '0');+ await expect(avatar).not.toBeFocused();+ // No additional leave or window focus: the first shell enter must recover.+ await page.evaluate(() => window.dispatchEvent(new CustomEvent('avibe:pet-hover', { detail: { hover: true } })));+ await expect(dock).toHaveCSS('opacity', '1');+ await expect(dock).toHaveCSS('pointer-events', 'auto');});+for (const theme of ['light', 'dark']) {+ for (const cause of ['double-click', 'blur']) {+ test(`idle dock hides after ${cause} until shell leave/re-enter (${theme})`, async ({ page }, testInfo) => {+ await page.goto('/e2e/pet-mini/fixture.html?main=false&activities=0&asr=1');+ await page.evaluate((theme) => { document.documentElement.dataset.theme = theme; }, theme);+ const avatar = page.locator('.pet-mini-avatar-button');+ const dock = page.locator('.pet-mini-dock');+ await avatar.hover();+ await avatar.focus();+ await page.evaluate(() => window.dispatchEvent(new CustomEvent('avibe:pet-hover', { detail: { hover: true } })));+ await expect(dock).toHaveCSS('opacity', '1');+ if (cause === 'double-click') await avatar.dblclick();+ else await page.evaluate(() => window.dispatchEvent(new Event('blur')));+ await expect(dock).toHaveCSS('opacity', '0');+ await expect(dock).toHaveCSS('pointer-events', 'none');+ await expect(avatar).not.toBeFocused();+ await page.screenshot({ path: testInfo.outputPath('dock-suppressed.png'), animations: 'disabled' });+ // The actual pointer remains over the avatar: stale CSS hover and+ // repeated shell hover must both remain suppressed.+ await page.evaluate(() => window.dispatchEvent(new CustomEvent('avibe:pet-hover', { detail: { hover: true } })));+ await expect(dock).toHaveCSS('opacity', '0');+ await page.evaluate(() => window.dispatchEvent(new CustomEvent('avibe:pet-hover', { detail: { hover: false } })));+ await expect(dock).toHaveCSS('opacity', '0');+ await page.mouse.move(0, 0);+ await page.evaluate(() => window.dispatchEvent(new CustomEvent('avibe:pet-hover', { detail: { hover: true } })));+ await expect(dock).toHaveCSS('opacity', '1');+ await page.screenshot({ path: testInfo.outputPath('dock-reentered.png'), animations: 'disabled' });+ // Shell hover can show it again without window focus or CSS hover.+ await dock.locator('button').last().click();+ await expect(page.getByRole('textbox')).toBeVisible();+ await avatar.dblclick();+ await page.evaluate(() => window.dispatchEvent(new Event('blur')));+ await expect(dock).toHaveClass(/is-active/);+ await expect(dock).toHaveCSS('opacity', '1');+ });+ }+}+for (const reduced of [false, true]) {test(`thinking is content-sized and centred, and the reply widens it from the centre (reduced=${reduced})`, async ({ page }) => {await page.emulateMedia({ reducedMotion: reduced ? 'reduce' : 'no-preference' });diff --git a/ui/src/pet/PetPage.test.tsx b/ui/src/pet/PetPage.test.tsxindex fab7fbb38..62dbb73bb 100644--- a/ui/src/pet/PetPage.test.tsx+++ b/ui/src/pet/PetPage.test.tsx@@ -1318,9 +1318,9 @@ describe('PetPage review fixes, round 14', () => {await waitFor(() => expect(invoke).toHaveBeenCalledWith('pet_set_expanded', { expanded: true }));expect(order).toEqual([true]);// 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+ // keyboard activation, 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'));+ fireEvent.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, true]));@@ -1887,6 +1887,99 @@ describe('desktop mini v2 interaction contract', () => {expect(wrap.classList.contains('is-hovered')).toBe(false);});+ it.each(['blur', 'open'])('suppresses the idle dock after %s until shell leave and re-enter', async (cause) => {+ mainSession('S'); render(<PetPage />);+ const avatar = await screen.findByLabelText('pet.recentTurns');+ const wrap = avatar.closest('.pet-mini-avatar-wrap')!;+ const hover = (value: boolean) => act(() => {+ window.dispatchEvent(new CustomEvent(PET_HOVER_EVENT, { detail: { hover: value } }));+ });+ hover(true);+ act(() => avatar.focus());+ if (cause === 'open') {+ const { petBridge } = await import('./petBridge');+ vi.spyOn(petBridge, 'open').mockResolvedValue();+ await userEvent.dblClick(avatar);+ } else act(() => window.dispatchEvent(new Event('blur')));+ expect(wrap.classList.contains('is-hovered')).toBe(false);+ expect(wrap.classList.contains('is-hover-suppressed')).toBe(true);+ expect(document.activeElement).not.toBe(avatar);+ hover(true);+ expect(wrap.classList.contains('is-hovered')).toBe(false);+ hover(false);+ expect(wrap.classList.contains('is-hover-suppressed')).toBe(true);+ hover(true);+ expect(wrap.classList.contains('is-hover-suppressed')).toBe(false);+ expect(wrap.classList.contains('is-hovered')).toBe(true);+ });++ it.each(['blur', 'open'])('restores the idle dock on the first enter when already outside before %s', async (cause) => {+ mainSession('S'); render(<PetPage />);+ const avatar = await screen.findByLabelText('pet.recentTurns');+ const wrap = avatar.closest('.pet-mini-avatar-wrap')!;+ const hover = (value: boolean) => act(() => {+ window.dispatchEvent(new CustomEvent(PET_HOVER_EVENT, { detail: { hover: value } }));+ });+ hover(true);+ if (cause === 'open') {+ const opened = deferred<void>();+ const { petBridge } = await import('./petBridge');+ vi.spyOn(petBridge, 'open').mockReturnValue(opened.promise);+ await userEvent.dblClick(avatar);+ // The pointer leaves while the session handoff is still pending.+ hover(false);+ act(() => window.dispatchEvent(new Event('blur')));+ await act(async () => opened.resolve());+ } else {+ hover(false);+ act(() => window.dispatchEvent(new Event('blur')));+ }+ expect(wrap.classList.contains('is-hovered')).toBe(false);+ expect(wrap.classList.contains('is-hover-suppressed')).toBe(true);+ // The shell emits transitions only: no second false arrives before enter.+ hover(true);+ expect(wrap.classList.contains('is-hover-suppressed')).toBe(false);+ expect(wrap.classList.contains('is-hovered')).toBe(true);+ });++ it('keeps the typing dock active through a double-click and window blur', async () => {+ mainSession('S'); render(<PetPage />);+ await userEvent.click(await screen.findByLabelText('pet.keyboard.open'));+ const input = await screen.findByRole('textbox');+ const { petBridge } = await import('./petBridge');+ vi.spyOn(petBridge, 'open').mockResolvedValue();+ await userEvent.dblClick(screen.getByLabelText('pet.recentTurns'));+ act(() => window.dispatchEvent(new Event('blur')));+ expect(document.querySelector('.pet-mini-dock.is-active')).not.toBeNull();+ expect(document.querySelector('.is-hover-suppressed')).toBeNull();+ expect(screen.getByRole('textbox')).toBe(input);+ });++ it('keeps listening and finishing docks active through double-click and blur', async () => {+ const done = deferred<string>();+ const finish = vi.fn();+ class Dictation { done = done.promise; start = async () => {}; finish = finish; abort = () => {}; }+ await withVoiceEnv(() => true, Dictation, async () => {+ mainSession('S'); render(<PetPage />);+ await userEvent.click(await screen.findByLabelText('pet.voice.open'));+ await waitFor(() => expect(pose()).toBe('listening'));+ const { petBridge } = await import('./petBridge');+ vi.spyOn(petBridge, 'open').mockResolvedValue();+ await userEvent.dblClick(screen.getByLabelText('pet.recentTurns'));+ act(() => window.dispatchEvent(new Event('blur')));+ expect(pose()).toBe('listening');+ expect(document.querySelector('.pet-mini-dock.is-active')).not.toBeNull();+ expect(document.querySelector('.is-hover-suppressed')).toBeNull();+ await userEvent.click(screen.getByLabelText('pet.voice.stop'));+ expect(finish).toHaveBeenCalledOnce();+ act(() => window.dispatchEvent(new Event('blur')));+ expect(document.querySelector('.pet-mini-dock.is-active')).not.toBeNull();+ expect(document.querySelector('.is-hover-suppressed')).toBeNull();+ await act(async () => done.resolve('transcript'));+ expect(await screen.findByRole('textbox')).toBeTruthy();+ });+ });+it('keeps the unread count visible until the inbox confirms the result was read', async () => {tails.S = [message('u', 'S', { author: 'user', type: 'user' }), message('r', 'S', { read_at: null })];unreadBySession = { S: 1 };@@ -2088,44 +2181,103 @@ describe('desktop mini v2 interaction contract', () => {});});- it('a double-click opens the conversation in Avibe and leaves the history as before', async () => {- const invoke = vi.fn((command: string) => {- if (command === 'pet_ready') return Promise.resolve({ binding: 'S', revision: 1, summon_pending: null });- if (command === 'pet_open') return Promise.resolve(null);- return Promise.resolve({ panel_side: 'left', panel_edge: 'bottom' });- });- Object.defineProperty(window, '__AVIBE_DESKTOP_SHELL__', { value: true, configurable: true });- Object.defineProperty(window, '__TAURI_INTERNALS__', { value: { invoke }, configurable: true });- try {- withHistory();- mainSession('S'); render(<PetPage />);- await waitFor(() => expect(document.querySelector('.pet-mini-reply-bubble')?.textContent).toContain('Old reply'));- const avatar = screen.getByLabelText('pet.recentTurns');- const opens = () => invoke.mock.calls.filter(([command]) => command === 'pet_open');- // Closed before: closed after, with the conversation opened once.- await userEvent.setup().dblClick(avatar);- await waitFor(() => expect(opens()).toEqual([['pet_open', { link: 'avibe://session/S' }]]));- await act(async () => new Promise((resolve) => setTimeout(resolve, 15)));- expect(historyIsOpen()).toBe(false);- expect(avatar.getAttribute('aria-expanded')).toBe('false');- // Open before: open after.- await userEvent.click(avatar);- await waitFor(() => expect(historyIsOpen()).toBe(true));- await userEvent.setup().dblClick(avatar);- await waitFor(() => expect(opens()).toHaveLength(2));- await act(async () => new Promise((resolve) => setTimeout(resolve, 15)));- expect(historyIsOpen()).toBe(true);- expect(avatar.getAttribute('aria-expanded')).toBe('true');- // Keyboard activation (no click count) and single clicks never open it.+ it.each([false, true])('a double-click opens once without ever toggling history (initially open=%s)', async (initiallyOpen) => {+ withHistory();+ mainSession('S'); render(<PetPage />);+ await waitFor(() => expect(document.querySelector('.pet-mini-reply-bubble')?.textContent).toContain('Old reply'));+ const { petBridge } = await import('./petBridge');+ const opens = vi.spyOn(petBridge, 'open').mockResolvedValue();+ const panel = vi.spyOn(petBridge, 'setExpanded');+ const avatar = screen.getByLabelText('pet.recentTurns');+ if (initiallyOpen) {fireEvent.click(avatar);- await waitFor(() => expect(historyIsOpen()).toBe(false));- await userEvent.click(avatar);await waitFor(() => expect(historyIsOpen()).toBe(true));- expect(opens()).toHaveLength(2);- } finally {- Reflect.deleteProperty(window, '__AVIBE_DESKTOP_SHELL__');- Reflect.deleteProperty(window, '__TAURI_INTERNALS__');}+ panel.mockClear();+ vi.useFakeTimers({ shouldAdvanceTime: true });+ const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime });+ await user.dblClick(avatar);+ expect(historyIsOpen()).toBe(initiallyOpen);+ expect(panel).not.toHaveBeenCalled();+ expect(opens).toHaveBeenCalledExactlyOnceWith('avibe://session/S');+ // The main window taking key is part of the double-click, not a collapse.+ act(() => window.dispatchEvent(new Event('blur')));+ await act(async () => vi.advanceTimersByTime(1000));+ expect(historyIsOpen()).toBe(initiallyOpen);+ expect(panel).not.toHaveBeenCalled();+ expect(opens).toHaveBeenCalledTimes(1);+ });++ it('confirms single pointer clicks after 450ms, while keyboard activation is immediate', async () => {+ withHistory();+ mainSession('S'); render(<PetPage />);+ await waitFor(() => expect(document.querySelector('.pet-mini-reply-bubble')?.textContent).toContain('Old reply'));+ const { petBridge } = await import('./petBridge');+ const opens = vi.spyOn(petBridge, 'open').mockResolvedValue();+ const avatar = screen.getByLabelText('pet.recentTurns');+ vi.useFakeTimers();+ for (const next of [true, false]) {+ fireEvent.pointerDown(avatar, { button: 0 });+ fireEvent.pointerUp(avatar);+ expect(historyIsOpen()).toBe(!next);+ await act(async () => vi.advanceTimersByTime(449));+ expect(historyIsOpen()).toBe(!next);+ await act(async () => vi.advanceTimersByTime(1));+ expect(historyIsOpen()).toBe(next);+ }+ await act(async () => fireEvent.click(avatar));+ expect(historyIsOpen()).toBe(true);+ await act(async () => fireEvent.click(avatar));+ expect(historyIsOpen()).toBe(false);+ expect(opens).not.toHaveBeenCalled();+ });++ it.each([1, 2])('pairs a second press with click count %s before the first timer can fire', async (clicks) => {+ withHistory();+ mainSession('S'); render(<PetPage />);+ await waitFor(() => expect(document.querySelector('.pet-mini-reply-bubble')?.textContent).toContain('Old reply'));+ const { petBridge } = await import('./petBridge');+ const opens = vi.spyOn(petBridge, 'open').mockResolvedValue();+ const panel = vi.spyOn(petBridge, 'setExpanded');+ const avatar = screen.getByLabelText('pet.recentTurns');+ vi.useFakeTimers();+ fireEvent.pointerDown(avatar, { button: 0 });+ fireEvent.mouseDown(avatar, { detail: 1 });+ fireEvent.pointerUp(avatar);+ await act(async () => vi.advanceTimersByTime(440));+ expect(historyIsOpen()).toBe(false);+ fireEvent.pointerDown(avatar, { button: 0 });+ fireEvent.mouseDown(avatar, { detail: clicks });+ await act(async () => vi.advanceTimersByTime(100));+ expect(panel).not.toHaveBeenCalled();+ fireEvent.pointerUp(avatar);+ fireEvent.doubleClick(avatar);+ await act(async () => vi.advanceTimersByTime(1000));+ expect(panel).not.toHaveBeenCalled();+ expect(opens).toHaveBeenCalledExactlyOnceWith('avibe://session/S');+ });++ it.each(['hold', 'drag', 'cancel', 'leave'])('a %s cancels a pending click and cannot open the conversation', async (gesture) => {+ withHistory();+ mainSession('S'); render(<PetPage />);+ await waitFor(() => expect(document.querySelector('.pet-mini-reply-bubble')?.textContent).toContain('Old reply'));+ const { petBridge } = await import('./petBridge');+ const opens = vi.spyOn(petBridge, 'open').mockResolvedValue();+ const avatar = screen.getByLabelText('pet.recentTurns');+ vi.useFakeTimers();+ fireEvent.pointerDown(avatar, { button: 0 });+ fireEvent.pointerUp(avatar);+ fireEvent.pointerDown(avatar, { button: 0, clientX: 0, clientY: 0 });+ fireEvent.mouseDown(avatar, { detail: 2 });+ if (gesture === 'hold') await act(async () => vi.advanceTimersByTime(320));+ if (gesture === 'drag') fireEvent.pointerMove(avatar, { buttons: 1, clientX: 20, clientY: 0 });+ if (gesture === 'cancel') fireEvent.pointerCancel(avatar);+ if (gesture === 'leave') fireEvent.pointerLeave(avatar);+ fireEvent.pointerUp(avatar);+ fireEvent.doubleClick(avatar);+ await act(async () => vi.advanceTimersByTime(1000));+ expect(historyIsOpen()).toBe(false);+ expect(opens).not.toHaveBeenCalled();});it('a quick click after a hold is a single click, not a double-click', async () => {@@ -2155,7 +2307,7 @@ describe('desktop mini v2 interaction contract', () => {expect(invoke.mock.calls.filter(([command]) => command === 'pet_open')).toEqual([]);});- it('a double-click that first collapsed the card list puts the list back', async () => {+ it('a double-click never collapses the expanded card list, while a confirmed single click does', async () => {canUseAgents = true;const row = workingIn('running').agents[0];runningAgents = { ...workingIn('running'), agents: [@@ -2167,9 +2319,23 @@ describe('desktop mini v2 interaction contract', () => {await waitFor(() => expect(document.querySelector('.pet-mini-collapsed')).not.toBeNull());await showCards();await waitFor(() => expect(document.querySelector('.pet-mini-scroll')).not.toBeNull());- await userEvent.setup().dblClick(screen.getByLabelText('pet.recentTurns'));- await act(async () => new Promise((resolve) => setTimeout(resolve, 15)));+ const { petBridge } = await import('./petBridge');+ vi.spyOn(petBridge, 'open').mockResolvedValue();+ const panel = vi.spyOn(petBridge, 'setExpanded');+ const avatar = screen.getByLabelText('pet.recentTurns');+ vi.useFakeTimers({ shouldAdvanceTime: true });+ const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime });+ await user.dblClick(avatar);expect(document.querySelector('.pet-mini-scroll')).not.toBeNull();+ expect(panel).not.toHaveBeenCalled();+ await act(async () => vi.advanceTimersByTime(1000));+ expect(document.querySelector('.pet-mini-scroll')).not.toBeNull();+ expect(panel).not.toHaveBeenCalled();+ expect(historyIsOpen()).toBe(false);+ await user.click(avatar);+ expect(document.querySelector('.pet-mini-scroll')).not.toBeNull();+ await act(async () => vi.advanceTimersByTime(450));+ expect(document.querySelector('.pet-mini-scroll')).toBeNull();expect(historyIsOpen()).toBe(false);});});@@ -2760,6 +2926,23 @@ describe('Vibey bubble visibility (spec §4.2)', () => {expect(bubbleOpen()).toBe(true);});+ it('a double-click leaves the lingering reply unseen and on its original timer', async () => {+ await runToResult();+ const { petBridge } = await import('./petBridge');+ const opens = vi.spyOn(petBridge, 'open').mockResolvedValue();+ const panel = vi.spyOn(petBridge, 'setExpanded');+ await userEvent.dblClick(screen.getByLabelText('pet.recentTurns'));+ expect(opens).toHaveBeenCalledExactlyOnceWith('avibe://session/S');+ expect(panel).not.toHaveBeenCalled();+ expect(markRead).not.toHaveBeenCalled();+ expect(bubbleOpen()).toBe(true);+ await act(async () => vi.advanceTimersByTime(1000));+ expect(document.querySelector('.pet-mini-detail.is-open')).toBeNull();+ expect(bubbleOpen()).toBe(true);+ await act(async () => vi.advanceTimersByTime(9500));+ expect(bubbleOpen()).toBe(false);+ });+it('keeps the bubble open from running to its result, then shows the reply for 10s', async () => {const classes = await runToResult();// No closed frame between the running bubble and the reply.diff --git a/ui/src/pet/PetPage.tsx b/ui/src/pet/PetPage.tsxindex a0678ca6b..d6eb14cb7 100644--- a/ui/src/pet/PetPage.tsx+++ b/ui/src/pet/PetPage.tsx@@ -35,6 +35,7 @@ import { FencedSource } from './fencedSource';import './pet-mini.css';const HOLD_MS = 320;+const DOUBLE_CLICK_MS = 450;const DISMISS_EXIT_MS = 500;const STOP_CONFIRM_MS = 3000;const STOP_LINGER_MS = 2500;@@ -281,25 +282,6 @@ const PetSurface: React.FC = () => {if (!binding || resolvingMain || (data.messages.length === 0 && !optimisticTitle)) return;openHistory();};- // A double-click (§5.1) opens Vibey's conversation in the main window. Its- // first click already acted, so the second puts the history and the cards- // back as they were before it.- const vibeyBefore = useRef<{ detailOpen: boolean; expanded: boolean } | null>(null);- const clickVibey = () => {- vibeyBefore.current = { detailOpen, expanded: petPanel.want() };- toggleVibey();- };- const doubleClickVibey = () => {- const before = vibeyBefore.current;- vibeyBefore.current = null;- if (before?.detailOpen) {- if (!detailOpen) openHistory();- } else if (before) {- setDetailOpen(false);- if (petPanel.want() !== before.expanded) void setPanel(before.expanded);- }- if (binding) void petBridge.open(sessionLink(binding)).catch(() => undefined);- };const [composing, setComposing] = useState(false);const [presentations, setPresentations] = useState<Record<string, CardPresentation>>({});const presentationNow = useRef<Record<string, CardPresentation>>({});@@ -317,9 +299,13 @@ const PetSurface: React.FC = () => {const [orderedIds, setOrderedIds] = useState<string[]>([]);const stopTimers = useRef<Record<string, number>>({});const inputRef = useRef<HTMLTextAreaElement>(null);- // `clicks` is the platform's click count for this press (its mousedown- // `detail`): 2 is the second press of a double-click.- const pressRef = useRef<{ held: boolean; dragged: boolean; clicks: number; x: number; y: number; timer: number } | null>(null);+ const avatarRef = useRef<HTMLButtonElement>(null);+ // Pair native mousedown click counts with time for webviews that always report 1.+ // No history/card side effects occur until a pointer single click is confirmed.+ const pressRef = useRef<{ held: boolean; dragged: boolean; clicks: number; double: boolean; x: number; y: number; timer: number } | null>(null);+ const pendingClickRef = useRef<{ at: number; timer: number } | null>(null);+ const doubleOpenedRef = useRef(false);+ const allowDoubleEventRef = useRef(false);const dismissTimers = useRef<Record<string, number>>({});const updatePresentation = useCallback((key: string, patch: CardPresentation | null) => {const next = { ...presentationNow.current };@@ -364,9 +350,13 @@ const PetSurface: React.FC = () => {Object.values(stopTimers.current).forEach(window.clearTimeout);Object.values(dismissTimers.current).forEach(window.clearTimeout);if (pressRef.current) window.clearTimeout(pressRef.current.timer);+ if (pendingClickRef.current) window.clearTimeout(pendingClickRef.current.timer);stopTimers.current = {};dismissTimers.current = {};pressRef.current = null;+ pendingClickRef.current = null;+ doubleOpenedRef.current = false;+ allowDoubleEventRef.current = false;};}, [binding, epoch]);useEffect(() => {@@ -376,7 +366,27 @@ const PetSurface: React.FC = () => {// The shell reports hover over Vibey and the dock: macOS gives a webview no// hover while its window is not key, and the pet never takes focus itself.const [hovered, setHovered] = useState(false);- useEffect(() => onPetHover(setHovered), []);+ const [hoverSuppressed, setHoverSuppressed] = useState(false);+ const shellHoveredRef = useRef(false);+ const hoverSuppressedRef = useRef(false);+ const handlePetHover = useCallback((next: boolean) => {+ shellHoveredRef.current = next;+ if (next && hoverSuppressedRef.current) {+ setHovered(false);+ return;+ }+ if (!next) hoverSuppressedRef.current = false;+ // Keep CSS hover suppressed until a fresh enter, even if WebKit's :hover is stale.+ if (next) setHoverSuppressed(false);+ setHovered(next);+ }, []);+ useEffect(() => onPetHover(handlePetHover), [handlePetHover]);+ const cancelPendingClick = useCallback(() => {+ const pending = pendingClickRef.current;+ if (!pending) return;+ window.clearTimeout(pending.timer);+ pendingClickRef.current = null;+ }, []);useEffect(() => {if (exchange.user?.text?.trim() === optimisticTitle) setOptimisticTitle('');@@ -615,11 +625,31 @@ const PetSurface: React.FC = () => {if (hotkeyHeld.current && voice.available) voice.start();else openComposer(draft);}, [listenPending, binding, canChat, expanded, voice.available, voice.start, openComposer, draft, uncertain]);+ const dockActiveRef = useRef(false);+ useLayoutEffect(() => { dockActiveRef.current = voice.busy || composing; }, [voice.busy, composing]);+ const suppressDock = useCallback(() => {+ if (dockActiveRef.current) return;+ // The shell emits transitions only; an already-outside pointer can enter next.+ hoverSuppressedRef.current = shellHoveredRef.current;+ setHoverSuppressed(true);+ setHovered(false);+ avatarRef.current?.blur();+ }, []);useEffect(() => {- const onBlur = () => { if (!voice.busy && !draft.trim()) void setPanel(false); };+ const onBlur = () => {+ cancelPendingClick();+ suppressDock();+ // Opening Avibe must preserve the history/card list through its key change.+ if (!doubleOpenedRef.current && !voice.busy && !draft.trim()) void setPanel(false);+ };+ const onFocus = () => { doubleOpenedRef.current = false; };window.addEventListener('blur', onBlur);- return () => window.removeEventListener('blur', onBlur);- }, [voice.busy, draft, setPanel]);+ window.addEventListener('focus', onFocus);+ return () => {+ window.removeEventListener('blur', onBlur);+ window.removeEventListener('focus', onFocus);+ };+ }, [cancelPendingClick, draft, setPanel, suppressDock, voice.busy]);useEffect(() => {const onKey = (event: KeyboardEvent) => {// Escape also dismisses an IME candidate list; that one is not ours.@@ -745,7 +775,6 @@ const PetSurface: React.FC = () => {const documentVisible = useDocumentVisible();const [pointerOverBubble, setPointerOverBubble] = useState(false);const bubbleRef = useRef<HTMLDivElement | null>(null);- const avatarRef = useRef<HTMLButtonElement>(null);// Focus inside a bubble that is replaced (by the input, the dictation// marquee, or a loading notice) moves to Vibey rather than to nowhere, or to// the input when the bubble closes above it. The node is checked as it@@ -784,6 +813,35 @@ const PetSurface: React.FC = () => {const toggleHistory = () => {if (detailOpen) { setDetailOpen(false); void setPanel(false); } else openHistory();};+ const openDoubleClick = () => {+ if (doubleOpenedRef.current) return;+ doubleOpenedRef.current = true;+ cancelPendingClick();+ if (!binding) return;+ void petBridge.open(sessionLink(binding)).then(() => {+ if (epoch.isCurrent()) suppressDock();+ }, () => undefined);+ };+ const beginDoubleClick = (clicks: number) => {+ const pending = pendingClickRef.current;+ // A native count alone cannot pair a click with a previous hold or drag.+ if (!pending || (clicks !== 2 && performance.now() - pending.at > DOUBLE_CLICK_MS)) return false;+ cancelPendingClick();+ return true;+ };+ const toggleVibeyRef = useRef(toggleVibey);+ useLayoutEffect(() => { toggleVibeyRef.current = toggleVibey; });+ const scheduleSingleClick = () => {+ cancelPendingClick();+ const at = performance.now();+ const timer = window.setTimeout(() => {+ if (pendingClickRef.current?.timer !== timer || !epoch.isCurrent()) return;+ pendingClickRef.current = null;+ allowDoubleEventRef.current = false;+ toggleVibeyRef.current();+ }, DOUBLE_CLICK_MS);+ pendingClickRef.current = { at, timer };+ };useLayoutEffect(() => {// Focus inside a bubble that folds away (still mounted) moves to Vibey too.if (showReplyBubble) return;@@ -792,7 +850,12 @@ const PetSurface: React.FC = () => {}, [showReplyBubble]);const avatar = (- <div className={clsx('pet-mini-avatar-wrap', voice.listening && 'is-listening', hovered && 'is-hovered')} data-pet-hover>+ <div className={clsx(+ 'pet-mini-avatar-wrap',+ voice.listening && 'is-listening',+ hovered && 'is-hovered',+ hoverSuppressed && 'is-hover-suppressed',+ )} data-pet-hover>{voice.listening && <span className="pet-mini-listen-ring" aria-hidden />}<buttonref={avatarRef}@@ -802,25 +865,51 @@ const PetSurface: React.FC = () => {aria-label={t('pet.recentTurns')}aria-expanded={historyOpen}data-pet-hit- onClick={(event) => { if (event.detail === 0) toggleVibey(); }}+ onClick={(event) => {+ if (event.detail !== 0) return;+ cancelPendingClick();+ doubleOpenedRef.current = false;+ allowDoubleEventRef.current = false;+ toggleVibey();+ }}+ onDoubleClick={() => {+ if (allowDoubleEventRef.current) openDoubleClick();+ }}onPointerDown={(event) => {if (event.button !== 0) return;const target = event.currentTarget;const pointerId = event.pointerId;- pressRef.current = { held: false, dragged: false, clicks: 1, x: event.clientX, y: event.clientY, timer: window.setTimeout(() => {- if (!epoch.isCurrent()) return;- const press = pressRef.current;- if (!press) return;- press.held = true;- target.setPointerCapture?.(pointerId);- if (!canChat || !binding) { void setPanel(true); return; }- if (uncertain) { void setPanel(true); setDetailOpen(true); return; }- if (voice.available) voice.start();- else openComposer(draft);- }, HOLD_MS) };+ doubleOpenedRef.current = false;+ allowDoubleEventRef.current = false;+ pressRef.current = {+ held: false,+ dragged: false,+ clicks: event.detail || 1,+ double: beginDoubleClick(event.detail),+ x: event.clientX,+ y: event.clientY,+ timer: window.setTimeout(() => {+ if (!epoch.isCurrent()) return;+ const press = pressRef.current;+ if (!press) return;+ press.held = true;+ cancelPendingClick();+ doubleOpenedRef.current = false;+ allowDoubleEventRef.current = false;+ target.setPointerCapture?.(pointerId);+ if (!canChat || !binding) { void setPanel(true); return; }+ if (uncertain) { void setPanel(true); setDetailOpen(true); return; }+ if (voice.available) voice.start();+ else openComposer(draft);+ }, HOLD_MS),+ };}}onMouseDown={(event) => {- if (pressRef.current) pressRef.current.clicks = event.detail;+ const press = pressRef.current;+ if (press) {+ press.clicks = event.detail;+ if (!press.double && beginDoubleClick(event.detail)) press.double = true;+ }// The input keeps its focus and caret: a Vibey click is not leaving it.if (inputRef.current && document.activeElement === inputRef.current) event.preventDefault();}}@@ -830,14 +919,19 @@ const PetSurface: React.FC = () => {if (Math.hypot(event.clientX - press.x, event.clientY - press.y) < 4) return;press.dragged = true;window.clearTimeout(press.timer);+ cancelPendingClick();+ doubleOpenedRef.current = false;+ allowDoubleEventRef.current = false;// The drop's layout arrives as the shell's snapshot (petShell).void petBridge.drag().catch(() => undefined);}}onPointerCancel={() => {const press = pressRef.current;pressRef.current = null;- vibeyBefore.current = null;if (press) window.clearTimeout(press.timer);+ cancelPendingClick();+ doubleOpenedRef.current = false;+ allowDoubleEventRef.current = false;if (press?.held) voice.stop(true);}}onPointerUp={() => {@@ -845,20 +939,29 @@ const PetSurface: React.FC = () => {pressRef.current = null;if (!press) return;window.clearTimeout(press.timer);- // Only a click right after a click on Vibey is its double-click; a- // hold, a drag or a cancelled press in between starts over.- if (press.held || press.dragged || press.clicks > 2) vibeyBefore.current = null;- if (press.held) voice.stop(true);- else if (press.dragged || press.clicks > 2) return;- else if (press.clicks === 2 && vibeyBefore.current) doubleClickVibey();- else clickVibey();+ if (press.held) {+ voice.stop(true);+ doubleOpenedRef.current = false;+ allowDoubleEventRef.current = false;+ } else if (press.dragged || press.clicks > 2) {+ cancelPendingClick();+ doubleOpenedRef.current = false;+ allowDoubleEventRef.current = false;+ } else if (press.double) {+ allowDoubleEventRef.current = true;+ openDoubleClick();+ } else {+ scheduleSingleClick();+ }}}onPointerLeave={() => {const press = pressRef.current;if (press && !press.held) {window.clearTimeout(press.timer);pressRef.current = null;- vibeyBefore.current = null;+ cancelPendingClick();+ doubleOpenedRef.current = false;+ allowDoubleEventRef.current = false;}}}onContextMenu={(event) => event.preventDefault()}diff --git a/ui/src/pet/pet-mini.css b/ui/src/pet/pet-mini.cssindex 01fe09258..64518100c 100644--- a/ui/src/pet/pet-mini.css+++ b/ui/src/pet/pet-mini.css@@ -526,6 +526,12 @@ to {opacity:1;transform:none;pointer-events:auto}+@media (hover:hover) {+.pet-mini-avatar-wrap.is-hover-suppressed .pet-mini-dock:not(.is-active) {+ opacity:0;+ transform:translateY(-6px) scale(.92);+ pointer-events:none}+}.pet-mini-dock button {display:flex;width:32px;