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
Autopilot can start a new video on an existing project's song
Claude3f266926e2ab
diff --git a/client/src/components/musicVideo/AutonomousRunPanel.test.jsx b/client/src/components/musicVideo/AutonomousRunPanel.test.jsxindex 44d0fff58f..88421ee9aa 100644--- a/client/src/components/musicVideo/AutonomousRunPanel.test.jsx+++ b/client/src/components/musicVideo/AutonomousRunPanel.test.jsx@@ -20,6 +20,7 @@ vi.mock('../../services/apiMusicVideo.js', () => ({resumeAutonomousMusicVideo: vi.fn(),stopAutonomousMusicVideo: vi.fn(),cancelAutonomousMusicVideo: vi.fn(),+ listMusicVideoProjectSummaries: vi.fn(async () => ({ items: [{ id: 'mv-src', name: 'Example Song', trackId: 'track-src' }, { id: 'mv-silent', name: 'No audio yet', trackId: null }] })),listMusicVideoCharacterStyles: vi.fn(async () => [{ id: 'example-style', label: 'Example style', characterName: 'Example Performer', referenceImageId: null }]),}));vi.mock('../../services/apiMoodBoard.js', () => ({ listMoodBoardNames: vi.fn(async () => [{ id: 'mb-1', name: 'Neon Rain' }]) }));@@ -329,6 +330,24 @@ describe('AutonomousStartDrawer', () => {});});+ // Uniquely catches the reuse choice not reaching the request, or song-making options still showing for it.+ it('starts on another project\'s song: sends its id, hides the song-making options and their checkpoints', async () => {+ api.startAutonomousMusicVideo.mockResolvedValue({ project: { id: 'mv-new' }, run: baseRun() });+ render(<AutonomousStartDrawer open onClose={() => {}} onStarted={() => {}} />);+ fireEvent.change(screen.getByLabelText('Prompt'), { target: { value: 'p' } });+ fireEvent.click(screen.getByLabelText('Lyrics', { selector: '#mv-auto-checkpoint-lyrics' }));+ await waitFor(() => expect(screen.getByRole('option', { name: 'Use the song from Example Song' })).toBeTruthy());+ expect(screen.queryByRole('option', { name: 'Use the song from No audio yet' })).toBeNull();+ fireEvent.change(screen.getByLabelText('Song to use'), { target: { value: 'mv-src' } });+ expect(screen.queryByLabelText('Song source')).toBeNull();+ expect(screen.queryByLabelText('Instrumental (no vocals)')).toBeNull();+ expect(document.querySelector('#mv-auto-checkpoint-lyrics')).toBeNull();+ fireEvent.change(screen.getByLabelText('Code authoring provider'), { target: { value: 'fixture-api' } });+ fireEvent.click(screen.getByRole('button', { name: /start autonomous video/i }));+ await waitFor(() => expect(api.startAutonomousMusicVideo).toHaveBeenCalled());+ expect(api.startAutonomousMusicVideo.mock.calls[0][0]).toMatchObject({ fromProjectId: 'mv-src', checkpoints: [] });+ });+it('sends the Suno form options only when set, and blocks an unrecognizable model version', async () => {api.startAutonomousMusicVideo.mockResolvedValue({ project: { id: 'mv-new' }, run: baseRun() });render(<AutonomousStartDrawer open onClose={() => {}} onStarted={() => {}} />);diff --git a/client/src/components/musicVideo/AutonomousStartDrawer.jsx b/client/src/components/musicVideo/AutonomousStartDrawer.jsxindex da4c690aca..37a18e6fd9 100644--- a/client/src/components/musicVideo/AutonomousStartDrawer.jsx+++ b/client/src/components/musicVideo/AutonomousStartDrawer.jsx@@ -9,13 +9,14 @@ import ToolPicker from './ToolPicker.jsx';import MoodBoardPicker from './MoodBoardPicker.jsx';import CharacterStyleSelect from './CharacterStyleSelect.jsx';import SongSourcePicker from './SongSourcePicker.jsx';+import ExistingSongSelect from './ExistingSongSelect.jsx';import ProviderModelSelector from '../ProviderModelSelector.jsx';import MusicVideoLlmStagesPicker from './MusicVideoLlmStagesPicker.jsx';import toast from '../ui/Toast';import useProviderModels from '../../hooks/useProviderModels.js';import { startAutonomousMusicVideo } from '../../services/apiMusicVideo.js';import {- AUTONOMOUS_CHECKPOINT_IDS, AUTONOMOUS_CHECKPOINT_LABELS, AUTONOMOUS_LIMIT_BOUNDS, ORCHESTRATOR_CHECKPOINTS, SUNO_LIMITS, SUNO_VOCAL_GENDERS, autonomousRequestFromDraft, emptyAutonomousDraft,+ AUTONOMOUS_CHECKPOINT_IDS, AUTONOMOUS_CHECKPOINT_LABELS, AUTONOMOUS_LIMIT_BOUNDS, ORCHESTRATOR_CHECKPOINTS, REUSED_SONG_SKIPPED_CHECKPOINTS, SUNO_LIMITS, SUNO_VOCAL_GENDERS, autonomousRequestFromDraft, emptyAutonomousDraft,isSunoModelValid,} from '../../lib/musicVideoAutonomous.js';@@ -46,7 +47,9 @@ export default function AutonomousStartDrawer({ open, onClose, onStarted }) {checkpoints: AUTONOMOUS_CHECKPOINT_IDS.filter((c) => (c === id ? !draft.checkpoints.includes(c) : draft.checkpoints.includes(c))),});const patchSuno = (next) => setDraft((d) => ({ ...d, suno: { ...d.suno, ...next } }));- const sunoModelValid = draft.songSource !== 'suno' || isSunoModelValid(draft.suno.model);+ const reusingSong = !!draft.fromProjectId;+ const checkpointIds = reusingSong ? AUTONOMOUS_CHECKPOINT_IDS.filter((id) => !REUSED_SONG_SKIPPED_CHECKPOINTS.includes(id)) : AUTONOMOUS_CHECKPOINT_IDS;+ const sunoModelValid = reusingSong || draft.songSource !== 'suno' || isSunoModelValid(draft.suno.model);const valid = draft.prompt.trim().length > 0 && authoringReady && sunoModelValid && (!orchestrated || !!orchestratorLlm.selectedProviderId);const handleSubmit = (e) => {@@ -104,9 +107,11 @@ export default function AutonomousStartDrawer({ open, onClose, onStarted }) {</p></div>- <SongSourcePicker idPrefix="mv-auto" songSource={draft.songSource} localFallback={draft.localFallback} localMusic={draft.localMusic} onChange={patch} />+ <ExistingSongSelect id="mv-auto-from-project" value={draft.fromProjectId} onChange={(fromProjectId) => patch({ fromProjectId })} />- {draft.songSource === 'suno' && (+ {!reusingSong && <SongSourcePicker idPrefix="mv-auto" songSource={draft.songSource} localFallback={draft.localFallback} localMusic={draft.localMusic} onChange={patch} />}++ {!reusingSong && draft.songSource === 'suno' && (<div className="grid grid-cols-[repeat(auto-fit,minmax(min(100%,10rem),16rem))] gap-3"><div><label htmlFor="mv-auto-suno-exclude" className="block text-xs text-port-text-muted mb-1">Exclude styles</label>@@ -137,7 +142,7 @@ export default function AutonomousStartDrawer({ open, onClose, onStarted }) {</div>)}- <ToggleChip id="mv-auto-instrumental" label="Instrumental (no vocals)" checked={draft.instrumental} onToggle={() => patch({ instrumental: !draft.instrumental })} />+ {!reusingSong && <ToggleChip id="mv-auto-instrumental" label="Instrumental (no vocals)" checked={draft.instrumental} onToggle={() => patch({ instrumental: !draft.instrumental })} />}<MediaModePicker id="mv-auto-media-mode" value={draft.mediaMode} onChange={(mediaMode) => patch({ mediaMode })} /><CodeAuthoringPicker value={draft.authoring} onChange={(authoring) => patch({ authoring })} onValidityChange={setAuthoringReady} disabled={submitting} />@@ -220,7 +225,7 @@ export default function AutonomousStartDrawer({ open, onClose, onStarted }) {<fieldset className="min-w-0" aria-labelledby="mv-auto-checkpoints-label"><span id="mv-auto-checkpoints-label" className="block text-xs text-port-text-muted mb-1">Pause for my approval after (optional)</span><div className="flex flex-wrap gap-1.5">- {AUTONOMOUS_CHECKPOINT_IDS.map((id) => (+ {checkpointIds.map((id) => (<ToggleChipkey={id}id={`mv-auto-checkpoint-${id}`}diff --git a/client/src/components/musicVideo/ExistingSongSelect.jsx b/client/src/components/musicVideo/ExistingSongSelect.jsxnew file mode 100644index 0000000000..6cc0d0438a--- /dev/null+++ b/client/src/components/musicVideo/ExistingSongSelect.jsx@@ -0,0 +1,39 @@+import { useEffect, useState } from 'react';+import { listMusicVideoProjectSummaries } from '../../services/apiMusicVideo.js';++const inputClass = 'w-full min-w-0 bg-port-bg border border-port-border rounded px-2 py-1.5 text-sm';++/**+ * Start an autonomous run on another project's song instead of making one: the+ * server copies its audio, analysis and timed lyrics, never its look. Lists the+ * projects that have a song, newest first.+ */+export default function ExistingSongSelect({ id, value, onChange }) {+ // null = not loaded yet.+ const [projects, setProjects] = useState(null);++ useEffect(() => {+ let active = true;+ listMusicVideoProjectSummaries({ limit: 500 }, { silent: true })+ .then((page) => { if (active) setProjects((page?.items || []).filter((p) => p.trackId || p.uploadedAudioFilename)); })+ .catch(() => { if (active) setProjects([]); });+ return () => { active = false; };+ }, []);+ const missing = value && projects && !projects.some((p) => p.id === value);++ return (+ <div className="min-w-0">+ <label htmlFor={id} className="block text-xs text-port-text-muted mb-1">Song to use</label>+ <select id={id} value={value || ''} onChange={(e) => onChange(e.target.value)} className={inputClass}>+ <option value="">{projects === null ? 'Loading…' : 'Make a new song'}</option>+ {missing && <option value={value}>{value} (not found)</option>}+ {(projects || []).map((p) => <option key={p.id} value={p.id}>Use the song from {p.name}</option>)}+ </select>+ {value && (+ <p className="text-[11px] text-port-text-muted mt-1">+ Its audio, lyrics and word timing are copied. No lyrics are written and no song is made; the look starts fresh.+ </p>+ )}+ </div>+ );+}diff --git a/client/src/lib/musicVideoAutonomous.js b/client/src/lib/musicVideoAutonomous.jsindex 592c567067..cc01f4b427 100644--- a/client/src/lib/musicVideoAutonomous.js+++ b/client/src/lib/musicVideoAutonomous.js@@ -60,6 +60,8 @@ export const emptyAutonomousDraft = () => ({mediaMode: 'code-images-video',authoring: { providerId: '', model: '', effort: '' },songSource: AUTONOMOUS_SONG_SOURCES[0],+ // Start on this project's song instead of making one ('' = make a new song).+ fromProjectId: '',localFallback: false,localMusic: {type: 'model',@@ -107,6 +109,9 @@ const optionalInt = (raw) => {return Number.isInteger(n) ? n : undefined;};+/** The checkpoints a run on an existing song never reaches. */+export const REUSED_SONG_SKIPPED_CHECKPOINTS = Object.freeze(['lyrics', 'song']);+/** The start request for a draft: blank optional fields are omitted so the server defaults apply. */export function autonomousRequestFromDraft(draft, { providerId, model, effort } = {}) {const budget = Number.parseFloat(draft.budget);@@ -137,8 +142,10 @@ export function autonomousRequestFromDraft(draft, { providerId, model, effort }...(draft.guidance.trim() ? { guidance: draft.guidance.trim() } : {}),budgetUsd: Number.isFinite(budget) && budget >= 0 ? budget : null,...(Object.keys(limits).length ? { limits } : {}),- // The orchestrator clears every review point itself, so it pauses at none.- checkpoints: orchestrated ? [] : draft.checkpoints,+ // The orchestrator clears every review point itself, so it pauses at none;+ // a reused song writes no lyrics and makes no song, so those never pause.+ checkpoints: orchestrated ? [] : draft.fromProjectId ? draft.checkpoints.filter((id) => !REUSED_SONG_SKIPPED_CHECKPOINTS.includes(id)) : draft.checkpoints,+ ...(draft.fromProjectId ? { fromProjectId: draft.fromProjectId } : {}),...(orchestrated ? { orchestrator: {providerId: draft.orchestrator.providerId,...(draft.orchestrator.model ? { model: draft.orchestrator.model } : {}),@@ -230,7 +237,7 @@ export function autonomousStageOutput(run, stageId) {add('conceptStyle', 'Visual style', out.concept?.style);if (out.moodBoardId) fields.push({ key: 'moodBoard', label: 'Mood board', href: `/mood-boards/${encodeURIComponent(out.moodBoardId)}`, text: out.moodBoard?.name || 'Open mood board' });} else if (stageId === 'song') {- add('songSource', 'Source', out.songSource ? AUTONOMOUS_SONG_SOURCE_LABELS[out.songSource] || out.songSource : null);+ add('songSource', 'Source', out.songSource === 'reused' ? 'Existing song' : out.songSource ? AUTONOMOUS_SONG_SOURCE_LABELS[out.songSource] || out.songSource : null);add('songFallbackReason', 'Why Suno was skipped', out.songFallbackReason);add('sunoSongIds', 'Suno song ids', Array.isArray(out.sunoSongIds) ? out.sunoSongIds.join(', ') : null, { mono: true });}diff --git a/server/lib/musicVideoValidation.js b/server/lib/musicVideoValidation.jsindex 4c51ecedfc..090df7f099 100644--- a/server/lib/musicVideoValidation.js+++ b/server/lib/musicVideoValidation.js@@ -1017,6 +1017,9 @@ export const musicVideoAutonomousStartSchema = z.object({checkpoints: z.array(z.enum(AUTONOMOUS_CHECKPOINT_IDS)).max(AUTONOMOUS_CHECKPOINT_IDS.length).optional(),// Reuse this existing mood board instead of generating one from the prompt.moodBoardId: z.string().trim().min(1).max(64).nullable().optional(),+ // Start on this project's song: its audio, analysis and lyric timing are copied,+ // so the run writes no lyrics, makes no song and skips re-analysis.+ fromProjectId: z.string().trim().min(1).max(80).optional(),// A built-in character style (musicVideoCharacterStyles.js) cast as protagonist from the start.characterStyleId: z.enum(MUSIC_VIDEO_CHARACTER_STYLE_IDS).nullable().optional(),// The LLM that writes the brief and lyrics (blank = an eligible TUI provider, else thediff --git a/server/services/musicVideo/autonomousBrief.js b/server/services/musicVideo/autonomousBrief.jsindex 2bfdb3fc48..a49517ced6 100644--- a/server/services/musicVideo/autonomousBrief.js+++ b/server/services/musicVideo/autonomousBrief.js@@ -22,12 +22,24 @@ import { assertProvider, resolveProviderAndModel, runPromptThroughProvider } froconst NOTE_MAX = 600;const NOTES_MAX = 10;-function buildBriefPrompt({ prompt, guidance, instrumental }) {+const SONG_LYRICS_MAX = 6000;++// A run that reuses an existing song designs only the video: the song is fixed.+function existingSongBlock(song) {+ if (!song) return '';+ const lyrics = trimTo(song.lyrics, SONG_LYRICS_MAX);+ return `+The song ALREADY EXISTS; do not write a new one. Design the video for this song. Keep "title" exactly as given, and describe the existing song's sound in "musicalDescription" and "sunoStyle".+Title: ${song.title}+${song.style ? `Song style: ${song.style}\n` : ''}${lyrics ? `Lyrics:\n${lyrics}\n` : ''}`;+}++function buildBriefPrompt({ prompt, guidance, instrumental, song = null }) {return `You are the creative director for a fully autonomous music video. From the operator's idea below, design the song AND the look of its video.Idea:${prompt}-${guidance ? `\nOperator guidance:\n${guidance}\n` : ''}+${guidance ? `\nOperator guidance:\n${guidance}\n` : ''}${existingSongBlock(song)}${instrumental ? 'The song is INSTRUMENTAL: no vocals.\n' : ''}Return JSON only, with exactly these keys:{@@ -76,14 +88,14 @@ function sanitizeBrief(parsed, { prompt }) {};}-export async function draftCreativeBrief({ prompt, guidance = '', instrumental = false, providerId, model, effort } = {}) {+export async function draftCreativeBrief({ prompt, guidance = '', instrumental = false, song = null, providerId, model, effort } = {}) {const { provider, selectedModel } = await resolveProviderAndModel({ providerId, model });assertProvider(provider, { message: 'No AI provider available to draft the music video brief', code: 'NO_PROVIDER' });const result = await runPromptThroughProvider({provider,model: selectedModel,...(effort ? { effort } : {}),- prompt: buildBriefPrompt({ prompt, guidance, instrumental }),+ prompt: buildBriefPrompt({ prompt, guidance, instrumental, song }),source: 'music-video-autonomous-brief',});let parsed;diff --git a/server/services/musicVideo/autonomousService.js b/server/services/musicVideo/autonomousService.jsindex 49f40dfaee..2114c428db 100644--- a/server/services/musicVideo/autonomousService.js+++ b/server/services/musicVideo/autonomousService.js@@ -81,6 +81,7 @@ import {normalizeAutonomousBrief,normalizeLocalMusicOptions,normalizeSunoOptions,+ SUNO_LIMITS,sunoSongFields,} from '../../lib/musicVideoAutonomous.js';import { withBackupAssetPublication } from '../../lib/backupSnapshotBoundary.js';@@ -108,6 +109,7 @@ const defaults = {generateSunoSong: async (fields, opts) => (await import('./autonomousSuno.js')).generateSunoSong(fields, opts),generateLocalSong: async (args) => (await import('./autonomousLocalSong.js')).generateLocalSong(args),cancelLocalSong: async (jobId) => (await import('../mediaJobQueue/index.js')).cancelJob(jobId),+ getTrack: async (id) => (await import('../tracks/index.js')).getTrack(id).catch(() => null),createTrack: async (input) => (await import('../trackAlbumMembership.js')).createTrackWithAlbum(input).then((r) => r.track),attachAudio: async (trackId, filename, take) => (await import('../trackAudioAttach.js')).attachAudioAsRender(trackId, filename, take),probeDuration: (filename) => probeVideoDuration(join(PATHS.music, filename)).catch(() => null),@@ -481,6 +483,15 @@ async function settleLyricTiming(projectId, run) {if (!draft || draft.storyboardSource === 'document') return;const status = productionReadiness(project).alignment.status;if (status === 'verified' || status === 'instrumental') return;+ const reviewer = runReviewer(run);+ // A reused song's timing a director already verified on its source project, untouched since.+ const reusedBasis = run.brief.songFrom?.verifiedAlignmentBasis;+ if (reusedBasis && reusedBasis === productionAlignmentBasis(project)) {+ const notes = 'Lyric timing carried over unchanged from the source project, where it was verified.';+ await deps.verifyAlignment(projectId, { basis: reusedBasis, notes, reviewer });+ await record('approve', notes);+ return;+ }const cues = (project.lyricCues || []).filter((c) => cueText(c));if (!cues.length) {if (!run.brief.instrumental) return;@@ -503,7 +514,6 @@ async function settleLyricTiming(projectId, run) {await record('revise', `${notes} ${held}`);return `${notes} ${held}`;}- const reviewer = runReviewer(run);await deps.verifyAlignment(projectId, { basis: productionAlignmentBasis(project), notes, reviewer });await record('approve', notes);}@@ -933,9 +943,13 @@ function briefGuidance(brief) {const STAGES = {async brief({ project, run }) {const { route, ...llm } = await llmOf(run, 'brief');- const { brief } = await deps.draftCreativeBrief({+ const reused = run.brief.songFrom;+ const { brief: drafted } = await deps.draftCreativeBrief({prompt: run.brief.prompt, guidance: briefGuidance(run.brief), instrumental: run.brief.instrumental, ...llm,+ ...(reused ? { song: { title: reused.title, style: reused.style, lyrics: run.output.lyrics } } : {}),});+ // A reused song keeps its own title and style; the brief only designs the video around it.+ const brief = reused ? { ...drafted, title: reused.title, ...(reused.style ? { sunoStyle: trimTo(reused.style, SUNO_LIMITS.style) } : {}) } : drafted;// A blank project name from the prompt gives way to the song title.if (!run.brief.name) await deps.updateProject(project.id, { name: trimTo(brief.title, 200) });await recordRoute(project, 'brief', route);@@ -945,6 +959,8 @@ const STAGES = {// The orchestrator judges the written lyrics and may rewrite them (orchestrateLyrics).async lyrics(ctx) {const { project, run, save } = ctx;+ // A reused song's lyrics were copied with it at start.+ if (run.brief.songFrom) return { output: {} };if (run.brief.instrumental || !isOrchestratedRun(run)) return writeRunLyrics(ctx);// The draft (or reviewed draft) is stored before the orchestrator judges it,// so a failed review retries only the review.@@ -1014,13 +1030,21 @@ const STAGES = {},async analyze({ project, run }) {- await deps.analyzeSong(project.id);- // A storyboard grant needs the lyric timings production verifies, so the autopilot aligns too.- if (!isOrchestratedRun(run) && autoApproves(run, 'storyboard')) await alignRunLyrics(project.id, run);- if (isOrchestratedRun(run) && (await orchestrateSong(project.id, run)).retake) {- // A local fallback stays local: the retake must not send the run back to Suno.- const reset = Object.fromEntries(SONG_OUTPUT_KEYS.filter((key) => key !== 'songSource' && key !== 'songFallbackReason').map((key) => [key, null]));- return { output: reset, goto: 'song', unlinkTrack: run.output.trackId || null };+ if (run.brief.songFrom) {+ // A reused song arrives analyzed and word-timed from its source project and is+ // kept as is (no song review, so no retake); only what the source lacks is made.+ if (!project.audioAnalysis) await deps.analyzeSong(project.id);+ const untimed = (project.lyricCues || []).some((c) => cueText(c) && !c.words?.length);+ if (untimed && (isOrchestratedRun(run) || autoApproves(run, 'storyboard'))) await alignRunLyrics(project.id, run);+ } else {+ await deps.analyzeSong(project.id);+ // A storyboard grant needs the lyric timings production verifies, so the autopilot aligns too.+ if (!isOrchestratedRun(run) && autoApproves(run, 'storyboard')) await alignRunLyrics(project.id, run);+ if (isOrchestratedRun(run) && (await orchestrateSong(project.id, run)).retake) {+ // A local fallback stays local: the retake must not send the run back to Suno.+ const reset = Object.fromEntries(SONG_OUTPUT_KEYS.filter((key) => key !== 'songSource' && key !== 'songFallbackReason').map((key) => [key, null]));+ return { output: reset, goto: 'song', unlinkTrack: run.output.trackId || null };+ }}// The single's own cover design, drafted from the song just made, ready// for the publishing kit. Best-effort: a failed draft never stops the video.@@ -1223,19 +1247,53 @@ async function assertBriefVideoModelsCapable(tools, models) {if (pool.some((route) => route.kind === 'video' && route.model)) await assertFootageVideoModelsCapable(pool, await loadPoolEnv());}+// The song fields a reused song brings along: the audio, its analysis and the+// timed lyrics. Never the source's look, cast, scenes, storyboard or treatment.+const REUSED_SONG_FIELDS = ['audioAnalysis', 'midiTranscription', 'lyricCues', 'lyricMarkers', 'phrases',+ 'vocalStemFilename', 'performanceConditioningSource', 'lyricAlignSource', 'lyricAlignSilentWords'];++/** The song an autonomous run reuses from another project, or a 4xx naming why it cannot. */+async function loadSongSource(projectId) {+ const source = await getProject(projectId);+ if (!source || source.deleted) throw runError(404, 'NOT_FOUND', 'The project to take the song from was not found');+ if (!source.trackId && !source.uploadedAudioFilename) throw runError(409, 'NO_SONG', `"${source.name}" has no song to reuse`);+ const track = source.trackId ? await deps.getTrack(source.trackId) : null;+ const cueLines = (source.lyricCues || []).map(cueText).filter(Boolean);+ return {+ source,+ title: trimTo(track?.title || source.name, SUNO_LIMITS.title) || 'Untitled',+ style: trimTo(source.concept?.songStyle || track?.prompt || '', 2000),+ lyrics: cueLines.length ? cueLines.join('\n') : (typeof track?.lyrics === 'string' ? track.lyrics.trim() : ''),+ // Verified timing carries over only while it is still verified on the source.+ verified: productionReadiness(source).alignment.status === 'verified',+ };+}+export async function startAutonomousVideo(input, { autoApproveAuthorized = false } = {}) {const brief = { ...normalizeAutonomousBrief(input), ...autoApproveGrant(input?.autoApprove, autoApproveAuthorized) };if (!brief.prompt) throw runError(400, 'VALIDATION_ERROR', 'A prompt is required');if (brief.orchestrator) Object.assign(brief, orchestratorGrant(autoApproveAuthorized));await assertBriefVideoModelsCapable(brief.tools, brief.models);+ const song = input?.fromProjectId ? await loadSongSource(input.fromProjectId) : null;+ if (song) {+ // No lyrics are written and no song is made, so those checkpoints have nothing to stop on.+ Object.assign(brief, {+ name: brief.name || trimTo(`${song.title} (Auto)`, 200),+ instrumental: !song.lyrics,+ checkpoints: brief.checkpoints.filter((id) => id !== 'lyrics' && id !== 'song'),+ songFrom: { projectId: song.source.id, title: song.title, style: song.style, verifiedAlignmentBasis: null },+ });+ }const now = new Date().toISOString();const created = await deps.createProject({name: brief.name || trimTo(brief.prompt.replace(/\s+/g, ' '), 60) || 'Autonomous music video',mode: 'autonomous',mediaMode: brief.mediaMode,...(brief.mediaMode !== 'code-images-video' ? { productionPolicy: { strategy: 'code-first', maxGeneratedVideoPercent: 0 } } : {}),+ ...(song ? { trackId: song.source.trackId || null, uploadedAudioFilename: song.source.uploadedAudioFilename || null } : {}),// The style id makes createProject cast its character and attach the sheet (styleSnapshots.js).- concept: { prompt: trimTo(brief.prompt, 8000), ...(brief.characterStyleId ? { characterStyleId: brief.characterStyleId } : {}) },+ concept: { prompt: trimTo(brief.prompt, 8000), ...(brief.characterStyleId ? { characterStyleId: brief.characterStyleId } : {}),+ ...(song?.style ? { songStyle: song.style } : {}) },automation: {tools: brief.tools,guidance: brief.guidance,@@ -1253,15 +1311,24 @@ export async function startAutonomousVideo(input, { autoApproveAuthorized = falsawaiting: null,brief,stages: emptyStages(),- output: {},+ output: song ? { trackId: song.source.trackId || null, lyrics: song.lyrics, songSource: 'reused' } : {},error: null,errorCode: null,processId: PROCESS_ID,createdAt: now,updatedAt: now,};- const out = await mutateProjectRecord(created.id, (current) => ({ project: { ...current, autonomousRun: run }, run }));- console.log(`🎬 Autonomous music video ${short(run.id)} started (${brief.tools.length} tool(s), ${brief.orchestrator ? `orchestrated by ${brief.orchestrator.providerId}` : `${brief.checkpoints.length} checkpoint(s)`}${brief.autoApprove.length ? `, auto-approve ${brief.autoApprove.join('/')}` : ''}${brief.origin.kind === 'schedule' ? ', scheduled' : ''})`);+ const out = await mutateProjectRecord(created.id, (current) => {+ if (!song) return { project: { ...current, autonomousRun: run }, run };+ const copied = Object.fromEntries(REUSED_SONG_FIELDS.filter((key) => song.source[key] !== undefined)+ .map((key) => [key, structuredClone(song.source[key])]));+ const project = { ...current, ...copied, ...(copied.audioAnalysis ? { status: 'analyzed' } : {}) };+ // Bound to the copy as written: any later change to the audio or timings unbinds it.+ const reused = { ...run, brief: { ...run.brief, songFrom: { ...run.brief.songFrom,+ verifiedAlignmentBasis: song.verified ? productionAlignmentBasis(project) : null } } };+ return { project: { ...project, autonomousRun: reused }, run: reused };+ });+ console.log(`🎬 Autonomous music video ${short(run.id)} started${song ? ` on the song from ${short(song.source.id)}` : ''} (${brief.tools.length} tool(s), ${brief.orchestrator ? `orchestrated by ${brief.orchestrator.providerId}` : `${brief.checkpoints.length} checkpoint(s)`}${brief.autoApprove.length ? `, auto-approve ${brief.autoApprove.join('/')}` : ''}${brief.origin.kind === 'schedule' ? ', scheduled' : ''})`);publish(out.project, out.run);advanceInBackground(created.id);return { project: out.project, run: presentAutonomousRun(out.run) };@@ -1342,6 +1409,7 @@ export async function resumeAutonomousVideo(projectId, edits = {}, { autoApprove// "Auto-approve the rest": replaces the brief's grant (an empty list clears it).const grant = edits.autoApprove !== undefined ? autoApproveGrant(edits.autoApprove, autoApproveAuthorized) : null;const retake = edits.retakeSong === true;+ if (retake && run.brief.songFrom) throw runError(409, 'SONG_REUSED', 'This run reuses an existing song, so it has no song to retake');if (retake) assertAtSongCheckpoint(run);const modelsChanged = modelsPatch !== null && JSON.stringify(modelsPatch) !== JSON.stringify(run.brief.models || {});const limitsPatch = edits.limits ? { ...run.brief.limits, ...edits.limits } : null;diff --git a/server/services/musicVideo/autonomousService.test.js b/server/services/musicVideo/autonomousService.test.jsindex 5f61714048..bee0e99b24 100644--- a/server/services/musicVideo/autonomousService.test.js+++ b/server/services/musicVideo/autonomousService.test.js@@ -607,6 +607,66 @@ describe('startAutonomousVideo', () => {});});+// A finished project whose song a new run reuses; everything but the song is its own look.+const SONG_SOURCE = {+ id: 'mv-src', name: 'Example Song', trackId: 'track-src', uploadedAudioFilename: null, status: 'ready',+ concept: { prompt: 'Its own concept', songStyle: 'post-punk, driving drums, -metal' },+ visualSpec: { moodBoardId: 'board-src', references: [{ id: 'ref-1', imageId: 'img-1' }] },+ audioAnalysis: { durationSec: 20, bpm: 120, sections: [{ id: 'chorus', label: 'Chorus', startSec: 0, endSec: 20 }] },+ midiTranscription: { filename: 'song.mid' },+ lyricCues: [{ id: 'c1', text: 'rain on glass', startSec: 1, endSec: 4, words: [+ { w: 'rain', startSec: 1, endSec: 2, conf: 'interpolated' }, { w: 'on', startSec: 2, endSec: 3, conf: 'interpolated' }, { w: 'glass', startSec: 3, endSec: 4, conf: 'interpolated' }] }],+ lyricMarkers: [{ cueIndex: 0, kind: 'section', text: 'Chorus' }],+ phrases: [{ id: 'mp-1', label: 'hook', intent: 'lift', startSec: 1, endSec: 4 }],+ vocalStemFilename: 'vocals.wav', performanceConditioningSource: 'vocal-stem', lyricAlignSource: 'vocal-stem', lyricAlignSilentWords: 0,+ scenes: [{ sceneId: 'mvs-src', startSec: 0, endSec: 20 }],+ castAndSets: { status: 'complete', cast: 'Its own lead' },+ treatment: { brief: 'Its own treatment' },+ filmLook: { preset: 'example' },+ productionReview: { draft: { lyricsMode: 'vocal', timingStatus: 'verified', storyboard: [{ sceneId: 'mvs-src' }] } },+};++describe('starting on an existing project\'s song (fromProjectId)', () => {+ beforeEach(() => {+ store.set('mv-src', clone(SONG_SOURCE));+ doubles.getTrack = vi.fn(async () => ({ id: 'track-src', title: 'Example Song', prompt: 'track style', lyrics: 'rain on glass' }));+ service.__setAutonomousDepsForTests(doubles);+ });++ // Uniquely catches a reused song re-running lyrics/Suno/analysis or the new project inheriting the source's look.+ it('copies only the song, writes no lyrics, makes no song, skips analysis, and leaves the source untouched', async () => {+ const { project, run } = await service.startAutonomousVideo({ prompt: 'skatepark at golden hour', fromProjectId: 'mv-src', checkpoints: ['lyrics', 'song', 'style'] });+ expect(project).toMatchObject({ name: 'Example Song (Auto)', trackId: 'track-src', status: 'analyzed',+ audioAnalysis: SONG_SOURCE.audioAnalysis, lyricCues: SONG_SOURCE.lyricCues, vocalStemFilename: 'vocals.wav', lyricAlignSource: 'vocal-stem' });+ expect(project.concept).toEqual({ prompt: 'skatepark at golden hour', songStyle: 'post-punk, driving drums, -metal' });+ for (const key of ['visualSpec', 'castAndSets', 'treatment', 'filmLook']) expect(project[key]).toBeUndefined();+ expect(project.scenes).toBeUndefined();+ expect(run.brief).toMatchObject({ checkpoints: ['style'], instrumental: false, songFrom: { projectId: 'mv-src', title: 'Example Song' } });+ expect(run.output).toMatchObject({ trackId: 'track-src', lyrics: 'rain on glass', songSource: 'reused' });++ await settled('awaiting-approval');+ await service.resumeAutonomousVideo('mv-auto');+ await vi.waitFor(() => expect(calls).toContain('production'));+ expect(calls).toEqual(['createProject', 'brief', 'board', 'updateProject', 'production']);+ expect(doubles.draftCreativeBrief).toHaveBeenCalledWith(expect.objectContaining({+ song: { title: 'Example Song', style: 'post-punk, driving drums, -metal', lyrics: 'rain on glass' },+ }));+ // The brief designs the video; the song keeps its own title and style.+ expect(runOf().output).toMatchObject({ title: 'Example Song', sunoStyle: 'post-punk, driving drums, -metal' });+ expect(runOf().stages).toMatchObject({ lyrics: { status: 'done' }, song: { status: 'done' }, analyze: { status: 'done' } });+ expect(store.get('mv-auto').name).toBe('Example Song (Auto)');+ expect(store.get('mv-src')).toEqual(SONG_SOURCE);+ await expect(service.resumeAutonomousVideo('mv-auto', { retakeSong: true })).rejects.toMatchObject({ status: 409 });+ });++ it('refuses a missing source or one with no song before creating anything', async () => {+ await expect(service.startAutonomousVideo({ prompt: 'p', fromProjectId: 'mv-missing' })).rejects.toMatchObject({ status: 404 });+ store.set('mv-src', { ...clone(SONG_SOURCE), trackId: null });+ await expect(service.startAutonomousVideo({ prompt: 'p', fromProjectId: 'mv-src' })).rejects.toMatchObject({ status: 409, code: 'NO_SONG' });+ expect(calls).toEqual([]);+ });+});+describe('overlay text pass before the final render', () => {const finding = (atSec, message, severity = 'error') => ({ id: `f${atSec}`, kind: severity === 'error' ? 'overlap' : 'contrast', severity, atSec, texts: ['A'], message, count: 1 });const textEntries = () => (runOf()?.orchestration?.reviews || []).filter((r) => r.checkpoint === 'text');@@ -1207,6 +1267,29 @@ describe('autopilot clears the gates it was granted on its own', () => {expect(project.productionReview.approvals).toMatchObject({ art: { approvedBy: 'autopilot' }, storyboard: { approvedBy: 'autopilot' } });});+ // Uniquely catches verified timing on the source being re-judged (and held) on the copy.+ it('carries a source\'s verified lyric timing over unchanged, without re-aligning', async () => {+ const source = clone(SONG_SOURCE);+ source.productionReview.alignmentBasis = actual.productionAlignmentBasis(source);+ store.set('mv-src', source);+ doubles.getTrack = vi.fn(async () => null);+ service.__setAutonomousDepsForTests(doubles);+ prepare.mockImplementation(async (id) => {+ const project = store.get(id);+ if (project.productionReview?.draft?.storyboard) return;+ Object.assign(project, {+ scenes: [{ sceneId: 'shot', startSec: 0, endSec: 20, label: 'Chorus' }],+ devArtifacts: [{ id: 'guide', version: 1, file: 'guide.html', mimeType: 'text/html' }],+ productionReview: { ...project.productionReview, draft: { ...GUIDE, lyricsMode: 'vocal', timingStatus: 'provisional', timingNotes: '', storyboard: [shot] } },+ });+ });+ await service.startAutonomousVideo({ prompt: 'p', tools: ['image:local'], fromProjectId: 'mv-src', ...GRANT[0] }, GRANT[1]);+ await vi.waitFor(() => expect(doubles.startProduction).toHaveBeenCalledOnce());+ expect(doubles.alignLyrics).not.toHaveBeenCalled();+ expect(doubles.analyzeSong).not.toHaveBeenCalled();+ expect(doubles.verifyAlignment).toHaveBeenCalledWith('mv-auto', expect.objectContaining({ notes: expect.stringContaining('source project') }));+ });+it('marks an instrumental song as one instead of asking for lyrics', async () => {analyzed({ productionReview: { draft: { ...GUIDE, lyricsMode: 'vocal', storyboard: [shot] } } });await service.startAutonomousVideo({ prompt: 'p', tools: ['image:local'], instrumental: true, ...GRANT[0] }, GRANT[1]);