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

address review (codex): move legacy-default handling to the data layer

[._.]/ Adam Eivyb27d9de9144f
diff --git a/client/src/pages/CharacterSheet.framing.test.jsx b/client/src/pages/CharacterSheet.framing.test.jsx
index caac995b2b..bfcc26f360 100644
--- a/client/src/pages/CharacterSheet.framing.test.jsx
+++ b/client/src/pages/CharacterSheet.framing.test.jsx
@@ -80,20 +80,13 @@ describe('human-centered framing', () => {
});
it('falls back to human-centered placeholders for an unnamed person', async () => {
+ // The server seeds an empty name/class on a fresh install (createDefaultCharacter), and
+ // migration 198 clears the legacy 'Adventurer'/'Developer' defaults on existing installs —
+ // so the page only ever sees an empty value for "unset" and renders the placeholder.
await renderChar({ name: '', class: '' });
expect(screen.getByText('Your name')).toBeInTheDocument();
expect(screen.getByText('Add a title')).toBeInTheDocument();
});
-
- it('treats the legacy RPG defaults (fresh install) as unset, showing the human placeholder', async () => {
- // createDefaultCharacter() ships name:'Adventurer', class:'Developer'; a fresh install must
- // not present that generic adventurer (epic #2672).
- await renderChar({ name: 'Adventurer', class: 'Developer' });
- expect(screen.getByText('Your name')).toBeInTheDocument();
- expect(screen.getByText('Add a title')).toBeInTheDocument();
- expect(screen.queryByText('Adventurer')).not.toBeInTheDocument();
- expect(screen.queryByText('Developer')).not.toBeInTheDocument();
- });
});
describe('birth-date prompt', () => {
diff --git a/client/src/pages/CharacterSheet.jsx b/client/src/pages/CharacterSheet.jsx
index c2a0af0955..140731af15 100644
--- a/client/src/pages/CharacterSheet.jsx
+++ b/client/src/pages/CharacterSheet.jsx
@@ -44,16 +44,6 @@ function hpColor(pct) {
return 'bg-port-error';
}
-// createDefaultCharacter() seeds these generic RPG defaults on a fresh install, so the raw
-// record's name/class are 'Adventurer'/'Developer' until the human edits them — which would
-// make the human-centered page still present a generic adventurer (the exact thing epic #2672
-// moves away from). Treat those legacy defaults as "unset" for display + edit-seeding so the
-// human placeholder shows instead. Display-only: the persisted record is untouched (no data /
-// federation change), and a user who genuinely wants either word can just type it back in.
-const LEGACY_DEFAULT_NAME = 'Adventurer';
-const LEGACY_DEFAULT_CLASS = 'Developer';
-const humanValue = (value, legacyDefault) => (value && value !== legacyDefault ? value : '');
-
// Per-domain skills derived on read from each domain's existing stats (#2674). Deliberately
// a plain read-only card: Slice 5 (#2677) owns the page's framing/redesign, so this stays
// easy to restyle or relocate wholesale.
@@ -203,8 +193,8 @@ export default function CharacterSheet() {
return;
}
setChar(data);
- setNameVal(humanValue(data.name, LEGACY_DEFAULT_NAME));
- setClassVal(humanValue(data.class, LEGACY_DEFAULT_CLASS));
+ setNameVal(data.name || '');
+ setClassVal(data.class || '');
} catch (err) {
setLoadError(err.message || 'Failed to load character data');
} finally {
@@ -315,7 +305,7 @@ export default function CharacterSheet() {
// could persist that stale value over the pending save (#2409).
if (nameSaving) return;
nameEditingRef.current = true;
- setNameVal(humanValue(char.name, LEGACY_DEFAULT_NAME));
+ setNameVal(char.name || '');
setEditingName(true);
};
@@ -326,7 +316,7 @@ export default function CharacterSheet() {
nameEditingRef.current = false;
setEditingName(false);
if (cancel) {
- setNameVal(humanValue(char.name, LEGACY_DEFAULT_NAME));
+ setNameVal(char.name || '');
return;
}
if (!(nameVal.trim() && nameVal.trim() !== char.name)) return;
@@ -410,10 +400,6 @@ export default function CharacterSheet() {
const birthdayPct = Number.isFinite(char.ageYears)
? Math.round((char.ageYears - Math.floor(char.ageYears)) * 100)
: 0;
- // Legacy RPG defaults ('Adventurer'/'Developer') read as unset, so a fresh install shows the
- // human placeholder rather than a generic adventurer (see humanValue above).
- const displayName = humanValue(char.name, LEGACY_DEFAULT_NAME);
- const displayClass = humanValue(char.class, LEGACY_DEFAULT_CLASS);
return (
<div className="h-full flex flex-col overflow-hidden">
@@ -501,10 +487,10 @@ export default function CharacterSheet() {
type="button"
onClick={startNameEdit}
disabled={nameSaving}
- aria-label={`Edit your name (currently ${displayName || 'Your name'})`}
+ aria-label={`Edit your name (currently ${char.name || 'Your name'})`}
className="text-2xl font-bold text-white cursor-pointer hover:text-port-accent transition-colors truncate text-left bg-transparent border-0 p-0 disabled:opacity-60 disabled:cursor-wait"
>
- {displayName || 'Your name'}
+ {char.name || 'Your name'}
</button>
)}
</div>
@@ -525,7 +511,7 @@ export default function CharacterSheet() {
className="text-sm text-gray-400 cursor-pointer hover:text-port-accent transition-colors"
title="Click to edit your title"
>
- {displayClass || 'Add a title'}
+ {char.class || 'Add a title'}
</span>
)}
</div>
diff --git a/scripts/migrations/198-character-clear-legacy-rpg-defaults.js b/scripts/migrations/198-character-clear-legacy-rpg-defaults.js
new file mode 100644
index 0000000000..f8cdff7f5f
--- /dev/null
+++ b/scripts/migrations/198-character-clear-legacy-rpg-defaults.js
@@ -0,0 +1,77 @@
+/**
+ * Clear the legacy generic RPG identity from an existing character.json.
+ *
+ * Background:
+ * The Character page used to seed `createDefaultCharacter()` with
+ * `name: 'Adventurer'`, `class: 'Developer'` — a generic D&D adventurer. The
+ * human-centered reframe (#2677, epic #2672) changes the seed to empty strings
+ * so a fresh install renders the "Your name" / "Add a title" placeholders and
+ * never presents a generic adventurer.
+ *
+ * That seed change is prospective only: an install created before #2677 still
+ * has `name: 'Adventurer'` / `class: 'Developer'` persisted, so it would keep
+ * showing the old identity forever. This migration converges those installs on
+ * the new behavior by clearing the fields to '' — but ONLY when they exactly
+ * match the old shipped defaults, so a user who deliberately typed either word
+ * (or has already personalized their name/title) is left untouched.
+ *
+ * Approach:
+ * - Per-field, exact-match only: `name === 'Adventurer'` → '' and
+ * `class === 'Developer'` → '' independently. Any other value is a
+ * deliberate choice and is preserved.
+ * - Rewrites the file only when something actually changed — a no-op by
+ * construction on the common case (already personalized, or already blank),
+ * and on a fresh post-#2677 install (blank seed) there is nothing to match.
+ * - Preserves every other field and stamps `updatedAt` when it does change.
+ */
+
+import { readFile, writeFile } from 'fs/promises';
+import { join } from 'path';
+
+const CHARACTER_REL = 'data/character.json';
+
+const LEGACY_DEFAULT_NAME = 'Adventurer';
+const LEGACY_DEFAULT_CLASS = 'Developer';
+
+export default {
+ async up({ rootDir }) {
+ const path = join(rootDir, CHARACTER_REL);
+ const raw = await readFile(path, 'utf-8').catch((err) => {
+ if (err.code === 'ENOENT') return null;
+ throw err;
+ });
+ if (raw == null) {
+ console.log('✅ Character: no character.json — nothing to clear');
+ return { cleared: false, reason: 'no-file' };
+ }
+
+ let character;
+ try {
+ character = JSON.parse(raw);
+ } catch {
+ // A corrupt character.json is not this migration's problem to fix, and
+ // rewriting it would risk destroying recoverable data.
+ console.warn('⚠️ Character: character.json is not valid JSON — skipping');
+ return { cleared: false, reason: 'unparseable' };
+ }
+ if (character == null || typeof character !== 'object' || Array.isArray(character)) {
+ console.warn('⚠️ Character: character.json is not an object — skipping');
+ return { cleared: false, reason: 'unexpected-shape' };
+ }
+
+ const next = { ...character };
+ let changed = false;
+ if (next.name === LEGACY_DEFAULT_NAME) { next.name = ''; changed = true; }
+ if (next.class === LEGACY_DEFAULT_CLASS) { next.class = ''; changed = true; }
+
+ if (!changed) {
+ console.log('✅ Character: no legacy RPG defaults to clear — no changes');
+ return { cleared: false };
+ }
+
+ next.updatedAt = new Date().toISOString();
+ await writeFile(path, JSON.stringify(next, null, 2) + '\n');
+ console.log('🧹 Character: cleared legacy "Adventurer" / "Developer" defaults');
+ return { cleared: true };
+ },
+};
diff --git a/scripts/migrations/198-character-clear-legacy-rpg-defaults.test.js b/scripts/migrations/198-character-clear-legacy-rpg-defaults.test.js
new file mode 100644
index 0000000000..42e8841c57
--- /dev/null
+++ b/scripts/migrations/198-character-clear-legacy-rpg-defaults.test.js
@@ -0,0 +1,97 @@
+import { describe, it, expect, beforeEach, afterEach } from 'vitest';
+import { mkdtemp, mkdir, rm, readFile, writeFile } from 'fs/promises';
+import { tmpdir } from 'os';
+import { join } from 'path';
+
+import migration from './198-character-clear-legacy-rpg-defaults.js';
+
+let rootDir;
+
+const CHARACTER_REL = 'data/character.json';
+
+async function seed(character) {
+ await mkdir(join(rootDir, 'data'), { recursive: true });
+ await writeFile(join(rootDir, CHARACTER_REL), JSON.stringify(character, null, 2));
+}
+
+async function readCharacter() {
+ return JSON.parse(await readFile(join(rootDir, CHARACTER_REL), 'utf-8'));
+}
+
+const character = (overrides = {}) => ({
+ name: 'Adventurer',
+ class: 'Developer',
+ xp: 100,
+ hp: 15,
+ maxHp: 15,
+ events: [],
+ createdAt: '2020-01-01T00:00:00.000Z',
+ updatedAt: '2020-01-01T00:00:00.000Z',
+ ...overrides,
+});
+
+beforeEach(async () => {
+ rootDir = await mkdtemp(join(tmpdir(), 'portos-mig198-'));
+});
+
+afterEach(async () => {
+ await rm(rootDir, { recursive: true, force: true });
+});
+
+describe('198-character-clear-legacy-rpg-defaults', () => {
+ it('clears the exact legacy name and class, preserving other fields', async () => {
+ await seed(character());
+
+ const result = await migration.up({ rootDir });
+
+ expect(result.cleared).toBe(true);
+ const out = await readCharacter();
+ expect(out.name).toBe('');
+ expect(out.class).toBe('');
+ // Everything else is preserved.
+ expect(out.xp).toBe(100);
+ expect(out.events).toEqual([]);
+ // updatedAt is refreshed since a change landed.
+ expect(out.updatedAt).not.toBe('2020-01-01T00:00:00.000Z');
+ });
+
+ it('clears each legacy default independently', async () => {
+ await seed(character({ name: 'Alice', class: 'Developer' }));
+ expect((await migration.up({ rootDir })).cleared).toBe(true);
+ const out = await readCharacter();
+ expect(out.name).toBe('Alice'); // a deliberate name is kept
+ expect(out.class).toBe(''); // the legacy class is cleared
+ });
+
+ it('leaves a personalized name/class untouched (no rewrite)', async () => {
+ await seed(character({ name: 'Alice', class: 'Explorer' }));
+ const before = await readFile(join(rootDir, CHARACTER_REL), 'utf-8');
+
+ const result = await migration.up({ rootDir });
+
+ expect(result.cleared).toBe(false);
+ expect(await readFile(join(rootDir, CHARACTER_REL), 'utf-8')).toBe(before);
+ });
+
+ it('is a no-op on a fresh post-#2677 install (already-blank seed)', async () => {
+ await seed(character({ name: '', class: '' }));
+ const before = await readFile(join(rootDir, CHARACTER_REL), 'utf-8');
+
+ expect((await migration.up({ rootDir })).cleared).toBe(false);
+ expect(await readFile(join(rootDir, CHARACTER_REL), 'utf-8')).toBe(before);
+ });
+
+ it('tolerates a missing character.json', async () => {
+ expect(await migration.up({ rootDir })).toEqual({ cleared: false, reason: 'no-file' });
+ });
+
+ it('skips an unparseable or unexpectedly-shaped file rather than destroying it', async () => {
+ await mkdir(join(rootDir, 'data'), { recursive: true });
+ await writeFile(join(rootDir, CHARACTER_REL), '{not json');
+ expect((await migration.up({ rootDir })).reason).toBe('unparseable');
+ expect(await readFile(join(rootDir, CHARACTER_REL), 'utf-8')).toBe('{not json');
+
+ await writeFile(join(rootDir, CHARACTER_REL), '[]');
+ expect((await migration.up({ rootDir })).reason).toBe('unexpected-shape');
+ });
+});
diff --git a/server/services/character.js b/server/services/character.js
index b786ee4bfc..9034a69368 100644
--- a/server/services/character.js
+++ b/server/services/character.js
@@ -117,8 +117,13 @@ function createEvent(type, description, overrides = {}) {
export function createDefaultCharacter() {
const now = new Date().toISOString();
return {
- name: 'Adventurer',
- class: 'Developer',
+ // Empty = unset. The human-centered Character page (#2677) renders "Your name" / "Add a
+ // title" placeholders for an empty name/class, so a fresh install starts blank rather than
+ // presenting the old generic "Adventurer" / "Developer" identity (epic #2672). Existing
+ // installs whose character.json still carries those legacy defaults are cleared by
+ // migration 198.
+ name: '',
+ class: '',
xp: 0,
hp: DEFAULT_MAX_HP,
maxHp: DEFAULT_MAX_HP,