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
fix(issue-2757): distinguish unset birth date from invalid/unreadable in level CTA
[._.]/ Adam Eivyf858528c5958
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex c9c2724f97..5abc15ea48 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -2,6 +2,8 @@## Added+- [issue-2757] **The "set your birth date" prompt now tells you when your date is broken rather than just missing.** When your Character sheet or the CyberCity level badges can't show a level, they used to always say "set your birth date" — even if you'd already entered one that turned out to be invalid, dated in the future, or stored in a config file that couldn't be read. Now those cases show a distinct "fix your birth date" prompt (with a warning color) so you're not told to set a date you already entered, while a genuinely unset date still gets the original friendly "set" prompt. Every prompt still deep-links to the age editor where the field lives. The distinction is carried as an explicit, per-machine-derived status that's never persisted or synced between machines.+- [issue-2674] **Your Character sheet now has skills that reflect how you actually use PortOS.** Six skills — Wordsmith (universes, Writers Room works, and catalog records), Mentalist (POST), Vitalist (health logging), Strategist (goal discipline), Archivist (Brain/memory), and Auteur (media) — level up from the work you've already done, on a curve where each doubling of use earns a level, so they climb quickly at first and then ask for real commitment. Nothing new is tracked to make this work: each skill reads the stats its domain already keeps, so the skills are accurate from the moment you upgrade rather than starting everyone at zero. A domain you've never touched is honestly level 0, and a domain whose stats can't be read says "Unavailable" rather than pretending it's zero. Skills are computed fresh on every read and never saved or synced between your machines — usage differs per machine, so syncing them would let the laptop you barely open overwrite the desktop you live in.- [issue-2675] **Your Character sheet now shows the goals you're actually working toward.** A new Life Goals card sits under your metrics and lists your four most urgent active goals with their progress, each linking straight through to Goals. It's a read-only mirror of the goals you already keep — nothing is stored or duplicated on the Character surface, so there's still exactly one place your goals live and one place to change them. Goals are ranked by the same urgency the Goals page uses; if you haven't set a birth date there's no horizon to rank against, so your goals are listed as-is rather than given a made-up order. Completed and abandoned goals drop off, and if you have no active goals the card invites you to set some instead of rendering an empty block. A card that can't reach your goals says so plainly rather than claiming you have none.diff --git a/client/src/components/city/CityHudCompact.jsx b/client/src/components/city/CityHudCompact.jsxindex db0b945667..9e2e5eec97 100644--- a/client/src/components/city/CityHudCompact.jsx+++ b/client/src/components/city/CityHudCompact.jsx@@ -8,6 +8,7 @@ import CityMiniMap from './CityMiniMap';import CityFilterBar from './CityFilterBar';import CityFocusPanel from './CityFocusPanel';import { CITY_PANE_IDS, CITY_INTEL_PANE_IDS, CITY_PANE_LABELS } from './cityPanes';+import { birthDateCta } from '../../utils/characterXp';// A 44×44 dock control. `active`/`aria-pressed` mark a toggled disclosure launcher;// omit `active` for one-shot actions (photo, history) that just fire a callback.@@ -101,6 +102,10 @@ export default function CityHudCompact({);const criticalCount = items.filter(i => i.severity === 'critical').length;const hasApps = (apps || []).length > 0;+ // No usable level → the birth-date CTA distinguishes a genuinely unset date ("set") from a+ // present-but-unusable one ("fix" — invalid/future/unreadable) so we don't tell the user to+ // set a date they already entered (#2757). Null when a real level exists.+ const birthCta = character && character.level == null ? birthDateCta(character.birthDateStatus) : null;const onSettings = location.pathname === '/city/settings';const goSettings = () => navigate(onSettings ? `/city${location.search}` : `/city/settings${location.search}`);@@ -180,17 +185,18 @@ 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.+ ) : birthCta ? (+ // Character loaded but no usable level (age-based, #2673). Prompt the user to set the+ // birth date — or FIX it when present-but-unusable (#2757) — routing to the age editor+ // where the field lives.<buttontype="button"- onClick={() => navigate('/meatspace/age')}- aria-label="Set your birth date to show your level"- title="Set your birth date"+ 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">- LV —+ {birthCta.badgeLabel}</button>) : null}</div>diff --git a/client/src/components/city/CityHudCompact.test.jsx b/client/src/components/city/CityHudCompact.test.jsxindex 847d2313ac..8d7cced3a1 100644--- a/client/src/components/city/CityHudCompact.test.jsx+++ b/client/src/components/city/CityHudCompact.test.jsx@@ -108,4 +108,33 @@ describe('CityHudCompact', () => {expect(screen.queryByText('ATTENTION')).not.toBeInTheDocument();expect(screen.getByTestId('loc').textContent).toBe('');});++ describe('birth-date level CTA (#2757)', () => {+ it('shows a SET prompt (LV —) for a genuinely unset birth date', () => {+ renderCompact('', { character: { level: null, birthDateStatus: 'unset' } });+ expect(screen.getByRole('button', { name: /set your birth date/i })).toBeInTheDocument();+ expect(screen.getByText('LV —')).toBeInTheDocument();+ });++ it('shows a FIX prompt (LV !) for a present-but-invalid birth date', () => {+ renderCompact('', { character: { level: null, birthDateStatus: 'invalid' } });+ const btn = screen.getByRole('button', { name: /fix your birth date/i });+ expect(btn).toBeInTheDocument();+ expect(screen.getByText('LV !')).toBeInTheDocument();+ expect(screen.queryByText('LV —')).not.toBeInTheDocument();+ });++ it('shows a FIX prompt for an unreadable config, not a set prompt', () => {+ renderCompact('', { character: { level: null, birthDateStatus: 'unreadable' } });+ expect(screen.getByRole('button', { name: /fix your birth date/i })).toBeInTheDocument();+ expect(screen.queryByRole('button', { name: /set your birth date/i })).not.toBeInTheDocument();+ });++ it('shows the numeric level (no CTA) when a level exists', () => {+ renderCompact('', { character: { level: 7, birthDateStatus: 'ok' } });+ expect(screen.getByText('LV 7')).toBeInTheDocument();+ expect(screen.queryByText('LV —')).not.toBeInTheDocument();+ expect(screen.queryByText('LV !')).not.toBeInTheDocument();+ });+ });});diff --git a/client/src/components/city/CityXpBadge.jsx b/client/src/components/city/CityXpBadge.jsxindex 2f76ad8f0d..56ecc8b20e 100644--- a/client/src/components/city/CityXpBadge.jsx+++ b/client/src/components/city/CityXpBadge.jsx@@ -1,6 +1,6 @@import { useState, useEffect, useRef, useMemo } from 'react';import { useNavigate } from 'react-router-dom';-import { computeAgeView, diffXp } from '../../utils/characterXp';+import { computeAgeView, diffXp, birthDateCta } from '../../utils/characterXp';// CyberCity character HUD badge (roadmap 2.11; reframed in #2673). A compact floating panel// showing the current **age-based level** (life experience = age) and a progress bar =@@ -50,17 +50,20 @@ 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, 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';+ // No usable level → show a prompt instead of NaN and send the click to the age editor (where+ // the birth-date field lives). The CTA distinguishes a genuinely unset date ("set") from a+ // present-but-unusable one ("fix" — invalid/future/unreadable), so we never tell the user to+ // set a date they already entered (#2757).+ const cta = view.hasBirthDate ? null : birthDateCta(view.birthDateStatus);+ const levelLabel = view.hasBirthDate ? `LV ${view.level}` : cta.badgeLabel;+ const target = view.hasBirthDate ? '/character' : cta.path;return (<div className="absolute bottom-16 right-3 pointer-events-auto"><buttontype="button"onClick={() => navigate(target)}- title={view.hasBirthDate ? 'Open character sheet' : 'Set your birth date'}+ title={view.hasBirthDate ? 'Open character sheet' : cta.title}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)]'@@ -116,7 +119,7 @@ export default function CityXpBadge({ character }) {<div className="relative flex items-center justify-between mt-1"><span className="font-pixel text-[8px] text-gray-500 tracking-wider">- {view.hasBirthDate ? `${pct}% TO NEXT` : 'SET BIRTH DATE'}+ {view.hasBirthDate ? `${pct}% TO NEXT` : cta.badgeCaption}</span>{view.hp != null && view.maxHp != null && (<spandiff --git a/client/src/pages/CharacterSheet.jsx b/client/src/pages/CharacterSheet.jsxindex 2d5b8c3b0a..7f096e8530 100644--- a/client/src/pages/CharacterSheet.jsx+++ b/client/src/pages/CharacterSheet.jsx@@ -1,9 +1,10 @@import { useState, useEffect, useCallback, useRef } from 'react';import { useNavigate } from 'react-router-dom';import {- Sword, Star, Moon, ScrollText, Heart, UserRound, Cake,+ Sword, Star, Moon, ScrollText, Heart, UserRound, Cake, AlertTriangle,Sparkles, RefreshCw, Dices, X, ChevronDown, Zap, Image, Activity} from 'lucide-react';+import { birthDateCta } from '../utils/characterXp';import BrailleSpinner from '../components/BrailleSpinner';import GoalsCard from '../components/character/GoalsCard';import toast from '../components/ui/Toast';@@ -408,6 +409,11 @@ export default function CharacterSheet() {? Math.round((char.ageYears - Math.floor(char.ageYears)) * 100): 0;+ // No usable level → CTA distinguishes a genuinely unset birth date ("set") from a+ // present-but-unusable one ("fix" — invalid/future/unreadable) so the user isn't told to set+ // a date they already entered (#2757). Null when a real level exists (no CTA rendered).+ const birthCta = char.level == null ? birthDateCta(char.birthDateStatus) : null;+return (<div className="h-full flex flex-col overflow-hidden">{/* Header */}@@ -539,21 +545,27 @@ export default function CharacterSheet() {)}</div>- {/* Birth-date prompt — the human-centered level is age (#2673). Until a birth date- is on record there is no level to show, so surface a clear call to set it,- deep-linking to the age editor where the field lives. */}- {char.level == null && (+ {/* Birth-date prompt — the human-centered level is age (#2673). Until a USABLE birth+ date is on record there is no level to show, so surface a clear call to action,+ deep-linking to the age editor where the field lives. A present-but-unusable date+ (invalid/future/unreadable, #2757) shows a "fix" prompt instead of "set" so the+ user isn't told to set a date they already entered. */}+ {birthCta && (<buttontype="button"- onClick={() => navigate('/meatspace/age')}- className="mt-4 w-full flex items-center gap-3 px-4 py-3 rounded-lg border border-dashed border-port-accent/50 bg-port-accent/5 hover:bg-port-accent/10 text-left transition-colors"+ onClick={() => navigate(birthCta.path)}+ className={`mt-4 w-full flex items-center gap-3 px-4 py-3 rounded-lg border border-dashed text-left transition-colors ${+ birthCta.kind === 'fix'+ ? 'border-port-warning/50 bg-port-warning/5 hover:bg-port-warning/10'+ : 'border-port-accent/50 bg-port-accent/5 hover:bg-port-accent/10'+ }`}>- <Cake className="w-5 h-5 text-port-accent flex-shrink-0" />+ {birthCta.kind === 'fix'+ ? <AlertTriangle className="w-5 h-5 text-port-warning flex-shrink-0" />+ : <Cake className="w-5 h-5 text-port-accent flex-shrink-0" />}<div className="min-w-0">- <div className="text-sm font-medium text-white">Set your birth date</div>- <div className="text-xs text-gray-400">- Your level is your life experience — each year lived is a level. Add your birth date to see it.- </div>+ <div className="text-sm font-medium text-white">{birthCta.heading}</div>+ <div className="text-xs text-gray-400">{birthCta.caption}</div></div></button>)}diff --git a/client/src/utils/characterXp.js b/client/src/utils/characterXp.jsindex ab7e89be17..89edd8b665 100644--- a/client/src/utils/characterXp.js+++ b/client/src/utils/characterXp.js@@ -75,6 +75,10 @@ export function computeAgeView(character) {? Math.floor(character.level): (ageYears != null ? Math.floor(ageYears) : null);const hasBirthDate = level != null;+ // Server-derived classification of WHY there's no level (#2757). Absent on an older server+ // bundle → treat as 'unset' (the historical behavior). Carried through so the badge can show+ // a "fix" prompt for a present-but-unusable date instead of a "set" prompt.+ const birthDateStatus = character?.birthDateStatus ?? (hasBirthDate ? 'ok' : 'unset');// Fraction through the current year of life = progress toward the next birthday.const progress = (hasBirthDate && ageYears != null)@@ -87,6 +91,7 @@ export function computeAgeView(character) {level,ageYears,hasBirthDate,+ birthDateStatus,progress,// Rough countdown to next birthday for the badge caption; null when age is unknown.daysToNextBirthday: hasBirthDate ? Math.max(0, Math.ceil((1 - progress) * 365.25)) : null,@@ -122,3 +127,42 @@ export function diffXp(prev, next) {return { gained, leveledUp };}++// Map a server-derived `birthDateStatus` (#2757) to the call-to-action the level surfaces render+// when there is no usable level. The CTA distinguishes a genuinely UNSET birth date ("set")+// from one that is present-but-unusable — invalid, in the future, or an unreadable config ("fix")+// — so a user is never told to *set* a date they already entered. Every case deep-links to the+// age editor (`/meatspace/age`) where the field lives. Returns `null` for 'ok' (a real level+// exists; no CTA). Tolerates an absent/unknown status by treating it as 'unset'.+export function birthDateCta(status) {+ const fix = (caption) => ({+ kind: 'fix',+ path: '/meatspace/age',+ title: 'Fix your birth date',+ heading: 'Fix your birth date',+ caption,+ badgeLabel: 'LV !',+ badgeCaption: 'FIX BIRTH DATE',+ });+ switch (status) {+ case 'ok':+ return null;+ case 'unreadable':+ return fix("Your birth date couldn't be read. Re-enter it to restore your level.");+ case 'future':+ return fix('Your birth date is in the future. Update it to see your level.');+ case 'invalid':+ return fix('Your birth date looks invalid. Update it to see your level.');+ case 'unset':+ default:+ return {+ kind: 'set',+ path: '/meatspace/age',+ title: 'Set your birth date',+ heading: 'Set your birth date',+ caption: 'Your level is your life experience — each year lived is a level. Add your birth date to see it.',+ badgeLabel: 'LV —',+ badgeCaption: 'SET BIRTH DATE',+ };+ }+}diff --git a/client/src/utils/characterXp.test.js b/client/src/utils/characterXp.test.jsindex 079d07528b..7a37921494 100644--- a/client/src/utils/characterXp.test.js+++ b/client/src/utils/characterXp.test.js@@ -6,6 +6,7 @@ import {computeXpView,computeAgeView,diffXp,+ birthDateCta,} from './characterXp';describe('levelFromXP', () => {@@ -144,6 +145,52 @@ describe('computeAgeView', () => {expect(vm.daysToNextBirthday).toBeGreaterThan(360);expect(vm.daysToNextBirthday).toBeLessThanOrEqual(366);});++ it('surfaces the server birthDateStatus (#2757)', () => {+ expect(computeAgeView({ level: null, ageYears: null, birthDateStatus: 'invalid' }).birthDateStatus).toBe('invalid');+ expect(computeAgeView({ level: 40, ageYears: 40, birthDateStatus: 'ok' }).birthDateStatus).toBe('ok');+ });++ it('defaults birthDateStatus for an older server bundle that omits it', () => {+ // No level → assume unset (the historical CTA); a real level → ok.+ expect(computeAgeView({ level: null, ageYears: null }).birthDateStatus).toBe('unset');+ expect(computeAgeView({ level: 33, ageYears: 33.2 }).birthDateStatus).toBe('ok');+ });+});++describe('birthDateCta (#2757)', () => {+ it('returns null for a usable date (ok) — no CTA', () => {+ expect(birthDateCta('ok')).toBeNull();+ });++ it('prompts to SET only for a genuinely unset date', () => {+ const cta = birthDateCta('unset');+ expect(cta.kind).toBe('set');+ expect(cta.title).toBe('Set your birth date');+ expect(cta.badgeLabel).toBe('LV —');+ expect(cta.path).toBe('/meatspace/age');+ });++ it('prompts to FIX for a present-but-unusable date, distinct from set', () => {+ for (const status of ['invalid', 'future', 'unreadable']) {+ const cta = birthDateCta(status);+ expect(cta.kind).toBe('fix');+ expect(cta.title).toBe('Fix your birth date');+ expect(cta.badgeLabel).toBe('LV !');+ expect(cta.path).toBe('/meatspace/age');+ }+ });++ it('gives the unreadable case its own copy', () => {+ expect(birthDateCta('unreadable').caption).toMatch(/couldn't be read/i);+ expect(birthDateCta('future').caption).toMatch(/future/i);+ expect(birthDateCta('invalid').caption).toMatch(/invalid/i);+ });++ it('treats an unknown/absent status as unset (backward compatible)', () => {+ expect(birthDateCta(undefined).kind).toBe('set');+ expect(birthDateCta('mystery').kind).toBe('set');+ });});describe('diffXp', () => {diff --git a/server/services/character.js b/server/services/character.jsindex 1b5dc4d187..214b9a6cd4 100644--- a/server/services/character.js+++ b/server/services/character.js@@ -18,7 +18,7 @@ import path from 'path';import { atomicWrite, ensureDir, readJSONFile, PATHS } from '../lib/fileUtils.js';import * as jiraService from './jira.js';import * as cosService from './cos.js';-import { getBirthDate } from './meatspace.js';+import { getBirthDateStrict } from './meatspace.js';import { getCharacterSkills } from './characterSkills.js';import { getCharacterMetrics } from './characterMetrics.js';import { createSignalContext } from './characterSignals.js';@@ -33,7 +33,7 @@ const DEFAULT_MAX_HP = 15;// stale age-level (or a per-machine usage-derived skill set) never lands on disk or in the// federated snapshot. `skills` (#2674) and `metrics` (#2676) are per-machine by design — see// characterSkills.js / characterMetrics.js.-const DERIVED_FIELDS = ['level', 'ageYears', 'skills', 'metrics'];+const DERIVED_FIELDS = ['level', 'ageYears', 'skills', 'metrics', 'birthDateStatus'];/*** Copy `record` without any derived field. The single chokepoint for that rule — used by the@@ -84,6 +84,26 @@ export function levelFromAge(ageYears) {return Number.isFinite(ageYears) ? Math.floor(ageYears) : null;}+// Pure: classify the birth-date state so the "no level" CTA can distinguish a genuinely+// unset date from one that is present-but-unusable (#2757). `levelFromAge(ageYears)` collapses+// all of unset/invalid/future/unreadable into `null`, which the client used to treat uniformly+// as "set your birth date" — telling a user to *set* a date they already entered. This restores+// 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+// 'ok' → a usable past birthDate (a real level exists)+// Mirrors ageYearsFromBirthDate's own null cases 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';+ return 'ok';+}+// Legacy pre-#2673 XP→level curve, retained ONLY for the federation wire projection// (getWireCharacter) so an older peer — which still levels off XP — receives a level// consistent with the shared `xp`. NOT used for the live age-based level.@@ -163,13 +183,17 @@ async function loadRawCharacter() {// empty".async function enrichCharacter(raw, { withSkills = true, withMetrics = true } = {}) {const read = withSkills || withMetrics ? createSignalContext() : null;- const [{ birthDate }, skills, metrics] = await Promise.all([- getBirthDate().catch(() => ({ birthDate: null })),+ const [{ birthDate, readable }, skills, metrics] = await Promise.all([+ // A thrown read (rather than a corrupt-but-parsed one) is also unreadable, not unset.+ getBirthDateStrict().catch(() => ({ birthDate: null, readable: false })),withSkills ? getCharacterSkills(read) : Promise.resolve(undefined),withMetrics ? getCharacterMetrics(read) : Promise.resolve(undefined),]);const ageYears = ageYearsFromBirthDate(birthDate);- const enriched = { ...raw, ageYears, level: levelFromAge(ageYears) };+ // birthDateStatus (#2757) lets the CTA branch "set" (unset) vs "fix" (invalid/future/unreadable)+ // instead of conflating every null-level case. Derived + stripped like the other DERIVED_FIELDS.+ const birthDateStatus = birthDateStatusFrom(birthDate, readable);+ const enriched = { ...raw, ageYears, level: levelFromAge(ageYears), birthDateStatus };// Drop any stale persisted key when a registry wasn't computed, so a hand-edited// character.json can't pass its own `skills`/`metrics` off as freshly derived.if (withSkills) enriched.skills = skills;diff --git a/server/services/character.test.js b/server/services/character.test.jsindex 22a2633e0e..bef89a5273 100644--- a/server/services/character.test.js+++ b/server/services/character.test.js@@ -1,9 +1,9 @@-import { describe, it, expect, vi, beforeEach } from 'vitest';+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';// In-memory backing for the character.json read/write so the test exercises the// real read-modify-save path without touching disk. `birthDate` drives the mocked// meatspace accessor so age-based level derivation is deterministic.-const store = vi.hoisted(() => ({ value: null, birthDate: null }));+const store = vi.hoisted(() => ({ value: null, birthDate: null, readable: true }));vi.mock('../lib/fileUtils.js', () => ({PATHS: { data: '/tmp/portos-test-data' },@@ -45,6 +45,10 @@ vi.mock('./characterSignals.js', () => ({}));vi.mock('./meatspace.js', () => ({getBirthDate: vi.fn(async () => ({ birthDate: store.birthDate })),+ // getBirthDateStrict adds the read-trustworthiness flag the birthDateStatus derivation+ // needs (#2757). `store.readable` defaults true so existing tests are unaffected; the+ // unreadable-config case flips it to false.+ getBirthDateStrict: vi.fn(async () => ({ birthDate: store.birthDate, readable: store.readable ?? true })),}));vi.mock('fs/promises', () => ({@@ -93,6 +97,78 @@ describe('levelFromAge', () => {});});+describe('birthDateStatusFrom (#2757)', () => {+ const now = new Date('2026-07-01T00:00:00Z');+ it('reports unreadable when the config read is untrustworthy, even with a would-be-valid date', () => {+ expect(characterService.birthDateStatusFrom('1984-01-01', false, now)).toBe('unreadable');+ expect(characterService.birthDateStatusFrom(null, false, now)).toBe('unreadable');+ });+ it('reports unset for an absent date on a readable config', () => {+ expect(characterService.birthDateStatusFrom(null, true, now)).toBe('unset');+ expect(characterService.birthDateStatusFrom('', true, now)).toBe('unset');+ });+ it('reports invalid for an unparseable date', () => {+ expect(characterService.birthDateStatusFrom('not-a-date', true, now)).toBe('invalid');+ });+ it('reports future for a date past now', () => {+ expect(characterService.birthDateStatusFrom('2030-01-01', true, now)).toBe('future');+ });+ it('reports ok for a usable past date', () => {+ expect(characterService.birthDateStatusFrom('1984-01-01', true, now)).toBe('ok');+ });+});++describe('getCharacter birthDateStatus (#2757)', () => {+ beforeEach(() => {+ store.value = { name: 'Gandalf', class: 'Wizard', xp: 0, hp: 15, maxHp: 15, events: [] };+ store.birthDate = null;+ store.readable = true;+ });+ afterEach(() => { store.readable = true; });++ it('is "unset" with a null level when no birthDate is on record', async () => {+ const char = await characterService.getCharacter();+ expect(char.level).toBeNull();+ expect(char.birthDateStatus).toBe('unset');+ });++ it('is "invalid" for a present-but-unparseable birthDate (still null level)', async () => {+ store.birthDate = 'not-a-date';+ const char = await characterService.getCharacter();+ expect(char.level).toBeNull();+ expect(char.birthDateStatus).toBe('invalid');+ });++ it('is "unreadable" when the meatspace config read fails, distinct from unset', async () => {+ store.readable = false;+ const char = await characterService.getCharacter();+ expect(char.level).toBeNull();+ expect(char.birthDateStatus).toBe('unreadable');+ });++ it('is "ok" for a usable past birthDate', async () => {+ const birth = new Date();+ birth.setFullYear(birth.getFullYear() - 40);+ birth.setDate(birth.getDate() - 30);+ store.birthDate = birth.toISOString();+ const char = await characterService.getCharacter();+ expect(char.level).toBe(40);+ expect(char.birthDateStatus).toBe('ok');+ });++ it('never persists birthDateStatus to character.json', async () => {+ const char = await characterService.getCharacter();+ await characterService.saveCharacter(char);+ expect(store.value.birthDateStatus).toBeUndefined();+ });++ it('is stripped from the federation wire payload', async () => {+ store.value = { ...store.value, birthDateStatus: 'ok' };+ const wire = await characterService.getWireCharacter();+ expect(wire.birthDateStatus).toBeUndefined();+ });+});+describe('getCharacter age-based level', () => {beforeEach(() => {store.value = { name: 'Gandalf', class: 'Wizard', xp: 5000, level: 3, hp: 15, maxHp: 15 };diff --git a/server/services/meatspace.js b/server/services/meatspace.jsindex 8982fc0824..694407ea79 100644--- a/server/services/meatspace.js+++ b/server/services/meatspace.js@@ -7,7 +7,7 @@import { readFile } from 'fs/promises';import { join } from 'path';-import { atomicWrite, PATHS, ensureDir, readJSONFile } from '../lib/fileUtils.js';+import { atomicWrite, PATHS, ensureDir, readJSONFile, readJSONFileStrict } from '../lib/fileUtils.js';import { getSnpIndex } from './genome.js';import { mlGetProfileIfEnabled, mlPatchProfileIfEnabled } from './mortalLoomStore.js';@@ -280,6 +280,19 @@ export async function getBirthDate() {return { birthDate: migrated.birthDate };}+// Like getBirthDate, but reports whether the config read was TRUSTWORTHY (see+// readJSONFileStrict / CLAUDE.md's "Sentinel + validate" rule). A corrupt/unreadable+// config.json yields `{ birthDate: null, readable: false }` — distinct from a genuinely+// unset date (`readable: true`) — so consumers (the character enrichment, #2757) can tell a+// user "your birth date is unreadable, fix it" instead of "set your birth date". An ENOENT+// (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 };+ const migrated = await migrateBirthDateFromGoals(config);+ return { birthDate: migrated.birthDate, readable: true };+}+export async function updateBirthDate(birthDate, { syncGoals = true } = {}) {const config = await loadConfig();config.birthDate = birthDate;