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
feat(dashboard): add System Health Widget with server metrics
Adam Eivy01e4a92660c9
diff --git a/.changelog/v0.14.x.md b/.changelog/v0.14.x.mdindex 4a44fa6b3e..e81e66ca41 100644--- a/.changelog/v0.14.x.md+++ b/.changelog/v0.14.x.md@@ -26,6 +26,14 @@ This release adds Ghostty terminal theme integration and a project update workfl- **"Secret" checkbox on new env var** — when adding a new env var, check "Secret" to auto-add it to the masked list- **One-per-line env var display** — env vars now render vertically instead of comma-separated for better readability+### System Health Widget+- **Dashboard health overview** — new widget at the top of the dashboard showing server uptime, memory/CPU usage, PM2 process status, and app health at a glance+- **Color-coded status indicators** — healthy (green), warning (yellow), or critical (red) based on system metrics+- **Progress bars for resource usage** — visual memory and CPU usage bars that change color as thresholds are crossed (75%=warning, 90%=critical)+- **Warning banners** — prominent alerts for high memory, CPU load, errored processes, or excessive restarts+- **CoS status integration** — shows if Chief of Staff is running/paused with active agent count+- **New `/api/health/system` endpoint** — consolidates system metrics, PM2 process stats, app status, and CoS state in one API call+## Fixes- **Disabled GLSL custom shaders** — fragment shaders (bloom, nebula, rain, etc.) ran per-pixel every frame causing GPU-bound lag on terminal output; themes now use color palettes onlydiff --git a/client/src/components/SystemHealthWidget.jsx b/client/src/components/SystemHealthWidget.jsxnew file mode 100644index 0000000000..ece6c38671--- /dev/null+++ b/client/src/components/SystemHealthWidget.jsx@@ -0,0 +1,241 @@+import { useState, useEffect, memo } from 'react';+import { Link } from 'react-router-dom';+import {+ Activity,+ Server,+ Cpu,+ HardDrive,+ ChevronRight,+ AlertTriangle,+ CheckCircle,+ XCircle,+ Clock,+ Zap+} from 'lucide-react';+import * as api from '../services/api';++/**+ * SystemHealthWidget - Compact system health overview for the Dashboard+ * Shows server uptime, memory/CPU usage, process status, and warnings+ */+const SystemHealthWidget = memo(function SystemHealthWidget() {+ const [health, setHealth] = useState(null);+ const [loading, setLoading] = useState(true);++ useEffect(() => {+ const loadData = async () => {+ const data = await api.getSystemHealth({ silent: true }).catch(() => null);+ setHealth(data);+ setLoading(false);+ };++ loadData();+ // Refresh every 30 seconds+ const interval = setInterval(loadData, 30000);+ return () => clearInterval(interval);+ }, []);++ // Don't render while loading+ if (loading) {+ return null;+ }++ // Don't render if no data+ if (!health) {+ return null;+ }++ const { overallHealth, warnings, system, processes, apps, cos } = health;++ // Get status color and icon+ const getHealthStyle = () => {+ switch (overallHealth) {+ case 'healthy':+ return { color: 'text-port-success', bg: 'bg-port-success/10', icon: CheckCircle };+ case 'warning':+ return { color: 'text-port-warning', bg: 'bg-port-warning/10', icon: AlertTriangle };+ case 'critical':+ return { color: 'text-port-error', bg: 'bg-port-error/10', icon: XCircle };+ default:+ return { color: 'text-gray-400', bg: 'bg-gray-400/10', icon: Activity };+ }+ };++ const healthStyle = getHealthStyle();+ const HealthIcon = healthStyle.icon;++ // Get color for usage percentage+ const getUsageColor = (percent) => {+ if (percent >= 90) return 'text-port-error';+ if (percent >= 75) return 'text-port-warning';+ return 'text-port-success';+ };++ // Get progress bar color+ const getBarColor = (percent) => {+ if (percent >= 90) return 'bg-port-error';+ if (percent >= 75) return 'bg-port-warning';+ return 'bg-port-success';+ };++ return (+ <div className="bg-port-card border border-port-border rounded-xl p-4 sm:p-6">+ {/* Header */}+ <div className="flex items-center justify-between mb-4">+ <div className="flex items-center gap-3">+ <div className={`p-2 rounded-lg ${healthStyle.bg}`}>+ <Server className={`w-5 h-5 ${healthStyle.color}`} />+ </div>+ <div>+ <h3 className="text-lg font-semibold text-white">System Health</h3>+ <div className="flex items-center gap-2 text-sm">+ <HealthIcon size={14} className={healthStyle.color} />+ <span className={healthStyle.color}>+ {overallHealth.charAt(0).toUpperCase() + overallHealth.slice(1)}+ </span>+ <span className="text-gray-500">•</span>+ <Clock size={12} className="text-gray-400" />+ <span className="text-gray-400">{system.uptimeFormatted}</span>+ </div>+ </div>+ </div>+ <Link+ to="/apps"+ className="flex items-center gap-1 text-sm text-port-accent hover:text-port-accent/80 transition-colors min-h-[40px] px-2"+ >+ <span className="hidden sm:inline">Details</span>+ <ChevronRight size={16} />+ </Link>+ </div>++ {/* Warnings */}+ {warnings.length > 0 && (+ <div className="mb-4 space-y-2">+ {warnings.map((warning, idx) => (+ <div+ key={idx}+ className="flex items-center gap-2 px-3 py-2 rounded-lg bg-port-warning/10 text-port-warning text-sm"+ >+ <AlertTriangle size={14} />+ <span>{warning.message}</span>+ </div>+ ))}+ </div>+ )}++ {/* Stats Grid */}+ <div className="grid grid-cols-2 sm:grid-cols-4 gap-3">+ {/* Memory Usage */}+ <div className="bg-port-bg/50 rounded-lg p-3">+ <div className="flex items-center gap-2 mb-1">+ <HardDrive size={14} className="text-purple-400" />+ <span className="text-xs text-gray-500">Memory</span>+ </div>+ <div className={`text-lg sm:text-xl font-bold ${getUsageColor(system.memory.usagePercent)}`}>+ {system.memory.usagePercent}%+ </div>+ <div className="text-xs text-gray-500">+ {system.memory.usedFormatted} / {system.memory.totalFormatted}+ </div>+ <div className="mt-2 h-1.5 bg-port-border rounded-full overflow-hidden">+ <div+ className={`h-full rounded-full transition-all ${getBarColor(system.memory.usagePercent)}`}+ style={{ width: `${system.memory.usagePercent}%` }}+ />+ </div>+ </div>++ {/* CPU Usage */}+ <div className="bg-port-bg/50 rounded-lg p-3">+ <div className="flex items-center gap-2 mb-1">+ <Cpu size={14} className="text-blue-400" />+ <span className="text-xs text-gray-500">CPU</span>+ </div>+ <div className={`text-lg sm:text-xl font-bold ${getUsageColor(system.cpu.usagePercent)}`}>+ {system.cpu.usagePercent}%+ </div>+ <div className="text-xs text-gray-500">+ {system.cpu.cores} cores+ </div>+ <div className="mt-2 h-1.5 bg-port-border rounded-full overflow-hidden">+ <div+ className={`h-full rounded-full transition-all ${getBarColor(Math.min(100, system.cpu.usagePercent))}`}+ style={{ width: `${Math.min(100, system.cpu.usagePercent)}%` }}+ />+ </div>+ </div>++ {/* Processes */}+ <div className="bg-port-bg/50 rounded-lg p-3">+ <div className="flex items-center gap-2 mb-1">+ <Activity size={14} className="text-emerald-400" />+ <span className="text-xs text-gray-500">Processes</span>+ </div>+ <div className="text-lg sm:text-xl font-bold text-white">+ {processes.online}+ <span className="text-sm font-normal text-gray-500">/{processes.total}</span>+ </div>+ <div className="flex items-center gap-1 text-xs text-gray-500">+ {processes.errored > 0 ? (+ <span className="text-port-error">{processes.errored} errored</span>+ ) : processes.stopped > 0 ? (+ <span>{processes.stopped} stopped</span>+ ) : (+ <span className="text-port-success">All running</span>+ )}+ </div>+ </div>++ {/* Apps */}+ <div className="bg-port-bg/50 rounded-lg p-3">+ <div className="flex items-center gap-2 mb-1">+ <Zap size={14} className="text-amber-400" />+ <span className="text-xs text-gray-500">Apps</span>+ </div>+ <div className="text-lg sm:text-xl font-bold text-white">+ {apps.online}+ <span className="text-sm font-normal text-gray-500">/{apps.total}</span>+ </div>+ <div className="flex items-center gap-1 text-xs text-gray-500">+ {apps.stopped > 0 ? (+ <span>{apps.stopped} stopped</span>+ ) : apps.notStarted > 0 ? (+ <span>{apps.notStarted} not started</span>+ ) : apps.online === apps.total ? (+ <span className="text-port-success">All online</span>+ ) : (+ <span>Ready</span>+ )}+ </div>+ </div>+ </div>++ {/* CoS Status (if running) */}+ {cos && (+ <div className="mt-4 pt-4 border-t border-port-border">+ <div className="flex items-center justify-between text-sm">+ <div className="flex items-center gap-2">+ <div className={`w-2 h-2 rounded-full ${cos.running ? (cos.paused ? 'bg-port-warning' : 'bg-port-success animate-pulse') : 'bg-gray-500'}`} />+ <span className="text-gray-300">Chief of Staff</span>+ <span className="text-gray-500">+ {cos.running ? (cos.paused ? 'Paused' : 'Active') : 'Stopped'}+ </span>+ </div>+ {cos.running && (+ <div className="flex items-center gap-3 text-xs text-gray-500">+ {cos.activeAgents > 0 && (+ <span className="text-port-accent">{cos.activeAgents} agent{cos.activeAgents !== 1 ? 's' : ''}</span>+ )}+ {cos.queuedTasks > 0 && (+ <span>{cos.queuedTasks} queued</span>+ )}+ </div>+ )}+ </div>+ </div>+ )}+ </div>+ );+});++export default SystemHealthWidget;diff --git a/client/src/pages/Dashboard.jsx b/client/src/pages/Dashboard.jsxindex addf9b3eb2..0ec10b870d 100644--- a/client/src/pages/Dashboard.jsx+++ b/client/src/pages/Dashboard.jsx@@ -2,6 +2,7 @@ import { useState, useEffect, useCallback, useMemo } from 'react';import { Link } from 'react-router-dom';import AppTile from '../components/AppTile';import BrailleSpinner from '../components/BrailleSpinner';+import SystemHealthWidget from '../components/SystemHealthWidget';import CosDashboardWidget from '../components/CosDashboardWidget';import GoalProgressWidget from '../components/GoalProgressWidget';import UpcomingTasksWidget from '../components/UpcomingTasksWidget';@@ -90,6 +91,11 @@ export default function Dashboard() {</div>)}+ {/* System Health Widget */}+ <div className="mb-6">+ <SystemHealthWidget />+ </div>+{/* CoS Status Widget */}<div className="mb-6"><CosDashboardWidget />diff --git a/client/src/services/api.js b/client/src/services/api.jsindex 5c47de5f96..28503d4c30 100644--- a/client/src/services/api.js+++ b/client/src/services/api.js@@ -39,6 +39,7 @@ async function request(endpoint, options = {}) {// Healthexport const checkHealth = () => request('/health');+export const getSystemHealth = (options) => request('/health/system', options);// Appsexport const getApps = () => request('/apps');diff --git a/server/routes/health.js b/server/routes/health.jsindex 5e69adc060..2d882c0ff1 100644--- a/server/routes/health.js+++ b/server/routes/health.js@@ -1,4 +1,8 @@import { Router } from 'express';+import os from 'os';+import { listProcesses } from '../services/pm2.js';+import * as apps from '../services/apps.js';+import * as cos from '../services/cos.js';const router = Router();@@ -12,4 +16,134 @@ router.get('/health', (req, res) => {});});+/**+ * GET /api/health/system - Comprehensive system health summary+ * Returns system metrics, app status, and CoS status for dashboard display+ */+router.get('/health/system', async (req, res) => {+ const startTime = Date.now();++ // Gather data in parallel+ const [pm2Processes, allApps, cosStatus] = await Promise.all([+ listProcesses().catch(() => []),+ apps.getAllApps({ includeArchived: false }).catch(() => []),+ cos.getStatus().catch(() => null)+ ]);++ // System metrics+ const totalMem = os.totalmem();+ const freeMem = os.freemem();+ const usedMem = totalMem - freeMem;+ const memUsagePercent = Math.round((usedMem / totalMem) * 100);+ const cpuLoad = os.loadavg()[0]; // 1-minute load average+ const cpuCount = os.cpus().length;+ const cpuUsagePercent = Math.round((cpuLoad / cpuCount) * 100);++ // Process status summary from PM2+ const processStats = {+ total: pm2Processes.length,+ online: pm2Processes.filter(p => p.status === 'online').length,+ stopped: pm2Processes.filter(p => p.status === 'stopped').length,+ errored: pm2Processes.filter(p => p.status === 'errored').length,+ totalMemory: pm2Processes.reduce((sum, p) => sum + (p.memory || 0), 0),+ totalCpu: pm2Processes.reduce((sum, p) => sum + (p.cpu || 0), 0),+ totalRestarts: pm2Processes.reduce((sum, p) => sum + (p.restarts || 0), 0)+ };++ // App status summary+ const appStats = {+ total: allApps.length,+ online: allApps.filter(a => a.overallStatus === 'online').length,+ stopped: allApps.filter(a => a.overallStatus === 'stopped').length,+ notStarted: allApps.filter(a => a.overallStatus === 'not_started' || a.overallStatus === 'not_found').length+ };++ // Determine overall health status+ let overallHealth = 'healthy';+ const warnings = [];++ if (memUsagePercent > 90) {+ overallHealth = 'critical';+ warnings.push({ type: 'memory', message: 'Memory usage above 90%' });+ } else if (memUsagePercent > 75) {+ if (overallHealth !== 'critical') overallHealth = 'warning';+ warnings.push({ type: 'memory', message: 'Memory usage above 75%' });+ }++ if (cpuUsagePercent > 100) {+ if (overallHealth !== 'critical') overallHealth = 'warning';+ warnings.push({ type: 'cpu', message: 'CPU load high' });+ }++ if (processStats.errored > 0) {+ overallHealth = 'critical';+ warnings.push({ type: 'process', message: `${processStats.errored} process(es) errored` });+ }++ if (processStats.totalRestarts > 10) {+ if (overallHealth !== 'critical') overallHealth = 'warning';+ warnings.push({ type: 'restarts', message: `${processStats.totalRestarts} total restarts` });+ }++ // CoS status+ const cosInfo = cosStatus ? {+ running: cosStatus.running,+ paused: cosStatus.paused,+ activeAgents: cosStatus.activeAgents || 0,+ queuedTasks: cosStatus.queueLength || 0+ } : null;++ // Format memory for display+ const formatBytes = (bytes) => {+ const gb = bytes / (1024 * 1024 * 1024);+ if (gb >= 1) return `${gb.toFixed(1)}GB`;+ const mb = bytes / (1024 * 1024);+ return `${mb.toFixed(0)}MB`;+ };++ // Format uptime for display+ const uptime = process.uptime();+ const days = Math.floor(uptime / 86400);+ const hours = Math.floor((uptime % 86400) / 3600);+ const minutes = Math.floor((uptime % 3600) / 60);+ let uptimeFormatted;+ if (days > 0) {+ uptimeFormatted = `${days}d ${hours}h`;+ } else if (hours > 0) {+ uptimeFormatted = `${hours}h ${minutes}m`;+ } else {+ uptimeFormatted = `${minutes}m`;+ }++ const responseTime = Date.now() - startTime;+ console.log(`💓 GET /api/health/system (${responseTime}ms)`);++ res.json({+ timestamp: new Date().toISOString(),+ overallHealth,+ warnings,+ system: {+ uptime,+ uptimeFormatted,+ memory: {+ total: totalMem,+ used: usedMem,+ free: freeMem,+ usagePercent: memUsagePercent,+ totalFormatted: formatBytes(totalMem),+ usedFormatted: formatBytes(usedMem),+ freeFormatted: formatBytes(freeMem)+ },+ cpu: {+ cores: cpuCount,+ loadAvg1m: cpuLoad,+ usagePercent: cpuUsagePercent+ }+ },+ processes: processStats,+ apps: appStats,+ cos: cosInfo+ });+});+export default router;