Skip to content

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

feat([issue-705]): add CyberCity federation horizon

[._.]/ Adam Eivy622518d1316c
diff --git a/client/src/components/city/CityFederationHorizon.jsx b/client/src/components/city/CityFederationHorizon.jsx
new file mode 100644
index 0000000000..9962e801fd
--- /dev/null
+++ b/client/src/components/city/CityFederationHorizon.jsx
@@ -0,0 +1,128 @@
+import { useMemo, useRef, useEffect } from 'react';
+import { useFrame } from '@react-three/fiber';
+import { Text } from '@react-three/drei';
+import * as THREE from 'three';
+import { PIXEL_FONT_URL } from './cityConstants';
+import { computeFederationHorizon, FEDERATION } from '../../utils/cityFederation';
+
+// The sync link reaching inward from a peer toward the city. Solid + bright when
+// the peer is actively syncing, dashed when the link is broken (offline / failing),
+// faint when idle.
+function FederationBridge({ from, color, broken, intensity }) {
+ const lineRef = useRef();
+
+ // `from` is the peer's ground position; the bridge stretches inward toward the
+ // city center so it reads as a link reaching home.
+ const geometry = useMemo(() => {
+ const dir = new THREE.Vector3(-from[0], 0, -from[2]);
+ if (dir.lengthSq() > 0) dir.normalize();
+ const start = new THREE.Vector3(from[0] + dir.x * 1.5, 0.6, from[2] + dir.z * 1.5);
+ const end = new THREE.Vector3(
+ from[0] + dir.x * (1.5 + FEDERATION.bridgeReach),
+ 0.6,
+ from[2] + dir.z * (1.5 + FEDERATION.bridgeReach),
+ );
+ const geom = new THREE.BufferGeometry().setFromPoints([start, end]);
+ geom.computeLineDistances(); // required for the dashed (broken) material
+ return geom;
+ }, [from]);
+
+ useEffect(() => () => geometry.dispose(), [geometry]);
+
+ return (
+ <line ref={lineRef} geometry={geometry}>
+ {broken ? (
+ <lineDashedMaterial color={color} transparent opacity={0.15 + intensity * 0.25} dashSize={1.1} gapSize={0.9} />
+ ) : (
+ <lineBasicMaterial color={color} transparent opacity={0.2 + intensity * 0.4} />
+ )}
+ </line>
+ );
+}
+
+// A distant peer (or the void marker) rendered as a neon-trimmed silhouette.
+function Monolith({ position, width, height, color, opacity, label, sublabel, online, animate }) {
+ const capRef = useRef();
+
+ useFrame(({ clock }) => {
+ if (!animate || !online || !capRef.current) return;
+ const pulse = 0.6 + ((Math.sin(clock.getElapsedTime() * 1.2 + position[0]) + 1) / 2) * 0.6;
+ capRef.current.material.emissiveIntensity = pulse;
+ });
+
+ return (
+ <group position={position}>
+ {/* Dark body with a faint neon glow scaled by reachability */}
+ <mesh position={[0, height / 2, 0]}>
+ <boxGeometry args={[width, height, width * 0.4]} />
+ <meshStandardMaterial
+ color="#0a0a18"
+ emissive={color}
+ emissiveIntensity={opacity}
+ transparent
+ opacity={Math.min(0.9, 0.4 + opacity)}
+ depthWrite={false}
+ />
+ </mesh>
+ {/* Bright neon cap at the top edge */}
+ <mesh ref={capRef} position={[0, height + 0.3, 0]}>
+ <boxGeometry args={[width * 1.05, 0.6, width * 0.45]} />
+ <meshStandardMaterial color={color} emissive={color} emissiveIntensity={online ? 0.9 : 0.4} transparent opacity={Math.min(1, opacity + 0.4)} depthWrite={false} />
+ </mesh>
+ {label && (
+ <Text position={[0, height + 2.2, 0]} fontSize={1.6} color={color} anchorX="center" anchorY="middle" font={PIXEL_FONT_URL} maxWidth={20}>
+ {label}
+ </Text>
+ )}
+ {sublabel && (
+ <Text position={[0, height + 0.9, 0]} fontSize={1.0} color="#94a3b8" anchorX="center" anchorY="middle" font={PIXEL_FONT_URL} maxWidth={20}>
+ {sublabel}
+ </Text>
+ )}
+ </group>
+ );
+}
+
+export default function CityFederationHorizon({ instances, settings }) {
+ const { peers, voidMarker } = useMemo(
+ () => computeFederationHorizon(instances?.peers),
+ [instances],
+ );
+
+ // The horizon is a handful of distant static meshes, but honor the quality
+ // dial: drop the gentle peer pulse on the lowest preset.
+ const animate = (settings?.particleDensity ?? 1) >= 0.5;
+
+ return (
+ <group>
+ {peers.map(peer => (
+ <group key={peer.id}>
+ <Monolith
+ position={peer.position}
+ width={peer.width}
+ height={peer.height}
+ color={peer.color}
+ opacity={peer.opacity}
+ label={peer.name}
+ sublabel={peer.online ? 'LINKED' : peer.status.toUpperCase()}
+ online={peer.online}
+ animate={animate}
+ />
+ <FederationBridge from={peer.position} color={peer.color} broken={peer.bridge.broken} intensity={peer.bridge.intensity} />
+ </group>
+ ))}
+ {/* Void machine — always present so the federation horizon never goes empty */}
+ <Monolith
+ position={voidMarker.position}
+ width={voidMarker.width}
+ height={voidMarker.height}
+ color={voidMarker.color}
+ opacity={voidMarker.opacity}
+ label="VOID"
+ sublabel="PRIMARY"
+ online={false}
+ animate={false}
+ />
+ </group>
+ );
+}
diff --git a/client/src/components/city/CityScene.jsx b/client/src/components/city/CityScene.jsx
index d37a03a9bf..39c18f0472 100644
--- a/client/src/components/city/CityScene.jsx
+++ b/client/src/components/city/CityScene.jsx
@@ -14,6 +14,7 @@ import CityBillboards from './CityBillboards';
import CityShootingStars from './CityShootingStars';
import CityVolumetricLights from './CityVolumetricLights';
import CitySkyline from './CitySkyline';
+import CityFederationHorizon from './CityFederationHorizon';
import CityDataRain from './CityDataRain';
import CityNeonSigns from './CityNeonSigns';
import CityEmbers from './CityEmbers';
@@ -72,6 +73,7 @@ export default function CityScene({ apps, agentMap, onBuildingClick, cosStatus,
<CityShootingStars playSfx={playSfx} settings={settings} />
{!explorationMode && <CityCelestial settings={settings} />}
<CitySkyline />
+ <CityFederationHorizon instances={instances} settings={settings} />
<CityGround settings={settings} />
<BuildingCluster
diff --git a/client/src/utils/cityFederation.js b/client/src/utils/cityFederation.js
new file mode 100644
index 0000000000..30d15d2551
--- /dev/null
+++ b/client/src/utils/cityFederation.js
@@ -0,0 +1,83 @@
+// Pure, deterministic helpers for CyberCity's "federation horizon": placing sync
+// peers as distant skyline silhouettes and deriving their reachability (opacity)
+// and sync-bridge state from real instance data. A void marker is always present
+// so the horizon stays meaningful even on a single-instance install. No three.js
+// / React imports so the topology is unit-testable (mirrors cityFlowLines.js).
+
+import { hashString } from './hashString';
+
+export const FEDERATION = {
+ radius: 76, // distant ring, beyond CitySkyline (~55–70) so peers read as far cities
+ bridgeReach: 16, // how far the sync bridge stretches inward from a peer toward the city
+ onlineColor: '#8b5cf6', // violet — matches the existing INSTANCE MESH beacon
+ offlineColor: '#ef4444',
+ unknownColor: '#64748b', // slate — also the void marker's color
+};
+
+// Silhouette opacity by reachability. Online peers read clearly; unknown/unprobed
+// are dim; offline are barely visible — but never zero, so the horizon never goes
+// empty when a peer drops.
+export function reachabilityOpacity(status) {
+ if (status === 'online') return 0.55;
+ if (status === 'offline') return 0.18;
+ return 0.3; // unknown / not yet probed
+}
+
+export function statusColor(status) {
+ if (status === 'online') return FEDERATION.onlineColor;
+ if (status === 'offline') return FEDERATION.offlineColor;
+ return FEDERATION.unknownColor;
+}
+
+// The sync "bridge" between this install and a peer. It's `active` (solid, bright)
+// only when the peer is online AND sync is enabled; `broken` (dashed) when the
+// peer is offline or has recent sync failures; otherwise a faint idle link.
+export function bridgeState(peer) {
+ const online = peer?.status === 'online';
+ const failing = peer?.status === 'offline' || (peer?.consecutiveFailures || 0) > 0;
+ const active = online && !!peer?.syncEnabled;
+ return {
+ active,
+ broken: failing,
+ intensity: active ? 1 : online ? 0.5 : 0.2,
+ };
+}
+
+// Place one peer on the distant ring. Angle/height/width are derived from a stable
+// hash of the peer id, so a peer keeps its spot (and shape) across reloads and is
+// independent of its position in the list.
+export function placePeer(peer, index, { radius = FEDERATION.radius } = {}) {
+ const seed = hashString(peer?.id || peer?.name || peer?.address || `peer-${index}`);
+ const angle = ((seed % 3600) / 3600) * Math.PI * 2;
+ const r = radius + (seed % 11); // slight depth variation across the ring
+ return {
+ id: peer?.id || `peer-${index}`,
+ name: peer?.name || peer?.host || peer?.address || 'peer',
+ status: peer?.status || 'unknown',
+ online: peer?.status === 'online',
+ angle,
+ position: [Math.cos(angle) * r, 0, Math.sin(angle) * r],
+ height: 18 + (seed % 14), // taller than the faint skyline so peers stand out
+ width: 3 + (seed % 3),
+ opacity: reachabilityOpacity(peer?.status),
+ color: statusColor(peer?.status),
+ bridge: bridgeState(peer),
+ };
+}
+
+// Build the full horizon: a placement per peer plus a fixed "void machine" marker
+// (the reserved zone for the remote primary instance) that is always rendered, so
+// the federation horizon is visible even with zero peers.
+export function computeFederationHorizon(peers, opts = {}) {
+ const radius = opts.radius ?? FEDERATION.radius;
+ const placed = (peers || []).map((peer, i) => placePeer(peer, i, { radius }));
+ const voidMarker = {
+ id: 'void-machine',
+ position: [0, 0, -(radius + 6)],
+ height: 28,
+ width: 6,
+ color: FEDERATION.unknownColor,
+ opacity: 0.22,
+ };
+ return { peers: placed, voidMarker };
+}
diff --git a/client/src/utils/cityFederation.test.js b/client/src/utils/cityFederation.test.js
new file mode 100644
index 0000000000..62f6aa651a
--- /dev/null
+++ b/client/src/utils/cityFederation.test.js
@@ -0,0 +1,114 @@
+import { describe, it, expect } from 'vitest';
+import {
+ FEDERATION,
+ reachabilityOpacity,
+ statusColor,
+ bridgeState,
+ placePeer,
+ computeFederationHorizon,
+} from './cityFederation';
+
+describe('reachabilityOpacity', () => {
+ it('orders online > unknown > offline, all non-zero', () => {
+ const online = reachabilityOpacity('online');
+ const unknown = reachabilityOpacity('unknown');
+ const offline = reachabilityOpacity('offline');
+ expect(online).toBeGreaterThan(unknown);
+ expect(unknown).toBeGreaterThan(offline);
+ expect(offline).toBeGreaterThan(0); // offline peers stay faintly visible
+ });
+
+ it('treats an unrecognised/missing status as unknown', () => {
+ expect(reachabilityOpacity(undefined)).toBe(reachabilityOpacity('unknown'));
+ });
+});
+
+describe('statusColor', () => {
+ it('maps each status to its color', () => {
+ expect(statusColor('online')).toBe(FEDERATION.onlineColor);
+ expect(statusColor('offline')).toBe(FEDERATION.offlineColor);
+ expect(statusColor('whatever')).toBe(FEDERATION.unknownColor);
+ });
+});
+
+describe('bridgeState', () => {
+ it('is active and unbroken when online and syncing', () => {
+ const b = bridgeState({ status: 'online', syncEnabled: true });
+ expect(b).toMatchObject({ active: true, broken: false });
+ expect(b.intensity).toBe(1);
+ });
+
+ it('is broken when offline', () => {
+ const b = bridgeState({ status: 'offline', syncEnabled: true });
+ expect(b.active).toBe(false);
+ expect(b.broken).toBe(true);
+ });
+
+ it('is broken when online but accumulating sync failures', () => {
+ const b = bridgeState({ status: 'online', syncEnabled: true, consecutiveFailures: 3 });
+ expect(b.broken).toBe(true);
+ });
+
+ it('is an idle (not active, not broken) link when online with sync disabled', () => {
+ const b = bridgeState({ status: 'online', syncEnabled: false });
+ expect(b.active).toBe(false);
+ expect(b.broken).toBe(false);
+ expect(b.intensity).toBeLessThan(1);
+ });
+});
+
+describe('placePeer', () => {
+ const peer = { id: 'peer-abc', name: 'studio', status: 'online', syncEnabled: true };
+
+ it('is deterministic for the same peer id', () => {
+ expect(placePeer(peer, 0)).toEqual(placePeer(peer, 5));
+ });
+
+ it('places the peer on the distant ring near the configured radius', () => {
+ const { position } = placePeer(peer, 0);
+ const r = Math.hypot(position[0], position[2]);
+ expect(r).toBeGreaterThanOrEqual(FEDERATION.radius);
+ expect(r).toBeLessThan(FEDERATION.radius + 11);
+ });
+
+ it('carries the peer color, opacity, and bridge derived from status', () => {
+ const placed = placePeer(peer, 0);
+ expect(placed.color).toBe(FEDERATION.onlineColor);
+ expect(placed.opacity).toBe(reachabilityOpacity('online'));
+ expect(placed.bridge.active).toBe(true);
+ expect(placed.online).toBe(true);
+ });
+
+ it('gives distinct peers distinct angles', () => {
+ const a = placePeer({ id: 'aaa' }, 0);
+ const b = placePeer({ id: 'zzz' }, 1);
+ expect(a.angle).not.toBeCloseTo(b.angle, 3);
+ });
+
+ it('falls back to a stable label and unknown status for a bare peer', () => {
+ const placed = placePeer({ id: 'x' }, 2);
+ expect(placed.name).toBe('peer');
+ expect(placed.status).toBe('unknown');
+ expect(placed.color).toBe(FEDERATION.unknownColor);
+ });
+});
+
+describe('computeFederationHorizon', () => {
+ it('always returns a void marker, even with no peers', () => {
+ expect(computeFederationHorizon([]).voidMarker.id).toBe('void-machine');
+ expect(computeFederationHorizon(undefined).voidMarker.id).toBe('void-machine');
+ expect(computeFederationHorizon([]).peers).toEqual([]);
+ });
+
+ it('places the void marker behind downtown beyond the ring', () => {
+ const { voidMarker } = computeFederationHorizon([], { radius: 50 });
+ expect(voidMarker.position).toEqual([0, 0, -56]);
+ });
+
+ it('returns one placement per peer', () => {
+ const peers = [{ id: 'a', status: 'online' }, { id: 'b', status: 'offline' }];
+ const { peers: placed } = computeFederationHorizon(peers);
+ expect(placed).toHaveLength(2);
+ expect(placed.map(p => p.id)).toEqual(['a', 'b']);
+ });
+});