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: preserve category kind on client merge + render canon in all arc/volume prompts

[._.]/ Adam Eivybab2b2cf53ed
diff --git a/client/src/pages/UniverseBuilder.jsx b/client/src/pages/UniverseBuilder.jsx
index fa958c035a..3948873508 100644
--- a/client/src/pages/UniverseBuilder.jsx
+++ b/client/src/pages/UniverseBuilder.jsx
@@ -77,28 +77,35 @@ const mergeVariations = (existing, fresh) => {
// them; the LLM's repeat is a hallucination at this point). Dedupes by name
// AND slugline (for settings) so an expand that re-emits "Foundry City" or
// "INT. FOUNDRY CITY — DAY" can't create a phantom duplicate. Mirrors the
-// server-side dedupe in backfillCanonFromCategories (storyBible#normalizeBibleName).
+// server-side dedupe in backfillCanonFromCategories + storyBible's
+// MERGE_CONFIG (`storyBible.js` keyFields).
//
-// Sluglines use `normalizeSlugline` (same identity rule the rest of the app
-// uses — `server/lib/scenePrompt.js` + `client/src/lib/scenePrompt.js` +
-// `storyBible.js` MERGE_CONFIG.setting.keyFields). Without this, sluglines
-// that differ only in dash style or punctuation ("INT. FOUNDRY CITY — DAY"
-// vs "INT FOUNDRY CITY - DAY") would land as two separate place-canon
-// entries even though every downstream lookup treats them as one.
-const mergeCanonByName = (existing, fresh) => {
+// Identity rules are kind-aware to match the server:
+// - characters/objects → `normalizeBibleName` (trim + lowercase).
+// - settings → `normalizeSlugline` for BOTH `slugline` AND `name`
+// (`storyBible.js` MERGE_CONFIG.setting.keyFields).
+// Without this, sluglines that differ only in dash
+// style or punctuation ("INT. FOUNDRY CITY — DAY"
+// vs "INT FOUNDRY CITY - DAY") would land as two
+// separate place-canon entries, and `Foundry-City`
+// vs `Foundry City` would duplicate by name even
+// though every downstream lookup treats them as one.
+const mergeCanonByName = (existing, fresh, kind = 'character') => {
// Empty/missing fresh — return `existing` unchanged (preserve reference so
// a no-op expand doesn't trigger downstream identity-comparing effects).
if (!fresh?.length) return existing || [];
- const norm = (s) => (typeof s === 'string' ? s.trim().toLowerCase() : '');
+ const normName = kind === 'setting'
+ ? (s) => (typeof s === 'string' ? normalizeSlugline(s) : '')
+ : (s) => (typeof s === 'string' ? s.trim().toLowerCase() : '');
const normSlug = (s) => (typeof s === 'string' ? normalizeSlugline(s) : '');
const seen = new Set();
for (const e of existing || []) {
- if (e?.name) seen.add(norm(e.name));
+ if (e?.name) seen.add(normName(e.name));
if (e?.slugline) seen.add(normSlug(e.slugline));
}
const merged = [...(existing || [])];
for (const e of fresh) {
- const nameKey = norm(e?.name);
+ const nameKey = normName(e?.name);
const sluglineKey = normSlug(e?.slugline);
if ((nameKey && seen.has(nameKey)) || (sluglineKey && seen.has(sluglineKey))) continue;
if (nameKey) seen.add(nameKey);
@@ -538,7 +545,17 @@ export default function UniverseBuilder() {
for (const cat of allCatKeys) {
const locked = preservedVariations[cat] || [];
const fresh = (llmCategories[cat]?.variations || []);
- mergedCategories[cat] = { variations: mergeVariations(locked, fresh) };
+ // Preserve the bucket's `kind` so the category-to-canon-trunk contract
+ // survives the round-trip. Precedence: existing draft kind (the user
+ // may have curated it) → LLM-returned kind for this bucket → undefined
+ // (server's sanitizeCategory then falls back to the default-map / 'other').
+ const existingKind = draft.categories?.[cat]?.kind;
+ const freshKind = llmCategories[cat]?.kind;
+ const kind = existingKind || freshKind;
+ mergedCategories[cat] = {
+ ...(kind ? { kind } : {}),
+ variations: mergeVariations(locked, fresh),
+ };
}
// Composite sheets merge follows the same locked-first + dedupe pattern.
const mergedSheets = (() => {
@@ -558,10 +575,18 @@ export default function UniverseBuilder() {
// entries always win on name/slugline collision so a re-expand can't
// clobber hand-authored or series-extracted records. mergeCanonByName
// short-circuits when `fresh` is empty so identity is preserved.
- const pickCanon = (key) => mergeCanonByName(draft[key] || [], Array.isArray(result[key]) ? result[key] : []);
- const mergedCharacters = pickCanon('characters');
- const mergedSettings = pickCanon('settings');
- const mergedObjects = pickCanon('objects');
+ //
+ // `kind` is passed so settings use `normalizeSlugline` for both `name` and
+ // `slugline` (matching the server's MERGE_CONFIG.setting.keyFields) —
+ // dash/punct-variant identifiers collide instead of duplicating.
+ const pickCanon = (key, kind) => mergeCanonByName(
+ draft[key] || [],
+ Array.isArray(result[key]) ? result[key] : [],
+ kind,
+ );
+ const mergedCharacters = pickCanon('characters', 'character');
+ const mergedSettings = pickCanon('settings', 'setting');
+ const mergedObjects = pickCanon('objects', 'object');
const expandedDraft = {
...draft,
diff --git a/data.sample/prompts/stages/pipeline-arc-overview.md b/data.sample/prompts/stages/pipeline-arc-overview.md
index 5de9f114c8..ec09355ecf 100644
--- a/data.sample/prompts/stages/pipeline-arc-overview.md
+++ b/data.sample/prompts/stages/pipeline-arc-overview.md
@@ -34,6 +34,16 @@ No shape pre-picked. Choose the single Vonnegut shape that best matches the prem
- **Target total episode count (rough budget across all seasons):** {{series.issueCountTarget}}
+## Linked World — canonical entities
+
+The series is grounded in this World Builder world: **{{worldName}}**. When you write season loglines / synopses and the protagonist arc, ground them in these entities by name (not generic placeholders). If a world canon entry below names a character, place, or object that fits the season's beats, prefer it over inventing a new one.
+
+### World canon — named characters, places, objects
+
+```
+{{worldCanonText}}
+```
+
{{> bible-deference }}
## How to shape the arc
diff --git a/data.sample/prompts/stages/pipeline-arc-verify.md b/data.sample/prompts/stages/pipeline-arc-verify.md
index aea8ffff6f..02358ba092 100644
--- a/data.sample/prompts/stages/pipeline-arc-verify.md
+++ b/data.sample/prompts/stages/pipeline-arc-verify.md
@@ -15,6 +15,16 @@ You are a continuity editor doing a cross-season pass on a planned series. The u
{{> bible-deference }}
+## Linked World — canonical entities
+
+The series is grounded in this World Builder world: **{{worldName}}**. When you flag continuity findings, address characters/places/objects by their canonical names below. A "character contradiction" finding should reference the canon character; a "dropped subplot" finding should reference a canon place or object when relevant.
+
+### World canon — named characters, places, objects
+
+```
+{{worldCanonText}}
+```
+
## Full arc
- **Whole-series logline:** {{arc.logline}}
diff --git a/scripts/migrations/019-arc-resolve-volume-verify-canon-context.js b/scripts/migrations/019-arc-volume-prompts-canon-context.js
similarity index 73%
rename from scripts/migrations/019-arc-resolve-volume-verify-canon-context.js
rename to scripts/migrations/019-arc-volume-prompts-canon-context.js
index dee06f973c..0c5e8f702f 100644
--- a/scripts/migrations/019-arc-resolve-volume-verify-canon-context.js
+++ b/scripts/migrations/019-arc-volume-prompts-canon-context.js
@@ -1,10 +1,12 @@
/**
- * Add `{{worldCanonText}}` context block to the arc-resolve and
- * volume-verify prompt templates so the LLM sees named universe canon
- * (characters/places/objects) alongside the existing exploratory
- * `worldCategoriesText`.
+ * Add `{{worldCanonText}}` context block to the four arc/volume prompt
+ * templates that receive linked-world context so the LLM sees named
+ * universe canon (characters/places/objects) alongside the existing
+ * exploratory `worldCategoriesText`.
*
* Updates (per ACCEPTED_OLD_MD5 below):
+ * - data/prompts/stages/pipeline-arc-overview.md
+ * - data/prompts/stages/pipeline-arc-verify.md
* - data/prompts/stages/pipeline-arc-resolve.md
* - data/prompts/stages/pipeline-volume-verify.md
*
@@ -12,8 +14,11 @@
* Phase A retired the default `characters` category; characters now live in
* `universe.characters[]` (canon). Without this template change, arc-level
* prompts that grounded continuity findings in entity names lost the
- * character roster entirely. See PLAN.md → Phase B + the
- * "arcPlanner prompt context — include canon" backlog item it folded in.
+ * character roster entirely. arcPlanner exposes `worldCanonText` to every
+ * arc context now, but a context field without a template reference is
+ * silently ignored — so every prompt that gets the field must render it.
+ * See PLAN.md → Phase B + the "arcPlanner prompt context — include canon"
+ * backlog item it folded in.
*
* Strategy — unmodified-only update, mirrors migration 003:
* - If the on-disk file matches the prior shipped MD5 (either the pre-005
@@ -37,6 +42,14 @@ const md5 = (str) => {
// recent shipped hash first, then older). Any match is treated as
// "unmodified by user → safe to replace."
const ACCEPTED_OLD_MD5 = {
+ 'pipeline-arc-overview.md': [
+ 'd34d72b8e49ba303d38607845dd87f1c', // current (pre-Phase B) shipped
+ '6a3ecab43d1f46b7ef9aab6c69ea0326', // pre-005 (shape-aware), still in setup-data.js OLD list
+ ],
+ 'pipeline-arc-verify.md': [
+ 'ff56d8387162017e08d5d0491060ddd6', // current (pre-Phase B) shipped
+ '52e31abc93e3105176236fcaa5d1575a', // pre-005 (shape-aware), still in setup-data.js OLD list
+ ],
'pipeline-arc-resolve.md': [
'a8677bbe1eb38f871fb152a5b0fec7c6', // current (pre-Phase B) shipped
'87bc5c01f1a8a97b681727a38b05edc6', // pre-005 (shape-aware), still in setup-data.js OLD list
@@ -49,6 +62,8 @@ const ACCEPTED_OLD_MD5 = {
// New shipped hashes — what data.sample carries post-migration.
const NEW_SHIPPED_MD5 = {
+ 'pipeline-arc-overview.md': '59e19fb81417e640194a5e3ac5773125',
+ 'pipeline-arc-verify.md': 'd077c3d6197fbb9a684a1fbb41a9493c',
'pipeline-arc-resolve.md': '2651dc3947adc75c02c4f394135f2703',
'pipeline-volume-verify.md': '56ad31371452a6fdf68597512f8c0d35',
};
@@ -114,9 +129,10 @@ export default {
if (skipped > 0) {
console.warn(
- `\n⚠️ ${skipped} arc prompt(s) could not be auto-updated because they were customized.\n` +
- ` The {{worldCanonText}} block will not render character names in arc-verify/resolve\n` +
- ` until the files are merged manually. See data.sample/prompts/stages/.`,
+ `\n⚠️ ${skipped} arc/volume prompt(s) could not be auto-updated because they were customized.\n` +
+ ` The {{worldCanonText}} block will not render character names in arc-overview/\n` +
+ ` arc-verify/arc-resolve/volume-verify until the files are merged manually. See\n` +
+ ` data.sample/prompts/stages/.`,
);
}
},
diff --git a/scripts/setup-data.js b/scripts/setup-data.js
index 2283538fcd..8390be7284 100644
--- a/scripts/setup-data.js
+++ b/scripts/setup-data.js
@@ -148,9 +148,12 @@ const SHIPPED_PROMPT_OLD_MD5 = {
// season-episodes: 6e349a… (pre-003) and c4928e… (post-003, pre-005) both
// auto-updatable to the post-005 (shape-aware) hash.
'pipeline-season-episodes.md': ['6e349ad26bed8a0ccb042571f03f03eb', 'c4928e2a5f833358116b29d2d669888d'],
- // Shape-aware additions (migration 005).
- 'pipeline-arc-overview.md': '6a3ecab43d1f46b7ef9aab6c69ea0326',
- 'pipeline-arc-verify.md': '52e31abc93e3105176236fcaa5d1575a',
+ // arc-overview: 6a3eca… (pre-005) and d34d72… (post-005, pre-019) both
+ // auto-updatable to the post-019 (worldCanonText) hash.
+ 'pipeline-arc-overview.md': ['6a3ecab43d1f46b7ef9aab6c69ea0326', 'd34d72b8e49ba303d38607845dd87f1c'],
+ // arc-verify: 52e31a… (pre-005) and ff56d8… (post-005, pre-019) both
+ // auto-updatable to the post-019 (worldCanonText) hash.
+ 'pipeline-arc-verify.md': ['52e31abc93e3105176236fcaa5d1575a', 'ff56d8387162017e08d5d0491060ddd6'],
// volume-verify: c6ea28… (pre-005) and 03f3c8… (post-005, pre-019) both
// auto-updatable to the post-019 (worldCanonText) hash.
'pipeline-volume-verify.md': ['c6ea28e972ad6e229bafb2d602b4dda3', '03f3c874cb80e1c98abcf03168fa7a92'],
@@ -179,8 +182,8 @@ const SHIPPED_PROMPT_NEW_MD5 = {
'pipeline-comic-script.md': '1e0af305c27d0c80c4b482d2ebcb4a0d',
'pipeline-teleplay.md': '376f779f4687b598f1c92ca4e770fd5a',
'pipeline-season-episodes.md':'50c68a29c3ebc275db3095d06bd87100',
- 'pipeline-arc-overview.md': 'd34d72b8e49ba303d38607845dd87f1c',
- 'pipeline-arc-verify.md': 'ff56d8387162017e08d5d0491060ddd6',
+ 'pipeline-arc-overview.md': '59e19fb81417e640194a5e3ac5773125',
+ 'pipeline-arc-verify.md': 'd077c3d6197fbb9a684a1fbb41a9493c',
'pipeline-volume-verify.md': '56ad31371452a6fdf68597512f8c0d35',
'pipeline-arc-resolve.md': '2651dc3947adc75c02c4f394135f2703',
'pipeline-extract-scenes.md': 'c51fb208568d0d903eb43b437478b0ba',
diff --git a/server/services/universeBuilderExpand.js b/server/services/universeBuilderExpand.js
index e2f1aff0a0..6b8088c40c 100644
--- a/server/services/universeBuilderExpand.js
+++ b/server/services/universeBuilderExpand.js
@@ -283,9 +283,20 @@ const normalizeCompositeSheets = (raw) =>
// so the merge step downstream can rely on `Array.isArray`. Stamps `source`
// pre-sanitize so the sanitizer's `ensureSource` allowlist validates it (a
// post-sanitize stamp would bypass that check).
+//
+// Strip `id`/`createdAt`/`updatedAt` from raw entries before sanitizing.
+// `sanitizeBibleList` preserves any non-empty `id` it sees on input, so an
+// LLM that hallucinates an `id` (or — more likely — copies an example id from
+// the prompt) would otherwise inject duplicate or arbitrary identifiers into
+// the draft. The sanitizer mints a fresh id when one is missing; that's the
+// correct behavior for expand, which is always creating fresh canon entries.
const normalizeCanonArray = (raw, kind) => {
if (!Array.isArray(raw)) return [];
- const stamped = raw.map((e) => (e && typeof e === 'object' ? { ...e, source: BIBLE_SOURCE.UNIVERSE_EXPAND } : e));
+ const stamped = raw.map((e) => {
+ if (!e || typeof e !== 'object') return e;
+ const { id: _ignoredId, createdAt: _ca, updatedAt: _ua, ...rest } = e;
+ return { ...rest, source: BIBLE_SOURCE.UNIVERSE_EXPAND };
+ });
// Expand is creating fresh entries; let the sanitizer stamp timestamps
// instead of preserving (likely-absent) ones from the LLM output.
return sanitizeBibleList(stamped, kind, { preserveTimestamps: false });