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
refactor: route client localStorage and keyboard activation through shared helpers (#2527)
Adam Eivy9f487e6b9f10
diff --git a/client/src/components/IngredientPicker.jsx b/client/src/components/IngredientPicker.jsxindex 21d73fb8de..925deb6ae3 100644--- a/client/src/components/IngredientPicker.jsx+++ b/client/src/components/IngredientPicker.jsx@@ -25,6 +25,7 @@ import { Search, Plus, Loader2, X, Sparkles } from 'lucide-react';import Modal from './ui/Modal';import { listCatalogIngredients } from '../services/apiCatalog';import { CATALOG_BADGE_BY_ID, payloadSnippet } from '../lib/catalogTypes';+import { clickableProps } from '../lib/a11yKeyboard';// Type chip color comes from the shared registry. Snippet uses the registry's// per-type fallback chain at a slightly longer cap for the picker rows.@@ -222,8 +223,8 @@ export default function IngredientPicker({return (<li key={it.id}>{multi ? (- <div role="button" tabIndex={0} onClick={() => toggleSelected(it.id)}- onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); toggleSelected(it.id); } }}+ <div onClick={() => toggleSelected(it.id)}+ {...clickableProps(() => toggleSelected(it.id))}className={`${rowClass} cursor-pointer`}>{inner}</div>diff --git a/client/src/components/MortalLoomBanner.jsx b/client/src/components/MortalLoomBanner.jsxindex 4100c9e26f..ddcd088a7b 100644--- a/client/src/components/MortalLoomBanner.jsx+++ b/client/src/components/MortalLoomBanner.jsx@@ -1,6 +1,7 @@import { useState, useEffect } from 'react';import { Link } from 'react-router-dom';import { X, ExternalLink, Smartphone } from 'lucide-react';+import { safeReadStorage, safeWriteStorage } from '../lib/safeStorage';const APP_STORE_URL = 'https://apps.apple.com/app/id6760883701';const DISMISS_KEY = 'mortalloom-banner-dismissed-v1';@@ -9,12 +10,11 @@ export default function MortalLoomBanner({ section = 'this data' }) {const [dismissed, setDismissed] = useState(true);useEffect(() => {- const v = typeof window !== 'undefined' ? window.localStorage.getItem(DISMISS_KEY) : '1';- setDismissed(v === '1');+ setDismissed(safeReadStorage(DISMISS_KEY) === '1');}, []);const handleDismiss = () => {- window.localStorage.setItem(DISMISS_KEY, '1');+ safeWriteStorage(DISMISS_KEY, '1');setDismissed(true);};diff --git a/client/src/components/WhileAwayWidget.jsx b/client/src/components/WhileAwayWidget.jsxindex a210ee5673..063b3c503b 100644--- a/client/src/components/WhileAwayWidget.jsx+++ b/client/src/components/WhileAwayWidget.jsx@@ -12,6 +12,7 @@ import {import * as api from '../services/api';import socket from '../services/socket';import { timeAgo } from '../utils/formatters';+import { safeReadStorage, safeWriteStorage } from '../lib/safeStorage';// Per-device "last visit" marker. The widget shows agent activity that// completed since this timestamp; "Mark as seen" advances it to now. Kept in@@ -20,13 +21,10 @@ import { timeAgo } from '../utils/formatters';const LAST_SEEN_KEY = 'portos.whileAway.lastSeen';const readLastSeen = () => {- // localStorage access can throw in private-mode / storage-disabled /- // security-error contexts — never let that crash the dashboard render.- // Even *reading* the `window.localStorage` property can throw in some- // sandboxed iframes, so it's acquired inside the try (not before it).- let raw = null;- try { raw = window.localStorage.getItem(LAST_SEEN_KEY); }- catch { return null; }+ // safeReadStorage swallows the private-mode / storage-disabled / security-error+ // throws (including the property-access throw in sandboxed iframes) and returns+ // null so this never crashes the dashboard render.+ const raw = safeReadStorage(LAST_SEEN_KEY);// A finite, non-future ISO string is the only valid marker; anything else// (absent, garbage, clock-skewed) means "no marker" → server applies its// own 24h fallback so the card still renders.@@ -36,13 +34,10 @@ const readLastSeen = () => {return raw;};-const writeLastSeen = (iso) => {- // A write failure (quota / disabled / property-access throw) must not break- // "Mark as seen" — the subsequent refetch still runs; the window just isn't- // persisted this time.- try { window.localStorage.setItem(LAST_SEEN_KEY, iso); }- catch { /* private mode / quota — graceful no-op */ }-};+// A write failure (quota / disabled / property-access throw) is swallowed by+// safeWriteStorage — "Mark as seen" still refetches; the window just isn't+// persisted this time.+const writeLastSeen = (iso) => safeWriteStorage(LAST_SEEN_KEY, iso);function ActivityRow({ item, kind }) {const Icon = kind === 'incident' ? XCircle : CheckCircle;diff --git a/client/src/components/meatspace/tabs/GenomeTab.jsx b/client/src/components/meatspace/tabs/GenomeTab.jsxindex 05d38e8fa2..f5a9608826 100644--- a/client/src/components/meatspace/tabs/GenomeTab.jsx+++ b/client/src/components/meatspace/tabs/GenomeTab.jsx@@ -59,6 +59,7 @@ import { ATTACHMENT_MAX_FILE_SIZE } from '../../../utils/fileUpload';import GenomeCategoryCard from '../GenomeCategoryCard';import EpigeneticTracker from '../EpigeneticTracker';import ProvenanceChip from '../../ui/ProvenanceChip';+import { clickableProps } from '../../../lib/a11yKeyboard';const CATEGORY_META = {longevity: { emoji: '\u2728', label: 'Longevity', color: 'purple' },@@ -369,14 +370,7 @@ export default function GenomeTab() {onDragLeave={handleDragLeave}className="border-2 border-dashed border-port-border rounded-lg p-12 text-center transition-colors hover:border-gray-500 cursor-pointer focus:outline-none focus:border-port-accent"onClick={() => fileInputRef.current?.click()}- onKeyDown={(e) => {- if (e.key === 'Enter' || e.key === ' ') {- e.preventDefault();- fileInputRef.current?.click();- }- }}- role="button"- tabIndex={0}+ {...clickableProps(() => fileInputRef.current?.click())}aria-label="Upload your 23andMe raw data file — drag and drop or activate to browse">{uploading ? (diff --git a/client/src/components/pipeline/editorial/EditorialHealthPanel.jsx b/client/src/components/pipeline/editorial/EditorialHealthPanel.jsxindex a6e67057fe..c5f2ec7808 100644--- a/client/src/components/pipeline/editorial/EditorialHealthPanel.jsx+++ b/client/src/components/pipeline/editorial/EditorialHealthPanel.jsx@@ -35,6 +35,7 @@ import {READINESS_GATE_LABELS,READINESS_GATE_ORDER,} from '../../../lib/editorialHealth';+import { clickableProps } from '../../../lib/a11yKeyboard';const SEVERITY_DOT = { high: 'bg-rose-400', medium: 'bg-amber-400', low: 'bg-gray-400' };@@ -80,12 +81,10 @@ function Sparkline({ points, selectedIndex = null, onSelect }) {cx={c.x}cy={c.y}r={active ? 3.5 : isLast ? 2.5 : 2}- role="button"- tabIndex={0}+ {...clickableProps(select)}aria-pressed={active}aria-label={`Revision ${i + 1} of ${coords.length}, score ${c.score}${active ? ' (selected)' : ''}`}onClick={select}- onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); select(); } }}className={`cursor-pointer outline-none transition-all ${active ? 'fill-port-warning' : isLast ? 'fill-port-accent' : 'fill-port-accent/50 hover:fill-port-accent'}`}><title>{`Revision ${i + 1} · score ${c.score}`}</title>diff --git a/client/src/components/pipeline/manuscript/ManuscriptReadAloud.jsx b/client/src/components/pipeline/manuscript/ManuscriptReadAloud.jsxindex 4c46b5afa4..f0013a0f86 100644--- a/client/src/components/pipeline/manuscript/ManuscriptReadAloud.jsx+++ b/client/src/components/pipeline/manuscript/ManuscriptReadAloud.jsx@@ -25,12 +25,11 @@ import toast from '../../ui/Toast';import { formatDurationMs } from '../../../utils/formatters';import { narratePipelineProse } from '../../../services/api';import { STAGE_LABEL } from './constants';+import { clickableProps } from '../../../lib/a11yKeyboard';+import { safeReadStorage, safeWriteStorage } from '../../../lib/safeStorage';const NARRATOR_VOICE_KEY = 'portos.manuscript.narratorVoice';-const initialVoice = () => {- if (typeof window === 'undefined') return '';- return window.localStorage.getItem(NARRATOR_VOICE_KEY) || '';-};+const initialVoice = () => safeReadStorage(NARRATOR_VOICE_KEY) || '';export default function ManuscriptReadAloud({ open, onClose, section }) {const content = section?.content || '';@@ -181,7 +180,7 @@ export default function ManuscriptReadAloud({ open, onClose, section }) {const changeVoice = (next) => {setVoiceId(next);- if (typeof window !== 'undefined') window.localStorage.setItem(NARRATOR_VOICE_KEY, next || '');+ safeWriteStorage(NARRATOR_VOICE_KEY, next || '');// Cached segments were synthesized with the prior voice — invalidate so the// next play re-synthesizes with the new narrator.resetNarration();@@ -203,10 +202,8 @@ export default function ManuscriptReadAloud({ open, onClose, section }) {nodes.push(<spankey={`seg-${seg.index}`}- role="button"- tabIndex={0}+ {...clickableProps(() => jumpTo(seg.index))}onClick={() => jumpTo(seg.index)}- onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); jumpTo(seg.index); } }}title={hard ? `Hard to say: ${reasons.join('; ')}` : undefined}className={['cursor-pointer rounded transition-colors',diff --git a/client/src/components/tribe/TribeCircleMap.jsx b/client/src/components/tribe/TribeCircleMap.jsxindex 8c5f09e6d1..9ca2d158ff 100644--- a/client/src/components/tribe/TribeCircleMap.jsx+++ b/client/src/components/tribe/TribeCircleMap.jsx@@ -1,6 +1,7 @@import { useMemo, useState } from 'react';import { RINGS, TRIBE_RINGS, ENERGY, STATUS_HEX, contactStatus, energyFor, initialsFor } from '../../lib/tribe.js';+import { clickableProps } from '../../lib/a11yKeyboard';// Concentric-circles map of the Tribe: "Me" at the center, each Dunbar ring is a// tinted band (support innermost → village outermost) and every person is a node@@ -243,12 +244,8 @@ export default function TribeCircleMap({ contacts, selectedId, onSelect, onLogToonMouseLeave={() => setHovered((cur) => (cur === contact.id ? null : cur))}onFocus={() => { setHovered(contact.id); setActiveId(contact.id); }}onBlur={() => setHovered((cur) => (cur === contact.id ? null : cur))}- tabIndex={0}- role="button"+ {...clickableProps(() => onSelect?.(contact))}aria-label={`${contact.name || 'Unnamed'} — ${ringLabel}, ${status.label}`}- onKeyDown={(e) => {- if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); onSelect?.(contact); }- }}>{isSelected && (<circle r={r + 5} fill="none" stroke="#3b82f6" strokeWidth="2" strokeOpacity="0.9" />diff --git a/client/src/pages/PipelineManuscriptEditor.jsx b/client/src/pages/PipelineManuscriptEditor.jsxindex 547048d913..b90e6c071f 100644--- a/client/src/pages/PipelineManuscriptEditor.jsx+++ b/client/src/pages/PipelineManuscriptEditor.jsx@@ -39,6 +39,7 @@ import { usePipelineProgress } from '../hooks/usePipelineProgress';import { filterGenerationModels, mergeModelLists, localBackendForProvider, modelOptionLabel } from '../utils/providers';import useLocalModels from '../hooks/useLocalModels';import { locateAnchors } from '../lib/manuscriptAnchors';+import { safeReadStorage, safeWriteStorage } from '../lib/safeStorage';import ManuscriptLiveSection from '../components/pipeline/manuscript/ManuscriptLiveSection';import AnnotatedManuscriptSection from '../components/pipeline/manuscript/AnnotatedManuscriptSection';import ManuscriptCommentIndex from '../components/pipeline/manuscript/ManuscriptCommentIndex';@@ -59,10 +60,7 @@ import {const EMPTY = [];const VIEW_MODE_KEY = 'portos.manuscript.viewMode';-const initialViewMode = () => {- if (typeof window === 'undefined') return 'live';- return window.localStorage.getItem(VIEW_MODE_KEY) === 'review' ? 'review' : 'live';-};+const initialViewMode = () => (safeReadStorage(VIEW_MODE_KEY) === 'review' ? 'review' : 'live');export default function PipelineManuscriptEditor() {const params = useParams();@@ -130,7 +128,7 @@ export default function PipelineManuscriptEditor() {const liveContentFor = (issueId) => liveSectionsRef.current.find((s) => s.issueId === issueId)?.content ?? '';useEffect(() => {- if (typeof window !== 'undefined') window.localStorage.setItem(VIEW_MODE_KEY, viewMode);+ safeWriteStorage(VIEW_MODE_KEY, viewMode);}, [viewMode]);useEffect(() => {diff --git a/client/src/pages/Security.jsx b/client/src/pages/Security.jsxindex 158777f7a2..05dd6391eb 100644--- a/client/src/pages/Security.jsx+++ b/client/src/pages/Security.jsx@@ -3,6 +3,7 @@ import { Camera, Mic, MicOff, Video, VideoOff, RefreshCw, Settings, Volume2 } frimport api from '../services/api';import Banner from '../components/ui/Banner';import { FormField } from '../components/ui/FormField';+import { safeReadStorage, safeReadJsonStorage, safeWriteStorage, safeRemoveStorage } from '../lib/safeStorage';const MEDIA_CONSTRAINTS_KEY = 'portos-media-constraints';@@ -27,22 +28,21 @@ export default function Security() {// Load saved device preferencesuseEffect(() => {- const saved = localStorage.getItem(MEDIA_CONSTRAINTS_KEY);- if (saved) {- try {- const { videoDeviceId, audioDeviceId } = JSON.parse(saved);- if (videoDeviceId) setSelectedVideo(videoDeviceId);- if (audioDeviceId) setSelectedAudio(audioDeviceId);- } catch {- localStorage.removeItem(MEDIA_CONSTRAINTS_KEY);- }+ const saved = safeReadJsonStorage(MEDIA_CONSTRAINTS_KEY);+ if (saved && typeof saved === 'object') {+ const { videoDeviceId, audioDeviceId } = saved;+ if (videoDeviceId) setSelectedVideo(videoDeviceId);+ if (audioDeviceId) setSelectedAudio(audioDeviceId);+ } else if (safeReadStorage(MEDIA_CONSTRAINTS_KEY) !== null) {+ // Corrupt/unparseable entry — clear it so it stops failing on every load.+ safeRemoveStorage(MEDIA_CONSTRAINTS_KEY);}}, []);// Save device preferences when they changeuseEffect(() => {if (selectedVideo || selectedAudio) {- localStorage.setItem(MEDIA_CONSTRAINTS_KEY, JSON.stringify({+ safeWriteStorage(MEDIA_CONSTRAINTS_KEY, JSON.stringify({videoDeviceId: selectedVideo,audioDeviceId: selectedAudio}));diff --git a/client/src/services/voiceVisibility.js b/client/src/services/voiceVisibility.jsindex 0462563859..515ccfa923 100644--- a/client/src/services/voiceVisibility.js+++ b/client/src/services/voiceVisibility.js@@ -1,3 +1,5 @@+import { safeReadStorage, safeWriteStorage } from '../lib/safeStorage';+export const HIDDEN_KEY = 'portos.voice.hidden';export const VISIBILITY_EVENT = 'portos:voice:visibility';export const ENGAGE_EVENT = 'portos:voice:engage';@@ -5,15 +7,11 @@ export const DISENGAGE_EVENT = 'portos:voice:disengage';// Sentinel '0' = explicitly engaged. Anything else (including key absent)// means hidden — keeps legacy users hidden by default after the flip.-export const readVoiceHidden = () => {- if (typeof window === 'undefined') return true;- return window.localStorage.getItem(HIDDEN_KEY) !== '0';-};+export const readVoiceHidden = () => safeReadStorage(HIDDEN_KEY) !== '0';export const writeVoiceHidden = (hidden) => {- if (typeof window === 'undefined') return;- window.localStorage.setItem(HIDDEN_KEY, hidden ? '1' : '0');- window.dispatchEvent(new Event(VISIBILITY_EVENT));+ safeWriteStorage(HIDDEN_KEY, hidden ? '1' : '0');+ if (typeof window !== 'undefined') window.dispatchEvent(new Event(VISIBILITY_EVENT));};// Storage events fire for every localStorage write in any tab; gate to our key