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: Music Video style snapshots are derived on the server from universe and mood-board ids (#9105)

[._.]/ Adam Eivy61169d9d19d1
diff --git a/client/src/components/musicVideo/CreativeSetupPanel.jsx b/client/src/components/musicVideo/CreativeSetupPanel.jsx
index c37268d530..2461bb54bc 100644
--- a/client/src/components/musicVideo/CreativeSetupPanel.jsx
+++ b/client/src/components/musicVideo/CreativeSetupPanel.jsx
@@ -1,10 +1,9 @@
import { useEffect, useState } from 'react';
import { Link } from 'react-router';
import { listUniverseNames, getUniverse } from '../../services/apiUniverseBuilder.js';
-import { getMoodBoard } from '../../services/apiMoodBoard.js';
import MoodBoardReferenceStrip from '../moodBoard/MoodBoardReferenceStrip.jsx';
import { uuidv4 } from '../../lib/uuid.js';
-import { pullUniverseCanonReferences, universeStyleSnapshot, moodBoardStyleSnapshot } from '../../lib/musicVideoUniverseRefs.js';
+import { pullUniverseCanonReferences } from '../../lib/musicVideoUniverseRefs.js';
const inputClass = 'w-full min-w-0 bg-port-bg border border-port-border rounded px-2 py-1.5 text-sm';
const kinds = [['character', 'Cast'], ['place', 'Places'], ['object', 'Objects']];
@@ -73,9 +72,6 @@ export default function CreativeSetupPanel({ project, onSave, onPendingChange })
setSaving(true);
setError('');
const concept = { subjects: draft.subjects, universeId: draft.universeId || null };
- if (draft.universeId !== (project.concept?.universeId || '') || project.concept?.universeStyle == null) {
- concept.universeStyle = draft.universeId && universe?.id === draft.universeId ? universeStyleSnapshot(universe) : '';
- }
const visualSpec = { moodBoardId: draft.moodBoardId || null };
const canon = { characters: [], places: [], objects: [] };
for (const item of selectedCanon) {
@@ -83,13 +79,7 @@ export default function CreativeSetupPanel({ project, onSave, onPendingChange })
}
const pulled = pullUniverseCanonReferences(canon, project.visualSpec?.references || []);
if (pulled.added) visualSpec.references = pulled.next;
- const refreshBoard = draft.moodBoardId !== (project.visualSpec?.moodBoardId || '') || project.concept?.moodBoardStyle == null;
- const boardRequest = draft.moodBoardId && refreshBoard
- ? getMoodBoard(draft.moodBoardId, { silent: true }) : Promise.resolve(null);
- return boardRequest.then((board) => {
- if (refreshBoard) concept.moodBoardStyle = moodBoardStyleSnapshot(board);
- return onSave({ concept, visualSpec });
- }).then(() => setEditing(false)).catch((err) => setError(err.message || 'Could not save creative setup')).finally(() => setSaving(false));
+ return onSave({ concept, visualSpec }).then(() => setEditing(false)).catch((err) => setError(err.message || 'Could not save creative setup')).finally(() => setSaving(false));
};
return <section className="bg-port-card border border-port-border rounded-lg p-3 space-y-3 min-w-0 break-words" aria-label="Creative setup">
diff --git a/client/src/components/musicVideo/CreativeSetupPanel.test.jsx b/client/src/components/musicVideo/CreativeSetupPanel.test.jsx
index 435a149eee..2d3580bfa6 100644
--- a/client/src/components/musicVideo/CreativeSetupPanel.test.jsx
+++ b/client/src/components/musicVideo/CreativeSetupPanel.test.jsx
@@ -39,7 +39,7 @@ describe('creative setup', () => {
fireEvent.click(screen.getByText('Save creative setup'));
await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
expect(onSave.mock.calls[0][0]).toMatchObject({
- concept: { universeId: 'u1', universeStyle: 'Example universe\nInk silhouettes', moodBoardStyle: expect.stringContaining('Loose brush strokes'), subjects: [
+ concept: { universeId: 'u1', subjects: [
{ kind: 'character', name: 'Example singer', role: 'band', description: 'Silver coat', canonId: 'c1' },
{ kind: 'object', name: 'Glass guitar', description: 'Transparent blue glass' },
] }, visualSpec: { moodBoardId: 'b1' },
@@ -57,7 +57,7 @@ describe('creative setup', () => {
expect(screen.queryByText(/Unsaved singer/)).toBeNull();
});
- it('cannot save a pending universe under the previously loaded style and clears style on deselection', async () => {
+ it('cannot save while a newly chosen universe is still loading and sends a null id on deselection', async () => {
let resolveNext;
getUniverse.mockResolvedValueOnce({ id: 'u1', name: 'Example universe', styleNotes: 'Old style', characters: [] })
.mockImplementationOnce(() => new Promise((resolve) => { resolveNext = resolve; }));
@@ -69,7 +69,7 @@ describe('creative setup', () => {
expect(screen.getByText('Save creative setup').disabled).toBe(true);
fireEvent.change(screen.getByLabelText('Universe'), { target: { value: '' } });
fireEvent.click(screen.getByText('Save creative setup'));
- await waitFor(() => expect(onSave).toHaveBeenCalledWith(expect.objectContaining({ concept: expect.objectContaining({ universeId: null, universeStyle: '' }) })));
+ await waitFor(() => expect(onSave).toHaveBeenCalledWith(expect.objectContaining({ concept: expect.objectContaining({ universeId: null }) })));
await act(async () => { resolveNext({ id: 'u2', name: 'Other universe', styleNotes: 'Wrong style' }); });
});
diff --git a/client/src/lib/README.md b/client/src/lib/README.md
index a969d12560..cc467570a1 100644
--- a/client/src/lib/README.md
+++ b/client/src/lib/README.md
@@ -61,7 +61,7 @@ grep -i "what you want to do" client/src/lib/README.md
| `musicVideoLayers.js` | Music-video per-scene visual layers (#8985), re-exported from `server/lib/musicVideoLayers.js`: `MUSIC_VIDEO_VISUAL_LAYERS`, `MUSIC_VIDEO_STILL_MOVES`, `sceneVisualLayer(scene, { layered })`, `sceneHasAuthoredSpan`, `sceneRenderReady(scene, { layered })`. Used by `components/musicVideo/SceneCard.jsx`, `ProjectToolbar.jsx` and `hooks/useMusicVideoSceneMedia.js`. |
| `musicVideoTakes.js` | Music-video scene takes view helpers (#8965): `sceneTakeList(scene, kind)` lists a scene's image/video takes with an un-materialized pre-takes selection appended as a read-only `legacy` take; `takePreviewKey`, `takeThumbUrl`, `takeProvenance`; `TAKE_SLOT` maps a take kind to its selection field. Used by `components/musicVideo/SceneTakeStrip.jsx` and `pages/MusicVideo.jsx`. |
| `musicVideoShotTiming.js` | Re-export of `server/lib/musicVideoShotTiming.js` (#8977) — shot modes, the verified source-audio lip-sync capability table, `performanceBlockedReason`, `planPerformanceWindow`, `grokCoverage`, `approximateMotionCues`, `shotSplitLimit` (when a scene offers a lyric-boundary split). Used by `hooks/useMusicVideoSceneMedia.js` and `components/musicVideo/SceneCard.jsx`. |
-| `musicVideoUniverseRefs.js` | `pullUniverseCanonReferences(universe, existingReferences)` (#8978) maps a linked universe's characters/places/objects to visual-spec references (character/set/prop roles), skipping images already present and capping at `MUSIC_VIDEO_MAX_REFERENCES` (24, mirrors the server schema). Returns `{ next, added, skipped }`; the caller persists `next` via the ordinary visualSpec PATCH. Used by `components/musicVideo/VisualSpecPanel.jsx`. Also `universeStyleSnapshot(universe)` / `moodBoardStyleSnapshot(board)` — the bounded style text copied into `concept.universeStyle` / `concept.moodBoardStyle` by the creative setup panel and the automation-first create drawer. |
+| `musicVideoUniverseRefs.js` | `pullUniverseCanonReferences(universe, existingReferences)` (#8978) maps a linked universe's characters/places/objects to visual-spec references (character/set/prop roles), skipping images already present and capping at `MUSIC_VIDEO_MAX_REFERENCES` (24, mirrors the server schema). Returns `{ next, added, skipped }`; the caller persists `next` via the ordinary visualSpec PATCH. Used by `components/musicVideo/VisualSpecPanel.jsx`. (The style snapshots are derived server-side, #9105.) |
| `musicVideoAutomation.js` | Music Video automation brief, client half: re-exports the server tool catalog (`MUSIC_VIDEO_AUTOMATION_TOOLS` / `_TOOL_IDS`), `DEFAULT_AUTOMATION_TOOLS` (the unmetered tools), and the form mapping `automationDraftFrom(automation)` / `automationFromDraft(draft)` (empty budget = no cap). Used by the create drawer and `AutomationPanel`. |
| `bibleLimits.js` | `BIBLE_LIMITS` re-exported from the pure leaf `server/lib/bibleLimits.js`, plus the client-only `capImageRefs` / `appendImageRefById` for the optimistic imageRefs-append paths. |
| `characterEvolution.js` | The five-stage character evolution lens as the editors consume it. Re-exports `EVOLUTION_STAGES` / `EVOLUTION_OUTCOMES` / `EVOLUTION_STAGE_LABELS` / `EVOLUTION_STAGE_TEXT_FIELDS` / `EVOLUTION_EVIDENCE_FIELDS` / `EVOLUTION_EVIDENCE_STATUSES` / `CHARACTER_EVOLUTION_LIMITS` / `evolutionEvidenceStatus` / `isDeclaredEvolution` from the pure leaf `server/lib/characterEvolution.js` (a guard in `server/lib/characterEvolution.test.js` fails if this file ever restates a vocabulary instead of re-exporting it), adds the editor descriptors `EVOLUTION_STAGE_EDITOR_FIELDS` / `EVOLUTION_OUTCOME_HINTS` (#6440), and the draft-mutation helpers `evolutionStage` / `patchEvolution` / `patchEvolutionStage` / `patchEvolutionEvidence` that keep an editor's draft collapsing to the same shape the server sanitizer produces — so a present-but-empty field is a real clear (#6441). |
diff --git a/client/src/lib/musicVideoUniverseRefs.js b/client/src/lib/musicVideoUniverseRefs.js
index 034c45f3a4..c281d2ba15 100644
--- a/client/src/lib/musicVideoUniverseRefs.js
+++ b/client/src/lib/musicVideoUniverseRefs.js
@@ -9,31 +9,6 @@
// can never produce a spec the server would reject.
import { uuidv4 } from './uuid.js';
-import { collectBoardStyleContext } from '../../../server/lib/moodBoardStyleContext.js';
-
-// Authored style snapshots copied into a project's concept (universeStyle /
-// moodBoardStyle, bounded by the server's 4000-char schema cap) so later edits
-// to the source universe or board never silently restyle a video.
-const STYLE_SNAPSHOT_MAX = 4000;
-
-export function universeStyleSnapshot(universe) {
- if (!universe) return '';
- const embrace = universe.influences?.embrace || [];
- const avoid = universe.influences?.avoid || [];
- return [
- universe.name,
- universe.styleNotes,
- embrace.length ? `Embrace: ${embrace.join(', ')}` : '',
- avoid.length ? `Avoid: ${avoid.join(', ')}` : '',
- ].filter(Boolean).join('\n').slice(0, STYLE_SNAPSHOT_MAX);
-}
-
-export function moodBoardStyleSnapshot(board) {
- const context = board ? collectBoardStyleContext(board) : null;
- if (!context) return '';
- return [context.name, context.description, ...context.items.map((item) => Object.values(item).join('; '))]
- .filter(Boolean).join('\n').slice(0, STYLE_SNAPSHOT_MAX);
-}
export const MUSIC_VIDEO_MAX_REFERENCES = 24;
diff --git a/client/src/pages/MusicVideo.jsx b/client/src/pages/MusicVideo.jsx
index bae26975de..4c68436cd1 100644
--- a/client/src/pages/MusicVideo.jsx
+++ b/client/src/pages/MusicVideo.jsx
@@ -45,9 +45,7 @@ import BeatTimeline from '../components/musicVideo/BeatTimeline.jsx';
import CreateProjectDrawer from '../components/musicVideo/CreateProjectDrawer.jsx';
import AutomationPanel from '../components/musicVideo/AutomationPanel.jsx';
import { automationDraftFrom, automationFromDraft } from '../lib/musicVideoAutomation.js';
-import { getUniverse, listUniverseNames } from '../services/apiUniverseBuilder.js';
-import { getMoodBoard } from '../services/apiMoodBoard.js';
-import { universeStyleSnapshot, moodBoardStyleSnapshot } from '../lib/musicVideoUniverseRefs.js';
+import { listUniverseNames } from '../services/apiUniverseBuilder.js';
import ProjectToolbar from '../components/musicVideo/ProjectToolbar.jsx';
import TrackPanel from '../components/musicVideo/TrackPanel.jsx';
import RenderStatusPanel from '../components/musicVideo/RenderStatusPanel.jsx';
@@ -240,24 +238,15 @@ export default function MusicVideo() {
}
if (creating) return;
setCreating(true);
- // Snapshot the chosen universe/board style into the concept at creation,
- // the same authored copy the creative setup panel saves.
- Promise.all([
- form.universeId ? getUniverse(form.universeId, { silent: true }) : null,
- form.moodBoardId ? getMoodBoard(form.moodBoardId, { silent: true }) : null,
- ])
- .then(([universe, board]) => createMusicVideoProject({
- name: form.name.trim(),
- mode: form.mode,
- trackId: form.trackId || null,
- concept: {
- universeId: form.universeId || null,
- universeStyle: universeStyleSnapshot(universe),
- moodBoardStyle: moodBoardStyleSnapshot(board),
- },
- ...(form.moodBoardId ? { visualSpec: { moodBoardId: form.moodBoardId } } : {}),
- ...(form.mode === 'autonomous' ? { automation: automationFromDraft(form.automation) } : {}),
- }, { silent: true }))
+ // Only the ids go up: the server snapshots the universe/board style into the concept.
+ createMusicVideoProject({
+ name: form.name.trim(),
+ mode: form.mode,
+ trackId: form.trackId || null,
+ concept: { universeId: form.universeId || null },
+ ...(form.moodBoardId ? { visualSpec: { moodBoardId: form.moodBoardId } } : {}),
+ ...(form.mode === 'autonomous' ? { automation: automationFromDraft(form.automation) } : {}),
+ }, { silent: true })
.then((proj) => {
setProjects((prev) => [...prev, proj]);
selectProject(proj.id);
diff --git a/server/services/musicVideo/projects.js b/server/services/musicVideo/projects.js
index 6b897c8a16..f2308027e4 100644
--- a/server/services/musicVideo/projects.js
+++ b/server/services/musicVideo/projects.js
@@ -26,6 +26,7 @@ import { emitRecordUpdated, emitRecordDeleted, autoSubscribeRecordToAllPeers } f
import { RENDER_TARGET } from '../../lib/renderTargets.js';
import { VIDEO_GEN_MODE, resolveVideoMode } from '../videoGen/modes.js';
import { getSettings } from '../settings.js';
+import { withStyleSnapshots } from './styleSnapshots.js';
// Shared dispatcher (#2899). ensureSchema() runs inside the selector (mirroring
// memoryBackend.js) so the backend is self-sufficient regardless of boot ordering.
@@ -85,7 +86,7 @@ async function seedVideoBackendDefault(input) {
}
export async function createProject(input) {
- const project = await (await selectBackend()).createProject(await seedVideoBackendDefault(input));
+ const project = await (await selectBackend()).createProject(await withStyleSnapshots(await seedVideoBackendDefault(input)));
announceNewProject(project.id);
return project;
}
@@ -97,7 +98,10 @@ export async function cloneProject(id, options = {}) {
}
export async function updateProject(id, patch) {
- const next = await (await selectBackend()).updateProject(id, patch);
+ const backend = await selectBackend();
+ const needsSnapshot = patch?.concept?.universeId !== undefined || patch?.visualSpec?.moodBoardId !== undefined;
+ const resolved = needsSnapshot ? await withStyleSnapshots(patch, await backend.getProject(id)) : patch;
+ const next = await backend.updateProject(id, resolved);
emitRecordUpdated('musicVideoProject', id);
return next;
}
diff --git a/server/services/musicVideo/styleSnapshots.js b/server/services/musicVideo/styleSnapshots.js
new file mode 100644
index 0000000000..906990f50d
--- /dev/null
+++ b/server/services/musicVideo/styleSnapshots.js
@@ -0,0 +1,76 @@
+// Server-derived style snapshots for a Music Video project's concept (#9105).
+// `concept.universeStyle` / `concept.moodBoardStyle` are authored copies of the
+// linked universe / mood board (bounded by the concept schema's 4000-char cap),
+// so later edits to the source never silently restyle a video. The client sends
+// only `concept.universeId` / `visualSpec.moodBoardId`; the create/update
+// dispatcher fills the snapshot text in here.
+
+import { collectBoardStyleContext } from '../../lib/moodBoardStyleContext.js';
+
+const STYLE_SNAPSHOT_MAX = 4000;
+
+export function universeStyleSnapshot(universe) {
+ if (!universe) return '';
+ const embrace = universe.influences?.embrace || [];
+ const avoid = universe.influences?.avoid || [];
+ return [
+ universe.name,
+ universe.styleNotes,
+ embrace.length ? `Embrace: ${embrace.join(', ')}` : '',
+ avoid.length ? `Avoid: ${avoid.join(', ')}` : '',
+ ].filter(Boolean).join('\n').slice(0, STYLE_SNAPSHOT_MAX);
+}
+
+export function moodBoardStyleSnapshot(board) {
+ const context = board ? collectBoardStyleContext(board) : null;
+ if (!context) return '';
+ return [context.name, context.description, ...context.items.map((item) => Object.values(item).join('; '))]
+ .filter(Boolean).join('\n').slice(0, STYLE_SNAPSHOT_MAX);
+}
+
+// A dangling or deleted source yields an empty snapshot rather than failing the
+// save — the same result the client produced when its fetch found nothing.
+async function loadOrEmpty(load, format, label, id) {
+ try {
+ return format(await load(id));
+ } catch (err) {
+ console.warn(`⚠️ Music Video ${label} snapshot skipped for ${id}: ${err.message}`);
+ return '';
+ }
+}
+
+const loadUniverse = async (id) => (await import('../universeBuilder/crud.js')).getUniverse(id);
+const loadBoard = async (id) => (await import('../moodBoard/index.js')).getBoard(id);
+
+const has = (obj, key) => obj != null && Object.prototype.hasOwnProperty.call(obj, key);
+
+/**
+ * Returns `input` with any missing snapshot derived from the ids it carries.
+ * `existing` is the stored project on a patch (null on create): a snapshot is
+ * (re)derived when the id changed or none was ever stored, and never when the
+ * caller supplied the snapshot text explicitly.
+ */
+export async function withStyleSnapshots(input, existing = null) {
+ if (!input) return input;
+ const concept = input.concept && typeof input.concept === 'object' ? { ...input.concept } : null;
+ let touched = false;
+
+ if (concept && has(concept, 'universeId') && !has(concept, 'universeStyle')) {
+ const id = concept.universeId || '';
+ if (id !== (existing?.concept?.universeId || '') || existing?.concept?.universeStyle == null) {
+ concept.universeStyle = id ? await loadOrEmpty(loadUniverse, universeStyleSnapshot, 'universe', id) : '';
+ touched = true;
+ }
+ }
+
+ if (has(input.visualSpec, 'moodBoardId') && !(concept && has(concept, 'moodBoardStyle'))) {
+ const id = input.visualSpec.moodBoardId || '';
+ if (id !== (existing?.visualSpec?.moodBoardId || '') || existing?.concept?.moodBoardStyle == null) {
+ const target = concept || {};
+ target.moodBoardStyle = id ? await loadOrEmpty(loadBoard, moodBoardStyleSnapshot, 'mood board', id) : '';
+ return { ...input, concept: target };
+ }
+ }
+
+ return touched ? { ...input, concept } : input;
+}
diff --git a/server/services/musicVideo/styleSnapshots.test.js b/server/services/musicVideo/styleSnapshots.test.js
new file mode 100644
index 0000000000..dde654d60b
--- /dev/null
+++ b/server/services/musicVideo/styleSnapshots.test.js
@@ -0,0 +1,52 @@
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+
+const getUniverse = vi.fn();
+const getBoard = vi.fn();
+vi.mock('../universeBuilder/crud.js', () => ({ getUniverse: (...a) => getUniverse(...a) }));
+vi.mock('../moodBoard/index.js', () => ({ getBoard: (...a) => getBoard(...a) }));
+
+const { withStyleSnapshots } = await import('./styleSnapshots.js');
+
+const UNIVERSE = { name: 'Example universe', styleNotes: 'Ink silhouettes', influences: { embrace: ['noir'], avoid: ['neon'] } };
+const BOARD = { name: 'Painted style', description: 'Watercolor', items: [{ type: 'text', text: 'Loose brush strokes' }] };
+
+describe('withStyleSnapshots (#9105)', () => {
+ beforeEach(() => {
+ getUniverse.mockReset().mockResolvedValue(UNIVERSE);
+ getBoard.mockReset().mockResolvedValue(BOARD);
+ });
+
+ it('derives both snapshots on create from ids alone', async () => {
+ const out = await withStyleSnapshots({ name: 'MV', concept: { universeId: 'u1' }, visualSpec: { moodBoardId: 'b1' } });
+ expect(out.concept.universeStyle).toBe('Example universe\nInk silhouettes\nEmbrace: noir\nAvoid: neon');
+ expect(out.concept.moodBoardStyle).toContain('Loose brush strokes');
+ expect(out.visualSpec).toEqual({ moodBoardId: 'b1' });
+ });
+
+ it('keeps an explicit snapshot and does not refetch an unchanged, already-snapshotted source', async () => {
+ const existing = { concept: { universeId: 'u1', universeStyle: 'kept', moodBoardStyle: 'kept' }, visualSpec: { moodBoardId: 'b1' } };
+ const patch = { concept: { universeId: 'u1', subjects: [] }, visualSpec: { moodBoardId: 'b1' } };
+ expect(await withStyleSnapshots(patch, existing)).toBe(patch);
+ const explicit = { concept: { universeId: 'u2', universeStyle: 'mine' } };
+ expect((await withStyleSnapshots(explicit, existing)).concept.universeStyle).toBe('mine');
+ expect(getUniverse).not.toHaveBeenCalled();
+ expect(getBoard).not.toHaveBeenCalled();
+ });
+
+ it('re-derives on a changed id, clears on deselection, and derives a legacy project missing a snapshot', async () => {
+ const existing = { concept: { universeId: 'u1', universeStyle: 'old', moodBoardStyle: 'old' }, visualSpec: { moodBoardId: 'b1' } };
+ const changed = await withStyleSnapshots({ concept: { universeId: 'u2' } }, existing);
+ expect(getUniverse).toHaveBeenCalledWith('u2');
+ expect(changed.concept.universeStyle).toContain('Ink silhouettes');
+ const cleared = await withStyleSnapshots({ concept: { universeId: null }, visualSpec: { moodBoardId: null } }, existing);
+ expect(cleared.concept).toMatchObject({ universeStyle: '', moodBoardStyle: '' });
+ const legacy = await withStyleSnapshots({ visualSpec: { moodBoardId: 'b1' } }, { concept: { universeId: 'u1' }, visualSpec: { moodBoardId: 'b1' } });
+ expect(legacy.concept.moodBoardStyle).toContain('Watercolor');
+ });
+
+ it('yields an empty snapshot for a missing source instead of failing the save', async () => {
+ getUniverse.mockRejectedValue(new Error('Universe not found'));
+ const out = await withStyleSnapshots({ concept: { universeId: 'gone' } });
+ expect(out.concept.universeStyle).toBe('');
+ });
+});