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

Reseed the art draft from a newer approved Cast & Sets revision

Claude0292e6e608fb
diff --git a/server/services/musicVideo/castAndSetsService.test.js b/server/services/musicVideo/castAndSetsService.test.js
index 2896aeffd1..586f13d770 100644
--- a/server/services/musicVideo/castAndSetsService.test.js
+++ b/server/services/musicVideo/castAndSetsService.test.js
@@ -402,6 +402,46 @@ describe('Cast & Sets check-in', () => {
expect(done.productionReview.approvals?.art).toBeUndefined();
});
+ it('reseeds untouched art draft fields from a newer approved revision and keeps edited ones', async () => {
+ const project = await seed();
+ await request(app).post(`/api/music-video/${project.id}/cast-and-sets`).send({});
+ await runTo(project.id, 'review');
+ await request(app).post(`/api/music-video/${project.id}/cast-and-sets/approve`).send({});
+ const first = (await current(project.id)).productionReview.draft;
+ await projects.mutateProjectRecord(project.id, (c) => ({ project: { ...c,
+ productionReview: { ...c.productionReview, draft: { ...c.productionReview.draft, visualLanguage: 'My own look notes' } } } }));
+
+ const revised = { ...DIRECTION, protagonist: { ...DIRECTION.protagonist, name: 'Signalman' },
+ sets: [{ ...DIRECTION.sets[0], name: 'Engine room' }, ...DIRECTION.sets.slice(1)] };
+ runPrompt.mockResolvedValue({ text: JSON.stringify(revised) });
+ await request(app).post(`/api/music-video/${project.id}/cast-and-sets`).send({});
+ await runTo(project.id, 'review');
+ await request(app).post(`/api/music-video/${project.id}/cast-and-sets/approve`).send({});
+
+ const draft = (await current(project.id)).productionReview.draft;
+ expect(draft.cast).toContain('Signalman');
+ expect(draft.environments).toContain('Engine room');
+ expect(draft.environments).not.toContain('Lamp room');
+ expect(draft.visualLanguage).toBe('My own look notes');
+ expect(draft.motionLanguage).toBe(first.motionLanguage);
+ });
+
+ it('reseeds a legacy seeded draft with no seed record but keeps typed notes', async () => {
+ const project = await seed();
+ await request(app).post(`/api/music-video/${project.id}/cast-and-sets`).send({});
+ await runTo(project.id, 'review');
+ // A draft seeded before the seed record existed: JSON text from an older direction.
+ await projects.mutateProjectRecord(project.id, (c) => ({ project: { ...c,
+ productionReview: { draft: { cast: JSON.stringify({ name: 'Old keeper' }, null, 2), environments: 'Typed set notes',
+ visualLanguage: JSON.stringify([{ name: 'Old set' }], null, 2) } } } }));
+ await request(app).post(`/api/music-video/${project.id}/cast-and-sets/approve`).send({});
+ const draft = (await current(project.id)).productionReview.draft;
+ expect(draft.cast).toContain('Keeper');
+ expect(draft.cast).not.toContain('Old keeper');
+ expect(draft.environments).toBe('Typed set notes');
+ expect(draft.visualLanguage).not.toContain('Old set');
+ });
+
it.each(['approved', 'skipped'])('rebuilds a %s check-in as a new revision that keeps the prior sheet as an earlier version', async (end) => {
const project = await seed();
await request(app).post(`/api/music-video/${project.id}/cast-and-sets`).send({});
diff --git a/server/services/musicVideo/productionReview.js b/server/services/musicVideo/productionReview.js
index f2c5f0d3c9..f03e25b66c 100644
--- a/server/services/musicVideo/productionReview.js
+++ b/server/services/musicVideo/productionReview.js
@@ -60,24 +60,45 @@ function hasProofEvidence(review) {
const describeDirection = value => typeof value === 'string' ? value : JSON.stringify(value || {}, null, 2);
+// What the art draft fields are seeded from. A seeded field that the user has
+// not edited follows the newest approved direction; an edited one is kept.
+const ART_SEEDS = {
+ cast: d => d.protagonist,
+ environments: d => d.sets,
+ visualLanguage: d => ({ look: d.look, palette: d.protagonist?.palette, world: d.world }),
+ motionLanguage: d => ({ movement: d.protagonist?.movement, camera: d.world?.camera, transitions: d.world?.transitions }),
+};
+// Drafts seeded before productionReview.seededDraft existed have no record of
+// what was seeded. describeDirection writes objects as JSON, which typed notes
+// never are, so a field holding a JSON object or list is treated as an untouched seed.
+const looksSeeded = value => {
+ if (!/^[[{]/.test(value.trim())) return false;
+ try { return typeof JSON.parse(value) === 'object'; } catch { return false; }
+};
+
/**
- * Seed the empty art-direction draft fields (and the visual guide) from a
- * Cast & Sets sheet. Text the director already typed — and a guide already
- * chosen — is never overwritten, and a document-shot draft is left alone.
+ * Seed the art-direction draft fields (and the visual guide) from a Cast & Sets
+ * sheet. A field that is blank or still holds the text an earlier approval
+ * seeded follows the newest direction; text the director typed — and a guide
+ * already chosen — is never overwritten, and a document-shot draft is left alone.
* Seeding supplies editable content only; it never records an approval.
*/
export function seedArtDraft(project, stage = project.castAndSets) {
const prior = project.productionReview?.draft || {};
if (prior.storyboardSource === 'document' || !stage?.direction) return project;
- const d = stage.direction;
- const keep = (key, fallback) => text(prior[key]) ? prior[key] : fallback;
+ const recorded = project.productionReview?.seededDraft;
+ const untouched = key => !text(prior[key])
+ || (recorded ? recorded[key] === hash(prior[key]) : looksSeeded(prior[key]));
const draft = { lyricsMode: 'vocal', timingStatus: 'provisional', timingNotes: '', storyboard: [], ...prior,
- cast: keep('cast', describeDirection(d.protagonist)),
- environments: keep('environments', describeDirection(d.sets)),
- visualLanguage: keep('visualLanguage', describeDirection({ look: d.look, palette: d.protagonist?.palette, world: d.world })),
- motionLanguage: keep('motionLanguage', describeDirection({ movement: d.protagonist?.movement, camera: d.world?.camera, transitions: d.world?.transitions })),
guideArtifactId: prior.guideArtifactId || (artifact(project, stage.artifactId) ? stage.artifactId : null) };
- return { ...project, productionReview: { ...project.productionReview, draft } };
+ // Kept outside the strict draft schema: the hash of each field as last seeded.
+ const seededDraft = {};
+ for (const [key, from] of Object.entries(ART_SEEDS)) {
+ if (!untouched(key)) continue;
+ draft[key] = describeDirection(from(stage.direction));
+ seededDraft[key] = hash(draft[key]);
+ }
+ return { ...project, productionReview: { ...project.productionReview, draft, seededDraft } };
}
export function productionReviewBasis(project) {