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 productivity district to CyberCity (roadmap 2.6)

[._.]/ Adam Eivyb4cb0124c485
diff --git a/client/src/components/city/CityProductivityDistrict.jsx b/client/src/components/city/CityProductivityDistrict.jsx
new file mode 100644
index 0000000000..1de15ebc18
--- /dev/null
+++ b/client/src/components/city/CityProductivityDistrict.jsx
@@ -0,0 +1,81 @@
+import { useMemo, useRef } from 'react';
+import { useFrame } from '@react-three/fiber';
+import { Text } from '@react-three/drei';
+import { PIXEL_FONT_URL } from './cityConstants';
+import { computeProductivityMonument } from '../../utils/cityProductivity';
+
+// CyberCity's productivity district (roadmap 2.6): a tapered streak monument (an obelisk on
+// a stepped plinth) in a southwest district. Its height and glow scale with the user's
+// current CoS completion streak; its color tiers by recent velocity (green surging → blue
+// steady → amber slowing → red idle). No productivity data reads dim slate ("NO DATA"),
+// distinct from a real zero-day streak. The capstone pulses brighter the longer the streak,
+// faster while velocity is surging. Mirrors CityBackupVault / CityHealthTower.
+export default function CityProductivityDistrict({ productivityData, settings }) {
+ const monument = useMemo(() => computeProductivityMonument(productivityData), [productivityData]);
+ const capRef = useRef();
+
+ // Honor the quality dial: drop the capstone pulse on the lowest preset, but keep the
+ // static glow so the streak is still legible.
+ const animate = (settings?.particleDensity ?? 1) >= 0.5;
+
+ useFrame(({ clock }) => {
+ if (!animate || !capRef.current) return;
+ // A longer streak breathes brighter; a surging velocity beats faster.
+ const speed = monument.surging ? 3.2 : 1.1;
+ const pulse = 0.5 + ((Math.sin(clock.getElapsedTime() * speed) + 1) / 2) * 0.6;
+ capRef.current.material.emissiveIntensity = pulse * (monument.intensity + 0.25);
+ });
+
+ const { position, baseWidth, height, color } = monument;
+ const shaftTop = height; // top of the tapered shaft (above the plinth, see group offset)
+ const sublabel = monument.present && monument.longest !== null
+ ? `${monument.tierLabel} · BEST ${monument.longest}`
+ : monument.tierLabel;
+
+ return (
+ <group position={position}>
+ {/* Stepped plinth the obelisk rises from */}
+ <mesh position={[0, 0.4, 0]}>
+ <boxGeometry args={[baseWidth * 1.6, 0.8, baseWidth * 1.6]} />
+ <meshStandardMaterial color="#0a0e16" emissive={color} emissiveIntensity={0.08} metalness={0.6} roughness={0.5} />
+ </mesh>
+ <mesh position={[0, 1.0, 0]}>
+ <boxGeometry args={[baseWidth * 1.2, 0.5, baseWidth * 1.2]} />
+ <meshStandardMaterial color="#0c121d" emissive={color} emissiveIntensity={0.12} metalness={0.6} roughness={0.5} />
+ </mesh>
+
+ {/* Tapered obelisk shaft — height scales with the streak */}
+ <group position={[0, 1.25, 0]}>
+ <mesh position={[0, shaftTop / 2, 0]}>
+ <cylinderGeometry args={[baseWidth * 0.18, baseWidth * 0.42, shaftTop, 4]} />
+ <meshStandardMaterial
+ color="#0a0e16"
+ emissive={color}
+ emissiveIntensity={0.12 + monument.intensity * 0.25}
+ metalness={0.6}
+ roughness={0.45}
+ />
+ </mesh>
+
+ {/* Glowing capstone — the live streak indicator that pulses */}
+ <mesh ref={capRef} position={[0, shaftTop + baseWidth * 0.22, 0]} rotation={[0, Math.PI / 4, 0]}>
+ <coneGeometry args={[baseWidth * 0.34, baseWidth * 0.55, 4]} />
+ <meshStandardMaterial color={color} emissive={color} emissiveIntensity={monument.intensity} toneMapped={false} />
+ </mesh>
+
+ {/* District title + streak above the monument */}
+ <Text position={[0, shaftTop + 2.6, 0]} fontSize={1.3} color={color} anchorX="center" anchorY="middle" font={PIXEL_FONT_URL} maxWidth={22}>
+ {monument.streakLabel}
+ </Text>
+ <Text position={[0, shaftTop + 1.7, 0]} fontSize={0.8} color="#94a3b8" anchorX="center" anchorY="middle" font={PIXEL_FONT_URL} maxWidth={22}>
+ {sublabel}
+ </Text>
+ </group>
+
+ {/* Ground readout of today's throughput */}
+ <Text position={[0, 0.05, baseWidth * 1.1]} rotation={[-Math.PI / 2, 0, 0]} fontSize={0.7} color="#94a3b8" anchorX="center" anchorY="middle" font={PIXEL_FONT_URL} maxWidth={22}>
+ {monument.completedToday !== null ? `TODAY ${monument.completedToday} DONE` : 'PRODUCTIVITY'}
+ </Text>
+ </group>
+ );
+}
diff --git a/client/src/components/city/CityScene.jsx b/client/src/components/city/CityScene.jsx
index d00db92c60..9ad7f74af2 100644
--- a/client/src/components/city/CityScene.jsx
+++ b/client/src/components/city/CityScene.jsx
@@ -18,6 +18,7 @@ import CityFederationHorizon from './CityFederationHorizon';
import CityBackupVault from './CityBackupVault';
import CityTaskQueue from './CityTaskQueue';
import CityHealthTower from './CityHealthTower';
+import CityProductivityDistrict from './CityProductivityDistrict';
import CityVoiceMarker from './CityVoiceMarker';
import CityAiCore from './CityAiCore';
import CityDataRain from './CityDataRain';
@@ -82,6 +83,7 @@ export default function CityScene({ apps, agentMap, onBuildingClick, cosStatus,
<CityBackupVault backupStatus={backupStatus} settings={settings} />
<CityTaskQueue cosTasks={cosTasks} settings={settings} />
<CityHealthTower healthMetrics={healthMetrics} settings={settings} />
+ <CityProductivityDistrict productivityData={productivityData} settings={settings} />
<CityVoiceMarker voiceState={voiceState} settings={settings} />
<CityAiCore aiActivity={aiActivity} settings={settings} />
<CityGround settings={settings} />
diff --git a/client/src/utils/cityProductivity.js b/client/src/utils/cityProductivity.js
new file mode 100644
index 0000000000..f7705a23f4
--- /dev/null
+++ b/client/src/utils/cityProductivity.js
@@ -0,0 +1,104 @@
+// Pure, deterministic helpers for CyberCity's productivity district (roadmap 2.6): a
+// streak monument (a glowing obelisk) in a southwest district whose height and glow scale
+// with the user's current CoS completion streak, tiered by recent velocity. The monument
+// distinguishes "no productivity data yet" (absent → dim, reads "NO DATA") from a real
+// zero-day streak (present but unlit beyond the base). No three.js / React imports so the
+// topology is unit-testable (mirrors cityBackupVault.js / cityHealthTower.js).
+
+export const MONUMENT = {
+ position: [-48, 0, 28], // southwest district — clear of the vault (-34), grid, archive, and the SE wellness tower
+ baseWidth: 5, // footprint of the obelisk base
+ minHeight: 3, // floor height so a 0-streak monument still reads as a stub, not nothing
+ maxHeight: 26, // height at/above STREAK_CAP days
+ streakCap: 30, // streak length mapped to full height; longer streaks stay capped (don't overrun the skybox)
+};
+
+// Velocity tiers drive the monument color so the district speaks recent throughput at a
+// glance. `velocity.percentage` from the quick-summary payload is "today vs. historical
+// average", where 100 ≈ on pace. Colors reuse the PortOS Tailwind design tokens.
+const TIERS = [
+ { min: 120, key: 'surging', color: '#22c55e', label: 'SURGING' }, // port-success — well above pace
+ { min: 80, key: 'steady', color: '#3b82f6', label: 'STEADY' }, // port-accent — roughly on pace
+ { min: 40, key: 'slowing', color: '#f59e0b', label: 'SLOWING' }, // port-warning — below pace
+ { min: 0, key: 'idle', color: '#ef4444', label: 'IDLE' }, // port-error — little/no recent throughput
+];
+
+const ABSENT_COLOR = '#64748b'; // slate — no productivity data at all
+
+const clamp01 = (n) => Math.max(0, Math.min(1, n));
+
+// Coerce a value to a finite number or return null (the "absent" sentinel) so callers can
+// distinguish a missing/garbage field from a legitimate 0.
+function finiteOrNull(value) {
+ return typeof value === 'number' && Number.isFinite(value) ? value : null;
+}
+
+// Map a streak length (in days) to a 0..1 fill against the cap, clamped. Returns null for a
+// non-numeric input so an absent streak never collapses into a real 0-day streak.
+export function streakLevel(streak, cap = MONUMENT.streakCap) {
+ const s = finiteOrNull(streak);
+ if (s === null) return null;
+ if (typeof cap !== 'number' || !Number.isFinite(cap) || cap <= 0) return null;
+ return clamp01(s / cap);
+}
+
+// Classify recent velocity into a color tier. A non-numeric velocity (absent) falls through
+// to the lowest tier's color via the caller; here we only resolve a present number.
+export function velocityTier(velocity) {
+ const v = finiteOrNull(velocity);
+ if (v === null) return null;
+ return TIERS.find((t) => v >= t.min) || TIERS[TIERS.length - 1];
+}
+
+// Full derived view-model for the component. `productivityData` is the quick-summary payload
+// (`{ streak: { current, longest, weekly, lastActive }, today: { completed, ... },
+// velocity: { percentage, ... } }`). A missing/non-object payload, or one with no streak
+// field, yields an absent monument (dim, floor height) rather than a crash.
+export function computeProductivityMonument(productivityData) {
+ const payload = productivityData && typeof productivityData === 'object' ? productivityData : {};
+ const streakSrc = payload.streak && typeof payload.streak === 'object' ? payload.streak : {};
+ const todaySrc = payload.today && typeof payload.today === 'object' ? payload.today : {};
+ const velocitySrc = payload.velocity && typeof payload.velocity === 'object' ? payload.velocity : {};
+
+ const current = finiteOrNull(streakSrc.current);
+ const longest = finiteOrNull(streakSrc.longest);
+ const completedToday = finiteOrNull(todaySrc.completed);
+ const level = streakLevel(current) ?? 0; // 0 for both absent and a real 0-streak; `present` disambiguates
+ const present = current !== null;
+
+ const tier = velocityTier(velocitySrc.percentage);
+ // Absent productivity data reads slate/dim; a present payload always gets a tier color
+ // (idle red when velocity is missing-but-data-exists, so the monument never goes dark on
+ // a real-but-quiet day).
+ const color = present ? (tier?.color ?? TIERS[TIERS.length - 1].color) : ABSENT_COLOR;
+ const tierLabel = present ? (tier?.label ?? TIERS[TIERS.length - 1].label) : 'NO DATA';
+
+ const height = MONUMENT.minHeight + level * (MONUMENT.maxHeight - MONUMENT.minHeight);
+ // Emissive intensity: brighter as the streak grows; a present-but-zero streak still glows
+ // faintly so it's legible; an absent monument is nearly dark.
+ const intensity = present ? 0.3 + level * 0.7 : 0.1;
+
+ // Short streak label: "12 DAY STREAK" / "1 DAY STREAK" / "NO STREAK" (real 0) / "NO DATA".
+ let streakLabel;
+ if (!present) streakLabel = 'NO DATA';
+ else if (current === 0) streakLabel = 'NO STREAK';
+ else streakLabel = `${current} DAY${current === 1 ? '' : 'S'} STREAK`;
+
+ return {
+ position: MONUMENT.position,
+ baseWidth: MONUMENT.baseWidth,
+ height,
+ level,
+ present,
+ current: present ? current : null,
+ longest,
+ completedToday,
+ color,
+ intensity,
+ tierKey: present ? (tier?.key ?? TIERS[TIERS.length - 1].key) : 'absent',
+ tierLabel,
+ streakLabel,
+ // The monument pulses brighter the higher the streak; surging velocity adds urgency.
+ surging: tier?.key === 'surging',
+ };
+}
diff --git a/client/src/utils/cityProductivity.test.js b/client/src/utils/cityProductivity.test.js
new file mode 100644
index 0000000000..df98da582b
--- /dev/null
+++ b/client/src/utils/cityProductivity.test.js
@@ -0,0 +1,134 @@
+import { describe, it, expect } from 'vitest';
+import {
+ MONUMENT,
+ streakLevel,
+ velocityTier,
+ computeProductivityMonument,
+} from './cityProductivity';
+
+const full = {
+ streak: { current: 12, longest: 30, weekly: 3, lastActive: '2026-06-02' },
+ today: { completed: 8, succeeded: 7, failed: 1 },
+ velocity: { percentage: 130, label: 'surging' },
+};
+
+describe('streakLevel', () => {
+ it('maps streak/cap into 0..1', () => {
+ expect(streakLevel(15, 30)).toBe(0.5);
+ expect(streakLevel(30, 30)).toBe(1);
+ });
+
+ it('clamps above the cap to 1 and negatives to 0', () => {
+ expect(streakLevel(999, 30)).toBe(1);
+ expect(streakLevel(-5, 30)).toBe(0);
+ });
+
+ it('treats a legitimate zero streak as level 0, not absent', () => {
+ expect(streakLevel(0, 30)).toBe(0);
+ });
+
+ it('returns null for non-numeric streaks or bad caps', () => {
+ expect(streakLevel(undefined)).toBeNull();
+ expect(streakLevel(null)).toBeNull();
+ expect(streakLevel(NaN)).toBeNull();
+ expect(streakLevel('12')).toBeNull();
+ expect(streakLevel(12, 0)).toBeNull();
+ expect(streakLevel(12, -1)).toBeNull();
+ });
+});
+
+describe('velocityTier', () => {
+ it('classifies into the expected tiers', () => {
+ expect(velocityTier(130).key).toBe('surging');
+ expect(velocityTier(100).key).toBe('steady');
+ expect(velocityTier(60).key).toBe('slowing');
+ expect(velocityTier(10).key).toBe('idle');
+ expect(velocityTier(0).key).toBe('idle');
+ });
+
+ it('returns null for non-numeric velocity', () => {
+ expect(velocityTier(undefined)).toBeNull();
+ expect(velocityTier(null)).toBeNull();
+ expect(velocityTier(NaN)).toBeNull();
+ expect(velocityTier('100')).toBeNull();
+ });
+});
+
+describe('computeProductivityMonument', () => {
+ it('carries the fixed position and base width through unchanged', () => {
+ const vm = computeProductivityMonument(full);
+ expect(vm.position).toEqual(MONUMENT.position);
+ expect(vm.baseWidth).toBe(MONUMENT.baseWidth);
+ });
+
+ it('derives a full view-model from complete data', () => {
+ const vm = computeProductivityMonument(full);
+ expect(vm.present).toBe(true);
+ expect(vm.current).toBe(12);
+ expect(vm.longest).toBe(30);
+ expect(vm.completedToday).toBe(8);
+ expect(vm.level).toBeCloseTo(0.4);
+ expect(vm.color).toBe('#22c55e'); // surging tier
+ expect(vm.tierKey).toBe('surging');
+ expect(vm.surging).toBe(true);
+ expect(vm.streakLabel).toBe('12 DAYS STREAK');
+ expect(vm.height).toBeGreaterThan(MONUMENT.minHeight);
+ });
+
+ it('singularizes a one-day streak label', () => {
+ const vm = computeProductivityMonument({ ...full, streak: { current: 1 } });
+ expect(vm.streakLabel).toBe('1 DAY STREAK');
+ });
+
+ it('distinguishes a real zero-day streak from absent data', () => {
+ const zero = computeProductivityMonument({ streak: { current: 0 }, velocity: { percentage: 50 } });
+ expect(zero.present).toBe(true);
+ expect(zero.current).toBe(0);
+ expect(zero.level).toBe(0);
+ expect(zero.streakLabel).toBe('NO STREAK');
+ expect(zero.color).toBe('#f59e0b'); // slowing tier still colors it, not slate
+ expect(zero.height).toBeCloseTo(MONUMENT.minHeight);
+ expect(zero.intensity).toBeGreaterThan(0.1); // faintly lit, above the absent floor
+
+ const absent = computeProductivityMonument({});
+ expect(absent.present).toBe(false);
+ expect(absent.current).toBeNull();
+ expect(absent.level).toBe(0);
+ expect(absent.streakLabel).toBe('NO DATA');
+ expect(absent.tierLabel).toBe('NO DATA');
+ expect(absent.color).toBe('#64748b'); // slate
+ expect(absent.height).toBeCloseTo(MONUMENT.minHeight);
+ expect(absent.intensity).toBeLessThan(zero.intensity);
+ });
+
+ it('colors a present-but-velocity-missing payload as idle, never dark', () => {
+ const vm = computeProductivityMonument({ streak: { current: 5 } });
+ expect(vm.present).toBe(true);
+ expect(vm.color).toBe('#ef4444'); // idle tier fallback
+ expect(vm.tierLabel).toBe('IDLE');
+ });
+
+ it('clamps a streak above the cap to full height', () => {
+ const vm = computeProductivityMonument({ streak: { current: 9999 }, velocity: { percentage: 100 } });
+ expect(vm.level).toBe(1);
+ expect(vm.height).toBeCloseTo(MONUMENT.maxHeight);
+ expect(vm.intensity).toBeCloseTo(1);
+ });
+
+ it('handles null / undefined / non-object input as absent without crashing', () => {
+ for (const bad of [null, undefined, 'nope', 42, []]) {
+ const vm = computeProductivityMonument(bad);
+ expect(vm.present).toBe(false);
+ expect(vm.level).toBe(0);
+ expect(vm.streakLabel).toBe('NO DATA');
+ expect(vm.position).toEqual(MONUMENT.position);
+ }
+ });
+
+ it('tolerates a non-object streak/today/velocity sub-field', () => {
+ const vm = computeProductivityMonument({ streak: 'oops', today: 5, velocity: null });
+ expect(vm.present).toBe(false);
+ expect(vm.completedToday).toBeNull();
+ expect(vm.longest).toBeNull();
+ });
+});