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
address review (claude, codex): guard Element Flash Enter listener against focused controls/overlays
[._.]/ Adam Eivy0c47174913a5
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 728a2d73e5..68a29cdcd2 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -123,4 +123,4 @@- **[issue-2654] Lift the CoS actionable-insights fetch into `ChiefOfStaff.fetchData` so the banner refreshes for the whole staleness class.** `ActionableInsightsBanner` owned its own `/cos/actionable-insights` fetch on a 60s `useAutoRefetch` poll, decoupled from the parent's 30s task poll, so its server-derived counts (blocked, approvals, "N health issues") lagged any parent-owned data change until that poll. A prior fix bridged only the TasksTab mutation path via an `insightsRefreshKey` counter; socket-driven task changes, agent spawn/completion, and health checks stayed stale. Insights are now fetched inside `ChiefOfStaff.fetchData`'s `Promise.all` and passed down as an `insights` prop, making the banner presentational (it keeps only dismiss/expand/unblock UI state); its unblock path calls `onRefresh` up instead of owning a `refetch()`. The banner's counts refresh **only** through `fetchData`: the 30s poll, task mutations (TasksTab `onRefresh`), the unblock-up path, and agent spawn/completion (which already call `fetchData`). There is deliberately no on-demand "refresh just the insights" path, because `/cos/actionable-insights` runs a health check that **auto-restarts errored PM2 processes** (`server/services/cosHealthMonitor.js`) and re-emits `cos:health:check` — so refreshing from the `cos:health:check` socket handler would loop, and refreshing from the manual "Run Check" button would fire a second process-restart ~1s after the button's own check. Daemon/manual health changes therefore refresh the banner on the next `fetchData` poll (a 2× improvement over the retired 60s self-poll, and the cadence skew is gone). A failed/transient insights fetch (`null`) preserves the last-good array; a legitimately-empty `[]` clears the banner. Because that same insights call triggers a fresh server health check whose `cos:health:check` socket emit can land before `fetchData`'s own (pre-check) `getCosHealth` read resolves, `fetchData` keeps whichever health check is newer by `lastCheck` (`Date.parse`-normalized), and preserves the last-good health when its own read fails — instead of blanking a fresher socket-delivered result. Retires `insightsRefreshKey`, `refreshTasks`'s signal bump, the banner's `refreshKey` prop, its `didMountRef` skip-mount effect, and its `useAutoRefetch` self-poll. Tests cover the prop-driven render, null/empty gating, the unblock-up path, guards asserting neither the `cos:health:check` socket handler nor the manual button re-fetches insights (no loop, no second restart), and the stale/failed-read health-overwrite guards.-- **Fix Element Flash: pressing Enter/Return after answering now advances to the next question.** In the Element Flash recall test (`ElementsSong.jsx`), the Enter-to-submit handler lived only on the answer `<input>`, which unmounts once the result is shown — so a second Enter did nothing and the user had to click "Next" to continue. `ElementFlashMode` now binds a window `keydown` listener while a result is showing (input unmounted) that advances on Enter/Return, mirroring the "Next" button; the `next()` handler was hoisted above the completion early-return so the effect can reference it without breaking hook order. A new test drives answer → Enter (submit) → Enter (advance) and asserts the question counter increments.+- **Fix Element Flash: pressing Enter/Return after answering now advances to the next question.** In the Element Flash recall test (`ElementsSong.jsx`), the Enter-to-submit handler lived only on the answer `<input>`, which unmounts once the result is shown — so a second Enter did nothing and the user had to click "Next" to continue. `ElementFlashMode` now binds a window `keydown` listener while a result is showing (input unmounted) that advances on Enter/Return, mirroring the "Next" button; the `next()` handler was hoisted above the completion early-return so the effect can reference it without breaking hook order. The listener ignores auto-repeat (`e.repeat`) and any Enter that a focused control or open overlay already owns (`e.target.closest('button, a, input, textarea, select, [role="dialog"], [role="menu"], [contenteditable]')`) — so a keyboard user tabbed to the Back/Next button doesn't double-advance, and an Enter meant for the command palette doesn't leak through to the quiz. Tests drive answer → Enter (submit) → Enter (advance) asserting the counter increments, and pin that an Enter fired from the focused Next button is not hijacked by the window listener.diff --git a/client/src/components/meatspace/post/ElementsSong.jsx b/client/src/components/meatspace/post/ElementsSong.jsxindex 5fb43668a7..057e04765e 100644--- a/client/src/components/meatspace/post/ElementsSong.jsx+++ b/client/src/components/meatspace/post/ElementsSong.jsx@@ -746,7 +746,15 @@ function ElementFlashMode({ item, mastery, onBack, onComplete }) {useEffect(() => {if (!showResult) return undefined;const onKeyDown = (e) => {- if (e.key === 'Enter') { e.preventDefault(); next(); }+ if (e.key !== 'Enter' || e.repeat) return;+ // Don't hijack Enter that a focused control (the Back/Next buttons fire+ // their own activation) or an open overlay/dialog (e.g. the command+ // palette) already owns — otherwise a focused Next button double-advances+ // and an Enter meant for the overlay leaks through to the quiz. Only act+ // when no interactive element owns the keystroke (focus is on the body).+ if (e.target?.closest?.('button, a, input, textarea, select, [role="dialog"], [role="menu"], [contenteditable="true"]')) return;+ e.preventDefault();+ next();};window.addEventListener('keydown', onKeyDown);return () => window.removeEventListener('keydown', onKeyDown);diff --git a/client/src/components/meatspace/post/ElementsSong.test.jsx b/client/src/components/meatspace/post/ElementsSong.test.jsxindex b9caacffe0..1c8cc6766d 100644--- a/client/src/components/meatspace/post/ElementsSong.test.jsx+++ b/client/src/components/meatspace/post/ElementsSong.test.jsx@@ -109,4 +109,32 @@ describe('ElementsSong — Element Flash recall test', () => {expect(screen.getByText('2 / 2')).toBeInTheDocument();expect(screen.getByRole('textbox')).toBeInTheDocument();});++ it('does not hijack Enter fired from a focused button (no double-advance)', async () => {+ render(<ElementsSong item={item} onBack={() => {}} />);+ await settle();++ fireEvent.click(screen.getByText('Element Flash'));+ await settle();+ expect(screen.getByText('1 / 2')).toBeInTheDocument();++ const input = screen.getByRole('textbox');+ fireEvent.change(input, { target: { value: 'x' } });+ fireEvent.keyDown(input, { key: 'Enter' });+ await settle();++ // Enter originating from the focused Next button must be ignored by the+ // window listener — the button's own activation is the single advance, so+ // the window listener firing too would skip a question. (RTL keyDown does+ // not trigger the native click, so the guard working = no advance here.)+ const nextBtn = screen.getByText('Next');+ fireEvent.keyDown(nextBtn, { key: 'Enter' });+ await settle();+ expect(screen.getByText('1 / 2')).toBeInTheDocument();++ // A genuine click on Next still advances exactly once.+ fireEvent.click(nextBtn);+ await settle();+ expect(screen.getByText('2 / 2')).toBeInTheDocument();+ });});