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 voice-agent district marker to CyberCity (roadmap 2.4)

[._.]/ Adam Eivy5e6dcaf4bb62
diff --git a/client/src/components/city/CityScene.jsx b/client/src/components/city/CityScene.jsx
index daefd05d3d..a4e459ff08 100644
--- a/client/src/components/city/CityScene.jsx
+++ b/client/src/components/city/CityScene.jsx
@@ -17,6 +17,7 @@ import CitySkyline from './CitySkyline';
import CityFederationHorizon from './CityFederationHorizon';
import CityBackupVault from './CityBackupVault';
import CityTaskQueue from './CityTaskQueue';
+import CityVoiceMarker from './CityVoiceMarker';
import CityDataRain from './CityDataRain';
import CityNeonSigns from './CityNeonSigns';
import CityEmbers from './CityEmbers';
@@ -27,7 +28,7 @@ import CitySky from './CitySky';
import PlayerController from './PlayerController';
import CameraTransition from './CameraTransition';
-export default function CityScene({ apps, agentMap, onBuildingClick, cosStatus, reviewCounts, instances, backupStatus, cosTasks, productivityData, settings, playSfx, keysRef, dimmedAppIds }) {
+export default function CityScene({ apps, agentMap, onBuildingClick, cosStatus, reviewCounts, instances, backupStatus, cosTasks, voiceState, productivityData, settings, playSfx, keysRef, dimmedAppIds }) {
const [positions, setPositions] = useState(null);
const [proximityApp, setProximityApp] = useState(null);
const [transitioning, setTransitioning] = useState(false);
@@ -78,6 +79,7 @@ export default function CityScene({ apps, agentMap, onBuildingClick, cosStatus,
<CityFederationHorizon instances={instances} settings={settings} />
<CityBackupVault backupStatus={backupStatus} settings={settings} />
<CityTaskQueue cosTasks={cosTasks} settings={settings} />
+ <CityVoiceMarker voiceState={voiceState} settings={settings} />
<CityGround settings={settings} />
<BuildingCluster
diff --git a/client/src/components/city/CityVoiceMarker.jsx b/client/src/components/city/CityVoiceMarker.jsx
new file mode 100644
index 0000000000..bbf05878bc
--- /dev/null
+++ b/client/src/components/city/CityVoiceMarker.jsx
@@ -0,0 +1,61 @@
+import { useMemo, useRef } from 'react';
+import { useFrame } from '@react-three/fiber';
+import { Text } from '@react-three/drei';
+import { PIXEL_FONT_URL } from './cityConstants';
+import { computeVoiceMarker } from '../../utils/cityVoiceMarker';
+
+// CyberCity's voice-agent district marker (roadmap 2.4): a modest ground-level beacon
+// north of downtown — a low disc with a short pole and a glowing orb on top. The orb's
+// color and pulse mirror the voice agent's live state: calm slate on standby, accent blue
+// while listening, green while dictating, red on error, and barely-lit when voice mode is
+// off. Keeps to a small footprint so it reads as a district marker, not a landmark.
+export default function CityVoiceMarker({ voiceState, settings }) {
+ const marker = useMemo(() => computeVoiceMarker(voiceState), [voiceState]);
+ const orbRef = useRef();
+
+ // Honor the quality dial: drop the beacon pulse on the lowest preset, but keep the
+ // static glow so the voice state stays legible.
+ const animate = (settings?.particleDensity ?? 1) >= 0.5;
+
+ useFrame(({ clock }) => {
+ if (!animate || !orbRef.current) return;
+ // Error throbs urgently; listening/dictating breathe actively; idle sits calm;
+ // a disabled marker holds its dim static glow (no pulse).
+ if (marker.disabled) {
+ orbRef.current.material.emissiveIntensity = marker.intensity;
+ return;
+ }
+ const speed = marker.alerting ? 3 : marker.active ? 2 : 0.7;
+ const pulse = 0.5 + ((Math.sin(clock.getElapsedTime() * speed) + 1) / 2) * 0.6;
+ orbRef.current.material.emissiveIntensity = pulse * (marker.intensity + 0.2);
+ });
+
+ const { position, baseRadius, poleHeight, beaconRadius, color, label } = marker;
+
+ return (
+ <group position={position}>
+ {/* Low disc base — anchors the marker to the ground */}
+ <mesh position={[0, 0.1, 0]}>
+ <cylinderGeometry args={[baseRadius, baseRadius * 1.15, 0.2, 24]} />
+ <meshStandardMaterial color="#0c1620" emissive={color} emissiveIntensity={0.12} metalness={0.5} roughness={0.6} />
+ </mesh>
+ {/* Slim antenna pole */}
+ <mesh position={[0, poleHeight / 2, 0]}>
+ <cylinderGeometry args={[0.14, 0.18, poleHeight, 12]} />
+ <meshStandardMaterial color="#1a2533" emissive={color} emissiveIntensity={0.15} metalness={0.7} roughness={0.4} />
+ </mesh>
+ {/* Beacon orb — the live voice-state indicator */}
+ <mesh ref={orbRef} position={[0, poleHeight + beaconRadius * 0.6, 0]}>
+ <sphereGeometry args={[beaconRadius, 20, 20]} />
+ <meshStandardMaterial color={color} emissive={color} emissiveIntensity={marker.intensity} toneMapped={false} />
+ </mesh>
+ {/* Label + live-state sublabel above the beacon */}
+ <Text position={[0, poleHeight + beaconRadius * 0.6 + 1.6, 0]} fontSize={1} color={color} anchorX="center" anchorY="middle" font={PIXEL_FONT_URL} maxWidth={16}>
+ VOICE
+ </Text>
+ <Text position={[0, poleHeight + beaconRadius * 0.6 + 0.9, 0]} fontSize={0.7} color="#94a3b8" anchorX="center" anchorY="middle" font={PIXEL_FONT_URL} maxWidth={16}>
+ {label}
+ </Text>
+ </group>
+ );
+}
diff --git a/client/src/hooks/useCityData.js b/client/src/hooks/useCityData.js
index 8b6b057d52..8e90fa5120 100644
--- a/client/src/hooks/useCityData.js
+++ b/client/src/hooks/useCityData.js
@@ -20,6 +20,9 @@ export const useCityData = () => {
const [notificationCounts, setNotificationCounts] = useState({ unread: 0 });
const [backupStatus, setBackupStatus] = useState(null);
const [cosTasks, setCosTasks] = useState([]);
+ // Voice-agent district marker: `enabled` from the persisted /voice/status payload,
+ // `live` driven by the per-socket voice:* events (idle | listening | dictating | error).
+ const [voiceState, setVoiceState] = useState(null);
const [loading, setLoading] = useState(true);
const logIdRef = useRef(0);
@@ -33,7 +36,7 @@ export const useCityData = () => {
// /notifications/count returns the lightweight { count } payload — the HUD
// and Attention pane only need unread, and notifications:count socket
// events keep it fresh after this initial fetch.
- const [appsData, agents, cosAgentsData, status, reviewData, instanceData, health, notif, backup, cosTasksData] = await Promise.all([
+ const [appsData, agents, cosAgentsData, status, reviewData, instanceData, health, notif, backup, cosTasksData, voice] = await Promise.all([
api.getApps().catch(() => []),
api.getRunningAgents().catch(() => []),
api.getCosAgents().catch(() => []),
@@ -44,6 +47,7 @@ export const useCityData = () => {
api.getNotificationCount().catch(() => ({ count: 0 })),
api.getBackupStatus({ silent: true }).catch(() => null),
api.getCosTasks({ silent: true }).catch(() => ({ tasks: [] })),
+ api.getVoiceStatus({ silent: true }).catch(() => null),
]);
setApps(appsData);
@@ -56,6 +60,10 @@ export const useCityData = () => {
setNotificationCounts({ unread: notif?.count ?? 0 });
setBackupStatus(backup);
setCosTasks(Array.isArray(cosTasksData?.tasks) ? cosTasksData.tasks : []);
+ // Seed the marker with the persisted enabled flag; live sub-state starts idle and the
+ // voice:* socket handlers below take over. Preserve a prior `live` across refetches so
+ // a mid-turn fetchAll doesn't snap the beacon back to idle.
+ setVoiceState(prev => ({ enabled: voice?.enabled ?? false, live: prev?.live || 'idle' }));
setLoading(false);
}, []);
@@ -188,6 +196,25 @@ export const useCityData = () => {
const handleCosTasksChanged = (data) => setCosTasks(Array.isArray(data?.tasks) ? data.tasks : []);
socket.on('cos:tasks:cos:changed', handleCosTasksChanged);
+ // Voice-agent district marker: the voice pipeline emits these directly to the
+ // active socket (no subscribe gate). `voice:dictation` toggles the dictating beacon,
+ // `voice:error` lights it red, and `voice:idle` (turn complete / reset) returns it to
+ // standby — unless dictation is still on, in which case it stays green.
+ const handleVoiceDictation = (data) => setVoiceState(prev => ({
+ ...(prev || { enabled: true }),
+ enabled: prev?.enabled ?? true,
+ live: data?.enabled ? 'dictating' : 'idle',
+ }));
+ const handleVoiceError = () => setVoiceState(prev => ({ ...(prev || { enabled: true }), live: 'error' }));
+ const handleVoiceIdle = () => setVoiceState(prev => (
+ // Keep dictating lit while a dictation session is active; a turn ending mid-dictation
+ // shouldn't blink the beacon back to standby.
+ prev?.live === 'dictating' ? prev : { ...(prev || { enabled: true }), live: 'idle' }
+ ));
+ socket.on('voice:dictation', handleVoiceDictation);
+ socket.on('voice:error', handleVoiceError);
+ socket.on('voice:idle', handleVoiceIdle);
+
// Subscribe but do NOT unsubscribe on cleanup. The cos:* and notifications:*
// namespaces are shared (useNotifications in Layout, useAgentFeedbackToast).
// Server uses a per-socket Set, so unsubscribing here would yank the
@@ -206,6 +233,9 @@ export const useCityData = () => {
socket.off('backup:started', handleBackupStarted);
socket.off('backup:completed', handleBackupCompleted);
socket.off('cos:tasks:cos:changed', handleCosTasksChanged);
+ socket.off('voice:dictation', handleVoiceDictation);
+ socket.off('voice:error', handleVoiceError);
+ socket.off('voice:idle', handleVoiceIdle);
};
}, [fetchAll, fetchApps, fetchBackup]);
@@ -222,6 +252,7 @@ export const useCityData = () => {
notificationCounts,
backupStatus,
cosTasks,
+ voiceState,
loading,
connected: socket.connected,
};
diff --git a/client/src/pages/CyberCity.jsx b/client/src/pages/CyberCity.jsx
index 41885ca863..ade464bda2 100644
--- a/client/src/pages/CyberCity.jsx
+++ b/client/src/pages/CyberCity.jsx
@@ -13,7 +13,7 @@ import CitySettingsPanel from '../components/city/CitySettingsPanel';
import { computeFilterResult } from '../utils/cityFilter';
function CyberCityInner() {
- const { apps, cosAgents, cosStatus, eventLogs, agentMap, reviewCounts, instances, systemHealth, notificationCounts, backupStatus, cosTasks, loading, connected } = useCityData();
+ const { apps, cosAgents, cosStatus, eventLogs, agentMap, reviewCounts, instances, systemHealth, notificationCounts, backupStatus, cosTasks, voiceState, loading, connected } = useCityData();
const { settings, updateSetting } = useCitySettingsContext();
const { playSfx } = useCityAudio(settings);
const navigate = useNavigate();
@@ -108,6 +108,7 @@ function CyberCityInner() {
instances={instances}
backupStatus={backupStatus}
cosTasks={cosTasks}
+ voiceState={voiceState}
productivityData={productivityData}
settings={settings}
playSfx={playSfx}
diff --git a/client/src/utils/cityVoiceMarker.js b/client/src/utils/cityVoiceMarker.js
new file mode 100644
index 0000000000..d2f70b6ca3
--- /dev/null
+++ b/client/src/utils/cityVoiceMarker.js
@@ -0,0 +1,94 @@
+// Pure, deterministic helpers for CyberCity's voice-agent district marker (roadmap 2.4):
+// a small ground-level beacon north of downtown whose lighting mirrors the voice agent's
+// live state — calm slate when idle, accent blue while listening, green while dictating,
+// red on error, and dimmed when voice mode is disabled. The live state is socket-driven
+// (`voice:idle` / `voice:dictation` / `voice:error`); the `enabled` flag comes from the
+// persisted /voice/status payload. No three.js / React imports so the topology is
+// unit-testable (mirrors cityBackupVault.js).
+
+export const MARKER = {
+ position: [0, 0, -40], // front-north: between the building grid (~±25) and the far skyline,
+ // clear of the backup vault (x≈-34), CoS warehouse (x≈+34), +Z archive district, and
+ // the federation horizon (radius 76).
+ baseRadius: 2.2,
+ poleHeight: 6,
+ beaconRadius: 0.9,
+};
+
+// Beacon color per voice state — reuses the PortOS Tailwind design tokens so the marker
+// speaks the same visual language as the rest of the UI.
+const STATE_COLORS = {
+ idle: '#475569', // slate — voice mode on, nothing happening
+ listening: '#3b82f6', // port-accent — capturing a turn
+ dictating: '#22c55e', // port-success — dictation appending to the daily log
+ error: '#ef4444', // port-error — a turn failed
+ disabled: '#1e293b', // dim slate — voice mode off
+};
+
+const STATE_LABELS = {
+ idle: 'STANDBY',
+ listening: 'LISTENING',
+ dictating: 'DICTATING',
+ error: 'VOICE ERROR',
+ disabled: 'VOICE OFF',
+};
+
+// Emissive intensity per state — the marker glows brightest while actively working
+// (listening / dictating), throbs on error, sits calm when idle, and barely lights when
+// disabled so it reads as "asleep" without disappearing.
+const STATE_INTENSITY = {
+ idle: 0.45,
+ listening: 1,
+ dictating: 1,
+ error: 0.9,
+ disabled: 0.12,
+};
+
+const VALID_STATES = new Set(['idle', 'listening', 'dictating', 'error', 'disabled']);
+
+// Derive the marker's live state from the voice view payload. `enabled` is the persisted
+// flag; `live` is the latest socket-driven sub-state (idle | listening | dictating | error).
+// Voice mode is treated as off unless `enabled === true` — an absent flag (status fetch
+// failed / voice never configured) reads as `disabled`, never as a live "on" state. A stale
+// live value is ignored while disabled. An unrecognized live value falls back to `idle`.
+export function markerState(voice) {
+ if (!voice || voice.enabled !== true) return 'disabled';
+ const live = voice.live;
+ if (live === 'error') return 'error';
+ if (live === 'dictating') return 'dictating';
+ if (live === 'listening') return 'listening';
+ return 'idle';
+}
+
+export function markerColor(state) {
+ return STATE_COLORS[VALID_STATES.has(state) ? state : 'idle'] || STATE_COLORS.idle;
+}
+
+export function markerLabel(state) {
+ return STATE_LABELS[VALID_STATES.has(state) ? state : 'idle'] || STATE_LABELS.idle;
+}
+
+// Should the beacon pulse urgently (error) vs. calmly? Listening/dictating get an active
+// pulse; idle breathes slowly; disabled doesn't animate.
+export function markerIsActive(state) {
+ return state === 'listening' || state === 'dictating';
+}
+
+// Full derived view-model for the component: position + state + color + label + flags +
+// emissive intensity. Mirrors computeBackupVault's shape so the component layer stays thin.
+export function computeVoiceMarker(voice) {
+ const state = markerState(voice);
+ return {
+ position: MARKER.position,
+ baseRadius: MARKER.baseRadius,
+ poleHeight: MARKER.poleHeight,
+ beaconRadius: MARKER.beaconRadius,
+ state,
+ color: markerColor(state),
+ label: markerLabel(state),
+ active: markerIsActive(state),
+ alerting: state === 'error',
+ disabled: state === 'disabled',
+ intensity: STATE_INTENSITY[state] ?? STATE_INTENSITY.idle,
+ };
+}
diff --git a/client/src/utils/cityVoiceMarker.test.js b/client/src/utils/cityVoiceMarker.test.js
new file mode 100644
index 0000000000..14ecab7e5a
--- /dev/null
+++ b/client/src/utils/cityVoiceMarker.test.js
@@ -0,0 +1,119 @@
+import { describe, it, expect } from 'vitest';
+import {
+ MARKER,
+ markerState,
+ markerColor,
+ markerLabel,
+ markerIsActive,
+ computeVoiceMarker,
+} from './cityVoiceMarker';
+
+describe('markerState', () => {
+ it('is disabled when voice mode is off, regardless of a stale live value', () => {
+ expect(markerState({ enabled: false })).toBe('disabled');
+ expect(markerState({ enabled: false, live: 'listening' })).toBe('disabled');
+ });
+
+ it('is disabled for missing / empty input', () => {
+ expect(markerState(undefined)).toBe('disabled');
+ expect(markerState(null)).toBe('disabled');
+ expect(markerState({})).toBe('disabled'); // enabled absent → treated as off
+ });
+
+ it('maps each live sub-state when voice mode is enabled', () => {
+ expect(markerState({ enabled: true, live: 'error' })).toBe('error');
+ expect(markerState({ enabled: true, live: 'dictating' })).toBe('dictating');
+ expect(markerState({ enabled: true, live: 'listening' })).toBe('listening');
+ expect(markerState({ enabled: true, live: 'idle' })).toBe('idle');
+ });
+
+ it('falls back to idle for an absent / unrecognized live value when enabled', () => {
+ expect(markerState({ enabled: true })).toBe('idle');
+ expect(markerState({ enabled: true, live: 'bogus' })).toBe('idle');
+ });
+
+ it('prioritizes error over other live states', () => {
+ // The live field carries one sub-state, but guard the precedence contract anyway.
+ expect(markerState({ enabled: true, live: 'error' })).toBe('error');
+ });
+});
+
+describe('markerColor', () => {
+ it('maps each state to a distinct token', () => {
+ expect(markerColor('idle')).toBe('#475569');
+ expect(markerColor('listening')).toBe('#3b82f6');
+ expect(markerColor('dictating')).toBe('#22c55e');
+ expect(markerColor('error')).toBe('#ef4444');
+ expect(markerColor('disabled')).toBe('#1e293b');
+ });
+
+ it('falls back to idle for an unknown state', () => {
+ expect(markerColor('bogus')).toBe(markerColor('idle'));
+ });
+});
+
+describe('markerLabel', () => {
+ it('gives a distinct uppercase label per state', () => {
+ expect(markerLabel('idle')).toBe('STANDBY');
+ expect(markerLabel('listening')).toBe('LISTENING');
+ expect(markerLabel('dictating')).toBe('DICTATING');
+ expect(markerLabel('error')).toBe('VOICE ERROR');
+ expect(markerLabel('disabled')).toBe('VOICE OFF');
+ });
+
+ it('falls back to the idle label for an unknown state', () => {
+ expect(markerLabel('bogus')).toBe(markerLabel('idle'));
+ });
+});
+
+describe('markerIsActive', () => {
+ it('is active only while listening or dictating', () => {
+ expect(markerIsActive('listening')).toBe(true);
+ expect(markerIsActive('dictating')).toBe(true);
+ expect(markerIsActive('idle')).toBe(false);
+ expect(markerIsActive('error')).toBe(false);
+ expect(markerIsActive('disabled')).toBe(false);
+ });
+});
+
+describe('computeVoiceMarker', () => {
+ it('carries the fixed position/geometry through unchanged', () => {
+ const vm = computeVoiceMarker({ enabled: true });
+ expect(vm.position).toEqual(MARKER.position);
+ expect(vm.baseRadius).toBe(MARKER.baseRadius);
+ expect(vm.poleHeight).toBe(MARKER.poleHeight);
+ expect(vm.beaconRadius).toBe(MARKER.beaconRadius);
+ });
+
+ it('derives color/label/flags/intensity for each state', () => {
+ const idle = computeVoiceMarker({ enabled: true, live: 'idle' });
+ expect(idle).toMatchObject({ state: 'idle', color: '#475569', label: 'STANDBY', active: false, alerting: false, disabled: false });
+ expect(idle.intensity).toBeGreaterThan(0);
+
+ const listening = computeVoiceMarker({ enabled: true, live: 'listening' });
+ expect(listening).toMatchObject({ state: 'listening', color: '#3b82f6', active: true, alerting: false });
+
+ const dictating = computeVoiceMarker({ enabled: true, live: 'dictating' });
+ expect(dictating).toMatchObject({ state: 'dictating', color: '#22c55e', active: true });
+
+ const error = computeVoiceMarker({ enabled: true, live: 'error' });
+ expect(error).toMatchObject({ state: 'error', color: '#ef4444', alerting: true, active: false });
+
+ const disabled = computeVoiceMarker({ enabled: false });
+ expect(disabled).toMatchObject({ state: 'disabled', color: '#1e293b', disabled: true, active: false });
+ expect(disabled.intensity).toBeLessThan(idle.intensity);
+ });
+
+ it('treats missing / empty input as disabled', () => {
+ expect(computeVoiceMarker(undefined).state).toBe('disabled');
+ expect(computeVoiceMarker(null).state).toBe('disabled');
+ expect(computeVoiceMarker({}).state).toBe('disabled');
+ });
+
+ it('always returns a finite emissive intensity', () => {
+ for (const live of ['idle', 'listening', 'dictating', 'error', undefined, 'bogus']) {
+ const vm = computeVoiceMarker({ enabled: true, live });
+ expect(Number.isFinite(vm.intensity)).toBe(true);
+ }
+ });
+});