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 a pointer click from parking focus on a Space-owning surface's buttons (#4748)
[._.]/ Adam Eivy593c6a235298
diff --git a/client/src/CLAUDE.md b/client/src/CLAUDE.mdindex b12c118d87..f5898b1527 100644--- a/client/src/CLAUDE.md+++ b/client/src/CLAUDE.md@@ -12,7 +12,7 @@ These apply to React/Vite client code. Universal constraints (functional program- **Chrome floating over media uses `.port-media-overlay`** - a label, status bar, badge, or control panel sitting on top of an image, a video, or a 3D canvas takes its surface and ink from the theme (`.port-media-overlay`, or `.port-media-overlay-strong` for a small label directly on photography; `.port-media-overlay-item` for its buttons, `.port-media-overlay-divider` for its separators — all defined in `index.css`, which carries the mechanism and the rule for picking between this, `.always-dark`, and the OpenWorld HUD remap). **Don't write `bg-black/NN` + `text-white`/`text-gray-N00` for this** — day mode remaps the text to the theme's dark ink while the black scrim stays black, so the label renders dark-on-black. Older overlays outside the 3D/Three.js pages still carry that idiom (migration tracked in #3796), so match the new convention rather than the nearest neighbor.- **Alphabetical navigation** - sidebar nav items in `Layout.jsx` are alphabetically ordered after the Dashboard+OpenWorld top section and separator; children within collapsible sections are also alphabetical- **OpenWorld's internal names match the user-facing area.** The scene tree lives under `components/openworld/`, its pure helpers are `utils/openWorld*.js`, its hooks are `useOpenWorld*.js`, and its CSS scope is `.openworld-themed`. The legacy OpenWorld command ids remain deliberately frozen because they are opaque values persisted in ⌘K history. Keep the persisted `portos-city-settings` key unchanged when adding settings migrations.-- **Space is an app-global hotkey** - the voice widget binds Space for push-to-talk. A surface that owns Space itself (a timed drill, a keyer, a transport control) must claim it with `useKeyCapture` (capture phase + `stopImmediatePropagation`), or the mic opens on every press. Conversely, a global single-key handler stands down when the browser is about to activate a focused button. All three global key paths — `useKeyCapture`, `useKeyboardShortcuts`, and the voice widget's own hotkey listener — decide that through the one shared `shouldIgnoreGlobalKey(event, opts)` predicate in `lib/a11yKeyboard.js`, so a new guard goes THERE, never at one caller (that drift is what let `useKeyCapture` swallow button activation, #4748).+- **Space is an app-global hotkey** - the voice widget binds Space for push-to-talk. A surface that owns Space itself (a timed drill, a keyer, a transport control) must claim it with `useKeyCapture` (capture phase + `stopImmediatePropagation`), or the mic opens on every press. Conversely, a global single-key handler stands down when the browser is about to activate a focused button. All three global key paths — `useKeyCapture`, `useKeyboardShortcuts`, and the voice widget's own hotkey listener — decide that through the one shared `shouldIgnoreGlobalKey(event, opts)` predicate in `lib/a11yKeyboard.js`, so a new guard goes THERE, never at one caller (that drift is what let `useKeyCapture` swallow button activation, #4748). The corollary: on a surface that OWNS a key, spread `noPointerFocusProps` on its buttons — a mouse click that parks focus on one silently takes that key over, because the global handler correctly stands down for native activation.- **Reactive UI updates** - after mutations (delete, create, update), update local state directly instead of refetching the entire list from the server. Use `setState(prev => prev.filter(...))` or similar patterns for immediate feedback## API errors and save gatingdiff --git a/client/src/components/RapidReader.jsx b/client/src/components/RapidReader.jsxindex 5f49c7184f..52624f16c4 100644--- a/client/src/components/RapidReader.jsx+++ b/client/src/components/RapidReader.jsx@@ -2,6 +2,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';+import { noPointerFocusProps } from '../lib/a11yKeyboard';// 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@@ -170,7 +171,7 @@ export default function RapidReader({<div className="flex items-center gap-2"><buttontype="button"- onClick={back}+ onClick={back} {...noPointerFocusProps}className="min-h-10 min-w-10 flex items-center justify-center rounded-lg border border-port-border text-gray-400 hover:text-white hover:bg-port-bg/60"title="Back 5 (←)"aria-label="Back 5 words"@@ -179,7 +180,7 @@ export default function RapidReader({</button><buttontype="button"- onClick={togglePlay}+ onClick={togglePlay} {...noPointerFocusProps}className="min-h-10 min-w-10 flex items-center justify-center rounded-lg bg-port-accent/15 border border-port-accent/40 text-port-accent hover:bg-port-accent/25"title={playing ? 'Pause (space)' : 'Play (space)'}aria-label={playing ? 'Pause' : 'Play'}@@ -188,7 +189,7 @@ export default function RapidReader({</button><buttontype="button"- onClick={fwd}+ onClick={fwd} {...noPointerFocusProps}className="min-h-10 min-w-10 flex items-center justify-center rounded-lg border border-port-border text-gray-400 hover:text-white hover:bg-port-bg/60"title="Forward 5 (→)"aria-label="Forward 5 words"@@ -197,7 +198,7 @@ export default function RapidReader({</button><buttontype="button"- onClick={restart}+ onClick={restart} {...noPointerFocusProps}className="min-h-10 min-w-10 flex items-center justify-center rounded-lg border border-port-border text-gray-400 hover:text-white hover:bg-port-bg/60"title="Restart (R)"aria-label="Restart"@@ -300,6 +301,11 @@ function FocalSlot({ chunk, focalColor }) {// and Modal IS that layer. The claim runs in the capture phase, so Esc reaches// onClose and never Modal's own bubble-phase close — the reader owns Esc here.export function RapidReaderModal({ open, text, title, onClose, ...readerProps }) {+ // Aim the dialog's initial focus at the header ROW, not at the Close button+ // inside it. Focus otherwise lands on the first focusable descendant, and+ // Space on a focused button belongs to the browser — so the reader's own+ // Space (play/pause) would have dismissed the reader instead.+ const headerRef = useRef(null);return (<Modalopen={open}@@ -307,8 +313,9 @@ export function RapidReaderModal({ open, text, title, onClose, ...readerProps })size="xl"ariaLabel={title || 'Rapid Reader'}panelClassName="bg-port-card border border-port-border rounded-xl shadow-2xl"+ initialFocusRef={headerRef}>- <div className="flex items-center justify-between gap-2 px-4 py-2 border-b border-port-border">+ <div ref={headerRef} tabIndex={-1} className="flex items-center justify-between gap-2 px-4 py-2 border-b border-port-border"><div className="flex items-center gap-2 text-sm text-gray-300 truncate"><Zap size={14} className="text-port-accent shrink-0" /><span className="truncate">{title || 'Rapid Reader'}</span>@@ -316,6 +323,7 @@ export function RapidReaderModal({ open, text, title, onClose, ...readerProps })<buttontype="button"onClick={onClose}+ {...noPointerFocusProps}className="min-h-[44px] min-w-[44px] flex items-center justify-center text-gray-400 hover:text-white"aria-label="Close rapid reader">diff --git a/client/src/components/RapidReader.test.jsx b/client/src/components/RapidReader.test.jsxindex 731f3bddd1..40e9c4d137 100644--- a/client/src/components/RapidReader.test.jsx+++ b/client/src/components/RapidReader.test.jsx@@ -67,6 +67,23 @@ describe('RapidReader keyboard transport', () => {expect(screen.getByLabelText('Play')).toBeInTheDocument();});+ // A dialog focuses its first focusable descendant. That used to be the header+ // Close button — and Space on a focused button belongs to the browser, so the+ // reader's own Space dismissed the reader instead of pausing it (#4748).+ it('keeps initial focus off the modal Close button, so Space still pauses', () => {+ const onClose = vi.fn();+ render(<RapidReaderModal open text="alpha bravo charlie delta" title="Notes" onClose={onClose} />);++ expect(document.activeElement).not.toBe(screen.getByLabelText('Close rapid reader'));++ // Aimed at whatever actually holds focus, not at document.body — the whole+ // point is where the browser would route a real keystroke.+ act(() => { fireEvent.keyDown(document.activeElement, { key: ' ', code: 'Space' }); });++ expect(screen.getByLabelText('Play')).toBeInTheDocument();+ expect(onClose).not.toHaveBeenCalled();+ });+it('keeps its keys inside RapidReaderModal, whose own Modal is that dialog', () => {render(<RapidReaderModal open text="alpha bravo charlie delta" title="Notes" onClose={vi.fn()} />);diff --git a/client/src/components/meatspace/post/MorseTrainer.jsx b/client/src/components/meatspace/post/MorseTrainer.jsxindex 52c847fd6f..a216e1c2b8 100644--- a/client/src/components/meatspace/post/MorseTrainer.jsx+++ b/client/src/components/meatspace/post/MorseTrainer.jsx@@ -10,6 +10,7 @@ import { streakGlyph } from '../../../lib/streakGlyph.js';import { safeReadJsonStorage, safeWriteStorage } from '../../../lib/safeStorage';import { resumeAudioContext } from '../../../lib/audioContext.js';import { MORSE_MATERIAL_MODES, canAdvanceMorseLevel, selectMorsePrompt } from '../../../lib/morsePractice.js';+import { isPressKey } from '../../../lib/a11yKeyboard.js';import PostCompletionActions from './PostCompletionActions';import { startRetryableSaves } from './completionSave';@@ -851,7 +852,7 @@ function ListView({ currentPath }) {);}-function KeyPad({ keying }) {+export function KeyPad({ keying }) {return (<div className="bg-port-card border border-port-border rounded-lg p-4 space-y-3"><div className="flex items-center justify-between">@@ -863,12 +864,29 @@ function KeyPad({ keying }) {<Eraser size={11} /> Clear</button></div>+ {/* Space on a focused button belongs to the browser (useKeyCapture stands+ down for it), so the pad has to key on its OWN key events — otherwise+ tapping it once with the mouse would leave focus here and make the+ spacebar dead, on the very control labelled "TAP / HOLD SPACE".+ preventDefault suppresses the native click-on-keyup too, so one press+ is one press. */}<button+ type="button"onMouseDown={keying.beginPress}onMouseUp={keying.endPress}onMouseLeave={keying.endPress}onTouchStart={(e) => { e.preventDefault(); keying.beginPress(); }}onTouchEnd={(e) => { e.preventDefault(); keying.endPress(); }}+ onKeyDown={(e) => {+ if (!isPressKey(e)) return;+ e.preventDefault();+ if (!e.repeat) keying.beginPress();+ }}+ onKeyUp={(e) => {+ if (!isPressKey(e)) return;+ e.preventDefault();+ keying.endPress();+ }}className={`w-full select-none py-6 rounded-lg border-2 font-mono text-base transition-colors ${keying.pressing ? 'border-port-accent bg-port-accent/20 text-port-accent' : 'border-port-border bg-port-bg text-gray-400 hover:border-port-accent'}`}diff --git a/client/src/components/meatspace/post/MorseTrainer.test.jsx b/client/src/components/meatspace/post/MorseTrainer.test.jsxindex fe7f7d0731..52b1e36898 100644--- a/client/src/components/meatspace/post/MorseTrainer.test.jsx+++ b/client/src/components/meatspace/post/MorseTrainer.test.jsx@@ -22,7 +22,7 @@ vi.mock('../../../services/api', () => ({updateMorseLevel: vi.fn(() => Promise.resolve({ kochLevel: 2, kochLevelSet: true, adopted: false, settings: null })),}));-import MorseTrainer, { MODES, MORSE_MODE_IDS, MORSE_TABLE, isNodeOnPath, resultsToItems } from './MorseTrainer';+import MorseTrainer, { MODES, MORSE_MODE_IDS, MORSE_TABLE, KeyPad, isNodeOnPath, resultsToItems } from './MorseTrainer';import { submitTrainingEntry, getTrainingStats, submitMorseRound, getMorseProgress, updateMorseLevel } from '../../../services/api';// Minimal Web Audio mock so CopyDrill's round flow (which calls ensureCtx →@@ -611,3 +611,55 @@ describe('MorseTrainer iOS audio session', () => {expect(navigator.audioSession.type).toBe('auto');});});++// The practice key is the on-screen twin of the spacebar, and both must work+// after the other has been used. Space on a focused button belongs to the+// browser (useKeyCapture stands down for it, #4748), so once a mouse tap parks+// focus on this pad the global claim no longer fires — the pad has to key on+// its own key events or the spacebar goes dead on the control labelled+// "TAP / HOLD SPACE".+describe('MorseTrainer practice key — keyboard parity with the spacebar', () => {+ const makeKeying = () => ({+ beginPress: vi.fn(), endPress: vi.fn(), clear: vi.fn(), pressing: false,+ });+ const pad = () => screen.getByRole('button', { name: /TAP \/ HOLD SPACE/i });++ it('keys on Space while focused, and does not double-fire via the native click', () => {+ const keying = makeKeying();+ render(<KeyPad keying={keying} />);+ const button = pad();+ button.focus();+ expect(document.activeElement).toBe(button);++ fireEvent.keyDown(button, { key: ' ', code: 'Space' });+ expect(keying.beginPress).toHaveBeenCalledTimes(1);+ expect(keying.endPress).not.toHaveBeenCalled();++ fireEvent.keyUp(button, { key: ' ', code: 'Space' });+ expect(keying.endPress).toHaveBeenCalledTimes(1);+ // The keydown preventDefaults, so the browser never synthesizes the click+ // that would key a second time.+ expect(keying.beginPress).toHaveBeenCalledTimes(1);+ });++ it('treats an auto-repeat keydown as one continuous press, not a re-key', () => {+ const keying = makeKeying();+ render(<KeyPad keying={keying} />);+ const button = pad();++ fireEvent.keyDown(button, { key: ' ', code: 'Space' });+ fireEvent.keyDown(button, { key: ' ', code: 'Space', repeat: true });+ fireEvent.keyDown(button, { key: ' ', code: 'Space', repeat: true });++ expect(keying.beginPress).toHaveBeenCalledTimes(1);+ });++ it('ignores keys that are not a press', () => {+ const keying = makeKeying();+ render(<KeyPad keying={keying} />);++ fireEvent.keyDown(pad(), { key: 'a', code: 'KeyA' });++ expect(keying.beginPress).not.toHaveBeenCalled();+ });+});diff --git a/client/src/components/meatspace/post/PostCognitiveDrillRunner.jsx b/client/src/components/meatspace/post/PostCognitiveDrillRunner.jsxindex 1b1baedf2a..ae6a25094b 100644--- a/client/src/components/meatspace/post/PostCognitiveDrillRunner.jsx+++ b/client/src/components/meatspace/post/PostCognitiveDrillRunner.jsx@@ -4,7 +4,7 @@ import { DRILL_LABELS, nBackBalancedAccuracy, effectiveCognitiveDrillConfig, cogimport { safeReadJsonStorage, safeWriteStorage } from '../../../lib/safeStorage.js';import useMounted from '../../../hooks/useMounted';import useKeyCapture from '../../../hooks/useKeyCapture';-import { isPressKey } from '../../../lib/a11yKeyboard.js';+import { isPressKey, noPointerFocusProps } from '../../../lib/a11yKeyboard.js';import Modal from '../../ui/Modal';/**@@ -908,7 +908,7 @@ function NBackRunner({ drill, drillIndex, drillCount, onComplete, isTraining })<buttontype="button"- onClick={registerMatch}+ onClick={registerMatch} {...noPointerFocusProps}disabled={!active || pos < n}className="w-full px-6 py-4 bg-rose-500/20 hover:bg-rose-500/30 disabled:opacity-40 disabled:cursor-not-allowed text-rose-300 border border-rose-500/40 font-semibold rounded-lg transition-colors">@@ -1576,7 +1576,7 @@ function ReactionTimeRunner({ drill, drillIndex, drillCount, onComplete, isTrain{phase === 'waiting' && (<buttontype="button"- onClick={() => respond(0)}+ onClick={() => respond(0)} {...noPointerFocusProps}aria-label="Wait for the signal"className="w-32 h-32 rounded-full bg-port-border/30 text-gray-500 text-sm flex items-center justify-center">@@ -1587,7 +1587,7 @@ function ReactionTimeRunner({ drill, drillIndex, drillCount, onComplete, isTrain{phase === 'go' && mode === 'simple' && (<buttontype="button"- onClick={() => respond(0)}+ onClick={() => respond(0)} {...noPointerFocusProps}className="w-32 h-32 rounded-full bg-port-success/80 hover:bg-port-success text-white font-bold text-lg transition-colors">GO!@@ -1602,7 +1602,7 @@ function ReactionTimeRunner({ drill, drillIndex, drillCount, onComplete, isTrain<buttonkey={i}type="button"- onClick={() => respond(i)}+ onClick={() => respond(i)} {...noPointerFocusProps}className={`flex items-center justify-center gap-2 px-4 py-6 rounded-lg border font-semibold transition-colors ${isTarget? 'bg-port-success/80 hover:bg-port-success border-port-success text-white'@@ -1778,10 +1778,10 @@ function BinaryChoiceRunner({ type, drill, drillIndex, drillCount, onComplete, i</div><div className="grid grid-cols-2 gap-3">- <button type="button" onClick={() => recordRef.current('left')} disabled={phase !== 'stimulus'} className="px-5 py-4 rounded-lg border border-port-border bg-port-card hover:bg-port-bg disabled:opacity-40 text-white font-medium">+ <button type="button" onClick={() => recordRef.current('left')} {...noPointerFocusProps} disabled={phase !== 'stimulus'} className="px-5 py-4 rounded-lg border border-port-border bg-port-card hover:bg-port-bg disabled:opacity-40 text-white font-medium">← {leftLabel}</button>- <button type="button" onClick={() => recordRef.current('right')} disabled={phase !== 'stimulus'} className="px-5 py-4 rounded-lg border border-port-border bg-port-card hover:bg-port-bg disabled:opacity-40 text-white font-medium">+ <button type="button" onClick={() => recordRef.current('right')} {...noPointerFocusProps} disabled={phase !== 'stimulus'} className="px-5 py-4 rounded-lg border border-port-border bg-port-card hover:bg-port-bg disabled:opacity-40 text-white font-medium">{rightLabel} →</button></div>@@ -1895,7 +1895,7 @@ function GoNoGoRunner({ drill, drillIndex, drillCount, onComplete, isTraining })<buttontype="button"aria-label={symbolLabel}- onClick={() => recordRef.current(true)}+ onClick={() => recordRef.current(true)} {...noPointerFocusProps}disabled={!accepting}className="mx-auto w-48 h-48 rounded-2xl border border-port-border bg-port-card flex items-center justify-center disabled:opacity-70 motion-reduce:transition-none">diff --git a/client/src/components/meatspace/post/PostCognitiveDrillRunner.test.jsx b/client/src/components/meatspace/post/PostCognitiveDrillRunner.test.jsxindex e349ce0e53..64d3cc93d1 100644--- a/client/src/components/meatspace/post/PostCognitiveDrillRunner.test.jsx+++ b/client/src/components/meatspace/post/PostCognitiveDrillRunner.test.jsx@@ -1,5 +1,6 @@import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';import { render, screen, fireEvent, act, within } from '@testing-library/react';+import { installVoiceHotkeySpy } from '../../../test/voiceHotkeySpy';import PostCognitiveDrillRunner, {localAccuracyScore,localSchulteMetrics,@@ -919,19 +920,16 @@ describe('n-back tutorial card', () => {// key in the capture phase so the mic never opens mid-drill. Stand in for the// widget with a bubble-phase window listener and assert it stays silent.describe('Space-driven drills do not leak the key to the global voice hotkey', () => {- let voiceHotkey;+ const voiceHotkey = installVoiceHotkeySpy();beforeEach(() => {vi.useFakeTimers();- voiceHotkey = vi.fn();- window.addEventListener('keydown', voiceHotkey);markDrillTutorialSeen('n-back');markDrillTutorialSeen('go-no-go');markDrillTutorialSeen('reaction-time');});afterEach(() => {- window.removeEventListener('keydown', voiceHotkey);vi.useRealTimers();window.localStorage.clear();});@@ -946,7 +944,7 @@ describe('Space-driven drills do not leak the key to the global voice hotkey', (act(() => { fireEvent.keyDown(document.body, { code: 'Space', key: ' ' }); });act(() => { vi.advanceTimersByTime(1000); });- expect(voiceHotkey).not.toHaveBeenCalled();+ expect(voiceHotkey()).not.toHaveBeenCalled();expect(onComplete.mock.calls[0][0].questions).toEqual([expect.objectContaining({ index: 1, answered: 'match', correct: true }),]);@@ -965,7 +963,7 @@ describe('Space-driven drills do not leak the key to the global voice hotkey', (act(() => { fireEvent.keyDown(document.body, { code: 'Space', key: ' ' }); });act(() => { vi.advanceTimersByTime(250); });- expect(voiceHotkey).not.toHaveBeenCalled();+ expect(voiceHotkey()).not.toHaveBeenCalled();expect(onComplete.mock.calls[0][0].questions).toHaveLength(1);});@@ -979,7 +977,7 @@ describe('Space-driven drills do not leak the key to the global voice hotkey', (act(() => { fireEvent.keyDown(document.body, { code: 'Space', key: ' ' }); });act(() => { vi.advanceTimersByTime(500); });- expect(voiceHotkey).not.toHaveBeenCalled();+ expect(voiceHotkey()).not.toHaveBeenCalled();expect(onComplete.mock.calls[0][0].questions).toHaveLength(1);});@@ -994,21 +992,40 @@ describe('Space-driven drills do not leak the key to the global voice hotkey', (// Now in the 500ms result phase: a second press must NOT record anything,// and must NOT reach the voice hotkey either.act(() => { fireEvent.keyDown(document.body, { code: 'Space', key: ' ' }); });- expect(voiceHotkey).not.toHaveBeenCalled();+ expect(voiceHotkey()).not.toHaveBeenCalled();act(() => { vi.advanceTimersByTime(600); });act(() => { fireEvent.keyDown(document.body, { code: 'Space', key: ' ' }); });act(() => { vi.advanceTimersByTime(600); });- expect(voiceHotkey).not.toHaveBeenCalled();+ expect(voiceHotkey()).not.toHaveBeenCalled();expect(onComplete.mock.calls[0][0].questions).toHaveLength(2);});+ // Space on a focused button belongs to the browser (#4748), so a mouse click+ // that parked focus on the on-screen response button would take the drill's+ // key over — and native activation fires on keyUP, inflating a scored+ // reaction time. The buttons therefore refuse focus from a pointer press.+ // jsdom doesn't implement click-to-focus, so the cancelled mousedown (which+ // is what suppresses the focus in a real browser) is the observable here.+ it('refuses pointer focus on the on-screen Match button, so Space stays the scored path', () => {+ const drill = { type: 'n-back', config: { n: 1, stimulusMs: 1000 }, sequence: ['A', 'A'] };+ render(+ <PostCognitiveDrillRunner drill={drill} drillIndex={0} drillCount={1} onComplete={vi.fn()} isTraining={false} />,+ );+ act(() => { vi.advanceTimersByTime(1900); }); // into the 2nd stimulus, so Match is enabled+ const match = screen.getByRole('button', { name: 'Match' });+ expect(match).toBeEnabled();++ // fireEvent returns false when the event was canceled.+ expect(fireEvent.mouseDown(match)).toBe(false);+ });+it('lets an unrelated key through — this is not a blanket keyboard trap', () => {const drill = { type: 'n-back', config: { n: 1, stimulusMs: 1000 }, sequence: ['A', 'A'] };render(<PostCognitiveDrillRunner drill={drill} drillIndex={0} drillCount={1} onComplete={vi.fn()} isTraining={false} />,);act(() => { fireEvent.keyDown(document.body, { code: 'KeyJ', key: 'j' }); });- expect(voiceHotkey).toHaveBeenCalledTimes(1);+ expect(voiceHotkey()).toHaveBeenCalledTimes(1);});});diff --git a/client/src/components/openworld/OpenWorldHud.jsx b/client/src/components/openworld/OpenWorldHud.jsxindex 27fc7e8f97..a6ea1b536b 100644--- a/client/src/components/openworld/OpenWorldHud.jsx+++ b/client/src/components/openworld/OpenWorldHud.jsx@@ -1,6 +1,7 @@import { useState, useEffect, useMemo, useRef } from 'react';import { useNavigate, useLocation } from 'react-router';import { Camera, Compass, History, Map as MapIcon, Settings } from 'lucide-react';+import { noPointerFocusProps } from '../../lib/a11yKeyboard';import OpenWorldIntelPane from './OpenWorldIntelPane';import OpenWorldFocusPanel from './OpenWorldFocusPanel';import OpenWorldAgentBar from './OpenWorldAgentBar';@@ -59,11 +60,14 @@ function Crosshair() {);}+// The HUD floats over a keyboard-driven world: a pointer click must not leave+// focus parked on the button, or Space stops jumping and starts re-pressing it.function HudAction({ icon: Icon, label, hint, active, primary = false, onClick }) {return (<buttontype="button"onClick={onClick}+ {...noPointerFocusProps}title={label}aria-label={label}aria-pressed={active === undefined ? undefined : active}diff --git a/client/src/components/ui/Modal.jsx b/client/src/components/ui/Modal.jsxindex 33f9eb8b92..ea2ead5d97 100644--- a/client/src/components/ui/Modal.jsx+++ b/client/src/components/ui/Modal.jsx@@ -175,13 +175,16 @@ export default function Modal({panelClassName = '',ariaLabelledBy,ariaLabel,+ initialFocusRef,}) {const backdropRef = useRef(null);const dialogRef = useRef(null);// Trap keyboard focus inside the dialog while open, then restore it to the// element that opened the modal (WCAG 2.4.3 / 2.1.2). Runs for every Modal- // regardless of the Esc/backdrop opt-outs.- useFocusTrap(open, dialogRef);+ // regardless of the Esc/backdrop opt-outs. Focus otherwise lands on the first+ // focusable descendant — usually a header Close button, which is wrong for a+ // dialog whose own content owns the keyboard: pass `initialFocusRef` to aim it.+ useFocusTrap(open, dialogRef, { initialFocusRef });// `useId()` is React's render-safe stable id source — survives StrictMode's// double-invoke without allocating extra ids the way a `modalIdSeq++`// module-scope counter would.diff --git a/client/src/lib/README.md b/client/src/lib/README.mdindex 6234d3be9c..83c93eeb8e 100644--- a/client/src/lib/README.md+++ b/client/src/lib/README.md@@ -91,7 +91,7 @@ grep -i "what you want to do" client/src/lib/README.md| Module | Purpose ||---|---|-| `a11yKeyboard.js` | `clickableProps(handler, { role?, disabled? })` → `{ role, tabIndex, onKeyDown }` and `onActivateKeyDown(handler)` — make a non-`<button>` element with an `onClick` keyboard-accessible (Enter/Space activation, focusable, `role="button"`). Spread `clickableProps` next to the existing `onClick`. Use instead of hand-rolling `role`/`tabIndex`/`onKeyDown` on clickable `<div>`/`<span>`/`<li>`. Also the shared predicate every app-global key handler consults: `shouldIgnoreGlobalKey(event, { enabledInDialog?, ignoreRepeat?, allowChords? })` — the single "must this handler stand down?" answer (editable target, native Space button activation, ⌘/Ctrl/Alt chord, OS auto-repeat, open `aria-modal` dialog), used by `useKeyboardShortcuts`, `useKeyCapture` AND the voice widget's push-to-talk hotkey so their guard lists can't drift. Add a new guard there, not at one caller. Its parts are exported too: `isEditableTarget(el)`, `isButtonActivation(event)` (true when Space would natively activate the focused button) and `isPressKey(event)` (Enter or Space by either `key` or `code`). |+| `a11yKeyboard.js` | `clickableProps(handler, { role?, disabled? })` → `{ role, tabIndex, onKeyDown }` and `onActivateKeyDown(handler)` — make a non-`<button>` element with an `onClick` keyboard-accessible (Enter/Space activation, focusable, `role="button"`). Spread `clickableProps` next to the existing `onClick`. Use instead of hand-rolling `role`/`tabIndex`/`onKeyDown` on clickable `<div>`/`<span>`/`<li>`. Also the shared predicate every app-global key handler consults: `shouldIgnoreGlobalKey(event, { enabledInDialog?, ignoreRepeat?, allowChords? })` — the single "must this handler stand down?" answer (editable target, native Space button activation, ⌘/Ctrl/Alt chord, OS auto-repeat, open `aria-modal` dialog), used by `useKeyboardShortcuts`, `useKeyCapture` AND the voice widget's push-to-talk hotkey so their guard lists can't drift. Add a new guard there, not at one caller. Its parts are exported too: `isEditableTarget(el)`, `isButtonActivation(event)` (true when Space would natively activate the focused button) and `isPressKey(event)` (Enter or Space by either `key` or `code`). Plus `noPointerFocusProps` — spread on the buttons of a surface that owns a key globally (a Space-scored drill, the Morse keyer, the OpenWorld HUD), so a mouse click can't park focus there and take that key over via native button activation. || `appIdentity.js` | `PORTOS_APP_ID` — stable id of the baseline PortOS app (mirrors `server/lib/appIdentity.js`). Dependency-free so a module reachable from a node-env server test (e.g. `components/apps/constants.js`) can identify PortOS without importing `services/apiCore.js`, which pulls in React via `ui/Toast`. `apiCore.js` re-exports it, so `import { PORTOS_APP_ID } from '../services/api'` still works. || `applyManuscriptEdits.js` | `applyEditsToContent(content, edits, anchorQuote)` — PREVIEW-ONLY client mirror of the server's accept splice (`server/services/pipeline/manuscriptFix.js`): locate each `find` (nearest the anchor when recurring), drop overlaps, replace bottom-up. Powers the Manuscript editor's whole-manuscript impact preview. || `audioRecorder.js` | `startMemoRecording()` → `{ stream, stop, cancel }` handle whose `stop()` resolves to `{ audioBase64, mimeType, peak, durationMs }` (16 kHz mono WAV, base64); the live `stream` lets a tuner tap the same mic. `createStreamAnalyser(stream, { fftSize })` → `{ analyser, context, close }` taps an `AnalyserNode` off an existing stream (no second getUserMedia). Plus `blobToWav16k`, `encodePcmToWav`, `pickRecordingMimeType`, `arrayBufferToBase64`. Standalone one-shot memo capture for catalog voice ingest — NOT the live voice-agent recorder in `services/voiceClient.js`. |diff --git a/client/src/lib/a11yKeyboard.js b/client/src/lib/a11yKeyboard.jsindex ad1838647f..ea5471797c 100644--- a/client/src/lib/a11yKeyboard.js+++ b/client/src/lib/a11yKeyboard.js@@ -176,3 +176,21 @@ export function shouldIgnoreGlobalKey(event, { enabledInDialog = false, ignoreReif (!enabledInDialog && document.querySelector('[aria-modal="true"]')) return true;return false;}++/**+ * Props that stop a POINTER press from parking keyboard focus on a button.+ *+ * On a surface that owns a key globally — a drill scored on Space, the Morse+ * keyer, the OpenWorld rig — a button that keeps focus after a mouse click+ * silently takes that key over: `shouldIgnoreGlobalKey` correctly stands the+ * global handler down for native button activation, so the next Space presses+ * the lingering button instead of driving the surface. Spread this on the+ * buttons of such a surface.+ *+ * `preventDefault` on `mousedown` suppresses only the focus, not the click — and+ * only for pointer input, so a keyboard user who tabs to the button still+ * focuses and activates it normally.+ */+export const noPointerFocusProps = {+ onMouseDown: (event) => event.preventDefault(),+};diff --git a/client/src/lib/a11yKeyboard.test.js b/client/src/lib/a11yKeyboard.test.jsindex fca37b2845..ec88c8903a 100644--- a/client/src/lib/a11yKeyboard.test.js+++ b/client/src/lib/a11yKeyboard.test.js@@ -1,5 +1,5 @@import { describe, it, expect, vi, afterEach } from 'vitest';-import { onActivateKeyDown, clickableProps, isButtonActivation, isPressKey, isEditableTarget, shouldIgnoreGlobalKey } from './a11yKeyboard.js';+import { onActivateKeyDown, clickableProps, isButtonActivation, isPressKey, isEditableTarget, shouldIgnoreGlobalKey, noPointerFocusProps } from './a11yKeyboard.js';describe('onActivateKeyDown', () => {it('returns undefined when handler is not a function', () => {@@ -205,3 +205,23 @@ describe('shouldIgnoreGlobalKey', () => {expect(shouldIgnoreGlobalKey({ key: 'a', target: plainTarget }, { enabledInDialog: true })).toBe(false);});});++describe('noPointerFocusProps', () => {+ it('cancels the mousedown default, which is what would focus the button', () => {+ const button = document.createElement('button');+ document.body.appendChild(button);+ button.addEventListener('mousedown', noPointerFocusProps.onMouseDown);++ const event = new MouseEvent('mousedown', { bubbles: true, cancelable: true });+ button.dispatchEvent(event);++ expect(event.defaultPrevented).toBe(true);+ // Only focus is suppressed — the click still reaches the handler.+ const clicked = vi.fn();+ button.addEventListener('click', clicked);+ button.dispatchEvent(new MouseEvent('click', { bubbles: true }));+ expect(clicked).toHaveBeenCalledTimes(1);++ button.remove();+ });+});