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([issue-712]): address claude+codex review
Adam Eivy07ac65c5e680
diff --git a/client/src/components/mobile/MobileApproveFlow.jsx b/client/src/components/mobile/MobileApproveFlow.jsxindex 4eb75eee77..147f25c3a6 100644--- a/client/src/components/mobile/MobileApproveFlow.jsx+++ b/client/src/components/mobile/MobileApproveFlow.jsx@@ -1,5 +1,5 @@import { useState } from 'react';-import { Check, X, Inbox } from 'lucide-react';+import { Check, X, Inbox, AlertTriangle } from 'lucide-react';import * as api from '../../services/api';import toast from '../ui/Toast';import BrailleSpinner from '../BrailleSpinner';@@ -12,12 +12,10 @@ export default function MobileApproveFlow() {const { data, loading, refetch } = useAutoRefetch(() => api.getCosTasks({ silent: true }), 20_000);const [busyId, setBusyId] = useState(null);- // GET /api/cos/tasks returns { user, cos } — awaiting-approval lives on cos.- const awaiting = data?.cos?.awaitingApproval || [];-const approve = async (task) => {setBusyId(task.id);- const result = await api.approveCosTask(task.id).catch((err) => {+ // silent: this flow owns the error toast in the catch below.+ const result = await api.approveCosTask(task.id, { silent: true }).catch((err) => {toast.error(`Approve failed: ${err.message}`);return null;});@@ -32,7 +30,8 @@ export default function MobileApproveFlow() {const reject = async (task) => {setBusyId(task.id);- const result = await api.deleteCosTask(task.id, 'internal').catch((err) => {+ // silent: this flow owns the error toast in the catch below.+ const result = await api.deleteCosTask(task.id, 'internal', { silent: true }).catch((err) => {toast.error(`Reject failed: ${err.message}`);return null;});@@ -46,6 +45,21 @@ export default function MobileApproveFlow() {return <div className="flex justify-center py-12"><BrailleSpinner text="Loading approvals" /></div>;}+ // useAutoRefetch preserves the last good snapshot on error, so a null `data`+ // after the initial load means the fetch never succeeded — distinguish that+ // from a genuinely-empty queue so a failed fetch doesn't read as "all clear".+ if (!data) {+ return (+ <div className="flex flex-col items-center gap-2 py-12 text-center text-gray-500">+ <AlertTriangle size={40} aria-hidden="true" />+ <p className="text-base">Approvals are unavailable right now.</p>+ </div>+ );+ }++ // GET /api/cos/tasks returns { user, cos } — awaiting-approval lives on cos.+ const awaiting = data.cos?.awaitingApproval || [];+if (awaiting.length === 0) {return (<div className="flex flex-col items-center gap-2 py-12 text-center text-gray-500">diff --git a/client/src/components/mobile/MobileAskFlow.jsx b/client/src/components/mobile/MobileAskFlow.jsxindex 5960f29a95..fc270b8156 100644--- a/client/src/components/mobile/MobileAskFlow.jsx+++ b/client/src/components/mobile/MobileAskFlow.jsx@@ -14,9 +14,10 @@ export default function MobileAskFlow() {const [answer, setAnswer] = useState('');const [streaming, setStreaming] = useState(false);const controllerRef = useRef(null);+ const mountedRef = useRef(true);// Abort any in-flight stream when the flow unmounts (back to hub / nav away).- useEffect(() => () => controllerRef.current?.abort(), []);+ useEffect(() => () => { mountedRef.current = false; controllerRef.current?.abort(); }, []);const ask = useCallback(async (q) => {const trimmed = (q ?? question).trim();@@ -44,7 +45,8 @@ export default function MobileAskFlow() {).catch((err) => {if (err.name !== 'AbortError') toast.error(err.message || 'Ask failed');});- setStreaming(false);+ // Skip the state write if the flow unmounted mid-stream.+ if (mountedRef.current) setStreaming(false);}, [question, streaming]);return (diff --git a/client/src/components/mobile/MobileCaptureFlow.jsx b/client/src/components/mobile/MobileCaptureFlow.jsxindex 799e366655..fc264c95e5 100644--- a/client/src/components/mobile/MobileCaptureFlow.jsx+++ b/client/src/components/mobile/MobileCaptureFlow.jsx@@ -1,4 +1,4 @@-import { useState, useCallback } from 'react';+import { useState, useCallback, useRef, useEffect } from 'react';import { Send, Check } from 'lucide-react';import * as api from '../../services/api';import toast from '../ui/Toast';@@ -11,6 +11,9 @@ export default function MobileCaptureFlow() {const [text, setText] = useState('');const [saving, setSaving] = useState(false);const [justSaved, setJustSaved] = useState(false);+ const savedTimerRef = useRef(null);++ useEffect(() => () => clearTimeout(savedTimerRef.current), []);const onTranscript = useCallback((chunk) => {setText((prev) => (prev ? `${prev} ${chunk}`.trim() : chunk));@@ -20,7 +23,8 @@ export default function MobileCaptureFlow() {const trimmed = text.trim();if (!trimmed || saving) return;setSaving(true);- const result = await api.captureBrainThought(trimmed).catch((err) => {+ // silent: this flow owns the error toast in the catch below.+ const result = await api.captureBrainThought(trimmed, undefined, undefined, { silent: true }).catch((err) => {toast.error(`Capture failed: ${err.message}`);return null;});@@ -28,7 +32,8 @@ export default function MobileCaptureFlow() {if (!result) return;setText('');setJustSaved(true);- setTimeout(() => setJustSaved(false), 2000);+ clearTimeout(savedTimerRef.current);+ savedTimerRef.current = setTimeout(() => setJustSaved(false), 2000);toast.success('Captured to Brain');};diff --git a/client/src/components/mobile/MobileHealthFlow.jsx b/client/src/components/mobile/MobileHealthFlow.jsxindex f375ea0a73..c81e304d33 100644--- a/client/src/components/mobile/MobileHealthFlow.jsx+++ b/client/src/components/mobile/MobileHealthFlow.jsx@@ -10,6 +10,7 @@ const HEALTH_STYLE = {healthy: { color: 'text-port-success', Icon: CheckCircle, label: 'Healthy' },warning: { color: 'text-port-warning', Icon: AlertTriangle, label: 'Warning' },critical: { color: 'text-port-error', Icon: XCircle, label: 'Critical' },+ unknown: { color: 'text-gray-400', Icon: AlertTriangle, label: 'Unknown' },};function tone(pct, warn, critical) {@@ -28,7 +29,8 @@ export default function MobileHealthFlow() {const restart = async (app) => {setRestartingId(app.id);- const result = await api.restartApp(app.id).catch((err) => {+ // silent: this flow owns the error toast in the catch below.+ const result = await api.restartApp(app.id, { silent: true }).catch((err) => {toast.error(`Restart failed: ${err.message}`);return null;});@@ -45,15 +47,29 @@ export default function MobileHealthFlow() {return <div className="flex justify-center py-12"><BrailleSpinner text="Loading health" /></div>;}- const style = HEALTH_STYLE[health?.overallHealth] || HEALTH_STYLE.healthy;+ // useAutoRefetch preserves the last good snapshot on error, so a null `health`+ // after the initial load means the fetch has never succeeded — show an+ // explicit unavailable state rather than a misleading "Healthy".+ if (!health) {+ return (+ <div className="flex flex-col items-center gap-2 py-12 text-center text-gray-500">+ <AlertTriangle size={32} aria-hidden="true" />+ <p className="text-base">System health is unavailable right now.</p>+ </div>+ );+ }++ // Unrecognized overallHealth falls to a neutral "unknown" style, never "healthy".+ const style = HEALTH_STYLE[health.overallHealth] || HEALTH_STYLE.unknown;const StatusIcon = style.Icon;const mem = health?.system?.memory;const disk = health?.system?.disk;const cpu = health?.system?.cpu;const thresholds = health?.thresholds || {};- // Only PM2-managed apps can be restarted; others (Xcode/native) have no runtime.- const restartable = (apps || []).filter((a) => a.overallStatus && a.overallStatus !== 'n/a');+ // Only active, PM2-managed apps can be restarted; archived apps and+ // others (Xcode/native, overallStatus 'n/a') have no restartable runtime.+ const restartable = (apps || []).filter((a) => !a.archived && a.overallStatus && a.overallStatus !== 'n/a');return (<div className="space-y-4">diff --git a/client/src/components/mobile/MobileLogFlow.jsx b/client/src/components/mobile/MobileLogFlow.jsxindex 845f6e9cb1..56e833e537 100644--- a/client/src/components/mobile/MobileLogFlow.jsx+++ b/client/src/components/mobile/MobileLogFlow.jsx@@ -1,4 +1,4 @@-import { useState } from 'react';+import { useState, useRef, useEffect } from 'react';import { Wine, Cigarette, Check } from 'lucide-react';import * as api from '../../services/api';import toast from '../ui/Toast';@@ -25,6 +25,9 @@ export default function MobileLogFlow() {const [tab, setTab] = useState('alcohol');const [busy, setBusy] = useState(null);const [lastLogged, setLastLogged] = useState(null);+ const flashTimerRef = useRef(null);++ useEffect(() => () => clearTimeout(flashTimerRef.current), []);// Custom presets change rarely — poll slowly just to pick up edits made elsewhere.const { data: customDrinks } = useAutoRefetch(() => api.getCustomDrinks({ silent: true }), 300_000);@@ -33,7 +36,8 @@ export default function MobileLogFlow() {const logDrink = async (drink) => {const key = `${drink.name}-${drink.oz}-${drink.abv}`;setBusy(key);- const result = await api.logAlcoholDrink({ name: drink.name, oz: drink.oz, abv: drink.abv }).catch((err) => {+ // silent: this flow owns the error toast in the catch below.+ const result = await api.logAlcoholDrink({ name: drink.name, oz: drink.oz, abv: drink.abv }, { silent: true }).catch((err) => {toast.error(`Log failed: ${err.message}`);return null;});@@ -45,7 +49,8 @@ export default function MobileLogFlow() {const logNic = async (product) => {const key = `${product.product}-${product.mgPerUnit}`;setBusy(key);- const result = await api.logNicotine({ product: product.product, mgPerUnit: product.mgPerUnit }).catch((err) => {+ // silent: this flow owns the error toast in the catch below.+ const result = await api.logNicotine({ product: product.product, mgPerUnit: product.mgPerUnit }, { silent: true }).catch((err) => {toast.error(`Log failed: ${err.message}`);return null;});@@ -57,7 +62,8 @@ export default function MobileLogFlow() {const flash = (msg) => {setLastLogged(msg);toast.success(msg);- setTimeout(() => setLastLogged(null), 2500);+ clearTimeout(flashTimerRef.current);+ flashTimerRef.current = setTimeout(() => setLastLogged(null), 2500);};// Normalize both kinds into one button shape { key, label, detail, onTap }diff --git a/client/src/pages/Mobile.test.jsx b/client/src/pages/Mobile.test.jsxindex 7191f50954..d6670fe8a9 100644--- a/client/src/pages/Mobile.test.jsx+++ b/client/src/pages/Mobile.test.jsx@@ -20,6 +20,7 @@ vi.mock('../services/api', () => ({getApps: vi.fn().mockResolvedValue([{ id: 'app1', name: 'BookLoom', overallStatus: 'online' },{ id: 'native', name: 'iOSApp', overallStatus: 'n/a' },+ { id: 'old', name: 'OldApp', overallStatus: 'stopped', archived: true },]),restartApp: vi.fn().mockResolvedValue({ ok: true }),handleSelfRestart: vi.fn(),@@ -77,12 +78,13 @@ describe('Mobile hub', () => {});describe('Mobile flow dispatch', () => {- it('renders the log flow with one-tap presets and posts on tap', async () => {+ it('renders the log flow with one-tap presets and posts silently on tap', async () => {renderAt('/mobile/log');const beerBtn = await screen.findByText('Beer');fireEvent.click(beerBtn.closest('button'));await waitFor(() => {- expect(api.logAlcoholDrink).toHaveBeenCalledWith({ name: 'Beer', oz: 12, abv: 5 });+ // Flow owns its own error toast, so the API call must be silent.+ expect(api.logAlcoholDrink).toHaveBeenCalledWith({ name: 'Beer', oz: 12, abv: 5 }, { silent: true });});});@@ -91,17 +93,33 @@ describe('Mobile flow dispatch', () => {expect(await screen.findByText(/Nothing awaiting approval/i)).toBeTruthy();});- it('renders the health flow with a restart button for managed apps only', async () => {+ it('renders the health flow with a restart button for managed, non-archived apps only', async () => {renderAt('/mobile/health');expect(await screen.findByText('BookLoom')).toBeTruthy();- // n/a (native) app is filtered out of the restartable list.+ // n/a (native) and archived apps are filtered out of the restartable list.expect(screen.queryByText('iOSApp')).toBeNull();+ expect(screen.queryByText('OldApp')).toBeNull();fireEvent.click(screen.getByLabelText('Restart BookLoom'));- await waitFor(() => expect(api.restartApp).toHaveBeenCalledWith('app1'));+ await waitFor(() => expect(api.restartApp).toHaveBeenCalledWith('app1', { silent: true }));});it('redirects an unknown flow slug back to the hub', () => {renderAt('/mobile/bogus');expect(screen.getByText('Quick Actions')).toBeTruthy();});++ it('shows an explicit unavailable state when health never loads (not a false "Healthy")', async () => {+ // useAutoRefetch keeps data null when the fetch rejects.+ api.getSystemHealth.mockRejectedValueOnce(new Error('boom'));+ renderAt('/mobile/health');+ expect(await screen.findByText(/System health is unavailable/i)).toBeTruthy();+ expect(screen.queryByText('Healthy')).toBeNull();+ });++ it('shows an unavailable state for approvals when the queue fetch fails (not "Nothing awaiting")', async () => {+ api.getCosTasks.mockRejectedValueOnce(new Error('boom'));+ renderAt('/mobile/approve');+ expect(await screen.findByText(/Approvals are unavailable/i)).toBeTruthy();+ expect(screen.queryByText(/Nothing awaiting approval/i)).toBeNull();+ });});diff --git a/client/src/services/apiAgents.js b/client/src/services/apiAgents.jsindex f3f72cb3d0..5df3856c49 100644--- a/client/src/services/apiAgents.js+++ b/client/src/services/apiAgents.js@@ -67,12 +67,12 @@ export const updateCosTask = (id, updates) => request(`/cos/tasks/${id}`, {method: 'PUT',body: JSON.stringify(updates)});-export const deleteCosTask = (id, taskType = 'user') => request(`/cos/tasks/${id}?type=${taskType}`, { method: 'DELETE' });+export const deleteCosTask = (id, taskType = 'user', options) => request(`/cos/tasks/${id}?type=${taskType}`, { method: 'DELETE', ...options });export const reorderCosTasks = (taskIds) => request('/cos/tasks/reorder', {method: 'POST',body: JSON.stringify({ taskIds })});-export const approveCosTask = (id) => request(`/cos/tasks/${id}/approve`, { method: 'POST' });+export const approveCosTask = (id, options) => request(`/cos/tasks/${id}/approve`, { method: 'POST', ...options });export const forceCosEvaluate = () => request('/cos/evaluate', { method: 'POST' });export const forceSpawnTask = (taskId) => request(`/cos/tasks/${taskId}/spawn`, { method: 'POST' });export const getCosHealth = () => request('/cos/health');diff --git a/client/src/services/apiApps.js b/client/src/services/apiApps.jsindex 8994d79531..edd17ea04c 100644--- a/client/src/services/apiApps.js+++ b/client/src/services/apiApps.js@@ -17,7 +17,7 @@ export const deleteApp = (id) => request(`/apps/${id}`, { method: 'DELETE' });// App actionsexport const startApp = (id) => request(`/apps/${id}/start`, { method: 'POST' });export const stopApp = (id) => request(`/apps/${id}/stop`, { method: 'POST' });-export const restartApp = (id) => request(`/apps/${id}/restart`, { method: 'POST' });+export const restartApp = (id, options) => request(`/apps/${id}/restart`, { method: 'POST', ...options });export const upgradeAppTls = (id, body) => request(`/apps/${id}/upgrade-tls`, {method: 'POST',body: JSON.stringify(body),diff --git a/client/src/services/apiBrain.js b/client/src/services/apiBrain.jsindex ddc5b0e67f..238223cb43 100644--- a/client/src/services/apiBrain.js+++ b/client/src/services/apiBrain.js@@ -9,9 +9,10 @@ export const updateBrainSettings = (settings) => request('/brain/settings', {});// Brain - Capture & Inbox-export const captureBrainThought = (text, providerOverride, modelOverride) => request('/brain/capture', {+export const captureBrainThought = (text, providerOverride, modelOverride, options) => request('/brain/capture', {method: 'POST',- body: JSON.stringify({ text, providerOverride, modelOverride })+ body: JSON.stringify({ text, providerOverride, modelOverride }),+ ...options});export const getBrainInbox = (options = {}) => {const params = new URLSearchParams();diff --git a/client/src/services/apiMeatspace.js b/client/src/services/apiMeatspace.jsindex 18b51d70b9..a20ed9609f 100644--- a/client/src/services/apiMeatspace.js+++ b/client/src/services/apiMeatspace.js@@ -75,9 +75,10 @@ export const getDailyAlcohol = (from, to) => {if (to) params.set('to', to);return request(`/meatspace/alcohol/daily?${params}`);};-export const logAlcoholDrink = (data) => request('/meatspace/alcohol/log', {+export const logAlcoholDrink = (data, options) => request('/meatspace/alcohol/log', {method: 'POST',- body: JSON.stringify(data)+ body: JSON.stringify(data),+ ...options});export const updateAlcoholDrink = (date, index, data) => request(`/meatspace/alcohol/log/${date}/${index}`, {method: 'PUT',@@ -105,9 +106,10 @@ export const getDailyNicotine = (from, to) => {if (to) params.set('to', to);return request(`/meatspace/nicotine/daily?${params}`);};-export const logNicotine = (data) => request('/meatspace/nicotine/log', {+export const logNicotine = (data, options) => request('/meatspace/nicotine/log', {method: 'POST',- body: JSON.stringify(data)+ body: JSON.stringify(data),+ ...options});export const updateNicotineEntry = (date, index, data) => request(`/meatspace/nicotine/log/${date}/${index}`, {method: 'PUT',