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

Stop the art draft reseed from rewriting entered text

Claudede95414d30cc
diff --git a/server/services/musicVideo/castAndSetsService.test.js b/server/services/musicVideo/castAndSetsService.test.js
index 586f13d770..ca11a68475 100644
--- a/server/services/musicVideo/castAndSetsService.test.js
+++ b/server/services/musicVideo/castAndSetsService.test.js
@@ -426,20 +426,31 @@ describe('Cast & Sets check-in', () => {
expect(draft.motionLanguage).toBe(first.motionLanguage);
});
- it('reseeds a legacy seeded draft with no seed record but keeps typed notes', async () => {
+ it('never rewrites entered text, keeps equivalent text as written, and lets it follow a newer revision', 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.
+ // Entered by hand (no seed record): the current cast as compact JSON in another key
+ // order, and JSON that differs from the direction.
+ const { name, ...rest } = DIRECTION.protagonist;
+ const sameCast = JSON.stringify({ ...rest, name });
+ const ownSets = JSON.stringify([{ name: 'My own set' }]);
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) } } } }));
+ productionReview: { draft: { cast: sameCast, environments: ownSets } } } }));
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');
+ // Re-preparing the review seeds again; it must not reformat anything.
+ expect((await request(app).post(`/api/music-video/${project.id}/production-review/prepare`).send({})).status).toBe(200);
+ let draft = (await current(project.id)).productionReview.draft;
+ expect(draft.cast).toBe(sameCast);
+ expect(draft.environments).toBe(ownSets);
+
+ runPrompt.mockResolvedValue({ text: JSON.stringify({ ...DIRECTION, protagonist: { ...DIRECTION.protagonist, name: 'Signalman' } }) });
+ 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({});
+ draft = (await current(project.id)).productionReview.draft;
+ expect(draft.cast).toContain('Signalman');
+ expect(draft.environments).toBe(ownSets);
});
it.each(['approved', 'skipped'])('rebuilds a %s check-in as a new revision that keeps the prior sheet as an earlier version', async (end) => {
diff --git a/server/services/musicVideo/productionReview.js b/server/services/musicVideo/productionReview.js
index f03e25b66c..a366013fe4 100644
--- a/server/services/musicVideo/productionReview.js
+++ b/server/services/musicVideo/productionReview.js
@@ -68,35 +68,44 @@ const ART_SEEDS = {
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; }
+// Equal content in any formatting: JSON compares by value (key order and
+// whitespace ignored), plain text by its trimmed string.
+const parsedJson = value => {
+ if (!/^[[{]/.test(value.trim())) return undefined;
+ try { return JSON.parse(value); } catch { return undefined; }
+};
+const sameContent = (a, b) => {
+ const [x, y] = [parsedJson(a), parsedJson(b)];
+ return x !== undefined && y !== undefined ? hash(x) === hash(y) : a.trim() === b.trim();
};
/**
* 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.
+ * sheet. A blank field, or one still holding the exact text an earlier approval
+ * seeded, follows the newest direction. Text that already says what the
+ * direction says is kept as written (rewriting its formatting would stale an
+ * art approval for nothing), and any other text the director or an agent
+ * entered — and a guide already chosen — is never overwritten. 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 recorded = project.productionReview?.seededDraft;
- const untouched = key => !text(prior[key])
- || (recorded ? recorded[key] === hash(prior[key]) : looksSeeded(prior[key]));
+ const recorded = project.productionReview?.seededDraft || {};
const draft = { lyricsMode: 'vocal', timingStatus: 'provisional', timingNotes: '', storyboard: [], ...prior,
guideArtifactId: prior.guideArtifactId || (artifact(project, stage.artifactId) ? stage.artifactId : null) };
// Kept outside the strict draft schema: the hash of each field as last seeded.
+ // A field absent here was entered by hand and is never rewritten.
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]);
+ const seed = describeDirection(from(stage.direction));
+ const current = text(prior[key]) ? prior[key] : null;
+ if (current && sameContent(current, seed)) seededDraft[key] = hash(current);
+ else if (!current || recorded[key] === hash(current)) {
+ draft[key] = seed;
+ seededDraft[key] = hash(seed);
+ }
}
return { ...project, productionReview: { ...project.productionReview, draft, seededDraft } };
}