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.

fix(desktop): route every mini press-and-hold through one voice decision

Max475e236a0fc9
diff --git a/docs/plans/2026-10-12-desktop-mini-delivery.md b/docs/plans/2026-10-12-desktop-mini-delivery.md
index f85fcc479..9d9182ef6 100644
--- a/docs/plans/2026-10-12-desktop-mini-delivery.md
+++ b/docs/plans/2026-10-12-desktop-mini-delivery.md
@@ -58,8 +58,9 @@ can be verified on a real desktop test prerelease. Pet voice now appears
whenever Web Locks, `getUserMedia` and ASR are all available; missing Web Locks
still denies it, and hotkey/hold still falls back to text in that case. ASR
status is read as soon as voice may be used (the pet window starts unfocused,
-so this read does not wait for focus), and a held-hotkey summon waits for that
-first read. Each window reactivation re-reads it, so a settings change takes
+so this read does not wait for focus). Every press-and-hold entry (hotkey and
+avatar) goes through one queued decision that waits for that first read while
+held and falls back to text if released first. Each window reactivation re-reads it, so a settings change takes
effect without restarting the pet; a failed re-read keeps the last known status.
Availability gates only starting a capture; an active capture keeps its stop
control.
diff --git a/ui/src/pet/PetPage.test.tsx b/ui/src/pet/PetPage.test.tsx
index 7aed4f528..c9be2accf 100644
--- a/ui/src/pet/PetPage.test.tsx
+++ b/ui/src/pet/PetPage.test.tsx
@@ -1737,6 +1737,35 @@ describe('desktop mini v2 interaction contract', () => {
});
});
+ it.each([
+ ['still held', true],
+ ['released', false],
+ ])('decides an avatar hold that outlives a pending ASR read once it settles (%s)', async (_label, held) => {
+ const status = deferred<{ ok: boolean; json: () => Promise<unknown> }>();
+ class Dictation { done = new Promise<string>(() => {}); start = async () => {}; finish = () => {}; abort = () => {}; }
+ await withVoiceEnv(() => true, Dictation, async () => {
+ vi.stubGlobal('fetch', vi.fn(() => status.promise));
+ devBind('S'); render(<PetPage />); await screen.findByText('Session S');
+ const avatar = screen.getByLabelText('pet.toggle');
+ vi.useFakeTimers();
+ try {
+ fireEvent.pointerDown(avatar, { button: 0, pointerId: 1 });
+ await act(async () => vi.advanceTimersByTime(400));
+ expect(screen.queryByRole('textbox')).toBeNull();
+ expect(pose()).not.toBe('listening');
+ if (!held) fireEvent.pointerUp(avatar, { pointerId: 1 });
+ await act(async () => status.resolve({ ok: true, json: async () => ({ available: true }) }));
+ } finally {
+ vi.useRealTimers();
+ }
+ if (held) await waitFor(() => expect(pose()).toBe('listening'));
+ else {
+ expect(await screen.findByRole('textbox')).toBeTruthy();
+ expect(pose()).not.toBe('listening');
+ }
+ });
+ });
+
it('discards voice preview and final text from the previous authorization epoch', async () => {
const done = deferred<string>();
let preview!: (text: string) => void;
diff --git a/ui/src/pet/PetPage.tsx b/ui/src/pet/PetPage.tsx
index 8692496b3..29eb72cd0 100644
--- a/ui/src/pet/PetPage.tsx
+++ b/ui/src/pet/PetPage.tsx
@@ -418,12 +418,12 @@ const PetSurface: React.FC = () => {
}, [setPanel, voice.stop, voice.listening, composing]);
useOnSummon(onSummon);
useEffect(() => {
- if (!listenPending || !binding || !canChat || !expanded || voice.pending) return;
+ if (!listenPending || !binding || !canChat || !expanded) return;
petComposer.takeListen();
if (uncertain) { setDetailOpen(true); return; }
- if (voice.available && hotkeyHeld.current) voice.start();
+ if (hotkeyHeld.current) voice.begin();
else openComposer(draft);
- }, [listenPending, binding, canChat, expanded, voice.pending, voice.available, voice.start, openComposer, draft, uncertain]);
+ }, [listenPending, binding, canChat, expanded, voice.begin, openComposer, draft, uncertain]);
useEffect(() => {
const onBlur = () => { if (!voice.listening && !draft.trim()) void setPanel(false); };
window.addEventListener('blur', onBlur);
@@ -484,8 +484,7 @@ const PetSurface: React.FC = () => {
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);
+ voice.begin();
}, HOLD_MS) };
}}
onPointerMove={(event) => {
@@ -743,7 +742,18 @@ function usePetVoice({ enabled, epoch, draft, onOpenComposer }: { enabled: boole
}).catch(() => { if (alive && epoch.isCurrent()) unknown(); });
return () => { alive = false; };
}, [enabled, epoch, asrReads]);
+ // A press-and-hold is queued here and decided by an effect with the current
+ // render's state, so callers holding a stale closure still decide correctly.
+ // Before the first status read settles a held press waits; releasing it
+ // falls back to text right away.
+ const queuedRef = useRef<'held' | 'released' | null>(null);
+ const [queueTick, setQueueTick] = useState(0);
const stop = useCallback((commit: boolean) => {
+ if (queuedRef.current) {
+ queuedRef.current = commit ? 'released' : null;
+ setQueueTick((tick) => tick + 1);
+ return;
+ }
const capture = captureRef.current;
if (!capture) return;
capture.ending = true;
@@ -796,9 +806,24 @@ function usePetVoice({ enabled, epoch, draft, onOpenComposer }: { enabled: boole
const clearError = useCallback(() => setError(null), []);
useEffect(() => cancel, [epoch, enabled, cancel]);
useEffect(() => () => setError(null), [epoch, enabled]);
- // Until the first status read settles, a voice summon cannot tell voice from text.
+ // Press-and-hold entry for every surface (hotkey and avatar): voice when it
+ // is available, text otherwise.
const pending = enabled && supported && !asr.settled;
- return { available, pending, cloudRequired: asr.checked && !asr.available, listening, preview, error, clearError, start, stop, cancel };
+ const begin = useCallback(() => {
+ queuedRef.current = 'held';
+ setQueueTick((tick) => tick + 1);
+ }, []);
+ useEffect(() => {
+ const queued = queuedRef.current;
+ if (!queued || (queued === 'held' && pending)) return;
+ queuedRef.current = null;
+ // A deferred press handler: it acts on a user press once state allows.
+ // eslint-disable-next-line react-hooks/set-state-in-effect
+ if (queued === 'held' && available) start();
+ else onOpenComposer(draft);
+ }, [queueTick, pending, available, start, onOpenComposer, draft]);
+ useEffect(() => () => { queuedRef.current = null; }, [epoch, enabled]);
+ return { available, begin, cloudRequired: asr.checked && !asr.available, listening, preview, error, clearError, start, stop, cancel };
}
type VoiceFailure = 'startFailed' | 'empty' | 'failed';