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([warning-banner-component]): extract shared Banner UI primitive and migrate five hand-rolled sites
[._.]/ Adam Eivy1683de75d2e1
diff --git a/client/src/components/cos/tabs/MemoryTab.jsx b/client/src/components/cos/tabs/MemoryTab.jsxindex 65a11c6e15..2326d447c5 100644--- a/client/src/components/cos/tabs/MemoryTab.jsx+++ b/client/src/components/cos/tabs/MemoryTab.jsx@@ -2,6 +2,7 @@ import { useState, useEffect, useCallback, useRef } from 'react';import { useSearchParams } from 'react-router-dom';import {Trash2, X, Check, XCircle, Pencil, AlertTriangle, Brain, Bot} from 'lucide-react';import toast from '../../ui/Toast';+import Banner from '../../ui/Banner';import * as api from '../../../services/api';import { MEMORY_TYPES, MEMORY_TYPE_COLORS } from '../constants';import { getAppName } from '../../../utils/formatters';@@ -129,22 +130,24 @@ export default function MemoryTab({ apps = [] }) {<div className="space-y-6">{/* Backend status banner */}{backendStatus?.backend === 'file' && (- <div className="bg-port-warning/10 border border-port-warning/30 rounded-lg p-4 flex items-start gap-3">- <AlertTriangle className="text-port-warning shrink-0 mt-0.5" size={20} />- <div className="flex-1">- <p className="text-port-warning font-medium">PostgreSQL unavailable — using file storage</p>- {backendStatus.db?.error && (- <p className="text-sm text-gray-400 mt-1">{backendStatus.db.error}</p>- )}- <p className="text-sm text-gray-500 mt-1">Some PostgreSQL-only features like cross-instance sync and DB snapshots are unavailable.</p>- </div>- <button- onClick={fetchData}- className="px-3 py-1.5 text-sm bg-port-warning/20 text-port-warning hover:bg-port-warning/30 rounded-lg transition-colors shrink-0"- >- Retry- </button>- </div>+ <Banner+ size="lg"+ icon={AlertTriangle}+ title="PostgreSQL unavailable — using file storage"+ actions={+ <button+ onClick={fetchData}+ className="px-3 py-1.5 text-sm bg-port-warning/20 text-port-warning hover:bg-port-warning/30 rounded-lg transition-colors"+ >+ Retry+ </button>+ }+ >+ {backendStatus.db?.error && (+ <p className="text-sm text-gray-400 mt-1">{backendStatus.db.error}</p>+ )}+ <p className="text-sm text-gray-500 mt-1">Some PostgreSQL-only features like cross-instance sync and DB snapshots are unavailable.</p>+ </Banner>)}{/* Header */}diff --git a/client/src/components/cos/tabs/ScheduleTab.jsx b/client/src/components/cos/tabs/ScheduleTab.jsxindex 39ce9415b3..3960d68172 100644--- a/client/src/components/cos/tabs/ScheduleTab.jsx+++ b/client/src/components/cos/tabs/ScheduleTab.jsx@@ -7,6 +7,7 @@ import AppIcon from '../../AppIcon';import CronInput from '../../CronInput';import { AGENT_OPTIONS, DEFAULT_REVIEW_STOP_MODE, toggleAppMetadataOverride, agentOptionButtonClass } from '../constants';import ReviewerPicker from '../ReviewerPicker';+import Banner from '../../ui/Banner';import { CodeReviewDefaultsProvider, useCodeReviewDefaults } from '../../../hooks/useCodeReviewDefaults';import { isCronExpression, describeCron } from '../../../utils/cronHelpers';import ToggleSwitch from '../../ToggleSwitch';@@ -381,10 +382,9 @@ function GlobalConfigControls({ taskType, config, onUpdate, onTrigger, onReset,/></div>{isPaused && (- <div className="flex items-center gap-2 px-3 py-2 bg-port-warning/10 border border-port-warning/30 rounded text-xs text-port-warning">- <AlertCircle size={14} className="shrink-0" />+ <Banner icon={AlertCircle} className="items-center">All scheduled runs are paused for this task- </div>+ </Banner>)}<div>@@ -1117,16 +1117,12 @@ export default function ScheduleTab({ apps }) {</div>{improvementDisabled && (- <div className="flex items-start gap-2 px-4 py-3 bg-port-warning/10 border border-port-warning/30 rounded-lg text-sm text-port-warning">- <AlertCircle size={16} className="shrink-0 mt-0.5" />- <div>- <div className="font-medium">Improvement is disabled</div>- <div className="text-xs text-port-warning/80 mt-1">- No scheduled or on-demand improvement tasks will run. Enable the <span className="font-mono">Improve</span> toggle in- {' '}<a href="/cos/config" className="underline hover:text-port-warning">CoS → Config</a> to use this page.- </div>+ <Banner size="md" icon={AlertCircle} title="Improvement is disabled">+ <div className="text-xs text-port-warning/80 mt-1">+ No scheduled or on-demand improvement tasks will run. Enable the <span className="font-mono">Improve</span> toggle in+ {' '}<a href="/cos/config" className="underline hover:text-port-warning">CoS → Config</a> to use this page.</div>- </div>+ </Banner>)}{schedule.onDemandRequests?.length > 0 && (diff --git a/client/src/components/settings/LocalSetupPanel.jsx b/client/src/components/settings/LocalSetupPanel.jsxindex 26f2bb5119..76b905b935 100644--- a/client/src/components/settings/LocalSetupPanel.jsx+++ b/client/src/components/settings/LocalSetupPanel.jsx@@ -1,6 +1,7 @@import { useState, useEffect, useCallback, useRef } from 'react';import { CheckCircle2, XCircle, Wand2, RefreshCw, Terminal, AlertTriangle, Box, Cpu } from 'lucide-react';import toast from '../ui/Toast';+import Banner from '../ui/Banner';import BrailleSpinner from '../BrailleSpinner';import { usePrevious } from '../../hooks/usePrevious.js';@@ -200,24 +201,21 @@ export default function LocalSetupPanel({ pythonPath, onPythonPathChange, onPack) : (<>{check.archMismatch && (- <div className="flex items-start gap-2 text-xs text-port-warning bg-port-warning/10 border border-port-warning/30 rounded p-2 mb-3">- <Cpu size={14} className="shrink-0 mt-0.5" />- <div className="flex-1">- <div>- This Python reports <code>{check.interpreterArch}</code> but your Mac is <code>{check.hostArch}</code>.- <code>mlx</code> ships arm64-only wheels — installing it here will fail.- </div>- {check.suggestedArm64Python && (- <button- type="button"- onClick={() => onPythonPathChange(check.suggestedArm64Python)}- className="mt-2 inline-flex items-center gap-1.5 px-2 py-1 text-xs bg-port-accent hover:bg-port-accent/80 text-white rounded"- >- <Wand2 size={12} /> Switch to {check.suggestedArm64Python}- </button>- )}+ <Banner icon={Cpu} className="mb-3">+ <div>+ This Python reports <code>{check.interpreterArch}</code> but your Mac is <code>{check.hostArch}</code>.+ <code>mlx</code> ships arm64-only wheels — installing it here will fail.</div>- </div>+ {check.suggestedArm64Python && (+ <button+ type="button"+ onClick={() => onPythonPathChange(check.suggestedArm64Python)}+ className="mt-2 inline-flex items-center gap-1.5 px-2 py-1 text-xs bg-port-accent hover:bg-port-accent/80 text-white rounded"+ >+ <Wand2 size={12} /> Switch to {check.suggestedArm64Python}+ </button>+ )}+ </Banner>)}<ul className="grid grid-cols-2 gap-x-4 gap-y-1 text-xs mb-3">{check.required.map(pkg => {@@ -234,13 +232,12 @@ export default function LocalSetupPanel({ pythonPath, onPythonPathChange, onPack</ul>{check.externallyManaged && check.missing.length > 0 ? (<div className="space-y-2">- <div className="flex items-start gap-2 text-xs text-port-warning bg-port-warning/10 border border-port-warning/30 rounded p-2">- <AlertTriangle size={14} className="shrink-0 mt-0.5" />+ <Banner icon={AlertTriangle}><div>This Python is <strong>externally managed</strong> (PEP 668) — pip can't install into it.Create a PortOS-owned venv to install packages safely without touching your system Python.</div>- </div>+ </Banner><buttontype="button"onClick={handleCreateVenv}diff --git a/client/src/components/ui/Banner.jsx b/client/src/components/ui/Banner.jsxnew file mode 100644index 0000000000..f8e570bff8--- /dev/null+++ b/client/src/components/ui/Banner.jsx@@ -0,0 +1,81 @@+// Shared semantic-tone banner primitive. Replaces the hand-rolled+// `<div className="bg-port-warning/10 border border-port-warning/30 rounded p-2 …">`+// (and matching success/error/info variants) that were copy-pasted across the+// client.+//+// Knobs map to real call-site shapes — nothing speculative:+// tone — semantic color trio (text + bg-tint + border). `warning` is the+// default since that's the dominant in-repo usage.+// icon — optional leading lucide glyph component (e.g. `AlertTriangle`).+// size — `sm` (px-3 py-2 / text-xs, dense — default), `md` (px-4 py-3 /+// text-sm), or `lg` (p-4 / text-sm). Icon scales with size.+// title — optional bold first line. Body styling is left to children so+// callers can mix tone-muted, gray-400 sub-text, links, etc.+// actions — optional right-side slot (e.g. a button) — sits on the same row+// as the icon + title block.+// className — passthrough for layout tweaks (e.g. `mb-6`); merged after the+// tone classes so callers can override defaults if needed.+//+// Any extra props pass through to the wrapping `<div>`.++// Each tone pre-composes every full class name it needs — Tailwind's JIT+// scans for complete tokens, so `${t.text}/30` would NOT generate the+// `border-port-warning/30` utility. Spell it out.+const TONES = {+ warning: {+ wrapper: 'border-port-warning/30 bg-port-warning/10 text-port-warning',+ iconColor: 'text-port-warning',+ },+ error: {+ wrapper: 'border-port-error/30 bg-port-error/10 text-port-error',+ iconColor: 'text-port-error',+ },+ success: {+ wrapper: 'border-port-success/30 bg-port-success/10 text-port-success',+ iconColor: 'text-port-success',+ },+ info: {+ wrapper: 'border-port-accent/30 bg-port-accent/10 text-port-accent',+ iconColor: 'text-port-accent',+ },+};++const SIZES = {+ sm: { padding: 'px-3 py-2', text: 'text-xs', iconSize: 14, gap: 'gap-2' },+ md: { padding: 'px-4 py-3', text: 'text-sm', iconSize: 16, gap: 'gap-2' },+ lg: { padding: 'p-4', text: 'text-sm', iconSize: 20, gap: 'gap-3' },+};++export default function Banner({+ tone = 'warning',+ icon: Icon,+ size = 'sm',+ title,+ actions,+ className = '',+ children,+ ...rest+}) {+ const t = TONES[tone] || TONES.warning;+ const s = SIZES[size] || SIZES.sm;++ // Border-radius scales with size — small banners use `rounded`, larger ones+ // use `rounded-lg` to match the surrounding call sites in the repo.+ const radius = size === 'lg' || size === 'md' ? 'rounded-lg' : 'rounded';++ return (+ <div+ className={`${s.padding} ${s.text} border ${radius} ${t.wrapper} flex items-start ${s.gap} ${className}`.trim()}+ {...rest}+ >+ {Icon ? (+ <Icon size={s.iconSize} className={`shrink-0 mt-0.5 ${t.iconColor}`} />+ ) : null}+ <div className="flex-1 min-w-0">+ {title ? <div className="font-medium">{title}</div> : null}+ {children}+ </div>+ {actions ? <div className="shrink-0">{actions}</div> : null}+ </div>+ );+}diff --git a/client/src/components/ui/Banner.test.jsx b/client/src/components/ui/Banner.test.jsxnew file mode 100644index 0000000000..f41be54052--- /dev/null+++ b/client/src/components/ui/Banner.test.jsx@@ -0,0 +1,62 @@+import { describe, it, expect } from 'vitest';+import { render, screen } from '@testing-library/react';+import { AlertTriangle } from 'lucide-react';++import Banner from './Banner';++describe('Banner', () => {+ it('renders children with the default warning tone, sm size, and rounded border', () => {+ render(<Banner>hi</Banner>);+ const body = screen.getByText('hi');+ const wrapper = body.closest('div.flex');+ expect(wrapper.className).toContain('bg-port-warning/10');+ expect(wrapper.className).toContain('border-port-warning/30');+ expect(wrapper.className).toContain('text-port-warning');+ expect(wrapper.className).toContain('text-xs');+ expect(wrapper.className).toContain('px-3');+ expect(wrapper.className).toContain('py-2');+ expect(wrapper.className.split(/\s+/)).toContain('rounded');+ });++ it('applies the requested tone', () => {+ render(<Banner tone="error">x</Banner>);+ const wrapper = screen.getByText('x').closest('div.flex');+ expect(wrapper.className).toContain('bg-port-error/10');+ expect(wrapper.className).toContain('border-port-error/30');+ expect(wrapper.className).toContain('text-port-error');+ });++ it('uses rounded-lg + larger padding/icon at size="lg"', () => {+ render(<Banner size="lg" icon={AlertTriangle}>x</Banner>);+ const wrapper = screen.getByText('x').closest('div.flex');+ expect(wrapper.className).toContain('p-4');+ expect(wrapper.className).toContain('text-sm');+ expect(wrapper.className).toContain('rounded-lg');+ });++ it('renders the icon with the tone color class', () => {+ const { container } = render(<Banner tone="info" icon={AlertTriangle}>x</Banner>);+ const svg = container.querySelector('svg');+ expect(svg).not.toBeNull();+ expect(svg.getAttribute('class')).toContain('text-port-accent');+ });++ it('renders a bold title above the children when supplied', () => {+ render(<Banner title="Heads up">details below</Banner>);+ const titleEl = screen.getByText('Heads up');+ expect(titleEl.className).toContain('font-medium');+ expect(screen.getByText('details below')).toBeTruthy();+ });++ it('renders an actions slot when supplied', () => {+ render(<Banner actions={<button>Do it</button>}>msg</Banner>);+ expect(screen.getByRole('button', { name: 'Do it' })).toBeTruthy();+ });++ it('merges passthrough className after tone classes', () => {+ render(<Banner className="mb-6 custom-flag">x</Banner>);+ const wrapper = screen.getByText('x').closest('div.flex');+ expect(wrapper.className).toContain('mb-6');+ expect(wrapper.className).toContain('custom-flag');+ });+});diff --git a/client/src/pages/Loras.jsx b/client/src/pages/Loras.jsxindex ed27e25510..ec4f3f96ef 100644--- a/client/src/pages/Loras.jsx+++ b/client/src/pages/Loras.jsx@@ -12,6 +12,7 @@ import { Link } from 'react-router-dom';import { Trash2, Download, ExternalLink, Sparkles, AlertTriangle, KeyRound, Check, X, RefreshCw, Wand2 } from 'lucide-react';import toast from '../components/ui/Toast';import Modal from '../components/ui/Modal';+import Banner from '../components/ui/Banner';import { formatBytes } from '../utils/formatters';import { RUNNER_FAMILIES } from '../lib/runnerFamilies';import {@@ -498,10 +499,7 @@ function CivitaiAuthModal({ pendingUrl, message, auth, onClose, onSaved, onRetry</div>{message && (- <div className="text-xs bg-port-warning/10 border border-port-warning/30 rounded px-3 py-2 text-amber-100 flex items-start gap-2">- <AlertTriangle size={14} className="shrink-0 mt-0.5 text-port-warning" />- <span>{message}</span>- </div>+ <Banner icon={AlertTriangle}>{message}</Banner>)}<p className="text-xs text-gray-400 leading-relaxed">diff --git a/client/src/pages/Security.jsx b/client/src/pages/Security.jsxindex 7e653526ad..2301b8f19d 100644--- a/client/src/pages/Security.jsx+++ b/client/src/pages/Security.jsx@@ -1,6 +1,7 @@import { useState, useRef, useEffect, useCallback } from 'react';import { Camera, Mic, MicOff, Video, VideoOff, RefreshCw, Settings, Volume2 } from 'lucide-react';import api from '../services/api';+import Banner from '../components/ui/Banner';const MEDIA_CONSTRAINTS_KEY = 'portos-media-constraints';@@ -276,25 +277,24 @@ export default function Security() {{/* Audio interaction prompt for mobile browsers */}{audioNeedsInteraction && streaming && audioEnabled && (- <div className="mb-6 p-4 bg-port-warning/10 border border-port-warning/30 rounded-lg">- <div className="flex items-center justify-between gap-4">- <div className="flex items-center gap-3">- <Volume2 size={20} className="text-port-warning" />- <div>- <p className="text-port-warning font-medium">Audio requires interaction</p>- <p className="text-sm text-gray-400 mt-1">- Your browser requires user interaction to enable audio playback- </p>- </div>- </div>+ <Banner+ size="lg"+ icon={Volume2}+ title="Audio requires interaction"+ className="mb-6 items-center"+ actions={<buttononClick={enableAudio}className="px-4 py-2 bg-port-warning text-white rounded-lg font-medium hover:bg-port-warning/80 transition-colors whitespace-nowrap">Enable Audio</button>- </div>- </div>+ }+ >+ <p className="text-sm text-gray-400 mt-1">+ Your browser requires user interaction to enable audio playback+ </p>+ </Banner>)}{/* Settings panel */}