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): keep the style clause leading the render prompt

[._.]/ Adam Eivyfbf2fe34f9d4
diff --git a/server/lib/README.md b/server/lib/README.md
index 2705ee7b2d..fdf8692e26 100644
--- a/server/lib/README.md
+++ b/server/lib/README.md
@@ -127,7 +127,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub
| `universeBibleCompleteness.js` | Is a universe bible entry actually described? The shared per-kind expand-field vocabulary (`BIBLE_EXPAND_FIELDS`, `BIBLE_CORE_FIELDS`) and the `core`/`full` completeness predicates the quota-burn describe job scans with. Pure. |
| `universeMarkdown.js` | Pure deterministic Universe Builder world-bible export: `universeToMarkdown(record)` plus safe Markdown download filename helpers. |
| `universePromptRenderers.js` | Renderers that turn a universe's `categories` map + canon into prompt context. |
-| `universeVisualStyle.js` | The style a universe contributes to an IMAGE prompt: `buildVisualStyleClause(universe, {override, mode})` (curated `influences.embrace` tokens + a series `stylePromptOverride`, NEVER the free-text `styleNotes`, which is writing-stage direction), `universeAestheticLine` (the labeled variant canon sheet/LoRA renders lead with), `universeVisualStyleTokens`, `splitPromptTokens`, `dropTokensPresentIn` (drop style the browser already composed into the authored prompt) and `mergeNegativePromptTokens` (token-level union of comma-joined negatives). |
+| `universeVisualStyle.js` | The style a universe contributes to an IMAGE prompt: `buildVisualStyleClause(universe, {override, mode})` (curated `influences.embrace` tokens + a series `stylePromptOverride`, NEVER the free-text `styleNotes`, which is writing-stage direction), `universeAestheticLine` (the labeled variant canon sheet/LoRA renders lead with), `universeVisualStyleTokens`, `splitPromptTokens`, `stripStyleClause(text, clause)` (removes the copy the browser already prefixed, so the compiler keeps the LEADING one — matched on the joined clause so a token with its own punctuation like `M.C. Escher` still matches) and `mergeNegativePromptTokens` (token-level union of comma-joined negatives). |
| `writersRoomPresets.js` | Writers Room enums (WORK_KINDS, WORK_STATUSES, ANALYSIS_KINDS). |
| `writersRoomStylePresets.js` | Curated style presets for storyboards + universe. |
diff --git a/server/lib/universeVisualStyle.js b/server/lib/universeVisualStyle.js
index 604c9aaf10..8d13ab5821 100644
--- a/server/lib/universeVisualStyle.js
+++ b/server/lib/universeVisualStyle.js
@@ -27,21 +27,12 @@ const tokenList = (values) => (Array.isArray(values) ? values : [])
.map((token) => (typeof token === 'string' ? token.trim() : ''))
.filter(Boolean);
-// Trailing trim is load-bearing: the dedupe below splits a composed prompt on
-// its separators, so every part after the first arrives with a leading space.
const normalize = (token) => token.toLowerCase().replace(/\s+/g, ' ').trim();
/** Split a comma-joined prompt/negative string back into trimmed tokens. */
export const splitPromptTokens = (text) => (typeof text === 'string' ? text : '')
.split(',').map((token) => token.trim()).filter(Boolean);
-// Every separator a composed prompt can put between two style tokens: the
-// comma inside a joined token list, and the '. ' / newline that
-// `composeStyledPrompt` and the compiler use to butt the style clause against
-// the scene sentence. Splitting on all of them is what lets the dedupe below
-// compare whole tokens instead of substrings.
-const PROMPT_TOKEN_SEPARATORS = /[,.;\n]+/;
-
/** Curated visual token lists for a universe (`[]` for a missing universe). */
export function universeVisualStyleTokens(universe) {
return {
@@ -67,24 +58,30 @@ export function buildVisualStyleClause(universe, { override = '', mode = 'prepen
return parts.filter(Boolean).join('. ');
}
+const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
+
/**
- * Drop style tokens the authored prompt already carries.
+ * Remove a style clause the authored prompt already leads with.
*
* The browser composes the same universe preset onto a scene prompt before
- * POSTing it, and the server-side compiler then prepends the canonical style
- * clause. Without a token-level pass the entire embrace list lands twice in
- * every render prompt (and the avoid list twice in every negative), which is
- * pure budget with no effect on the image.
+ * POSTing it (`composeStyledPrompt`), and the compiler prepends the canonical
+ * clause too — so without this the whole token list lands twice in every
+ * render. Strip the browser's copy rather than the compiler's: diffusion models
+ * weight earlier tokens heaviest, and only the compiler's copy sits in front of
+ * the canon context where that conditioning is worth anything.
+ *
+ * Matching is on the JOINED clause, not token by token, which is what keeps a
+ * token carrying its own punctuation (`M.C. Escher`) intact — a per-token
+ * split on '.' would never match it and would emit it a second time.
*/
-export function dropTokensPresentIn(tokens, authoredText) {
- const text = typeof authoredText === 'string' ? authoredText : '';
- if (!text.trim()) return tokenList(tokens);
- // Compare WHOLE tokens, never substrings: a plain `includes` would drop
- // `flat colors` because the scene sentence happens to say "flat colors of
- // dusk", silently stripping a style token the render still needed.
- const present = new Set(text.split(PROMPT_TOKEN_SEPARATORS)
- .map((part) => normalize(part)).filter(Boolean));
- return tokenList(tokens).filter((token) => !present.has(normalize(token)));
+export function stripStyleClause(text, clause) {
+ const source = typeof text === 'string' ? text : '';
+ const trimmed = typeof clause === 'string' ? clause.trim() : '';
+ if (!trimmed || !source) return source;
+ // Whitespace in the composed prompt need not match the stored token spacing,
+ // and the clause is followed by the separator composeStyledPrompt inserted.
+ const pattern = new RegExp(`^\\s*${escapeRegExp(trimmed).replace(/\s+/g, '\\s+')}\\s*[.,;]?\\s*`, 'i');
+ return source.replace(pattern, '').trim();
}
/**
diff --git a/server/lib/universeVisualStyle.test.js b/server/lib/universeVisualStyle.test.js
index c0b563c7b0..d093964677 100644
--- a/server/lib/universeVisualStyle.test.js
+++ b/server/lib/universeVisualStyle.test.js
@@ -1,8 +1,8 @@
import { describe, expect, it } from 'vitest';
import {
buildVisualStyleClause,
- dropTokensPresentIn,
mergeNegativePromptTokens,
+ stripStyleClause,
universeAestheticLine,
universeVisualStyleTokens,
} from './universeVisualStyle.js';
@@ -36,22 +36,27 @@ describe('universeVisualStyle', () => {
expect(buildVisualStyleClause(universe, { ...override, mode: 'override' })).toBe('washed sepia');
});
- it('drops style tokens the authored prompt already carries', () => {
+ it('strips the style clause the browser already prefixed, leaving the scene', () => {
const authored = 'Ligne Claire, flat matte color fields. Tala kneels in silver grass.';
- expect(dropTokensPresentIn(universeVisualStyleTokens(universe).embrace, authored)).toEqual([]);
- expect(dropTokensPresentIn(['ligne claire', 'screenprint grain'], authored)).toEqual(['screenprint grain']);
- expect(dropTokensPresentIn(['ligne claire'], '')).toEqual(['ligne claire']);
+ expect(stripStyleClause(authored, 'ligne claire, flat matte color fields'))
+ .toBe('Tala kneels in silver grass.');
});
- it('matches whole tokens, so scene prose that merely contains one keeps it', () => {
- // A substring test would drop 'flat colors' here and quietly weaken the render.
- const prose = 'Tala watches the flat colors of dusk bleed over the ridge.';
- expect(dropTokensPresentIn(['flat colors', 'ligne claire'], prose))
- .toEqual(['flat colors', 'ligne claire']);
- // A token the composed prompt genuinely carries is still dropped, whether the
- // separator before it is a comma or the '. ' that butts style against scene.
- expect(dropTokensPresentIn(['flat colors'], 'ligne claire, flat colors. Tala kneels.'))
- .toEqual([]);
+ it('leaves a prompt that never carried the clause untouched', () => {
+ expect(stripStyleClause('A cautious arrival', 'ligne claire')).toBe('A cautious arrival');
+ expect(stripStyleClause('A cautious arrival', '')).toBe('A cautious arrival');
+ // Only a LEADING copy is the browser's duplicate; style words occurring in
+ // the scene sentence itself are the author's and must survive.
+ expect(stripStyleClause('Dusk in flat matte color fields', 'flat matte color fields'))
+ .toBe('Dusk in flat matte color fields');
+ });
+
+ it('matches a token carrying its own punctuation instead of emitting it twice', () => {
+ // A per-token split on '.' would never match `M.C. Escher`, so the compiler
+ // would prepend the whole clause again on top of the browser's copy.
+ const clause = 'ligne claire, M.C. Escher';
+ expect(stripStyleClause(`${clause}. Stairs fold back on themselves.`, clause))
+ .toBe('Stairs fold back on themselves.');
});
it('unions negatives at token level so a joined authored negative does not repeat the list', () => {
diff --git a/server/services/fableLoom/visualConditioning.js b/server/services/fableLoom/visualConditioning.js
index ad69e36f51..83cb5cee67 100644
--- a/server/services/fableLoom/visualConditioning.js
+++ b/server/services/fableLoom/visualConditioning.js
@@ -17,7 +17,7 @@ import {
} from '../../lib/scenePrompt.js';
import { resolveFableLoomProtagonistPresence } from '../../lib/fableLoomPlayback.js';
import {
- dropTokensPresentIn, mergeNegativePromptTokens, universeVisualStyleTokens,
+ mergeNegativePromptTokens, stripStyleClause, universeVisualStyleTokens,
} from '../../lib/universeVisualStyle.js';
import { getUniverse } from '../universeBuilder.js';
import { resolveCharacterLoras } from '../characterLoraResolver.js';
@@ -350,20 +350,19 @@ export async function compileFableLoomVisualRequest({
]).join('. '));
// Curated visual tokens only — `universe.styleNotes` is writing-stage
// direction (see lib/universeVisualStyle.js). The browser composes this same
- // preset onto the scene prompt before POSTing, so drop whatever it already
- // sent rather than emitting the token list a second time.
- const universeStyle = dropTokensPresentIn(
- universeVisualStyleTokens(universe).embrace,
- authoredPrompt,
- );
+ // preset onto the scene prompt before POSTing, so strip ITS copy and keep
+ // ours: the clause below leads the prompt, and only a leading copy gets the
+ // early-token weighting a diffusion model gives style.
+ const universeStyle = universeVisualStyleTokens(universe).embrace.join(', ');
+ const authoredBody = stripStyleClause(authoredPrompt, universeStyle);
const protagonistFraming = bindings.protagonistPresence === 'offscreen'
? 'Framing constraint: the canonical protagonist is speaking through the communicator off-screen. The camera is the remote witness: show the obstacle or environment the protagonist cannot see around a corner, beyond a bend, at a distance, or otherwise outside their sightline. The communicator stays on the protagonist\'s person and completely out of frame; never use a standalone comms device as the subject. Do not show their face, body, silhouette, or duplicate presence in this storyboard image.'
: '';
const positive = compact([
- universeStyle.length && `Universe style: ${universeStyle.join(', ')}`,
+ universeStyle && `Universe style: ${universeStyle}`,
placePrompt, ...characterPrompts, ...objectPrompts,
protagonistFraming,
- authoredPrompt || (kind === 'video' ? node.videoPrompt || node.prose : node.imagePrompt),
+ authoredBody || (kind === 'video' ? node.videoPrompt || node.prose : node.imagePrompt),
node.visualCanon?.shotNotes && `Shot continuity: ${node.visualCanon.shotNotes}`,
]).join('\n\n').slice(0, 8000);
const identityAvoid = bindings.boundCharacters.flatMap(({ character }) => character.identityPack?.avoid || []);
diff --git a/server/services/fableLoom/visualConditioning.test.js b/server/services/fableLoom/visualConditioning.test.js
index ebb9248556..0669bd6b03 100644
--- a/server/services/fableLoom/visualConditioning.test.js
+++ b/server/services/fableLoom/visualConditioning.test.js
@@ -113,8 +113,13 @@ describe('FableLoom visual conditioning compiler', () => {
expect(result.prompt).not.toContain('Aruun');
expect(result.prompt).not.toContain('PG-13');
- expect(result.prompt).not.toContain('Universe style:');
+ // The tokens appear exactly once, and in FRONT of the canon context — a
+ // diffusion model weights early tokens heaviest, so a surviving copy
+ // stranded after the place/character blocks is not equivalent.
expect(result.prompt.match(/ligne claire/g)).toHaveLength(1);
+ expect(result.prompt.startsWith('Universe style: ligne claire, flat matte color fields')).toBe(true);
+ expect(result.prompt.indexOf('Universe style:')).toBeLessThan(result.prompt.indexOf('Environment:'));
+ expect(result.prompt).toContain('A cautious arrival');
expect(result.negativePrompt.match(/photoreal/g)).toHaveLength(1);
expect(result.negativePrompt.match(/gore/g)).toHaveLength(1);
});