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
feat([scene-level-wardrobe-picking-per-scene]): per-scene wardrobe picker for storyboard renders
[._.]/ Adam Eivy78cd92fb7b63
diff --git a/client/src/components/pipeline/stages/StoryboardsStage.jsx b/client/src/components/pipeline/stages/StoryboardsStage.jsxindex b536024095..e4e062c398 100644--- a/client/src/components/pipeline/stages/StoryboardsStage.jsx+++ b/client/src/components/pipeline/stages/StoryboardsStage.jsx@@ -17,7 +17,7 @@*/import { useEffect, useRef, useState } from 'react';-import { Plus, Trash2, Sparkles, Loader2, Wand2, Film, WandSparkles } from 'lucide-react';+import { Plus, Trash2, Sparkles, Loader2, Wand2, Film, WandSparkles, Shirt } from 'lucide-react';import toast from '../../ui/Toast';import {generatePipelineVisualImage,@@ -26,7 +26,10 @@ import {refinePipelineSceneImagePrompt,updatePipelineIssue,extractPipelineStoryboardScenes,+ getUniverse,} from '../../../services/api';+import useMounted from '../../../hooks/useMounted';+import { matchCharactersInText } from '../../../lib/scenePrompt';import MediaJobThumb from '../MediaJobThumb';import { genConfigToImageOptions, genConfigToRefineOptions } from './VisualGenSettings';@@ -51,6 +54,22 @@ export default function StoryboardsStage({ issue, series, onStageUpdate, actionsif (armTimerRef.current) clearTimeout(armTimerRef.current);}, []);+ // Canon characters (with wardrobes) live on the linked universe — load them+ // once so each scene can offer a per-character wardrobe picker. Only+ // characters that own at least one wardrobe are pickable.+ const mountedRef = useMounted();+ const [wardrobeChars, setWardrobeChars] = useState([]);+ useEffect(() => {+ if (!series?.universeId) { setWardrobeChars([]); return undefined; }+ let cancelled = false;+ getUniverse(series.universeId).then((w) => {+ if (cancelled || !mountedRef.current) return;+ const chars = Array.isArray(w?.characters) ? w.characters : [];+ setWardrobeChars(chars.filter((c) => Array.isArray(c?.wardrobes) && c.wardrobes.length > 0));+ }).catch(() => { if (mountedRef.current) setWardrobeChars([]); });+ return () => { cancelled = true; };+ }, [series?.universeId, mountedRef]);+const teleplayReady = !!(issue.stages?.teleplay?.output || '').trim();const proseReady = !!(issue.stages?.prose?.output || '').trim();// Any non-null, non-arm value means an extract POST is in flight — both@@ -76,6 +95,10 @@ export default function StoryboardsStage({ issue, series, onStageUpdate, actionssetScenes(next);};+ // Wardrobe picks are discrete selections (no blur), so persist immediately.+ const setSceneAppearances = (i, nextAppearances) =>+ persist(scenes.map((s, j) => j === i ? { ...s, characterAppearances: nextAppearances } : s));+// Shot id stable enough for React keys + filename-hook correlation. Local// generation (vs server-assigned) is fine — every later persist round-trips// through the server which keeps whatever id the client wrote.@@ -186,6 +209,10 @@ export default function StoryboardsStage({ issue, series, onStageUpdate, actionsconst result = await generatePipelineVisualImage(issue.id, 'storyboards', {description: scene.description,slugline: scene.slugline || '',+ // The generic visual route has no scene index, so the scene's wardrobe+ // picks ride along in the request body (video/shot paths read them+ // server-side from the persisted scene).+ characterAppearances: scene.characterAppearances,...genConfigToImageOptions(genConfig),}).catch((err) => {toast.error(err.message || 'Failed to enqueue image');@@ -374,6 +401,13 @@ export default function StoryboardsStage({ issue, series, onStageUpdate, actions) : null}</div></div>+ {wardrobeChars.length > 0 ? (+ <WardrobePicker+ characters={wardrobeChars}+ scene={scene}+ onChange={(next) => setSceneAppearances(i, next)}+ />+ ) : null}<ShotListsceneIdx={i}shots={Array.isArray(scene.shots) ? scene.shots : []}@@ -469,3 +503,61 @@ function ShotList({</div>);}++// Per-scene wardrobe picker. Mirrors the server's character matching — a+// wardrobe only takes effect for characters whose name/alias appears in the+// scene description (+slugline), which is exactly the set the prompt builder+// features — so we only offer a dropdown for those. The user picks each+// outfit explicitly (no extractor guess); selecting "default" clears the pick.+function WardrobePicker({ characters, scene, onChange }) {+ const [open, setOpen] = useState(false);+ const matched = matchCharactersInText(+ `${scene.description || ''} ${scene.slugline || ''}`,+ characters,+ );+ const appearances = Array.isArray(scene.characterAppearances) ? scene.characterAppearances : [];+ const wardrobeFor = (charId) =>+ appearances.find((a) => a && a.characterId === charId)?.wardrobeId || '';+ const pickCount = matched.filter((c) => wardrobeFor(c.id)).length;++ const setWardrobe = (charId, wardrobeId) => {+ const rest = appearances.filter((a) => a && a.characterId !== charId);+ onChange(wardrobeId ? [...rest, { characterId: charId, wardrobeId }] : rest);+ };++ if (matched.length === 0) return null;++ return (+ <div className="mt-3 pt-3 border-t border-port-border/60">+ <button+ type="button"+ onClick={() => setOpen((v) => !v)}+ className="inline-flex items-center gap-1.5 text-[10px] uppercase tracking-wider text-gray-500 hover:text-gray-300"+ >+ <Shirt size={12} />+ Wardrobe{pickCount > 0 ? ` (${pickCount})` : ''}+ <span className="text-gray-600">{open ? '▾' : '▸'}</span>+ </button>+ {open ? (+ <ul className="mt-2 space-y-1.5">+ {matched.map((char) => (+ <li key={char.id} className="flex items-center gap-2">+ <span className="text-xs text-gray-300 w-28 shrink-0 truncate" title={char.name}>{char.name}</span>+ <select+ value={wardrobeFor(char.id)}+ onChange={(e) => setWardrobe(char.id, e.target.value)}+ aria-label={`Wardrobe for ${char.name}`}+ className="flex-1 px-2 py-1 bg-port-bg border border-port-border rounded text-white text-xs"+ >+ <option value="">— default outfit —</option>+ {char.wardrobes.map((w) => (+ <option key={w.id} value={w.id}>{w.name || 'Unnamed outfit'}</option>+ ))}+ </select>+ </li>+ ))}+ </ul>+ ) : null}+ </div>+ );+}diff --git a/client/src/lib/scenePrompt.js b/client/src/lib/scenePrompt.jsindex c33c7e87d6..5869335817 100644--- a/client/src/lib/scenePrompt.js+++ b/client/src/lib/scenePrompt.js@@ -86,6 +86,16 @@ export function matchObjectsInText(text, allObjects) {return matchEntriesByCandidates(text, allObjects, (o) => [o.name, ...(o.aliases || [])]);}+// Append a user-selected wardrobe description AFTER physicalDescription+// without clobbering it — mirror of server/lib/scenePrompt.js#appendWardrobe.+function appendWardrobe(base, wardrobeDesc) {+ if (!wardrobeDesc) return base;+ const wearing = `Wearing: ${wardrobeDesc}`;+ if (!base) return wearing;+ const sep = /[.!?]$/.test(base) ? ' ' : '. ';+ return `${base}${sep}${wearing}`;+}+export function buildScenePrompt(workTitle, scene, matchedCharacters, worldStyle = '', matchedPlace = null) {const stylePart = worldStyle && worldStyle.trim() ? `${worldStyle.trim()}. ` : '';const titlePart = workTitle ? `${workTitle}. ` : '';@@ -108,11 +118,26 @@ export function buildScenePrompt(workTitle, scene, matchedCharacters, worldStyle...baselineFrags,].filter(Boolean) : [];+ // Per-scene wardrobe picks: `scene.characterAppearances` is+ // [{ characterId, wardrobeId? }]. Mirror of server/lib/scenePrompt.js.+ const appearanceByCharId = new Map(+ (Array.isArray(scene?.characterAppearances) ? scene.characterAppearances : [])+ .filter((a) => a && a.characterId)+ .map((a) => [a.characterId, a]),+ );+// Accept either `physicalDescription` (writers-room shape) or// `description` (pipeline shape) — the composer doesn't care which// field carries the visual descriptor.const featuringFragments = (matchedCharacters || [])- .map((c) => ({ name: c.name, desc: (c.physicalDescription || c.description || '').trim() }))+ .map((c) => {+ const base = (c.physicalDescription || c.description || '').trim();+ const appearance = appearanceByCharId.get(c.id);+ const wardrobe = appearance?.wardrobeId+ ? (c.wardrobes || []).find((w) => w && w.id === appearance.wardrobeId)+ : null;+ return { name: c.name, desc: appendWardrobe(base, (wardrobe?.description || '').trim()) };+ }).filter((c) => c.desc).map((c) => `${c.name}: ${c.desc}`);diff --git a/server/lib/scenePrompt.js b/server/lib/scenePrompt.jsindex 9b37c20a51..d29599e02b 100644--- a/server/lib/scenePrompt.js+++ b/server/lib/scenePrompt.js@@ -107,6 +107,20 @@ export function matchObjectsInText(text, allObjects) {return matchEntriesByCandidates(text, allObjects, (o) => [o.name, ...(o.aliases || [])]);}+// Append a user-selected wardrobe description AFTER the character's physical+// description without clobbering it — wardrobe is a deliberate per-scene+// overlay, never a substitute for the canonical body fields. The "Wearing: …"+// label matches the existing "Palette: …" / "Era: …" fragment vocabulary, and+// the sentence separator keeps the two clauses from running together once the+// budget-truncation join collapses fragments with a single space.+function appendWardrobe(base, wardrobeDesc) {+ if (!wardrobeDesc) return base;+ const wearing = `Wearing: ${wardrobeDesc}`;+ if (!base) return wearing;+ const sep = /[.!?]$/.test(base) ? ' ' : '. ';+ return `${base}${sep}${wearing}`;+}+/*** Compose the final image-gen prompt with priority order (diffusion models* weight earlier tokens heaviest):@@ -158,11 +172,29 @@ export function buildScenePrompt(workTitle, scene, matchedCharacters, worldStyle...baselineFrags,].filter(Boolean) : [];+ // Per-scene wardrobe picks: `scene.characterAppearances` is+ // [{ characterId, wardrobeId? }]. When a matched character has a selected+ // wardrobe, its description is appended after physicalDescription. The user+ // picks these explicitly (no extractor guess); an absent or empty list+ // leaves every character on their canonical body description.+ const appearanceByCharId = new Map(+ (Array.isArray(scene?.characterAppearances) ? scene.characterAppearances : [])+ .filter((a) => a && a.characterId)+ .map((a) => [a.characterId, a]),+ );+// Accept either `physicalDescription` (writers-room shape) or// `description` (pipeline shape) — the composer doesn't care which// field carries the visual descriptor.const featuringFragments = (matchedCharacters || [])- .map((c) => ({ name: c.name, desc: (c.physicalDescription || c.description || '').trim() }))+ .map((c) => {+ const base = (c.physicalDescription || c.description || '').trim();+ const appearance = appearanceByCharId.get(c.id);+ const wardrobe = appearance?.wardrobeId+ ? (c.wardrobes || []).find((w) => w && w.id === appearance.wardrobeId)+ : null;+ return { name: c.name, desc: appendWardrobe(base, (wardrobe?.description || '').trim()) };+ }).filter((c) => c.desc).map((c) => `${c.name}: ${c.desc}`);diff --git a/server/lib/scenePrompt.test.js b/server/lib/scenePrompt.test.jsindex 0d6bb7c994..f05b4d1076 100644--- a/server/lib/scenePrompt.test.js+++ b/server/lib/scenePrompt.test.js@@ -253,3 +253,57 @@ describe('scenePrompt — buildScenePrompt', () => {expect(buildScenePrompt('', {}, [], '', null)).toBe('');});});++describe('scenePrompt — buildScenePrompt wardrobe appearances', () => {+ const baseScene = { visualPrompt: 'wide shot' };+ const aria = {+ id: 'c1',+ name: 'Aria',+ physicalDescription: 'tall, dark hair',+ wardrobes: [+ { id: 'wd-1', name: 'Field gear', description: 'mud-caked tactical jacket and boots' },+ { id: 'wd-2', name: 'Gala', description: 'emerald silk gown' },+ ],+ };++ it('appends the selected wardrobe after physicalDescription without replacing it', () => {+ const scene = { ...baseScene, characterAppearances: [{ characterId: 'c1', wardrobeId: 'wd-1' }] };+ const out = buildScenePrompt('S', scene, [aria], '', null);+ expect(out).toContain('Aria: tall, dark hair. Wearing: mud-caked tactical jacket and boots');+ });++ it('leaves the character on their physical description when no wardrobe is picked', () => {+ const out = buildScenePrompt('S', baseScene, [aria], '', null);+ expect(out).toContain('Featuring — Aria: tall, dark hair');+ expect(out).not.toContain('Wearing:');+ });++ it('ignores an appearance whose wardrobeId no longer resolves on the character', () => {+ const scene = { ...baseScene, characterAppearances: [{ characterId: 'c1', wardrobeId: 'wd-gone' }] };+ const out = buildScenePrompt('S', scene, [aria], '', null);+ expect(out).toContain('Aria: tall, dark hair');+ expect(out).not.toContain('Wearing:');+ });++ it('only applies the appearance to its matching characterId', () => {+ const marcus = { id: 'c2', name: 'Marcus', physicalDescription: 'broad shoulders', wardrobes: [] };+ const scene = { ...baseScene, characterAppearances: [{ characterId: 'c1', wardrobeId: 'wd-2' }] };+ const out = buildScenePrompt('S', scene, [aria, marcus], '', null);+ expect(out).toContain('Aria: tall, dark hair. Wearing: emerald silk gown');+ expect(out).toContain('Marcus: broad shoulders');+ });++ it('surfaces wardrobe even when the character has no physical description', () => {+ const ghost = { id: 'c3', name: 'Ghost', wardrobes: [{ id: 'wd-x', name: 'Cloak', description: 'a tattered grey cloak' }] };+ const scene = { ...baseScene, characterAppearances: [{ characterId: 'c3', wardrobeId: 'wd-x' }] };+ const out = buildScenePrompt('S', scene, [ghost], '', null);+ expect(out).toContain('Ghost: Wearing: a tattered grey cloak');+ });++ it('tolerates a malformed characterAppearances list', () => {+ const scene = { ...baseScene, characterAppearances: [null, { wardrobeId: 'wd-1' }, 'nope'] };+ const out = buildScenePrompt('S', scene, [aria], '', null);+ expect(out).toContain('Aria: tall, dark hair');+ expect(out).not.toContain('Wearing:');+ });+});diff --git a/server/routes/pipeline.js b/server/routes/pipeline.jsindex 06062e7c82..ec7ae40832 100644--- a/server/routes/pipeline.js+++ b/server/routes/pipeline.js@@ -386,6 +386,15 @@ const visualGenerateSchema = z.object({cfgScale: z.number().min(0).max(30).optional(),guidance: z.number().min(0).max(30).optional(),seed: z.number().int().min(0).optional(),+ // Per-scene wardrobe picks threaded from the storyboards UI — the generic+ // visual route has no scene index, so the client sends the selected+ // appearances directly. Each pins one canon character to one of its+ // wardrobes; the prompt builder appends the wardrobe after the character's+ // physical description.+ characterAppearances: z.array(z.object({+ characterId: z.string().trim().min(1).max(120),+ wardrobeId: z.string().trim().min(1).max(120).nullable().optional(),+ })).max(50).optional(),}).refine(refineImagePixelCap, { message: PIXEL_CAP_MESSAGE, path: ['width'] });// Render-schema factory — every cover/back-cover render route shares thediff --git a/server/services/pipeline/visualStages.js b/server/services/pipeline/visualStages.jsindex 428356e1cc..feca209f12 100644--- a/server/services/pipeline/visualStages.js+++ b/server/services/pipeline/visualStages.js@@ -200,11 +200,11 @@ const enqueueImageJob = ({ prompt, world, settings, options, mode, owner, logLin// for reuse across many scenes — see episodeVideo) or pass `canon` and let// us build the map here. `series?.places` is no longer read — that field// was retired with the series-side canon teardown.-export function composeVisualPrompt({ series, description, slugline = '', extraStyle = '', placeByKey = null, matchedCharacters = [], world = null, canon = null }) {+export function composeVisualPrompt({ series, description, slugline = '', extraStyle = '', placeByKey = null, matchedCharacters = [], world = null, canon = null, characterAppearances = [] }) {const map = placeByKey || buildPlaceByKey(canon?.places);const scenePrompt = buildScenePrompt(series?.name || '',- { visualPrompt: description || '', slugline },+ { visualPrompt: description || '', slugline, characterAppearances },matchedCharacters,stackStyle(series, extraStyle),matchScenePlace(slugline, map),@@ -797,6 +797,9 @@ export async function enqueueVisualImage(issueId, stageId, options = {}) {matchedCharacters,world,canon,+ // Storyboard scene renders thread the scene's wardrobe picks through the+ // generic visual-image route, which has no scene index to look them up.+ characterAppearances: options.characterAppearances,});if (!prompt) {throw new ServerError('visual prompt is empty (no description, no style)', {@@ -866,6 +869,7 @@ export async function enqueueStoryboardSceneVideo(issueId, sceneIndex, options =matchedCharacters,world,canon,+ characterAppearances: scene.characterAppearances,});const aspectRatio = ASPECT_PRESETS[options.aspectRatio] ? options.aspectRatio : '16:9';@@ -963,6 +967,8 @@ export async function enqueueStoryboardShotStartFrame(issueId, sceneIndex, shotImatchedCharacters,world,canon,+ // A shot inherits its parent scene's wardrobe picks.+ characterAppearances: scene.characterAppearances,});const jobId = enqueueImageJob({