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: make terminal fullscreen a focus-trapped dialog with Escape exit and focus return (#9120)
[._.]/ Adam Eivy7649f31f25ed
diff --git a/client/src/components/shell/ItermShellView.jsx b/client/src/components/shell/ItermShellView.jsxindex 95b1e4947c..993142336a 100644--- a/client/src/components/shell/ItermShellView.jsx+++ b/client/src/components/shell/ItermShellView.jsx@@ -5,6 +5,7 @@ import * as api from '../../services/api';import { readClipboard } from '../../lib/clipboard';import { useInstanceFeatures } from '../../hooks/useInstanceFeatures.js';import { useItermSession } from '../../hooks/useItermSession';+import useTerminalFullscreen from '../../hooks/useTerminalFullscreen';import TerminalHotKeys from './TerminalHotKeys';import ShellSourceSwitch from './ShellSourceSwitch';import ItermSessionTabs, { itermLocation } from './ItermSessionTabs';@@ -26,6 +27,7 @@ export default function ItermShellView() {const [showPasteInput, setShowPasteInput] = useState(false);const [fetchedStatus, setFetchedStatus] = useState(null);const pasteInputRef = useRef(null);+ const { containerRef, toggleRef } = useTerminalFullscreen(isFullscreen, () => setIsFullscreen(false));const {terminalRef, sessions, listed, status, activeSession, connected,@@ -83,7 +85,11 @@ export default function ItermShellView() {const geometry = activeSession ? `${activeSession.cols}×${activeSession.rows} · sized by iTerm` : null;return (- <div className={isFullscreen+ <div ref={containerRef}+ role={isFullscreen ? 'dialog' : undefined}+ aria-modal={isFullscreen ? 'true' : undefined}+ aria-label={isFullscreen ? 'Terminal fullscreen view' : undefined}+ className={isFullscreen? 'fixed inset-0 z-[70] flex flex-col bg-port-bg p-2': 'h-full flex flex-col gap-2 md:gap-3 p-2 md:p-6'}>{!isFullscreen && (@@ -99,6 +105,7 @@ export default function ItermShellView() {)}<buttononClick={() => setIsFullscreen(true)}+ ref={toggleRef}className="ml-auto flex items-center gap-1.5 px-2.5 py-2 bg-port-card hover:bg-port-border text-gray-300 hover:text-white rounded-lg text-sm transition-colors border border-port-border min-h-[40px] shrink-0"title="Fullscreen terminal"aria-label="Fullscreen terminal"diff --git a/client/src/components/shell/ItermShellView.test.jsx b/client/src/components/shell/ItermShellView.test.jsxindex 6316ffc333..c1700c23ed 100644--- a/client/src/components/shell/ItermShellView.test.jsx+++ b/client/src/components/shell/ItermShellView.test.jsx@@ -108,6 +108,24 @@ describe('ItermShellView', () => {expect(screen.getByRole('link', { name: /Back to PortOS shells/ }).getAttribute('href')).toBe('/shell');});+ it('fullscreen is a modal dialog: focus moves in, Escape exits, focus returns to the toggle', () => {+ state.hook = hookState();+ renderAt('/shell/iterm', <ItermShellView />);+ expect(screen.queryByRole('dialog')).toBeNull();+ const toggle = screen.getByRole('button', { name: 'Fullscreen terminal' });+ toggle.focus();+ fireEvent.click(toggle);+ const dialog = screen.getByRole('dialog', { name: 'Terminal fullscreen view' });+ expect(dialog.getAttribute('aria-modal')).toBe('true');+ expect(dialog.contains(document.activeElement)).toBe(true);+ // Escape typed inside the terminal belongs to the program running there.+ fireEvent.keyDown(screen.getByTestId('iterm-terminal'), { key: 'Escape' });+ expect(screen.getByRole('dialog')).toBeTruthy();+ fireEvent.keyDown(screen.getByRole('button', { name: 'Exit fullscreen' }), { key: 'Escape' });+ expect(screen.queryByRole('dialog')).toBeNull();+ expect(document.activeElement).toBe(screen.getByRole('button', { name: 'Fullscreen terminal' }));+ });+it('names the fix for each status', () => {expect(itermHintText({ state: 'api-disabled' })).toMatch(/Enable Python API/);expect(itermHintText({ state: 'not-running' })).toMatch(/isn’t running/);diff --git a/client/src/hooks/README.md b/client/src/hooks/README.mdindex 6f8574b59d..41f11ee162 100644--- a/client/src/hooks/README.md+++ b/client/src/hooks/README.md@@ -203,6 +203,7 @@ grep -i "what you want to do" client/src/hooks/README.md| `useLocalModels` | Live installed Ollama/LM Studio model ids per backend, runtime capability badges, the server's editorial recommendation, and `installed` per backend (`null` until fetched) — the app-level verdict that counts a macOS bundle with no CLI shim. | Model pickers that must show currently-installed local models (not just a provider's stale stored `models`), or explain a selected model's live capabilities. Fold in via `mergeModelLists` + `localBackendForProvider`. || `useVisionModelIds` | `{ idsByProvider, loaded }` — vision-capable model ids the server reports (Ollama `/api/show` + LM Studio `type:'vlm'`), keyed by the provider id that serves them (`{ ollama: Set, lmstudio: Set }`), `null` until fetched; `loaded` flips once the fetch settles. Drops `backend:'cli'` rows (a blanket per-provider claim, not a per-model fact) and never vouches for a provider the server didn't enumerate. | Any VISION model picker — pass `idsByProvider` to `visionLocalModelFilter` / `assignmentModelOptions` so a new multimodal family (`gemma4`) isn't hidden by the stale client id regex, and so an installed VLM shows even when the provider's stored `models` snapshot is stale; gate any "none installed" messaging on `loaded` and on the provider being a local backend. || `useToolUseModelIds` | `{ idsByProvider, loaded }` — TOOL-USE (function-calling) capable model ids the server reports (Ollama `/api/show` `tools` capability + LM Studio catalog capabilities) via `/api/local-llm/tool-use-models`, keyed by the provider id that serves them (`{ ollama: Set, lmstudio: Set }`), `null` until fetched; `loaded` flips once the fetch settles. One module-shared fetch across every mounted caller, retried on a later mount if it failed. | Any AGENT model picker — pass `idsByProvider` to `localToolUseHint` / `withToolUseOptionLabel` so a tool-capable family the client id regex predates (`phi4-mini`) isn't mislabelled "⚠ no known tool use", and gate the annotation on `loaded` so the warning isn't asserted mid-fetch. |+| `useTerminalFullscreen` | `useTerminalFullscreen(isFullscreen, exitFullscreen)` → `{ containerRef, toggleRef }` — focus trap + Escape-to-exit (ignored while typing inside the terminal) + focus return to the toggle button (unmounted while fullscreen, so `useFocusTrap`'s own restore misses it). | The Shell and iTerm fullscreen overlays; any terminal-style surface that swaps its own trigger out when maximized. || `useTheme` | Dark/light theme + paired-theme switching. | Theme picker. || `useThreejsModelFamilies` | Three.js subject-family checklist options served by `/api/threejs-models/families`; `[]` when the fetch fails, plus the exported `GENERAL_FAMILY_ID` default. | Any surface picking a subject family — the taxonomy is served, never mirrored client-side, so the picker and the generation prompt cannot drift. Hide the picker on an empty list rather than rendering an empty select. || `useSingToScore` | Capture a sung melody from the mic and transcribe it into lead-sheet notation. `start()` opens the mic, counts in on the shared metronome, then accumulates a pitch track relative to beat 1; `stop()` runs the `transcribePitchTrack` pipeline (segment → quantize at the song tempo → spell for the key) and returns the lead-sheet body. Exposes `{ phase, beat, result, error, start, stop, reset }`; tears down mic/analyser/tracker/metronome on stop and unmount. | The Song editor's Sing-to-score panel. |diff --git a/client/src/hooks/index.js b/client/src/hooks/index.jsindex 04efb8e097..7fc3d235b9 100644--- a/client/src/hooks/index.js+++ b/client/src/hooks/index.js@@ -95,6 +95,7 @@ export { default as useRunWithPicker } from './useRunWithPicker.js';export * from './useRecentImageGallery.js';export { default as useReviewerModelOptions } from './useReviewerModelOptions.js';export { default as useRowDraft } from './useRowDraft.js';+export { default as useTerminalFullscreen } from './useTerminalFullscreen.js';export { default as useTheme } from './useTheme.js';export { default as useThreejsModelFamilies } from './useThreejsModelFamilies.js';export { default as useUniverse } from './useUniverse.js';diff --git a/client/src/hooks/useTerminalFullscreen.js b/client/src/hooks/useTerminalFullscreen.jsnew file mode 100644index 0000000000..26fa44f595--- /dev/null+++ b/client/src/hooks/useTerminalFullscreen.js@@ -0,0 +1,39 @@+import { useEffect, useRef } from 'react';+import useFocusTrap from './useFocusTrap.js';++// Modal behavior for the Shell / iTerm fullscreen overlay: focus moves in and+// is trapped while `isFullscreen`, Escape exits, and focus returns to the+// fullscreen toggle on exit. The toggle is unmounted while fullscreen (the+// header is hidden), so useFocusTrap's own restore hits a detached node —+// `toggleRef` is re-attached on exit and focused here instead.+//+// Escape typed INSIDE the terminal is left alone: xterm forwards it to the+// program (vim, TUIs), and exiting fullscreen on every such keypress would+// break them. Shift+Tab leaves the terminal, after which Escape exits.+export default function useTerminalFullscreen(isFullscreen, exitFullscreen) {+ const containerRef = useRef(null);+ const toggleRef = useRef(null);+ const wasFullscreen = useRef(false);++ useFocusTrap(isFullscreen, containerRef);+ const exitRef = useRef(exitFullscreen);+ exitRef.current = exitFullscreen;+ // Own listener rather than useEscapeKey: that hook drops the event, and the+ // target decides whether this Escape is ours.+ useEffect(() => {+ if (!isFullscreen) return undefined;+ const onKey = (e) => {+ if (e.key !== 'Escape' || e.target?.closest?.('.xterm, [data-testid="iterm-terminal"]')) return;+ exitRef.current();+ };+ window.addEventListener('keydown', onKey);+ return () => window.removeEventListener('keydown', onKey);+ }, [isFullscreen]);++ useEffect(() => {+ if (wasFullscreen.current && !isFullscreen) toggleRef.current?.focus();+ wasFullscreen.current = isFullscreen;+ }, [isFullscreen]);++ return { containerRef, toggleRef };+}diff --git a/client/src/pages/Shell.jsx b/client/src/pages/Shell.jsxindex 6682f193ed..b054a31a68 100644--- a/client/src/pages/Shell.jsx+++ b/client/src/pages/Shell.jsx@@ -4,6 +4,7 @@ import * as api from '../services/api';import { readClipboard } from '../lib/clipboard';import useClickOutside from '../hooks/useClickOutside';import useEscapeKey from '../hooks/useEscapeKey';+import useTerminalFullscreen from '../hooks/useTerminalFullscreen';import { useShellSession, MAX_SESSIONS } from '../hooks/useShellSession';import TerminalHotKeys from '../components/shell/TerminalHotKeys';import ShellSessionTabs from '../components/shell/ShellSessionTabs';@@ -131,10 +132,16 @@ function PortosShellView() {showPasteInput, setShowPasteInput, pasteInputRef, handlePasteInputEvent, sendImage,};+ const { containerRef, toggleRef } = useTerminalFullscreen(isFullscreen, () => setIsFullscreen(false));+const statusLabel = connected ? 'Connected' : 'Disconnected';return (- <div className={isFullscreen+ <div ref={containerRef}+ role={isFullscreen ? 'dialog' : undefined}+ aria-modal={isFullscreen ? 'true' : undefined}+ aria-label={isFullscreen ? 'Terminal fullscreen view' : undefined}+ className={isFullscreen? 'fixed inset-0 z-[70] flex flex-col bg-port-bg p-2'// Deliberately tighter than the app-wide `p-4 md:p-6` mobile gutter: every// pixel here is a terminal row/column, and the chrome above it is already@@ -185,6 +192,7 @@ function PortosShellView() {<div className="flex items-center gap-2 ml-auto shrink-0"><buttononClick={() => setIsFullscreen(true)}+ ref={toggleRef}className="flex items-center gap-1.5 px-2.5 py-2 bg-port-card hover:bg-port-border text-gray-300 hover:text-white rounded-lg text-sm transition-colors border border-port-border min-h-[40px]"title="Fullscreen terminal"aria-label="Fullscreen terminal"