Skip to content

An agentic browser harness: an AI side panel & orb in your own logged-in Chrome, Edge, Arc, Brave or even Firefox run by the agent/subscription you already use (Claude Code, Codex, Antigravity). Free, open source, no API key. Also an MCP server.

feat(hands-free): draw the mic orb in a closed shadow root — words streamed as they are heard, a ring before sending, a press to discard, stop or approve, a long press to drag, and left Control held to talk

Shahriarc313970a14b8
diff --git a/src/extension/entrypoints/content.ts b/src/extension/entrypoints/content.ts
index 7b44fde..be5ad08 100644
--- a/src/extension/entrypoints/content.ts
+++ b/src/extension/entrypoints/content.ts
@@ -1,5 +1,6 @@
import { exposeActions } from '@/lib/actions/host';
import { exposeFrameProbe } from '@/lib/frames/host';
+import { exposeHandsFree } from '@/lib/handsfree/host';
import { exposeIndicator } from '@/lib/indicator/host';
import { exposeMonitor } from '@/lib/monitor/watch';
import { exposeRail } from '@/lib/rail/host';
@@ -20,5 +21,6 @@ export default defineContentScript({
exposeIndicator();
exposeRail();
exposeToast();
+ exposeHandsFree();
},
});
diff --git a/src/lib/handsfree/host.test.ts b/src/lib/handsfree/host.test.ts
new file mode 100644
index 0000000..43dd211
--- /dev/null
+++ b/src/lib/handsfree/host.test.ts
@@ -0,0 +1,357 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { fakeBrowser } from 'wxt/testing';
+import { OVERLAY_ATTRIBUTE } from '@/lib/overlay';
+import { AUTO_SEND_MS, HANDS_FREE_CHANNEL, type OrbCommand, type OrbView } from './events';
+import { exposeHandsFree } from './host';
+
+type Frame = { op: string } & Record<string, unknown>;
+type Unsent<T> = T extends unknown ? Omit<T, 'channel'> : never;
+type Trigger = (message: unknown, sender: unknown, respond: (value: unknown) => void) => Promise<unknown>;
+
+const view = (patch: Partial<OrbView> = {}): OrbView => ({
+ theme: 'ember',
+ since: 0,
+ position: null,
+ link: 'live',
+ run: 'idle',
+ voice: 'listening',
+ pushToTalk: false,
+ ...patch,
+});
+
+/* A person pressing a key; a key event the page makes up is untrusted, and the orb ignores it. */
+function key(type: 'keydown' | 'keyup', code: string, init: KeyboardEventInit = {}, trusted = true): void {
+ const event = new KeyboardEvent(type, { code, bubbles: true, ...init });
+ if (trusted) Object.defineProperty(event, 'isTrusted', { value: true });
+ window.dispatchEvent(event);
+}
+
+function trustedClick(target: Element): void {
+ const event = new MouseEvent('click', { bubbles: true });
+ Object.defineProperty(event, 'isTrusted', { value: true });
+ target.dispatchEvent(event);
+}
+
+let root: ShadowRoot | null;
+let sent: Frame[];
+const answers = new Map<string, unknown>();
+
+/* The orb answers through sendResponse, which the fake's typing leaves out. */
+async function deliver(command: Unsent<OrbCommand>): Promise<unknown> {
+ let reply: unknown;
+ await (fakeBrowser.runtime.onMessage.trigger as unknown as Trigger)({ channel: HANDS_FREE_CHANNEL, ...command }, {}, (value) => {
+ reply = value;
+ });
+ return reply;
+}
+
+const show = (patch: Partial<OrbView> = {}) => deliver({ op: 'show', view: view(patch) });
+const heard = (text: string, final: boolean) => deliver({ op: 'heard', text, final });
+const $ = <T extends Element = HTMLElement>(selector: string) => root!.querySelector(selector) as T;
+const requests = (op: string) => sent.filter((frame) => frame.op === op);
+const shown = () => [...root!.querySelectorAll('.tok')].map((token) => token.textContent).join(' ');
+const press = () => $('.orb').dispatchEvent(new MouseEvent('click', { bubbles: true }));
+
+beforeEach(() => {
+ vi.useFakeTimers();
+ fakeBrowser.reset();
+ sent = [];
+ answers.clear();
+ root = null;
+ vi.spyOn(fakeBrowser.runtime, 'sendMessage').mockImplementation(async (message: unknown) => {
+ const frame = message as Frame;
+ sent.push(frame);
+ return answers.get(frame.op) ?? { ok: true };
+ });
+ const attach = Element.prototype.attachShadow;
+ vi.spyOn(Element.prototype, 'attachShadow').mockImplementation(function (this: Element, init: ShadowRootInit) {
+ root = attach.call(this, { ...init, mode: 'open' });
+ return root;
+ });
+ if (!HTMLElement.prototype.setPointerCapture) HTMLElement.prototype.setPointerCapture = () => undefined;
+ exposeHandsFree();
+});
+
+afterEach(() => {
+ vi.useRealTimers();
+ vi.restoreAllMocks();
+ document.getElementById('browsentic-hands-free')?.remove();
+});
+
+describe('the hands-free orb', () => {
+ it('asks the background what to show as soon as the page loads', () => {
+ expect(requests('sync')).toHaveLength(1);
+ });
+
+ it('mounts as a marked overlay A-Eye will skip, and says so to the background', async () => {
+ expect(await show()).toEqual({ ok: true });
+ expect(document.getElementById('browsentic-hands-free')?.hasAttribute(OVERLAY_ATTRIBUTE)).toBe(true);
+ expect($('.wrap').dataset.tone).toBe('listen');
+ });
+
+ it('streams what is said, counts down after a pause, then sends it', async () => {
+ await show();
+ await heard('open the', false);
+ await heard('open the second result', false);
+ expect(shown()).toBe('open the second result');
+ expect($('.wrap').classList.contains('counting')).toBe(false);
+
+ await heard('open the second result', true);
+ expect($('.wrap').classList.contains('counting')).toBe(true);
+ expect(requests('submit')).toHaveLength(0);
+
+ vi.advanceTimersByTime(AUTO_SEND_MS);
+ expect(requests('submit')).toEqual([
+ expect.objectContaining({ text: 'open the second result', liveTools: false }),
+ ]);
+ expect($('.caption').dataset.kind).toBe('sent');
+ });
+
+ it('keeps words that did not change, and only streams in the new ones', async () => {
+ await show();
+ await heard('scroll down', false);
+ const first = root!.querySelector('.tok');
+ await heard('scroll down a bit', false);
+ expect(root!.querySelector('.tok')).toBe(first);
+ expect(shown()).toBe('scroll down a bit');
+ });
+
+ it('throws the sentence away when pressed during the countdown', async () => {
+ await show();
+ await heard('delete my account', true);
+ press();
+ expect(shown()).toBe('Cleared — say it again.');
+ vi.advanceTimersByTime(AUTO_SEND_MS * 2);
+ expect(requests('submit')).toHaveLength(0);
+ });
+
+ it('waits for the next pause when speech resumes during the countdown', async () => {
+ await show();
+ await heard('open settings', true);
+ vi.advanceTimersByTime(AUTO_SEND_MS - 200);
+ await heard('and then', false);
+ vi.advanceTimersByTime(AUTO_SEND_MS);
+ expect(requests('submit')).toHaveLength(0);
+ await heard('and then privacy', true);
+ vi.advanceTimersByTime(AUTO_SEND_MS);
+ expect(requests('submit')[0]).toMatchObject({ text: 'open settings and then privacy' });
+ });
+
+ it('ignores speech while the agent works, and a press stops the run', async () => {
+ await show({ run: 'working', voice: 'paused' });
+ await heard('click buy', true);
+ vi.advanceTimersByTime(AUTO_SEND_MS);
+ expect(requests('submit')).toHaveLength(0);
+ expect($('.wrap').dataset.face).toBe('dots');
+ press();
+ expect(requests('cancel')).toHaveLength(1);
+ });
+
+ it('mutes, listens, asks for the microphone, or opens the panel, by what it is showing', async () => {
+ await show();
+ press();
+ expect(requests('listen').at(-1)).toMatchObject({ on: false });
+
+ await show({ voice: 'muted' });
+ press();
+ expect(requests('listen').at(-1)).toMatchObject({ on: true });
+
+ await show({ voice: 'needs-mic' });
+ press();
+ expect(requests('grantMic')).toHaveLength(1);
+
+ await show({ voice: 'paused', link: 'off' });
+ press();
+ expect(requests('openPanel')).toHaveLength(1);
+ });
+
+ it('turns ember for an approval and opens the request on a press, which a forged click cannot answer', async () => {
+ await show();
+ await show({
+ run: 'approval',
+ voice: 'paused',
+ approval: { toolId: 't1', action: 'clickElement', site: 'shop.test', detail: 'selector: #buy' },
+ });
+ expect($('.wrap').dataset.tone).toBe('ask');
+ expect($('.caption').dataset.kind).toBe('ask');
+
+ press();
+ expect($('.pop').hidden).toBe(false);
+ expect($('.pop-title').textContent).toBe('Allow click element?');
+ expect($('.pop-detail').textContent).toBe('selector: #buy');
+ expect(root!.querySelector('[data-decide="always"]')?.textContent).toBe('Always on shop.test');
+
+ $('[data-decide="allow"]').dispatchEvent(new MouseEvent('click', { bubbles: true }));
+ expect(requests('decide')).toHaveLength(0);
+ trustedClick($('[data-decide="always"]'));
+ expect(requests('decide')).toEqual([expect.objectContaining({ toolId: 't1', allow: true, remember: true })]);
+
+ await show({ run: 'working', voice: 'paused' });
+ expect($('.pop').hidden).toBe(true);
+ });
+
+ it('shows the code the agent wrote, and never offers “always” for it', async () => {
+ await show({
+ run: 'approval',
+ voice: 'paused',
+ approval: { toolId: 't2', action: 'injectCode', site: 'shop.test', purpose: 'Total the cart', code: 'return 1 + 1;' },
+ });
+ press();
+ expect($('.pop-code').textContent).toBe('return 1 + 1;');
+ expect($('.pop-purpose').textContent).toBe('Total the cart');
+ expect(root!.querySelector('[data-decide="always"]')).toBeNull();
+ });
+
+ it('opens the arc menu after a second of hover, and not before', async () => {
+ await show();
+ $('.wrap').dispatchEvent(new PointerEvent('pointerenter', { pointerType: 'mouse' }));
+ vi.advanceTimersByTime(900);
+ expect($('.wrap').classList.contains('open')).toBe(false);
+ vi.advanceTimersByTime(100);
+ expect($('.wrap').classList.contains('open')).toBe(true);
+ const slots = [...root!.querySelectorAll<HTMLElement>('.item')].map((item) => Number.parseFloat(item.style.getPropertyValue('--x')));
+ expect(slots).toEqual([...slots].sort((a, b) => a - b));
+ });
+
+ it('rides live code and an A-Eye pick along with the next instruction, then lets them go', async () => {
+ await show();
+ $('[data-item="code"]').dispatchEvent(new MouseEvent('click', { bubbles: true }));
+ answers.set('pick', { focus: { tag: 'button', label: 'Buy now', selector: '#buy' } });
+ $('[data-item="focus"]').dispatchEvent(new MouseEvent('click', { bubbles: true }));
+ await vi.waitFor(() => expect(root!.querySelectorAll('.chip')).toHaveLength(2));
+ expect(root!.querySelector('.chips')?.textContent).toContain('A-Eye · Buy now');
+
+ await heard('buy it', true);
+ vi.advanceTimersByTime(AUTO_SEND_MS);
+ expect(requests('submit')[0]).toMatchObject({ text: 'buy it', liveTools: true, focus: { label: 'Buy now' } });
+ expect(root!.querySelectorAll('.chip')).toHaveLength(1);
+ });
+
+ it('holds a reply for a tab nobody is looking at, and reads it once they are', async () => {
+ await show();
+ vi.spyOn(document, 'visibilityState', 'get').mockReturnValue('hidden');
+ await deliver({ op: 'say', text: 'Done — **three** results.', tone: 'reply' });
+ expect(shown()).not.toContain('results.');
+
+ vi.spyOn(document, 'visibilityState', 'get').mockReturnValue('visible');
+ document.dispatchEvent(new Event('visibilitychange'));
+ expect($('.caption').dataset.kind).toBe('reply');
+ expect(shown()).toBe('Done — **three** results.');
+ });
+
+ it('drags on a long press and remembers where it was dropped', async () => {
+ await show();
+ const orb = $('.orb');
+ const at = (type: string, x: number, y: number) =>
+ orb.dispatchEvent(new PointerEvent(type, { pointerId: 1, isPrimary: true, button: 0, clientX: x, clientY: y, bubbles: true }));
+ const start = { x: Number.parseFloat($('.wrap').style.left), y: Number.parseFloat($('.wrap').style.top) };
+ at('pointerdown', start.x, start.y);
+ vi.advanceTimersByTime(400);
+ expect($('.wrap').classList.contains('lifted')).toBe(true);
+ at('pointermove', start.x - 200, start.y - 150);
+ at('pointerup', start.x - 200, start.y - 150);
+ expect(requests('move')).toHaveLength(1);
+ press();
+ expect(requests('listen')).toHaveLength(0);
+ });
+
+ describe('hold to talk', () => {
+ const held = { pushToTalk: true, voice: 'held' as const };
+
+ it('toggles from the menu, and wears the key on the orb', async () => {
+ await show();
+ $('[data-item="talk"]').dispatchEvent(new MouseEvent('click', { bubbles: true }));
+ expect(requests('pushToTalk')).toEqual([expect.objectContaining({ on: true })]);
+ await show(held);
+ expect($('.wrap').classList.contains('push-to-talk')).toBe(true);
+ expect($('[data-item="talk"]').classList.contains('on')).toBe(true);
+ });
+
+ it('talks while left Control is held, and sends the moment the words are in', async () => {
+ await show(held);
+ key('keydown', 'ControlLeft');
+ vi.advanceTimersByTime(250);
+ expect(requests('talk')).toEqual([expect.objectContaining({ on: true })]);
+ expect($('.wrap').classList.contains('holding')).toBe(true);
+
+ await show({ ...held, voice: 'listening' });
+ await heard('scroll to the', false);
+ await heard('scroll to the reviews', true);
+ vi.advanceTimersByTime(AUTO_SEND_MS * 2);
+ expect(requests('submit')).toHaveLength(0);
+
+ key('keyup', 'ControlLeft');
+ expect(requests('talk').at(-1)).toMatchObject({ on: false });
+ await show(held);
+ expect(requests('submit')).toEqual([expect.objectContaining({ text: 'scroll to the reviews' })]);
+ });
+
+ it('sends what was still being heard when the key came up', async () => {
+ await show(held);
+ key('keydown', 'ControlLeft');
+ vi.advanceTimersByTime(250);
+ await show({ ...held, voice: 'listening' });
+ await heard('go back', false);
+ key('keyup', 'ControlLeft');
+ vi.advanceTimersByTime(2500);
+ expect(requests('submit')[0]).toMatchObject({ text: 'go back' });
+ });
+
+ it('never opens the mic for a tap, a shortcut, a click or a scroll', async () => {
+ await show(held);
+ key('keydown', 'ControlLeft');
+ key('keyup', 'ControlLeft');
+ vi.advanceTimersByTime(500);
+
+ key('keydown', 'ControlLeft');
+ key('keydown', 'KeyC', { ctrlKey: true });
+ vi.advanceTimersByTime(500);
+
+ key('keydown', 'ControlLeft', { shiftKey: true });
+ vi.advanceTimersByTime(500);
+
+ key('keydown', 'ControlLeft');
+ const click = new PointerEvent('pointerdown', { bubbles: true });
+ Object.defineProperty(click, 'isTrusted', { value: true });
+ window.dispatchEvent(click);
+ vi.advanceTimersByTime(500);
+
+ expect(requests('talk')).toHaveLength(0);
+ });
+
+ it('throws the words away when a shortcut lands mid-hold', async () => {
+ await show(held);
+ key('keydown', 'ControlLeft');
+ vi.advanceTimersByTime(250);
+ await show({ ...held, voice: 'listening' });
+ await heard('select all', false);
+ key('keydown', 'KeyA', { ctrlKey: true });
+ expect(requests('talk').at(-1)).toMatchObject({ on: false });
+ await heard('select all', true);
+ await show(held);
+ vi.advanceTimersByTime(3000);
+ expect(requests('submit')).toHaveLength(0);
+ });
+
+ it('ignores a Control press the page made up', async () => {
+ await show(held);
+ key('keydown', 'ControlLeft', {}, false);
+ vi.advanceTimersByTime(500);
+ expect(requests('talk')).toHaveLength(0);
+ });
+
+ it('stays quiet where it is not the tab being listened for', async () => {
+ await show({ pushToTalk: true, voice: 'paused' });
+ key('keydown', 'ControlLeft');
+ vi.advanceTimersByTime(500);
+ expect(requests('talk')).toHaveLength(0);
+ });
+ });
+
+ it('leaves when hands-free ends', async () => {
+ await show();
+ await deliver({ op: 'hide' });
+ vi.advanceTimersByTime(400);
+ expect(document.getElementById('browsentic-hands-free')).toBeNull();
+ });
+});
diff --git a/src/lib/handsfree/host.ts b/src/lib/handsfree/host.ts
new file mode 100644
index 0000000..7f6b5de
--- /dev/null
+++ b/src/lib/handsfree/host.ts
@@ -0,0 +1,1011 @@
+import { browser } from 'wxt/browser';
+import type { FocusedElement } from '@/lib/actions/protocol';
+import { MAX_STORED_FILE_BYTES } from '@/lib/files/report';
+import { OVERLAY_ATTRIBUTE } from '@/lib/overlay';
+import { RAIL_PALETTES, RAIL_TONES } from '@/lib/rail/events';
+import { readingMs, sharedWords, wordsOf } from './caption';
+import {
+ AUTO_SEND_MS,
+ HANDS_FREE_CHANNEL,
+ HOLD_KEY_CODE,
+ ORB_ICONS,
+ isOrbCommand,
+ type CaptionTone,
+ type OrbIcon,
+ type OrbRequest,
+ type OrbView,
+} from './events';
+import {
+ MENU_ITEM,
+ arcSlots,
+ clearOfMenu,
+ menuRadius,
+ outwardFrom,
+ placeBeside,
+ placeOrb,
+ sidesFacing,
+ toPosition,
+ type Point,
+ type Slot,
+} from './geometry';
+import { STYLES } from './styles';
+
+const HOST_ID = 'browsentic-hands-free';
+const HOVER_OPEN_MS = 1000;
+const HOVER_CLOSE_MS = 380;
+const LONG_PRESS_MS = 380;
+const DRAG_SLOP_PX = 8;
+const SPEAKING_MS = 700;
+const SENT_MS = 1400;
+const HINT_MS = 2800;
+const LEAVE_MS = 220;
+const FRESH_MS = 4000;
+const GLIDE_MS = 400;
+const SPEECH_IDLE_MS = 8000;
+const TIP_ROOM_PX = 26;
+const HOLD_MS = 250;
+const SETTLE_MS = 2500;
+const SPEECH_STAGGER_MS = 45;
+const REPLY_STAGGER_MS = 32;
+
+type MenuId = 'file' | 'code' | 'focus' | 'talk' | 'panel';
+type CaptionKind = 'speech' | 'sent' | 'reply' | 'error' | 'ask' | 'hint';
+type Unsent<T> = T extends unknown ? Omit<T, 'channel'> : never;
+
+const onMac = (): boolean => {
+ const agent = navigator as Navigator & { userAgentData?: { platform?: string } };
+ return /mac/i.test(agent.userAgentData?.platform ?? navigator.platform ?? '');
+};
+
+/** What the hold key is called on the keyboard in front of the user; only the label differs. */
+const HOLD_KEY = onMac() ? { name: 'control', cap: '⌃' } : { name: 'Ctrl', cap: 'ctrl' };
+
+const MENU: { id: MenuId; icon: OrbIcon; label: string }[] = [
+ { id: 'file', icon: 'file', label: 'Attach a file' },
+ { id: 'code', icon: 'code', label: 'Live code' },
+ { id: 'focus', icon: 'focus', label: 'Focus point (A-Eye)' },
+ { id: 'talk', icon: 'keyboard', label: `Hold ${HOLD_KEY.name} to talk` },
+ { id: 'panel', icon: 'panel', label: 'Open the side panel' },
+];
+
+const LABELS: Record<CaptionKind, string> = {
+ speech: 'Listening',
+ sent: 'Sent',
+ reply: 'Browsentic',
+ error: 'Heads up',
+ ask: 'Needs your OK',
+ hint: '',
+};
+
+const TONE_KIND: Record<CaptionTone, CaptionKind> = { reply: 'reply', error: 'error', ask: 'ask' };
+
+const VOICE_HINTS: Partial<Record<OrbView['voice'], string>> = {
+ 'needs-mic': 'Browsentic needs the microphone — tap the mic to allow it.',
+ blocked: 'The microphone is blocked for Browsentic — tap the mic to fix it.',
+ 'no-mic': 'No microphone was found — tap the mic to try again.',
+ 'no-service': 'No speech service answered — tap the mic to try again.',
+ yielded: 'Another page took the microphone — tap the mic to listen here.',
+};
+
+function icon(name: OrbIcon): string {
+ return `<svg viewBox="0 0 24 24" aria-hidden="true">${ORB_ICONS[name].map((d) => `<path d="${d}"/>`).join('')}</svg>`;
+}
+
+function escape(text: string): string {
+ return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
+}
+
+const spoken = (action: string): string =>
+ action.replace(/([a-z])([A-Z])/g, '$1 $2').toLowerCase();
+
+const focusName = (focus: FocusedElement): string => focus.label?.trim() || focus.role || focus.tag;
+
+const request = <T = unknown>(message: Unsent<OrbRequest>): Promise<T | undefined> =>
+ browser.runtime.sendMessage({ channel: HANDS_FREE_CHANNEL, ...message }).catch(() => undefined) as Promise<T | undefined>;
+
+/**
+ * Hands-free mode's face on the page: one microphone orb, drawn in a closed shadow root
+ * like the rail and the toast, and marked as an overlay so A-Eye never lands on it. The
+ * background decides what it shows; the orb owns only what lives and dies with the page —
+ * where it is being dragged, what has been said since the last send, and what rides along.
+ */
+export function exposeHandsFree(): void {
+ let orb: Orb | null = null;
+
+ browser.runtime.onMessage.addListener((message: unknown, _sender, sendResponse) => {
+ if (!isOrbCommand(message)) return;
+ if (message.op === 'hide') {
+ orb?.leave();
+ orb = null;
+ } else if (message.op === 'show') {
+ if (!orb?.alive()) orb = mountOrb(message.view);
+ else orb.update(message.view);
+ } else if (message.op === 'heard') {
+ orb?.heard(message.text, message.final);
+ } else {
+ orb?.say(message.text, message.tone);
+ }
+ sendResponse({ ok: orb?.alive() ?? message.op === 'hide' });
+ });
+
+ document.getElementById(HOST_ID)?.remove();
+ resync();
+ window.addEventListener('pageshow', (event) => {
+ if (!event.persisted) return;
+ orb?.remove();
+ orb = null;
+ resync();
+ });
+
+ function resync(): void {
+ void request({ op: 'sync' });
+ }
+}
+
+interface Orb {
+ alive: () => boolean;
+ update: (view: OrbView) => void;
+ heard: (text: string, final: boolean) => void;
+ say: (text: string, tone: CaptionTone) => void;
+ leave: () => void;
+ remove: () => void;
+}
+
+function mountOrb(first: OrbView): Orb | null {
+ if (!document.documentElement) return null;
+
+ const host = document.createElement('div');
+ host.id = HOST_ID;
+ host.setAttribute(OVERLAY_ATTRIBUTE, '');
+ host.style.cssText = 'all: initial; position: static;';
+ const root = host.attachShadow({ mode: 'closed' });
+ root.innerHTML = `<style>${STYLES}</style>
+ <div class="layer" role="region" aria-label="Browsentic hands-free">
+ <div class="caption" hidden><span class="label"></span><p class="words" aria-live="polite"></p><div class="chips"></div></div>
+ <div class="pop" role="dialog" aria-label="The agent is asking to act" hidden></div>
+ <div class="wrap">
+ <span class="halo"></span>
+ ${MENU.map(
+ ({ id, icon: name, label }, index) =>
+ `<button type="button" class="item" data-item="${id}" style="--i:${index};--r:${MENU.length - 1 - index}" aria-label="${escape(label)}">${icon(name)}<span class="tip">${escape(label)}</span>${id === 'file' ? '<b class="badge"></b>' : ''}</button>`,
+ ).join('')}
+ <svg class="ring" viewBox="0 0 72 72" aria-hidden="true"><circle class="track" cx="36" cy="36" r="33"/><circle class="count" cx="36" cy="36" r="33"/></svg>
+ <span class="ping"></span><span class="ping2"></span>
+ <span class="spin"></span>
+ <button type="button" class="orb">
+ <span class="face mic">${icon('mic')}</span>
+ <span class="face off">${icon('micOff')}</span>
+ <span class="face shield">${icon('shield')}</span>
+ <span class="face dots"><i></i><i></i><i></i></span>
+ <span class="face stop">${icon('stop')}</span>
+ <span class="status"></span>
+ <span class="keycap" aria-hidden="true">${escape(HOLD_KEY.cap)}</span>
+ </button>
+ </div>
+ <input type="file" hidden />
+ </div>`;
+ document.documentElement.append(host);
+
+ const $ = <T extends Element>(selector: string) => root.querySelector(selector) as T;
+ const layer = $<HTMLElement>('.layer');
+ const wrap = $<HTMLElement>('.wrap');
+ const button = $<HTMLButtonElement>('.orb');
+ const halo = $<HTMLElement>('.halo');
+ const caption = $<HTMLElement>('.caption');
+ const label = $<HTMLElement>('.label');
+ const words = $<HTMLElement>('.words');
+ const chips = $<HTMLElement>('.chips');
+ const pop = $<HTMLElement>('.pop');
+ const picker = $<HTMLInputElement>('input[type="file"]');
+ const items = new Map<MenuId, HTMLButtonElement>(
+ [...root.querySelectorAll<HTMLButtonElement>('.item')].map((item) => [item.dataset.item as MenuId, item]),
+ );
+
+ let view = first;
+ let alive = true;
+ let center: Point = placeOrb(view.position, viewport());
+ let menuOpen = false;
+ let popOpen = false;
+ let picking = false;
+
+ let committed = '';
+ let interim = '';
+ let shown: string[] = [];
+ let kind: CaptionKind | null = null;
+ let heldSay: { text: string; tone: CaptionTone } | null = null;
+
+ let liveTools = false;
+ let focus: FocusedElement | null = null;
+ const files: { id: string; name: string }[] = [];
+
+ let hold: 'idle' | 'pending' | 'talking' = 'idle';
+ let settling = false;
+ let muffled = false;
+
+ let pointer: { id: number; start: Point; grab: Point; moved: boolean } | null = null;
+ let lifted = false;
+ let swallowClick = false;
+
+ const timers = {
+ hover: 0,
+ close: 0,
+ press: 0,
+ count: 0,
+ speaking: 0,
+ caption: 0,
+ glide: 0,
+ idle: 0,
+ hold: 0,
+ settle: 0,
+ };
+ const stop = (name: keyof typeof timers) => {
+ clearTimeout(timers[name]);
+ timers[name] = 0;
+ };
+
+ paintTheme();
+ paintState(null);
+ applyPosition();
+ const fresh = Date.now() - view.since < FRESH_MS && document.visibilityState === 'visible';
+ wrap.classList.add(fresh ? 'entering' : 'arriving');
+ wrap.addEventListener('animationend', (event) => {
+ if (event.target === wrap) wrap.classList.remove('entering', 'arriving');
+ });
+ if (fresh) hint('Hands-free is on — just speak. Hover the mic for more.');
+ else voiceHint(null);
+
+ button.addEventListener('mousedown', (event) => event.preventDefault());
+ button.addEventListener('contextmenu', (event) => event.preventDefault());
+ button.addEventListener('pointerdown', onPointerDown);
+ button.addEventListener('pointermove', onPointerMove);
+ button.addEventListener('pointerup', onPointerUp);
+ button.addEventListener('pointercancel', onPointerUp);
+ button.addEventListener('click', () => {
+ if (swallowClick) {
+ swallowClick = false;
+ return;
+ }
+ press();
+ });
+ button.addEventListener('focus', () => {
+ if (button.matches(':focus-visible')) openMenu();
+ });
+
+ wrap.addEventListener('pointerenter', (event) => {
+ if (event.pointerType === 'touch') return;
+ stop('close');
+ if (!menuOpen && !lifted && !popOpen && !picking) timers.hover = window.setTimeout(openMenu, HOVER_OPEN_MS);
+ });
+ wrap.addEventListener('pointerleave', () => {
+ stop('hover');
+ if (menuOpen && !lifted) timers.close = window.setTimeout(closeMenu, HOVER_CLOSE_MS);
+ });
+ wrap.addEventListener('focusout', (event) => {
+ if (!wrap.contains(event.relatedTarget as Node | null) && !wrap.matches(':hover')) closeMenu();
+ });
+ layer.addEventListener('keydown', (event) => {
+ if (event.key !== 'Escape') return;
+ closeMenu();
+ closePop();
+ });
+
+ for (const [id, item] of items) {
+ item.addEventListener('mousedown', (event) => event.preventDefault());
+ item.addEventListener('click', () => choose(id));
+ }
+ picker.addEventListener('change', () => {
+ const file = picker.files?.[0];
+ picker.value = '';
+ if (file) void attach(file);
+ });
+
+ /* The page widens the moment the panel it was detached from closes; the orb glides to the
+ new middle rather than jumping there. */
+ const onResize = () => {
+ if (!lifted) center = placeOrb(view.position, viewport());
+ wrap.classList.add('gliding');
+ stop('glide');
+ timers.glide = window.setTimeout(() => wrap.classList.remove('gliding'), GLIDE_MS);
+ applyPosition();
+ };
+ const onVisible = () => {
+ if (document.visibilityState !== 'visible' || !heldSay) return;
+ const held = heldSay;
+ heldSay = null;
+ say(held.text, held.tone);
+ };
+ /* Hold-to-talk's key, heard from the page itself. A key the page made up is never a person
+ holding one, so only trusted events count — anything else could open the microphone. */
+ const detached = () => {
+ if (host.isConnected) return false;
+ remove();
+ return true;
+ };
+ const onKeyDown = (event: KeyboardEvent) => {
+ if (!event.isTrusted || detached()) return;
+ if (event.code !== HOLD_KEY_CODE) holdCancel();
+ else if (!event.repeat && !event.shiftKey && !event.altKey && !event.metaKey) holdDown();
+ };
+ const onKeyUp = (event: KeyboardEvent) => {
+ if (event.isTrusted && !detached() && event.code === HOLD_KEY_CODE) holdUp();
+ };
+ const onInterrupt = (event: Event) => {
+ if (event.isTrusted && !detached()) holdCancel();
+ };
+ const onHidden = () => {
+ if (document.visibilityState !== 'visible') holdCancel();
+ };
+ window.addEventListener('keydown', onKeyDown, true);
+ window.addEventListener('keyup', onKeyUp, true);
+ window.addEventListener('pointerdown', onInterrupt, true);
+ window.addEventListener('wheel', onInterrupt, { capture: true, passive: true });
+ window.addEventListener('blur', holdCancel);
+ document.addEventListener('visibilitychange', onHidden);
+
+ window.addEventListener('resize', onResize, { passive: true });
+ document.addEventListener('visibilitychange', onVisible);
+
+ function viewport() {
+ return { width: window.innerWidth, height: window.innerHeight };
+ }
+
+ function paintTheme(): void {
+ const palette = RAIL_PALETTES[view.theme];
+ const tones = RAIL_TONES[view.theme];
+ for (const [key, value] of Object.entries(palette)) layer.style.setProperty(`--${key}`, value);
+ layer.style.setProperty('--magenta', tones.listening);
+ layer.style.setProperty('--ember', tones.warn);
+ layer.style.setProperty('--amber', tones.pending);
+ layer.style.setProperty('--lime', tones.live);
+ layer.toggleAttribute('data-light', view.theme === 'daylight');
+ }
+
+ function listening(): boolean {
+ return view.run === 'idle' && (view.voice === 'listening' || view.voice === 'starting');
+ }
+
+ function drafting(): boolean {
+ return Boolean(committed || interim || timers.count);
+ }
+
+ function paintState(before: OrbView | null): void {
+ const { run, voice, link } = view;
+ const face =
+ run === 'approval'
+ ? 'shield'
+ : run === 'working'
+ ? 'dots'
+ : listening() || voice === 'paused' || voice === 'held'
+ ? 'mic'
+ : 'off';
+ const tone =
+ run === 'approval'
+ ? 'ask'
+ : run === 'working'
+ ? 'work'
+ : listening() || hold === 'talking'
+ ? 'listen'
+ : voice in VOICE_HINTS
+ ? 'trouble'
+ : 'quiet';
+ wrap.dataset.face = face;
+ wrap.dataset.tone = tone;
+ wrap.dataset.link = link;
+ wrap.classList.toggle('push-to-talk', view.pushToTalk);
+ const talkItem = items.get('talk');
+ talkItem?.classList.toggle('on', view.pushToTalk);
+ const talkTip = talkItem?.querySelector('.tip');
+ if (talkTip) talkTip.textContent = view.pushToTalk ? `Hold to talk is on — ${HOLD_KEY.name}` : `Hold ${HOLD_KEY.name} to talk`;
+ button.setAttribute('aria-label', pressLabel());
+ if (!before) return;
+
+ if (hold !== 'idle' && !holdable()) holdCancel();
+ if (voice === 'held') muffled = false;
+
+ if (before.run !== 'approval' && run === 'approval' && view.approval) {
+ const { action, site } = view.approval;
+ show('ask', `The agent wants to ${spoken(action)}${site ? ` on ${site}` : ''} — tap the mic to review it.`, 0);
+ }
+ if (run !== 'approval') {
+ closePop();
+ if (kind === 'ask') fadeCaption();
+ }
+ if (settling && voice === 'held') flush();
+ else if (!listening() && drafting() && hold !== 'talking' && !settling) {
+ discardDraft();
+ if (kind === 'speech') fadeCaption();
+ }
+ if (voice !== before.voice && voice !== 'held' && before.voice !== 'held') voiceHint(before);
+ }
+
+ function voiceHint(before: OrbView | null): void {
+ if (document.visibilityState !== 'visible' || view.run !== 'idle') return;
+ const trouble = VOICE_HINTS[view.voice];
+ if (trouble) hint(trouble);
+ else if (view.voice === 'muted' && before) hint('Muted — tap the mic to listen again.');
+ else if (listening() && before && (before.voice === 'muted' || before.voice in VOICE_HINTS)) hint('Listening…');
+ }
+
+ function pressLabel(): string {
+ if (view.run === 'approval') return 'Review what the agent is asking to do';
+ if (view.run === 'working') return 'Stop the agent';
+ if (drafting()) return 'Discard what you said';
+ if (view.voice === 'held') return `Hold ${HOLD_KEY.name} to talk`;
+ if (view.voice === 'needs-mic' || view.voice === 'blocked') return 'Allow the microphone';
+ if (view.link === 'off') return 'Open the side panel to pair';
+ if (listening()) return 'Mute the microphone';
+ return 'Listen';
+ }
+
+ function press(): void {
+ stop('hover');
+ if (view.run === 'approval') {
+ togglePop();
+ return;
+ }
+ closeMenu();
+ if (view.run === 'working') {
+ void request({ op: 'cancel' });
+ hint('Stopping the agent…');
+ return;
+ }
+ if (drafting()) {
+ discardDraft();
+ show('hint', 'Cleared — say it again.', HINT_MS);
+ return;
+ }
+ if (view.voice === 'needs-mic' || view.voice === 'blocked') {
+ void request({ op: 'grantMic' });
+ return;
+ }
+ if (view.link === 'off') {
+ void request({ op: 'openPanel' });
+ return;
+ }
+ if (view.link === 'pending') {
+ hint('Reconnecting to the Browsentic daemon…');
+ return;
+ }
+ if (view.voice === 'held') {
+ hint(`Hold ${HOLD_KEY.name} to talk — let go to send.`);
+ return;
+ }
+ void request({ op: 'listen', on: !listening() });
+ }
+
+ function heard(text: string, final: boolean): void {
+ if (picking || muffled || !(listening() || hold === 'talking' || settling)) return;
+ if (final) {
+ committed = committed ? `${committed} ${text}` : text;
+ interim = '';
+ if (!view.pushToTalk) startCountdown();
+ } else {
+ interim = text;
+ stopCountdown();
+ }
+ stop('idle');
+ if (!view.pushToTalk) {
+ timers.idle = window.setTimeout(() => {
+ if (timers.count) return;
+ discardDraft();
+ fadeCaption();
+ }, SPEECH_IDLE_MS);
+ }
+ wrap.classList.add('speaking');
+ stop('speaking');
+ timers.speaking = window.setTimeout(() => wrap.classList.remove('speaking'), SPEAKING_MS);
+ stream('speech', [committed, interim].filter(Boolean).join(' '), SPEECH_STAGGER_MS, wordsOf(committed).length);
+ button.setAttribute('aria-label', pressLabel());
+ }
+
+ function discardDraft(): void {
+ stopCountdown();
+ stop('idle');
+ committed = '';
+ interim = '';
+ }
+
+ function startCountdown(): void {
+ stop('count');
+ wrap.classList.remove('counting');
+ void wrap.offsetWidth;
+ wrap.classList.add('counting');
+ timers.count = window.setTimeout(submit, AUTO_SEND_MS);
+ }
+
+ function stopCountdown(): void {
+ stop('count');
+ wrap.classList.remove('counting');
+ }
+
+ function holdable(): boolean {
+ return view.pushToTalk && view.run === 'idle' && view.link === 'live' && !picking && !popOpen && !lifted;
+ }
+
+ function holdDown(): void {
+ if (hold !== 'idle' || settling || !holdable() || view.voice !== 'held') return;
+ hold = 'pending';
+ timers.hold = window.setTimeout(() => {
+ hold = 'talking';
+ muffled = false;
+ discardDraft();
+ closeMenu();
+ wrap.classList.add('holding');
+ void request({ op: 'talk', on: true });
+ show('speech', '', 0);
+ }, HOLD_MS);
+ }
+
+ function holdUp(): void {
+ if (hold === 'pending') {
+ stop('hold');
+ hold = 'idle';
+ return;
+ }
+ if (hold !== 'talking') return;
+ hold = 'idle';
+ wrap.classList.remove('holding');
+ void request({ op: 'talk', on: false });
+ settling = true;
+ stop('settle');
+ timers.settle = window.setTimeout(flush, SETTLE_MS);
+ }
+
+ /** A shortcut, a click or a scroll while the key was down: it was never meant as speech. */
+ function holdCancel(): void {
+ stop('hold');
+ if (hold !== 'talking') {
+ hold = 'idle';
+ return;
+ }
+ hold = 'idle';
+ muffled = true;
+ wrap.classList.remove('holding');
+ void request({ op: 'talk', on: false });
+ discardDraft();
+ if (kind === 'speech') fadeCaption();
+ }
+
+ /** The key is up and the recognizer has finished the last words: send what was said, straight away. */
+ function flush(): void {
+ stop('settle');
+ if (!settling) return;
+ settling = false;
+ committed = [committed, interim].filter(Boolean).join(' ');
+ interim = '';
+ if (committed.trim()) submit();
+ else {
+ discardDraft();
+ if (kind === 'speech') fadeCaption();
+ }
+ }
+
+ function submit(): void {
+ stopCountdown();
+ stop('idle');
+ const text = committed.trim();
+ committed = '';
+ interim = '';
+ if (!text) return;
+ void request({ op: 'submit', text, focus: focus ?? undefined, liveTools });
+ focus = null;
+ files.length = 0;
+ paintChips();
+ items.get('focus')?.classList.remove('on');
+ kind = 'sent';
+ caption.dataset.kind = 'sent';
+ label.textContent = LABELS.sent;
+ for (const token of words.children) token.classList.remove('interim');
+ armCaption(SENT_MS);
+ }
+
+ function say(text: string, tone: CaptionTone): void {
+ if (document.visibilityState !== 'visible') {
+ heldSay = { text, tone };
+ return;
+ }
+ if (drafting()) return;
+ show(TONE_KIND[tone], text, readingMs(text));
+ }
+
+ function hint(text: string): void {
+ if (kind === 'speech' || kind === 'ask') return;
+ show('hint', text, HINT_MS);
+ }
+
+ function show(next: CaptionKind, text: string, lingerMs: number): void {
+ stream(next, text, next === 'hint' ? 0 : REPLY_STAGGER_MS);
+ if (lingerMs > 0) armCaption(lingerMs);
+ else stop('caption');
+ }
+
+ /** New words blur in one after another; words a revised reading kept stay exactly where they were. */
+ function stream(next: CaptionKind, text: string, staggerMs: number, settled = Infinity): void {
+ const incoming = wordsOf(text);
+ const keep = kind === next ? sharedWords(shown, incoming) : 0;
+ if (kind !== next) {
+ kind = next;
+ caption.dataset.kind = next;
+ label.textContent = LABELS[next];
+ }
+ stop('caption');
+ caption.classList.remove('leaving');
+ caption.hidden = false;
+
+ while (words.children.length > keep) words.lastElementChild?.remove();
+ incoming.slice(keep).forEach((word, index) => {
+ const token = document.createElement('span');
+ token.className = 'tok';
+ token.textContent = word;
+ token.style.animationDelay = `${index * staggerMs}ms`;
+ words.append(token);
+ });
+ [...words.children].forEach((token, index) => token.classList.toggle('interim', index >= settled));
+ shown = incoming;
+ placeCaption();
+ words.classList.toggle('overflow', overflowing());
+ }
+
+ /* Measured from the tokens' own boxes: they are still rising into place when this runs, and
+ a bottom-aligned box that overflows does so at its top, which scrollHeight never counts. */
+ function overflowing(): boolean {
+ const first = words.firstElementChild as HTMLElement | null;
+ const last = words.lastElementChild as HTMLElement | null;
+ if (!first || !last) return false;
+ return last.offsetTop + last.offsetHeight - first.offsetTop > words.clientHeight + 1;
+ }
+
+ function armCaption(ms: number): void {
+ stop('caption');
+ timers.caption = window.setTimeout(fadeCaption, ms);
+ }
+
+ function fadeCaption(): void {
+ stop('caption');
+ kind = null;
+ shown = [];
+ caption.classList.add('leaving');
+ timers.caption = window.setTimeout(() => {
+ words.replaceChildren();
+ label.textContent = '';
+ caption.classList.remove('leaving');
+ caption.removeAttribute('data-kind');
+ caption.hidden = chips.childElementCount === 0;
+ placeCaption();
+ }, 200);
+ }
+
+ function paintChips(): void {
+ const chip = (name: OrbIcon, text: string, onClear: () => void) => {
+ const element = document.createElement('span');
+ element.className = 'chip';
+ element.innerHTML = `${icon(name)}<span>${escape(text)}</span><button type="button" aria-label="Remove">${icon('close')}</button>`;
+ element.querySelector('button')!.addEventListener('click', () => {
+ onClear();
+ paintChips();
+ });
+ return element;
+ };
+ const next: HTMLElement[] = [];
+ if (focus) {
+ next.push(
+ chip('focus', `A-Eye · ${focusName(focus)}`, () => {
+ focus = null;
+ items.get('focus')?.classList.remove('on');
+ }),
+ );
+ }
+ if (liveTools) {
+ next.push(
+ chip('code', 'Live code', () => {
+ liveTools = false;
+ items.get('code')?.classList.remove('on');
+ }),
+ );
+ }
+ for (const file of files) {
+ next.push(
+ chip('file', file.name, () => {
+ files.splice(files.indexOf(file), 1);
+ void request({ op: 'detach', fileId: file.id });
+ }),
+ );
+ }
+ chips.replaceChildren(...next);
+ const badge = items.get('file')?.querySelector('.badge');
+ if (badge) {
+ badge.textContent = files.length ? String(files.length) : '';
+ badge.classList.toggle('shown', files.length > 0);
+ }
+ if (next.length) caption.hidden = false;
+ else if (!kind) caption.hidden = true;
+ placeCaption();
+ }
+
+ function choose(id: MenuId): void {
+ if (id === 'file') {
+ closeMenu();
+ picker.click();
+ } else if (id === 'code') {
+ liveTools = !liveTools;
+ items.get('code')?.classList.toggle('on', liveTools);
+ paintChips();
+ hint(
+ liveTools
+ ? 'Live code on — the agent may write a script for this page. You approve it before it runs.'
+ : 'Live code off.',
+ );
+ } else if (id === 'focus') {
+ closeMenu();
+ void pickFocus();
+ } else if (id === 'talk') {
+ const on = !view.pushToTalk;
+ void request({ op: 'pushToTalk', on });
+ hint(on ? `Hold to talk — hold ${HOLD_KEY.name} and speak, let go to send.` : 'Listening all the time again.');
+ } else {
+ void request({ op: 'openPanel' });
+ }
+ }
+
+ async function pickFocus(): Promise<void> {
+ if (picking) return;
+ picking = true;
+ stopCountdown();
+ wrap.classList.add('picking');
+ caption.hidden = true;
+ const outcome = await request<{ focus?: FocusedElement; error?: string }>({ op: 'pick' });
+ picking = false;
+ wrap.classList.remove('picking');
+ if (outcome?.focus) {
+ focus = outcome.focus;
+ items.get('focus')?.classList.add('on');
+ paintChips();
+ hint(`A-Eye has ${focusName(focus)} — say what to do with it.`);
+ } else {
+ paintChips();
+ if (outcome?.error) show('error', `A-Eye couldn’t read that element: ${outcome.error}`, HINT_MS);
+ }
+ }
+
+ async function attach(file: File): Promise<void> {
+ const content = file.size <= MAX_STORED_FILE_BYTES ? await readAsBase64(file).catch(() => undefined) : undefined;
+ const outcome = await request<{ ok: boolean; fileId?: string; error?: string }>({
+ op: 'attach',
+ file: { name: file.name, mime: file.type || 'application/octet-stream', size: file.size, content },
+ });
+ if (!outcome?.ok || !outcome.fileId) {
+ show('error', `Couldn’t attach “${file.name}”${outcome?.error ? `: ${outcome.error}` : ''}.`, HINT_MS);
+ return;
+ }
+ files.push({ id: outcome.fileId, name: file.name });
+ paintChips();
+ hint(`Attached ${file.name} — say what to do with it.`);
+ }
+
+ function openMenu(): void {
+ stop('hover');
+ stop('close');
+ if (menuOpen || lifted || popOpen || picking) return;
+ menuOpen = true;
+ layoutMenu();
+ wrap.classList.add('open');
+ placeCaption();
+ }
+
+ function closeMenu(): void {
+ stop('hover');
+ stop('close');
+ if (!menuOpen) return;
+ menuOpen = false;
+ wrap.classList.remove('open');
+ placeCaption();
+ }
+
+ function layoutMenu(): void {
+ const outward = outwardFrom(center, viewport());
+ const slots = arcSlots(MENU.length, outward);
+ MENU.forEach(({ id }, index) => {
+ const item = items.get(id);
+ const slot = slots[index];
+ if (!item || !slot) return;
+ item.style.setProperty('--x', `${slot.x}px`);
+ item.style.setProperty('--y', `${slot.y}px`);
+ item.dataset.tip = tipSide(slot);
+ });
+ halo.style.setProperty('--halo', `${menuRadius(outward) + MENU_ITEM / 2 + 14}px`);
+ }
+
+ function togglePop(): void {
+ if (popOpen) closePop();
+ else openPop();
+ }
+
+ function openPop(): void {
+ const ask = view.approval;
+ if (!ask) return;
+ closeMenu();
+ popOpen = true;
+ const always = ask.site && !ask.code;
+ pop.innerHTML = `
+ <div class="pop-head">${icon('shield')}<span class="pop-title">${escape(ask.code ? 'Allow this code to run?' : `Allow ${spoken(ask.action)}?`)}</span></div>
+ ${ask.site ? `<p class="pop-site">on ${escape(ask.site)}</p>` : ''}
+ ${ask.code ? `<p class="pop-purpose">${escape(ask.purpose ?? 'No purpose given.')}</p><pre class="pop-code">${escape(ask.code)}</pre>` : ''}
+ ${!ask.code && ask.detail ? `<p class="pop-detail">${escape(ask.detail)}</p>` : ''}
+ <div class="pop-actions">
+ <button type="button" class="btn" data-decide="deny">Deny</button>
+ ${always ? `<button type="button" class="btn" data-decide="always" title="Stop asking for ${escape(ask.action)} on ${escape(ask.site!)}">Always on ${escape(ask.site!)}</button>` : ''}
+ <button type="button" class="btn primary" data-decide="allow">Allow</button>
+ </div>
+ <span class="arrow"></span>`;
+ for (const choice of pop.querySelectorAll<HTMLButtonElement>('[data-decide]')) {
+ /* The one click here that must come from a person: it lets the agent act. */
+ choice.addEventListener('click', (event) => {
+ if (!event.isTrusted) return;
+ const decision = choice.dataset.decide;
+ void request({ op: 'decide', toolId: ask.toolId, allow: decision !== 'deny', remember: decision === 'always' });
+ closePop();
+ hint(decision === 'deny' ? 'Denied.' : 'Allowed — carrying on.');
+ });
+ }
+ pop.hidden = false;
+ if (kind === 'ask') {
+ kind = null;
+ caption.hidden = chips.childElementCount === 0;
+ }
+ placePop();
+ pop.querySelector<HTMLButtonElement>('[data-decide="deny"]')?.focus({ preventScroll: true });
+ }
+
+ function closePop(): void {
+ if (!popOpen) return;
+ popOpen = false;
+ pop.hidden = true;
+ pop.replaceChildren();
+ placeCaption();
+ }
+
+ function applyPosition(): void {
+ wrap.style.left = `${center.x}px`;
+ wrap.style.top = `${center.y}px`;
+ if (menuOpen) layoutMenu();
+ placeCaption();
+ placePop();
+ }
+
+ function placeCaption(): void {
+ if (caption.hidden) return;
+ const outward = outwardFrom(center, viewport());
+ const gap = menuOpen ? clearOfMenu(outward) + TIP_ROOM_PX : 12;
+ const placed = placeBeside(
+ { width: caption.offsetWidth, height: caption.offsetHeight },
+ center,
+ gap,
+ viewport(),
+ sidesFacing(outward),
+ );
+ caption.dataset.side = placed.side;
+ caption.style.left = `${placed.left}px`;
+ caption.style.top = `${placed.top}px`;
+ }
+
+ function placePop(): void {
+ if (!popOpen) return;
+ const placed = placeBeside(
+ { width: pop.offsetWidth, height: pop.offsetHeight },
+ center,
+ 16,
+ viewport(),
+ sidesFacing(outwardFrom(center, viewport())),
+ );
+ const along = placed.side === 'top' || placed.side === 'bottom' ? pop.offsetWidth : pop.offsetHeight;
+ pop.dataset.side = placed.side;
+ pop.style.left = `${placed.left}px`;
+ pop.style.top = `${placed.top}px`;
+ pop.style.setProperty('--arrow', `${Math.min(along - 18, Math.max(18, placed.arrow))}px`);
+ }
+
+ function onPointerDown(event: PointerEvent): void {
+ if (event.button !== 0 || !event.isPrimary) return;
+ stop('hover');
+ const start = { x: event.clientX, y: event.clientY };
+ pointer = { id: event.pointerId, start, grab: { x: start.x - center.x, y: start.y - center.y }, moved: false };
+ timers.press = window.setTimeout(() => {
+ if (!pointer) return;
+ lifted = true;
+ closeMenu();
+ closePop();
+ wrap.classList.add('lifted');
+ caption.classList.add('dragged');
+ button.setPointerCapture(pointer.id);
+ }, LONG_PRESS_MS);
+ }
+
+ function onPointerMove(event: PointerEvent): void {
+ if (!pointer || event.pointerId !== pointer.id) return;
+ if (!lifted) {
+ if (Math.hypot(event.clientX - pointer.start.x, event.clientY - pointer.start.y) > DRAG_SLOP_PX) {
+ stop('press');
+ pointer.moved = true;
+ }
+ return;
+ }
+ const room = viewport();
+ center = placeOrb(toPosition({ x: event.clientX - pointer.grab.x, y: event.clientY - pointer.grab.y }, room), room);
+ applyPosition();
+ }
+
+ function onPointerUp(event: PointerEvent): void {
+ if (!pointer || event.pointerId !== pointer.id) return;
+ stop('press');
+ const dragged = lifted || pointer.moved;
+ pointer = null;
+ if (lifted) {
+ lifted = false;
+ wrap.classList.remove('lifted');
+ caption.classList.remove('dragged');
+ void request({ op: 'move', position: toPosition(center, viewport()) });
+ }
+ if (!dragged) return;
+ swallowClick = true;
+ setTimeout(() => (swallowClick = false), 0);
+ }
+
+ function update(next: OrbView): void {
+ const before = view;
+ view = next;
+ if (next.theme !== before.theme) paintTheme();
+ if (!lifted && (next.position?.x !== before.position?.x || next.position?.y !== before.position?.y)) {
+ center = placeOrb(next.position, viewport());
+ applyPosition();
+ }
+ paintState(before);
+ if (popOpen && next.approval?.toolId !== before.approval?.toolId) {
+ closePop();
+ if (next.approval) openPop();
+ }
+ }
+
+ function remove(): void {
+ alive = false;
+ for (const name of Object.keys(timers) as (keyof typeof timers)[]) stop(name);
+ window.removeEventListener('resize', onResize);
+ document.removeEventListener('visibilitychange', onVisible);
+ window.removeEventListener('keydown', onKeyDown, true);
+ window.removeEventListener('keyup', onKeyUp, true);
+ window.removeEventListener('pointerdown', onInterrupt, true);
+ window.removeEventListener('wheel', onInterrupt, true);
+ window.removeEventListener('blur', holdCancel);
+ document.removeEventListener('visibilitychange', onHidden);
+ host.remove();
+ }
+
+ function leave(): void {
+ if (!alive) return;
+ holdCancel();
+ alive = false;
+ closeMenu();
+ closePop();
+ fadeCaption();
+ wrap.classList.add('leaving');
+ window.setTimeout(remove, LEAVE_MS);
+ }
+
+ return { alive: () => alive && host.isConnected, update, heard, say, leave, remove };
+}
+
+function tipSide(slot: Slot): 'top' | 'bottom' | 'left' | 'right' {
+ if (Math.abs(slot.x) > Math.abs(slot.y)) return slot.x > 0 ? 'right' : 'left';
+ return slot.y > 0 ? 'bottom' : 'top';
+}
+
+function readAsBase64(file: File): Promise<string> {
+ return new Promise((resolve, reject) => {
+ const reader = new FileReader();
+ reader.onload = () => {
+ const result = reader.result;
+ resolve(typeof result === 'string' ? result.slice(result.indexOf(',') + 1) : '');
+ };
+ reader.onerror = () => reject(reader.error ?? new Error('Could not read the file'));
+ reader.readAsDataURL(file);
+ });
+}
diff --git a/src/lib/handsfree/styles.ts b/src/lib/handsfree/styles.ts
new file mode 100644
index 0000000..b6a6852
--- /dev/null
+++ b/src/lib/handsfree/styles.ts
@@ -0,0 +1,469 @@
+import { AUTO_SEND_MS } from './events';
+import { MENU_ITEM, ORB_SIZE } from './geometry';
+
+const RING = 2 * Math.PI * 33;
+
+/** The panel's look, spelled out for a surface with no stylesheet: its tokens, its easing, its token animation. */
+export const STYLES = `
+ :host { all: initial; }
+ * { box-sizing: border-box; margin: 0; padding: 0; }
+ .layer {
+ --ease: cubic-bezier(0.16, 1, 0.3, 1);
+ --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
+ --shade: rgb(0 0 0 / 70%);
+ --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
+ font-family: var(--sans);
+ color: var(--ink);
+ -webkit-font-smoothing: antialiased;
+ }
+ .layer[data-light] { --shade: rgb(40 30 20 / 28%); }
+ svg { display: block; width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
+
+ .wrap {
+ position: fixed;
+ z-index: 2147483646;
+ width: ${ORB_SIZE}px;
+ height: ${ORB_SIZE}px;
+ margin: -${ORB_SIZE / 2}px 0 0 -${ORB_SIZE / 2}px;
+ transition: opacity 180ms ease, transform 420ms var(--spring);
+ }
+ .wrap.gliding { transition: opacity 180ms ease, transform 420ms var(--spring), left 380ms var(--ease), top 380ms var(--ease); }
+ .wrap.entering { animation: orb-rise 620ms var(--spring) both; }
+ .wrap.arriving { animation: orb-fade 220ms ease both; }
+ .wrap.leaving { opacity: 0; transform: translateY(18px) scale(0.7); transition: opacity 200ms ease, transform 220ms ease-in; }
+ .wrap.picking { opacity: 0; visibility: hidden; pointer-events: none; transition: opacity 160ms ease, visibility 0s linear 160ms; }
+
+ .orb {
+ all: unset;
+ position: relative;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ width: ${ORB_SIZE}px;
+ height: ${ORB_SIZE}px;
+ border-radius: 999px;
+ cursor: pointer;
+ touch-action: none;
+ user-select: none;
+ -webkit-user-select: none;
+ color: var(--inkDim);
+ border: 1px solid var(--line);
+ background:
+ radial-gradient(circle at 50% 28%, color-mix(in oklch, var(--ink) 9%, transparent), transparent 62%),
+ var(--ground2);
+ box-shadow:
+ 0 16px 40px -14px var(--shade),
+ 0 0 0 1px rgb(0 0 0 / 22%),
+ 0 6px 26px -10px color-mix(in oklch, var(--accent, var(--brand)) 55%, transparent);
+ transition: transform 260ms var(--ease), box-shadow 260ms var(--ease), border-color 200ms ease, color 200ms ease;
+ }
+ .orb:hover { transform: translateY(-1px); border-color: color-mix(in oklch, var(--accent, var(--brand)) 40%, var(--line)); }
+ .orb:focus-visible { outline: 2px solid color-mix(in oklch, var(--brand) 70%, transparent); outline-offset: 3px; }
+ .wrap.lifted .orb {
+ transform: scale(1.12);
+ cursor: grabbing;
+ box-shadow:
+ 0 26px 56px -16px var(--shade),
+ 0 0 0 1px rgb(0 0 0 / 22%),
+ 0 10px 34px -8px color-mix(in oklch, var(--accent, var(--brand)) 70%, transparent);
+ }
+
+ .face { position: absolute; width: 22px; height: 22px; opacity: 0; transform: scale(0.6); transition: opacity 180ms ease, transform 260ms var(--ease); }
+ .wrap[data-face="mic"] .face.mic,
+ .wrap[data-face="off"] .face.off,
+ .wrap[data-face="shield"] .face.shield,
+ .wrap[data-face="dots"] .face.dots { opacity: 1; transform: none; }
+ .wrap[data-face="dots"] .orb:hover .face.dots { opacity: 0; transform: scale(0.6); }
+ .wrap[data-face="dots"] .orb:hover .face.stop { opacity: 1; transform: none; }
+ .face.stop { width: 16px; height: 16px; color: var(--ember); }
+ .face.stop svg { fill: currentColor; }
+ .face.dots { display: flex; align-items: center; justify-content: center; gap: 4px; }
+ .face.dots i { width: 5px; height: 5px; border-radius: 999px; background: var(--brand); animation: orb-think 1.2s ease-in-out infinite; }
+ .face.dots i:nth-child(2) { animation-delay: 0.16s; }
+ .face.dots i:nth-child(3) { animation-delay: 0.32s; }
+
+ .wrap[data-tone="listen"] { --accent: var(--magenta); }
+ .wrap[data-tone="listen"] .orb { color: var(--magenta); animation: orb-breathe 2.6s ease-in-out infinite; }
+ .wrap[data-tone="work"] { --accent: var(--brand); }
+ .wrap[data-tone="work"] .orb { color: var(--brand); animation: orb-glow 1.6s ease-in-out infinite; }
+ .wrap[data-tone="ask"] { --accent: var(--ember); }
+ .wrap[data-tone="ask"] .orb { color: var(--ember); border-color: color-mix(in oklch, var(--ember) 55%, transparent); }
+ .wrap[data-tone="trouble"] { --accent: var(--amber); }
+ .wrap[data-tone="trouble"] .orb { color: var(--amber); }
+ .wrap[data-tone="quiet"] .orb { color: var(--inkFaint); }
+
+ .ping, .ping2 {
+ position: absolute;
+ inset: 0;
+ border-radius: 999px;
+ pointer-events: none;
+ background: color-mix(in oklch, var(--accent, var(--magenta)) 30%, transparent);
+ opacity: 0;
+ }
+ .wrap.speaking .ping { animation: orb-ping 1s cubic-bezier(0, 0, 0.2, 1) infinite; }
+ .wrap.speaking .ping2 { animation: orb-ping 1s cubic-bezier(0, 0, 0.2, 1) 0.5s infinite; }
+ .wrap.speaking .orb {
+ border-color: color-mix(in oklch, var(--magenta) 70%, transparent);
+ box-shadow:
+ 0 16px 40px -14px var(--shade),
+ 0 0 0 3px color-mix(in oklch, var(--magenta) 22%, transparent),
+ 0 0 26px 2px color-mix(in oklch, var(--magenta) 45%, transparent);
+ }
+ .wrap[data-tone="ask"] .ping { animation: orb-ping 1.4s cubic-bezier(0, 0, 0.2, 1) infinite; }
+
+ .spin {
+ position: absolute;
+ inset: -6px;
+ border-radius: 999px;
+ pointer-events: none;
+ opacity: 0;
+ background: conic-gradient(from 0deg, transparent 0 40%, color-mix(in oklch, var(--brand) 35%, transparent) 62%, var(--brand) 92%, transparent 100%);
+ filter: drop-shadow(0 0 5px color-mix(in oklch, var(--brand) 80%, transparent));
+ -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3.5px), #000 calc(100% - 3px));
+ mask: radial-gradient(farthest-side, transparent calc(100% - 3.5px), #000 calc(100% - 3px));
+ transition: opacity 240ms ease;
+ }
+ .wrap[data-tone="work"] .spin { opacity: 1; animation: orb-spin 1.1s linear infinite; }
+
+ .ring { position: absolute; left: 50%; top: 50%; width: 72px; height: 72px; margin: -36px 0 0 -36px; transform: rotate(-90deg); pointer-events: none; overflow: visible; }
+ .ring circle { stroke-width: 2.5; opacity: 0; transition: opacity 160ms ease; }
+ .ring .track { stroke: color-mix(in oklch, var(--brand) 22%, transparent); }
+ .ring .count { stroke: var(--brand); stroke-dasharray: ${RING}; stroke-dashoffset: 0; filter: drop-shadow(0 0 4px color-mix(in oklch, var(--brand) 70%, transparent)); }
+ .wrap.counting .ring circle { opacity: 1; }
+ .wrap.counting .ring .count { animation: orb-drain ${AUTO_SEND_MS}ms linear forwards; }
+
+ .status {
+ position: absolute;
+ right: 2px;
+ bottom: 2px;
+ width: 11px;
+ height: 11px;
+ border-radius: 999px;
+ border: 2px solid var(--ground2);
+ background: var(--inkFaint);
+ display: none;
+ }
+ .wrap[data-link="pending"] .status { display: block; background: var(--amber); animation: orb-pulse 1.4s ease-in-out infinite; }
+ .wrap[data-link="off"] .status { display: block; }
+ .wrap[data-tone="ask"] .status { display: block; background: var(--ember); box-shadow: 0 0 8px 1px color-mix(in oklch, var(--ember) 70%, transparent); animation: none; }
+
+ .keycap {
+ position: absolute;
+ left: 50%;
+ bottom: 5px;
+ translate: -50% 0;
+ display: none;
+ min-width: 16px;
+ padding: 0 3px;
+ border-radius: 4px;
+ border: 1px solid var(--line);
+ background: var(--ground);
+ color: var(--inkDim);
+ font: 600 8.5px/12px ui-monospace, SFMono-Regular, Menlo, monospace;
+ letter-spacing: 0.04em;
+ text-align: center;
+ text-transform: uppercase;
+ transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
+ }
+ .wrap.push-to-talk .keycap { display: block; }
+ .wrap.push-to-talk .face { translate: 0 -4px; }
+ .wrap.holding .orb {
+ transform: scale(1.06);
+ border-color: color-mix(in oklch, var(--magenta) 75%, transparent);
+ box-shadow:
+ 0 16px 40px -14px var(--shade),
+ 0 0 0 3px color-mix(in oklch, var(--magenta) 25%, transparent),
+ 0 0 26px 2px color-mix(in oklch, var(--magenta) 45%, transparent);
+ }
+ .wrap.holding .keycap { background: var(--magenta); border-color: var(--magenta); color: var(--ground); }
+
+ .halo {
+ position: absolute;
+ left: 50%;
+ top: 50%;
+ width: calc(var(--halo, 120px) * 2);
+ height: calc(var(--halo, 120px) * 2);
+ margin: calc(var(--halo, 120px) * -1) 0 0 calc(var(--halo, 120px) * -1);
+ border-radius: 999px;
+ pointer-events: none;
+ }
+ .wrap.open .halo { pointer-events: auto; }
+
+ .item {
+ all: unset;
+ position: absolute;
+ left: 50%;
+ top: 50%;
+ width: ${MENU_ITEM}px;
+ height: ${MENU_ITEM}px;
+ margin: -${MENU_ITEM / 2}px 0 0 -${MENU_ITEM / 2}px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ border-radius: 999px;
+ cursor: pointer;
+ color: var(--inkDim);
+ border: 1px solid var(--line);
+ background: var(--ground2);
+ box-shadow: 0 10px 26px -12px var(--shade), 0 0 0 1px rgb(0 0 0 / 18%);
+ opacity: 0;
+ visibility: hidden;
+ pointer-events: none;
+ transform: translate(0, 0) scale(0.35);
+ transition:
+ transform 260ms ease-in calc(var(--r, 0) * 28ms),
+ opacity 200ms ease calc(var(--r, 0) * 28ms),
+ visibility 0s linear 360ms,
+ background-color 150ms ease, color 150ms ease, border-color 150ms ease;
+ }
+ .item svg { width: 17px; height: 17px; }
+ .wrap.open .item {
+ opacity: 1;
+ visibility: visible;
+ pointer-events: auto;
+ transform: translate(var(--x, 0), var(--y, 0)) scale(1);
+ transition:
+ transform 460ms var(--spring) calc(var(--i, 0) * 60ms),
+ opacity 220ms ease calc(var(--i, 0) * 60ms),
+ visibility 0s,
+ background-color 150ms ease, color 150ms ease, border-color 150ms ease;
+ }
+ .item:hover, .item:focus-visible { color: var(--ink); background: var(--surface); border-color: color-mix(in oklch, var(--brand) 40%, var(--line)); outline: none; }
+ .item.on { color: var(--ember); border-color: color-mix(in oklch, var(--ember) 45%, transparent); background: color-mix(in oklch, var(--ember) 12%, var(--ground2)); }
+ .item.busy svg { animation: orb-pulse 1.1s ease-in-out infinite; }
+ .item .badge {
+ position: absolute;
+ top: -3px;
+ right: -3px;
+ min-width: 16px;
+ height: 16px;
+ padding: 0 4px;
+ border-radius: 999px;
+ background: var(--brand);
+ color: var(--ground);
+ font: 700 9px/16px ui-monospace, SFMono-Regular, Menlo, monospace;
+ text-align: center;
+ display: none;
+ }
+ .item .badge.shown { display: block; }
+ .tip {
+ position: absolute;
+ padding: 5px 9px;
+ border-radius: 8px;
+ border: 1px solid var(--line);
+ background: var(--ground2);
+ color: var(--ink);
+ font: 500 11px/1.2 var(--sans);
+ white-space: nowrap;
+ pointer-events: none;
+ opacity: 0;
+ transform: scale(0.94);
+ transition: opacity 140ms ease, transform 180ms var(--ease);
+ box-shadow: 0 10px 24px -12px var(--shade);
+ }
+ .item[data-tip="top"] .tip { bottom: calc(100% + 8px); left: 50%; translate: -50% 0; }
+ .item[data-tip="bottom"] .tip { top: calc(100% + 8px); left: 50%; translate: -50% 0; }
+ .item[data-tip="left"] .tip { right: calc(100% + 8px); top: 50%; translate: 0 -50%; }
+ .item[data-tip="right"] .tip { left: calc(100% + 8px); top: 50%; translate: 0 -50%; }
+ .item:hover .tip, .item:focus-visible .tip { opacity: 1; transform: none; }
+
+ .caption {
+ position: fixed;
+ z-index: 2147483646;
+ display: flex;
+ flex-direction: column;
+ gap: 7px;
+ width: max-content;
+ max-width: min(360px, calc(100vw - 24px));
+ padding: 10px 13px 11px;
+ border: 1px solid var(--line);
+ border-radius: 14px;
+ background: color-mix(in oklch, var(--ground2) 94%, transparent);
+ -webkit-backdrop-filter: blur(14px) saturate(1.2);
+ backdrop-filter: blur(14px) saturate(1.2);
+ box-shadow: 0 16px 40px -16px var(--shade), 0 0 0 1px rgb(0 0 0 / 20%);
+ pointer-events: none;
+ animation: orb-caption-in 260ms var(--ease) both;
+ transition: opacity 200ms ease, left 260ms var(--ease), top 260ms var(--ease);
+ }
+ .caption.dragged { transition: opacity 200ms ease; }
+ .caption[hidden] { display: none; }
+ .caption.leaving { opacity: 0; }
+ .caption[data-side="bottom"] .chips { order: -1; }
+ .label {
+ display: flex;
+ align-items: center;
+ gap: 6px;
+ font: 600 9.5px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
+ letter-spacing: 0.12em;
+ text-transform: uppercase;
+ color: var(--tone, var(--inkFaint));
+ }
+ .label::before {
+ content: "";
+ width: 6px;
+ height: 6px;
+ border-radius: 999px;
+ background: currentColor;
+ box-shadow: 0 0 8px 1px color-mix(in oklch, currentColor 70%, transparent);
+ }
+ .label:empty { display: none; }
+ .caption[data-kind="speech"] { --tone: var(--magenta); }
+ .caption[data-kind="sent"], .caption[data-kind="reply"] { --tone: var(--brand); }
+ .caption[data-kind="error"] { --tone: var(--amber); }
+ .caption[data-kind="ask"] { --tone: var(--ember); border-color: color-mix(in oklch, var(--ember) 40%, var(--line)); }
+ .words {
+ display: flex;
+ flex-wrap: wrap;
+ align-content: flex-end;
+ column-gap: 0.28em;
+ max-height: calc(1.45em * 4);
+ overflow: hidden;
+ font: 400 14px/1.45 var(--sans);
+ color: var(--ink);
+ }
+ .words:empty { display: none; }
+ .words.overflow { -webkit-mask-image: linear-gradient(to bottom, transparent, #000 1.6em); mask-image: linear-gradient(to bottom, transparent, #000 1.6em); }
+ .caption[data-kind="hint"] .words { font-size: 12.5px; color: var(--inkDim); }
+ .caption[data-kind="sent"] .words { color: var(--brand); }
+ .caption[data-kind="error"] .words { color: color-mix(in oklch, var(--amber) 70%, var(--ink)); }
+ .tok { display: inline-block; animation: orb-token 420ms var(--ease) both; }
+ .tok.interim { color: var(--inkDim); }
+
+ .chips { display: flex; flex-wrap: wrap; gap: 5px; pointer-events: auto; }
+ .chips:empty { display: none; }
+ .chip {
+ display: inline-flex;
+ align-items: center;
+ gap: 5px;
+ max-width: 240px;
+ height: 22px;
+ padding: 0 3px 0 8px;
+ border-radius: 999px;
+ border: 1px solid color-mix(in oklch, var(--ember) 40%, transparent);
+ background: color-mix(in oklch, var(--ember) 10%, transparent);
+ color: var(--ink);
+ font: 500 11px/1 var(--sans);
+ }
+ .chip svg { width: 12px; height: 12px; flex: none; color: var(--ember); }
+ .chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
+ .chip button {
+ all: unset;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ width: 16px;
+ height: 16px;
+ border-radius: 999px;
+ color: var(--inkFaint);
+ cursor: pointer;
+ }
+ .chip button:hover { background: var(--surface); color: var(--ink); }
+ .chip button svg { width: 10px; height: 10px; color: inherit; }
+
+ .pop {
+ position: fixed;
+ z-index: 2147483647;
+ width: min(360px, calc(100vw - 24px));
+ padding: 12px 12px 10px;
+ border: 1px solid color-mix(in oklch, var(--ember) 45%, var(--line));
+ border-radius: 14px;
+ background: var(--ground2);
+ box-shadow: 0 22px 50px -18px var(--shade), 0 0 0 1px rgb(0 0 0 / 22%), 0 0 30px -12px color-mix(in oklch, var(--ember) 50%, transparent);
+ animation: orb-pop-in 280ms var(--ease) both;
+ }
+ .pop[hidden] { display: none; }
+ .pop[data-side="top"] { transform-origin: var(--arrow) 100%; }
+ .pop[data-side="bottom"] { transform-origin: var(--arrow) 0; }
+ .pop[data-side="left"] { transform-origin: 100% var(--arrow); }
+ .pop[data-side="right"] { transform-origin: 0 var(--arrow); }
+ .arrow {
+ position: absolute;
+ width: 12px;
+ height: 12px;
+ background: var(--ground2);
+ border: 1px solid color-mix(in oklch, var(--ember) 45%, var(--line));
+ transform: rotate(45deg);
+ }
+ .pop[data-side="top"] .arrow { bottom: -7px; left: calc(var(--arrow) - 6px); border-top: 0; border-left: 0; }
+ .pop[data-side="bottom"] .arrow { top: -7px; left: calc(var(--arrow) - 6px); border-bottom: 0; border-right: 0; }
+ .pop[data-side="left"] .arrow { right: -7px; top: calc(var(--arrow) - 6px); border-bottom: 0; border-left: 0; }
+ .pop[data-side="right"] .arrow { left: -7px; top: calc(var(--arrow) - 6px); border-top: 0; border-right: 0; }
+ .pop-head { display: flex; align-items: center; gap: 8px; }
+ .pop-head svg { width: 16px; height: 16px; flex: none; color: var(--ember); }
+ .pop-title { font: 600 13px/1.35 var(--sans); color: var(--ink); }
+ .pop-site { margin: 3px 0 0 24px; font: 500 10.5px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--inkFaint); }
+ .pop-detail {
+ margin-top: 9px;
+ padding: 7px 9px;
+ border-radius: 8px;
+ background: color-mix(in oklch, var(--ground) 70%, transparent);
+ border: 1px solid var(--line);
+ font: 11px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
+ color: var(--inkDim);
+ overflow-wrap: anywhere;
+ }
+ .pop-purpose { margin-top: 9px; font: 12px/1.45 var(--sans); color: var(--ink); }
+ .pop-code {
+ margin-top: 7px;
+ max-height: 160px;
+ overflow: auto;
+ padding: 8px 9px;
+ border-radius: 8px;
+ background: color-mix(in oklch, var(--ground) 80%, transparent);
+ border: 1px solid var(--line);
+ font: 10.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
+ color: var(--inkDim);
+ white-space: pre;
+ tab-size: 2;
+ }
+ .pop-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; margin-top: 11px; }
+ .btn {
+ all: unset;
+ height: 28px;
+ padding: 0 11px;
+ border-radius: 8px;
+ font: 500 12px/28px var(--sans);
+ color: var(--inkDim);
+ cursor: pointer;
+ white-space: nowrap;
+ transition: background-color 150ms ease, color 150ms ease;
+ }
+ .btn:hover, .btn:focus-visible { background: var(--surface); color: var(--ink); outline: none; }
+ .btn.primary { background: var(--brand); color: var(--ground); font-weight: 600; }
+ .btn.primary:hover, .btn.primary:focus-visible { background: color-mix(in oklch, var(--brand) 86%, var(--ink)); color: var(--ground); }
+
+ @keyframes orb-rise {
+ from { opacity: 0; transform: translateY(70px) scale(0.4); }
+ 60% { opacity: 1; }
+ }
+ @keyframes orb-fade { from { opacity: 0; transform: scale(0.9); } }
+ @keyframes orb-think {
+ 0%, 70%, 100% { opacity: 0.25; transform: translateY(0); }
+ 35% { opacity: 1; transform: translateY(-2px); }
+ }
+ @keyframes orb-ping { 0% { opacity: 0.9; transform: scale(1); } 75%, 100% { opacity: 0; transform: scale(1.75); } }
+ @keyframes orb-spin { to { transform: rotate(360deg); } }
+ @keyframes orb-drain { to { stroke-dashoffset: ${RING}; } }
+ @keyframes orb-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
+ @keyframes orb-breathe {
+ 0%, 100% { border-color: color-mix(in oklch, var(--magenta) 22%, var(--line)); }
+ 50% { border-color: color-mix(in oklch, var(--magenta) 55%, var(--line)); }
+ }
+ @keyframes orb-glow {
+ 0%, 100% { box-shadow: 0 16px 40px -14px var(--shade), 0 0 0 1px rgb(0 0 0 / 22%), 0 6px 26px -10px color-mix(in oklch, var(--brand) 55%, transparent); }
+ 50% { box-shadow: 0 16px 40px -14px var(--shade), 0 0 0 1px rgb(0 0 0 / 22%), 0 0 30px 0 color-mix(in oklch, var(--brand) 55%, transparent); }
+ }
+ @keyframes orb-token {
+ from { opacity: 0; filter: blur(4px); transform: translateY(3px); }
+ to { opacity: 1; filter: blur(0); transform: none; }
+ }
+ @keyframes orb-caption-in { from { opacity: 0; transform: translateY(4px) scale(0.98); } }
+ @keyframes orb-pop-in { from { opacity: 0; transform: scale(0.92); } }
+
+ @media (prefers-reduced-motion: reduce) {
+ .wrap, .wrap *, .caption, .caption *, .pop { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
+ .wrap.counting .ring .count { animation-duration: ${AUTO_SEND_MS}ms !important; }
+ }
+ @media print { .layer { display: none; } }
+`;
diff --git a/vitest.config.ts b/vitest.config.ts
index 4ffe1f2..152a81a 100644
--- a/vitest.config.ts
+++ b/vitest.config.ts
@@ -23,7 +23,7 @@ export default defineConfig({
test: {
name: 'lib',
include: ['src/lib/**/*.test.ts'],
- exclude: [...configDefaults.exclude, 'src/lib/actions/page/**'],
+ exclude: [...configDefaults.exclude, 'src/lib/actions/page/**', 'src/lib/handsfree/host.test.ts'],
},
},
{
@@ -31,7 +31,7 @@ export default defineConfig({
test: {
name: 'dom',
environment: 'happy-dom',
- include: ['src/lib/actions/page/**/*.test.ts'],
+ include: ['src/lib/actions/page/**/*.test.ts', 'src/lib/handsfree/host.test.ts'],
},
},
{