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

re-sync the character sheet on every save, avoid duplicating a referenced sheet, restore the lead on clear

[._.]/ Adam Eivy56d532995259
diff --git a/client/src/components/musicVideo/CharacterStylePicker.jsx b/client/src/components/musicVideo/CharacterStylePicker.jsx
index ecd7636cf9..90af8f85b6 100644
--- a/client/src/components/musicVideo/CharacterStylePicker.jsx
+++ b/client/src/components/musicVideo/CharacterStylePicker.jsx
@@ -46,11 +46,12 @@ export default function CharacterStylePicker({ project, value, onChange, idFor }
{style && <div className="border border-port-border rounded p-2 space-y-2 min-w-0">
<p className="text-xs">{style.summary}</p>
<p className="text-xs text-port-text-muted">{style.credit} · <a className="text-port-accent" href={style.sourceUrl} target="_blank" rel="noreferrer">character spec</a></p>
+ {style.referenceImageId && <p className="text-xs text-port-text-muted">Saving the setup adds the sheet to this project as its character reference.</p>}
{value !== (project.concept?.characterStyleId || '') && <p className="text-xs text-port-text-muted">{style.characterName} joins the cast as protagonist when you save.</p>}
<div className="flex flex-wrap items-start gap-2">
{style.referenceImageId
? <img src={`/data/images/${encodeURIComponent(style.referenceImageId)}`} alt={`${style.characterName} character sheet`} className="w-24 h-24 object-cover rounded bg-black shrink-0" />
- : <p className="text-xs text-port-text-muted flex-1 min-w-0">No character sheet on this install yet. Render one, add it under Look references, then choose it here.</p>}
+ : <p className="text-xs text-port-text-muted flex-1 min-w-0">No character sheet on this install yet. Render one, add it under Look references, then choose it here and save.</p>}
<div className="flex flex-col gap-1 min-w-0">
<Link className="text-sm text-port-accent min-h-[44px] inline-flex items-center" to={`/media/image?${new URLSearchParams({ prompt: style.sheetPrompt })}`}>Render a character sheet</Link>
{images.length > 0 && <>
diff --git a/server/services/musicVideo/styleSnapshots.js b/server/services/musicVideo/styleSnapshots.js
index 6b1f46dbaf..64df2e688d 100644
--- a/server/services/musicVideo/styleSnapshots.js
+++ b/server/services/musicVideo/styleSnapshots.js
@@ -79,12 +79,19 @@ export async function withStyleSnapshots(input, existing = null) {
}
if (concept && has(concept, 'characterStyleId') && !has(concept, 'characterStyle')) {
- const id = concept.characterStyleId || '';
+ const style = concept.characterStyleId ? getMusicVideoCharacterStyle(concept.characterStyleId) : null;
const previousId = existing?.concept?.characterStyleId || '';
- if (id !== previousId || existing?.concept?.characterStyle == null) {
- const cast = await castCharacterStyle(concept, visualSpec, existing, previousId, id);
- Object.assign(concept, cast.concept);
- visualSpec = cast.visualSpec;
+ const previous = previousId ? getMusicVideoCharacterStyle(previousId) : null;
+ if ((style?.id || '') !== previousId || existing?.concept?.characterStyle == null) {
+ concept.characterStyle = musicVideoCharacterStyleSnapshot(style);
+ concept.subjects = castCharacterStyle(concept.subjects ?? existing?.concept?.subjects ?? [], previous, style);
+ touched = true;
+ }
+ // Every save re-syncs the sheet, so one chosen after the style was first
+ // saved still reaches the project.
+ const synced = await syncCharacterStyleSheet(visualSpec, existing, previous, style);
+ if (synced !== visualSpec) {
+ visualSpec = synced;
touched = true;
}
}
@@ -104,42 +111,50 @@ export async function withStyleSnapshots(input, existing = null) {
}
/**
- * Picking a character style snapshots its text, casts its character as the
- * protagonist and adds this install's character sheet (if one is set) as a
- * character reference; switching away removes what the previous style added
- * and leaves every director-authored subject and reference alone.
+ * The style's character leads the cast and an existing protagonist steps back;
+ * switching away removes the previous style's character and, if that leaves no
+ * protagonist, hands the role back to the first remaining character.
*/
-async function castCharacterStyle(concept, visualSpec, existing, previousId, id) {
- const style = id ? getMusicVideoCharacterStyle(id) : null;
- const previous = previousId ? getMusicVideoCharacterStyle(previousId) : null;
-
- const dropSubject = new Set([previous, style].filter(Boolean).map(musicVideoCharacterStyleSubjectId));
- let subjects = (concept.subjects ?? existing?.concept?.subjects ?? []).filter((s) => !dropSubject.has(s.id));
+function castCharacterStyle(subjects, previous, style) {
+ const drop = new Set([previous, style].filter(Boolean).map(musicVideoCharacterStyleSubjectId));
+ const rest = subjects.filter((s) => !drop.has(s.id));
if (style) {
- // The style's character leads the cast; an existing protagonist steps back.
- subjects = [musicVideoCharacterStyleSubject(style),
- ...subjects.map((s) => (s.role === 'protagonist' ? { ...s, role: 'supporting' } : s))].slice(0, 24);
+ return [musicVideoCharacterStyleSubject(style),
+ ...rest.map((s) => (s.role === 'protagonist' ? { ...s, role: 'supporting' } : s))].slice(0, 24);
}
+ if (!previous || rest.some((s) => s.role === 'protagonist')) return rest;
+ const lead = rest.findIndex((s) => s.kind === 'character');
+ return lead < 0 ? rest : rest.map((s, i) => (i === lead ? { ...s, role: 'protagonist' } : s));
+}
- const dropRef = new Set([previous, style].filter(Boolean).map(musicVideoCharacterStyleReferenceId));
+/**
+ * Keeps the project's character-sheet reference in step with this install's
+ * sheet for the style: added (conditioning when a slot is free), replaced when
+ * the sheet changed, removed with the style. A sheet already in the project as
+ * a director's reference is marked as the character instead of added twice.
+ * Returns `visualSpec` itself when nothing changed.
+ */
+async function syncCharacterStyleSheet(visualSpec, existing, previous, style) {
+ const drop = new Set([previous, style].filter(Boolean).map(musicVideoCharacterStyleReferenceId));
const baseRefs = visualSpec?.references ?? existing?.visualSpec?.references ?? [];
- let references = baseRefs.filter((ref) => !dropRef.has(ref.id));
+ let references = baseRefs.filter((ref) => !drop.has(ref.id));
const imageId = style ? await getCharacterStyleReferenceImage(style.id) : null;
- if (imageId && references.length < 24) {
- const conditioning = references.filter((ref) => ref.condition).length;
- references = [...references, {
- id: musicVideoCharacterStyleReferenceId(style),
- imageId,
- role: 'character',
- label: `${style.character.name} character sheet`,
- use: 'reference',
- condition: conditioning < MUSIC_VIDEO_MAX_CONDITIONING_REFERENCES,
- }];
+ if (imageId) {
+ const freeSlot = references.filter((ref) => ref.condition).length < MUSIC_VIDEO_MAX_CONDITIONING_REFERENCES;
+ const same = references.findIndex((ref) => ref.imageId === imageId);
+ if (same >= 0) {
+ references = references.map((ref, i) => (i === same ? { ...ref, role: 'character', condition: ref.condition || freeSlot } : ref));
+ } else if (references.length < 24) {
+ references = [...references, {
+ id: musicVideoCharacterStyleReferenceId(style),
+ imageId,
+ role: 'character',
+ label: `${style.character.name} character sheet`,
+ use: 'reference',
+ condition: freeSlot,
+ }];
+ }
}
- const referencesChanged = references.length !== baseRefs.length || references.some((ref, i) => ref !== baseRefs[i]);
-
- return {
- concept: { characterStyle: musicVideoCharacterStyleSnapshot(style), subjects },
- visualSpec: referencesChanged ? { ...(visualSpec || {}), references } : visualSpec,
- };
+ if (JSON.stringify(references) === JSON.stringify(baseRefs)) return visualSpec;
+ return { ...(visualSpec || {}), references };
}
diff --git a/server/services/musicVideo/styleSnapshots.test.js b/server/services/musicVideo/styleSnapshots.test.js
index 3a58ccf1df..5c6181a640 100644
--- a/server/services/musicVideo/styleSnapshots.test.js
+++ b/server/services/musicVideo/styleSnapshots.test.js
@@ -74,10 +74,28 @@ describe('withStyleSnapshots (#9105)', () => {
const picked = { concept: { characterStyleId: 'claudia-slopcore', characterStyle: out.concept.characterStyle, subjects: out.concept.subjects }, visualSpec: out.visualSpec };
const cleared = await withStyleSnapshots({ concept: { characterStyleId: null } }, picked);
expect(cleared.concept.characterStyle).toBe('');
- expect(cleared.concept.subjects.map((s) => s.id)).toEqual(['mvc-1']);
+ // The director's lead gets the protagonist role back.
+ expect(cleared.concept.subjects).toEqual([director]);
expect(cleared.visualSpec.references).toEqual(conditioned);
});
+ it('adds a sheet chosen after the style was first saved, and marks a sheet already referenced instead of duplicating it', async () => {
+ const first = await withStyleSnapshots({ concept: { characterStyleId: 'claudia-slopcore' } });
+ expect(first.visualSpec).toBeUndefined();
+ const saved = { concept: first.concept, visualSpec: { references: [{ id: 'mine', imageId: 'sheet.png', role: 'mood' }] } };
+ const patch = { concept: { characterStyleId: 'claudia-slopcore', subjects: first.concept.subjects } };
+ expect(await withStyleSnapshots(patch, saved)).toBe(patch);
+
+ getCharacterStyleReferenceImage.mockResolvedValue('sheet.png');
+ const resaved = await withStyleSnapshots(patch, saved);
+ expect(resaved.concept.subjects).toEqual(first.concept.subjects);
+ expect(resaved.visualSpec.references).toEqual([{ id: 'mine', imageId: 'sheet.png', role: 'character', condition: true }]);
+
+ getCharacterStyleReferenceImage.mockResolvedValue('new-sheet.png');
+ const replaced = await withStyleSnapshots(patch, { ...saved, visualSpec: resaved.visualSpec });
+ expect(replaced.visualSpec.references.map((r) => [r.id, r.imageId])).toEqual([['mine', 'sheet.png'], ['mvr-style-claudia-slopcore', 'new-sheet.png']]);
+ });
+
it('casts without a reference when this install has no sheet for the style', async () => {
const out = await withStyleSnapshots({ concept: { characterStyleId: 'claudia-slopcore' } });
expect(out.concept.subjects).toHaveLength(1);