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(city): waterfront Data Harbor district visualizing the DB and data/ filesystem
[._.]/ Adam Eivyfdb503c2ba07
diff --git a/client/src/components/city/CityDataHarbor.jsx b/client/src/components/city/CityDataHarbor.jsxnew file mode 100644index 0000000000..f898ee9607--- /dev/null+++ b/client/src/components/city/CityDataHarbor.jsx@@ -0,0 +1,273 @@+import { useMemo, useRef, useState, useCallback } from 'react';+import { useFrame } from '@react-three/fiber';+import { Html } from '@react-three/drei';+import { PIXEL_FONT_URL, cityDayMix } from './cityConstants';+import { useCityPalette } from './CityPaletteContext';+import CityLabel from './CityLabel';+import { computeDataHarbor, DATA_HARBOR } from '../../utils/cityDataHarbor';+import { WORLD } from '../../utils/cityPlan';++// CyberCity's Data Harbor: a pier district over the bay (master plan, north shore) that+// renders GET /api/city/introspection — the database quay (one disk-stack silo per Postgres+// table, an orbiting ring on pgvector tables, a migration obelisk) beside the archive racks+// (one container rack per data/ domain, lit slats tracking disk usage). Clicking a silo or+// rack opens a holographic detail card. Mirrors CityMemoryDistrict: the pure helper does+// all topology, this component only renders + animates.++const DECK_COLOR = '#10182a';+const PYLON_COLOR = '#0a0f1c';+const OFFLINE_COLOR = '#ef4444';++// Holographic info card for a clicked silo/rack — same visual language as+// HolographicPanel.jsx (the app-building hologram).+function HarborHoloCard({ selected }) {+ const { kind, data } = selected;+ const accentClass = kind === 'silo' ? 'border-cyan-500/50 text-cyan-300' : 'border-violet-500/50 text-violet-300';+ return (+ <Html position={[data.x, DATA_HARBOR.deckY + data.height + 2.6, data.z]} center distanceFactor={12} style={{ pointerEvents: 'none' }}>+ <div className={`bg-black/90 border ${accentClass} rounded-md px-3 py-2 whitespace-nowrap backdrop-blur-sm`} style={{ boxShadow: '0 0 16px rgba(6,182,212,0.25)' }}>+ <div className="font-pixel tracking-wider font-bold text-[12px] max-w-[180px] truncate">{data.label}</div>+ {kind === 'silo' ? (+ <div className="text-[9px] font-pixel tracking-wide mt-1 space-y-0.5 text-gray-300">+ <div>{data.rowEstimate.toLocaleString()} rows</div>+ <div>{data.bytesLabel}</div>+ {data.hasEmbedding && <div className="text-pink-400">pgvector embeddings</div>}+ </div>+ ) : (+ <div className="text-[9px] font-pixel tracking-wide mt-1 space-y-0.5 text-gray-300">+ <div>{data.sublabel}</div>+ <div>{data.files.toLocaleString()} files</div>+ <div className="text-gray-500">data/{data.name === '(root)' ? '' : data.name}</div>+ </div>+ )}+ </div>+ </Html>+ );+}++// One database table: a stack of glowing disks on a dark plinth; pgvector tables carry a+// slowly orbiting ring (rotated by the parent's single useFrame via ringRefs).+function TableSilo({ silo, onSelect, registerRing, dayMix }) {+ const disks = useMemo(() => Array.from({ length: silo.diskCount }, (_, i) => i), [silo.diskCount]);+ const [hovered, setHovered] = useState(false);+ const step = DATA_HARBOR.diskHeight + DATA_HARBOR.diskGap;+ return (+ <group position={[silo.x, DATA_HARBOR.deckY, silo.z]}>+ <group+ onClick={(e) => { e.stopPropagation(); onSelect(); }}+ onPointerEnter={() => setHovered(true)}+ onPointerLeave={() => setHovered(false)}+ >+ {/* Plinth */}+ <mesh position={[0, 0.1, 0]}>+ <cylinderGeometry args={[silo.diskRadius + 0.25, silo.diskRadius + 0.35, 0.2, 16]} />+ <meshStandardMaterial color={PYLON_COLOR} roughness={0.8} />+ </mesh>+ {disks.map((i) => (+ <mesh key={i} position={[0, 0.2 + step * i + DATA_HARBOR.diskHeight / 2, 0]}>+ <cylinderGeometry args={[silo.diskRadius, silo.diskRadius, DATA_HARBOR.diskHeight, 20]} />+ <meshStandardMaterial+ color={silo.color}+ emissive={silo.color}+ // The top disk reads as the silo's "live" surface; lower disks dim slightly.+ emissiveIntensity={(i === silo.diskCount - 1 ? 0.55 : 0.28) + (hovered ? 0.3 : 0)}+ metalness={0.4}+ roughness={0.3}+ toneMapped={false}+ />+ </mesh>+ ))}+ </group>+ {silo.hasEmbedding && (+ <mesh ref={registerRing} position={[0, 0.2 + step * silo.diskCount + 0.35, 0]} rotation={[Math.PI / 2.6, 0, 0]}>+ <torusGeometry args={[silo.diskRadius + 0.45, 0.05, 8, 32]} />+ <meshBasicMaterial color={silo.color} transparent opacity={0.7} toneMapped={false} />+ </mesh>+ )}+ <CityLabel position={[0, silo.height + 1.5, 0]} fontSize={0.42} color={silo.color} dayMix={dayMix} anchorX="center" anchorY="middle" font={PIXEL_FONT_URL} maxWidth={7}>+ {silo.label}+ </CityLabel>+ <CityLabel position={[0, silo.height + 1.05, 0]} fontSize={0.3} color="#94a3b8" dayMix={dayMix} anchorX="center" anchorY="middle" font={PIXEL_FONT_URL} maxWidth={7}>+ {silo.sublabel}+ </CityLabel>+ </group>+ );+}++// One data/ domain: a container rack whose lit slat count tracks its share of disk usage.+function DomainRack({ rack, accent, tintStructure, onSelect, dayMix }) {+ const [hovered, setHovered] = useState(false);+ const slats = useMemo(() => Array.from({ length: DATA_HARBOR.rackSlats }, (_, i) => i), []);+ const slatStep = (rack.height - 0.6) / DATA_HARBOR.rackSlats;+ return (+ <group position={[rack.x, DATA_HARBOR.deckY, rack.z]}>+ <group+ onClick={(e) => { e.stopPropagation(); onSelect(); }}+ onPointerEnter={() => setHovered(true)}+ onPointerLeave={() => setHovered(false)}+ >+ <mesh position={[0, rack.height / 2, 0]}>+ <boxGeometry args={[rack.width, rack.height, rack.depth]} />+ <meshStandardMaterial color={tintStructure(DECK_COLOR)} roughness={0.6} metalness={0.3} />+ </mesh>+ {/* Slat rows on the front (bay-facing) face — lit bottom-up by fill ratio. */}+ {slats.map((i) => {+ const lit = i < rack.litSlats;+ return (+ <mesh key={i} position={[0, 0.45 + i * slatStep, rack.depth / 2 + 0.02]}>+ <boxGeometry args={[rack.width - 0.5, slatStep * 0.45, 0.05]} />+ <meshStandardMaterial+ color={lit ? accent : '#1f2937'}+ emissive={lit ? accent : '#000000'}+ emissiveIntensity={lit ? 0.6 + (hovered ? 0.3 : 0) : 0}+ toneMapped={false}+ />+ </mesh>+ );+ })}+ </group>+ <CityLabel position={[0, rack.height + 1.2, 0]} fontSize={0.42} color={accent} dayMix={dayMix} anchorX="center" anchorY="middle" font={PIXEL_FONT_URL} maxWidth={7}>+ {rack.label}+ </CityLabel>+ <CityLabel position={[0, rack.height + 0.75, 0]} fontSize={0.3} color="#94a3b8" dayMix={dayMix} anchorX="center" anchorY="middle" font={PIXEL_FONT_URL} maxWidth={7}>+ {rack.sublabel}+ </CityLabel>+ </group>+ );+}++// A pier deck on pylons over the water.+function PierDeck({ x, z, width, depth, tintStructure }) {+ const pylons = useMemo(() => {+ const out = [];+ const halfW = width / 2 - 0.6;+ const halfD = depth / 2 - 0.6;+ for (const px of [-halfW, halfW]) {+ for (const pz of [-halfD, halfD]) out.push([x + px, pz + z]);+ }+ return out;+ }, [x, z, width, depth]);+ return (+ <group>+ <mesh position={[x, DATA_HARBOR.deckY - 0.15, z]}>+ <boxGeometry args={[width, 0.3, depth]} />+ <meshStandardMaterial color={tintStructure(DECK_COLOR)} roughness={0.7} metalness={0.25} />+ </mesh>+ {pylons.map(([px, pz], i) => (+ <mesh key={i} position={[px, WORLD.waterY - 0.8, pz]}>+ <cylinderGeometry args={[0.28, 0.34, 3, 8]} />+ <meshStandardMaterial color={PYLON_COLOR} roughness={0.9} />+ </mesh>+ ))}+ </group>+ );+}++export default function CityDataHarbor({ introspection, settings }) {+ const { accent, tintStructure } = useCityPalette();+ const district = useMemo(() => computeDataHarbor(introspection), [introspection]);+ const [selected, setSelected] = useState(null);+ const dayMix = cityDayMix(settings);+ const animate = (settings?.particleDensity ?? 1) >= 0.5;++ // All pgvector rings spin from one frame callback (single mutation site).+ const ringRefs = useRef([]);+ ringRefs.current = [];+ const registerRing = useCallback((el) => { if (el) ringRefs.current.push(el); }, []);+ const offlineRef = useRef();++ useFrame(({ clock }) => {+ const t = clock.getElapsedTime();+ if (animate) {+ for (const ring of ringRefs.current) ring.rotation.z = t * 0.6;+ }+ if (offlineRef.current) {+ offlineRef.current.material.emissiveIntensity = 0.5 + ((Math.sin(t * 2.2) + 1) / 2) * 0.6;+ }+ });++ if (district.empty) return null;++ const [bx, , bz] = district.base;+ const { silos, racks, obelisk, totals, overflow, dbDown } = district;+ const select = (kind, data) => setSelected((prev) =>+ prev && prev.kind === kind && prev.data.name === data.name ? null : { kind, data });++ return (+ <group>+ {/* Gangway from the shoreline avenue out to the pier head. */}+ <PierDeck x={bx} z={(WORLD.shorelineZ + bz) / 2} width={4.6} depth={Math.abs(bz - WORLD.shorelineZ) + 2} tintStructure={tintStructure} />+ {/* West quay (database silos) + east yard (archive racks). */}+ <PierDeck x={bx - 11} z={bz - 0.6} width={15} depth={11} tintStructure={tintStructure} />+ <PierDeck x={bx + 11} z={bz - 0.6} width={15} depth={11} tintStructure={tintStructure} />++ {silos.map((silo) => (+ <TableSilo+ key={silo.name}+ silo={silo}+ onSelect={() => select('silo', silo)}+ registerRing={registerRing}+ dayMix={dayMix}+ />+ ))}++ {/* DB offline: the quay keeps its deck but flies a pulsing red beacon. */}+ {dbDown && (+ <group position={[bx - 11, DATA_HARBOR.deckY, bz - 0.6]}>+ <mesh ref={offlineRef} position={[0, 1.6, 0]}>+ <octahedronGeometry args={[0.9, 0]} />+ <meshStandardMaterial color={OFFLINE_COLOR} emissive={OFFLINE_COLOR} emissiveIntensity={0.8} toneMapped={false} />+ </mesh>+ <CityLabel position={[0, 3.4, 0]} fontSize={0.7} color={OFFLINE_COLOR} dayMix={dayMix} anchorX="center" anchorY="middle" font={PIXEL_FONT_URL} maxWidth={10}>+ DB OFFLINE+ </CityLabel>+ </group>+ )}++ {racks.map((rack) => (+ <DomainRack+ key={rack.name}+ rack={rack}+ accent={accent}+ tintStructure={tintStructure}+ onSelect={() => select('rack', rack)}+ dayMix={dayMix}+ />+ ))}++ {/* Migration obelisk at the pier head. */}+ {obelisk && (+ <group position={[bx, DATA_HARBOR.deckY, bz - 7]}>+ <mesh position={[0, 1.8, 0]}>+ <boxGeometry args={[0.7, 3.6, 0.7]} />+ <meshStandardMaterial color={tintStructure('#16213a')} emissive={accent} emissiveIntensity={0.18} roughness={0.4} toneMapped={false} />+ </mesh>+ <mesh position={[0, 3.85, 0]}>+ <octahedronGeometry args={[0.45, 0]} />+ <meshStandardMaterial color={accent} emissive={accent} emissiveIntensity={0.7} toneMapped={false} />+ </mesh>+ <CityLabel position={[0, 5, 0]} fontSize={0.42} color={accent} dayMix={dayMix} anchorX="center" anchorY="middle" font={PIXEL_FONT_URL} maxWidth={8}>+ {`${obelisk.applied} MIGRATIONS`}+ </CityLabel>+ </group>+ )}++ {/* District title + totals, tall enough to read from the shore. */}+ <CityLabel position={[bx, 11, bz - 2]} fontSize={1.4} color={accent} dayMix={dayMix} anchorX="center" anchorY="middle" font={PIXEL_FONT_URL} maxWidth={30}>+ DATA HARBOR+ </CityLabel>+ <CityLabel position={[bx, 9.9, bz - 2]} fontSize={0.7} color="#94a3b8" dayMix={dayMix} anchorX="center" anchorY="middle" font={PIXEL_FONT_URL} maxWidth={34}>+ {dbDown+ ? (totals.fsLabel ? `FILES ${totals.fsLabel}` : 'NO DATA')+ : `${totals.tableCount} TABLES${totals.dbSizeLabel ? ` ${totals.dbSizeLabel}` : ''}${totals.fsLabel ? ` • FILES ${totals.fsLabel}` : ''}`}+ </CityLabel>+ {(overflow.tables > 0 || overflow.domains > 0) && (+ <CityLabel position={[bx, 9.1, bz - 2]} fontSize={0.45} color="#64748b" dayMix={dayMix} anchorX="center" anchorY="middle" font={PIXEL_FONT_URL} maxWidth={30}>+ {`+${overflow.tables + overflow.domains} MORE`}+ </CityLabel>+ )}++ {selected && <HarborHoloCard selected={selected} />}+ </group>+ );+}diff --git a/client/src/components/city/CityScene.jsx b/client/src/components/city/CityScene.jsxindex 7796370917..16252ccda9 100644--- a/client/src/components/city/CityScene.jsx+++ b/client/src/components/city/CityScene.jsx@@ -28,6 +28,7 @@ import CitySeasonalDecor from './CitySeasonalDecor';import CityEasterEggs from './CityEasterEggs';import CityVoiceMarker from './CityVoiceMarker';import CityMemoryDistrict from './CityMemoryDistrict';+import CityDataHarbor from './CityDataHarbor';import CityJiraDistrict from './CityJiraDistrict';import CityAiCore from './CityAiCore';import CityDataRain from './CityDataRain';@@ -47,7 +48,7 @@ import { cityDayMix } from './cityConstants';import { CityPaletteProvider } from './CityPaletteContext';import ErrorBoundary from '../ErrorBoundary';-export default function CityScene({ apps, agentMap, onBuildingClick, cosStatus, reviewCounts, instances, backupStatus, cosTasks, healthMetrics, voiceState, aiActivity, productivityData, activityCalendar, goals, character, chronotype, memoryGraph, inboxDepth, jiraTickets, playback = false, photoMode, photoPresetId, photoDof, onPhotoCaptureReady, settings, playSfx, keysRef, dimmedAppIds, background, palette }) {+export default function CityScene({ apps, agentMap, onBuildingClick, cosStatus, reviewCounts, instances, backupStatus, cosTasks, healthMetrics, voiceState, aiActivity, productivityData, activityCalendar, goals, character, chronotype, memoryGraph, inboxDepth, jiraTickets, introspection, playback = false, photoMode, photoPresetId, photoDof, onPhotoCaptureReady, settings, playSfx, keysRef, dimmedAppIds, background, palette }) {const [positions, setPositions] = useState(null);const [proximityApp, setProximityApp] = useState(null);const [transitioning, setTransitioning] = useState(false);@@ -221,6 +222,7 @@ export default function CityScene({ apps, agentMap, onBuildingClick, cosStatus,<CityEasterEggs character={character} goals={goals} productivityData={productivityData} settings={settings} /><CityVoiceMarker voiceState={voiceState} settings={settings} /><CityMemoryDistrict memoryGraph={memoryGraph} inboxDepth={inboxDepth} settings={settings} />+ <CityDataHarbor introspection={introspection} settings={settings} /><CityJiraDistrict jiraTickets={jiraTickets} settings={settings} /><CityAiCore aiActivity={aiActivity} positions={positions} apps={apps} settings={settings} /><CityGround settings={settings} />diff --git a/client/src/pages/CyberCity.jsx b/client/src/pages/CyberCity.jsxindex 8ccdc308f2..cfa26414ef 100644--- a/client/src/pages/CyberCity.jsx+++ b/client/src/pages/CyberCity.jsx@@ -231,6 +231,14 @@ function CyberCityInner() {60_000,);+ // Storage introspection drives the Data Harbor district (DB table silos + data/ domain+ // racks on the waterfront). Server-side cache does the heavy lifting; a 2-minute poll+ // keeps the harbor current. Same last-good-snapshot semantics as the fetches above.+ const { data: introspection } = useAutoRefetch(+ () => api.getCityIntrospection({ silent: true }),+ 120_000,+ );+// JIRA sprint district: the set of apps with JIRA wired up (each carries instanceId+projectKey),// collapsed to a stable signature that gates and re-triggers the poll only when that set changes.const jiraAppsKey = useMemo(@@ -351,6 +359,7 @@ function CyberCityInner() {memoryGraph={memoryGraph}inboxDepth={inboxData?.counts?.needs_review ?? 0}jiraTickets={jiraTickets}+ introspection={introspection}playback={playback.active}photoMode={photoMode}photoPresetId={photoPresetId}diff --git a/client/src/services/apiCity.js b/client/src/services/apiCity.jsindex b268badeef..5b16628097 100644--- a/client/src/services/apiCity.js+++ b/client/src/services/apiCity.js@@ -21,3 +21,8 @@ export const getCitySnapshotConfig = (options = {}) =>// POST /api/city/snapshots/capture — capture a frame on demand.export const captureCitySnapshot = (options = {}) =>request('/city/snapshots/capture', { method: 'POST', ...options });++// GET /api/city/introspection — DB tables + data/ domain sizes for the Data+// Harbor district. Server-cached; `db: null` means the database is unreachable.+export const getCityIntrospection = (options = {}) =>+ request('/city/introspection', options);diff --git a/client/src/utils/README.md b/client/src/utils/README.mdindex 4fab265da9..f8bf160c7b 100644--- a/client/src/utils/README.md+++ b/client/src/utils/README.md@@ -71,6 +71,7 @@ its tunable constants and placement helpers.| `cityArtifacts` | Earned-artifact milestones (level/goal/streak) → placed artifact descriptors (`computeArtifacts`). || `cityBackupVault` | Backup-vault health/alerting state and color (`computeBackupVault`, `vaultHealth`). || `cityChronotype` | Chronotype energy curve by hour → brightness/tempo modifiers (`computeChronotypeEnergy`). |+| `cityDataHarbor` | Data Harbor pier district: DB table silos + data/ domain racks from /api/city/introspection (`computeDataHarbor`). || `cityDistrictLayout` | Shared district layout math: auto-columns, grid placement, tallying, metric→height scaling. || `cityEasterEggs` | Unlockable easter eggs from context (date/character/goals) → placements (`computeEasterEggs`). || `cityFederation` | Sync-peer reachability horizon: status color/opacity, bridge state, peer placement (`computeFederationHorizon`). |diff --git a/client/src/utils/cityDataHarbor.js b/client/src/utils/cityDataHarbor.jsnew file mode 100644index 0000000000..ad5a1d8b65--- /dev/null+++ b/client/src/utils/cityDataHarbor.js@@ -0,0 +1,167 @@+// Pure, deterministic helpers for CyberCity's Data Harbor: a pier district over the bay+// (master-plan parcel `dataHarbor`, north shore) that makes the install's storage legible+// at a glance. The PostgreSQL datastore becomes the **database quay** — one disk-stack silo+// per table, stack height log-scaled by row count, disk radius log-scaled by relation size,+// an orbiting ring marking pgvector (embedding) tables, and a migration obelisk at the pier+// head. The `data/` filesystem becomes the **archive racks** — one shipping-container rack+// per domain directory, lit slats log-scaled by disk usage. Data arrives from+// GET /api/city/introspection; `db: null` (unreachable) renders as a dimmed offline quay,+// distinct from a reachable-but-empty database. No three.js / React imports so the topology+// is unit-testable (mirrors cityMemoryDistrict.js / cityTaskQueue.js).++import { hashString } from './hashString';+import { formatBytes } from './formatters';+import { PARCELS } from './cityPlan';++export const DATA_HARBOR = {+ base: PARCELS.dataHarbor.anchor, // pier district over the bay (see cityPlan.js)+ deckY: 0.55, // pier deck height above the water+ maxSilos: 10, // visible table-silo cap; the rest fold into the overflow count+ maxRacks: 8, // visible domain-rack cap+ siloSpacing: 3.6, // x-distance between adjacent silos+ siloRowGap: 4.4, // z-distance between the two silo rows+ diskHeight: 0.42, // one disk in a silo stack+ diskGap: 0.14, // vertical gap between disks+ minDisks: 1,+ maxDisks: 7, // a packed table stays a legible stack, not a tower+ minDiskRadius: 0.65,+ maxDiskRadius: 1.35,+ rackSpacing: 3.1, // x-distance between adjacent racks+ rackWidth: 2.3,+ rackDepth: 1.6,+ rackHeight: 3.2,+ rackSlats: 8, // emissive slat rows per rack; lit count tracks the fill ratio+};++// Deterministic silo color per table name — the city's neon spread, hashed so a table keeps+// its color across refetches and installs.+const PALETTE = ['#06b6d4', '#ec4899', '#8b5cf6', '#22c55e', '#f59e0b', '#3b82f6', '#f43f5e', '#a855f7'];+export function tableColor(name) {+ return PALETTE[hashString(String(name || '')) % PALETTE.length];+}++const clamp = (n, lo, hi) => Math.min(hi, Math.max(lo, n));++// log2-scale `value` into [0, 1] against `max` (both floored at 0). A zero max yields 0.+const logRatio = (value, max) => {+ const v = Math.max(0, Number.isFinite(value) ? value : 0);+ const m = Math.max(0, Number.isFinite(max) ? max : 0);+ if (m <= 0) return 0;+ return clamp(Math.log2(1 + v) / Math.log2(1 + m), 0, 1);+};++const shortCount = (n) => {+ if (!Number.isFinite(n)) return '0';+ if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M`;+ if (n >= 1_000) return `${(n / 1_000).toFixed(1)}K`;+ return String(n);+};++// Silo geometry for the visible top-N tables (already size-sorted by the server; re-sorted+// here defensively). Two rows: the heavyweights up front (bay side), the rest behind.+function computeSilos(tables) {+ const sorted = [...tables].sort((a, b) => (b.totalBytes ?? 0) - (a.totalBytes ?? 0));+ const visible = sorted.slice(0, DATA_HARBOR.maxSilos);+ const maxRows = Math.max(...visible.map((t) => t.rowEstimate ?? 0), 0);+ const maxBytes = Math.max(...visible.map((t) => t.totalBytes ?? 0), 0);+ const [bx, , bz] = DATA_HARBOR.base;+ const perRow = Math.ceil(visible.length / 2);++ return visible.map((table, i) => {+ const row = i < perRow ? 0 : 1;+ const col = row === 0 ? i : i - perRow;+ const rowCount = row === 0 ? perRow : visible.length - perRow;+ const rowWidth = (rowCount - 1) * DATA_HARBOR.siloSpacing;+ const diskCount = clamp(+ Math.round(1 + logRatio(table.rowEstimate, maxRows) * (DATA_HARBOR.maxDisks - 1)),+ DATA_HARBOR.minDisks,+ DATA_HARBOR.maxDisks,+ );+ const diskRadius = DATA_HARBOR.minDiskRadius+ + logRatio(table.totalBytes, maxBytes) * (DATA_HARBOR.maxDiskRadius - DATA_HARBOR.minDiskRadius);+ return {+ name: table.name,+ x: bx - 11 + col * DATA_HARBOR.siloSpacing - rowWidth / 2 + (row === 0 ? 0 : DATA_HARBOR.siloSpacing / 2),+ z: bz + (row === 0 ? 1.5 : 1.5 - DATA_HARBOR.siloRowGap),+ diskCount,+ diskRadius,+ height: diskCount * (DATA_HARBOR.diskHeight + DATA_HARBOR.diskGap),+ hasEmbedding: Boolean(table.hasEmbedding),+ color: tableColor(table.name),+ rowEstimate: table.rowEstimate ?? 0,+ totalBytes: table.totalBytes ?? 0,+ label: String(table.name || '').toUpperCase(),+ sublabel: `${shortCount(table.rowEstimate ?? 0)} ROWS`,+ bytesLabel: formatBytes(table.totalBytes ?? 0),+ };+ });+}++// Rack geometry for the visible top-N data/ domains (server sorts by size; defensively+// re-sorted). Two rows on the east pier — a tight container yard.+function computeRacks(domains) {+ const sorted = [...domains].sort((a, b) => (b.bytes ?? 0) - (a.bytes ?? 0));+ const visible = sorted.slice(0, DATA_HARBOR.maxRacks);+ const maxBytes = Math.max(...visible.map((d) => d.bytes ?? 0), 0);+ const [bx, , bz] = DATA_HARBOR.base;+ const perRow = Math.ceil(visible.length / 2);++ return visible.map((domain, i) => {+ const row = i < perRow ? 0 : 1;+ const col = row === 0 ? i : i - perRow;+ const rowCount = row === 0 ? perRow : visible.length - perRow;+ const rowWidth = (rowCount - 1) * DATA_HARBOR.rackSpacing;+ const fillRatio = logRatio(domain.bytes, maxBytes);+ return {+ name: domain.name,+ x: bx + 11 + col * DATA_HARBOR.rackSpacing - rowWidth / 2,+ z: bz + (row === 0 ? 1.5 : 1.5 - DATA_HARBOR.siloRowGap),+ width: DATA_HARBOR.rackWidth,+ depth: DATA_HARBOR.rackDepth,+ height: DATA_HARBOR.rackHeight,+ fillRatio,+ litSlats: clamp(Math.round(fillRatio * DATA_HARBOR.rackSlats), domain.bytes > 0 ? 1 : 0, DATA_HARBOR.rackSlats),+ bytes: domain.bytes ?? 0,+ files: domain.files ?? 0,+ label: String(domain.name || '').toUpperCase(),+ sublabel: formatBytes(domain.bytes ?? 0),+ };+ });+}++// The whole district model from one introspection payload.+// - introspection missing entirely → { empty: true } (nothing renders — first load)+// - db: null → dbDown: true (quay renders dimmed + "DB OFFLINE")+// - fs: null → racks: [] (rack pier renders empty deck)+export function computeDataHarbor(introspection) {+ if (!introspection || typeof introspection !== 'object') return { empty: true };++ const db = introspection.db && Array.isArray(introspection.db.tables) ? introspection.db : null;+ const fsSection = introspection.fs && Array.isArray(introspection.fs.domains) ? introspection.fs : null;+ const tables = db?.tables ?? [];+ const domains = fsSection?.domains ?? [];++ return {+ empty: false,+ dbDown: !db,+ base: DATA_HARBOR.base,+ silos: computeSilos(tables),+ racks: computeRacks(domains),+ obelisk: db?.migrations+ ? { applied: db.migrations.applied ?? 0, lastApplied: db.migrations.lastApplied ?? null }+ : null,+ totals: {+ tableCount: tables.length,+ dbSizeBytes: db?.sizeBytes ?? null,+ dbSizeLabel: db?.sizeBytes != null ? formatBytes(db.sizeBytes) : null,+ fsBytes: fsSection?.totalBytes ?? null,+ fsLabel: fsSection?.totalBytes != null ? formatBytes(fsSection.totalBytes) : null,+ fsFiles: fsSection?.totalFiles ?? null,+ domainCount: domains.length,+ },+ overflow: {+ tables: Math.max(0, tables.length - DATA_HARBOR.maxSilos),+ domains: Math.max(0, domains.length - DATA_HARBOR.maxRacks),+ },+ };+}diff --git a/client/src/utils/cityDataHarbor.test.js b/client/src/utils/cityDataHarbor.test.jsnew file mode 100644index 0000000000..d04f9d1f54--- /dev/null+++ b/client/src/utils/cityDataHarbor.test.js@@ -0,0 +1,132 @@+import { describe, it, expect } from 'vitest';+import { computeDataHarbor, tableColor, DATA_HARBOR } from './cityDataHarbor';+import { PARCELS, isInWater, WORLD } from './cityPlan';++const table = (name, rowEstimate, totalBytes, hasEmbedding = false) =>+ ({ name, rowEstimate, totalBytes, hasEmbedding });+const domain = (name, bytes, files) => ({ name, bytes, files });++const happyIntrospection = () => ({+ ts: '2026-06-09T00:00:00.000Z',+ db: {+ sizeBytes: 5_000_000,+ tables: [+ table('memories', 1200, 900_000, true),+ table('catalog_scraps', 40, 50_000, true),+ table('schema_migrations', 12, 8_000),+ ],+ migrations: { applied: 12, lastApplied: '2026-06-01T00:00:00.000Z' },+ },+ fs: {+ domains: [domain('images', 3_100_000_000, 2400), domain('brain', 800_000, 60)],+ totalBytes: 3_100_800_000,+ totalFiles: 2460,+ },+});++describe('computeDataHarbor', () => {+ it('returns empty for a missing payload (nothing fetched yet)', () => {+ expect(computeDataHarbor(null)).toEqual({ empty: true });+ expect(computeDataHarbor(undefined)).toEqual({ empty: true });+ });++ it('flags dbDown when db is null without losing the filesystem racks', () => {+ const district = computeDataHarbor({ ...happyIntrospection(), db: null });+ expect(district.dbDown).toBe(true);+ expect(district.silos).toEqual([]);+ expect(district.obelisk).toBeNull();+ expect(district.racks).toHaveLength(2);+ });++ it('distinguishes a reachable-but-empty db from a down one', () => {+ const district = computeDataHarbor({+ ts: 'x',+ db: { sizeBytes: 1000, tables: [], migrations: null },+ fs: { domains: [], totalBytes: 0, totalFiles: 0 },+ });+ expect(district.dbDown).toBe(false);+ expect(district.silos).toEqual([]);+ });++ it('builds one silo per table with monotonic log scaling', () => {+ const district = computeDataHarbor(happyIntrospection());+ expect(district.silos).toHaveLength(3);+ const byName = Object.fromEntries(district.silos.map((s) => [s.name, s]));+ // More rows → at least as many disks; more bytes → at least as wide.+ expect(byName.memories.diskCount).toBeGreaterThanOrEqual(byName.catalog_scraps.diskCount);+ expect(byName.catalog_scraps.diskCount).toBeGreaterThanOrEqual(byName.schema_migrations.diskCount);+ expect(byName.memories.diskRadius).toBeGreaterThanOrEqual(byName.catalog_scraps.diskRadius);+ expect(byName.memories.diskCount).toBeLessThanOrEqual(DATA_HARBOR.maxDisks);+ // Embedding flag passes through.+ expect(byName.memories.hasEmbedding).toBe(true);+ expect(byName.schema_migrations.hasEmbedding).toBe(false);+ // Labels are render-ready.+ expect(byName.memories.label).toBe('MEMORIES');+ expect(byName.memories.sublabel).toBe('1.2K ROWS');+ });++ it('caps silos/racks at the visible max and reports the overflow', () => {+ const intro = happyIntrospection();+ intro.db.tables = Array.from({ length: 14 }, (_, i) => table(`t${i}`, i * 10, i * 1000));+ intro.fs.domains = Array.from({ length: 11 }, (_, i) => domain(`d${i}`, i * 1000, i));+ const district = computeDataHarbor(intro);+ expect(district.silos).toHaveLength(DATA_HARBOR.maxSilos);+ expect(district.racks).toHaveLength(DATA_HARBOR.maxRacks);+ expect(district.overflow).toEqual({ tables: 4, domains: 3 });+ // The visible set is the biggest-by-size, not the first-N.+ expect(district.silos.map((s) => s.name)).toContain('t13');+ expect(district.silos.map((s) => s.name)).not.toContain('t0');+ });++ it('keeps every structure inside the harbor parcel, over the water', () => {+ const intro = happyIntrospection();+ intro.db.tables = Array.from({ length: 14 }, (_, i) => table(`t${i}`, i * 10, i * 1000));+ intro.fs.domains = Array.from({ length: 11 }, (_, i) => domain(`d${i}`, i * 1000, i));+ const district = computeDataHarbor(intro);+ const parcel = PARCELS.dataHarbor;+ for (const s of [...district.silos, ...district.racks]) {+ expect(Math.abs(s.x - parcel.anchor[0]), s.name).toBeLessThanOrEqual(parcel.w / 2);+ expect(Math.abs(s.z - parcel.anchor[2]), s.name).toBeLessThanOrEqual(parcel.d / 2);+ expect(isInWater(s.x, s.z), s.name).toBe(true);+ }+ });++ it('scales rack slats by log byte share with a lit floor for non-empty domains', () => {+ const district = computeDataHarbor(happyIntrospection());+ const images = district.racks.find((r) => r.name === 'images');+ const brain = district.racks.find((r) => r.name === 'brain');+ expect(images.litSlats).toBe(DATA_HARBOR.rackSlats); // the max domain is fully lit+ expect(brain.litSlats).toBeGreaterThanOrEqual(1); // non-empty never reads as unlit+ expect(brain.litSlats).toBeLessThan(images.litSlats);+ expect(images.sublabel).toBe('2.9 GB');+ });++ it('carries totals and the migration obelisk', () => {+ const district = computeDataHarbor(happyIntrospection());+ expect(district.obelisk).toEqual({ applied: 12, lastApplied: '2026-06-01T00:00:00.000Z' });+ expect(district.totals.tableCount).toBe(3);+ expect(district.totals.dbSizeLabel).toBe('4.8 MB');+ expect(district.totals.fsLabel).toBe('2.9 GB');+ expect(district.totals.domainCount).toBe(2);+ });++ it('is deterministic', () => {+ expect(computeDataHarbor(happyIntrospection())).toEqual(computeDataHarbor(happyIntrospection()));+ });+});++describe('tableColor', () => {+ it('is stable per name and varies across names', () => {+ expect(tableColor('memories')).toBe(tableColor('memories'));+ const colors = new Set(['memories', 'catalog_scraps', 'universes', 'memory_links'].map(tableColor));+ expect(colors.size).toBeGreaterThan(1);+ });+});++describe('harbor sits inside the world', () => {+ it('parcel is in the bay but inside the world bound', () => {+ const [x, , z] = DATA_HARBOR.base;+ expect(isInWater(x, z)).toBe(true);+ expect(Math.abs(z)).toBeLessThanOrEqual(WORLD.bound);+ });+});diff --git a/client/src/utils/index.js b/client/src/utils/index.jsindex 829db7159a..23f9eaa4f4 100644--- a/client/src/utils/index.js+++ b/client/src/utils/index.js@@ -40,6 +40,7 @@ export * from './cityAiCore.js';export * from './cityArtifacts.js';export * from './cityBackupVault.js';export * from './cityChronotype.js';+export * from './cityDataHarbor.js';export * from './cityDistrictLayout.js';export * from './cityEasterEggs.js';export * from './cityFederation.js';