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
address review (codex): region aliases never resolved, and warps overshot the orbit cap
[._.]/ Adam Eivy5276b90f5e0a
diff --git a/client/src/components/city/CityFocusCamera.jsx b/client/src/components/city/CityFocusCamera.jsxindex 1af2958188..745b476847 100644--- a/client/src/components/city/CityFocusCamera.jsx+++ b/client/src/components/city/CityFocusCamera.jsx@@ -3,6 +3,7 @@ import { useThree, useFrame } from '@react-three/fiber';import * as THREE from 'three';import { smoothstep } from '../../utils/easing';import { computeFocusCamera, computeRegionCamera } from '../../utils/cityFocusCamera';+import { computeDistrictBounds } from '../../utils/cityMiniMap';// In-canvas camera controller for OpenWorld's two URL-addressed camera targets: a single// building (`/openworld/apps/:appId`, issue #2593) and a whole fast-travel region@@ -41,6 +42,14 @@ export default function CityFocusCamera({ focusedAppId, focusedRegion, positions() => (focusedRegion?.anchor ? `region:${focusedRegion.id}` : null),[focusedRegion?.anchor, focusedRegion?.id],);+ // A data-driven region (downtown / the archive grid) is framed by what's actually placed,+ // not by its nominal parcel — those grids grow with the install's app count, so a fixed+ // rectangle clips the outer towers on a big install. Static regions pass null and keep the+ // parcel footprint.+ const regionBounds = useMemo(+ () => (focusedRegion?.district ? computeDistrictBounds(positions, focusedRegion.district) : null),+ [focusedRegion?.district, positions],+ );const animRef = useRef(null);const controlsWasEnabledRef = useRef(true);@@ -57,7 +66,11 @@ export default function CityFocusCamera({ focusedAppId, focusedRegion, positionsconst pos = wantFocus ? positions?.get?.(focusedAppId) : null;// Focus wanted but the layout position isn't ready yet → hold and retry next frame.if (wantFocus && !pos) return;- // Regions come straight from the static plan, so there is no equivalent wait.+ // A static region comes straight from the plan, so there is no equivalent wait — but a+ // data-driven one must wait for the layout, or the first fly frames the nominal parcel+ // and never re-flies once the real bounds arrive. `positions` present with null bounds+ // is a genuinely EMPTY district (no archived apps yet), which correctly uses the parcel.+ if (!wantFocus && active && focusedRegion?.district && !positions) return;const wantRegion = !wantFocus && active && regionKey !== null;const key = wantFocus ? focusedAppId : wantRegion ? regionKey : null;@@ -79,7 +92,7 @@ export default function CityFocusCamera({ focusedAppId, focusedRegion, positionsconst fovDeg = camera.isPerspectiveCamera ? camera.fov : undefined;const framed = wantFocus? computeFocusCamera({ building: pos, aspect, fovDeg, hudSafe })- : computeRegionCamera({ region: focusedRegion, aspect, fovDeg, hudSafe });+ : computeRegionCamera({ region: focusedRegion, bounds: regionBounds, aspect, fovDeg, hudSafe });endPos = new THREE.Vector3(...framed.position);endTarget = new THREE.Vector3(...framed.target);}diff --git a/client/src/components/city/CityScene.jsx b/client/src/components/city/CityScene.jsxindex 97648e0e77..edcdf35d28 100644--- a/client/src/components/city/CityScene.jsx+++ b/client/src/components/city/CityScene.jsx@@ -50,6 +50,7 @@ import CityPhotoCamera from './CityPhotoCamera';import CityDepthOfField from './CityDepthOfField';import CityAdaptiveQuality from './CityAdaptiveQuality';import { cityDayMix, getTimeOfDayPreset } from './cityConstants';+import { CITY_MAX_ORBIT_DISTANCE } from '../../utils/cityFocusCamera';import { CityPaletteProvider } from './CityPaletteContext';import ErrorBoundary from '../ErrorBoundary';import { useVisibilityEvent } from '../../hooks/useVisibilityEvent';@@ -357,7 +358,9 @@ export default function CityScene({ apps, agentMap, onBuildingClick, onToggleCamkeyPanSpeed={24}maxPolarAngle={Math.PI / 2.2}minDistance={5}- maxDistance={120}+ // Shared with the framing math (see CITY_MAX_ORBIT_DISTANCE) so a fast-travel fly+ // never ends past a distance the controls would immediately snap back.+ maxDistance={CITY_MAX_ORBIT_DISTANCE}enableDampingdampingFactor={0.05}mouseButtons={{ LEFT: THREE.MOUSE.PAN, MIDDLE: THREE.MOUSE.DOLLY, RIGHT: THREE.MOUSE.ROTATE }}diff --git a/client/src/hooks/useNavWorkingSet.js b/client/src/hooks/useNavWorkingSet.jsindex 99feed9498..5933e308ff 100644--- a/client/src/hooks/useNavWorkingSet.js+++ b/client/src/hooks/useNavWorkingSet.js@@ -20,7 +20,24 @@ const LEGACY_NAV_PATHS = {'/system-health': '/system-resources',};-const migratePath = (path) => LEGACY_NAV_PATHS[path] || path;+// Whole-subtree renames: a stored path AT or UNDER the key moves to the value, keeping+// whatever followed. `/city` → `/openworld` (the 3D world's rename) covers `/city`,+// `/city/settings`, and `/city/apps/:id` in one rule, mirroring App.jsx's PrefixRedirect.+// Without it the browser URL redirects but the *stored* path doesn't, so a pinned `/city`+// row no longer resolves against the manifest and silently disappears on upgrade.+const LEGACY_NAV_PREFIXES = [+ ['/city', '/openworld'],+];++const migratePath = (path) => {+ const exact = LEGACY_NAV_PATHS[path];+ if (exact) return exact;+ for (const [from, to] of LEGACY_NAV_PREFIXES) {+ // Segment-anchored so a sibling route like `/cityscape` is never rewritten.+ if (path === from || path.startsWith(`${from}/`)) return `${to}${path.slice(from.length)}`;+ }+ return path;+};const migratePaths = (paths) => [...new Set(paths.map(migratePath))];/**diff --git a/client/src/hooks/useNavWorkingSet.test.jsx b/client/src/hooks/useNavWorkingSet.test.jsxindex 8a43e8debd..2ae19ad142 100644--- a/client/src/hooks/useNavWorkingSet.test.jsx+++ b/client/src/hooks/useNavWorkingSet.test.jsx@@ -50,6 +50,32 @@ describe('useNavWorkingSet', () => {expect(result.current.isPinned('/system-resources')).toBe(true);});+ it('migrates the whole legacy /city subtree to /openworld', () => {+ // The 3D world moved from /city to /openworld. App.jsx redirects the browser URL, but+ // the STORED path is what pinned/recent resolve against — without a migration a pinned+ // "City" row stops matching the manifest and silently vanishes on upgrade.+ localStorage.setItem(PINNED_KEY, JSON.stringify(['/city', '/city/settings', '/city/apps/portos']));+ const { result } = renderHook(() => useNavWorkingSet(resolveNavEntry), { wrapper });++ expect(result.current.pinned.map((row) => row.path)).toEqual([+ '/openworld', '/openworld/settings', '/openworld/apps/portos',+ ]);+ expect(result.current.isPinned('/openworld')).toBe(true);+ });++ it('leaves a sibling route that merely starts with the legacy prefix alone', () => {+ // The rewrite is segment-anchored: /cityscape is a different page, not /city.+ localStorage.setItem(PINNED_KEY, JSON.stringify(['/cityscape']));+ const { result } = renderHook(() => useNavWorkingSet(resolveNavEntry), { wrapper });+ expect(result.current.pinned.map((row) => row.path)).toEqual(['/cityscape']);+ });++ it('collapses a legacy path onto its already-migrated twin instead of duplicating', () => {+ localStorage.setItem(PINNED_KEY, JSON.stringify(['/city', '/openworld']));+ const { result } = renderHook(() => useNavWorkingSet(resolveNavEntry), { wrapper });+ expect(result.current.pinned.map((row) => row.path)).toEqual(['/openworld']);+ });+it('excludes pinned and the current path from recent', () => {localStorage.setItem(RECENT_KEY, JSON.stringify(['/start', '/x', '/y']));localStorage.setItem(PINNED_KEY, JSON.stringify(['/x']));diff --git a/client/src/utils/cityFocusCamera.js b/client/src/utils/cityFocusCamera.jsindex 8a85a7b14a..655775a439 100644--- a/client/src/utils/cityFocusCamera.js+++ b/client/src/utils/cityFocusCamera.js@@ -10,6 +10,15 @@// Vertical field of view of the city camera (matches CityScene's <Canvas camera={{ fov: 50 }}>).export const CITY_CAMERA_FOV_DEG = 50;+// How far the orbital camera may sit from its target. CityScene passes this straight to+// OrbitControls as `maxDistance`, and every framing helper here clamps to it — the two MUST+// be the same number. When they weren't, a fast-travel warp to a big district on a phone+// computed ~218 units while the controls capped at 120, so OrbitControls yanked the camera+// in the moment the fly handed control back and the region never fit the frame.+// Sized to fit the widest region (60-unit Downtown) on a narrow portrait viewport, where the+// horizontal extent — not the HUD — is what forces the camera back.+export const CITY_MAX_ORBIT_DISTANCE = 240;+// Ground-footprint radius of a single borough: the process ring (BOROUGH_PARAMS.processRingRadius// = 3) plus a process building's half-footprint and a little breathing room. Buildings never spread// wider than this on the ground, so a sphere of this radius (grown by the tower height) bounds the@@ -88,7 +97,10 @@ function frameFromRadius({ centerX, centerZ, targetY, radius, aspect, fovDeg, hu// Distance so the bounding sphere fits both the (HUD-reduced) vertical and horizontal extents.const distV = radius / (halfV * usableH);const distH = radius / (halfH * usableW);- const distance = Math.max(distV, distH);+ // Clamped to the ceiling the controls enforce: a fly that ended beyond it would be snapped+ // back by OrbitControls the instant it re-enabled. A subject too large to fit at the cap is+ // framed as well as the cap allows — imperfect, but stable instead of jarring.+ const distance = Math.min(CITY_MAX_ORBIT_DISTANCE, Math.max(distV, distH));// Pan the framed region so the subject sits in the clear area: push it left of a right-edge panel// and up above a bottom-edge panel. Panning moves camera + target by the same world delta.@@ -132,14 +144,29 @@ const REGION_TARGET_Y = 3;// Compute the establishing camera for one fast-travel region.// region — { anchor: [x, y, z], w, d } (from openWorldRegions.getRegion).+// bounds — optional { minX, maxX, minZ, maxZ } of what is ACTUALLY on the ground for a+// data-driven district (downtown / the archive grid, whose extent grows with the+// install's app count). When given it supersedes the parcel's nominal w/d, so a+// big install frames its real skyline instead of clipping the outer towers; the+// parcel is still the floor, so a near-empty install doesn't zoom into one tower.// aspect / fovDeg / hudSafe — as computeFocusCamera.// Returns { position:[x,y,z], target:[x,y,z], distance, radius }.-export function computeRegionCamera({ region, aspect = 1, fovDeg = CITY_CAMERA_FOV_DEG, hudSafe } = {}) {+export function computeRegionCamera({ region, bounds, aspect = 1, fovDeg = CITY_CAMERA_FOV_DEG, hudSafe } = {}) {const anchor = Array.isArray(region?.anchor) ? region.anchor : [];- const cx = finiteOr(anchor[0], 0);- const cz = finiteOr(anchor[2], 0);- const w = Math.max(0, finiteOr(region?.w, 0));- const d = Math.max(0, finiteOr(region?.d, 0));+ let cx = finiteOr(anchor[0], 0);+ let cz = finiteOr(anchor[2], 0);+ let w = Math.max(0, finiteOr(region?.w, 0));+ let d = Math.max(0, finiteOr(region?.d, 0));++ const hasBounds = [bounds?.minX, bounds?.maxX, bounds?.minZ, bounds?.maxZ].every(Number.isFinite);+ if (hasBounds) {+ // Center on the live cloud and take the larger of live vs nominal on each axis — a grid+ // that has outgrown its parcel widens the shot, one that hasn't keeps the parcel's.+ cx = (bounds.minX + bounds.maxX) / 2;+ cz = (bounds.minZ + bounds.maxZ) / 2;+ w = Math.max(w, bounds.maxX - bounds.minX + BOROUGH_GROUND_RADIUS * 2);+ d = Math.max(d, bounds.maxZ - bounds.minZ + BOROUGH_GROUND_RADIUS * 2);+ }const radius = Math.max(MIN_REGION_RADIUS, Math.hypot(w, d) / 2) * REGION_FRAMING_MARGIN;diff --git a/client/src/utils/cityFocusCamera.test.js b/client/src/utils/cityFocusCamera.test.jsindex 03eec1c5d8..f93b8cb89e 100644--- a/client/src/utils/cityFocusCamera.test.js+++ b/client/src/utils/cityFocusCamera.test.js@@ -1,5 +1,5 @@import { describe, it, expect } from 'vitest';-import { computeFocusCamera, BOROUGH_GROUND_RADIUS, CITY_CAMERA_FOV_DEG, computeRegionCamera } from './cityFocusCamera';+import { computeFocusCamera, BOROUGH_GROUND_RADIUS, CITY_CAMERA_FOV_DEG, computeRegionCamera, CITY_MAX_ORBIT_DISTANCE } from './cityFocusCamera';const building = { x: 12, z: -24, height: 6 };@@ -115,3 +115,75 @@ describe('computeRegionCamera', () => {}});});++import { listRegions } from './openWorldRegions';++describe('framing stays inside the orbit-distance ceiling', () => {+ // CityScene hands CITY_MAX_ORBIT_DISTANCE straight to OrbitControls as maxDistance. A fly+ // that ended beyond it would be yanked back the instant the controls re-enabled, so the+ // framing math must never return a farther distance than the controls will keep.+ const VIEWPORTS = [+ ['desktop', 16 / 9, { right: 0.28, bottom: 0 }],+ ['narrow phone', 390 / 780, { right: 0, bottom: 0.5 }],+ ['degenerate', 0.2, { right: 0.9, bottom: 0.9 }],+ ];++ it('every real region frames within the ceiling on every viewport', () => {+ const over = [];+ for (const region of listRegions()) {+ for (const [name, aspect, hudSafe] of VIEWPORTS) {+ const { distance } = computeRegionCamera({ region, aspect, fovDeg: 50, hudSafe });+ if (distance > CITY_MAX_ORBIT_DISTANCE) over.push(`${region.id} @ ${name}: ${distance.toFixed(1)}`);+ }+ }+ expect(over).toEqual([]);+ });++ it('clamps rather than exceeding the ceiling for an absurdly large region', () => {+ const { distance } = computeRegionCamera({+ region: { anchor: [0, 0, 0], w: 5000, d: 5000 }, aspect: 0.4, fovDeg: 50,+ });+ expect(distance).toBe(CITY_MAX_ORBIT_DISTANCE);+ });++ it('clamps the borough focus camera too — they share the optics', () => {+ const { distance } = computeFocusCamera({+ building: { x: 0, z: 0, height: 100000 }, aspect: 0.4, fovDeg: 50,+ });+ expect(distance).toBe(CITY_MAX_ORBIT_DISTANCE);+ });+});++describe('computeRegionCamera — data-driven districts', () => {+ const parcel = { anchor: [0, 0, 0], w: 60, d: 60 };++ it('widens and re-centers on live layout bounds that outgrew the parcel', () => {+ const nominal = computeRegionCamera({ region: parcel, aspect: 16 / 9 });+ const grown = computeRegionCamera({+ region: parcel,+ bounds: { minX: -90, maxX: 90, minZ: -40, maxZ: 40 },+ aspect: 16 / 9,+ });+ expect(grown.radius).toBeGreaterThan(nominal.radius);+ // Re-centered on the live cloud, which here is symmetric about the parcel anchor.+ expect(grown.target[2]).toBeCloseTo(0, 6);+ });++ it('keeps the parcel as a floor so a near-empty install does not zoom into one tower', () => {+ const nominal = computeRegionCamera({ region: parcel, aspect: 16 / 9 });+ const tiny = computeRegionCamera({+ region: parcel,+ bounds: { minX: -6, maxX: 6, minZ: -6, maxZ: 6 },+ aspect: 16 / 9,+ });+ expect(tiny.radius).toBe(nominal.radius);+ });++ it('ignores partial or non-finite bounds rather than producing NaNs', () => {+ for (const bounds of [null, undefined, {}, { minX: 0, maxX: 10 }, { minX: NaN, maxX: 1, minZ: 0, maxZ: 1 }]) {+ const { position, target, radius } = computeRegionCamera({ region: parcel, bounds, aspect: 16 / 9 });+ for (const n of [...position, ...target, radius]) expect(Number.isFinite(n)).toBe(true);+ expect(radius).toBe(computeRegionCamera({ region: parcel, aspect: 16 / 9 }).radius);+ }+ });+});diff --git a/client/src/utils/openWorldRegions.js b/client/src/utils/openWorldRegions.jsindex 187d4a7c5f..314e23a24b 100644--- a/client/src/utils/openWorldRegions.js+++ b/client/src/utils/openWorldRegions.js@@ -18,12 +18,18 @@ import { PARCELS } from './cityPlan';// Ordered for the fast-travel list: the two places you look at most first, then a clockwise// sweep of the outer districts, then the far shore. `parcel` keys into PARCELS for geography;// `appPath` is the 2D PortOS page the region visualizes (null for pure set dressing).+//+// `district` marks a region whose real extent is DATA-DRIVEN — the downtown and archive grids+// grow with the install's app count, so their PARCELS footprint is only a nominal size. It+// names the district key in `computeCityLayout`'s output, which the camera uses to measure the+// buildings actually on the ground instead of framing a fixed rectangle and clipping the+// outer towers.export const OPEN_WORLD_REGIONS = [- { id: 'downtown', parcel: 'downtown', label: 'Downtown', blurb: 'Every managed app, one tower each.', appPath: '/apps', aliases: ['downtown', 'apps district', 'app towers'] },+ { id: 'downtown', parcel: 'downtown', district: 'downtown', label: 'Downtown', blurb: 'Every managed app, one tower each.', appPath: '/apps', aliases: ['downtown', 'apps district', 'app towers'] },{ id: 'ai-core', parcel: 'aiCore', label: 'AI Core Plaza', blurb: 'The reactor at the center — live AI provider activity.', appPath: '/ai', aliases: ['ai core', 'core plaza', 'the core', 'reactor'] },{ id: 'task-queue', parcel: 'taskQueue', label: 'Task Queue', blurb: 'Chief of Staff work stacked up and moving.', appPath: '/cos/tasks', aliases: ['task queue', 'queue', 'cos queue'] },{ id: 'wellness', parcel: 'health', label: 'Wellness Tower', blurb: 'System vitals — CPU, memory, disk.', appPath: '/system-resources/overview', aliases: ['wellness tower', 'health tower', 'vitals tower'] },- { id: 'archive', parcel: 'warehouse', label: 'Archive District', blurb: 'Cold storage for archived apps.', appPath: '/apps', aliases: ['archive district', 'warehouse', 'cold storage'] },+ { id: 'archive', parcel: 'warehouse', district: 'warehouse', label: 'Archive District', blurb: 'Cold storage for archived apps.', appPath: '/apps', aliases: ['archive district', 'warehouse', 'cold storage'] },{ id: 'quiet-corner', parcel: 'easterEggs', label: 'Quiet Corner', blurb: 'The odd little things the world keeps to itself.', appPath: null, aliases: ['quiet corner', 'easter eggs'] },{ id: 'productivity', parcel: 'productivity', label: 'Productivity Terrace', blurb: 'Streaks, throughput, and the activity heatmap.', appPath: '/insights/overview', aliases: ['productivity terrace', 'productivity', 'streak district'] },{ id: 'backup-vault', parcel: 'backupVault', label: 'Backup Vault', blurb: 'The sealed door — last backup and its health.', appPath: '/settings/backup', aliases: ['backup vault', 'the vault'] },diff --git a/server/lib/navManifest.js b/server/lib/navManifest.jsindex d3ef4af04d..64846381e6 100644--- a/server/lib/navManifest.js+++ b/server/lib/navManifest.js@@ -11,6 +11,12 @@ import { PORTOS_APP_ID } from './appIdentity.js';// imported because a server lib can't reach into client code; navManifest.test.js scrapes// the registry and fails on drift in the paths, the labels, AND the aliases.// Written as [id, label, aliases] tuples so the axis that varies is the only thing repeated.+//+// Aliases are authored in the human phrasing the fast-travel search box uses ("memory+// quarter") and registered KEBAB-CASED, because resolveNavCommand normalizes its input to+// kebab before matching: a space-separated alias can never be hit. Registering them raw+// didn't just fail to resolve — the fallback tiers matched a substring against an unrelated+// command, so "memory quarter" landed on /brain/memory and "voice beacon" on /settings/voice.const OPEN_WORLD_REGION_COMMANDS = [['downtown', 'Downtown', ['downtown', 'apps district', 'app towers']],['ai-core', 'AI Core Plaza', ['ai core', 'core plaza', 'the core', 'reactor']],@@ -31,7 +37,7 @@ const OPEN_WORLD_REGION_COMMANDS = [path: `/openworld/region/${id}`,label,section: 'Main',- aliases,+ aliases: aliases.map((a) => a.replace(/\s+/g, '-')),keywords: ['openworld', 'fast travel', 'warp', 'region', 'teleport'],}));diff --git a/server/lib/navManifest.test.js b/server/lib/navManifest.test.jsindex 91d244c3a9..47ee9dfca2 100644--- a/server/lib/navManifest.test.js+++ b/server/lib/navManifest.test.js@@ -289,14 +289,39 @@ describe('nav contract — OpenWorld regions match the registry labels and alias});it('every registry alias is addressable as a nav alias', () => {+ // The registry authors aliases in human phrasing ("memory quarter"); the manifest+ // registers them kebab-cased, because that is the form resolveNavCommand matches on.+ const kebab = (a) => a.replace(/\s+/g, '-');const missing = readRegistry().flatMap((r) => {const cmd = navByPath.get(`/openworld/region/${r.id}`);if (!cmd) return [];const navAliases = new Set(cmd.aliases || []);- return r.aliases.filter((a) => !navAliases.has(a)).map((a) => `${r.id}: "${a}"`);+ return r.aliases.filter((a) => !navAliases.has(kebab(a))).map((a) => `${r.id}: "${a}"`);});expect(missing).toEqual([]);});++ it('every region alias actually RESOLVES to its own region', () => {+ // Parity with the registry is not enough on its own: resolveNavCommand normalizes its+ // input to kebab-case, so a space-separated alias never matches exactly and instead+ // falls through to the substring tiers — which is how "memory quarter" resolved to+ // /brain/memory and "voice beacon" to /settings/voice while every parity check passed.+ // Assert the behavior users actually get, phrased the way they'd say it.+ const wrong = readRegistry().flatMap((r) => {+ const want = `/openworld/region/${r.id}`;+ return r.aliases+ .map((alias) => ({ alias, got: resolveNavCommand(alias)?.path ?? null }))+ .filter(({ got }) => got !== want)+ .map(({ alias, got }) => `${r.id}: "${alias}" → ${got ?? 'NULL'} (want ${want})`);+ });+ expect(wrong).toEqual([]);+ });++ it('resolves a region by its label as spoken', () => {+ for (const r of readRegistry()) {+ expect(resolveNavCommand(r.label)?.path).toBe(`/openworld/region/${r.id}`);+ }+ });});// Settings is the one tabbed page whose tab bar (SettingsTabsHeader.jsx `TABS`,