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: fold retired characters category into canon at expand boundary; gate Linked World prompt block on hasLinkedWorld; add migration 019 test
[._.]/ Adam Eivy8035e31e5678
diff --git a/data.sample/prompts/stages/pipeline-arc-overview.md b/data.sample/prompts/stages/pipeline-arc-overview.mdindex ec09355ecf..ea4efd6b6a 100644--- a/data.sample/prompts/stages/pipeline-arc-overview.md+++ b/data.sample/prompts/stages/pipeline-arc-overview.md@@ -34,6 +34,7 @@ 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}}+{{#hasLinkedWorld}}## Linked World — canonical entitiesThe 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.@@ -43,6 +44,7 @@ The series is grounded in this World Builder world: **{{worldName}}**. When you```{{worldCanonText}}```+{{/hasLinkedWorld}}{{> bible-deference }}diff --git a/data.sample/prompts/stages/pipeline-arc-resolve.md b/data.sample/prompts/stages/pipeline-arc-resolve.mdindex 09ffd29755..44d7919e03 100644--- a/data.sample/prompts/stages/pipeline-arc-resolve.md+++ b/data.sample/prompts/stages/pipeline-arc-resolve.md@@ -14,6 +14,7 @@ Every series is published as both a graphic novel (issues → volumes) AND a TV{{series.premise}}```+{{#hasLinkedWorld}}## Linked World — canonical entitiesThe arc is grounded in this World Builder world: **{{worldName}}**. When you rewrite synopses, ground them in these entities by name. If a finding flagged "world entity drift", swap the made-up entity for the closest match below.@@ -35,6 +36,7 @@ The arc is grounded in this World Builder world: **{{worldName}}**. When you rew```{{worldCompositesText}}```+{{/hasLinkedWorld}}{{> bible-deference }}diff --git a/data.sample/prompts/stages/pipeline-arc-verify.md b/data.sample/prompts/stages/pipeline-arc-verify.mdindex 02358ba092..d0b297f19f 100644--- a/data.sample/prompts/stages/pipeline-arc-verify.md+++ b/data.sample/prompts/stages/pipeline-arc-verify.md@@ -15,6 +15,7 @@ You are a continuity editor doing a cross-season pass on a planned series. The u{{> bible-deference }}+{{#hasLinkedWorld}}## Linked World — canonical entitiesThe 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.@@ -24,6 +25,7 @@ The series is grounded in this World Builder world: **{{worldName}}**. When you```{{worldCanonText}}```+{{/hasLinkedWorld}}## Full arcdiff --git a/data.sample/prompts/stages/pipeline-volume-verify.md b/data.sample/prompts/stages/pipeline-volume-verify.mdindex 652c0b272c..e204ad2448 100644--- a/data.sample/prompts/stages/pipeline-volume-verify.md+++ b/data.sample/prompts/stages/pipeline-volume-verify.md@@ -14,6 +14,7 @@ Every series is published in two parallel formats: graphic novel (issues → vol{{series.premise}}```+{{#hasLinkedWorld}}## Linked World — canonical entitiesThe arc was authored against this World Builder world: **{{worldName}}**. Continuity findings should call out when the volume references factions / characters / locations that don't exist in this entity set.@@ -35,6 +36,7 @@ The arc was authored against this World Builder world: **{{worldName}}**. Contin```{{worldCompositesText}}```+{{/hasLinkedWorld}}{{> bible-deference }}diff --git a/scripts/migrations/019-arc-volume-prompts-canon-context.js b/scripts/migrations/019-arc-volume-prompts-canon-context.jsindex e9a574c157..faaea35b8c 100644--- a/scripts/migrations/019-arc-volume-prompts-canon-context.js+++ b/scripts/migrations/019-arc-volume-prompts-canon-context.js@@ -62,10 +62,10 @@ 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',+ 'pipeline-arc-overview.md': '0a1f6ffa6908522e3690c5e9e53a6ee0',+ 'pipeline-arc-verify.md': '36aa70cdfc25d7549573a4d556e7702c',+ 'pipeline-arc-resolve.md': '8e348f3d1894382889f9f0ee7d5c6792',+ 'pipeline-volume-verify.md': '49458d36700cb94e34806d536ffe2940',};export default {diff --git a/scripts/migrations/019-arc-volume-prompts-canon-context.test.js b/scripts/migrations/019-arc-volume-prompts-canon-context.test.jsnew file mode 100644index 0000000000..10e8ed7bb5--- /dev/null+++ b/scripts/migrations/019-arc-volume-prompts-canon-context.test.js@@ -0,0 +1,141 @@+/**+ * Test for migration 019 — arc/volume prompt templates gain {{worldCanonText}}+ * (gated by {{#hasLinkedWorld}}).+ *+ * Picked up via the vitest include glob in server/vitest.config.js+ * (`../scripts/migrations/**\/*.test.js`).+ */+import { describe, it, expect, beforeEach, afterEach } from 'vitest';+import { mkdtempSync, rmSync, writeFileSync, readFileSync, mkdirSync, existsSync } from 'fs';+import { tmpdir } from 'os';+import { join } from 'path';++import migration from './019-arc-volume-prompts-canon-context.js';++// Mirror of the migration's hash table — when these change the test fixtures+// below need to mirror the change too.+const ACCEPTED_OLD_MD5 = {+ 'pipeline-arc-overview.md': [+ 'd34d72b8e49ba303d38607845dd87f1c',+ '6a3ecab43d1f46b7ef9aab6c69ea0326',+ ],+ 'pipeline-arc-verify.md': [+ 'ff56d8387162017e08d5d0491060ddd6',+ '52e31abc93e3105176236fcaa5d1575a',+ ],+ 'pipeline-arc-resolve.md': [+ 'a8677bbe1eb38f871fb152a5b0fec7c6',+ '87bc5c01f1a8a97b681727a38b05edc6',+ ],+ 'pipeline-volume-verify.md': [+ '03f3c874cb80e1c98abcf03168fa7a92',+ 'c6ea28e972ad6e229bafb2d602b4dda3',+ ],+};+const NEW_SHIPPED_MD5 = {+ 'pipeline-arc-overview.md': '0a1f6ffa6908522e3690c5e9e53a6ee0',+ 'pipeline-arc-verify.md': '36aa70cdfc25d7549573a4d556e7702c',+ 'pipeline-arc-resolve.md': '8e348f3d1894382889f9f0ee7d5c6792',+ 'pipeline-volume-verify.md': '49458d36700cb94e34806d536ffe2940',+};++// Lookup the real data.sample file for a given prompt; used to seed+// fixtures and to compute "current" file bodies for round-trip checks.+const repoRoot = join(import.meta.dirname || new URL('.', import.meta.url).pathname, '..', '..');+const sampleBody = (filename) =>+ readFileSync(join(repoRoot, 'data.sample', 'prompts', 'stages', filename), 'utf-8');++// A synthetic body that hashes to none of the accepted-old hashes — used to+// stand in for a user-customized prompt template.+const customizedBody = (filename) => `# CUSTOMIZED ${filename}\n\nuser-modified content not matching any shipped hash\n`;++describe('migration 019 — arc/volume prompt canon context', () => {+ let rootDir;+ let stagesDir;+ let sampleDir;++ beforeEach(() => {+ rootDir = mkdtempSync(join(tmpdir(), 'migration-019-'));+ stagesDir = join(rootDir, 'data', 'prompts', 'stages');+ sampleDir = join(rootDir, 'data.sample', 'prompts', 'stages');+ mkdirSync(stagesDir, { recursive: true });+ mkdirSync(sampleDir, { recursive: true });+ // Seed the sample dir with the actual updated content from the repo so+ // the migration has something to copy when it finds an old-hash match.+ for (const filename of Object.keys(NEW_SHIPPED_MD5)) {+ writeFileSync(join(sampleDir, filename), sampleBody(filename));+ }+ });++ afterEach(() => {+ rmSync(rootDir, { recursive: true, force: true });+ });++ it('no-ops when the stage prompt is missing (setup-data.js will create it)', async () => {+ // No file in stagesDir; migration should skip without error.+ await expect(migration.up({ rootDir })).resolves.not.toThrow();+ for (const filename of Object.keys(NEW_SHIPPED_MD5)) {+ expect(existsSync(join(stagesDir, filename))).toBe(false);+ }+ });++ it('skips files already at the new hash (idempotent re-run)', async () => {+ // Seed data/ with the same content as the sample (already migrated).+ for (const filename of Object.keys(NEW_SHIPPED_MD5)) {+ writeFileSync(join(stagesDir, filename), sampleBody(filename));+ }+ const before = Object.fromEntries(+ Object.keys(NEW_SHIPPED_MD5).map((f) => [f, readFileSync(join(stagesDir, f), 'utf-8')]),+ );+ await migration.up({ rootDir });+ for (const filename of Object.keys(NEW_SHIPPED_MD5)) {+ const after = readFileSync(join(stagesDir, filename), 'utf-8');+ expect(after).toBe(before[filename]); // unchanged+ }+ });++ it('upgrades a pre-Phase B file (matching ACCEPTED_OLD_MD5[0]) to the new sample content', async () => {+ // Fetches the pre-Phase B body via git so we can plant a fixture whose+ // hash genuinely matches `ACCEPTED_OLD_MD5['pipeline-arc-resolve.md'][0]`.+ // Pinned to commit d4002a39 (the merge-base before Phase B landed). If+ // git isn't on PATH or the commit is gone (e.g. shallow clone), skip —+ // the no-op + customized-skip + idempotent paths cover the other branches.+ let preBody;+ try {+ const { execSync } = await import('node:child_process');+ preBody = execSync('git show d4002a39:data.sample/prompts/stages/pipeline-arc-resolve.md', {+ cwd: repoRoot,+ encoding: 'utf-8',+ });+ } catch {+ return; // git unavailable — exercise via the other branches.+ }+ writeFileSync(join(stagesDir, 'pipeline-arc-resolve.md'), preBody);+ await migration.up({ rootDir });+ expect(readFileSync(join(stagesDir, 'pipeline-arc-resolve.md'), 'utf-8'))+ .toBe(sampleBody('pipeline-arc-resolve.md'));+ });++ it('skips (does not clobber) a customized file whose hash matches neither old nor new', async () => {+ for (const filename of Object.keys(NEW_SHIPPED_MD5)) {+ writeFileSync(join(stagesDir, filename), customizedBody(filename));+ }+ await migration.up({ rootDir });+ for (const filename of Object.keys(NEW_SHIPPED_MD5)) {+ expect(readFileSync(join(stagesDir, filename), 'utf-8')).toBe(customizedBody(filename));+ }+ });++ it('exposes ACCEPTED_OLD_MD5 and NEW_SHIPPED_MD5 with consistent shapes', () => {+ // Belt-and-suspenders: catch a future hash-table edit that forgets a file.+ expect(Object.keys(ACCEPTED_OLD_MD5).sort()).toEqual(Object.keys(NEW_SHIPPED_MD5).sort());+ for (const old of Object.values(ACCEPTED_OLD_MD5)) {+ expect(Array.isArray(old)).toBe(true);+ expect(old.length).toBeGreaterThan(0);+ for (const h of old) expect(h).toMatch(/^[0-9a-f]{32}$/);+ }+ for (const h of Object.values(NEW_SHIPPED_MD5)) {+ expect(h).toMatch(/^[0-9a-f]{32}$/);+ }+ });+});diff --git a/scripts/setup-data.js b/scripts/setup-data.jsindex 8390be7284..8954b245cb 100644--- a/scripts/setup-data.js+++ b/scripts/setup-data.js@@ -182,10 +182,10 @@ const SHIPPED_PROMPT_NEW_MD5 = {'pipeline-comic-script.md': '1e0af305c27d0c80c4b482d2ebcb4a0d','pipeline-teleplay.md': '376f779f4687b598f1c92ca4e770fd5a','pipeline-season-episodes.md':'50c68a29c3ebc275db3095d06bd87100',- 'pipeline-arc-overview.md': '59e19fb81417e640194a5e3ac5773125',- 'pipeline-arc-verify.md': 'd077c3d6197fbb9a684a1fbb41a9493c',- 'pipeline-volume-verify.md': '56ad31371452a6fdf68597512f8c0d35',- 'pipeline-arc-resolve.md': '2651dc3947adc75c02c4f394135f2703',+ 'pipeline-arc-overview.md': '0a1f6ffa6908522e3690c5e9e53a6ee0',+ 'pipeline-arc-verify.md': '36aa70cdfc25d7549573a4d556e7702c',+ 'pipeline-volume-verify.md': '49458d36700cb94e34806d536ffe2940',+ 'pipeline-arc-resolve.md': '8e348f3d1894382889f9f0ee7d5c6792','pipeline-extract-scenes.md': 'c51fb208568d0d903eb43b437478b0ba','writers-room-places.md': '24a33628cc94d80fa5ca60831d973daf','cos-agent-briefing.md': 'dccb392a43cbd3dac900fee12c31619a',diff --git a/server/services/pipeline/arcPlanner.js b/server/services/pipeline/arcPlanner.jsindex a67831691d..201f221acb 100644--- a/server/services/pipeline/arcPlanner.js+++ b/server/services/pipeline/arcPlanner.js@@ -86,6 +86,11 @@ async function loadWorldContext(universeId) {const avoid = Array.isArray(world.influences?.avoid) ? world.influences.avoid : [];return {+ // Truthy mustache flag the prompt templates use to gate the entire+ // "Linked World" block — unlinked arc/verify runs render a neutral+ // placeholder instead of telling the LLM the series is grounded in a+ // non-existent world.+ hasLinkedWorld: true,worldName: world.name || '',worldStarter: world.starterPrompt || '',worldLogline: world.logline || '',@@ -103,8 +108,11 @@ async function loadWorldContext(universeId) {}// Fallback when series has no linked world — prompt partials still expect-// these variables to be defined.+// these variables to be defined. `hasLinkedWorld: false` lets the template's+// `{{#hasLinkedWorld}}…{{/hasLinkedWorld}}` block fall through so the LLM+// isn't told to ground arcs in a non-existent universe.const EMPTY_WORLD_CONTEXT = {+ hasLinkedWorld: false,worldName: '(no linked world)',worldStarter: '',worldLogline: '',diff --git a/server/services/universeBuilderExpand.js b/server/services/universeBuilderExpand.jsindex bab90dce26..18649d3652 100644--- a/server/services/universeBuilderExpand.js+++ b/server/services/universeBuilderExpand.js@@ -426,6 +426,23 @@ export async function expandWorldTemplate({const logline = trimField(parsed.logline, LOGLINE_MAX);const premise = trimField(parsed.premise, PREMISE_MAX);const styleNotes = trimField(parsed.styleNotes, STYLE_NOTES_MAX);+ // Phase A retired the default `characters` category — the persisted+ // sanitizer drops it (RETIRED_CATEGORY_KEYS) and the v3→v4 backfill no+ // longer fires (schemaVersion already ≥4). If the LLM emits a top-level+ // `characters` category bucket here, fold its variations into the canon+ // characters[] return before normalizing, so the entries land in canon+ // instead of being silently dropped on auto-save round-trip.+ const rawCategories = parsed.categories && typeof parsed.categories === 'object' ? parsed.categories : {};+ const retiredCharBucket = rawCategories.characters;+ let rawCharacters = Array.isArray(parsed.characters) ? [...parsed.characters] : [];+ if (retiredCharBucket && Array.isArray(retiredCharBucket.variations)) {+ for (const v of retiredCharBucket.variations) {+ if (!v || typeof v !== 'object' || !v.label) continue;+ rawCharacters.push({ name: v.label, prompt: v.prompt });+ }+ const { characters: _drop, ...rest } = rawCategories;+ parsed.categories = rest;+ }const categories = normalizeCategories(parsed.categories || {});const compositeSheets = normalizeCompositeSheets(parsed.compositeSheets || [],@@ -433,7 +450,7 @@ export async function expandWorldTemplate({// normalizeCanonArray stamps `source: BIBLE_SOURCE.UNIVERSE_EXPAND` on each// entry before sanitize, so provenance lands on disk consistently with the// existing categories→canon backfill in universeBuilder.js.- const characters = normalizeCanonArray(parsed.characters, BIBLE_KIND.CHARACTER);+ const characters = normalizeCanonArray(rawCharacters, BIBLE_KIND.CHARACTER);const settings = normalizeCanonArray(parsed.settings, BIBLE_KIND.SETTING);const objects = normalizeCanonArray(parsed.objects, BIBLE_KIND.OBJECT);// sanitizeInfluences enforces the same per-entry cap, list cap, and