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
Keep every render made for a music video in its collection (#11264)
[._.]/6bd4d8dfed74
diff --git a/client/src/components/imageGen/ImageGenFormEditor.jsx b/client/src/components/imageGen/ImageGenFormEditor.jsxindex 7b73cfee91..e381dc2112 100644--- a/client/src/components/imageGen/ImageGenFormEditor.jsx+++ b/client/src/components/imageGen/ImageGenFormEditor.jsx@@ -4,6 +4,7 @@ import UniverseStylePicker from '../media/UniverseStylePicker';import PromptEnhancer from '../media/PromptEnhancer';import PromptFromMedia from '../media/PromptFromMedia';import RemoteMediaTargetPicker from '../federatedMedia/RemoteMediaTargetPicker';+import MusicVideoFilingSelect from '../media/MusicVideoFilingSelect';import { FormField } from '../ui/FormField';import Banner from '../ui/Banner';import AutoSizeTextarea from '../ui/AutoSizeTextarea';@@ -131,6 +132,8 @@ export default function ImageGenFormEditor({ form, backend, generation }) {)}</div>+ <MusicVideoFilingSelect id="image-gen-music-video" />+{(loraTest.pending || loraTest.error) && (<Banner tone={loraTest.error ? 'error' : 'info'}><p>{loraTest.error || 'Preparing this LoRA test…'}</p>diff --git a/client/src/components/media/MusicVideoFilingSelect.jsx b/client/src/components/media/MusicVideoFilingSelect.jsxnew file mode 100644index 0000000000..036a7339d2--- /dev/null+++ b/client/src/components/media/MusicVideoFilingSelect.jsx@@ -0,0 +1,43 @@+import { useEffect, useState } from 'react';+import { useSearchParams } from 'react-router';+import { listMusicVideoProjectSummaries } from '../../services/apiMusicVideo.js';+import { MUSIC_VIDEO_FILING_PARAM } from '../../lib/musicVideoFiling.js';++/**+ * "For music video" picker on the Image Gen and Video Gen forms: the render+ * also lands in the picked video's collection, with or without a shot. The+ * pick lives in the URL (`musicVideo`), set too by a handoff from one of the+ * video's clips, so the form sends what the picker shows.+ */+export default function MusicVideoFilingSelect({ id = 'media-gen-music-video', disabled = false }) {+ const [searchParams, setSearchParams] = useSearchParams();+ const value = searchParams.get(MUSIC_VIDEO_FILING_PARAM) || '';+ const [projects, setProjects] = useState([]);+ useEffect(() => {+ let active = true;+ listMusicVideoProjectSummaries({ limit: 100 }, { silent: true })+ .then((page) => { if (active) setProjects(page?.items || []); })+ .catch(() => {});+ return () => { active = false; };+ }, []);+ const pick = (projectId) => setSearchParams((previous) => {+ const next = new URLSearchParams(previous);+ if (projectId) next.set(MUSIC_VIDEO_FILING_PARAM, projectId);+ else next.delete(MUSIC_VIDEO_FILING_PARAM);+ return next;+ }, { replace: true });+ if (!value && projects.length === 0) return null;+ const listed = projects.some((project) => project.id === value);+ return (+ <div className="flex min-w-0 items-center gap-2">+ <label htmlFor={id} className="shrink-0 text-xs text-gray-400">Music video <span className="text-gray-500">(Optional)</span></label>+ <select id={id} value={value} onChange={(e) => pick(e.target.value)} disabled={disabled}+ title="Also keep this render in the music video's collection"+ className="min-w-0 flex-1 bg-port-bg border border-port-border rounded px-2 py-1 text-sm min-h-[44px] sm:min-h-0">+ <option value="">None</option>+ {value && !listed && <option value={value}>This music video</option>}+ {projects.map((project) => <option key={project.id} value={project.id}>{project.name || 'Untitled'}</option>)}+ </select>+ </div>+ );+}diff --git a/client/src/components/media/MusicVideoFilingSelect.test.jsx b/client/src/components/media/MusicVideoFilingSelect.test.jsxnew file mode 100644index 0000000000..b566e71a64--- /dev/null+++ b/client/src/components/media/MusicVideoFilingSelect.test.jsx@@ -0,0 +1,31 @@+import { describe, it, expect, vi } from 'vitest';+import { fireEvent, render, screen } from '@testing-library/react';+import { MemoryRouter, useLocation } from 'react-router';+import MusicVideoFilingSelect from './MusicVideoFilingSelect';++vi.mock('../../services/apiMusicVideo.js', () => ({+ listMusicVideoProjectSummaries: vi.fn(async () => ({ items: [{ id: 'mv-a', name: 'Example Video' }, { id: 'mv-b', name: 'Second Video' }] })),+}));++function Search() {+ return <output data-testid="search">{useLocation().search}</output>;+}++// Uniquely catches the picker showing one video while the form files the render under another (the URL is what is sent).+describe('MusicVideoFilingSelect', () => {+ it('shows the video handed over in the URL and keeps the URL in step with a new pick', async () => {+ render(+ <MemoryRouter initialEntries={['/video/generate?musicVideo=mv-a']}>+ <MusicVideoFilingSelect />+ <Search />+ </MemoryRouter>,+ );+ const select = await screen.findByLabelText(/Music video/);+ await screen.findByRole('option', { name: 'Second Video' });+ expect(select.value).toBe('mv-a');+ fireEvent.change(select, { target: { value: 'mv-b' } });+ expect(screen.getByTestId('search').textContent).toBe('?musicVideo=mv-b');+ fireEvent.change(select, { target: { value: '' } });+ expect(screen.getByTestId('search').textContent).toBe('');+ });+});diff --git a/client/src/hooks/useImageGenPageRuntime.js b/client/src/hooks/useImageGenPageRuntime.jsindex 46915b2643..5d659b4503 100644--- a/client/src/hooks/useImageGenPageRuntime.js+++ b/client/src/hooks/useImageGenPageRuntime.js@@ -31,6 +31,7 @@ import {listMediaJobs,regenerateGalleryImage,} from '../services/api';+import { musicVideoFilingFields } from '../lib/musicVideoFiling';const IMAGE_QUEUE_EVENTS = ['media-jobs:changed'];@@ -291,6 +292,7 @@ export function useImageGenPageRuntime() {cleanC2PA: fields.cleanC2PA,denoise: fields.denoise,};+ Object.assign(payload, musicVideoFilingFields(searchParams));const hasInitImage = derived.i2iCapable && images.initImage.source != null;const hasReferenceImages = derived.populatedRefs.length > 0;if (hasInitImage || hasReferenceImages) {@@ -414,6 +416,7 @@ export function useImageGenPageRuntime() {denoise: fields.denoise,};if (fields.seed && Number(fields.seed) >= 0) payload.seed = Number(fields.seed);+ Object.assign(payload, musicVideoFilingFields(searchParams));const data = await generateImage(payload, { silent: true });setResult({...data,diff --git a/client/src/hooks/useMediaPreviewActions.js b/client/src/hooks/useMediaPreviewActions.jsindex 345bd8f7ca..3d24c84715 100644--- a/client/src/hooks/useMediaPreviewActions.js+++ b/client/src/hooks/useMediaPreviewActions.js@@ -4,6 +4,7 @@ import toast from '../components/ui/Toast';import { cleanGalleryImage, extractLastFrame, removeImageWatermark } from '../services/apiImageVideo';import { normalizeVideoTiling } from '../lib/videoTilingOptions';import { hydrateMediaItem } from '../components/media/mediaDetail';+import { MUSIC_VIDEO_FILING_PARAM, musicVideoOf } from '../lib/musicVideoFiling';// Handoffs that copy a record's prompt/settings into a generator form read the// FULL record: a compact gallery item (#8292) only holds a prompt preview, so@@ -44,9 +45,11 @@ function buildImageGenParams(item) {// placeholder for items that lost theirs — skip it so the next render doesn't// start with that literal, and an item we never generated lands on a blank// prompt rather than a bogus one. The caller adds `sourceImageFile`, which is-// the only thing that differs between the two.+// the only thing that differs between the two. A clip made for a music video+// hands the video on, so the next render lands in its collection too.function buildVideoGenParams(item) {const params = new URLSearchParams();+ if (musicVideoOf(item)) params.set(MUSIC_VIDEO_FILING_PARAM, musicVideoOf(item));if (item.prompt && item.prompt !== '(no prompt)') params.set('prompt', item.prompt);const neg = item.negativePrompt || item.raw?.negativePrompt || item.raw?.negative_prompt;if (neg) params.set('negativePrompt', neg);@@ -101,7 +104,8 @@ export default function useMediaPreviewActions({ onCleanComplete = null } = {})if (!item) return;if (item.kind === 'video') {if (item.id != null && item.id !== '') {- navigate(`/media/video?remix=${encodeURIComponent(item.id)}`);+ const projectId = musicVideoOf(item);+ navigate(`/media/video?remix=${encodeURIComponent(item.id)}${projectId ? `&${MUSIC_VIDEO_FILING_PARAM}=${encodeURIComponent(projectId)}` : ''}`);return;}const params = new URLSearchParams();diff --git a/client/src/hooks/useMediaPreviewActions.test.jsx b/client/src/hooks/useMediaPreviewActions.test.jsxindex 092d3ece0e..ad679e8cc5 100644--- a/client/src/hooks/useMediaPreviewActions.test.jsx+++ b/client/src/hooks/useMediaPreviewActions.test.jsx@@ -212,6 +212,18 @@ describe('useMediaPreviewActions.handleContinue', () => {expect(params.get('sourceImageFile')).toBe('last.png');expect(params.get('prompt')).toBeNull();});++ // Uniquely catches a re-render of a music video's clip falling out of that video's collection.+ it('hands on the music video a clip was made for, on Continue and Remix', async () => {+ extractLastFrame.mockResolvedValue({ filename: 'last.png' });+ const clip = { kind: 'video', id: 'vid-3', prompt: 'a neon alley', raw: { musicVideo: { projectId: 'mv-example', sceneId: null } } };+ const { result } = renderHook(() => useMediaPreviewActions());+ await result.current.handleContinue(clip);+ expect(parseNav().params.get('musicVideo')).toBe('mv-example');+ result.current.handleRemix(clip);+ expect(parseNav().params.get('remix')).toBe('vid-3');+ expect(parseNav().params.get('musicVideo')).toBe('mv-example');+ });});// A compact gallery row (#8292) carries only a prompt preview; every handoffdiff --git a/client/src/lib/README.md b/client/src/lib/README.mdindex 8de66c5aa3..93d90a4634 100644--- a/client/src/lib/README.md+++ b/client/src/lib/README.md@@ -60,6 +60,7 @@ grep -i "what you want to do" client/src/lib/README.md| `beatColors.js` | `BEAT_KIND_COLORS` + `getBeatKindColor(kind)` — per-kind display colors for reader-map emotional beats (kinds defined server-side in `storyArc.js`). Keeps every beat visualization consistent. || `beatGrid.js` | Music-video beat-quantized timeline arranger (#1854). `buildBeatGridPoints(audioAnalysis)` merges beats/downbeats/section edges into one ranked snap-point list; `snapTimeToGrid(timeSec, gridPoints, toleranceSec)` finds the nearest point within tolerance; `computeSceneSpans(scenes, durationSec)` lays out scenes without a persisted `startSec`/`endSec` contiguously as a display-only fallback; `computeDragSpan({kind, startSpan, deltaSec, gridPoints, ...})` resolves a timeline drag gesture (`'move'` or `'right'` — no `'left'`, since the render can only trim from a clip's own frame 0) into a new span; `shouldMarkBeatAligned({kind, snapped, wasPersisted})` gates the `beatAligned` flag so a reposition-only drag can't silently promote an unpersisted scene's placeholder fallback duration into a "saved exactly" render duration; `autoArrangeScenes(scenes, audioAnalysis)` proposes a full `{ sceneId, startSec, endSec, beatAligned }[]` arrangement by distributing scenes across song sections weighted by each section's `energy` (#1915). Used by `components/musicVideo/BeatTimeline.jsx` and `pages/MusicVideo.jsx`. || `musicVideoAspect.js` | Re-export of `server/lib/musicVideoAspect.js`: `musicVideoAspect`, `musicVideoFrameGenSize`. Used by `hooks/useMusicVideoSceneMedia.js` so board frames match the project aspect. |+| `musicVideoFiling.js` | Which music video an Image Gen / Video Gen render is for: `MUSIC_VIDEO_FILING_PARAM` (the `musicVideo` URL param), `musicVideoFilingFields(searchParams)` (the `musicVideoProjectId` request field), `musicVideoOf(item)` (a record's video). Used by `components/media/MusicVideoFilingSelect.jsx`, `hooks/useMediaPreviewActions.js` and the two generate pages. || `musicVideoMotion.js` | Re-export of `server/lib/musicVideoMotion.js` (`MOTION_CONTINUITY_CLAUSE`) for board motion prompts. || `musicVideoBatchPlan.js` | Pure helpers for the Music Video missing-frame / missing-clip batches (#10153): `videoBatchPreview` (count + fal estimate summed from `falSceneTake`, unpriced count), `scenesWaitingForFrame`, `videosButtonLabel`, `batchSummary`, `batchActive`, `batchSceneName`. Used by `components/musicVideo/ProjectActionGroups.jsx`. || `musicVideoLayers.js` | Music-video per-scene visual layers (#8985), re-exported from `server/lib/musicVideoLayers.js`: `MUSIC_VIDEO_VISUAL_LAYERS`, `MUSIC_VIDEO_STILL_MOVES`, `MUSIC_VIDEO_TEXT_ZONES` / `MUSIC_VIDEO_LYRIC_ROLES` (#10583 lyric type per shot), `sceneVisualLayer(scene, { layered })`, `sceneHasAuthoredSpan`, `sceneRenderReady(scene, { layered })`. Used by `components/musicVideo/SceneCard.jsx`, `ProjectActionGroups.jsx` and `hooks/useMusicVideoSceneMedia.js`. |diff --git a/client/src/lib/index.js b/client/src/lib/index.jsindex 5df65a4566..05344cd1b8 100644--- a/client/src/lib/index.js+++ b/client/src/lib/index.js@@ -71,6 +71,7 @@ export * from './muscriptorModels.js';export * from './musicVideoBatchPlan.js';export * from './musicVideoLayers.js';export * from './musicVideoAspect.js';+export * from './musicVideoFiling.js';export * from './musicVideoMotion.js';export * from './musicVideoTakes.js';export * from './musicVideoSceneAttention.js';diff --git a/client/src/lib/musicVideoFiling.js b/client/src/lib/musicVideoFiling.jsnew file mode 100644index 0000000000..0034851467--- /dev/null+++ b/client/src/lib/musicVideoFiling.js@@ -0,0 +1,21 @@+/**+ * Which music video an Image Gen or Video Gen render is made for. The forms+ * keep it in the `musicVideo` URL param, so it survives a reload and rides a+ * handoff from one of the video's clips (Remix, Continue, a trim), and send it+ * as `musicVideoProjectId`: the server files the render into that video's+ * collection even when no shot keeps it.+ */++export const MUSIC_VIDEO_FILING_PARAM = 'musicVideo';++/** The request fields that file a render into the video named in the URL. */+export function musicVideoFilingFields(searchParams) {+ const projectId = searchParams?.get(MUSIC_VIDEO_FILING_PARAM);+ return projectId ? { musicVideoProjectId: projectId } : {};+}++/** The music video a gallery item or history record was made for, if any. */+export function musicVideoOf(item) {+ const projectId = (item?.raw || item)?.musicVideo?.projectId;+ return typeof projectId === 'string' && projectId ? projectId : null;+}diff --git a/client/src/pages/VideoGen.jsx b/client/src/pages/VideoGen.jsxindex ac7d7096bc..d96b383c04 100644--- a/client/src/pages/VideoGen.jsx+++ b/client/src/pages/VideoGen.jsx@@ -104,6 +104,8 @@ import { REACTOR_MAX_PROMPT_LENGTH } from '../lib/reactorVideoClip.js';import { videoGenEnqueuePolicy } from '../lib/videoGenEnqueuePolicy.js';import { styledVideoPrompt } from '../lib/videoGenSubmission.js';import ReactorPanel from '../components/videoGen/ReactorPanel';+import MusicVideoFilingSelect from '../components/media/MusicVideoFilingSelect';+import { MUSIC_VIDEO_FILING_PARAM, musicVideoFilingFields, musicVideoOf } from '../lib/musicVideoFiling';import { formatCount, formatUsd, timeAgo } from '../utils/formatters';import ResolutionField from '../components/media/ResolutionField';import { VIDEO_EDGE_BOUNDS, videoEdgeBoundsForModel, IC_LORA_MODES } from '../lib/videoGenParams.js';@@ -484,8 +486,11 @@ export default function VideoGen() {const raw = item?.raw || item;if (!raw) return;applyRemix(raw);+ // A clip made for a music video keeps its remix in that video's collection.+ const projectId = musicVideoOf(raw);+ if (projectId) setSearchParams((prev) => { const n = new URLSearchParams(prev); n.set(MUSIC_VIDEO_FILING_PARAM, projectId); return n; }, { replace: true });window.scrollTo({ top: 0, behavior: 'smooth' });- }, [applyRemix]);+ }, [applyRemix, setSearchParams]);// Cross-page Remix (#6290). Media History (and every other MediaPreview// surface) hands this page a RECORD ID rather than a render-settings bundle,@@ -872,6 +877,9 @@ export default function VideoGen() {});};+ // The form's request plus the music video it is filed under, if one is picked.+ const generatePayload = () => ({ ...buildGeneratePayload(), ...musicVideoFilingFields(searchParams) });+const handleGenerate = async (e) => {e?.preventDefault?.();if (generating) {@@ -883,7 +891,7 @@ export default function VideoGen() {// be pointing at a lapsed peer — re-derive at the moment of commit and say// so, rather than letting the peer reject a render already paid for.if (!verifyRemoteTarget()) return;- await runGeneration(buildGeneratePayload()).catch(() => {});+ await runGeneration(generatePayload()).catch(() => {});};const verifyRemoteTarget = () => {@@ -904,7 +912,7 @@ export default function VideoGen() {// including any multipart uploads, and the appropriate lane can start it// without waiting for this tab's active SSE render.if (!verifyRemoteTarget()) return;- await generateVideo(buildGeneratePayload())+ await generateVideo(generatePayload()).then((data) => {const position = Number.isInteger(data?.position) ? ` (position ${data.position})` : '';toast.success(`Queued${position}`);@@ -1810,6 +1818,8 @@ export default function VideoGen() {default — see ImageGenTab's videoGenDisplaySleep) — a GPU-watchdogcrash on this model is rare enough that most renders shouldn't pay forthe mitigation, but the option needs to be one click away right here. */}+ <MusicVideoFilingSelect id="video-gen-music-video" disabled={generating} />+{canSleepDisplay && (<label htmlFor="video-gen-display-sleep" className="flex items-start gap-2 text-xs text-gray-400 cursor-pointer"><inputdiff --git a/client/src/test/imageGenPageMocks.jsx b/client/src/test/imageGenPageMocks.jsxindex d9e5f36f2c..45f57c08b7 100644--- a/client/src/test/imageGenPageMocks.jsx+++ b/client/src/test/imageGenPageMocks.jsx@@ -215,6 +215,8 @@ vi.mock('../hooks/useModelDownloadStatus', () => ({vi.mock('../hooks/useHfTokenStatus', () => ({useHfTokenStatus: () => ({ present: state.hfTokenPresent, refresh: vi.fn() }),}));+// The music-video picker lists projects over the network; its own suite covers it.+vi.mock('../components/media/MusicVideoFilingSelect', () => ({ default: () => null }));vi.mock('../hooks/useAgyModels', () => ({ useAgyModels: () => ({ models: [], error: null }) }));vi.mock('../hooks/useMediaCompletionRefresh', () => ({ useMediaCompletionRefresh: vi.fn() }));vi.mock('../hooks/useMediaAnnotations', () => ({diff --git a/client/src/test/videoGenPageMocks.jsx b/client/src/test/videoGenPageMocks.jsxindex 8eca1155a7..1ac7afd1ad 100644--- a/client/src/test/videoGenPageMocks.jsx+++ b/client/src/test/videoGenPageMocks.jsx@@ -291,6 +291,8 @@ vi.mock('../components/videoGen/VideoGenGallery', () => ({default: (props) => { state.galleryProps = props; return null; },}));vi.mock('../components/media/MediaPreview', () => ({ default: () => null }));+// The music-video picker lists projects over the network; its own suite covers it.+vi.mock('../components/media/MusicVideoFilingSelect', () => ({ default: () => null }));vi.mock('../components/media/StylePresetPicker', () => ({ default: () => null }));vi.mock('../components/media/MediaJobsQueue', () => ({ default: () => null }));vi.mock('../components/imageGen/LoraPicker', () => ({diff --git a/server/lib/backupAssetOwners.js b/server/lib/backupAssetOwners.jsindex f5921da2e9..0203f3f0e2 100644--- a/server/lib/backupAssetOwners.js+++ b/server/lib/backupAssetOwners.js@@ -34,6 +34,7 @@ export const BACKUP_ASSET_OWNERS = Object.freeze([{ id: 'music-take-publication', status: 'admitted', modules: ['services/musicTakePublication.js'] },{ id: 'media-job-completion', status: 'admitted', modules: ['services/mediaJobQueue/index.js'] },{ id: 'media-job-attach-hooks', status: 'admitted', modules: ['services/mediaJobImageHook.js'] },+ { id: 'music-video-collection-hook', status: 'admitted', modules: ['services/musicVideoCollectionHook.js'] },{id: 'pipeline-filename-hooks',status: 'admitted',diff --git a/server/routes/imageGen.js b/server/routes/imageGen.jsindex 9e19318ae5..cda3be9056 100644--- a/server/routes/imageGen.js+++ b/server/routes/imageGen.js@@ -239,6 +239,11 @@ const generateSchema = z.object({// (an `endImage` take) instead of its start frame.slot: z.enum(['end']).optional(),}).optional(),+ // File the render into this music video's media collection even when no shot+ // keeps it (sheets, tests, alternates): musicVideoCollectionHook for the+ // queued lanes, inline below for the synchronous one. Collection only; the+ // render itself is unchanged.+ musicVideoProjectId: z.string().min(1).max(200).optional(),// Durable catalog attach (#1359). When present, the mediaJobQueue completion// hook (catalogImageAttachHook) files the finished render onto this catalog// ingredient even if the page that started the render has since unmounted —@@ -698,6 +703,10 @@ router.post('/generate', imageGenUploads, asyncHandler(async (req, res) => {await assertRevisionOpen(params.musicVideo.projectId, params.musicVideo.revisionId, { sceneId: params.musicVideo.sceneId, kind: 'image' });}const result = await imageGen.generateImage(params);+ if (params.musicVideoProjectId && result?.filename) {+ const { fileIntoMusicVideoCollection } = await import('../services/musicVideoCollectionHook.js');+ await fileIntoMusicVideoCollection(params.musicVideoProjectId, [{ kind: 'image', ref: result.filename }]);+ }if (params.fableLoom && result?.filename) {await attachNodeImage(params.fableLoom.loomId,diff --git a/server/routes/musicVideoTakes.test.js b/server/routes/musicVideoTakes.test.jsindex 38d137e369..5ef1d1b430 100644--- a/server/routes/musicVideoTakes.test.js+++ b/server/routes/musicVideoTakes.test.js@@ -281,3 +281,30 @@ describe('swapping a shot from unused takes', () => {expect((await reload()).scenes.find((scene) => scene.sceneId === sceneA.sceneId).referenceImageId).toBe('b-2.png');});});++describe('renders made for a video with no shot', () => {+ // Uniquely catches a sheet, test or Video Gen render for the video (no shot keeps it) missing from its collection and the picker.+ it('files completed renders naming the video, and clips stamped with it, into its collection', async () => {+ const { mediaJobEvents } = await import('../services/mediaJobQueue/index.js');+ const hook = await import('../services/musicVideoCollectionHook.js');+ hook.__testing.reset();+ hook.initMusicVideoCollectionHook();+ seedImage('sheet.png');+ seedImage('frame.png');+ seedVideoHistory([{ id: 'test-clip' }, { id: 'trimmed-copy', musicVideo: { projectId: project.id, sceneId: null } }, { id: 'other-clip' }]);+ mediaJobEvents.emit('completed', { kind: 'image', id: 'job-sheet', params: { musicVideo: { projectId: project.id, castAndSets: { key: 'cast:lead' } } }, result: { filename: 'sheet.png' } });+ mediaJobEvents.emit('completed', { kind: 'video', id: 'test-clip', params: { musicVideoProjectId: project.id, sourceImagePath: '/abs/images/frame.png' }, result: { generationId: 'test-clip' } });+ mediaJobEvents.emit('completed', { kind: 'video', id: 'other-clip', params: {}, result: { generationId: 'other-clip' } });+ mediaJobEvents.emit('completed', { kind: 'image', id: 'job-gone', params: { musicVideoProjectId: 'mv-missing' }, result: { filename: 'frame.png' } });+ await hook.__testing.drain();+ hook.__testing.reset();++ const { getCollection, musicVideoCollectionId } = await import('../services/mediaCollections.js');+ const filed = async () => (await getCollection(musicVideoCollectionId(project.id))).items.map((item) => `${item.kind}:${item.ref}`).sort();+ expect(await filed()).toEqual(['image:sheet.png', 'video:test-clip']);++ const pool = (await request(app).get(`${base()}/media-pool`)).body.items;+ expect(await filed()).toEqual(['image:sheet.png', 'video:test-clip', 'video:trimmed-copy']);+ expect(pool.find((item) => item.assetId === 'test-clip')).toMatchObject({ kind: 'video', sceneId: null, sourceImageId: 'frame.png' });+ });+});diff --git a/server/routes/videoGen.js b/server/routes/videoGen.jsindex a7caf2f9ee..3354167913 100644--- a/server/routes/videoGen.js+++ b/server/routes/videoGen.js@@ -483,6 +483,9 @@ const generateBodySchema = z.object({revisionId: z.string().min(1).max(200).optional(),}).optional(),),+ // File the clip into this music video's media collection even when no shot+ // keeps it (musicVideoCollectionHook). Collection only; the render is unchanged.+ musicVideoProjectId: z.string().min(1).max(200).optional(),// FableLoom scene-video render. The media-job completion hook files the// finished history id onto the tagged loom node, even if the editor has// unmounted. Video requests are multipart, so parse the JSON tag beforediff --git a/server/services/bootstrap.js b/server/services/bootstrap.jsindex 1c1408c9f3..d496c8ebed 100644--- a/server/services/bootstrap.js+++ b/server/services/bootstrap.js@@ -152,6 +152,7 @@ import { initFableLoomSceneImageHook } from './fableLoomSceneImageHook.js';import { initFableLoomSceneVideoHook } from './fableLoomSceneVideoHook.js';import { initMusicVideoSceneImageHook } from './musicVideoSceneImageHook.js';import { initMusicVideoSceneVideoHook } from './musicVideoSceneVideoHook.js';+import { initMusicVideoCollectionHook } from './musicVideoCollectionHook.js';import { initMusicVideoCastSetsImageHook } from './musicVideoCastSetsImageHook.js';import { initMusicVideoCoverArtImageHook } from './musicVideoCoverArtImageHook.js';import { initCreativeDirectorMusicBedHook } from './creativeDirectorMusicBedHook.js';@@ -697,6 +698,9 @@ const initMediaJobDependentHooks = () => {// Music Video scene-video hook — durably files a queued i2v scene clip onto// its project scene's `videoHistoryId` on completion (#1760 Phase 1).initMusicVideoSceneVideoHook();+ // Music Video collection hook — files every render that names a music video+ // (a shot's, Cast & Sets, or a tagged Image/Video Gen request) into its collection.+ initMusicVideoCollectionHook();// Music Video Cast & Sets hook — files a queued check-in reference image// (character sheet, looks, set plates, in-set tests) onto its stage key.// It only listens: nothing is generated at boot.diff --git a/server/services/musicVideo/mediaPool.js b/server/services/musicVideo/mediaPool.jsindex 964f14c7bc..cb0d70631c 100644--- a/server/services/musicVideo/mediaPool.js+++ b/server/services/musicVideo/mediaPool.js@@ -3,10 +3,11 @@* kept in the project's own media collection (`mvc-<projectId>`) so nothing a* shot drops is lost, and listed for the shot card's "Swap from unused" picker.*- * Filing happens when a take lands (projects.js appendSceneTakes), when a+ * Filing happens when a take lands (projects.js appendSceneTakes), when any+ * render naming the video completes (musicVideoCollectionHook.js), when a* change drops takes from the board (a cut shot, a merge, a re-plan, a pruned* take), and on every pool read, which also backfills whatever the project- * already holds. A clip's still is kept on its video history entry+ * already holds and every clip stamped with it. A clip's still is kept on its video history entry* (`musicVideo.sourceImageId`), so a clip on the floor still pairs with its* still after the shot that held both is gone.*/@@ -138,12 +139,15 @@ async function stampClipProvenance(clips) {* gallery or history) is left out rather than shown as a broken tile.*/export async function getMusicVideoMediaPool(project) {- await fileMusicVideoMedia(project, projectTakeAssets(project));const [{ getCollection, musicVideoCollectionId }, { loadHistory }, { resolveGalleryImage }] = await Promise.all([import('../mediaCollections.js'), import('../videoGen/history.js'), import('../../lib/pathSafety.js'),]);- const collection = await getCollection(musicVideoCollectionId(project.id)).catch(() => null);const history = new Map((await loadHistory()).filter((entry) => entry?.id).map((entry) => [entry.id, entry]));+ // A clip stamped with this video (a trim or upscale of one of its clips copies the stamp) belongs here too.+ const stamped = [...history.values()].filter((entry) => entry.musicVideo?.projectId === project.id)+ .map((entry) => ({ kind: 'video', ref: entry.id }));+ await fileMusicVideoMedia(project, [...projectTakeAssets(project), ...stamped]);+ const collection = await getCollection(musicVideoCollectionId(project.id)).catch(() => null);const items = buildMediaPool(project, collection?.items || [], history).filter((item) => (item.kind === 'video' ? history.has(item.assetId) : Boolean(resolveGalleryImage(item.assetId))))// A partner that is gone is not offered, so "Use … + its still|clip" always works.diff --git a/server/services/musicVideoCollectionHook.js b/server/services/musicVideoCollectionHook.jsnew file mode 100644index 0000000000..f266014d7a--- /dev/null+++ b/server/services/musicVideoCollectionHook.js@@ -0,0 +1,74 @@+/**+ * Music Video collection hook: every image and clip rendered for a music video+ * lands in that video's media collection (`mvc-<projectId>`), not only the+ * ones a shot keeps as a take. A shot's render files through its take+ * (projects.js appendSceneTakes); this hook also covers renders with no shot:+ * Cast & Sets images, cover art, and Image Gen / Video Gen requests that name+ * the video with `musicVideoProjectId` (the forms send it when opened from a+ * music video's clip, and agents pass it for tests, sheets and alternates).+ * Filing is idempotent, so a shot render filed by both paths lands once.+ *+ * Best-effort bookkeeping: a failure is logged, never thrown. Mounted once at+ * server boot; it only listens.+ */++import { basename } from 'path';+import { mediaJobEvents } from './mediaJobQueue/index.js';+import { withBackupAssetPublication } from '../lib/backupSnapshotBoundary.js';+import { createKeyCachedQueue } from '../lib/createKeyCachedQueue.js';++/** The project and asset a completed job files, or null when it names no music video. */+function musicVideoCollectionTarget(job) {+ if (job?.kind !== 'image' && job?.kind !== 'video') return null;+ const params = job.params || {};+ const projectId = params.musicVideoProjectId || params.musicVideo?.projectId;+ if (typeof projectId !== 'string' || !projectId) return null;+ const ref = job.kind === 'image' ? job.result?.filename : (job.result?.generationId || job.id);+ if (typeof ref !== 'string' || !ref) return null;+ const sourceImageId = job.kind === 'video' && typeof params.sourceImagePath === 'string' ? basename(params.sourceImagePath) : null;+ return {+ projectId,+ asset: { kind: job.kind, ref, sceneId: params.musicVideo?.sceneId || null, take: sourceImageId ? { sourceImageId } : null },+ };+}++/** File assets into a project's collection by id; a project that is gone files nothing. */+export async function fileIntoMusicVideoCollection(projectId, assets) {+ const [{ getProject }, { fileMusicVideoMedia }] = await Promise.all([+ import('./musicVideo/projects.js'), import('./musicVideo/mediaPool.js'),+ ]);+ const project = await getProject(projectId).catch(() => null);+ if (!project) return false;+ await fileMusicVideoMedia(project, assets);+ return true;+}++const serialize = createKeyCachedQueue();+const inFlight = new Set();+let completedHandler = null;++export function initMusicVideoCollectionHook() {+ if (completedHandler) return;+ completedHandler = (job) => {+ const target = musicVideoCollectionTarget(job);+ if (!target) return;+ const handled = withBackupAssetPublication(() => serialize(target.projectId,+ () => fileIntoMusicVideoCollection(target.projectId, [target.asset])))+ .catch((err) => console.error(`❌ music-video collection hook failed for ${target.projectId}: ${err?.message || err}`));+ inFlight.add(handled);+ handled.finally(() => inFlight.delete(handled));+ };+ mediaJobEvents.on('completed', completedHandler);+ console.log('🗂️ Music Video collection hook initialized');+}++export const __testing = {+ reset() {+ if (completedHandler) mediaJobEvents.off('completed', completedHandler);+ completedHandler = null;+ serialize.clear();+ },+ async drain() {+ while (inFlight.size > 0) await Promise.allSettled([...inFlight]);+ },+};diff --git a/server/services/videoGen/submitJob.js b/server/services/videoGen/submitJob.jsindex 16337d2592..d69fd040dc 100644--- a/server/services/videoGen/submitJob.js+++ b/server/services/videoGen/submitJob.js@@ -389,6 +389,7 @@ const submitValidatedVideoGenJob = async (body, uploads) => {const { remoteMedia, audio } = prepared;const { jobId, position, status } = await enqueue({prompt: body.prompt, remoteMedia, ...(body.musicVideo ? { musicVideo: body.musicVideo } : {}),+ ...(body.musicVideoProjectId ? { musicVideoProjectId: body.musicVideoProjectId } : {}),...(body.musicVideo && prepared.sourceImagePath ? { sourceImagePath: prepared.sourceImagePath } : {}),...(body.musicVideo ? { ...remoteMedia.request } : {}),...(audio ? { audioConditioning: audio.audioConditioning, uploadedTempPaths: [audio.audioFilePath],@@ -418,6 +419,7 @@ const submitValidatedVideoGenJob = async (body, uploads) => {uploadedTempPath,...(body.musicVideo ? { musicVideo: body.musicVideo } : {}),...(body.fableLoom ? { fableLoom: body.fableLoom } : {}),+ ...(body.musicVideoProjectId ? { musicVideoProjectId: body.musicVideoProjectId } : {}),...(body.visualConditioning ? { visualConditioning: body.visualConditioning } : {}),...hosted.buildParams(body, prepared),...(projectAspect ? { aspectRatio: projectAspect, frameAspect: projectAspect } : {}),@@ -499,6 +501,7 @@ const submitValidatedVideoGenJob = async (body, uploads) => {icSkipStage2: isTruthyMeta(body.icSkipStage2),...(body.musicVideo ? { musicVideo: body.musicVideo } : {}),...(body.fableLoom ? { fableLoom: body.fableLoom } : {}),+ ...(body.musicVideoProjectId ? { musicVideoProjectId: body.musicVideoProjectId } : {}),...(body.visualConditioning ? { visualConditioning: body.visualConditioning } : {}),...localPerformanceParams,});