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: separate characters-bucket fold from legacy backfill, enrich canon renderer with personality/slugline/recurringDetails, fix mergeCanonByName within-batch dedupe, correct PLAN doc

[._.]/ Adam Eivy4aba46ff147c
diff --git a/PLAN.md b/PLAN.md
index ef2af8fd66..f8c619b41c 100644
--- a/PLAN.md
+++ b/PLAN.md
@@ -36,7 +36,7 @@ For project goals, see [GOALS.md](./GOALS.md). For completed work, see [DONE.md]
- [x] ~~**Retire `universe.categories` on the schema.**~~ **Rejected 2026-05-17** — categories are an active user-facing exploration workflow (custom buckets like `factions`/`colonies`/`raider_clans`, bulk variation generation, batch render). Canon has no equivalent. See "Categories vs canon — decision" below.
- [→] **Drop the default `characters` category.** Folded into Next Up #1 Phase A.
- [→] **Universe expand LLM contract enrichment.** Folded into Next Up #1 Phase B.
-- [→] **arcPlanner prompt context — include canon characters/places/objects.** Folded into Next Up #1 Phase B (Phase B PR shipped `renderCanonForPrompt(world)` + `worldCanonText` + migration 019 for the arc-resolve/volume-verify templates). Follow-up: sweep `grep -rn "world\.categories" server/services/pipeline server/services/universeBuilder*.js` for other prompt builders that read categories but not canon.
+- [→] **arcPlanner prompt context — include canon characters/places/objects.** Folded into Next Up #1 Phase B (Phase B PR shipped `renderCanonForPrompt(world)` + `worldCanonText` + migration 019 for all four arc/volume templates: `pipeline-arc-overview`, `pipeline-arc-verify`, `pipeline-arc-resolve`, `pipeline-volume-verify`). Follow-up: sweep `grep -rn "world\.categories" server/services/pipeline server/services/universeBuilder*.js` for other prompt builders that read categories but not canon.
- [ ] **Settings → Places kind rename.** `BIBLE_KIND.SETTING → BIBLE_KIND.PLACE`, `BIBLE_FIELD[SETTING]: 'settings' → 'places'`. Touches ~20 files. Stick the rename to bible context — app settings stays as "settings".
- [ ] **Use rendered reference images as i2i anchors in downstream comic-page renders for models that support it.** SDXL/Flux pipelines anchor every panel render on the per-character rendered ref.
diff --git a/client/src/pages/UniverseBuilder.jsx b/client/src/pages/UniverseBuilder.jsx
index c873dae27f..93f511916b 100644
--- a/client/src/pages/UniverseBuilder.jsx
+++ b/client/src/pages/UniverseBuilder.jsx
@@ -122,10 +122,15 @@ const mergeCanonByName = (existing, fresh, kind = 'character') => {
const collides = (nameKey && seen.has(nameKey))
|| (sluglineKey && seen.has(sluglineKey))
|| aliasMatches.some((k) => seen.has(k));
- if (collides) continue;
+ // On collision, still register every identity key the fresh entry
+ // carried — so a *later* fresh entry with overlapping aliases/sluglines
+ // is recognized as a within-batch duplicate too. Without this, fresh
+ // entry A (collides on alias) gets skipped silently and fresh entry B
+ // (uses A's primary name) slips in as a duplicate of the existing record.
if (nameKey) seen.add(nameKey);
if (sluglineKey) seen.add(sluglineKey);
for (const k of aliasMatches) seen.add(k);
+ if (collides) continue;
merged.push(e);
}
return merged;
diff --git a/server/lib/universePromptRenderers.js b/server/lib/universePromptRenderers.js
index f46bb715c6..8162b7da95 100644
--- a/server/lib/universePromptRenderers.js
+++ b/server/lib/universePromptRenderers.js
@@ -52,35 +52,46 @@ const truncDesc = (s) => {
// One row per canon trunk; renderCanonForPrompt iterates this so a future
// kind addition (or field tweak) is a one-line change. formatEntry truncates
// the long description field so a single entry can't dominate the prompt.
+// Build a ` - name [role]: physDesc. personality (background). tags: a, b`
+// line for a canon character. Trailing metadata is rendered only when
+// present so an empty bible doesn't pollute the prompt with empty markers.
+const formatCharacter = (c) => {
+ const role = c.role ? ` [${c.role}]` : '';
+ const tags = Array.isArray(c.tags) && c.tags.length ? ` tags: ${c.tags.join(', ')}` : '';
+ const parts = [
+ truncDesc(c.physicalDescription || c.description || ''),
+ truncDesc(c.personality || ''),
+ c.background ? `background: ${truncDesc(c.background)}` : '',
+ ].filter(Boolean);
+ const body = parts.length ? `: ${parts.join('. ')}` : '';
+ return ` - ${c.name}${role}${body}${tags}`;
+};
+
+// Place: prefer name; show slugline when present (screenplay-style location
+// header used by scene matchers); include recurringDetails — the expand
+// contract collects all three and the LLM uses them as continuity anchors.
+const formatSetting = (s) => {
+ const label = s.name || s.slugline || '(unnamed)';
+ const sluglineTag = s.name && s.slugline ? ` (${s.slugline})` : '';
+ const palette = s.palette ? ` palette: ${s.palette}` : '';
+ const parts = [
+ truncDesc(s.description || ''),
+ s.recurringDetails ? `recurring: ${truncDesc(s.recurringDetails)}` : '',
+ ].filter(Boolean);
+ const body = parts.length ? `: ${parts.join('. ')}` : '';
+ return ` - ${label}${sluglineTag}${body}${palette}`;
+};
+
+const formatObject = (o) => {
+ const desc = truncDesc(o.description || '');
+ const sig = o.significance ? ` (${truncDesc(o.significance)})` : '';
+ return ` - ${o.name}${desc ? `: ${desc}` : ''}${sig}`;
+};
+
const CANON_SECTIONS = [
- {
- field: 'characters',
- header: 'characters',
- formatEntry: (c) => {
- const desc = truncDesc(c.physicalDescription || c.description || '');
- const role = c.role ? ` [${c.role}]` : '';
- return ` - ${c.name}${role}${desc ? `: ${desc}` : ''}`;
- },
- },
- {
- field: 'settings',
- header: 'places',
- formatEntry: (s) => {
- const label = s.name || s.slugline || '(unnamed)';
- const desc = truncDesc(s.description || '');
- const palette = s.palette ? ` palette: ${s.palette}` : '';
- return ` - ${label}${desc ? `: ${desc}` : ''}${palette}`;
- },
- },
- {
- field: 'objects',
- header: 'objects',
- formatEntry: (o) => {
- const desc = truncDesc(o.description || '');
- const sig = o.significance ? ` (${truncDesc(o.significance)})` : '';
- return ` - ${o.name}${desc ? `: ${desc}` : ''}${sig}`;
- },
- },
+ { field: 'characters', header: 'characters', formatEntry: formatCharacter },
+ { field: 'settings', header: 'places', formatEntry: formatSetting },
+ { field: 'objects', header: 'objects', formatEntry: formatObject },
];
// Render the universe's canon arrays (characters/settings/objects) into a
diff --git a/server/services/universeBuilder.js b/server/services/universeBuilder.js
index ee388d00b9..19591d28d6 100644
--- a/server/services/universeBuilder.js
+++ b/server/services/universeBuilder.js
@@ -436,12 +436,56 @@ export const sanitizeCompositeSheets = (raw = []) => {
return sheets;
};
+// Always-on fold of the retired `characters` category bucket into
+// universe.characters[]. Runs regardless of schemaVersion so the Phase A
+// retirement contract holds for every write path (createUniverse,
+// updateUniverse, importer share-bucket, stale-client PATCH). Dedupes by
+// normalized name so existing canon records are preserved on collision.
+// Returns the (mutated-shape) canon arrays the caller should consume.
+function foldRetiredCharactersBucket(raw, canon) {
+ const categories = raw && typeof raw.categories === 'object' ? raw.categories : {};
+ const charBucket = categories.characters;
+ const variations = Array.isArray(charBucket)
+ ? charBucket
+ : Array.isArray(charBucket?.variations)
+ ? charBucket.variations
+ : null;
+ if (!variations) return canon;
+ const next = {
+ characters: Array.isArray(canon.characters) ? [...canon.characters] : [],
+ settings: canon.settings,
+ objects: canon.objects,
+ };
+ const seen = new Set(next.characters.map((e) => normalizeBibleName(e?.name)));
+ for (const variation of variations) {
+ const labelSource = typeof variation === 'string' ? variation : variation?.label;
+ const label = trimTo(labelSource, BIBLE_LIMITS.NAME_MAX);
+ if (!label) continue;
+ const nameKey = normalizeBibleName(label);
+ if (seen.has(nameKey)) continue;
+ if (next.characters.length >= BIBLE_LIMITS.ENTRIES_PER_BIBLE_MAX) break;
+ const entry = {
+ name: label,
+ prompt: trimTo(typeof variation === 'object' ? variation?.prompt : '', BIBLE_LIMITS.PROMPT_MAX),
+ tags: [],
+ source: BIBLE_SOURCE.UNIVERSE_EXPAND,
+ };
+ if (typeof variation === 'object' && variation?.locked === true) entry.locked = true;
+ next.characters.push(entry);
+ seen.add(nameKey);
+ }
+ return next;
+}
+
// Backfill canon arrays from v1 `categories[].variations[]`. Idempotent:
// entries matching an existing canon name (case-insensitive) are skipped, so
-// hand-authored / series-extracted records are never overwritten. Categories
-// stay intact during the transition; Phase 2 UI retires them.
+// hand-authored / series-extracted records are never overwritten. The
+// retired `characters` bucket is handled by foldRetiredCharactersBucket
+// before this runs; here we only fold the *other* legacy categories
+// (landscapes/environments/structures/vehicles + customs) into
+// settings/objects for the v3→v4 transition.
function backfillCanonFromCategories(raw, existingCanon) {
- // v2 hot path — already backfilled. Sanitize through the kind sanitizers
+ // v4 hot path — already backfilled. Sanitize through the kind sanitizers
// once and return; no category scan needed.
if (raw.schemaVersion >= CURRENT_SCHEMA_VERSION) {
return {
@@ -466,6 +510,9 @@ function backfillCanonFromCategories(raw, existingCanon) {
const categories = raw && typeof raw.categories === 'object' ? raw.categories : {};
for (const [rawKey, value] of Object.entries(categories)) {
const categoryKey = normalizeCategoryKey(rawKey) || rawKey;
+ // Skip the retired `characters` bucket — foldRetiredCharactersBucket
+ // already handled it on the always-on path.
+ if (categoryKey === 'characters') continue;
const { kind, tags } = resolveCanonForCategory(categoryKey);
const targetField = BIBLE_FIELD[kind];
const variations = Array.isArray(value?.variations) ? value.variations : [];
@@ -519,14 +566,21 @@ const sanitizeTemplate = (raw) => {
mergeLegacyPromptsIntoInfluences(raw.influences, raw.stylePrompt, raw.negativePrompt),
);
const locked = sanitizeLocked(raw.locked);
- // Canon registries. Backfill copies legacy `categories[].variations[]` into
- // the matching kind on first read so series-side prompts can pull canon by
- // entity name; categories stays alive until Phase 2 retires it.
- const canonBackfill = backfillCanonFromCategories(raw, {
+ // Canon registries. Two passes:
+ // 1. foldRetiredCharactersBucket — Phase A retirement contract. ALWAYS
+ // runs (regardless of schemaVersion) so a `categories.characters`
+ // bucket arriving from any write path folds into universe.characters[].
+ // 2. backfillCanonFromCategories — legacy v3→v4 migration. Runs ONLY for
+ // pre-v4 reads, folds all OTHER category buckets (landscapes/vehicles/
+ // custom) into settings/objects. New v4 universes skip this so Phase
+ // B's separation of canon (named entities) and categories (exploratory
+ // variations) stays clean.
+ const foldedCanon = foldRetiredCharactersBucket(raw, {
characters: raw.characters,
settings: raw.settings,
objects: raw.objects,
});
+ const canonBackfill = backfillCanonFromCategories(raw, foldedCanon);
const { characters, settings, objects, schemaVersion } = canonBackfill;
const llm = raw.llm && typeof raw.llm === 'object'
? {
@@ -631,6 +685,14 @@ export async function createUniverse(input = {}) {
characters: input.characters || [],
settings: input.settings || [],
objects: input.objects || [],
+ // Stamp the current schema so backfillCanonFromCategories takes its
+ // hot-path skip on first read. Without this, the legacy categories→
+ // canon backfill fires on every brand-new universe and re-pollutes
+ // `characters/settings/objects` with every category variation —
+ // counter to Phase B's separation of canon (named entities) from
+ // categories (exploratory variations). New universes are always at
+ // CURRENT_SCHEMA_VERSION; the backfill exists only for legacy reads.
+ schemaVersion: CURRENT_SCHEMA_VERSION,
llm: input.llm || {},
createdAt: now,
updatedAt: now,