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): reject impossible dates, guard non-object config, warn-style city badges
[._.]/ Adam Eivy4109370507e7
diff --git a/client/src/components/city/CityHudCompact.jsx b/client/src/components/city/CityHudCompact.jsxindex 9e2e5eec97..847c7b128f 100644--- a/client/src/components/city/CityHudCompact.jsx+++ b/client/src/components/city/CityHudCompact.jsx@@ -194,7 +194,13 @@ export default function CityHudCompact({onClick={() => navigate(birthCta.path)}aria-label={`${birthCta.title} to show your level`}title={birthCta.title}- 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"+ // A present-but-unusable date (invalid/future/unreadable) renders in the warning color,+ // matching the CharacterSheet "fix" prompt and the changelog's promise (#2757).+ className={`bg-black/85 backdrop-blur-sm rounded-lg px-2.5 min-h-[44px] flex items-center font-pixel text-[11px] tracking-wider border ${+ birthCta.kind === 'fix'+ ? 'border-port-warning/50 text-port-warning'+ : 'border-cyan-500/40 text-cyan-300/70'+ }`}>{birthCta.badgeLabel}</button>diff --git a/client/src/components/city/CityXpBadge.jsx b/client/src/components/city/CityXpBadge.jsxindex 56ecc8b20e..0095171093 100644--- a/client/src/components/city/CityXpBadge.jsx+++ b/client/src/components/city/CityXpBadge.jsx@@ -57,6 +57,9 @@ export default function CityXpBadge({ character }) {const cta = view.hasBirthDate ? null : birthDateCta(view.birthDateStatus);const levelLabel = view.hasBirthDate ? `LV ${view.level}` : cta.badgeLabel;const target = view.hasBirthDate ? '/character' : cta.path;+ // A present-but-unusable date (invalid/future/unreadable) renders in the warning color, matching+ // the CharacterSheet "fix" prompt and the changelog's promise (#2757). Never true while leveling.+ const fixState = cta?.kind === 'fix';return (<div className="absolute bottom-16 right-3 pointer-events-auto">@@ -67,9 +70,11 @@ export default function CityXpBadge({ character }) {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)]'- : gaining- ? 'border-cyan-400/70 shadow-[0_0_12px_rgba(6,182,212,0.45)]'- : 'border-cyan-500/30'+ : fixState+ ? 'border-port-warning/60 shadow-[0_0_12px_rgba(245,158,11,0.35)]'+ : gaining+ ? 'border-cyan-400/70 shadow-[0_0_12px_rgba(6,182,212,0.45)]'+ : 'border-cyan-500/30'}`}>{/* Transient flash overlay keyed on burst.seq so it re-mounts each gain */}@@ -89,8 +94,8 @@ export default function CityXpBadge({ character }) {<div className="relative flex items-center justify-between gap-2"><div className="flex items-center gap-2"><span- className={`font-pixel text-base tracking-wider ${leveling ? 'text-amber-300' : 'text-cyan-300'}`}- style={{ textShadow: leveling ? '0 0 10px rgba(245,158,11,0.7)' : '0 0 8px rgba(6,182,212,0.5)' }}+ className={`font-pixel text-base tracking-wider ${leveling ? 'text-amber-300' : fixState ? 'text-port-warning' : 'text-cyan-300'}`}+ style={{ textShadow: leveling ? '0 0 10px rgba(245,158,11,0.7)' : fixState ? '0 0 8px rgba(245,158,11,0.5)' : '0 0 8px rgba(6,182,212,0.5)' }}>{levelLabel}</span>diff --git a/server/services/character.js b/server/services/character.jsindex 214b9a6cd4..0dd67cff23 100644--- a/server/services/character.js+++ b/server/services/character.js@@ -47,15 +47,32 @@ export function stripDerivedFields(record) {return out;}+// Pure: is `birthDate` a USABLE stored birth date — a real calendar day, not just a string+// `new Date` happens to parse? The canonical stored form is `YYYY-MM-DD` (birthDateInputSchema),+// but legacy/migrated data can be a full ISO timestamp, so accept a `YYYY-MM-DD` prefix+// (optionally followed by a time) and verify the day round-trips. This rejects the cases+// `new Date` silently NORMALIZES — an impossible calendar day (`2021-02-29` → Mar 1,+// `2024-02-30`) or a loose numeric like `"0"` — which would otherwise yield a bogus level+// instead of the "fix your birth date" CTA (#2757, codex review). Non-string / non-date-shaped+// input is not usable.+export function usableBirthDate(birthDate) {+ if (typeof birthDate !== 'string') return false;+ const m = birthDate.match(/^(\d{4})-(\d{2})-(\d{2})/);+ if (!m) return false;+ const y = Number(m[1]), mo = Number(m[2]), d = Number(m[3]);+ const dt = new Date(Date.UTC(y, mo - 1, d));+ return dt.getUTCFullYear() === y && dt.getUTCMonth() + 1 === mo && dt.getUTCDate() === d;+}+// 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;+ if (!usableBirthDate(birthDate)) return null;const birth = new Date(birthDate);- if (Number.isNaN(birth.getTime()) || birth.getTime() > now.getTime()) return null;+ if (birth.getTime() > now.getTime()) return null;// Completed calendar years = how many birthdays have passed.let years = now.getUTCFullYear() - birth.getUTCFullYear();@@ -91,16 +108,17 @@ export function levelFromAge(ageYears) {// the sentinel distinction (absent vs failed vs valid — see CLAUDE.md) as an explicit status:// 'unreadable' → the meatspace config could not be read/parsed (getBirthDateStrict readable:false)// 'unset' → no birthDate on record-// 'invalid' → birthDate present but not a parseable date-// 'future' → birthDate parses but is in the future+// 'invalid' → birthDate present but not a usable calendar date (unparseable, or an+// impossible/normalized day like 2021-02-29 — see usableBirthDate)+// 'future' → birthDate is a real date but in the future// 'ok' → a usable past birthDate (a real level exists)-// Mirrors ageYearsFromBirthDate's own null cases so status and level never disagree.+// Mirrors ageYearsFromBirthDate's own null cases (via the shared usableBirthDate check) so+// status and level never disagree.export function birthDateStatusFrom(birthDate, readable = true, now = new Date()) {if (!readable) return 'unreadable';if (!birthDate) return 'unset';- const birth = new Date(birthDate);- if (Number.isNaN(birth.getTime())) return 'invalid';- if (birth.getTime() > now.getTime()) return 'future';+ if (!usableBirthDate(birthDate)) return 'invalid';+ if (new Date(birthDate).getTime() > now.getTime()) return 'future';return 'ok';}diff --git a/server/services/character.test.js b/server/services/character.test.jsindex bef89a5273..62d32894a5 100644--- a/server/services/character.test.js+++ b/server/services/character.test.js@@ -110,6 +110,16 @@ describe('birthDateStatusFrom (#2757)', () => {it('reports invalid for an unparseable date', () => {expect(characterService.birthDateStatusFrom('not-a-date', true, now)).toBe('invalid');});+ it('reports invalid for an impossible/normalized calendar day (not a bogus level) (#2757 codex)', () => {+ // new Date('2021-02-29') silently rolls to Mar 1 — must be rejected, not treated as ok.+ expect(characterService.birthDateStatusFrom('2021-02-29', true, now)).toBe('invalid');+ expect(characterService.birthDateStatusFrom('2024-02-30', true, now)).toBe('invalid');+ expect(characterService.birthDateStatusFrom('0', true, now)).toBe('invalid');+ expect(characterService.birthDateStatusFrom('1990/05/15', true, now)).toBe('invalid');+ });+ it('accepts a full ISO timestamp (legacy/migrated storage), not just YYYY-MM-DD', () => {+ expect(characterService.birthDateStatusFrom('1984-01-01T00:00:00.000Z', true, now)).toBe('ok');+ });it('reports future for a date past now', () => {expect(characterService.birthDateStatusFrom('2030-01-01', true, now)).toBe('future');});diff --git a/server/services/meatspace.birthDate.test.js b/server/services/meatspace.birthDate.test.jsnew file mode 100644index 0000000000..4b4a0478e1--- /dev/null+++ b/server/services/meatspace.birthDate.test.js@@ -0,0 +1,55 @@+import { describe, it, expect, vi, beforeEach } from 'vitest';++// getBirthDateStrict (#2757) reports whether the meatspace config read was TRUSTWORTHY, so the+// character CTA can say "fix your birth date" for a corrupt/unreadable config vs "set your birth+// date" for a genuinely unset one. This suite drives the file layer through a mock so the+// readable-vs-unreadable classification is exercised without touching disk. meatspace.test.js+// deliberately inlines pure functions to avoid mocking; this file isolates the one I/O function.++const store = vi.hoisted(() => ({ ok: true, value: null }));++vi.mock('../lib/fileUtils.js', () => ({+ PATHS: { data: '/tmp/portos-test-data', meatspace: '/tmp/portos-test-data/meatspace', digitalTwin: '/tmp/portos-test-data/digital-twin' },+ atomicWrite: vi.fn(async () => {}),+ ensureDir: vi.fn(async () => {}),+ readJSONFile: vi.fn(async () => ({})),+ // The strict reader returns { ok, value } — ok:false is a corrupt/unreadable file, ok:true a+ // clean parse (whose ROOT SHAPE getBirthDateStrict must still validate).+ readJSONFileStrict: vi.fn(async () => ({ ok: store.ok, value: store.value })),+}));+vi.mock('./genome.js', () => ({ getSnpIndex: vi.fn(async () => ({})) }));+vi.mock('./mortalLoomStore.js', () => ({+ mlGetProfileIfEnabled: vi.fn(async () => null),+ mlPatchProfileIfEnabled: vi.fn(async () => {}),+}));+vi.mock('fs/promises', () => ({ readFile: vi.fn(async () => '{}') }));++const meatspace = await import('./meatspace.js');++describe('getBirthDateStrict (#2757)', () => {+ beforeEach(() => { store.ok = true; store.value = { birthDate: null }; });++ it('is readable with the date for a clean object config', async () => {+ store.value = { birthDate: '1984-01-01' };+ expect(await meatspace.getBirthDateStrict()).toEqual({ birthDate: '1984-01-01', readable: true });+ });++ it('is readable+unset for a clean object config with no birthDate', async () => {+ store.value = {};+ expect(await meatspace.getBirthDateStrict()).toEqual({ birthDate: undefined, readable: true });+ });++ it('is UNREADABLE when the strict read failed (corrupt/unparseable file)', async () => {+ store.ok = false; store.value = null;+ expect(await meatspace.getBirthDateStrict()).toEqual({ birthDate: null, readable: false });+ });++ it('is UNREADABLE for a parseable-but-non-object root (array / string / number) — codex review', async () => {+ for (const bad of [[], 'corrupt', 42, null]) {+ store.ok = true; store.value = bad;+ // A non-object root is a corrupt config, not a trustworthy "unset" — must read as unreadable+ // so the CTA prompts "fix", never the friendly "set".+ expect(await meatspace.getBirthDateStrict()).toEqual({ birthDate: null, readable: false });+ }+ });+});diff --git a/server/services/meatspace.js b/server/services/meatspace.jsindex 694407ea79..a33df23981 100644--- a/server/services/meatspace.js+++ b/server/services/meatspace.js@@ -8,6 +8,7 @@import { readFile } from 'fs/promises';import { join } from 'path';import { atomicWrite, PATHS, ensureDir, readJSONFile, readJSONFileStrict } from '../lib/fileUtils.js';+import { isPlainObject } from '../lib/objects.js';import { getSnpIndex } from './genome.js';import { mlGetProfileIfEnabled, mlPatchProfileIfEnabled } from './mortalLoomStore.js';@@ -288,7 +289,10 @@ export async function getBirthDate() {// (never-written) config is a trustworthy empty and stays `readable: true`.export async function getBirthDateStrict() {const { ok, value: config } = await readJSONFileStrict(CONFIG_FILE, structuredClone(DEFAULT_CONFIG));- if (!ok) return { birthDate: null, readable: false };+ // `ok` only means the JSON parsed — a parseable-but-non-object root (`[]`, `"corrupt"`, a+ // bare number) is still a corrupt config, not a trustworthy "unset". Treat it as unreadable+ // so the CTA prompts "fix" rather than the friendly "set" (#2757, codex review).+ if (!ok || !isPlainObject(config)) return { birthDate: null, readable: false };const migrated = await migrateBirthDateFromGoals(config);return { birthDate: migrated.birthDate, readable: true };}