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
Cast & Sets: apply plain-text feedback to a whole sheet or one image
Claude1e1b1e006ed5
diff --git a/client/src/components/musicVideo/CastAndSetsCheckin.jsx b/client/src/components/musicVideo/CastAndSetsCheckin.jsxindex 7d815671a9..5d0f33dfc9 100644--- a/client/src/components/musicVideo/CastAndSetsCheckin.jsx+++ b/client/src/components/musicVideo/CastAndSetsCheckin.jsx@@ -3,6 +3,7 @@ import LlmRouteNote from './LlmRouteNote.jsx';import Pill from '../ui/Pill.jsx';import { staleApprovalText } from '../../lib/musicVideoStages.js';import CastAndSetsDirectionEditor from './CastAndSetsDirectionEditor.jsx';+import CastAndSetsFeedback from './CastAndSetsFeedback.jsx';import CastAndSetsReferenceProgress from './CastAndSetsReferenceProgress.jsx';const WORKING = new Set(['directing', 'imaging', 'assembling']);@@ -36,8 +37,9 @@ function statusLine(stage) {* Edit direction on a procedural sheet, Resume, Skip). An approved sheet whose* concept, style, subjects or song changed since (`stale`, from the server's* readiness) says what changed and offers Keep approved beside Rebuild (#10141).+ * A sheet in review (or approved) takes plain-text feedback below the actions.*/-export default function CastAndSetsCheckin({ id, project, stale = null, busy, onOpenSheet, onOpenPreview, onApprove, onRegenerate, onEditDirection, onResume, onRebuild, onReconfirm, onRevert, onSkip }) {+export default function CastAndSetsCheckin({ id, project, stale = null, busy, onOpenSheet, onOpenPreview, onApprove, onRegenerate, onEditDirection, onApplyFeedback, onRemoveFeedback, onResume, onRebuild, onReconfirm, onRevert, onSkip }) {const stage = project.castAndSets;if (!stage) return null;const working = WORKING.has(stage.status) && !stage.interrupted;@@ -114,6 +116,9 @@ export default function CastAndSetsCheckin({ id, project, stale = null, busy, on</button>)}</div>+ {onApplyFeedback && stage.direction && !working && ['review', 'approved'].includes(stage.status) && (+ <CastAndSetsFeedback stage={stage} busy={busy} onApply={onApplyFeedback} onRemove={onRemoveFeedback} />+ )}</div>);}diff --git a/client/src/components/musicVideo/CastAndSetsCheckin.test.jsx b/client/src/components/musicVideo/CastAndSetsCheckin.test.jsxindex 0162ca005e..b875b576c3 100644--- a/client/src/components/musicVideo/CastAndSetsCheckin.test.jsx+++ b/client/src/components/musicVideo/CastAndSetsCheckin.test.jsx@@ -7,7 +7,7 @@ import { castAndSetsPreviewItems } from './CastAndSetsReferenceProgress.jsx';const { listeners, api, getMediaJob } = vi.hoisted(() => ({listeners: new Map(),- api: { getMusicVideoProject: vi.fn(), startMusicVideoCastAndSets: vi.fn(), regenerateMusicVideoCastAndSets: vi.fn(), editMusicVideoCastAndSetsDirection: vi.fn(), resumeMusicVideoCastAndSets: vi.fn(), approveMusicVideoCastAndSets: vi.fn(), reconfirmMusicVideoCastAndSets: vi.fn(), revertMusicVideoProductionInput: vi.fn(), skipMusicVideoCastAndSets: vi.fn() },+ api: { getMusicVideoProject: vi.fn(), startMusicVideoCastAndSets: vi.fn(), regenerateMusicVideoCastAndSets: vi.fn(), editMusicVideoCastAndSetsDirection: vi.fn(), resumeMusicVideoCastAndSets: vi.fn(), approveMusicVideoCastAndSets: vi.fn(), reconfirmMusicVideoCastAndSets: vi.fn(), revertMusicVideoProductionInput: vi.fn(), skipMusicVideoCastAndSets: vi.fn(), applyMusicVideoCastAndSetsFeedback: vi.fn(), removeMusicVideoCastAndSetsFeedback: vi.fn() },getMediaJob: vi.fn(),}));vi.mock('../../services/socket', () => ({ default: {@@ -203,6 +203,49 @@ describe('Cast & Sets direction editing', () => {});});+describe('Cast & Sets sheet feedback', () => {+ const direction = { protagonist: { name: 'Keeper' }, sets: [{ id: 'harbor', name: 'Harbor', description: 'a wet quay' }] };+ const sheet = (extra = {}) => ({ id: 'example-project', castAndSets: {+ revision: 1, status: 'review', direction, images: {},+ plan: { 'set:harbor': { key: 'set:harbor', label: 'Harbor', prompt: 'Empty set plate', deps: [], refKeys: [] } },+ ...extra,+ } });++ it('sends whole-sheet feedback, clears the box, and shows what the revision changed', async () => {+ const note = 'Fewer light sources, eighties analog film';+ api.applyMusicVideoCastAndSetsFeedback.mockResolvedValue({ project: sheet({ revision: 2, status: 'directing', feedback: [{ id: 'fb-1', text: note }] }) });+ const view = render(<Harness initial={sheet()} locked={false} />);+ const apply = screen.getByRole('button', { name: 'Apply feedback' });+ expect(apply).toBeDisabled();+ fireEvent.change(screen.getByLabelText('What should change?'), { target: { value: note } });+ await act(async () => { fireEvent.click(apply); });+ expect(api.applyMusicVideoCastAndSetsFeedback).toHaveBeenCalledWith('example-project', { text: note }, { silent: true });+ // Working again: the box waits for the new sheet.+ expect(screen.queryByLabelText('What should change?')).toBeNull();++ await stage(sheet({ revision: 2, feedback: [{ id: 'fb-1', text: note }], changeSummary: { revision: 2, changes: ['Look rewritten for every image', 'Lighting: Harbor'], rerendered: 1 } }));+ expect(screen.getByLabelText('What should change?').value).toBe('');+ expect(screen.getByText(/Revision 2: Look rewritten for every image · Lighting: Harbor · 1 image re-rendered/)).toBeInTheDocument();+ expect(screen.getByText('Standing feedback (1)')).toBeInTheDocument();++ api.removeMusicVideoCastAndSetsFeedback.mockResolvedValue({ project: sheet({ revision: 2, feedback: [] }) });+ await act(async () => { fireEvent.click(screen.getByRole('button', { name: `Stop applying: ${note}` })); });+ expect(api.removeMusicVideoCastAndSetsFeedback).toHaveBeenCalledWith('example-project', 'fb-1', { silent: true });+ expect(screen.queryByText(/Standing feedback/)).toBeNull();+ view.unmount();+ });++ it('aims feedback at one image and keeps the text when the request fails', async () => {+ api.applyMusicVideoCastAndSetsFeedback.mockRejectedValue(new Error('No provider'));+ render(<Harness initial={sheet()} locked={false} />);+ fireEvent.change(screen.getByLabelText('What should change?'), { target: { value: 'One lamp only' } });+ fireEvent.change(screen.getByLabelText('Applies to'), { target: { value: 'set:harbor' } });+ await act(async () => { fireEvent.click(screen.getByRole('button', { name: 'Apply feedback' })); });+ expect(api.applyMusicVideoCastAndSetsFeedback).toHaveBeenCalledWith('example-project', { text: 'One lamp only', target: 'set:harbor' }, { silent: true });+ expect(screen.getByLabelText('What should change?').value).toBe('One lamp only');+ });+});+describe('Cast & Sets tab: undo, regenerate and guide import', () => {const sheet = { id: 'sheet-1', title: 'Check-in sheet', kind: 'cast-sets', version: 1, status: 'approved', mimeType: 'text/html', updatedAt: '2026-01-01T00:00:00Z' };const imported = { id: 'guide-1', title: 'My guide', kind: 'other', version: 1, status: 'pending', mimeType: 'image/png', updatedAt: '2026-01-02T00:00:00Z' };diff --git a/client/src/components/musicVideo/CastAndSetsFeedback.jsx b/client/src/components/musicVideo/CastAndSetsFeedback.jsxnew file mode 100644index 0000000000..d3ec145fa3--- /dev/null+++ b/client/src/components/musicVideo/CastAndSetsFeedback.jsx@@ -0,0 +1,82 @@+import { useState } from 'react';+import { MessageSquare, X } from 'lucide-react';+import AutoSizeTextarea from '../ui/AutoSizeTextarea';+import { formatCount } from '../../utils/formatters.js';++const buttonClass = 'flex items-center gap-1 rounded px-3 py-1.5 text-sm min-h-[44px] sm:min-h-0 disabled:opacity-50';++/**+ * Plain-text feedback on a Cast & Sets sheet. Aimed at the whole sheet, the+ * server rewrites the direction (and the look line every image prompt+ * carries) to honor it, re-renders what changed, and keeps honoring it on+ * later revisions and rebuilds until it is removed here. Aimed at one image,+ * it is that image's revision note. The last revision's change summary shows+ * under the box.+ */+export default function CastAndSetsFeedback({ stage, busy, onApply, onRemove }) {+ const [text, setText] = useState('');+ const [target, setTarget] = useState('');+ const images = Object.values(stage.plan || {});+ const standing = stage.feedback || [];+ const summary = stage.changeSummary?.revision === stage.revision ? stage.changeSummary : null;+ const apply = () => {+ const value = text.trim();+ if (!value) return;+ onApply({ text: value, target: target || null }).then((res) => {+ if (res) { setText(''); setTarget(''); }+ });+ };+ return (+ <div className="min-w-0 space-y-2 rounded border border-port-border bg-port-bg/40 p-2">+ <label htmlFor="mv-cast-feedback" className="block text-xs text-port-text-muted">What should change?</label>+ <AutoSizeTextarea+ id="mv-cast-feedback"+ value={text}+ rows={2}+ maxLength={2000}+ onChange={(e) => setText(e.target.value)}+ placeholder="e.g. Fewer light sources, more like eighties analog film"+ className="min-h-[44px] w-full rounded border border-port-border bg-port-bg px-2 py-1.5 text-sm"+ />+ <div className="flex flex-wrap items-center gap-2">+ {images.length > 0 && (+ <>+ <label htmlFor="mv-cast-feedback-target" className="sr-only">Applies to</label>+ <select id="mv-cast-feedback-target" value={target} onChange={(e) => setTarget(e.target.value)}+ className="min-h-[44px] min-w-0 max-w-full flex-1 rounded border border-port-border bg-port-bg px-2 py-1 text-sm sm:min-h-0 sm:flex-none">+ <option value="">Whole sheet</option>+ {images.map((item) => <option key={item.key} value={item.key}>{item.label || item.key}</option>)}+ </select>+ </>+ )}+ <button type="button" disabled={busy || !text.trim()} onClick={apply} className={`${buttonClass} bg-port-accent text-white`}>+ <MessageSquare size={14} aria-hidden="true" /> Apply feedback+ </button>+ </div>+ {stage.status === 'approved' && <p className="text-xs text-port-text-muted">Applying it re-opens the check-in for review.</p>}+ {summary && (+ <p className="text-xs text-port-text-muted" role="status">+ Revision {stage.revision}: {summary.changes.length ? summary.changes.join(' · ') : 'nothing the images are built from changed'}+ {' · '}{formatCount(summary.rerendered, { fallback: '0' })} {summary.rerendered === 1 ? 'image' : 'images'} re-rendered+ </p>+ )}+ {standing.length > 0 && (+ <details className="text-xs">+ <summary className="cursor-pointer text-port-text-muted">Standing feedback ({formatCount(standing.length)})</summary>+ <ul className="mt-1 space-y-1">+ {standing.map((f) => (+ <li key={f.id} className="flex items-start gap-2">+ <span className="min-w-0 flex-1 break-words">{f.text}</span>+ <button type="button" disabled={busy} onClick={() => onRemove(f.id)} aria-label={`Stop applying: ${f.text}`}+ title="Stop applying this to later revisions"+ className="flex min-h-[44px] min-w-[44px] shrink-0 items-center justify-center text-port-text-muted hover:text-port-error disabled:opacity-50 sm:min-h-0 sm:min-w-0">+ <X size={14} aria-hidden="true" />+ </button>+ </li>+ ))}+ </ul>+ </details>+ )}+ </div>+ );+}diff --git a/client/src/components/musicVideo/stages/CastSetsStage.jsx b/client/src/components/musicVideo/stages/CastSetsStage.jsxindex 078a395ead..8da2968037 100644--- a/client/src/components/musicVideo/stages/CastSetsStage.jsx+++ b/client/src/components/musicVideo/stages/CastSetsStage.jsx@@ -151,6 +151,8 @@ export default function CastSetsStage({ board }) {onApprove={board.approveCastAndSets}onRegenerate={() => castSets.regenerate()}onEditDirection={castSets.editDirection}+ onApplyFeedback={castSets.applyFeedback}+ onRemoveFeedback={castSets.removeFeedback}onResume={() => castSets.resume()}onRebuild={() => castSets.start()}onReconfirm={() => castSets.reconfirm()}diff --git a/client/src/hooks/useMusicVideoCastAndSets.js b/client/src/hooks/useMusicVideoCastAndSets.jsindex 32a3bfb43d..8fb3bbe240 100644--- a/client/src/hooks/useMusicVideoCastAndSets.js+++ b/client/src/hooks/useMusicVideoCastAndSets.js@@ -7,6 +7,8 @@ import {startMusicVideoCastAndSets,regenerateMusicVideoCastAndSets,editMusicVideoCastAndSetsDirection,+ applyMusicVideoCastAndSetsFeedback,+ removeMusicVideoCastAndSetsFeedback,resumeMusicVideoCastAndSets,approveMusicVideoCastAndSets,reconfirmMusicVideoCastAndSets,@@ -34,7 +36,7 @@ const reachedCheckpoint = (stage) => CHECKPOINTS.has(stage?.status) || stage?.in* `interrupted` by a restart), or null when it could not start or the wait was* abandoned with `cancelWait()` (the kickoff's Cancel).*- * Returns `{ busy, start, regenerate, editDirection, resume, approve, reconfirm, skip, runToCheckpoint, cancelWait }`.+ * Returns `{ busy, start, regenerate, editDirection, applyFeedback, removeFeedback, resume, approve, reconfirm, skip, runToCheckpoint, cancelWait }`.*/export default function useMusicVideoCastAndSets({ project, replaceProject } = {}) {const projectId = project?.id || null;@@ -117,6 +119,8 @@ export default function useMusicVideoCastAndSets({ project, replaceProject } = {const start = () => call(() => startMusicVideoCastAndSets(projectId, {}, { silent: true }));const regenerate = (notes) => call(() => regenerateMusicVideoCastAndSets(projectId, notes ? { notes } : {}, { silent: true }), 'Regenerating with your notes');const editDirection = (edits) => call(() => editMusicVideoCastAndSetsDirection(projectId, edits, { silent: true }), 'Direction saved — re-rendering what changed');+ const applyFeedback = ({ text, target = null }) => call(() => applyMusicVideoCastAndSetsFeedback(projectId, { text, ...(target ? { target } : {}) }, { silent: true }), 'Applying your feedback');+ const removeFeedback = (feedbackId) => call(() => removeMusicVideoCastAndSetsFeedback(projectId, feedbackId, { silent: true }));const resume = () => call(() => resumeMusicVideoCastAndSets(projectId, { silent: true }));const approve = () => call(() => approveMusicVideoCastAndSets(projectId, { silent: true }), 'Cast & Sets approved');const reconfirm = () => call(() => reconfirmMusicVideoCastAndSets(projectId, { silent: true }), 'Cast & Sets kept approved');@@ -149,5 +153,5 @@ export default function useMusicVideoCastAndSets({ project, replaceProject } = {w.resolve(null);};- return { busy, start, regenerate, editDirection, resume, approve, reconfirm, skip, runToCheckpoint, cancelWait };+ return { busy, start, regenerate, editDirection, applyFeedback, removeFeedback, resume, approve, reconfirm, skip, runToCheckpoint, cancelWait };}diff --git a/client/src/services/apiMusicVideo.js b/client/src/services/apiMusicVideo.jsindex 1a226f5947..f9bdebe2f5 100644--- a/client/src/services/apiMusicVideo.js+++ b/client/src/services/apiMusicVideo.js@@ -478,6 +478,12 @@ export const regenerateMusicVideoCastAndSets = (id, body = {}, options = {}) =>// Body: { protagonist?, world?, sets?: [{ id, imageRole }] } — the director's direct edits to a procedural direction.export const editMusicVideoCastAndSetsDirection = (id, body, options = {}) =>request(`/music-video/${encodeURIComponent(id)}/cast-and-sets/direction`, { method: 'PATCH', body: JSON.stringify(body), ...options });+// Body: { text, target? } — plain-text feedback on the sheet. No target = the whole+// sheet (standing feedback the direction keeps honoring); a target names one image.+export const applyMusicVideoCastAndSetsFeedback = (id, body, options = {}) =>+ request(`/music-video/${encodeURIComponent(id)}/cast-and-sets/feedback`, { method: 'POST', body: JSON.stringify(body), ...options });+export const removeMusicVideoCastAndSetsFeedback = (id, feedbackId, options = {}) =>+ request(`/music-video/${encodeURIComponent(id)}/cast-and-sets/feedback/${encodeURIComponent(feedbackId)}`, { method: 'DELETE', ...options });export const resumeMusicVideoCastAndSets = (id, options = {}) =>request(`/music-video/${encodeURIComponent(id)}/cast-and-sets/resume`, { method: 'POST', body: '{}', ...options });export const approveMusicVideoCastAndSets = (id, options = {}) =>diff --git a/server/lib/hostControlRoutes.js b/server/lib/hostControlRoutes.jsindex a25a1df275..fbb25637bb 100644--- a/server/lib/hostControlRoutes.js+++ b/server/lib/hostControlRoutes.js@@ -445,6 +445,7 @@ export const HOST_CONTROL_ROUTES = Object.freeze(['POST /api/music-video/:id/cast-and-sets','POST /api/music-video/:id/cast-and-sets/regenerate','PATCH /api/music-video/:id/cast-and-sets/direction',+ 'POST /api/music-video/:id/cast-and-sets/feedback','POST /api/music-video/:id/cast-and-sets/resume','POST /api/music-video/:id/code/generate','POST /api/music-video/:id/code/sections/:sectionId/regenerate',diff --git a/server/lib/hostControlRoutes.test.js b/server/lib/hostControlRoutes.test.jsindex c781676d71..60638b3b91 100644--- a/server/lib/hostControlRoutes.test.js+++ b/server/lib/hostControlRoutes.test.js@@ -469,6 +469,7 @@ describe('Music Video agent workflow policy (#9869)', () => {'POST /api/music-video/:id/cast-and-sets','POST /api/music-video/:id/cast-and-sets/regenerate','PATCH /api/music-video/:id/cast-and-sets/direction',+ 'POST /api/music-video/:id/cast-and-sets/feedback','POST /api/music-video/:id/cast-and-sets/resume','POST /api/music-video/:id/code/generate','POST /api/music-video/:id/code/sections/:sectionId/regenerate',diff --git a/server/lib/musicVideoValidation.js b/server/lib/musicVideoValidation.jsindex d1f033aad4..a5efa09d44 100644--- a/server/lib/musicVideoValidation.js+++ b/server/lib/musicVideoValidation.js@@ -1164,6 +1164,16 @@ export const musicVideoCastAndSetsRegenerateSchema = z.object({effort: z.enum(EFFORT_LEVELS).optional(),}).strict();+// Plain-text feedback on a Cast & Sets sheet. No target = the whole sheet+// (standing feedback the direction keeps honoring); a target names one image.+export const musicVideoCastAndSetsFeedbackSchema = z.object({+ text: devArtifactNoteText,+ target: devArtifactNoteTarget,+ providerId: z.string().min(1).max(64).optional(),+ model: z.string().min(1).max(200).optional(),+ effort: z.enum(EFFORT_LEVELS).optional(),+}).strict();+// Direct edits to a procedural direction. A present text field replaces the// current value (empty clears it); an absent one keeps it.const castSetsText = (max) => z.string().max(max);diff --git a/server/routes/hostControlMediaAuthoring.test.js b/server/routes/hostControlMediaAuthoring.test.jsindex 0a0cc3c67b..4f237ed496 100644--- a/server/routes/hostControlMediaAuthoring.test.js+++ b/server/routes/hostControlMediaAuthoring.test.js@@ -131,6 +131,7 @@ vi.mock('../services/musicVideo/castAndSetsService.js', () => ({regenerateCastAndSets: vi.fn(async () => ({ status: 'running' })),editCastAndSetsDirection: vi.fn(async () => ({ status: 'running' })),resumeCastAndSets: vi.fn(async () => ({ status: 'running' })),+ applyCastAndSetsFeedback: vi.fn(async () => ({ status: 'running' })),}));import { authGate, hostControlRouteGate } from '../services/authGate.js';@@ -153,7 +154,7 @@ import { generateMusicVideoCode, regenerateMusicVideoCodeSection } from '../servimport { generateMixedMediaDocument, reviseMixedMediaEvents, regenerateMixedMediaSection } from '../services/musicVideo/documentGeneration.js';import { startAutoReview, resumeAutoReview } from '../services/musicVideo/autoReviewService.js';import { startProduction, resumeProduction } from '../services/musicVideo/productionService.js';-import { startCastAndSets, regenerateCastAndSets, editCastAndSetsDirection, resumeCastAndSets } from '../services/musicVideo/castAndSetsService.js';+import { startCastAndSets, regenerateCastAndSets, editCastAndSetsDirection, resumeCastAndSets, applyCastAndSetsFeedback } from '../services/musicVideo/castAndSetsService.js';let ownerSession;const id = '00000000-0000-4000-8000-000000000001';@@ -178,6 +179,7 @@ const musicVideoAuthoring = [[`/api/music-video/${id}/cast-and-sets/regenerate`, { ...picker }, regenerateCastAndSets, 202, 'post'],[`/api/music-video/${id}/cast-and-sets/direction`, { protagonist: { movement: 'Example movement' } }, editCastAndSetsDirection, 202, 'patch'],[`/api/music-video/${id}/cast-and-sets/resume`, { ...picker }, resumeCastAndSets, 202, 'post'],+ [`/api/music-video/${id}/cast-and-sets/feedback`, { text: 'Fewer light sources', ...picker }, applyCastAndSetsFeedback, 202, 'post'],[`/api/music-video/${id}/code/generate`, { ...picker }, generateMusicVideoCode, 200, 'post'],[`/api/music-video/${id}/code/sections/example-section/regenerate`, { ...picker }, regenerateMusicVideoCodeSection, 200, 'post'],[`/api/music-video/${id}/composition/document/generate`, { ...picker }, generateMixedMediaDocument, 201, 'post'],diff --git a/server/routes/musicVideo.js b/server/routes/musicVideo.jsindex 4f22dc22d9..4af17b6f46 100644--- a/server/routes/musicVideo.js+++ b/server/routes/musicVideo.js@@ -80,6 +80,7 @@ import {musicVideoDevArtifactFileQuerySchema,musicVideoCastAndSetsStartSchema,musicVideoCastAndSetsDirectionEditSchema,+ musicVideoCastAndSetsFeedbackSchema,musicVideoCastAndSetsRegenerateSchema,musicVideoDocumentDirectoryImportSchema,musicVideoDocumentFileQuerySchema,@@ -201,6 +202,8 @@ import { devArtifactTypeFor } from '../services/musicVideo/devArtifacts.js';import {startCastAndSets,editCastAndSetsDirection,+ applyCastAndSetsFeedback,+ removeCastAndSetsFeedbackEntry,regenerateCastAndSets,resumeCastAndSets,approveCastAndSets,@@ -1419,6 +1422,15 @@ router.patch('/:id/cast-and-sets/direction', asyncHandler(async (req, res) => {res.status(202).json(await editCastAndSetsDirection(req.params.id, input));}));+router.post('/:id/cast-and-sets/feedback', asyncHandler(async (req, res) => {+ const input = validateRequest(musicVideoCastAndSetsFeedbackSchema, req.body || {});+ res.status(202).json(await applyCastAndSetsFeedback(req.params.id, input));+}));++router.delete('/:id/cast-and-sets/feedback/:feedbackId', asyncHandler(async (req, res) => {+ res.json(await removeCastAndSetsFeedbackEntry(req.params.id, req.params.feedbackId));+}));+router.post('/:id/cast-and-sets/resume', asyncHandler(async (req, res) => {const input = validateRequest(musicVideoCastAndSetsStartSchema, req.body || {});res.status(202).json(await resumeCastAndSets(req.params.id, input));diff --git a/server/services/musicVideo/castAndSets.js b/server/services/musicVideo/castAndSets.jsindex 70b7efcb6d..abaac02f61 100644--- a/server/services/musicVideo/castAndSets.js+++ b/server/services/musicVideo/castAndSets.js@@ -18,6 +18,8 @@* images: { [key]: { status, jobId, imageId, history, failures, error, updatedAt,* submittedPrompt?, submittedPromptTruncated?, submittedReferences?, submittedRevision? } },* artifactId, artifactVersion, notesApplied,+ * feedback, // [{ id, text, at, revision }]: standing sheet feedback every direction call honors+ * changeSummary, // { revision, changes: [string], rerendered, at }: what the last revision changed* createdAt, updatedAt, approvedAt,* approvedInputs, // labeled input hashes the approval rests on (productionReview.js); absent on legacy approvals* approvedValues, // capped approved values of the revertible inputs, keyed like approvedInputs; absent = not revertible@@ -100,6 +102,8 @@ export function startCastAndSetsOnProject(project, { processId, productionRunIdartifactId: current?.artifactId || null,artifactVersion: current?.artifactVersion || null,notesApplied: [],+ // Standing feedback outlives a rebuild: the fresh direction still honors it.+ feedback: current?.feedback || [],createdAt: current?.createdAt || now,approvedAt: null,};@@ -131,6 +135,26 @@ export function reviseCastAndSetsOnProject(project, { processId, notesApplied =}, now);}+const MAX_FEEDBACK = 12;++/**+ * Add one piece of standing sheet feedback (newest last, capped). Returns+ * `{ project, stage, entry }`; the caller revises the stage in the same write.+ */+export function addCastAndSetsFeedback(project, { id, text }, now = new Date().toISOString()) {+ const stage = requireStage(project);+ const entry = { id, text: trimTo(String(text || ''), 2000), at: now, revision: (stage.revision || 0) + 1 };+ const feedback = [...(stage.feedback || []), entry].slice(-MAX_FEEDBACK);+ return { ...write(project, { ...stage, feedback }, now), entry };+}++/** Stop honoring one piece of standing feedback. Nothing re-renders. Returns `{ project, stage }`. */+export function removeCastAndSetsFeedback(project, feedbackId, now = new Date().toISOString()) {+ const stage = requireStage(project);+ if (!(stage.feedback || []).some((f) => f.id === feedbackId)) throw stageError(404, 'NOT_FOUND', 'That feedback is not on this check-in');+ return write(project, { ...stage, feedback: stage.feedback.filter((f) => f.id !== feedbackId) }, now);+}+/** Re-pin an interrupted working stage to this process. Returns `{ project, stage }`. */export function resumeCastAndSetsOnProject(project, { processId }, now = new Date().toISOString()) {const stage = requireStage(project);diff --git a/server/services/musicVideo/castAndSetsDirection.js b/server/services/musicVideo/castAndSetsDirection.jsindex 68d16c952f..6eacfe59f9 100644--- a/server/services/musicVideo/castAndSetsDirection.js+++ b/server/services/musicVideo/castAndSetsDirection.js@@ -199,7 +199,7 @@ const PROCEDURAL_OUTPUT_SHAPE = `{* (all optional). With `previous` + `notes` it becomes a revision request.* `medium` defaults to the previous direction's, else the project's.*/-export function buildCastAndSetsPrompt(project, { moodImages = [], board = null, track = null, previous = null, notes = [], medium = null } = {}) {+export function buildCastAndSetsPrompt(project, { moodImages = [], board = null, track = null, previous = null, notes = [], medium = null, feedback = [] } = {}) {// A saved direction without a medium predates the procedural one: photographic.const procedural = (medium || (previous ? (previous.medium || 'photographic') : castAndSetsMedium(project))) === 'procedural';const concept = project?.concept || {};@@ -271,6 +271,16 @@ export function buildCastAndSetsPrompt(project, { moodImages = [], board = null,].join('\n');const rules = procedural ? proceduralRules : photographicRules;+ // The director's standing sheet feedback: every direction call honors it,+ // a fresh rebuild included, and it rewrites the look line every image+ // prompt carries (`look` in the answer) instead of being pasted onto prompts.+ const standing = (Array.isArray(feedback) ? feedback : []).map((f) => trimTo(f?.text, FEEDBACK_TEXT)).filter(Boolean);+ const standingBlock = standing.length ? [+ 'DIRECTOR FEEDBACK ON EARLIER SHEETS (always honor it; where it disagrees with the mood board or visual style, the feedback wins):',+ ...standing.map((t) => `- ${t}`),+ 'Carry it into every field it touches (each set\'s description and lighting, the looks, the protagonist), and write "look": one line, under 400 characters, of the look every image prompt carries (film stock, light quality and sources, grain, color), rewritten so it agrees with this feedback.',+ ].join('\n') : '';+const revision = previous ? ['This is a REVISION. The current direction is:',JSON.stringify(previous),@@ -287,11 +297,18 @@ export function buildCastAndSetsPrompt(project, { moodImages = [], board = null,sectionLines.length ? `Song sections (index. label start–end):\n${sectionLines.join('\n')}` : 'The song has not been sectioned.',board_,rules,+ standingBlock,revision,- `Respond with ONLY one JSON object in this shape (replace every <…> with real content; do NOT output the angle-bracket text), no other text:\n${procedural ? PROCEDURAL_OUTPUT_SHAPE : OUTPUT_SHAPE}`,+ `Respond with ONLY one JSON object in this shape (replace every <…> with real content; do NOT output the angle-bracket text), no other text:\n${withLookField(procedural ? PROCEDURAL_OUTPUT_SHAPE : OUTPUT_SHAPE, standing.length > 0)}`,].filter(Boolean).join('\n\n');}+const FEEDBACK_TEXT = 2000;+// Only a direction call carrying standing feedback is asked for its own look line.+const withLookField = (shape, wanted) => (wanted+ ? shape.replace('"logline":', '"look": "<one line: film stock, light quality and sources, grain, color, agreeing with the director feedback>",\n "logline":')+ : shape);+// ---- parsing ----------------------------------------------------------------const isPlaceholder = (s) => typeof s === 'string' && /^\s*<.+>\s*$/.test(s);@@ -367,6 +384,7 @@ const overlaySchema = z.union([// One lenient parser per field: a field that does not fit its shape counts as// absent (the merge keeps the current value) rather than failing the answer.const FIELD_PARSERS = {+ look: text(500),logline: text(TEXT),interpretation: text(2000),protagonist: protagonistSchema,@@ -582,3 +600,43 @@ export function applyCastAndSetsDirectionEdits(previous, edits, { sections = []];return { direction: { ...direction, look: previous.look || '' }, changed };}++// ---- what a revision changed -------------------------------------------------++const MAX_CHANGE_LINES = 8;+const nameList = (names) => (names.length > 3 ? `${names.slice(0, 3).join(', ')} and ${names.length - 3} more` : names.join(', '));++/**+ * A short, plain-language list of what a revised direction changed, for the+ * director to read after feedback is applied: the look line, the protagonist,+ * the wardrobe, and per-set lighting/description. Empty when nothing the+ * images are built from changed.+ */+export function describeDirectionChanges(previous, next) {+ if (!previous || !next) return [];+ const same = (a, b) => JSON.stringify(a ?? '') === JSON.stringify(b ?? '');+ const out = [];+ if (!same(previous.look, next.look)) out.push('Look rewritten for every image');+ const p0 = previous.protagonist || {};+ const p1 = next.protagonist || {};+ const protagonistFields = Object.keys({ ...p0, ...p1 }).filter((k) => !same(p0[k], p1[k]));+ if (protagonistFields.length) out.push(`Protagonist: ${nameList(protagonistFields)}`);+ if (!same(previous.looks, next.looks)) out.push('Wardrobe looks revised');+ if (!same(previous.world?.lighting, next.world?.lighting)) out.push('World lighting revised');+ const before = new Map((previous.sets || []).map((s) => [s.id, s]));+ const lit = [];+ const described = [];+ for (const set of next.sets || []) {+ const old = before.get(set.id);+ if (!old) continue;+ if (!same(old.lighting, set.lighting)) lit.push(set.name);+ if (!same(old.description, set.description)) described.push(set.name);+ }+ if (lit.length) out.push(`Lighting: ${nameList(lit)}`);+ if (described.length) out.push(`Set descriptions: ${nameList(described)}`);+ const added = (next.sets || []).filter((s) => !before.has(s.id)).map((s) => s.name);+ const removed = (previous.sets || []).filter((s) => !(next.sets || []).some((n) => n.id === s.id)).map((s) => s.name);+ if (added.length) out.push(`New sets: ${nameList(added)}`);+ if (removed.length) out.push(`Sets dropped: ${nameList(removed)}`);+ return out.slice(0, MAX_CHANGE_LINES);+}diff --git a/server/services/musicVideo/castAndSetsService.js b/server/services/musicVideo/castAndSetsService.jsindex ca1e942e66..da33bf6836 100644--- a/server/services/musicVideo/castAndSetsService.js+++ b/server/services/musicVideo/castAndSetsService.js@@ -46,7 +46,9 @@ import {dispatchableImageKeys,linkCastAndSetsJob,presentCastAndSets,+ addCastAndSetsFeedback,reconfirmCastAndSetsOnProject,+ removeCastAndSetsFeedback,reserveCastAndSetsImage,resumeCastAndSetsOnProject,reviseCastAndSetsOnProject,@@ -60,6 +62,7 @@ import {buildCastAndSetsPrompt,castAndSetsAllowsImages,castAndSetsMedium,+ describeDirectionChanges,mergeCastAndSetsDirection,moodBoardImageList,parseCastAndSetsResponse,@@ -191,7 +194,10 @@ async function runDirection(projectId, { providerId, model, effort, notes = [],// silently re-cast into the other medium.// A saved direction without a medium predates the procedural one: photographic.const medium = notes.length && previous ? (previous.medium || 'photographic') : castAndSetsMedium(project);- const prompt = buildCastAndSetsPrompt(project, { moodImages, board, track, previous: notes.length ? previous : null, notes, medium }) + productionFeedbackContext(project);+ // Standing sheet feedback rides on every direction call, a fresh rebuild included.+ const feedback = stage?.feedback || [];+ const standing = feedback.length > 0;+ const prompt = buildCastAndSetsPrompt(project, { moodImages, board, track, previous: notes.length ? previous : null, notes, medium, feedback }) + productionFeedbackContext(project);let text;try {({ text } = await deps.runPrompt({ provider, model: selectedModel, ...effortArg(route), prompt, source: 'music-video-cast-sets' }));@@ -206,13 +212,16 @@ async function runDirection(projectId, { providerId, model, effort, notes = [],if (missing.length) return fail(projectId, `The creative direction answer is missing: ${missing.join(', ')}`);// The photographic look every image prompt carries: the mood board's composed// style, else the project's visual style (never the board's literal places).- direction.look = trimTo(board?.style?.prompt, 500) || trimTo(project.concept?.style, 500) || previous?.look || '';+ // While the director's sheet feedback stands, the direction's own look line+ // (rewritten to agree with it) wins over both.+ const baseLook = trimTo(board?.style?.prompt, 500) || trimTo(project.concept?.style, 500);+ direction.look = (standing && parsed.look) || (standing && previous?.look) || baseLook || previous?.look || '';// Mood board images inform the direction as text only, never as image references.- return writePlan(projectId, { direction, forceKeys });+ return writePlan(projectId, { direction, forceKeys, changes: previous ? describeDirectionChanges(previous, direction) : null });}/** (Re)build the plan from the stage's direction + accumulated per-image notes, then dispatch. */-async function writePlan(projectId, { direction = null, forceKeys = [] } = {}) {+async function writePlan(projectId, { direction = null, forceKeys = [], changes = null } = {}) {const project = await requireProject(projectId);const stage = project.castAndSets;const nextDirection = direction || stage.direction;@@ -226,9 +235,14 @@ async function writePlan(projectId, { direction = null, forceKeys = [] } = {}) {const preferred = run?.pool?.find((r) => r.kind === 'image') || stage.route || null;const route = codeOnly ? (stage.route || null) : await chooseCastAndSetsRoute(project, { preferred, settings });if (!route && !codeOnly) return fail(projectId, 'No enabled image backend is allowed for the Cast & Sets images — enable Codex (or another image tool in the brief) and resume');- const out = await mutateProjectRecord(projectId, (current) => setCastAndSetsDirection(current, {- direction: nextDirection, plan, route, renderKeys,- }));+ const out = await mutateProjectRecord(projectId, (current) => {+ const next = setCastAndSetsDirection(current, { direction: nextDirection, plan, route, renderKeys });+ if (!changes) return next;+ // What this revision changed, for the director to read beside the new sheet.+ const changeSummary = { revision: next.stage.revision, changes, rerendered: renderKeys.length, at: next.stage.updatedAt };+ const stage = { ...next.stage, changeSummary };+ return { project: { ...next.project, castAndSets: stage }, stage };+ });console.log(`🎭 Music Video Cast & Sets ${short(projectId)} r${out.stage.revision}: ${renderKeys.length} image(s) to render${route ? ` on ${route.mode}` : ' (code-only, no image backend)'}`);publish(projectId, out.project);return advance(projectId);@@ -648,6 +662,44 @@ export async function regenerateCastAndSets(projectId, { notes = null, providerIreturn { project: out.project, stage: presentCastAndSets(out.stage, PROCESS_ID) };}+/**+ * Apply the director's plain-text feedback on the sheet. Aimed at one image+ * (`target`: `character`, `looks`, `set:<id>`, a set's name, …) it is that+ * image's revision note (see regenerateCastAndSets). Aimed at the whole sheet+ * (no target) it becomes STANDING feedback: the direction is rewritten to+ * honor it, including the look line every image prompt carries, and every+ * later direction call (a rebuild included) keeps honoring it until the+ * director removes it. Only images whose prompt changed re-render.+ * Returns `{ project, stage }`.+ */+export async function applyCastAndSetsFeedback(projectId, { text, target = null, providerId, model, effort } = {}) {+ const project = await requireProject(projectId);+ const stage = project.castAndSets;+ if (!stage?.direction) throw new ServerError('There is no Cast & Sets sheet to give feedback on yet', { status: 409, code: 'CAST_SETS_NO_DIRECTION' });+ if (target) {+ if (!noteImageKeys(target, stage.plan || {})) throw new ServerError(`No image on this sheet is called ${target}`, { status: 422, code: 'CAST_SETS_UNKNOWN_IMAGE' });+ return regenerateCastAndSets(projectId, { notes: [{ target, text }], providerId, model, effort });+ }+ const note = { id: null, target: 'sheet', text };+ const out = await mutateProjectRecord(projectId, (current) => {+ const added = addCastAndSetsFeedback(current, { id: `fb-${randomUUID().slice(0, 8)}`, text });+ return reviseCastAndSetsOnProject(added.project, { processId: PROCESS_ID, notesApplied: [note], redirect: true });+ });+ console.log(`🎭 Music Video Cast & Sets ${short(projectId)} applying sheet feedback r${out.stage.revision} (${out.stage.feedback.length} standing)`);+ publish(projectId, out.project);+ inBackground('The feedback', projectId, () => runDirection(projectId, { providerId, model, effort, notes: [note] }));+ return { project: out.project, stage: presentCastAndSets(out.stage, PROCESS_ID) };+}++/** Stop honoring one piece of standing sheet feedback. Nothing re-renders until the next revision. Returns `{ project, stage }`. */+export async function removeCastAndSetsFeedbackEntry(projectId, feedbackId) {+ await requireProject(projectId);+ const out = await mutateProjectRecord(projectId, (current) => removeCastAndSetsFeedback(current, feedbackId));+ console.log(`🎭 Music Video Cast & Sets ${short(projectId)} feedback removed (${out.stage.feedback.length} standing)`);+ publish(projectId, out.project);+ return { project: out.project, stage: presentCastAndSets(out.stage, PROCESS_ID) };+}+/*** Save the director's direct edits to a procedural direction (construction,* palette, expressions, movement, world rules, per-set image role) through thediff --git a/server/services/musicVideo/castAndSetsService.test.js b/server/services/musicVideo/castAndSetsService.test.jsindex 500ad475a1..d559ea5a49 100644--- a/server/services/musicVideo/castAndSetsService.test.js+++ b/server/services/musicVideo/castAndSetsService.test.js@@ -461,6 +461,70 @@ describe('Cast & Sets check-in', () => {expect(after.castAndSets.images.character.history).toHaveLength(1);});+ it('applies sheet feedback by rewriting the direction and look, re-renders what changed, and keeps honoring it on a rebuild', async () => {+ const project = await seed();+ await request(app).post(`/api/music-video/${project.id}/cast-and-sets`).send({});+ await runTo(project.id, 'review');+ const before = jobs.length;+ const look = '1980s 35mm analog film, sparse practical light, heavy grain';+ const revised = { ...DIRECTION, look, sets: DIRECTION.sets.map((set) => (set.id === 'harbor' ? { ...set, lighting: 'one dim sodium streetlamp' } : set)) };+ runPrompt.mockResolvedValueOnce({ text: JSON.stringify(revised) });+ const note = 'Too many random light sources; keep them sparse and realistic, eighties analog film';++ const applied = await request(app).post(`/api/music-video/${project.id}/cast-and-sets/feedback`).send({ text: note });+ expect(applied.status).toBe(202);+ await runTo(project.id, 'review');+ const revisionPrompt = runPrompt.mock.calls[1][0].prompt;+ expect(revisionPrompt).toContain('DIRECTOR FEEDBACK ON EARLIER SHEETS');+ expect(revisionPrompt).toContain(note);+ expect(revisionPrompt).toContain('"look":');+ const after = await current(project.id);+ expect(after.castAndSets.direction.look).toBe(look);+ // The look line changed, so every image re-renders on the rewritten prompt, never the board's look.+ const rerendered = jobs.slice(before);+ expect(new Set(rerendered.map(keyOf))).toEqual(new Set(Object.keys(after.castAndSets.plan)));+ for (const job of rerendered) {+ expect(job.params.prompt).toContain(`Look: ${look}`);+ expect(job.params.prompt).not.toContain('raw flash, green light');+ }+ expect(after.castAndSets.changeSummary).toMatchObject({ revision: 2, rerendered: rerendered.length });+ expect(after.castAndSets.changeSummary.changes).toEqual(['Look rewritten for every image', 'Lighting: Harbor']);+ expect(after.castAndSets.feedback).toEqual([expect.objectContaining({ text: note, revision: 2 })]);++ // Approve, then rebuild: the fresh direction still carries the standing feedback and its look.+ await request(app).post(`/api/music-video/${project.id}/cast-and-sets/approve`).send({});+ runPrompt.mockResolvedValueOnce({ text: JSON.stringify(revised) });+ await request(app).post(`/api/music-video/${project.id}/cast-and-sets`).send({});+ await runTo(project.id, 'review');+ expect(runPrompt.mock.calls[2][0].prompt).toContain(note);+ expect((await current(project.id)).castAndSets.direction.look).toBe(look);++ // Removing it stops it riding on later calls; nothing re-renders now.+ const queued = jobs.length;+ const feedbackId = (await current(project.id)).castAndSets.feedback[0].id;+ const removed = await request(app).delete(`/api/music-video/${project.id}/cast-and-sets/feedback/${feedbackId}`);+ expect(removed.status).toBe(200);+ expect(removed.body.stage.feedback).toEqual([]);+ expect(jobs.length).toBe(queued);+ });++ it('applies feedback aimed at one image as that image\'s note, and refuses an image the sheet does not have', async () => {+ const project = await seed();+ await request(app).post(`/api/music-video/${project.id}/cast-and-sets`).send({});+ await runTo(project.id, 'review');+ const before = jobs.length;+ const applied = await request(app).post(`/api/music-video/${project.id}/cast-and-sets/feedback`).send({ text: 'One lamp only', target: 'set:harbor' });+ expect(applied.status).toBe(202);+ await runTo(project.id, 'review');+ expect(runPrompt).toHaveBeenCalledTimes(1);+ expect(jobs.slice(before).map(keyOf).sort()).toEqual(['set:harbor', 'test:2']);+ expect(jobs.find((j) => keyOf(j) === 'set:harbor' && !jobs.slice(0, before).includes(j)).params.prompt).toMatch(/Revision: One lamp only/);+ expect((await current(project.id)).castAndSets.feedback || []).toEqual([]);++ const unknown = await request(app).post(`/api/music-video/${project.id}/cast-and-sets/feedback`).send({ text: 'Brighter', target: 'set:nowhere' });+ expect([unknown.status, unknown.body.code]).toEqual([422, 'CAST_SETS_UNKNOWN_IMAGE']);+ });+it('approves itself in auto mode, and fails with a reason when no provider can direct', async () => {const auto = await seed({ automation: { tools: ['image:codex'], checkins: { castAndSets: 'auto' } } });await request(app).post(`/api/music-video/${auto.id}/cast-and-sets`).send({});