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 earned artifacts to CyberCity (roadmap 3.5)

[._.]/ Adam Eivy7cee082afa29
diff --git a/client/src/components/city/CityArtifacts.jsx b/client/src/components/city/CityArtifacts.jsx
new file mode 100644
index 0000000000..c528927c90
--- /dev/null
+++ b/client/src/components/city/CityArtifacts.jsx
@@ -0,0 +1,85 @@
+import { useMemo, useRef } from 'react';
+import { useFrame } from '@react-three/fiber';
+import { Text } from '@react-three/drei';
+import { PIXEL_FONT_URL } from './cityConstants';
+import { computeArtifacts, ARTIFACTS } from '../../utils/cityArtifacts';
+
+// CyberCity's earned artifacts (roadmap 3.5): a "Hall of Achievements" cluster of trophies
+// that only appear once a milestone is earned (level-ups, completed-goal counts, best CoS
+// streak). Each artifact is a dark pedestal topped by a glowing faceted emblem (an octahedron)
+// — visually distinct from the goal monuments' tower/scaffold so milestones don't read as
+// goals. The emblems shimmer in unison via a single per-frame ref mutation, gated on the
+// quality dial. Mirrors CityGoalMonuments / CityProductivityDistrict.
+function Artifact({ artifact }) {
+ const { color, intensity, label, position } = artifact;
+ const { pedestalWidth: pw, pedestalHeight: ph, emblemSize } = ARTIFACTS;
+ const emblemY = ph + emblemSize * 0.6;
+
+ return (
+ <group position={position}>
+ {/* Pedestal base */}
+ <mesh position={[0, ph / 2, 0]}>
+ <cylinderGeometry args={[pw * 0.6, pw * 0.7, ph, 6]} />
+ <meshStandardMaterial color="#0a0e16" emissive={color} emissiveIntensity={0.12} metalness={0.7} roughness={0.4} />
+ </mesh>
+
+ {/* Glowing faceted emblem — the artifact itself */}
+ <mesh position={[0, emblemY, 0]} rotation={[0, Math.PI / 4, 0]}>
+ <octahedronGeometry args={[emblemSize, 0]} />
+ <meshStandardMaterial color={color} emissive={color} emissiveIntensity={intensity} metalness={0.5} roughness={0.25} toneMapped={false} />
+ </mesh>
+
+ {/* A small point light makes the emblem read as a beacon at distance */}
+ <pointLight position={[0, emblemY, 0]} color={color} intensity={intensity * 1.5} distance={10} />
+
+ {/* Label below the pedestal */}
+ <Text position={[0, ph + emblemSize * 1.7, 0]} fontSize={0.5} color={color} anchorX="center" anchorY="middle" font={PIXEL_FONT_URL} maxWidth={6}>
+ {label}
+ </Text>
+ </group>
+ );
+}
+
+export default function CityArtifacts({ character, goals, productivityData, settings }) {
+ const hall = useMemo(
+ () => computeArtifacts({ character, goals, productivityData }),
+ [character, goals, productivityData],
+ );
+
+ // Shared shimmer driver: one ref scales emissive intensity for the whole cluster, so the
+ // shimmer is a single per-frame mutation regardless of artifact count.
+ const groupRef = useRef();
+
+ // Honor the quality dial: drop the shimmer on the lowest preset, but keep the static glow so
+ // earned artifacts stay legible.
+ const animate = (settings?.particleDensity ?? 1) >= 0.5;
+
+ useFrame(({ clock }) => {
+ if (!animate || !groupRef.current) return;
+ const pulse = (Math.sin(clock.getElapsedTime() * 1.4) + 1) / 2; // 0..1
+ const scale = 1 + pulse * 0.08;
+ groupRef.current.scale.set(scale, scale, scale);
+ });
+
+ if (!hall.hasData) return null;
+
+ const { base, artifacts, total } = hall;
+
+ return (
+ <group>
+ <group ref={groupRef}>
+ {artifacts.map((artifact) => (
+ <Artifact key={artifact.id} artifact={artifact} />
+ ))}
+ </group>
+
+ {/* District title behind the cluster */}
+ <Text position={[base[0], 10, base[2] + 4]} fontSize={1.2} color="#f59e0b" anchorX="center" anchorY="middle" font={PIXEL_FONT_URL} maxWidth={24}>
+ ACHIEVEMENTS
+ </Text>
+ <Text position={[base[0], 9, base[2] + 4]} fontSize={0.7} color="#94a3b8" anchorX="center" anchorY="middle" font={PIXEL_FONT_URL} maxWidth={24}>
+ {`${total} EARNED`}
+ </Text>
+ </group>
+ );
+}
diff --git a/client/src/components/city/CityScene.jsx b/client/src/components/city/CityScene.jsx
index 48e31adbb6..e4860d5c4d 100644
--- a/client/src/components/city/CityScene.jsx
+++ b/client/src/components/city/CityScene.jsx
@@ -20,6 +20,7 @@ import CityTaskQueue from './CityTaskQueue';
import CityHealthTower from './CityHealthTower';
import CityProductivityDistrict from './CityProductivityDistrict';
import CityGoalMonuments from './CityGoalMonuments';
+import CityArtifacts from './CityArtifacts';
import CityVoiceMarker from './CityVoiceMarker';
import CityAiCore from './CityAiCore';
import CityDataRain from './CityDataRain';
@@ -32,7 +33,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, healthMetrics, voiceState, aiActivity, productivityData, goals, settings, playSfx, keysRef, dimmedAppIds }) {
+export default function CityScene({ apps, agentMap, onBuildingClick, cosStatus, reviewCounts, instances, backupStatus, cosTasks, healthMetrics, voiceState, aiActivity, productivityData, goals, character, settings, playSfx, keysRef, dimmedAppIds }) {
const [positions, setPositions] = useState(null);
const [proximityApp, setProximityApp] = useState(null);
const [transitioning, setTransitioning] = useState(false);
@@ -86,6 +87,7 @@ export default function CityScene({ apps, agentMap, onBuildingClick, cosStatus,
<CityHealthTower healthMetrics={healthMetrics} settings={settings} />
<CityProductivityDistrict productivityData={productivityData} settings={settings} />
<CityGoalMonuments goals={goals} settings={settings} />
+ <CityArtifacts character={character} goals={goals} productivityData={productivityData} settings={settings} />
<CityVoiceMarker voiceState={voiceState} settings={settings} />
<CityAiCore aiActivity={aiActivity} settings={settings} />
<CityGround settings={settings} />
diff --git a/client/src/pages/CyberCity.jsx b/client/src/pages/CyberCity.jsx
index 7c18f44c43..9658c1d403 100644
--- a/client/src/pages/CyberCity.jsx
+++ b/client/src/pages/CyberCity.jsx
@@ -120,6 +120,7 @@ function CyberCityInner() {
aiActivity={aiActivity}
productivityData={productivityData}
goals={goalsData}
+ character={character}
settings={settings}
playSfx={playSfx}
keysRef={keysRef}
diff --git a/client/src/utils/cityArtifacts.js b/client/src/utils/cityArtifacts.js
new file mode 100644
index 0000000000..99ffdcf06d
--- /dev/null
+++ b/client/src/utils/cityArtifacts.js
@@ -0,0 +1,155 @@
+// Pure, deterministic helpers for CyberCity's "earned artifacts" (roadmap 3.5): a small
+// "Hall of Achievements" cluster of trophies/statues that only appear once a milestone is
+// earned. Artifacts are DERIVED from data the city already has — no new endpoint:
+// • level milestones — D&D-style character level crossing a threshold (level-up statues)
+// • completed-goal milestones — every Nth completed life goal (achievement trophies)
+// • streak milestones — best CoS completion streak crossing a threshold (streak trophies)
+// Nothing earned → empty cluster (no crash). No three.js / React imports so the topology is
+// unit-testable (mirrors cityGoalMonuments.js / cityProductivity.js).
+
+import { levelFromXP } from './characterXp';
+
+// Hall of Achievements — a clear cluster in the +X / -Z quadrant, between the task-queue
+// (x≈+34, z≈-10), health tower (x≈+48, z≈+28), goal-monument row (z≈-40) and voice marker
+// ([0,0,-40]). Artifacts lay out in a tight grid centered on this base.
+export const ARTIFACTS = {
+ base: [44, 0, -28], // center of the cluster
+ spacing: 6, // distance between adjacent pedestals (both x and z)
+ columns: 3, // grid width before wrapping to the next row (toward -Z)
+ pedestalWidth: 2,
+ pedestalHeight: 1.2,
+ emblemSize: 1.4, // size of the glowing emblem atop a pedestal
+};
+
+// Tiers drive the emblem color + glow so a richer milestone reads brighter. Colors reuse the
+// PortOS Tailwind design tokens.
+const TIERS = {
+ bronze: { color: '#f59e0b', intensity: 0.45 }, // port-warning
+ silver: { color: '#94a3b8', intensity: 0.6 }, // slate-light
+ gold: { color: '#22c55e', intensity: 0.85 }, // port-success
+};
+
+// Level-up milestones: a statue per crossed level threshold. Below level 2 nothing is earned
+// (level 1 is the starting state). Higher levels read as richer tiers.
+export const LEVEL_MILESTONES = [
+ { level: 2, tier: 'bronze', label: 'NOVICE' },
+ { level: 5, tier: 'silver', label: 'ADEPT' },
+ { level: 10, tier: 'gold', label: 'MASTER' },
+];
+
+// Completed-goal milestones: a trophy for every Nth completed life goal.
+export const GOAL_MILESTONES = [
+ { count: 1, tier: 'bronze', label: 'FIRST GOAL' },
+ { count: 5, tier: 'silver', label: '5 GOALS' },
+ { count: 10, tier: 'gold', label: '10 GOALS' },
+];
+
+// Best-streak milestones (in days): a trophy when the longest CoS completion streak crosses
+// a threshold. Uses the *best* (longest) streak so an earned trophy never disappears when the
+// current streak resets.
+export const STREAK_MILESTONES = [
+ { days: 3, tier: 'bronze', label: '3 DAY STREAK' },
+ { days: 7, tier: 'silver', label: '7 DAY STREAK' },
+ { days: 30, tier: 'gold', label: '30 DAY STREAK' },
+];
+
+// Coerce a value to a finite number or return null (the "absent" sentinel) so an absent field
+// never collapses into a real 0.
+function finiteOrNull(value) {
+ return typeof value === 'number' && Number.isFinite(value) ? value : null;
+}
+
+// Effective character level: trust a stored, consistent `level`; otherwise derive it from xp
+// (mirrors computeXpView in characterXp.js). Returns null when neither is usable.
+export function effectiveLevel(character) {
+ const lvl = character?.level;
+ if (Number.isFinite(lvl) && lvl >= 1) return Math.floor(lvl);
+ const xp = finiteOrNull(character?.xp);
+ if (xp === null) return null;
+ return levelFromXP(xp);
+}
+
+// Count completed goals from the goals payload. Accepts either the API wrapper `{ goals: [] }`
+// or a bare array; a missing/garbage input counts as 0.
+export function completedGoalCount(goals) {
+ const list = Array.isArray(goals) ? goals : Array.isArray(goals?.goals) ? goals.goals : [];
+ return list.filter((g) => g && typeof g === 'object' && g.status === 'completed').length;
+}
+
+// Best (longest) streak in days from the productivity quick-summary payload
+// (`{ streak: { current, longest, ... } }`). Falls back to `current` if `longest` is absent so
+// a payload that only carries a current streak still earns trophies. Returns null when absent.
+export function bestStreakDays(productivityData) {
+ const streak = productivityData?.streak;
+ if (!streak || typeof streak !== 'object') return null;
+ const longest = finiteOrNull(streak.longest);
+ if (longest !== null) return longest;
+ return finiteOrNull(streak.current);
+}
+
+// Build the list of EARNED artifact descriptors (kind/label/tier/threshold) from the three
+// inputs, before placement. Deterministic and side-effect-free.
+export function earnedArtifacts({ character, goals, productivityData } = {}) {
+ const earned = [];
+
+ const level = effectiveLevel(character);
+ if (level !== null) {
+ for (const m of LEVEL_MILESTONES) {
+ if (level >= m.level) {
+ earned.push({ id: `level-${m.level}`, kind: 'level', tier: m.tier, label: m.label, threshold: m.level });
+ }
+ }
+ }
+
+ const completed = completedGoalCount(goals);
+ for (const m of GOAL_MILESTONES) {
+ if (completed >= m.count) {
+ earned.push({ id: `goals-${m.count}`, kind: 'goal', tier: m.tier, label: m.label, threshold: m.count });
+ }
+ }
+
+ const streak = bestStreakDays(productivityData);
+ if (streak !== null) {
+ for (const m of STREAK_MILESTONES) {
+ if (streak >= m.days) {
+ earned.push({ id: `streak-${m.days}`, kind: 'streak', tier: m.tier, label: m.label, threshold: m.days });
+ }
+ }
+ }
+
+ return earned;
+}
+
+// Place a descriptor into the cluster grid. `index` is the 0-based slot; the grid fills left→
+// right across ARTIFACTS.columns, then wraps to the next row toward -Z. Centered on base.x.
+export function placeArtifact(descriptor, index) {
+ const col = index % ARTIFACTS.columns;
+ const row = Math.floor(index / ARTIFACTS.columns);
+ const xOffset = (col - (ARTIFACTS.columns - 1) / 2) * ARTIFACTS.spacing;
+ const x = ARTIFACTS.base[0] + xOffset;
+ const z = ARTIFACTS.base[2] - row * ARTIFACTS.spacing;
+ const tier = TIERS[descriptor.tier] || TIERS.bronze;
+
+ return {
+ ...descriptor,
+ color: tier.color,
+ intensity: tier.intensity,
+ position: [x, 0, z],
+ };
+}
+
+// Full derived view-model for the component. Injects all inputs; an all-absent / nothing-earned
+// state yields an empty cluster (`hasData: false`) rather than a crash. Ordering is stable
+// (level → goal → streak, each ascending threshold) so the cluster doesn't reshuffle across
+// refetches.
+export function computeArtifacts({ character, goals, productivityData } = {}) {
+ const descriptors = earnedArtifacts({ character, goals, productivityData });
+ const artifacts = descriptors.map((d, i) => placeArtifact(d, i));
+
+ return {
+ base: ARTIFACTS.base,
+ artifacts,
+ total: artifacts.length,
+ hasData: artifacts.length > 0,
+ };
+}
diff --git a/client/src/utils/cityArtifacts.test.js b/client/src/utils/cityArtifacts.test.js
new file mode 100644
index 0000000000..270868044e
--- /dev/null
+++ b/client/src/utils/cityArtifacts.test.js
@@ -0,0 +1,175 @@
+import { describe, it, expect } from 'vitest';
+import {
+ ARTIFACTS,
+ LEVEL_MILESTONES,
+ GOAL_MILESTONES,
+ STREAK_MILESTONES,
+ effectiveLevel,
+ completedGoalCount,
+ bestStreakDays,
+ earnedArtifacts,
+ placeArtifact,
+ computeArtifacts,
+} from './cityArtifacts';
+
+const completedGoals = (n) =>
+ Array.from({ length: n }, (_, i) => ({ id: `g-${i}`, status: 'completed' }));
+
+describe('effectiveLevel', () => {
+ it('trusts a stored, consistent level', () => {
+ expect(effectiveLevel({ level: 7 })).toBe(7);
+ expect(effectiveLevel({ level: 3.9 })).toBe(3); // floored
+ });
+
+ it('derives level from xp when no usable level', () => {
+ expect(effectiveLevel({ xp: 300 })).toBe(2); // 300 xp → level 2
+ expect(effectiveLevel({ xp: 0 })).toBe(1);
+ });
+
+ it('returns null when neither level nor xp is usable', () => {
+ expect(effectiveLevel(null)).toBeNull();
+ expect(effectiveLevel({})).toBeNull();
+ expect(effectiveLevel({ level: 0, xp: 'nope' })).toBeNull();
+ });
+});
+
+describe('completedGoalCount', () => {
+ it('counts only completed goals', () => {
+ const goals = [
+ { id: 'a', status: 'completed' },
+ { id: 'b', status: 'active' },
+ { id: 'c', status: 'completed' },
+ { id: 'd', status: 'abandoned' },
+ ];
+ expect(completedGoalCount(goals)).toBe(2);
+ });
+
+ it('accepts the API wrapper { goals: [] }', () => {
+ expect(completedGoalCount({ goals: completedGoals(3) })).toBe(3);
+ });
+
+ it('is 0 for missing / garbage / null-entry input', () => {
+ for (const bad of [null, undefined, 'nope', 42, {}]) {
+ expect(completedGoalCount(bad)).toBe(0);
+ }
+ expect(completedGoalCount([null, 'x', { status: 'completed' }])).toBe(1);
+ });
+});
+
+describe('bestStreakDays', () => {
+ it('prefers longest over current', () => {
+ expect(bestStreakDays({ streak: { current: 2, longest: 9 } })).toBe(9);
+ });
+
+ it('falls back to current when longest absent', () => {
+ expect(bestStreakDays({ streak: { current: 4 } })).toBe(4);
+ });
+
+ it('returns null when no streak data', () => {
+ expect(bestStreakDays(null)).toBeNull();
+ expect(bestStreakDays({})).toBeNull();
+ expect(bestStreakDays({ streak: {} })).toBeNull();
+ expect(bestStreakDays({ streak: 'nope' })).toBeNull();
+ });
+});
+
+describe('earnedArtifacts — thresholds', () => {
+ it('returns nothing when nothing is earned', () => {
+ expect(earnedArtifacts({})).toEqual([]);
+ expect(earnedArtifacts({ character: { level: 1 }, goals: [], productivityData: { streak: { longest: 0 } } })).toEqual([]);
+ });
+
+ it('earns level milestones at/above each threshold', () => {
+ const ids = earnedArtifacts({ character: { level: 5 } }).map((a) => a.id);
+ expect(ids).toContain('level-2');
+ expect(ids).toContain('level-5');
+ expect(ids).not.toContain('level-10');
+ });
+
+ it('does not earn a level statue at level 1', () => {
+ expect(earnedArtifacts({ character: { level: 1 } })).toEqual([]);
+ });
+
+ it('earns goal milestones for completed-goal counts', () => {
+ const ids = earnedArtifacts({ goals: completedGoals(5) }).map((a) => a.id);
+ expect(ids).toContain('goals-1');
+ expect(ids).toContain('goals-5');
+ expect(ids).not.toContain('goals-10');
+ });
+
+ it('earns streak milestones from the best streak', () => {
+ const ids = earnedArtifacts({ productivityData: { streak: { longest: 7 } } }).map((a) => a.id);
+ expect(ids).toContain('streak-3');
+ expect(ids).toContain('streak-7');
+ expect(ids).not.toContain('streak-30');
+ });
+
+ it('combines all three sources in stable order (level → goal → streak)', () => {
+ const earned = earnedArtifacts({
+ character: { level: 2 },
+ goals: completedGoals(1),
+ productivityData: { streak: { longest: 3 } },
+ });
+ expect(earned.map((a) => a.kind)).toEqual(['level', 'goal', 'streak']);
+ expect(earned.map((a) => a.id)).toEqual(['level-2', 'goals-1', 'streak-3']);
+ });
+
+ it('attaches a tier + label to each descriptor', () => {
+ const [a] = earnedArtifacts({ character: { level: 2 } });
+ expect(a.tier).toBe('bronze');
+ expect(a.label).toBe('NOVICE');
+ expect(a.threshold).toBe(2);
+ });
+});
+
+describe('placeArtifact', () => {
+ it('centers the first row on base.x and resolves the tier color', () => {
+ const placed = placeArtifact({ id: 'x', kind: 'level', tier: 'gold', label: 'L' }, 1);
+ // index 1 is the middle column of a 3-wide grid → centered on base.x
+ expect(placed.position[0]).toBeCloseTo(ARTIFACTS.base[0]);
+ expect(placed.position[2]).toBe(ARTIFACTS.base[2]);
+ expect(placed.color).toBe('#22c55e');
+ expect(placed.intensity).toBeGreaterThan(0);
+ });
+
+ it('wraps to the next row toward -Z after columns are filled', () => {
+ const first = placeArtifact({ id: 'a', tier: 'bronze' }, 0);
+ const wrapped = placeArtifact({ id: 'b', tier: 'bronze' }, ARTIFACTS.columns);
+ expect(wrapped.position[0]).toBeCloseTo(first.position[0]); // same column
+ expect(wrapped.position[2]).toBe(ARTIFACTS.base[2] - ARTIFACTS.spacing); // one row back
+ });
+
+ it('falls back to the bronze tier for an unknown tier', () => {
+ const placed = placeArtifact({ id: 'x', tier: 'unknown' }, 0);
+ expect(placed.color).toBe('#f59e0b');
+ });
+});
+
+describe('computeArtifacts', () => {
+ it('handles all-absent input as an empty cluster (no crash)', () => {
+ const vm = computeArtifacts({});
+ expect(vm.artifacts).toEqual([]);
+ expect(vm.total).toBe(0);
+ expect(vm.hasData).toBe(false);
+ expect(vm.base).toEqual(ARTIFACTS.base);
+ });
+
+ it('handles a fully-undefined call', () => {
+ const vm = computeArtifacts();
+ expect(vm.hasData).toBe(false);
+ });
+
+ it('places one artifact per earned milestone', () => {
+ const vm = computeArtifacts({
+ character: { level: 10 }, // 3 level milestones
+ goals: completedGoals(10), // 3 goal milestones
+ productivityData: { streak: { longest: 30 } }, // 3 streak milestones
+ });
+ expect(vm.total).toBe(LEVEL_MILESTONES.length + GOAL_MILESTONES.length + STREAK_MILESTONES.length);
+ expect(vm.hasData).toBe(true);
+ for (const a of vm.artifacts) {
+ expect(a.position).toHaveLength(3);
+ expect(typeof a.color).toBe('string');
+ }
+ });
+});