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 mini-map overlay to CyberCity (roadmap 2.8)

[._.]/ Adam Eivy895a31e15439
diff --git a/client/src/components/city/CityHud.jsx b/client/src/components/city/CityHud.jsx
index 3dd52f32b7..698792fa02 100644
--- a/client/src/components/city/CityHud.jsx
+++ b/client/src/components/city/CityHud.jsx
@@ -4,6 +4,7 @@ import CityIntelPane from './CityIntelPane';
import CityAgentBar from './CityAgentBar';
import CityFilterBar from './CityFilterBar';
import CityXpBadge from './CityXpBadge';
+import CityMiniMap from './CityMiniMap';
// WASD controls hint shown briefly on first exploration entry
function ControlsHint({ visible }) {
@@ -161,7 +162,7 @@ function HealthBar({ value, max, color }) {
);
}
-export default function CityHud({ cosStatus, cosAgents, agentMap, eventLogs, connected, apps, reviewCounts, instances, productivityData, systemHealth, notificationCounts, character, filter, onFilterChange, onJumpToFirst, matchCount, onToggleExploration, explorationMode }) {
+export default function CityHud({ cosStatus, cosAgents, agentMap, eventLogs, connected, apps, reviewCounts, instances, productivityData, systemHealth, notificationCounts, character, filter, onFilterChange, onJumpToFirst, matchCount, onToggleExploration, explorationMode, onSelectApp }) {
const navigate = useNavigate();
const location = useLocation();
const [time, setTime] = useState(new Date());
@@ -441,8 +442,11 @@ export default function CityHud({ cosStatus, cosAgents, agentMap, eventLogs, con
{/* Controls hint overlay */}
<ControlsHint visible={explorationMode} />
- {/* Bottom-left: Settings gear + legend + corner decoration */}
+ {/* Bottom-left: mini-map + Settings gear + legend + corner decoration */}
<div className="absolute bottom-16 left-3">
+ {/* Top-down mini-map of every building (roadmap 2.8) */}
+ <CityMiniMap apps={apps} onSelectApp={onSelectApp} />
+
{/* Status legend */}
<div className="pointer-events-none mb-2 bg-black/70 backdrop-blur-sm border border-cyan-500/15 rounded-lg px-2.5 py-2 space-y-1">
<div className="font-pixel text-[8px] text-cyan-500/50 tracking-wider mb-1">LEGEND</div>
diff --git a/client/src/components/city/CityMiniMap.jsx b/client/src/components/city/CityMiniMap.jsx
new file mode 100644
index 0000000000..4cbbe6246d
--- /dev/null
+++ b/client/src/components/city/CityMiniMap.jsx
@@ -0,0 +1,87 @@
+import { useMemo } from 'react';
+import { computeCityLayout } from './cityLayout';
+import { getBuildingColor } from './cityConstants';
+import { computeMiniMap } from '../../utils/cityMiniMap';
+
+// CyberCity mini-map overlay (roadmap 2.8). A compact top-down map in a HUD corner showing
+// every building as a dot at its REAL layout position, colored by status. The layout comes
+// from `computeCityLayout(apps)` — the same function CityScene uses to place buildings — so
+// the map can't drift from the actual city. Status colors reuse `getBuildingColor`, so a dot
+// matches its building's color exactly.
+//
+// Click-to-select reuses the existing building-click plumbing: `onSelectApp(app)` is the same
+// callback CityScene fires on a building click (CyberCity navigates to /apps/:id). When no
+// callback is supplied the map is purely informational.
+//
+// Hidden on very small screens (per CityHud conventions — the right-side intel pane and
+// bottom agent bar already crowd a phone viewport). It's flow-positioned (no absolute) so it
+// stacks cleanly at the top of CityHud's bottom-left rail above the status legend.
+
+// Map box size in px. Fixed so the projection has a stable target on desktop.
+const MAP_SIZE = 132;
+
+export default function CityMiniMap({ apps, onSelectApp }) {
+ const view = useMemo(() => {
+ const positions = computeCityLayout(Array.isArray(apps) ? apps : []);
+ return computeMiniMap(apps, positions);
+ }, [apps]);
+
+ if (view.empty) return null;
+
+ return (
+ <div className="hidden md:block mb-2 pointer-events-auto">
+ <div className="relative bg-black/85 backdrop-blur-sm border border-cyan-500/30 rounded-lg p-2">
+ <div className="flex items-center justify-between mb-1.5 px-0.5">
+ <span className="font-pixel text-[8px] text-cyan-500/60 tracking-wider">MAP</span>
+ <span className="font-pixel text-[8px] text-cyan-400/80 tracking-wider">{view.count}</span>
+ </div>
+
+ <div
+ className="relative rounded-sm border border-cyan-500/20 bg-cyan-500/[0.03] overflow-hidden"
+ style={{ width: MAP_SIZE, height: MAP_SIZE }}
+ >
+ {/* Faint grid lines for orientation */}
+ <div className="absolute inset-0 pointer-events-none" aria-hidden="true">
+ <div className="absolute top-1/2 left-0 right-0 h-px bg-cyan-500/10" />
+ <div className="absolute left-1/2 top-0 bottom-0 w-px bg-cyan-500/10" />
+ </div>
+
+ {view.dots.map((dot) => {
+ const color = getBuildingColor(dot.status, dot.archived);
+ const left = `${(dot.nx * 100).toFixed(2)}%`;
+ const top = `${(dot.ny * 100).toFixed(2)}%`;
+ const dotStyle = {
+ left,
+ top,
+ backgroundColor: color,
+ boxShadow: `0 0 4px ${color}`,
+ };
+ const title = `${dot.name} — ${dot.status.replace(/_/g, ' ')}`;
+
+ if (onSelectApp) {
+ return (
+ <button
+ key={dot.id}
+ type="button"
+ onClick={() => onSelectApp({ id: dot.id })}
+ title={title}
+ aria-label={title}
+ className="absolute w-1.5 h-1.5 rounded-full -translate-x-1/2 -translate-y-1/2 hover:scale-[2] hover:z-10 transition-transform focus:outline-none focus:ring-1 focus:ring-cyan-400"
+ style={dotStyle}
+ />
+ );
+ }
+ return (
+ <span
+ key={dot.id}
+ title={title}
+ className="absolute w-1.5 h-1.5 rounded-full -translate-x-1/2 -translate-y-1/2"
+ style={dotStyle}
+ />
+ );
+ })}
+ </div>
+ </div>
+ </div>
+ );
+}
diff --git a/client/src/pages/CyberCity.jsx b/client/src/pages/CyberCity.jsx
index 404fa6de43..c51aacc80d 100644
--- a/client/src/pages/CyberCity.jsx
+++ b/client/src/pages/CyberCity.jsx
@@ -136,6 +136,7 @@ function CyberCityInner() {
matchCount={filterResult.matches.length}
onToggleExploration={handleToggleExploration}
explorationMode={settings?.explorationMode}
+ onSelectApp={handleBuildingClick}
/>
<CityScanlines settings={settings} />
{showSettings && <CitySettingsPanel />}
diff --git a/client/src/utils/cityMiniMap.js b/client/src/utils/cityMiniMap.js
new file mode 100644
index 0000000000..02a97f76bf
--- /dev/null
+++ b/client/src/utils/cityMiniMap.js
@@ -0,0 +1,95 @@
+// Pure, deterministic helpers for CyberCity's mini-map overlay (roadmap 2.8): a top-down
+// HUD map that plots every building as a dot at its REAL city-layout position. The layout
+// itself comes from `computeCityLayout(apps)` (the same function CityScene uses to place
+// buildings), so the map can't drift from the actual city. This module only handles the
+// projection math — world (x, z) ground coordinates → normalized 0..1 map coordinates for a
+// fixed-size map box — plus bounds and empty/degenerate handling. No React / three.js
+// imports so the topology stays unit-testable (mirrors cityTaskQueue.js).
+
+// Padding (as a fraction of the box) so dots never sit exactly on the frame edge.
+export const MINI_MAP_PADDING = 0.08;
+
+// Compute the world-space bounds of a set of { x, z } layout positions. Returns null for an
+// empty input so callers can render an "empty city" state rather than a degenerate box.
+export function computeBounds(positions) {
+ const list = Array.isArray(positions) ? positions : [];
+ if (list.length === 0) return null;
+
+ let minX = Infinity;
+ let maxX = -Infinity;
+ let minZ = Infinity;
+ let maxZ = -Infinity;
+ for (const p of list) {
+ if (p.x < minX) minX = p.x;
+ if (p.x > maxX) maxX = p.x;
+ if (p.z < minZ) minZ = p.z;
+ if (p.z > maxZ) maxZ = p.z;
+ }
+ return { minX, maxX, minZ, maxZ };
+}
+
+// Project a single world (x, z) into normalized 0..1 map coordinates given the world bounds.
+// `nx` runs left→right with world +x; `ny` runs top→bottom with world +z (so the map reads
+// like a top-down floor plan). A zero-width or zero-height span (one app, or a row/column)
+// centers along that axis instead of dividing by zero. `padding` insets the usable area so
+// dots clear the frame. Results are clamped to [0, 1].
+export function projectPoint(point, bounds, padding = MINI_MAP_PADDING) {
+ if (!bounds) return { nx: 0.5, ny: 0.5 };
+ const spanX = bounds.maxX - bounds.minX;
+ const spanZ = bounds.maxZ - bounds.minZ;
+ const usable = 1 - 2 * padding;
+
+ const fracX = spanX > 0 ? (point.x - bounds.minX) / spanX : 0.5;
+ const fracZ = spanZ > 0 ? (point.z - bounds.minZ) / spanZ : 0.5;
+
+ const nx = padding + fracX * usable;
+ const ny = padding + fracZ * usable;
+ return { nx: clamp01(nx), ny: clamp01(ny) };
+}
+
+function clamp01(v) {
+ if (v < 0) return 0;
+ if (v > 1) return 1;
+ return v;
+}
+
+// Full derived view-model for the mini-map component. Takes the layout `positions` Map (the
+// return value of `computeCityLayout(apps)`, keyed by app id) plus the `apps` array (for
+// status/name/archived metadata), and produces a flat list of plotted dots with normalized
+// coordinates, the world bounds, and a count. Apps missing a layout position are skipped
+// (defensive — every active/archived app should have one). Handles empty/non-array inputs by
+// returning an empty, bounds-null view.
+export function computeMiniMap(apps, positions, opts = {}) {
+ const padding = opts.padding ?? MINI_MAP_PADDING;
+ const appList = Array.isArray(apps) ? apps : [];
+ const posMap = positions instanceof Map ? positions : new Map();
+
+ const placed = [];
+ for (const app of appList) {
+ const pos = posMap.get(app?.id);
+ if (!pos) continue;
+ placed.push({ app, pos });
+ }
+
+ const bounds = computeBounds(placed.map(({ pos }) => pos));
+
+ const dots = placed.map(({ app, pos }) => {
+ const { nx, ny } = projectPoint(pos, bounds, padding);
+ return {
+ id: app.id,
+ name: app.name || app.id,
+ status: app.archived ? 'archived' : (app.overallStatus || 'not_started'),
+ archived: Boolean(app.archived),
+ district: pos.district,
+ nx,
+ ny,
+ };
+ });
+
+ return {
+ dots,
+ bounds,
+ count: dots.length,
+ empty: dots.length === 0,
+ };
+}
diff --git a/client/src/utils/cityMiniMap.test.js b/client/src/utils/cityMiniMap.test.js
new file mode 100644
index 0000000000..abacf616fd
--- /dev/null
+++ b/client/src/utils/cityMiniMap.test.js
@@ -0,0 +1,154 @@
+import { describe, it, expect } from 'vitest';
+import {
+ MINI_MAP_PADDING,
+ computeBounds,
+ projectPoint,
+ computeMiniMap,
+} from './cityMiniMap';
+
+const pos = (x, z, district = 'downtown') => ({ x, z, district });
+
+describe('computeBounds', () => {
+ it('returns null for empty / non-array input', () => {
+ expect(computeBounds([])).toBeNull();
+ expect(computeBounds(undefined)).toBeNull();
+ expect(computeBounds(null)).toBeNull();
+ });
+
+ it('computes the min/max box for many points', () => {
+ const b = computeBounds([pos(-12, 0), pos(0, -12), pos(12, 12), pos(0, 0)]);
+ expect(b).toEqual({ minX: -12, maxX: 12, minZ: -12, maxZ: 12 });
+ });
+
+ it('collapses to a zero-span box for a single point', () => {
+ const b = computeBounds([pos(5, -3)]);
+ expect(b).toEqual({ minX: 5, maxX: 5, minZ: -3, maxZ: -3 });
+ });
+});
+
+describe('projectPoint', () => {
+ const bounds = { minX: -10, maxX: 10, minZ: -10, maxZ: 10 };
+ const p = MINI_MAP_PADDING;
+ const usable = 1 - 2 * p;
+
+ it('maps the min corner to the padded top-left', () => {
+ const { nx, ny } = projectPoint(pos(-10, -10), bounds);
+ expect(nx).toBeCloseTo(p);
+ expect(ny).toBeCloseTo(p);
+ });
+
+ it('maps the max corner to the padded bottom-right', () => {
+ const { nx, ny } = projectPoint(pos(10, 10), bounds);
+ expect(nx).toBeCloseTo(p + usable);
+ expect(ny).toBeCloseTo(p + usable);
+ });
+
+ it('maps the center to the middle of the box', () => {
+ const { nx, ny } = projectPoint(pos(0, 0), bounds);
+ expect(nx).toBeCloseTo(0.5);
+ expect(ny).toBeCloseTo(0.5);
+ });
+
+ it('maps +x right and +z down (top-down floor plan)', () => {
+ const right = projectPoint(pos(10, 0), bounds);
+ const left = projectPoint(pos(-10, 0), bounds);
+ const down = projectPoint(pos(0, 10), bounds);
+ const up = projectPoint(pos(0, -10), bounds);
+ expect(right.nx).toBeGreaterThan(left.nx);
+ expect(down.ny).toBeGreaterThan(up.ny);
+ });
+
+ it('centers a point along a zero-span axis instead of dividing by zero', () => {
+ const colBounds = { minX: 5, maxX: 5, minZ: -10, maxZ: 10 };
+ const { nx, ny } = projectPoint(pos(5, 0), colBounds);
+ expect(nx).toBeCloseTo(0.5); // x span is zero → centered
+ expect(ny).toBeCloseTo(0.5); // z span resolves normally
+ });
+
+ it('clamps out-of-bounds points into [0, 1]', () => {
+ const { nx, ny } = projectPoint(pos(1000, -1000), bounds);
+ expect(nx).toBeGreaterThanOrEqual(0);
+ expect(nx).toBeLessThanOrEqual(1);
+ expect(ny).toBeGreaterThanOrEqual(0);
+ expect(ny).toBeLessThanOrEqual(1);
+ });
+
+ it('falls back to center when bounds are null', () => {
+ expect(projectPoint(pos(3, 7), null)).toEqual({ nx: 0.5, ny: 0.5 });
+ });
+});
+
+describe('computeMiniMap', () => {
+ const positions = (entries) => new Map(entries.map(([id, x, z, district]) => [id, pos(x, z, district)]));
+
+ it('returns an empty, bounds-null view for no apps', () => {
+ const vm = computeMiniMap([], new Map());
+ expect(vm.empty).toBe(true);
+ expect(vm.count).toBe(0);
+ expect(vm.dots).toEqual([]);
+ expect(vm.bounds).toBeNull();
+ });
+
+ it('tolerates non-array apps / non-Map positions', () => {
+ const vm = computeMiniMap(undefined, undefined);
+ expect(vm.empty).toBe(true);
+ expect(vm.count).toBe(0);
+ });
+
+ it('plots a single app at the center', () => {
+ const apps = [{ id: 'a', name: 'Alpha', overallStatus: 'online' }];
+ const vm = computeMiniMap(apps, positions([['a', 0, 0]]));
+ expect(vm.count).toBe(1);
+ expect(vm.empty).toBe(false);
+ expect(vm.dots[0].nx).toBeCloseTo(0.5);
+ expect(vm.dots[0].ny).toBeCloseTo(0.5);
+ expect(vm.dots[0].status).toBe('online');
+ });
+
+ it('projects many apps within the padded box and preserves order', () => {
+ const apps = [
+ { id: 'a', overallStatus: 'online' },
+ { id: 'b', overallStatus: 'stopped' },
+ { id: 'c', overallStatus: 'online' },
+ ];
+ const vm = computeMiniMap(apps, positions([['a', -12, -12], ['b', 12, 12], ['c', 0, 0]]));
+ expect(vm.count).toBe(3);
+ expect(vm.dots.map(d => d.id)).toEqual(['a', 'b', 'c']);
+ for (const d of vm.dots) {
+ expect(d.nx).toBeGreaterThanOrEqual(0);
+ expect(d.nx).toBeLessThanOrEqual(1);
+ expect(d.ny).toBeGreaterThanOrEqual(0);
+ expect(d.ny).toBeLessThanOrEqual(1);
+ }
+ });
+
+ it('marks archived apps with the archived status regardless of overallStatus', () => {
+ const apps = [{ id: 'a', overallStatus: 'online', archived: true }];
+ const vm = computeMiniMap(apps, positions([['a', 0, 0, 'warehouse']]));
+ expect(vm.dots[0].status).toBe('archived');
+ expect(vm.dots[0].archived).toBe(true);
+ expect(vm.dots[0].district).toBe('warehouse');
+ });
+
+ it('defaults a missing status to not_started', () => {
+ const apps = [{ id: 'a' }];
+ const vm = computeMiniMap(apps, positions([['a', 0, 0]]));
+ expect(vm.dots[0].status).toBe('not_started');
+ });
+
+ it('falls back to the id when an app has no name', () => {
+ const apps = [{ id: 'svc-42', overallStatus: 'online' }];
+ const vm = computeMiniMap(apps, positions([['svc-42', 0, 0]]));
+ expect(vm.dots[0].name).toBe('svc-42');
+ });
+
+ it('skips apps that have no layout position', () => {
+ const apps = [
+ { id: 'a', overallStatus: 'online' },
+ { id: 'ghost', overallStatus: 'online' },
+ ];
+ const vm = computeMiniMap(apps, positions([['a', 0, 0]]));
+ expect(vm.count).toBe(1);
+ expect(vm.dots.map(d => d.id)).toEqual(['a']);
+ });
+});