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(cybercity): /simplify pass on Phase 1
Adam Eivy7a2f6d0f7eb2
diff --git a/client/src/components/city/Building.jsx b/client/src/components/city/Building.jsxindex 8f4c618903..7ec51d700f 100644--- a/client/src/components/city/Building.jsx+++ b/client/src/components/city/Building.jsx@@ -279,9 +279,6 @@ export default function Building({ app, position, agentCount, onClick, playSfx,const isOnline = app.overallStatus === 'online' && !app.archived;const isStopped = app.overallStatus === 'stopped' && !app.archived;const { width, depth } = BUILDING_PARAMS;- // Single multiplier applied to every opacity in the building when the search- // / status filter doesn't match this app. Faded enough to recede visually- // without disappearing — the user keeps spatial context.const dimMul = dimmed ? 0.25 : 1;// Name hash for seeded randomnessdiff --git a/client/src/components/city/CityFilterBar.jsx b/client/src/components/city/CityFilterBar.jsxindex 7451816adf..bb8a39b637 100644--- a/client/src/components/city/CityFilterBar.jsx+++ b/client/src/components/city/CityFilterBar.jsx@@ -1,52 +1,7 @@import { useEffect, useRef, useState } from 'react';+import { STATUS_FILTERS } from '../../utils/cityFilter';-const STATUS_FILTERS = [- { id: 'all', label: 'ALL', match: () => true },- { id: 'online', label: 'ONLINE', match: (app) => !app.archived && app.overallStatus === 'online' },- { id: 'stopped', label: 'STOPPED', match: (app) => !app.archived && app.overallStatus === 'stopped' },- {- id: 'errored',- label: 'ERRORED',- match: (app) => {- if (app.archived) return false;- const pm2 = app.pm2Status || {};- return Object.values(pm2).some(s => s?.status === 'errored');- },- },- {- id: 'agent',- label: 'AGENT',- match: (app, { agentMap }) => agentMap?.has?.(app.id),- },-];--// Compute the set of app IDs that should be dimmed in the 3D scene given the-// current filter + search query. The complement (matching apps) renders at full-// brightness; matches are also returned so a focus/jump action can use them.-export function computeFilterResult({ apps, status, search, agentMap }) {- const matcher = STATUS_FILTERS.find(f => f.id === status) || STATUS_FILTERS[0];- const trimmed = (search || '').trim().toLowerCase();- const matches = [];- const dimmed = new Set();-- (apps || []).forEach(app => {- const passesStatus = matcher.match(app, { agentMap });- const haystack = [app.name, app.id, ...(app.tags || [])]- .filter(Boolean)- .join(' ')- .toLowerCase();- const passesSearch = trimmed.length === 0 || haystack.includes(trimmed);- if (passesStatus && passesSearch) {- matches.push(app);- } else {- dimmed.add(app.id);- }- });-- return { matches, dimmed };-}--export default function CityFilterBar({ apps, agentMap, filter, onChange, matchCount, onJumpToFirst }) {+export default function CityFilterBar({ filter, onChange, matchCount, onJumpToFirst }) {const inputRef = useRef(null);const [open, setOpen] = useState(Boolean(filter.search));diff --git a/client/src/components/city/CityHud.jsx b/client/src/components/city/CityHud.jsxindex 2b73731083..95fe76f42e 100644--- a/client/src/components/city/CityHud.jsx+++ b/client/src/components/city/CityHud.jsx@@ -56,8 +56,6 @@ const formatUptime = (seconds) => {return `${s}s`;};-// Sentinel dot color for the system-health card. Reads from systemHealth.overallHealth-// when available, falls back to onlineRatio if the health endpoint is offline.const getHealthSentinel = (systemHealth, onlineRatio) => {if (systemHealth?.overallHealth === 'critical') return { dot: 'bg-red-400', text: 'text-red-400', label: 'CRITICAL' };if (systemHealth?.overallHealth === 'warning') return { dot: 'bg-amber-400', text: 'text-amber-400', label: 'WARN' };@@ -67,7 +65,6 @@ const getHealthSentinel = (systemHealth, onlineRatio) => {return { dot: 'bg-red-400', text: 'text-red-400', label: 'CRIT' };};-// Color a metric percentage cyan→amber→red so the eye can scan the row at a glance.const metricColor = (pct) => {if (pct == null) return 'text-gray-500';if (pct >= 90) return 'text-red-400';@@ -130,7 +127,23 @@ function GlitchTitle({ text, className }) {);}-// System health bar visualization+function StatButton({ label, valueClass, value, onClick, title, prefix = null }) {+ return (+ <button+ type="button"+ onClick={onClick}+ title={title}+ className="w-full flex items-center justify-between gap-6 -mx-1 px-1 py-0.5 rounded hover:bg-cyan-500/5 transition-colors"+ >+ <span className="font-pixel text-[10px] text-gray-400 tracking-wide">{label}</span>+ <span className={`font-pixel text-[11px] ${valueClass || 'text-cyan-400'}`}>+ {prefix}+ {value}+ </span>+ </button>+ );+}+function HealthBar({ value, max, color }) {const pct = max > 0 ? (value / max) * 100 : 0;return (@@ -160,10 +173,16 @@ export default function CityHud({ cosStatus, cosAgents, agentMap, eventLogs, conreturn () => clearInterval(interval);}, []);- const activeApps = apps.filter(a => !a.archived && a.overallStatus === 'online').length;- const stoppedApps = apps.filter(a => !a.archived && a.overallStatus === 'stopped').length;- const totalApps = apps.filter(a => !a.archived).length;- const archivedApps = apps.filter(a => a.archived).length;+ const { activeApps, stoppedApps, totalApps, archivedApps } = useMemo(() => {+ const acc = { activeApps: 0, stoppedApps: 0, totalApps: 0, archivedApps: 0 };+ (apps || []).forEach(a => {+ if (a.archived) { acc.archivedApps++; return; }+ acc.totalApps++;+ if (a.overallStatus === 'online') acc.activeApps++;+ else if (a.overallStatus === 'stopped') acc.stoppedApps++;+ });+ return acc;+ }, [apps]);const onlineRatio = totalApps > 0 ? activeApps / totalApps : 1;const sentinel = useMemo(() => getHealthSentinel(systemHealth, onlineRatio), [systemHealth, onlineRatio]);@@ -173,8 +192,11 @@ export default function CityHud({ cosStatus, cosAgents, agentMap, eventLogs, conconst pendingReview = reviewCounts?.total || 0;const alertCount = reviewCounts?.alert || 0;const peers = instances?.peers || [];- const onlinePeers = peers.filter(peer => peer.status === 'online').length;- const totalNodes = peers.length;+ const { onlinePeers, totalNodes } = useMemo(() => {+ let online = 0;+ peers.forEach(p => { if (p.status === 'online') online++; });+ return { onlinePeers: online, totalNodes: peers.length };+ }, [peers]);const activeAgentCount = (cosAgents || []).filter(a =>a.status === 'running' || a.state === 'coding' || a.state === 'thinking' || a.state === 'investigating'@@ -227,9 +249,6 @@ export default function CityHud({ cosStatus, cosAgents, agentMap, eventLogs, con</span></div>- {/* Health card: CPU / MEM / DISK with a single-glance sentinel.- Replaces the cryptic weather glyph — atmospheric weather still- lives in CityWeather, but the HUD readout is plain numbers. */}<buttontype="button"onClick={() => navigate('/')}@@ -253,119 +272,81 @@ export default function CityHud({ cosStatus, cosAgents, agentMap, eventLogs, con<span className={`font-pixel text-[8px] ${sentinel.text} tracking-wider`}>{sentinel.label}</span></div>- {/* Active agents — clicks into CoS */}- <button- type="button"+ <StatButton+ label="AGENTS"+ valueClass={activeAgentCount > 0 ? 'text-emerald-400' : 'text-gray-600'}+ value={`${activeAgentCount} ACTIVE`}+ prefix={activeAgentCount > 0 ? <span className="inline-block w-1.5 h-1.5 rounded-full bg-emerald-400 mr-1 animate-pulse" /> : null}onClick={() => navigate('/cos')}- className="w-full flex items-center justify-between gap-6 -mx-1 px-1 py-0.5 rounded hover:bg-cyan-500/5 transition-colors"title="Open Chief of Staff"- >- <span className="font-pixel text-[10px] text-gray-400 tracking-wide">AGENTS</span>- <span className={`font-pixel text-[11px] ${activeAgentCount > 0 ? 'text-emerald-400' : 'text-gray-600'}`}>- {activeAgentCount > 0 && <span className="inline-block w-1.5 h-1.5 rounded-full bg-emerald-400 mr-1 animate-pulse" />}- {activeAgentCount} ACTIVE- </span>- </button>+ />- {/* Stopped count — jumps to apps page */}{stoppedApps > 0 && (- <button- type="button"+ <StatButton+ label="STOPPED"+ valueClass="text-red-400"+ value={stoppedApps}onClick={() => navigate('/apps')}- className="w-full flex items-center justify-between gap-6 -mx-1 px-1 py-0.5 rounded hover:bg-cyan-500/5 transition-colors"title="View apps"- >- <span className="font-pixel text-[10px] text-gray-400 tracking-wide">STOPPED</span>- <span className="font-pixel text-[11px] text-red-400" style={{ textShadow: '0 0 4px rgba(239,68,68,0.3)' }}>- {stoppedApps}- </span>- </button>+ />)}- {/* Archived */}{archivedApps > 0 && (- <button- type="button"+ <StatButton+ label="ARCHIVED"+ valueClass="text-gray-500"+ value={archivedApps}onClick={() => navigate('/apps')}- className="w-full flex items-center justify-between gap-6 -mx-1 px-1 py-0.5 rounded hover:bg-cyan-500/5 transition-colors"title="View apps"- >- <span className="font-pixel text-[10px] text-gray-400 tracking-wide">ARCHIVED</span>- <span className="font-pixel text-[11px] text-gray-500">{archivedApps}</span>- </button>+ />)}- {/* Review pressure — jumps to review hub */}{(pendingReview > 0 || alertCount > 0) && (- <button- type="button"+ <StatButton+ label="REVIEW"+ valueClass={alertCount > 0 ? 'text-orange-400' : 'text-cyan-400'}+ value={`${pendingReview} PENDING${alertCount > 0 ? ` · ${alertCount} ALERT${alertCount === 1 ? '' : 'S'}` : ''}`}onClick={() => navigate('/review')}- className="w-full flex items-center justify-between gap-6 -mx-1 px-1 py-0.5 rounded hover:bg-cyan-500/5 transition-colors"title="Open Review Hub"- >- <span className="font-pixel text-[10px] text-gray-400 tracking-wide">REVIEW</span>- <span className={`font-pixel text-[11px] ${alertCount > 0 ? 'text-orange-400' : 'text-cyan-400'}`}>- {pendingReview} PENDING{alertCount > 0 ? ` · ${alertCount} ALERT${alertCount === 1 ? '' : 'S'}` : ''}- </span>- </button>+ />)}- {/* Instance mesh — jumps to federation page */}- <button- type="button"+ <StatButton+ label="NODES"+ valueClass={onlinePeers > 0 ? 'text-violet-400' : 'text-gray-500'}+ value={`${onlinePeers}/${totalNodes} LINKED`}onClick={() => navigate('/instances')}- className="w-full flex items-center justify-between gap-6 -mx-1 px-1 py-0.5 rounded hover:bg-cyan-500/5 transition-colors"title="Open Federation / Instances"- >- <span className="font-pixel text-[10px] text-gray-400 tracking-wide">NODES</span>- <span className={`font-pixel text-[11px] ${onlinePeers > 0 ? 'text-violet-400' : 'text-gray-500'}`}>- {onlinePeers}/{totalNodes} LINKED- </span>- </button>+ />- {/* Notifications — jumps to dashboard (where the alerts widget lives) */}{notificationCounts?.unread > 0 && (- <button- type="button"+ <StatButton+ label="NOTIFS"+ valueClass="text-cyan-400"+ value={`${notificationCounts.unread} UNREAD`}onClick={() => navigate('/')}- className="w-full flex items-center justify-between gap-6 -mx-1 px-1 py-0.5 rounded hover:bg-cyan-500/5 transition-colors"title="Open dashboard alerts"- >- <span className="font-pixel text-[10px] text-gray-400 tracking-wide">NOTIFS</span>- <span className="font-pixel text-[11px] text-cyan-400">- {notificationCounts.unread} UNREAD- </span>- </button>+ />)}- {/* Productivity - today's tasks */}{productivityData?.todaySucceeded > 0 && (- <button- type="button"+ <StatButton+ label="TASKS"+ valueClass="text-purple-400"+ value={`${productivityData.todaySucceeded} TODAY`}onClick={() => navigate('/cos')}- className="w-full flex items-center justify-between gap-6 -mx-1 px-1 py-0.5 rounded hover:bg-cyan-500/5 transition-colors"title="Open Chief of Staff"- >- <span className="font-pixel text-[10px] text-gray-400 tracking-wide">TASKS</span>- <span className="font-pixel text-[11px] text-purple-400" style={{ textShadow: '0 0 4px rgba(168,85,247,0.3)' }}>- {productivityData.todaySucceeded} TODAY- </span>- </button>+ />)}- {/* Streak */}{productivityData?.currentDailyStreak > 0 && (- <button- type="button"+ <StatButton+ label="STREAK"+ valueClass={productivityData.currentDailyStreak >= 3 ? 'text-orange-400' : 'text-gray-400'}+ value={`${productivityData.currentDailyStreak}d`}onClick={() => navigate('/cos')}- className="w-full flex items-center justify-between gap-6 -mx-1 px-1 py-0.5 rounded hover:bg-cyan-500/5 transition-colors"title="Open Chief of Staff"- >- <span className="font-pixel text-[10px] text-gray-400 tracking-wide">STREAK</span>- <span className={`font-pixel text-[11px] ${productivityData.currentDailyStreak >= 3 ? 'text-orange-400' : 'text-gray-400'}`}>- {productivityData.currentDailyStreak}d- </span>- </button>+ />)}{/* Divider */}@@ -391,13 +372,9 @@ export default function CityHud({ cosStatus, cosAgents, agentMap, eventLogs, con</div></div>- {/* Below title: filter chips + search. Centered so it reads as the- city's primary navigation aid. Press '/' from anywhere to focus. */}{filter && onFilterChange && (<div className="absolute top-14 left-1/2 -translate-x-1/2"><CityFilterBar- apps={apps}- agentMap={agentMap}filter={filter}onChange={onFilterChange}onJumpToFirst={onJumpToFirst}diff --git a/client/src/components/city/CityIntelPane.jsx b/client/src/components/city/CityIntelPane.jsxindex 69fefb7d0a..ee87c1b939 100644--- a/client/src/components/city/CityIntelPane.jsx+++ b/client/src/components/city/CityIntelPane.jsx@@ -1,5 +1,6 @@import { useMemo, useRef, useEffect, useState } from 'react';import { useNavigate } from 'react-router-dom';+import { formatClockTime } from '../../utils/formatters';const SEVERITY_RANK = { critical: 0, warning: 1, info: 2 };const SEVERITY_COLORS = {@@ -8,38 +9,33 @@ const SEVERITY_COLORS = {info: { dot: 'bg-cyan-400', text: 'text-cyan-300', border: 'border-cyan-500/25' },};-// Build the prioritized list of things that need the user's attention right now.-// Higher-priority (critical) items rise to the top; ties broken by category order.function buildAttentionItems({ apps, cosAgents, reviewCounts, instances, systemHealth, notificationCounts }) {const items = [];- // 1. Errored / stopped apps — most urgent, the city's reason for being a dashboard- const stoppedApps = (apps || []).filter(a => !a.archived && a.overallStatus === 'stopped');- stoppedApps.forEach(app => {- items.push({- id: `app-stopped-${app.id}`,- severity: 'critical',- label: `${app.name || app.id}`,- detail: 'Stopped',- to: `/apps/${app.id}`,- category: 'app',- });- });-- // PM2 process-level errors per app(apps || []).forEach(app => {if (app.archived) return;- const pm2 = app.pm2Status || {};- const erroredProcs = Object.entries(pm2).filter(([, s]) => s?.status === 'errored');- erroredProcs.forEach(([procName]) => {+ if (app.overallStatus === 'stopped') {items.push({- id: `proc-err-${app.id}-${procName}`,+ id: `app-stopped-${app.id}`,severity: 'critical',- label: `${app.name || app.id} · ${procName}`,- detail: 'Process errored',+ label: `${app.name || app.id}`,+ detail: 'Stopped',to: `/apps/${app.id}`,category: 'app',});+ }+ const pm2 = app.pm2Status || {};+ Object.entries(pm2).forEach(([procName, s]) => {+ if (s?.status === 'errored') {+ items.push({+ id: `proc-err-${app.id}-${procName}`,+ severity: 'critical',+ label: `${app.name || app.id} · ${procName}`,+ detail: 'Process errored',+ to: `/apps/${app.id}`,+ category: 'app',+ });+ }});});@@ -212,9 +208,7 @@ function ActivityLogList({ logs }) {const level = log.level || 'info';const colorClass = LEVEL_COLORS[level] || LEVEL_COLORS.info;const indicatorClass = LEVEL_INDICATORS[level] || LEVEL_INDICATORS.info;- const time = log.timestamp- ? new Date(log.timestamp).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', second: '2-digit' })- : '';+ const time = log.timestamp ? formatClockTime(new Date(log.timestamp)) : '';const message = log.message || log.event || JSON.stringify(log);return (diff --git a/client/src/hooks/useCityData.js b/client/src/hooks/useCityData.jsindex 9ec6fff721..bebf9edbef 100644--- a/client/src/hooks/useCityData.js+++ b/client/src/hooks/useCityData.js@@ -2,6 +2,9 @@ import { useState, useEffect, useCallback, useMemo, useRef } from 'react';import * as api from '../services/api';import socket from '../services/socket';+const healthSignature = (h) =>+ `${h?.overallHealth}|${h?.system?.cpu?.usagePercent}|${h?.system?.memory?.usagePercent}|${h?.system?.disk?.usagePercent}|${h?.warnings?.length ?? 0}`;+export const useCityData = () => {const [apps, setApps] = useState([]);const [cosAgents, setCosAgents] = useState([]);@@ -47,7 +50,11 @@ export const useCityData = () => {const fetchHealth = useCallback(async () => {const health = await api.getSystemHealth().catch(() => null);- if (health) setSystemHealth(health);+ if (!health) return;+ setSystemHealth(prev => {+ if (prev && healthSignature(prev) === healthSignature(health)) return prev;+ return health;+ });}, []);const agentMap = useMemo(() => {@@ -110,8 +117,6 @@ export const useCityData = () => {setRunningAgents(agents);}, 10000);- // System health refresh: every 15s. CPU/memory shift fast enough to matter- // for the operational HUD but not so fast that we want a per-second poll.healthPollRef.current = setInterval(fetchHealth, 15000);return () => {diff --git a/client/src/pages/CyberCity.jsx b/client/src/pages/CyberCity.jsxindex 5c40404e98..8c1134bb9e 100644--- a/client/src/pages/CyberCity.jsx+++ b/client/src/pages/CyberCity.jsx@@ -9,7 +9,7 @@ import CityHud from '../components/city/CityHud';import CityScanlines from '../components/city/CityScanlines';import { CitySettingsProvider, useCitySettingsContext } from '../components/city/CitySettingsContext';import CitySettingsPanel from '../components/city/CitySettingsPanel';-import { computeFilterResult } from '../components/city/CityFilterBar';+import { computeFilterResult } from '../utils/cityFilter';function CyberCityInner() {const { apps, cosAgents, cosStatus, eventLogs, agentMap, reviewCounts, instances, systemHealth, notificationCounts, loading, connected } = useCityData();@@ -52,8 +52,6 @@ function CyberCityInner() {}}, [navigate]);- // Submit (Enter) on the search bar jumps to the first match's app page —- // the closest thing to a focus-camera-on-match without rebuilding the layout.const handleJumpToFirst = useCallback(() => {const first = filterResult.matches[0];if (first?.id) navigate(`/apps/${first.id}`);diff --git a/client/src/utils/cityFilter.js b/client/src/utils/cityFilter.jsnew file mode 100644index 0000000000..ea18e4ae6b--- /dev/null+++ b/client/src/utils/cityFilter.js@@ -0,0 +1,42 @@+export const STATUS_FILTERS = [+ { id: 'all', label: 'ALL', match: () => true },+ { id: 'online', label: 'ONLINE', match: (app) => !app.archived && app.overallStatus === 'online' },+ { id: 'stopped', label: 'STOPPED', match: (app) => !app.archived && app.overallStatus === 'stopped' },+ {+ id: 'errored',+ label: 'ERRORED',+ match: (app) => {+ if (app.archived) return false;+ const pm2 = app.pm2Status || {};+ return Object.values(pm2).some(s => s?.status === 'errored');+ },+ },+ {+ id: 'agent',+ label: 'AGENT',+ match: (app, { agentMap }) => agentMap?.has?.(app.id),+ },+];++export function computeFilterResult({ apps, status, search, agentMap }) {+ const matcher = STATUS_FILTERS.find(f => f.id === status) || STATUS_FILTERS[0];+ const trimmed = (search || '').trim().toLowerCase();+ const matches = [];+ const dimmed = new Set();++ (apps || []).forEach(app => {+ const passesStatus = matcher.match(app, { agentMap });+ const haystack = [app.name, app.id, ...(app.tags || [])]+ .filter(Boolean)+ .join(' ')+ .toLowerCase();+ const passesSearch = trimmed.length === 0 || haystack.includes(trimmed);+ if (passesStatus && passesSearch) {+ matches.push(app);+ } else {+ dimmed.add(app.id);+ }+ });++ return { matches, dimmed };+}