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

feat(pipeline): world bible → new-series autofill (logline/premise/styleNotes)

[._.]/ Adam Eivy7415c3c0367f
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index e0b3e6a59a..fd25272e57 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -6,6 +6,8 @@
## Added
+- **World Builder → Pipeline bible bridge.** Worlds now carry three narrative-bible fields — `logline`, `premise`, and `styleNotes` — alongside the existing image-prompt template. The World Builder editor surfaces them in a new "Story bible" section, and the LLM "Expand starter → variations" pass now generates them in the same call (only overwriting the user's prose when the model actually produced new copy, so re-running expand to refresh image categories doesn't clobber hand-edited bible text). The Pipeline → New Series form gains a world dropdown as the first field; picking a world auto-fills logline / premise / style notes from that world (only into empty form fields, so a user who's already started typing isn't surprised). `worldId` + `premise` + `styleNotes` now ride the create-series payload alongside `logline`, populating the series bible in one click. Backed by new caps (`LOGLINE_MAX` / `PREMISE_MAX` / `STYLE_NOTES_MAX`) on `server/services/worldBuilder.js`, shared client-side via `WORLD_LOGLINE_MAX` / `WORLD_PREMISE_MAX` / `WORLD_STYLE_NOTES_MAX` exports from `apiWorldBuilder.js`. Test coverage in `server/services/worldBuilder.test.js` (persist + patch + trim-to-max) and `server/services/worldBuilderExpand.test.js` (asserts the EXPANSION_PROMPT keeps the bible contract).
+
- **Voice agent — read the page aloud.** A new `ui_read` voice tool extracts the visible text of the current page (main content area, excluding nav rails and the voice widget) and returns it verbatim. Ask "what does this say?", "read this aloud", or "what's on the page?" and the assistant speaks the content back. Text is captured from the same client-side index that already powers `ui_click` / `ui_fill`, so no extra round-trip and no new permissions. Output is capped at ~8 KB on a word boundary; longer pages get a graceful ellipsis tail.
- **Voice agent — destructive-action confirmation.** When the voice agent is about to click a button whose label matches Delete / Remove / Discard / Reset / Clear, the click is paused and the assistant asks for spoken confirmation ("say yes or confirm to delete, or cancel to skip"). Your next spoken word resolves the prompt: *yes / confirm / do it / go ahead* fires the click, *no / cancel / stop / never mind* drops the pending action, and anything else (a new request like "what time is it?") quietly discards the pending click and answers the new question. Pending confirmations expire after one minute so a forgotten "yes" minutes later can't re-fire a stale destructive click.
diff --git a/PLAN.md b/PLAN.md
index 2e2fa00b92..85205d7b16 100644
--- a/PLAN.md
+++ b/PLAN.md
@@ -6,7 +6,7 @@ For project goals, see [GOALS.md](./GOALS.md). For completed work, see [DONE.md]
## Next Up
-_(empty — pick the next chunk from Backlog)_
+- [ ] **Fix `lib/creativeDirectorPrompts.test.js` imageStrength wording assertions.** 3 tests in `server/lib/creativeDirectorPrompts.test.js` (around line 210) fail on `expect(out).toContain('Image strength: default')` — the prompt template no longer emits that exact phrasing for unset/null imageStrength. Pre-existing on `main` (verified 2026-05-12 while landing world-bible → pipeline wiring; out of scope for that PR). Either re-add the wording in the prompt builder or update the test to match the new output.
## Backlog
diff --git a/client/src/pages/Pipeline.jsx b/client/src/pages/Pipeline.jsx
index 878ee85578..db35d9e468 100644
--- a/client/src/pages/Pipeline.jsx
+++ b/client/src/pages/Pipeline.jsx
@@ -9,29 +9,75 @@
import { useEffect, useState } from 'react';
import { Link } from 'react-router-dom';
-import { Plus, Workflow as WorkflowIcon, Trash2, Loader2 } from 'lucide-react';
+import { Plus, Workflow as WorkflowIcon, Trash2, Loader2, Globe2 } from 'lucide-react';
import toast from '../components/ui/Toast';
import {
listPipelineSeries,
createPipelineSeries,
deletePipelineSeries,
PIPELINE_TARGET_FORMATS,
+ listWorlds,
+ WORLD_LOGLINE_MAX,
+ WORLD_PREMISE_MAX,
+ WORLD_STYLE_NOTES_MAX,
} from '../services/api';
+const emptyForm = () => ({
+ name: '',
+ worldId: '',
+ logline: '',
+ premise: '',
+ styleNotes: '',
+ targetFormat: 'comic+tv',
+});
+
export default function Pipeline() {
const [series, setSeries] = useState([]);
+ const [worlds, setWorlds] = useState([]);
const [loading, setLoading] = useState(true);
const [creating, setCreating] = useState(false);
const [showForm, setShowForm] = useState(false);
- const [form, setForm] = useState({ name: '', logline: '', targetFormat: 'comic+tv' });
+ const [form, setForm] = useState(emptyForm);
useEffect(() => {
- listPipelineSeries()
- .then((items) => setSeries(Array.isArray(items) ? items : []))
- .catch((err) => toast.error(err.message || 'Failed to load series'))
- .finally(() => setLoading(false));
+ Promise.all([
+ listPipelineSeries().catch(() => []),
+ // Worlds are optional — failing the fetch should still let the user
+ // create a series without one. Surface the error as a quiet toast.
+ listWorlds().catch((err) => {
+ toast.error(err.message || 'Failed to load worlds');
+ return [];
+ }),
+ ]).then(([s, w]) => {
+ setSeries(Array.isArray(s) ? s : []);
+ setWorlds(Array.isArray(w) ? w : []);
+ setLoading(false);
+ });
}, []);
+ // Pull logline/premise/styleNotes from the selected world. Only overwrites
+ // form fields that are currently empty so a user who's already typed a
+ // logline doesn't lose it when they pick a world afterwards.
+ const BIBLE_FIELDS = ['logline', 'premise', 'styleNotes'];
+ const handleWorldChange = (worldId) => {
+ if (!worldId) {
+ setForm((f) => ({ ...f, worldId: '' }));
+ return;
+ }
+ const w = worlds.find((x) => x.id === worldId);
+ if (!w) {
+ setForm((f) => ({ ...f, worldId }));
+ return;
+ }
+ setForm((f) => {
+ const next = { ...f, worldId };
+ for (const k of BIBLE_FIELDS) {
+ if (!f[k].trim()) next[k] = w[k] || '';
+ }
+ return next;
+ });
+ };
+
const handleCreate = async (e) => {
e?.preventDefault();
const name = form.name.trim();
@@ -43,6 +89,9 @@ export default function Pipeline() {
const created = await createPipelineSeries({
name,
logline: form.logline.trim(),
+ premise: form.premise.trim(),
+ styleNotes: form.styleNotes.trim(),
+ worldId: form.worldId || undefined,
targetFormat: form.targetFormat,
}).catch((err) => {
toast.error(err.message || 'Failed to create series');
@@ -52,7 +101,7 @@ export default function Pipeline() {
if (!created) return;
// Reactive insert — no full refetch (CLAUDE.md convention).
setSeries((prev) => [created, ...prev]);
- setForm({ name: '', logline: '', targetFormat: 'comic+tv' });
+ setForm(emptyForm());
setShowForm(false);
toast.success(`Created "${created.name}"`);
};
@@ -100,20 +149,45 @@ export default function Pipeline() {
{showForm && (
<form onSubmit={handleCreate} className="mb-6 p-4 bg-port-card border border-port-border rounded-lg space-y-3">
- <div>
- <label htmlFor="series-name" className="block text-xs uppercase tracking-wider text-gray-500 mb-1">
- Name
- </label>
- <input
- id="series-name"
- type="text"
- value={form.name}
- onChange={(e) => setForm((f) => ({ ...f, name: e.target.value }))}
- placeholder="Salt Run"
- className="w-full px-3 py-2 bg-port-bg border border-port-border rounded text-white"
- maxLength={200}
- autoFocus
- />
+ <div className="grid grid-cols-1 sm:grid-cols-[1fr_240px] gap-3">
+ <div>
+ <label htmlFor="series-name" className="block text-xs uppercase tracking-wider text-gray-500 mb-1">
+ Name
+ </label>
+ <input
+ id="series-name"
+ type="text"
+ value={form.name}
+ onChange={(e) => setForm((f) => ({ ...f, name: e.target.value }))}
+ placeholder="Salt Run"
+ className="w-full px-3 py-2 bg-port-bg border border-port-border rounded text-white"
+ maxLength={200}
+ autoFocus
+ />
+ </div>
+ <div>
+ <label htmlFor="series-world" className="block text-xs uppercase tracking-wider text-gray-500 mb-1">
+ <span className="inline-flex items-center gap-1"><Globe2 size={12} /> World (optional)</span>
+ </label>
+ <select
+ id="series-world"
+ value={form.worldId}
+ onChange={(e) => handleWorldChange(e.target.value)}
+ className="w-full px-3 py-2 bg-port-bg border border-port-border rounded text-white"
+ >
+ <option value="">— None —</option>
+ {worlds.map((w) => (
+ <option key={w.id} value={w.id}>{w.name}</option>
+ ))}
+ </select>
+ <p className="text-[11px] text-gray-500 mt-1">
+ {form.worldId
+ ? 'Logline / premise / style notes pulled from the world — edit below.'
+ : worlds.length === 0
+ ? 'No worlds yet. Build one in Media Gen → World Builder.'
+ : 'Pick a world to auto-fill the bible.'}
+ </p>
+ </div>
</div>
<div>
<label htmlFor="series-logline" className="block text-xs uppercase tracking-wider text-gray-500 mb-1">
@@ -126,9 +200,39 @@ export default function Pipeline() {
onChange={(e) => setForm((f) => ({ ...f, logline: e.target.value }))}
placeholder="A foundry city goes silent — and the only survivor is a child."
className="w-full px-3 py-2 bg-port-bg border border-port-border rounded text-white"
- maxLength={500}
+ maxLength={WORLD_LOGLINE_MAX}
/>
</div>
+ <div className="grid grid-cols-1 md:grid-cols-2 gap-3">
+ <div>
+ <label htmlFor="series-premise" className="block text-xs uppercase tracking-wider text-gray-500 mb-1">
+ Premise
+ </label>
+ <textarea
+ id="series-premise"
+ value={form.premise}
+ onChange={(e) => setForm((f) => ({ ...f, premise: e.target.value }))}
+ placeholder="Elevator pitch — setting, central conflict, stakes, tone."
+ className="w-full px-3 py-2 bg-port-bg border border-port-border rounded text-white text-sm"
+ rows={5}
+ maxLength={WORLD_PREMISE_MAX}
+ />
+ </div>
+ <div>
+ <label htmlFor="series-style-notes" className="block text-xs uppercase tracking-wider text-gray-500 mb-1">
+ Style notes
+ </label>
+ <textarea
+ id="series-style-notes"
+ value={form.styleNotes}
+ onChange={(e) => setForm((f) => ({ ...f, styleNotes: e.target.value }))}
+ placeholder="Visual / tonal references, mood, pacing, voice."
+ className="w-full px-3 py-2 bg-port-bg border border-port-border rounded text-white text-sm"
+ rows={5}
+ maxLength={WORLD_STYLE_NOTES_MAX}
+ />
+ </div>
+ </div>
<div>
<label htmlFor="series-format" className="block text-xs uppercase tracking-wider text-gray-500 mb-1">
Target format
diff --git a/client/src/pages/WorldBuilder.jsx b/client/src/pages/WorldBuilder.jsx
index fa9b850e77..e694d8e3be 100644
--- a/client/src/pages/WorldBuilder.jsx
+++ b/client/src/pages/WorldBuilder.jsx
@@ -17,7 +17,8 @@ import toast from '../components/ui/Toast';
import {
listWorlds, getWorld, createWorld, updateWorld, deleteWorld, expandWorld,
renderWorld, listWorldRuns, getProviders, WORLD_CATEGORIES,
- WORLD_CATEGORY_KEY_MAX, COMPOSITE_PROMPT_MAX, listImageModels, getSettings,
+ WORLD_CATEGORY_KEY_MAX, COMPOSITE_PROMPT_MAX, WORLD_LOGLINE_MAX,
+ WORLD_PREMISE_MAX, WORLD_STYLE_NOTES_MAX, listImageModels, getSettings,
} from '../services/api';
import BackendChipStrip from '../components/media/BackendChipStrip';
import ImageGenControls from '../components/imageGen/ImageGenControls';
@@ -89,6 +90,9 @@ const emptyTemplate = () => ({
starterPrompt: '',
stylePrompt: '',
negativePrompt: '',
+ logline: '',
+ premise: '',
+ styleNotes: '',
categories: ensureDraftCategories(),
compositeSheets: [],
llm: { provider: null, model: null },
@@ -181,6 +185,9 @@ export default function WorldBuilder() {
// by the LLM or added by the user.
categories: ensureDraftCategories(w.categories),
compositeSheets: w.compositeSheets || [],
+ logline: w.logline || '',
+ premise: w.premise || '',
+ styleNotes: w.styleNotes || '',
llm: w.llm || { provider: null, model: null },
});
}
@@ -206,6 +213,9 @@ export default function WorldBuilder() {
starterPrompt: draft.starterPrompt || '',
stylePrompt: draft.stylePrompt || '',
negativePrompt: draft.negativePrompt || '',
+ logline: draft.logline || '',
+ premise: draft.premise || '',
+ styleNotes: draft.styleNotes || '',
categories: draft.categories,
compositeSheets: draft.compositeSheets || [],
llm: draft.llm || {},
@@ -264,6 +274,12 @@ export default function WorldBuilder() {
...draft,
stylePrompt: result.stylePrompt || draft.stylePrompt,
negativePrompt: result.negativePrompt || draft.negativePrompt,
+ // Only overwrite the narrative bible fields when the LLM actually
+ // produced one — preserves any prose the user has already hand-edited
+ // when they re-run /expand to refresh just the image categories.
+ logline: result.logline || draft.logline,
+ premise: result.premise || draft.premise,
+ styleNotes: result.styleNotes || draft.styleNotes,
categories: ensureDraftCategories(result.categories),
compositeSheets: result.compositeSheets || draft.compositeSheets || [],
llm: result.llm || draft.llm,
@@ -283,6 +299,9 @@ export default function WorldBuilder() {
starterPrompt: expandedDraft.starterPrompt || '',
stylePrompt: expandedDraft.stylePrompt || '',
negativePrompt: expandedDraft.negativePrompt || '',
+ logline: expandedDraft.logline || '',
+ premise: expandedDraft.premise || '',
+ styleNotes: expandedDraft.styleNotes || '',
categories: expandedDraft.categories,
compositeSheets: expandedDraft.compositeSheets || [],
llm: expandedDraft.llm || {},
@@ -316,6 +335,9 @@ export default function WorldBuilder() {
starterPrompt: next.starterPrompt || '',
stylePrompt: next.stylePrompt || '',
negativePrompt: next.negativePrompt || '',
+ logline: next.logline || '',
+ premise: next.premise || '',
+ styleNotes: next.styleNotes || '',
categories: next.categories,
compositeSheets: next.compositeSheets || [],
llm: next.llm || {},
@@ -579,6 +601,53 @@ export default function WorldBuilder() {
defaultModel={draft.llm?.model || null}
/>
+ <section className="bg-port-card border border-port-border rounded p-4 flex flex-col gap-3">
+ <div>
+ <h2 className="text-sm font-semibold text-white">Story bible</h2>
+ <p className="text-xs text-gray-500 mt-0.5">
+ Pulled into the Pipeline → New Series form when this world is selected.
+ </p>
+ </div>
+ <div>
+ <label htmlFor="world-logline" className="text-xs text-gray-400 mb-1 block">Logline</label>
+ <input
+ id="world-logline"
+ type="text"
+ value={draft.logline || ''}
+ onChange={(e) => updateDraft({ logline: e.target.value })}
+ placeholder="One-sentence hook — A foundry city goes silent, and the only survivor is a child."
+ className="w-full bg-port-bg border border-port-border rounded px-3 py-2 text-white text-sm focus:outline-none focus:border-port-accent"
+ maxLength={WORLD_LOGLINE_MAX}
+ />
+ </div>
+ <div className="grid grid-cols-1 md:grid-cols-2 gap-3">
+ <div>
+ <label htmlFor="world-premise" className="text-xs text-gray-400 mb-1 block">Premise</label>
+ <textarea
+ id="world-premise"
+ value={draft.premise || ''}
+ onChange={(e) => updateDraft({ premise: e.target.value })}
+ placeholder="Elevator pitch — 1-3 short paragraphs about the setting, central conflict, stakes, and tone."
+ className="w-full bg-port-bg border border-port-border rounded px-3 py-2 text-white text-sm focus:outline-none focus:border-port-accent"
+ rows={6}
+ maxLength={WORLD_PREMISE_MAX}
+ />
+ </div>
+ <div>
+ <label htmlFor="world-style-notes" className="text-xs text-gray-400 mb-1 block">Style notes</label>
+ <textarea
+ id="world-style-notes"
+ value={draft.styleNotes || ''}
+ onChange={(e) => updateDraft({ styleNotes: e.target.value })}
+ placeholder="Narrative style: references (artists / films / comics), mood, palette, pacing, voice. Prose, not tokens."
+ className="w-full bg-port-bg border border-port-border rounded px-3 py-2 text-white text-sm focus:outline-none focus:border-port-accent"
+ rows={6}
+ maxLength={WORLD_STYLE_NOTES_MAX}
+ />
+ </div>
+ </div>
+ </section>
+
{/* Style template */}
<section className="bg-port-card border border-port-border rounded p-4 grid grid-cols-1 md:grid-cols-2 gap-3">
<div>
diff --git a/client/src/services/apiWorldBuilder.js b/client/src/services/apiWorldBuilder.js
index 47f809d089..d623c649d3 100644
--- a/client/src/services/apiWorldBuilder.js
+++ b/client/src/services/apiWorldBuilder.js
@@ -3,6 +3,11 @@ import { request } from './apiCore.js';
export const WORLD_CATEGORIES = ['landscapes', 'environments', 'characters', 'structures', 'vehicles'];
export const WORLD_CATEGORY_KEY_MAX = 64;
export const COMPOSITE_PROMPT_MAX = 4000;
+// Mirror of the bible-field caps in server/services/worldBuilder.js — used by
+// the World Builder + Pipeline forms for maxLength enforcement on inputs.
+export const WORLD_LOGLINE_MAX = 500;
+export const WORLD_PREMISE_MAX = 4000;
+export const WORLD_STYLE_NOTES_MAX = 4000;
export const listWorlds = () => request('/world-builder');
export const getWorld = (id) => request(`/world-builder/${encodeURIComponent(id)}`);
diff --git a/server/routes/worldBuilder.js b/server/routes/worldBuilder.js
index 63341fd339..c9b7352b09 100644
--- a/server/routes/worldBuilder.js
+++ b/server/routes/worldBuilder.js
@@ -67,6 +67,9 @@ const createSchema = z.object({
starterPrompt: z.string().trim().max(svc.STARTER_PROMPT_MAX).optional().default(''),
stylePrompt: z.string().trim().max(svc.PROMPT_FRAGMENT_MAX).optional().default(''),
negativePrompt: z.string().trim().max(svc.PROMPT_FRAGMENT_MAX).optional().default(''),
+ logline: z.string().trim().max(svc.LOGLINE_MAX).optional().default(''),
+ premise: z.string().trim().max(svc.PREMISE_MAX).optional().default(''),
+ styleNotes: z.string().trim().max(svc.STYLE_NOTES_MAX).optional().default(''),
categories: categoriesSchema.optional(),
compositeSheets: z.array(compositeSheetSchema).max(svc.COMPOSITE_SHEETS_MAX).optional(),
llm: llmSchema,
@@ -77,6 +80,9 @@ const patchSchema = z.object({
starterPrompt: z.string().trim().max(svc.STARTER_PROMPT_MAX).optional(),
stylePrompt: z.string().trim().max(svc.PROMPT_FRAGMENT_MAX).optional(),
negativePrompt: z.string().trim().max(svc.PROMPT_FRAGMENT_MAX).optional(),
+ logline: z.string().trim().max(svc.LOGLINE_MAX).optional(),
+ premise: z.string().trim().max(svc.PREMISE_MAX).optional(),
+ styleNotes: z.string().trim().max(svc.STYLE_NOTES_MAX).optional(),
categories: categoriesSchema.optional(),
compositeSheets: z.array(compositeSheetSchema).max(svc.COMPOSITE_SHEETS_MAX).optional(),
llm: llmSchema,
diff --git a/server/services/worldBuilder.js b/server/services/worldBuilder.js
index ee627c2ad7..9455ddb886 100644
--- a/server/services/worldBuilder.js
+++ b/server/services/worldBuilder.js
@@ -41,6 +41,11 @@ export const STARTER_PROMPT_MAX = 4000;
export const PROMPT_FRAGMENT_MAX = 2000;
export const COMPOSITE_PROMPT_MAX = 4000;
export const VARIATION_LABEL_MAX = 120;
+// Narrative bible fields — surfaced into the Pipeline "new series" form so a
+// world's logline/premise/style notes can seed a production series in one click.
+export const LOGLINE_MAX = 500;
+export const PREMISE_MAX = 4000;
+export const STYLE_NOTES_MAX = 4000;
export const VARIATIONS_PER_CATEGORY_MAX = 50;
export const COMPOSITE_SHEETS_MAX = 50;
export const COMPOSITE_SHEET_KINDS = Object.freeze([
@@ -168,6 +173,9 @@ const sanitizeTemplate = (raw) => {
const starterPrompt = trimTo(raw.starterPrompt, STARTER_PROMPT_MAX);
const stylePrompt = trimTo(raw.stylePrompt, PROMPT_FRAGMENT_MAX);
const negativePrompt = trimTo(raw.negativePrompt, PROMPT_FRAGMENT_MAX);
+ const logline = trimTo(raw.logline, LOGLINE_MAX);
+ const premise = trimTo(raw.premise, PREMISE_MAX);
+ const styleNotes = trimTo(raw.styleNotes, STYLE_NOTES_MAX);
const categories = sanitizeCategories(raw.categories || {});
const compositeSheets = sanitizeCompositeSheets(raw.compositeSheets || []);
const llm = raw.llm && typeof raw.llm === 'object'
@@ -184,6 +192,9 @@ const sanitizeTemplate = (raw) => {
starterPrompt,
stylePrompt,
negativePrompt,
+ logline,
+ premise,
+ styleNotes,
categories,
compositeSheets,
llm,
@@ -242,6 +253,9 @@ export async function createWorld(input = {}) {
starterPrompt: input.starterPrompt || '',
stylePrompt: input.stylePrompt || '',
negativePrompt: input.negativePrompt || '',
+ logline: input.logline || '',
+ premise: input.premise || '',
+ styleNotes: input.styleNotes || '',
categories: input.categories || {},
compositeSheets: input.compositeSheets || [],
llm: input.llm || {},
@@ -272,13 +286,20 @@ export async function updateWorld(id, patch = {}) {
? { ...(cur.llm || {}), ...(patch.llm || {}) }
: cur.llm;
+ // Scalar fields: only apply what the patch actually carries, so a partial
+ // PATCH never clobbers a field the caller didn't send. `categories` + `llm`
+ // are handled above (they need per-key merging, not replacement).
+ const PATCHABLE_SCALARS = [
+ 'name', 'starterPrompt', 'stylePrompt', 'negativePrompt',
+ 'logline', 'premise', 'styleNotes', 'compositeSheets',
+ ];
+ const scalarPatch = Object.fromEntries(
+ PATCHABLE_SCALARS.filter((k) => k in patch).map((k) => [k, patch[k]]),
+ );
+
const merged = sanitizeTemplate({
...cur,
- ...('name' in patch ? { name: patch.name } : {}),
- ...('starterPrompt' in patch ? { starterPrompt: patch.starterPrompt } : {}),
- ...('stylePrompt' in patch ? { stylePrompt: patch.stylePrompt } : {}),
- ...('negativePrompt' in patch ? { negativePrompt: patch.negativePrompt } : {}),
- ...('compositeSheets' in patch ? { compositeSheets: patch.compositeSheets } : {}),
+ ...scalarPatch,
categories: mergedCategories,
llm: mergedLlm,
updatedAt: new Date().toISOString(),
diff --git a/server/services/worldBuilder.test.js b/server/services/worldBuilder.test.js
index 12cc13cee5..15198e16b2 100644
--- a/server/services/worldBuilder.test.js
+++ b/server/services/worldBuilder.test.js
@@ -98,6 +98,43 @@ describe('worldBuilder service', () => {
await expect(svc.createWorld({ name: '' })).rejects.toThrow(/name is required/);
});
+ it('createWorld persists narrative bible fields (logline / premise / styleNotes)', async () => {
+ const w = await seedWorld({
+ logline: 'A foundry city goes silent, and the only survivor is a child.',
+ premise: 'Long-form premise paragraph about the setting, conflict, stakes, and tone.',
+ styleNotes: 'Moebius linework, oil-on-canvas grain, contemplative pacing, sparse dialogue.',
+ });
+ expect(w.logline).toBe('A foundry city goes silent, and the only survivor is a child.');
+ expect(w.premise).toBe('Long-form premise paragraph about the setting, conflict, stakes, and tone.');
+ expect(w.styleNotes).toBe('Moebius linework, oil-on-canvas grain, contemplative pacing, sparse dialogue.');
+ });
+
+ it('updateWorld patches narrative bible fields independently of categories', async () => {
+ const w = await seedWorld({ logline: 'original logline' });
+ const patched = await svc.updateWorld(w.id, {
+ logline: 'new logline',
+ premise: 'new premise',
+ styleNotes: 'new style notes',
+ });
+ expect(patched.logline).toBe('new logline');
+ expect(patched.premise).toBe('new premise');
+ expect(patched.styleNotes).toBe('new style notes');
+ // Untouched (existing) data preserved.
+ expect(patched.categories.landscapes.variations).toHaveLength(2);
+ expect(patched.stylePrompt).toBe(w.stylePrompt);
+ });
+
+ it('createWorld trims bible fields to their max length', async () => {
+ const w = await seedWorld({
+ logline: 'x'.repeat(svc.LOGLINE_MAX + 50),
+ premise: 'y'.repeat(svc.PREMISE_MAX + 50),
+ styleNotes: 'z'.repeat(svc.STYLE_NOTES_MAX + 50),
+ });
+ expect(w.logline).toHaveLength(svc.LOGLINE_MAX);
+ expect(w.premise).toHaveLength(svc.PREMISE_MAX);
+ expect(w.styleNotes).toHaveLength(svc.STYLE_NOTES_MAX);
+ });
+
it('updateWorld merges partial patches', async () => {
const w = await seedWorld();
const patched = await svc.updateWorld(w.id, { name: 'Renamed', stylePrompt: 'new style' });
diff --git a/server/services/worldBuilderExpand.js b/server/services/worldBuilderExpand.js
index b55d88f60f..f394792ead 100644
--- a/server/services/worldBuilderExpand.js
+++ b/server/services/worldBuilderExpand.js
@@ -17,6 +17,9 @@ import {
PROMPT_FRAGMENT_MAX,
COMPOSITE_PROMPT_MAX,
VARIATIONS_PER_CATEGORY_MAX,
+ LOGLINE_MAX,
+ PREMISE_MAX,
+ STYLE_NOTES_MAX,
sanitizeCategories,
sanitizeCompositeSheets,
} from './worldBuilder.js';
@@ -26,7 +29,7 @@ import { providerHonorsModelOverride, runPromptThroughProvider } from '../lib/pr
const LABEL_MAX = 80;
-const EXPANSION_PROMPT = `You are a world-building prompt engineer for a Stable-Diffusion-style image generation pipeline. You will turn the user's starter idea into a structured prompt set that produces a visually consistent universe across many renders.
+const EXPANSION_PROMPT = `You are a world-building prompt engineer for a Stable-Diffusion-style image generation pipeline AND a story-bible drafter for a comic/TV production pipeline. You will turn the user's starter idea into (a) a structured prompt set that produces a visually consistent universe across many renders, and (b) a short narrative bible that downstream writing stages can ingest.
# Starter idea
{starterPrompt}
@@ -34,6 +37,9 @@ const EXPANSION_PROMPT = `You are a world-building prompt engineer for a Stable-
# Output contract
Return a SINGLE JSON object. NO markdown, NO commentary. The object MUST have these top-level keys:
+- logline: string. ONE sentence (≤500 chars) capturing the world's central tension/hook — protagonist-agnostic if no protagonist is implied. Example: "A foundry city goes silent — and the only survivor is a child."
+- premise: string. 1-3 short paragraphs (≤4000 chars total) describing the setting, the central conflict or situation, the stakes, and the tone. Write it as the elevator pitch a showrunner would hand to a writers' room. No bullet points; prose only.
+- styleNotes: string. A prose paragraph (≤4000 chars) describing the visual + tonal style for the story bible — references (artists, films, comics, games), mood, palette, pacing, narrative voice. This is read by writers + creative directors, not the image model, so use full sentences instead of comma-separated tokens.
- stylePrompt: string. A single comma-separated style fragment (lighting, color palette, render quality, artist references) that will be PREFIXED to every variation prompt. Keep under 400 characters. No subject nouns — those go in variations.
- negativePrompt: string. Comma-separated tokens to avoid (e.g. "blurry, lowres, watermark, extra fingers"). Tailor to the world's aesthetic.
- categories: object. Atomic reusable buckets. Use snake_case keys. Start from these common buckets when useful:
@@ -77,6 +83,9 @@ Concrete compositeSheets examples:
const isExpansionShape = (o) => o && typeof o === 'object'
&& (typeof o.stylePrompt === 'string'
|| typeof o.negativePrompt === 'string'
+ || typeof o.logline === 'string'
+ || typeof o.premise === 'string'
+ || typeof o.styleNotes === 'string'
|| (o.categories && typeof o.categories === 'object')
|| Array.isArray(o.compositeSheets));
@@ -186,20 +195,25 @@ export async function expandWorldTemplate({ starterPrompt, providerId, model } =
const parsed = extractJson(raw);
console.log(`🌍 World Builder parsed JSON — keys=[${Object.keys(parsed || {}).join(',')}] categoryKeys=[${Object.keys(parsed?.categories || {}).join(',')}] compositeSheets=${Array.isArray(parsed?.compositeSheets) ? parsed.compositeSheets.length : 0}`);
- const stylePrompt = typeof parsed.stylePrompt === 'string'
- ? parsed.stylePrompt.trim().slice(0, PROMPT_FRAGMENT_MAX) : '';
- const negativePrompt = typeof parsed.negativePrompt === 'string'
- ? parsed.negativePrompt.trim().slice(0, PROMPT_FRAGMENT_MAX) : '';
+ const trimField = (value, max) => (typeof value === 'string' ? value.trim().slice(0, max) : '');
+ const stylePrompt = trimField(parsed.stylePrompt, PROMPT_FRAGMENT_MAX);
+ const negativePrompt = trimField(parsed.negativePrompt, PROMPT_FRAGMENT_MAX);
+ const logline = trimField(parsed.logline, LOGLINE_MAX);
+ const premise = trimField(parsed.premise, PREMISE_MAX);
+ const styleNotes = trimField(parsed.styleNotes, STYLE_NOTES_MAX);
const categories = normalizeCategories(parsed.categories || {});
const compositeSheets = normalizeCompositeSheets(parsed.compositeSheets || []);
const perCat = Object.keys(categories).map((k) => `${k}=${categories[k]?.variations?.length || 0}`).join(' ');
const totalVariations = Object.values(categories).reduce((n, c) => n + (c?.variations?.length || 0), 0);
- console.log(`🌍 World Builder expansion complete — runId=${runId} ${totalVariations} variations, ${compositeSheets.length} composite sheets (${perCat})`);
+ console.log(`🌍 World Builder expansion complete — runId=${runId} ${totalVariations} variations, ${compositeSheets.length} composite sheets, bible=${logline ? 'yes' : 'no'} (${perCat})`);
if (totalVariations === 0 && compositeSheets.length === 0) {
console.warn(`⚠️ World Builder expansion produced 0 variations — inspect data/runs/${runId}/output.txt for the raw LLM response`);
}
return {
+ logline,
+ premise,
+ styleNotes,
stylePrompt,
negativePrompt,
categories,
diff --git a/server/services/worldBuilderExpand.test.js b/server/services/worldBuilderExpand.test.js
index 682ba70677..642de63df9 100644
--- a/server/services/worldBuilderExpand.test.js
+++ b/server/services/worldBuilderExpand.test.js
@@ -239,4 +239,13 @@ describe('worldBuilderExpand.EXPANSION_PROMPT', () => {
expect(EXPANSION_PROMPT).toContain('world summary concept pitch poster');
expect(EXPANSION_PROMPT).toContain('materials swatches');
});
+
+ it('asks the LLM to emit a narrative bible (logline / premise / styleNotes)', () => {
+ // The pipeline pulls these straight into the New Series form, so the
+ // contract has to stay in the prompt. If this assertion fails, double-
+ // check that worldBuilderExpand.js still hydrates the three fields too.
+ expect(EXPANSION_PROMPT).toContain('logline:');
+ expect(EXPANSION_PROMPT).toContain('premise:');
+ expect(EXPANSION_PROMPT).toContain('styleNotes:');
+ });
});