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): calendar-accurate age, fix XP-decoupled surfaces, birthday flash
[._.]/ Adam Eivy619aaeda33ee
diff --git a/client/src/components/city/CityHudCompact.jsx b/client/src/components/city/CityHudCompact.jsxindex f727233a0b..db0b945667 100644--- a/client/src/components/city/CityHudCompact.jsx+++ b/client/src/components/city/CityHudCompact.jsx@@ -170,7 +170,7 @@ export default function CityHudCompact({<StatusDot on={connected} label={connected ? 'Link online' : 'Link offline'} onClass="bg-port-success shadow-[0_0_8px_rgba(34,197,94,0.6)]" offClass="bg-port-error" /><StatusDot on={cosStatus?.running} label={cosStatus?.running ? 'CoS running' : 'CoS idle'} onClass="bg-cyan-400 animate-pulse shadow-[0_0_8px_rgba(6,182,212,0.6)]" /></div>- {character?.level != null && (+ {character?.level != null ? (<buttontype="button"onClick={() => navigate('/character')}@@ -180,7 +180,19 @@ export default function CityHudCompact({>LV {character.level}</button>- )}+ ) : character ? (+ // Character loaded but no birthDate → level is null (age-based, #2673). Prompt the+ // user to set it, routing to the age editor where the birth-date field lives.+ <button+ type="button"+ onClick={() => navigate('/meatspace/age')}+ aria-label="Set your birth date to show your level"+ title="Set your birth date"+ className="bg-black/85 backdrop-blur-sm border border-cyan-500/40 rounded-lg px-2.5 min-h-[44px] flex items-center font-pixel text-[11px] text-cyan-300/70 tracking-wider"+ >+ LV —+ </button>+ ) : null}</div>{/* Focused building detail sheet (issue #2593) — replaces the disclosure sheet while adiff --git a/client/src/components/city/CityXpBadge.jsx b/client/src/components/city/CityXpBadge.jsxindex 7b3076624a..2f76ad8f0d 100644--- a/client/src/components/city/CityXpBadge.jsx+++ b/client/src/components/city/CityXpBadge.jsx@@ -27,7 +27,9 @@ export default function CityXpBadge({ character }) {if (!character) return;const { gained, leveledUp } = diffXp(prev, character);- if (gained <= 0) return;+ // Fire on an XP gain (cyan) OR a birthday age-level tick (amber) — a birthday rarely+ // coincides with an XP gain, so it must be able to burst on its own.+ if (gained <= 0 && !leveledUp) return;setBurst(b => ({ kind: leveledUp ? 'levelup' : 'gain', seq: b.seq + 1, gained }));clearTimeout(burstTimerRef.current);@@ -48,16 +50,17 @@ export default function CityXpBadge({ character }) {const gaining = burst.kind !== null;const barColor = leveling ? '#f59e0b' : '#06b6d4';const pct = Math.round(view.progress * 100);- // No birthDate set → level is null; show a prompt instead of NaN. The badge still links- // to /character where the birth date can be set (Slice 5 owns the inline prompt UI).+ // No birthDate set → level is null; show a prompt instead of NaN, and send the click to the+ // age editor (where the birth-date field actually lives) rather than the character sheet.const levelLabel = view.hasBirthDate ? `LV ${view.level}` : 'LV —';+ const target = view.hasBirthDate ? '/character' : '/meatspace/age';return (<div className="absolute bottom-16 right-3 pointer-events-auto"><buttontype="button"- onClick={() => navigate('/character')}- title="Open character sheet"+ onClick={() => navigate(target)}+ title={view.hasBirthDate ? 'Open character sheet' : 'Set your birth date'}className={`relative block w-40 sm:w-48 bg-black/85 backdrop-blur-sm border rounded-lg px-3 py-2.5 overflow-hidden text-left transition-all duration-300 hover:bg-cyan-500/10 ${leveling? 'border-amber-400/70 shadow-[0_0_16px_rgba(245,158,11,0.5)]'diff --git a/client/src/pages/CharacterSheet.jsx b/client/src/pages/CharacterSheet.jsxindex 4c44f704f1..40361d0745 100644--- a/client/src/pages/CharacterSheet.jsx+++ b/client/src/pages/CharacterSheet.jsx@@ -18,18 +18,6 @@ const charGet = (options = {}) => api.get('/character', { silent: true, ...optioconst charPost = (path, body, options = {}) => api.post(`/character${path}`, body, { silent: true, ...options });const charPut = (body, options = {}) => api.put('/character', body, { silent: true, ...options });-// D&D 5e XP thresholds (must match server)-const XP_THRESHOLDS = [- 0, 300, 900, 2700, 6500, 14000, 23000, 34000, 48000, 64000,- 85000, 100000, 120000, 140000, 165000, 195000, 225000, 265000, 305000, 355000-];-function xpForNextLevel(level) {- return level >= 20 ? XP_THRESHOLDS[19] : XP_THRESHOLDS[level];-}-function xpForCurrentLevel(level) {- return level <= 1 ? 0 : XP_THRESHOLDS[level - 1];-}-const EVENT_ICONS = {damage: Sword,xp: Star,@@ -296,10 +284,12 @@ export default function CharacterSheet() {}const hpPct = Math.max(0, Math.min(100, (char.hp / char.maxHp) * 100));- const nextLevelXP = xpForNextLevel(char.level);- const currentLevelXP = xpForCurrentLevel(char.level);- const levelRange = nextLevelXP - currentLevelXP;- const xpPct = char.level >= 20 ? 100 : Math.max(0, Math.min(100, ((char.xp - currentLevelXP) / levelRange) * 100));+ // Level is age-derived now (#2673) — it no longer maps to an XP threshold, so the old+ // "XP toward next level" bar is gone. XP survives as a plain cumulative stat here; the+ // birthday-progress bar lives on the CyberCity HUD badge (full page reframe is Slice 5).+ const birthdayPct = Number.isFinite(char.ageYears)+ ? Math.round((char.ageYears - Math.floor(char.ageYears)) * 100)+ : 0;return (<div className="h-full flex flex-col overflow-hidden">@@ -421,7 +411,7 @@ export default function CharacterSheet() {<div className="flex-shrink-0 flex items-center gap-3"><div className="relative w-20 h-20 flex items-center justify-center rounded-full border-2 border-port-accent bg-port-bg"><div className="text-center">- <div className="text-2xl font-bold text-port-accent">{char.level}</div>+ <div className="text-2xl font-bold text-port-accent">{char.level ?? '—'}</div><div className="text-[10px] uppercase tracking-wider text-gray-500">Level</div></div></div>@@ -447,24 +437,30 @@ export default function CharacterSheet() {</div></div>- {/* XP Bar */}- <div className="mt-3">- <div className="flex items-center justify-between mb-1">- <div className="flex items-center gap-1.5 text-sm font-medium text-gray-300">- <Sparkles className="w-4 h-4 text-port-warning" />- XP- </div>- <span className="text-sm text-gray-400">- {char.xp} / {nextLevelXP}- </span>- </div>- <div className="h-3 bg-port-bg rounded-full overflow-hidden border border-port-border">- <div- className="h-full rounded-full transition-all duration-500 ease-out bg-port-warning"- style={{ width: `${xpPct}%` }}- />+ {/* XP — a cumulative stat now (no longer a level-progress bar; level is age-based) */}+ <div className="mt-3 flex items-center justify-between">+ <div className="flex items-center gap-1.5 text-sm font-medium text-gray-300">+ <Sparkles className="w-4 h-4 text-port-warning" />+ XP</div>+ <span className="text-sm text-gray-400">{char.xp}</span></div>++ {/* Progress toward the next birthday (fractional part of the current year of life) */}+ {char.level != null && (+ <div className="mt-3">+ <div className="flex items-center justify-between mb-1">+ <div className="text-sm font-medium text-gray-300">Next birthday</div>+ <span className="text-sm text-gray-400">{birthdayPct}%</span>+ </div>+ <div className="h-3 bg-port-bg rounded-full overflow-hidden border border-port-border">+ <div+ className="h-full rounded-full transition-all duration-500 ease-out bg-port-accent"+ style={{ width: `${birthdayPct}%` }}+ />+ </div>+ </div>+ )}</div>{/* Quick Actions */}diff --git a/client/src/utils/characterXp.js b/client/src/utils/characterXp.jsindex 8502217869..ab7e89be17 100644--- a/client/src/utils/characterXp.js+++ b/client/src/utils/characterXp.js@@ -115,8 +115,10 @@ export function diffXp(prev, next) {const gained = Math.max(0, nextXp - prevXp);// Level is decoupled from XP now: a level-up burst fires only on a real age-level increase// (a birthday), never when an XP gain crosses a legacy threshold. When level is unknown- // (no birthDate on either snapshot) there is no level-up to celebrate.+ // (no birthDate on either snapshot) there is no level-up to celebrate. This is independent+ // of `gained` — a birthday almost never coincides with an XP gain, so gating it on XP would+ // mean the celebration never fires. The badge decides to burst on `gained > 0 || leveledUp`.const leveledUp = prevLevel != null && nextLevel != null && nextLevel > prevLevel;- return { gained, leveledUp: gained > 0 && leveledUp };+ return { gained, leveledUp };}diff --git a/client/src/utils/characterXp.test.js b/client/src/utils/characterXp.test.jsindex 261df7ec88..079d07528b 100644--- a/client/src/utils/characterXp.test.js+++ b/client/src/utils/characterXp.test.js@@ -179,6 +179,13 @@ describe('diffXp', () => {expect(d.leveledUp).toBe(true);});+ it('reports a birthday level-up even when XP did not change', () => {+ // A birthday almost never coincides with an XP gain — leveledUp must not depend on gained.+ const d = diffXp({ xp: 150, level: 41 }, { xp: 150, level: 42 });+ expect(d.gained).toBe(0);+ expect(d.leveledUp).toBe(true);+ });+it('does not burst on the first poll (no prior snapshot)', () => {expect(diffXp(null, { xp: 500, level: 2 })).toEqual({ gained: 0, leveledUp: false });expect(diffXp(undefined, { xp: 500 })).toEqual({ gained: 0, leveledUp: false });diff --git a/server/services/character.js b/server/services/character.jsindex a58e514532..abf922aa54 100644--- a/server/services/character.js+++ b/server/services/character.js@@ -21,20 +21,40 @@ const CHARACTER_FILE = path.join(PATHS.data, 'character.json');// damage/rest mechanics survive for backward-compat against a flat maxHp.const DEFAULT_MAX_HP = 15;-const MS_PER_YEAR = 365.25 * 24 * 60 * 60 * 1000;-// Derived fields getCharacter() attaches on read; they are stripped before persisting so a// stale age-level never lands on disk or in the federated snapshot.const DERIVED_FIELDS = ['level', 'ageYears'];-// Pure: fractional years lived since birthDate, or null when birthDate is unset/invalid.+// Pure: fractional years lived since birthDate (whole years + progress toward the next+// birthday), or null when birthDate is unset/invalid/future. Uses **calendar** birthdays,+// not a fixed 365.25-day average — averaging would tick the level up to a day early across+// leap years. UTC components are used on both sides so the tick lands on the birthday's UTC+// date regardless of the server's local timezone.export function ageYearsFromBirthDate(birthDate, now = new Date()) {if (!birthDate) return null;const birth = new Date(birthDate);- if (Number.isNaN(birth.getTime())) return null;- const years = (now.getTime() - birth.getTime()) / MS_PER_YEAR;- if (!Number.isFinite(years) || years < 0) return null;- return Math.round(years * 100) / 100;+ if (Number.isNaN(birth.getTime()) || birth.getTime() > now.getTime()) return null;++ // Completed calendar years = how many birthdays have passed.+ let years = now.getUTCFullYear() - birth.getUTCFullYear();+ const lastBirthday = new Date(birth);+ lastBirthday.setUTCFullYear(birth.getUTCFullYear() + years);+ if (lastBirthday.getTime() > now.getTime()) {+ years -= 1;+ lastBirthday.setUTCFullYear(lastBirthday.getUTCFullYear() - 1);+ }+ if (years < 0) return null;++ // Fraction of the way from the last birthday to the next (progress toward next birthday).+ const nextBirthday = new Date(lastBirthday);+ nextBirthday.setUTCFullYear(lastBirthday.getUTCFullYear() + 1);+ const span = nextBirthday.getTime() - lastBirthday.getTime();+ // frac ∈ [0, 1): now is always ≥ lastBirthday and < nextBirthday. Do NOT round the sum —+ // rounding e.g. 25.997 to 25.99→26.00 would push floor(ageYears) to the wrong level a day+ // early. levelFromAge() floors this, and display consumers round the fractional part.+ const frac = span > 0 ? Math.min(0.999999, Math.max(0, (now.getTime() - lastBirthday.getTime()) / span)) : 0;++ return years + frac;}// Pure: age-based level = whole years lived. null when age is unknown.diff --git a/server/services/character.test.js b/server/services/character.test.jsindex c0d6950c9f..223f4f215b 100644--- a/server/services/character.test.js+++ b/server/services/character.test.js@@ -52,6 +52,16 @@ describe('ageYearsFromBirthDate', () => {expect(characterService.ageYearsFromBirthDate('not-a-date', now)).toBeNull();expect(characterService.ageYearsFromBirthDate('2030-01-01', now)).toBeNull();});++ it('uses calendar birthdays — does not tick the level up a day early', () => {+ // The day BEFORE the 26th birthday: still 25 (a 365.25-day average would round to 26).+ const dayBefore = characterService.ageYearsFromBirthDate('2000-07-17', new Date('2026-07-16T00:00:00Z'));+ expect(Math.floor(dayBefore)).toBe(25);+ // On the birthday: ticks to 26 with ~0 progress.+ const onBirthday = characterService.ageYearsFromBirthDate('2000-07-17', new Date('2026-07-17T00:00:00Z'));+ expect(Math.floor(onBirthday)).toBe(26);+ expect(onBirthday - 26).toBeLessThan(0.01);+ });});describe('levelFromAge', () => {diff --git a/server/services/dataSync.js b/server/services/dataSync.jsindex c407e5fa3f..2d920b4c56 100644--- a/server/services/dataSync.js+++ b/server/services/dataSync.js@@ -272,8 +272,11 @@ async function applyCharacterRemote(remoteData) {const local = await readJSONFile(CHARACTER_FILE, null);if (!local) {- // No local character — accept remote entirely- await atomicWrite(CHARACTER_FILE, remoteData);+ // No local character — accept remote entirely, but strip a legacy persisted `level`+ // (an older peer still sends it): level is age-derived on read now (#2673), so a stored+ // value would be stale and would re-propagate in our own snapshot.+ const { level: _staleLevel, ...accepted } = remoteData;+ await atomicWrite(CHARACTER_FILE, accepted);console.log(`🔄 Character sync: accepted remote character`);return { applied: true, count: 1 };}