Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: stop OpenWorld playback Space from opening the voice mic (#4731)
[._.]/ Adam Eivy68778d196b9b
diff --git a/client/src/components/RapidReader.jsx b/client/src/components/RapidReader.jsxindex 8a2c10f6d0..fb4bb054e2 100644--- a/client/src/components/RapidReader.jsx+++ b/client/src/components/RapidReader.jsx@@ -1,6 +1,7 @@import { useEffect, useMemo, useRef, useState, useCallback } from 'react';import { Play, Pause, RotateCcw, Rewind, FastForward, X, Zap } from 'lucide-react';import Modal from './ui/Modal';+import useKeyCapture from '../hooks/useKeyCapture';// Optimal Recognition Point — the focal letter the eye lands on. Spritz-style:// shorter words use a left-shifted ORP, longer words shift right. Returns the@@ -98,15 +99,12 @@ export default function RapidReader({return () => clearTimeout(timeoutRef.current);}, [playing, idx, total, current, delayFor, onComplete]);- // Keyboard controls — only active when this component is mounted.- // Registered in the capture phase so we run before bubble-phase window- // listeners (notably VoiceWidget's hotkey, which also claims Space). When- // we handle a key we call stopImmediatePropagation so the voice agent- // doesn't toggle its mic on the same press.- useEffect(() => {- const onKey = (e) => {- const tag = e.target?.tagName;- if (tag === 'INPUT' || tag === 'TEXTAREA' || e.target?.isContentEditable) return;+ // Keyboard controls — only active while this component is mounted. Claimed in+ // the capture phase so a handled key never reaches a bubble-phase window+ // listener (notably VoiceWidget's hotkey, which also binds Space); keys we+ // do not handle pass through untouched.+ useKeyCapture({+ onKeyDown: (e) => {if (e.key === ' ') setPlaying((p) => !p);else if (e.key === 'ArrowLeft') setIdx((i) => Math.max(0, i - 1));else if (e.key === 'ArrowRight') setIdx((i) => Math.min(total - 1, i + 1));@@ -114,13 +112,10 @@ export default function RapidReader({else if (e.key === '+' || e.key === '=') setWpm((w) => Math.min(1200, w + 25));else if (e.key === '-' || e.key === '_') setWpm((w) => Math.max(100, w - 25));else if (e.key === 'Escape' && onClose) onClose();- else return;- e.preventDefault();- e.stopImmediatePropagation();- };- window.addEventListener('keydown', onKey, true);- return () => window.removeEventListener('keydown', onKey, true);- }, [total, onClose]);+ else return false;+ return true;+ },+ });const restart = () => { setIdx(0); setPlaying(true); };const togglePlay = () => {@@ -299,8 +294,8 @@ function FocalSlot({ chunk, focalColor }) {// Modal wrapper — full-screen overlay so any page can pop the reader without// leaving its context. Closes on Esc or backdrop click. The inner RapidReader-// registers a capture-phase window keydown listener (so Space / arrow keys-// can be claimed before VoiceWidget sees them) that, on Esc, calls onClose+// uses useKeyCapture, a capture-phase window keydown listener (so Space / arrow+// keys can be claimed before VoiceWidget sees them) that, on Esc, calls onClose// and then preventDefault() + stopImmediatePropagation(). Modal's window// listener is bubble-phase, so it never even reaches the same event — the// capture-phase stopImmediatePropagation cancels propagation entirely; evendiff --git a/client/src/components/RapidReader.test.jsx b/client/src/components/RapidReader.test.jsxnew file mode 100644index 0000000000..69ddea8179--- /dev/null+++ b/client/src/components/RapidReader.test.jsx@@ -0,0 +1,88 @@+import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';+import { render, screen, fireEvent, act } from '@testing-library/react';+import RapidReader from './RapidReader';++describe('RapidReader keyboard transport', () => {+ // Stands in for VoiceWidget's app-global push-to-talk hotkey, which binds the same+ // Space on `window` in the bubble phase. The reader claims its keys in the capture+ // phase, so a handled key must never reach this spy.+ let voiceHotkey;++ beforeEach(() => {+ voiceHotkey = vi.fn();+ window.addEventListener('keydown', voiceHotkey);+ });++ afterEach(() => {+ window.removeEventListener('keydown', voiceHotkey);+ });++ const renderReader = (props = {}) => render(+ <RapidReader text="alpha bravo charlie delta" chunkSize={1} {...props} />,+ );++ it('toggles play on Space without leaking the key to the global voice hotkey', () => {+ renderReader();+ expect(screen.getByLabelText('Play')).toBeInTheDocument();++ act(() => { fireEvent.keyDown(document.body, { key: ' ', code: 'Space' }); });++ expect(screen.getByLabelText('Pause')).toBeInTheDocument();+ expect(voiceHotkey).not.toHaveBeenCalled();+ });++ it('claims Escape for its own close handler', () => {+ const onClose = vi.fn();+ renderReader({ onClose });++ act(() => { fireEvent.keyDown(document.body, { key: 'Escape' }); });++ expect(onClose).toHaveBeenCalledTimes(1);+ expect(voiceHotkey).not.toHaveBeenCalled();+ });++ it('lets unhandled keys through to app-global listeners', () => {+ renderReader();++ act(() => { fireEvent.keyDown(document.body, { key: 'j' }); });++ expect(voiceHotkey).toHaveBeenCalledTimes(1);+ });++ it('ignores keys typed into a text field', () => {+ const { container } = renderReader();+ const input = document.createElement('input');+ container.appendChild(input);++ act(() => { fireEvent.keyDown(input, { key: ' ', code: 'Space' }); });++ expect(screen.getByLabelText('Play')).toBeInTheDocument();+ });++ it('ignores Space aimed at a <select>, where it natively opens the dropdown', () => {+ // The old hand-rolled guard only knew INPUT/TEXTAREA/contentEditable, so Space on a+ // focused <select> hijacked the transport. `isEditableTarget` covers SELECT.+ const { container } = renderReader();+ const select = document.createElement('select');+ container.appendChild(select);++ act(() => { fireEvent.keyDown(select, { key: ' ', code: 'Space' }); });++ expect(screen.getByLabelText('Play')).toBeInTheDocument();+ });++ it('steps through the text with the arrow keys', () => {+ // The current word is split across spans to anchor its focal letter, so the+ // token counter ("2/4") is the readable signal for which word is showing.+ const { container } = renderReader();+ const position = () => container.querySelector('.font-mono.text-gray-500').textContent.split(' ')[0];+ expect(position()).toBe('1/4');++ act(() => { fireEvent.keyDown(document.body, { key: 'ArrowRight' }); });+ expect(position()).toBe('2/4');++ act(() => { fireEvent.keyDown(document.body, { key: 'ArrowLeft' }); });+ expect(position()).toBe('1/4');+ expect(voiceHotkey).not.toHaveBeenCalled();+ });+});diff --git a/client/src/components/openworld/PlayerController.jsx b/client/src/components/openworld/PlayerController.jsxindex d035e3723d..38312e0229 100644--- a/client/src/components/openworld/PlayerController.jsx+++ b/client/src/components/openworld/PlayerController.jsx@@ -2,6 +2,7 @@ import { useRef, useEffect, useCallback, useMemo, Suspense } from 'react';import { useThree, useFrame } from '@react-three/fiber';import * as THREE from 'three';import PlayerAvatar from './PlayerAvatar';+import useKeyCapture from '../../hooks/useKeyCapture';import ErrorBoundary from '../ErrorBoundary';import {THIRD_PERSON, EYE_HEIGHT, DEFAULT_SPAWN_Z,@@ -312,32 +313,29 @@ export default function PlayerController({};}, [interact, playerActionRef]);- // In exploration mode, Space is the jump key — capture it before it bubbles to the- // global voice push-to-talk hotkey (VoiceWidget listens for the same key on `window`).- useEffect(() => {- if (!active) return undefined;- const isTypingTarget = (el) => {- if (!el) return false;- const tag = el.tagName;- return tag === 'INPUT' || tag === 'TEXTAREA' || el.isContentEditable;- };- const onKeyDownCapture = (e) => {- if (e.code !== 'Space' || isTypingTarget(document.activeElement)) return;- e.preventDefault();- e.stopImmediatePropagation();+ // In exploration mode, Space is the jump key — claim it in the capture phase so it+ // never reaches the global voice push-to-talk hotkey (VoiceWidget listens for the+ // same key on `window`). Only the keydown is claimed; the matching keyup just+ // clears the held-key state, matching how the rig reads every other movement key.+ useKeyCapture({+ enabled: active,+ onKeyDown: (e) => {+ if (e.code !== 'Space') return false;keysRef.current.add(' ');- };- const onKeyUpCapture = (e) => {- if (e.code !== 'Space') return;- keysRef.current.delete(' ');- };- window.addEventListener('keydown', onKeyDownCapture, true);- window.addEventListener('keyup', onKeyUpCapture, true);- return () => {- window.removeEventListener('keydown', onKeyDownCapture, true);- window.removeEventListener('keyup', onKeyUpCapture, true);+ return true;+ },+ onKeyUp: (e) => {+ if (e.code !== 'Space') return false;keysRef.current.delete(' ');- };+ return false;+ },+ });++ // Drop a held jump when exploration mode ends, so re-entering it does not start+ // mid-jump from a keyup that fired after the listeners went away.+ useEffect(() => {+ if (!active) return undefined;+ return () => { keysRef.current.delete(' '); };}, [active, keysRef]);useFrame((_, delta) => {diff --git a/client/src/components/openworld/PlayerController.test.jsx b/client/src/components/openworld/PlayerController.test.jsxnew file mode 100644index 0000000000..b143d056a4--- /dev/null+++ b/client/src/components/openworld/PlayerController.test.jsx@@ -0,0 +1,78 @@+import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';+import { render, fireEvent, act } from '@testing-library/react';+import * as THREE from 'three';++// PlayerController is an r3f component, but its Space handling is plain DOM wiring. The+// fiber hooks are stubbed so it can mount in jsdom without a WebGL canvas; rendering in+// first-person camera mode returns null, so nothing three.js-specific ever paints.+vi.mock('@react-three/fiber', () => ({+ useThree: () => ({ camera: new THREE.PerspectiveCamera(), gl: { domElement: document.createElement('canvas') } }),+ useFrame: () => {},+}));++const PlayerController = (await import('./PlayerController')).default;++describe('PlayerController Space (jump) capture', () => {+ // Stands in for VoiceWidget's app-global push-to-talk hotkey, which binds the same+ // Space on `window` in the bubble phase.+ let voiceHotkey;+ let keysRef;++ beforeEach(() => {+ voiceHotkey = vi.fn();+ window.addEventListener('keydown', voiceHotkey);+ keysRef = { current: new Set() };+ });++ afterEach(() => {+ window.removeEventListener('keydown', voiceHotkey);+ });++ const renderRig = (props = {}) => render(+ <PlayerController keysRef={keysRef} active cameraView="first" positions={new Map()} apps={[]} {...props} />,+ );++ it('holds the jump key without leaking Space to the global voice hotkey', () => {+ renderRig();++ act(() => { fireEvent.keyDown(document.body, { key: ' ', code: 'Space' }); });+ expect(keysRef.current.has(' ')).toBe(true);+ expect(voiceHotkey).not.toHaveBeenCalled();++ act(() => { fireEvent.keyUp(document.body, { key: ' ', code: 'Space' }); });+ expect(keysRef.current.has(' ')).toBe(false);+ });++ it('ignores Space typed into a text field', () => {+ const { container } = renderRig();+ const input = document.createElement('input');+ container.appendChild(input);++ act(() => { fireEvent.keyDown(input, { key: ' ', code: 'Space' }); });++ expect(keysRef.current.has(' ')).toBe(false);+ });++ it('drops a held jump when exploration mode ends', () => {+ const { rerender } = renderRig();+ act(() => { fireEvent.keyDown(document.body, { key: ' ', code: 'Space' }); });+ expect(keysRef.current.has(' ')).toBe(true);++ act(() => {+ rerender(+ <PlayerController keysRef={keysRef} active={false} cameraView="first" positions={new Map()} apps={[]} />,+ );+ });++ expect(keysRef.current.has(' ')).toBe(false);+ });++ it('binds nothing while exploration mode is off', () => {+ renderRig({ active: false });++ act(() => { fireEvent.keyDown(document.body, { key: ' ', code: 'Space' }); });++ expect(keysRef.current.has(' ')).toBe(false);+ expect(voiceHotkey).toHaveBeenCalledTimes(1);+ });+});diff --git a/client/src/pages/OpenWorld.jsx b/client/src/pages/OpenWorld.jsxindex c7b72c3fa9..bfd96c110e 100644--- a/client/src/pages/OpenWorld.jsx+++ b/client/src/pages/OpenWorld.jsx@@ -4,7 +4,8 @@ import { useOpenWorldData } from '../hooks/useOpenWorldData';import { useOpenWorldPlayback } from '../hooks/useOpenWorldPlayback';import useOpenWorldAudio from '../hooks/useOpenWorldAudio';import useKeyboardControls from '../hooks/useKeyboardControls';-import useKeyboardShortcuts from '../hooks/useKeyboardShortcuts';+import useKeyboardShortcuts, { isEditableTarget } from '../hooks/useKeyboardShortcuts';+import useKeyCapture from '../hooks/useKeyCapture';import { useAutoRefetch } from '../hooks/useAutoRefetch';import { mergeFrameIntoOpenWorldProps } from '../lib/openWorldPlaybackFrame';import * as api from '../services/api';@@ -311,8 +312,7 @@ function OpenWorldInner() {useEffect(() => {if (!photoMode) return;const onKey = (e) => {- const tag = e.target?.tagName;- if (tag === 'INPUT' || tag === 'TEXTAREA') return;+ if (isEditableTarget(e.target)) return;if (e.key === 'Escape') setPhotoMode(false);else if (e.key === 'ArrowLeft') setPhotoPresetId(id => cyclePreset(id, -1));else if (e.key === 'ArrowRight') setPhotoPresetId(id => cyclePreset(id, 1));@@ -323,20 +323,24 @@ function OpenWorldInner() {}, [photoMode]);// Playback keyboard transport: Esc exits, Space play/pause, ←/→ step a frame.- // Bound only while playback is active. Ignores key events while typing.- useEffect(() => {- if (!playback.active) return;- const onKey = (e) => {- const tag = e.target?.tagName;- if (tag === 'INPUT' || tag === 'TEXTAREA') return;+ // Bound only while playback is active. Claimed in the capture phase so Space+ // toggles playback WITHOUT also tripping the voice widget's app-global+ // push-to-talk hotkey; keys we do not handle pass through untouched.+ useKeyCapture({+ enabled: playback.active,+ onKeyDown: (e) => {+ // An open dialog layer (the settings drawer, a lightbox) owns the keyboard while+ // it is up — most importantly Escape, which has to dismiss that layer rather than+ // drop the user out of playback behind it.+ if (document.querySelector('[aria-modal="true"]')) return false;if (e.key === 'Escape') playback.exit();- else if (e.key === ' ') { e.preventDefault(); playback.togglePlay(); }+ else if (e.key === ' ') playback.togglePlay();else if (e.key === 'ArrowLeft') playback.step(-1);else if (e.key === 'ArrowRight') playback.step(1);- };- window.addEventListener('keydown', onKey);- return () => window.removeEventListener('keydown', onKey);- }, [playback.active, playback]);+ else return false;+ return true;+ },+ });// Task-complete chime (roadmap 3.4): when a CoS task transitions to completed, play a reward// chime. Track the set of completed ids across socket updates and chime on each newly-seen one.diff --git a/client/src/pages/OpenWorld.transport.test.jsx b/client/src/pages/OpenWorld.transport.test.jsxnew file mode 100644index 0000000000..25aac66430--- /dev/null+++ b/client/src/pages/OpenWorld.transport.test.jsx@@ -0,0 +1,138 @@+import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';+import { render, fireEvent, act } from '@testing-library/react';+import { MemoryRouter, Routes, Route } from 'react-router';++// Same stubbing strategy as OpenWorld.fastTravel.test.jsx: the 3D scene and the HUD are+// replaced with inert divs so the page's keyboard WIRING can be exercised in jsdom.+vi.mock('../components/openworld/OpenWorldScene', () => ({ default: () => <div data-testid="scene" /> }));+vi.mock('../components/openworld/OpenWorldHud', () => ({ default: () => null }));+vi.mock('../components/openworld/OpenWorldPhotoOverlay', () => ({ default: () => null }));+vi.mock('../components/openworld/OpenWorldPlaybackOverlay', () => ({ default: () => null }));+vi.mock('../components/openworld/OpenWorldSettingsDrawer', () => ({ default: () => null }));++vi.mock('../hooks/useOpenWorldData', () => ({+ useOpenWorldData: () => ({+ apps: [], cosAgents: [], cosStatus: {}, eventLogs: [], agentMap: new Map(),+ reviewCounts: {}, instances: {}, systemHealth: null, notificationCounts: {},+ backupStatus: null, cosTasks: [], healthMetrics: null, voiceState: null,+ character: null, aiActivity: null, loading: false, connected: true,+ }),+}));++// The playback hook is the surface under test: the page binds its transport keys only+// while `active`, and the spies below record what each key reached.+const playback = vi.hoisted(() => ({+ active: true, currentFrame: null, snapshots: [], frameIndex: 0, stats: null,+ playing: false, speed: 1, loading: false, error: null,+ enter: vi.fn(), exit: vi.fn(), seek: vi.fn(), step: vi.fn(),+ togglePlay: vi.fn(), cycleSpeed: vi.fn(),+}));+vi.mock('../hooks/useOpenWorldPlayback', () => ({ useOpenWorldPlayback: () => playback }));+vi.mock('../hooks/useOpenWorldAudio', () => ({ default: () => ({ playSfx: vi.fn(), isAudioReady: false }) }));+vi.mock('../hooks/useAutoRefetch', () => ({ useAutoRefetch: () => ({ data: null }) }));+vi.mock('../services/api', () => ({+ getCosQuickSummary: vi.fn(async () => null),+ getCosActivityCalendar: vi.fn(async () => null),+ getGoals: vi.fn(async () => null),+ getChronotype: vi.fn(async () => null),+ getMemoryGraph: vi.fn(async () => null),+ getBrainInbox: vi.fn(async () => null),+ getOpenWorldIntrospection: vi.fn(async () => null),+ getMySprintTickets: vi.fn(async () => []),+}));++const OpenWorld = (await import('./OpenWorld')).default;++const renderPage = () => render(+ <MemoryRouter initialEntries={['/openworld']}>+ <Routes><Route path="/openworld" element={<OpenWorld />} /></Routes>+ </MemoryRouter>+);++describe('OpenWorld playback transport keys', () => {+ // Stands in for VoiceWidget's app-global push-to-talk hotkey, which binds the same+ // Space on `window` in the bubble phase. If the transport ever stops CLAIMING the+ // key in the capture phase, this spy fires and the mic opens mid-playback.+ let voiceHotkey;++ beforeEach(() => {+ playback.active = true;+ playback.exit.mockClear();+ playback.step.mockClear();+ playback.togglePlay.mockClear();+ localStorage.clear();+ voiceHotkey = vi.fn();+ window.addEventListener('keydown', voiceHotkey);+ });++ afterEach(() => {+ window.removeEventListener('keydown', voiceHotkey);+ });++ it('toggles play on Space without leaking the key to the global voice hotkey', () => {+ renderPage();++ act(() => { fireEvent.keyDown(document.body, { key: ' ', code: 'Space' }); });++ expect(playback.togglePlay).toHaveBeenCalledTimes(1);+ expect(voiceHotkey).not.toHaveBeenCalled();+ });++ it('claims Escape and the arrow keys too', () => {+ renderPage();++ act(() => { fireEvent.keyDown(document.body, { key: 'ArrowLeft' }); });+ act(() => { fireEvent.keyDown(document.body, { key: 'ArrowRight' }); });+ act(() => { fireEvent.keyDown(document.body, { key: 'Escape' }); });++ expect(playback.step.mock.calls).toEqual([[-1], [1]]);+ expect(playback.exit).toHaveBeenCalledTimes(1);+ expect(voiceHotkey).not.toHaveBeenCalled();+ });++ it('lets unhandled keys through to app-global listeners', () => {+ renderPage();++ act(() => { fireEvent.keyDown(document.body, { key: 'j' }); });++ expect(voiceHotkey).toHaveBeenCalledTimes(1);+ expect(playback.togglePlay).not.toHaveBeenCalled();+ });++ it('ignores Space typed into a text field, leaving the transport alone', () => {+ const { container } = renderPage();+ const input = document.createElement('input');+ container.appendChild(input);+ input.focus();++ act(() => { fireEvent.keyDown(input, { key: ' ', code: 'Space' }); });++ expect(playback.togglePlay).not.toHaveBeenCalled();+ });++ it('yields the transport keys to an open dialog layer', () => {+ // The settings drawer renders aria-modal and closes on its own Escape handler; the+ // transport must not swallow that keystroke out from under it.+ const { container } = renderPage();+ const drawer = document.createElement('div');+ drawer.setAttribute('aria-modal', 'true');+ container.appendChild(drawer);++ act(() => { fireEvent.keyDown(document.body, { key: 'Escape' }); });+ act(() => { fireEvent.keyDown(document.body, { key: ' ', code: 'Space' }); });++ expect(playback.exit).not.toHaveBeenCalled();+ expect(playback.togglePlay).not.toHaveBeenCalled();+ expect(voiceHotkey).toHaveBeenCalledTimes(2);+ });++ it('binds nothing while playback is inactive', () => {+ playback.active = false;+ renderPage();++ act(() => { fireEvent.keyDown(document.body, { key: ' ', code: 'Space' }); });++ expect(playback.togglePlay).not.toHaveBeenCalled();+ expect(voiceHotkey).toHaveBeenCalledTimes(1);+ });+});