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): animate Vibey whenever the pet window is visible (#2799)
Max9366ef5b5fa6
diff --git a/docs/plans/2026-10-12-desktop-mini-main-agent.md b/docs/plans/2026-10-12-desktop-mini-main-agent.mdindex 8dc6c7940..951850c40 100644--- a/docs/plans/2026-10-12-desktop-mini-main-agent.md+++ b/docs/plans/2026-10-12-desktop-mini-main-agent.md@@ -424,7 +424,9 @@ Two beats, so the exit reads before the reflow:down; and `sleeping` sends a small `z` followed by a large `Z` upward.`idle` and `listening` render body-only art with the existing breathing.- The layered loops animate `transform` and `opacity` only. They pause while- the page is inactive. Reduced motion disables every animation and leaves the+ the window is hidden (`document.visibilityState` is not `visible`); focus+ does not matter, because the pet window is visible without ever taking+ focus. Reduced motion disables every animation and leaves thefull static composition visible. Sleeping deliberately keeps its `z`/`Z`loop while the window is visible, even though idle still settles after 30s.- Vibey on the mini stage is **115px** (the owner tuned it on the prototype:diff --git a/ui/e2e/pet-mini/layout.spec.ts b/ui/e2e/pet-mini/layout.spec.tsindex 871432130..043318cc0 100644--- a/ui/e2e/pet-mini/layout.spec.ts+++ b/ui/e2e/pet-mini/layout.spec.ts@@ -459,3 +459,41 @@ for (const trigger of ['reconnect', 'reactivation']) {expect(await page.evaluate(() => JSON.parse(localStorage.getItem('avibe.pet.devBinding')!).binding)).toBe('ses_main');});}++for (const pose of ['idle', 'ready', 'sleeping']) {+ test(`layered art animates while visible but unfocused and pauses only when hidden (${pose})`, async ({ page }) => {+ await page.goto(`/e2e/pet-mini/fixture.html?pose=${pose}`);+ const art = page.locator('.vibey-art');+ await expect(art).toBeVisible();+ // The loops live on the layers; the root's one-shot pose-change squash is+ // allowed to finish, so it is not part of the reading.+ const playStates = () => art.evaluate((node) => [...node.querySelectorAll('*')]+ .map((element) => getComputedStyle(element))+ .filter((style) => style.animationName !== 'none')+ .map((style) => style.animationPlayState));++ // The pet window is shown without ever taking focus.+ await page.evaluate(() => {+ Object.defineProperty(document, 'hasFocus', { configurable: true, value: () => false });+ window.dispatchEvent(new Event('blur'));+ });+ await expect(art).toHaveAttribute('data-active', 'true');+ const unfocused = await playStates();+ expect(unfocused.length).toBeGreaterThan(0);+ expect(new Set(unfocused)).toEqual(new Set(['running']));++ await page.evaluate(() => {+ Object.defineProperty(document, 'visibilityState', { configurable: true, get: () => 'hidden' });+ document.dispatchEvent(new Event('visibilitychange'));+ });+ await expect(art).toHaveAttribute('data-active', 'false');+ expect(new Set(await playStates())).toEqual(new Set(['paused']));++ await page.evaluate(() => {+ Object.defineProperty(document, 'visibilityState', { configurable: true, get: () => 'visible' });+ document.dispatchEvent(new Event('visibilitychange'));+ });+ await expect(art).toHaveAttribute('data-active', 'true');+ expect(new Set(await playStates())).toEqual(new Set(['running']));+ });+}diff --git a/ui/src/components/onboarding/motion.ts b/ui/src/components/onboarding/motion.tsindex 3e8c3f42b..d24eceb04 100644--- a/ui/src/components/onboarding/motion.ts+++ b/ui/src/components/onboarding/motion.ts@@ -1,24 +1,8 @@import { useEffect, useState } from 'react';+import { useDocumentVisible } from '@/lib/pageActivity';import { useRouteSurfaceActive } from '@/lib/routeSurfaceActivity';import { useReducedMotion } from 'framer-motion';-/**- * Whether the document is being presented at all. An interval keeps firing in a- * background tab — throttled, so its deltas arrive in one lump — and a CSS- * animation keeps its own timeline running there too. Reading visibility here is- * what lets both stop together.- */-function useDocumentVisible() {- const [visible, setVisible] = useState(() => typeof document === 'undefined' || !document.hidden);- useEffect(() => {- const read = () => setVisible(!document.hidden);- read();- document.addEventListener('visibilitychange', read);- return () => document.removeEventListener('visibilitychange', read);- }, []);- return visible;-}-/*** Whether this particular composition is on screen. A hidden tab is only half the* question: on a short window the diagram can sit entirely above the viewport whilediff --git a/ui/src/lib/pageActivity.test.ts b/ui/src/lib/pageActivity.test.tsindex e07c0480d..2de23bd5c 100644--- a/ui/src/lib/pageActivity.test.ts+++ b/ui/src/lib/pageActivity.test.ts@@ -1,5 +1,6 @@// @vitest-environment jsdom+import { act, renderHook } from '@testing-library/react';import { afterEach, describe, expect, it, vi } from 'vitest';import {@@ -10,6 +11,7 @@ import {onPageReactivated,type AwayReason,type PageActivitySnapshot,+ useDocumentVisible,} from './pageActivity';describe('isPageActive', () => {@@ -430,3 +432,27 @@ describe('canMarkConversationRead', () => {expect(canMarkConversationRead({ ...visibleTranscript, foregroundAppWindow: true })).toBe(false);});});++describe('useDocumentVisible', () => {+ afterEach(() => {+ delete (document as { visibilityState?: unknown }).visibilityState;+ delete (document as { hasFocus?: unknown }).hasFocus;+ });++ const setVisibility = (state: DocumentVisibilityState) => {+ Object.defineProperty(document, 'visibilityState', { configurable: true, get: () => state });+ document.dispatchEvent(new Event('visibilitychange'));+ };++ it('follows document visibility and ignores window focus', () => {+ Object.defineProperty(document, 'hasFocus', { configurable: true, value: () => false });+ setVisibility('visible');+ const { result } = renderHook(() => useDocumentVisible());+ act(() => { window.dispatchEvent(new Event('blur')); });+ expect(result.current).toBe(true);+ act(() => setVisibility('hidden'));+ expect(result.current).toBe(false);+ act(() => setVisibility('visible'));+ expect(result.current).toBe(true);+ });+});diff --git a/ui/src/lib/pageActivity.ts b/ui/src/lib/pageActivity.tsindex ff724de9a..0457628f3 100644--- a/ui/src/lib/pageActivity.ts+++ b/ui/src/lib/pageActivity.ts@@ -363,3 +363,23 @@ export function onPageReactivated(listener: PageReactivationListener): () => voiexport function usePageActive(): boolean {return useSyncExternalStore(subscribePageActive, getPageActive, () => false);}++const readDocumentVisible = (): boolean =>+ typeof document === 'undefined' || document.visibilityState === 'visible';++const subscribeDocumentVisible = (listener: () => void): (() => void) => {+ if (typeof document === 'undefined') return () => {};+ document.addEventListener('visibilitychange', listener);+ return () => document.removeEventListener('visibilitychange', listener);+};++/**+ * Whether the document is shown at all, ignoring focus. This is the half of+ * page activity that decides whether work drawn on screen is seen: a visible+ * window the user has not clicked into is still in front of them. Read+ * `usePageActive` instead where the user's attention matters, such as marking+ * a conversation read.+ */+export function useDocumentVisible(): boolean {+ return useSyncExternalStore(subscribeDocumentVisible, readDocumentVisible, () => true);+}diff --git a/ui/src/pet/PetAvatar.tsx b/ui/src/pet/PetAvatar.tsxindex 289bb8d1f..878bb7613 100644--- a/ui/src/pet/PetAvatar.tsx+++ b/ui/src/pet/PetAvatar.tsx@@ -1,7 +1,7 @@import { useEffect, useState } from 'react';import { useTranslation } from 'react-i18next';-import { usePageActive } from '@/lib/pageActivity';+import { useDocumentVisible } from '@/lib/pageActivity';import { VibeyArt, type VibeyPose } from './VibeyArt';import type { PetState } from './petState';@@ -38,7 +38,9 @@ export const PetAvatar: React.FC<{ pose: PetPose; badge?: number }> = ({};const PetPoseImage: React.FC<{ pose: PetPose; alt: string }> = ({ pose, alt }) => {- const pageActive = usePageActive();+ // Visibility, not focus: the pet window never takes focus by itself, so+ // gating on focus would freeze the art for as long as the user only looks.+ const visible = useDocumentVisible();const resting = pose === 'idle';const [settled, setSettled] = useState(false);@@ -52,7 +54,7 @@ const PetPoseImage: React.FC<{ pose: PetPose; alt: string }> = ({ pose, alt }) =<VibeyArtpose={pose as VibeyPose}label={alt}- active={pageActive}+ active={visible}breathing={!resting || !settled}/>);diff --git a/ui/src/pet/VibeyArt.tsx b/ui/src/pet/VibeyArt.tsxindex 0bcd6afd4..1995f30d7 100644--- a/ui/src/pet/VibeyArt.tsx+++ b/ui/src/pet/VibeyArt.tsx@@ -107,8 +107,9 @@ const CONFIG: Record<VibeyPose, { body: string; mood: 'is-breathing' | 'is-sleep/*** Layered Vibey art. The body breathes while accessories run their own loops.- * `active` is controlled by page activity so a hidden desktop window pauses all- * animation work without changing the rendered composition.+ * `active` follows document visibility, not focus, so a hidden desktop window+ * pauses all animation work without changing the rendered composition while a+ * visible but unfocused pet keeps moving.*/export function VibeyArt({pose,diff --git a/ui/src/pet/vibey-art.css b/ui/src/pet/vibey-art.cssindex 0fca3a52a..ee1ffa7d6 100644--- a/ui/src/pet/vibey-art.css+++ b/ui/src/pet/vibey-art.css@@ -196,8 +196,9 @@90%, 100% { opacity: 0; transform: translate(14%, -26%) scale(.9); }}-/* Inactive pages pause looping body/accessory motion while allowing the- one-shot pose-change squash to reach its final state. */+/* Hidden documents pause looping body/accessory motion while allowing the+ one-shot pose-change squash to reach its final state. Focus does not+ matter: the pet window is visible without ever taking focus. */.vibey-art[data-active='false'] * {animation-play-state: paused !important;}