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
feat: merge a Board scene with the next one, the inverse of split (#10810)
Adam Eivye9a903308e39
diff --git a/client/src/components/musicVideo/SceneCard.jsx b/client/src/components/musicVideo/SceneCard.jsxindex 976871b046..7da2ed6742 100644--- a/client/src/components/musicVideo/SceneCard.jsx+++ b/client/src/components/musicVideo/SceneCard.jsx@@ -3,7 +3,7 @@ import ShotActionInspector from './ShotActionInspector.jsx';import SceneCameraControls from './SceneCameraControls.jsx';import { MUSIC_VIDEO_MEDIUM_LABELS } from '../../../../server/lib/musicVideoMediumPlan.js';import { useEffect, useRef, useState } from 'react';-import { Trash2, Activity, ArrowUp, ArrowDown, ChevronRight, Image as ImageIcon, Video, Maximize2, AlertTriangle, ImagePlus, Clapperboard, Scissors } from 'lucide-react';+import { Trash2, Activity, ArrowUp, ArrowDown, ChevronRight, Image as ImageIcon, Video, Maximize2, AlertTriangle, ImagePlus, Clapperboard, Merge, Scissors } from 'lucide-react';import { formatDurationSec, formatUsd } from '../../utils/formatters.js';import { useVideoFileSrc } from '../../hooks/useVideoFileSrc.js';import PerformanceEvidence from './PerformanceEvidence.jsx';@@ -64,6 +64,8 @@ const SCENE_TIME_FIELDS = [['Start', 'startSec'], ['End', 'endSec']];* A shot longer than that lane renders in one take (the lip-sync audio window,* or Grok's longest clip) offers `onSplit(sceneId, backend)`, which cuts it* into contiguous scenes at lyric pauses / phrase boundaries server-side.+ * Any scene but the last offers `onMergeNext(sceneId, backend)` (with `nextEndSec`, the next scene's end), the inverse;+ * it is hidden when the joined span would exceed that lane's longest take.** The card is a disclosure: collapsed it is one row — frame thumbnail, title,* timing, lyric line and status — and it opens on tap to the full editor.@@ -78,7 +80,7 @@ export default function SceneCard({onMove, onDelete, onEditLocal, onSave,onGenerateFrame, onGenerateVideo, onContinueVideo,onOpenPreview, onSelectTake, onReviewTake, onImportTake, onImportClipTake, takeBusy = false, layered = false, documentComposition = false,- lipSyncBackend = '', songDurationSec = null, onSplit, falVideoSettings = null, onSeek, performanceReview = null, onRepairPerformance, repairBusy = false,+ lipSyncBackend = '', songDurationSec = null, onSplit, onMergeNext, nextEndSec = null, falVideoSettings = null, onSeek, performanceReview = null, onRepairPerformance, repairBusy = false,expanded, onToggleExpand, footageOptional = false, failedScenes = null, songReview = null,}) {const detailsRef = useRef(null);@@ -139,6 +141,9 @@ export default function SceneCard({const performanceCost = falTake?.performance ? (falCost || capability?.costLabel) : capability?.costLabel;const splitLimit = layer === 'footage' ? shotSplitLimit(scene, lipSyncBackend) : null;const canSplit = splitLimit != null && timedSpan != null && timedSpan > splitLimit + 1e-6;+ const mergedSpan = typeof scene.startSec === 'number' && typeof nextEndSec === 'number' ? nextEndSec - scene.startSec : null;+ const canMerge = !!onMergeNext && !isLast && !documentComposition+ && (splitLimit == null || (mergedSpan != null && mergedSpan <= splitLimit + 1e-6));const instruction = scene.takes?.find((take) => take.kind === 'video' && take.assetId === scene.videoHistoryId)?.shotInstruction;const repairPlan = planPerformanceRepair({ scene, temporal: performanceReview?.shot,excerptStartSec: performanceReview?.excerptStartSec, backend: lipSyncBackend, videoSettings: falVideoSettings || {} });@@ -389,6 +394,13 @@ export default function SceneCard({<Scissors size={13} /> Split on lyric boundaries</button>)}+ {canMerge && (+ <button type="button" onClick={() => onMergeNext(scene.sceneId, lipSyncBackend || null)}+ className="inline-flex items-center gap-1 rounded bg-port-bg border border-port-border hover:bg-port-border/40 px-2 py-1 text-xs min-h-[44px] sm:min-h-0"+ title="Join this shot with the next one into a single shot — the inverse of split">+ <Merge size={13} /> Merge with next+ </button>+ )}{underCovered && (<div role="alert" className="flex flex-wrap items-center gap-2 rounded border border-port-warning/40 bg-port-warning/10 px-2 py-1.5 text-xs text-port-warning"><AlertTriangle size={13} className="shrink-0" />diff --git a/client/src/components/musicVideo/SceneCard.test.jsx b/client/src/components/musicVideo/SceneCard.test.jsxindex 34f93f6cd3..9bd7e7de52 100644--- a/client/src/components/musicVideo/SceneCard.test.jsx+++ b/client/src/components/musicVideo/SceneCard.test.jsx@@ -143,3 +143,21 @@ describe('move buttons (#10785)', () => {expect(screen.getByText(/comes from the composition document/)).toBeTruthy();});});++describe('Merge with next (#10810)', () => {+ const scene = { sceneId: 's1', startSec: 0, endSec: 4, takes: [] };+ const props = { index: 0, expanded: true, onEditLocal: vi.fn(), onSave: vi.fn() };++ it('merges into the next scene, and hides when last, in a document composition, or past the backend limit', () => {+ const onMergeNext = vi.fn();+ const { rerender } = render(<SceneCard scene={scene} {...props} onMergeNext={onMergeNext} nextEndSec={8} lipSyncBackend="grok" />);+ fireEvent.click(screen.getByRole('button', { name: /Merge with next/ }));+ expect(onMergeNext).toHaveBeenCalledWith('s1', 'grok');+ rerender(<SceneCard scene={scene} {...props} onMergeNext={onMergeNext} nextEndSec={14} lipSyncBackend="grok" />);+ expect(screen.queryByRole('button', { name: /Merge with next/ })).toBeNull();+ rerender(<SceneCard scene={scene} {...props} onMergeNext={onMergeNext} nextEndSec={8} isLast />);+ expect(screen.queryByRole('button', { name: /Merge with next/ })).toBeNull();+ rerender(<SceneCard scene={scene} {...props} onMergeNext={onMergeNext} nextEndSec={8} documentComposition />);+ expect(screen.queryByRole('button', { name: /Merge with next/ })).toBeNull();+ });+});diff --git a/client/src/components/musicVideo/stages/BoardStage.jsx b/client/src/components/musicVideo/stages/BoardStage.jsxindex 99d52288f6..c3298ce830 100644--- a/client/src/components/musicVideo/stages/BoardStage.jsx+++ b/client/src/components/musicVideo/stages/BoardStage.jsx@@ -181,6 +181,8 @@ export default function BoardStage({ board }) {onMove={board.moveScene}onDelete={board.onDeleteScene}onSplit={board.onSplitScene}+ onMergeNext={board.onMergeNextScene}+ nextEndSec={scenes[idx + 1]?.endSec ?? null}onRepairPerformance={['code', 'document'].includes(project.composition?.mode) ? null : board.onRepairPerformance}repairBusy={board.repairBusy || videoSettings.saving}onEditLocal={board.editSceneLocal}diff --git a/client/src/pages/MusicVideo.jsx b/client/src/pages/MusicVideo.jsxindex eeb9398967..a4542dd309 100644--- a/client/src/pages/MusicVideo.jsx+++ b/client/src/pages/MusicVideo.jsx@@ -24,6 +24,7 @@ import {updateMusicVideoScene,deleteMusicVideoScene,splitMusicVideoScene,+ mergeMusicVideoNextScene,reorderMusicVideoScenes,importMusicVideoLyrics,importMusicVideoTrackLyrics,@@ -882,6 +883,16 @@ export default function MusicVideo() {.catch((err) => toast.error(err?.message || 'Failed to split scene'));};+ // Join a scene with the next one (the inverse of the split above).+ const handleMergeNextScene = (sceneId, backend) => {+ mergeMusicVideoNextScene(selected.id, sceneId, backend, { silent: true })+ .then(({ project }) => {+ replaceProject(project);+ toast.success('Merged with the next shot');+ })+ .catch((err) => toast.error(err?.message || 'Failed to merge scenes'));+ };+const moveScene = (idx, dir) => {const scenes = selected.scenes || [];const target = idx + dir;@@ -1161,6 +1172,7 @@ export default function MusicVideo() {onAddScene: handleAddScene,onDeleteScene: handleDeleteScene,onSplitScene: handleSplitScene,+ onMergeNextScene: handleMergeNextScene,onRepairPerformance: revisions.repairPerformance,repairBusy: revisions.busy,onRenderStyle: (mode) => {diff --git a/client/src/services/apiMusicVideo.js b/client/src/services/apiMusicVideo.jsindex f4ae746b5b..614366124c 100644--- a/client/src/services/apiMusicVideo.js+++ b/client/src/services/apiMusicVideo.js@@ -122,6 +122,11 @@ export const splitMusicVideoScene = (id, sceneId, backend, options = {}) =>request(`/music-video/${encodeURIComponent(id)}/scenes/${encodeURIComponent(sceneId)}/split`, {method: 'POST', body: JSON.stringify(backend ? { backend } : {}), ...options,});+// Join a scene with the next one, the inverse of split → { project, scene }.+export const mergeMusicVideoNextScene = (id, sceneId, backend, options = {}) =>+ request(`/music-video/${encodeURIComponent(id)}/scenes/${encodeURIComponent(sceneId)}/merge-next`, {+ method: 'POST', body: JSON.stringify(backend ? { backend } : {}), ...options,+ });// Optional vocal stem (#8977): a full-length vocal bounce on the master's// timebase that performance shots are conditioned on. Both → the project.export const uploadMusicVideoVocalStem = (id, file, options = {}) => {diff --git a/server/routes/musicVideo.js b/server/routes/musicVideo.jsindex d9bf9bcb96..3e23f1a023 100644--- a/server/routes/musicVideo.js+++ b/server/routes/musicVideo.js@@ -106,6 +106,7 @@ import {deleteScene,reorderProjectScenes,splitProjectScene,+ mergeProjectNextScene,setProjectMidiTranscription,appendSceneTakes,appendTakesAcrossScenes,@@ -1421,6 +1422,12 @@ router.post('/:id/scenes/:sceneId/split', asyncHandler(async (req, res) => {res.json(await splitProjectScene(req.params.id, req.params.sceneId, { backend }));}));+// Merge a scene with the next one — the inverse of split.+router.post('/:id/scenes/:sceneId/merge-next', asyncHandler(async (req, res) => {+ const { backend } = validateRequest(musicVideoSceneSplitSchema, req.body ?? {});+ res.json(await mergeProjectNextScene(req.params.id, req.params.sceneId, { backend }));+}));+// --- Scene takes (#8965) ---// Every render or import for a scene slot is kept as an immutable take; the// slot field is the director's explicit selection among them. A take's assetdiff --git a/server/routes/musicVideo.test.js b/server/routes/musicVideo.test.jsindex e7e4658de4..688c3a6160 100644--- a/server/routes/musicVideo.test.js+++ b/server/routes/musicVideo.test.js@@ -28,6 +28,7 @@ vi.mock('../services/musicVideo/projects.js', () => ({reorderProjectScenes: vi.fn(async (id, ids) => ({ id, scenes: ids.map((sceneId, order) => ({ sceneId, order })) })),// Scene split (#8977) — exercised against the real store in musicVideoSceneSplit.test.js.splitProjectScene: vi.fn(),+ mergeProjectNextScene: vi.fn(),setProjectMidiTranscription: vi.fn(async (id, midi) => ({ id, midiTranscription: midi })),// Scene takes (#8965) — exercised against the real store in musicVideoTakes.test.js.appendSceneTakes: vi.fn(),diff --git a/server/services/musicVideo/projects.js b/server/services/musicVideo/projects.jsindex 3a8d680d83..096393964e 100644--- a/server/services/musicVideo/projects.js+++ b/server/services/musicVideo/projects.js@@ -251,6 +251,15 @@ export async function splitProjectScene(id, sceneId, options = {}) {return mutateProjectRecord(id, (current) => splitScene(current, sceneId, options));}+/**+ * Join a scene with the next one (projectsLogic.mergeNextScene) — the inverse+ * of the split. Returns `{ project, scene }`.+ */+export async function mergeProjectNextScene(id, sceneId, options = {}) {+ const { mergeNextScene } = await import('./projectsLogic.js');+ return mutateProjectRecord(id, (current) => mergeNextScene(current, sceneId, options));+}+// ---- scene takes (#8965) ----// Append candidate takes to one scene: `{ scene, appended }`. A take fills its// slot only while the slot is empty — never replaces a selection (takes.js).diff --git a/server/services/musicVideo/projectsLogic.js b/server/services/musicVideo/projectsLogic.jsindex 8c6160baa2..bd5629b7e3 100644--- a/server/services/musicVideo/projectsLogic.js+++ b/server/services/musicVideo/projectsLogic.js@@ -757,6 +757,79 @@ export function splitScene(project, sceneId, { backend = null } = {}) {return { project: next, scenes: nextScenes.slice(idx, idx + count) };}+const timedSec = (v) => typeof v === 'number' && Number.isFinite(v);++/**+ * Join a scene with the one after it — the inverse of `splitScene`. The first+ * scene keeps its id, takes and selections and stretches to the next scene's+ * end; the lyric lines are joined; the next scene is removed and `order`+ * renumbered; a board-sourced storyboard draft merges the matching shots.+ * A selected clip survives (the director's cut was one continuous clip), but a+ * performance's lip-synced clip was generated for the old interval, so its+ * selection is cleared as in a split. When the second scene selects the same+ * video asset as the first, its take for that asset is kept too. Refuses when+ * the joined span exceeds the backend's longest take (`shotSplitLimit`) and for+ * a document composition, whose shot order lives in the shot manifest.+ * Returns `{ project, scene }`.+ */+export function mergeNextScene(project, sceneId, { backend = null } = {}) {+ const scenes = project.scenes || [];+ const idx = scenes.findIndex((s) => s.sceneId === sceneId);+ if (idx < 0) throw new ServerError('Scene not found', { status: 404, code: 'NOT_FOUND' });+ const scene = scenes[idx];+ const following = scenes[idx + 1];+ if (!following) throw new ServerError('This is the last scene — there is no next scene to merge.', { status: 400, code: 'MUSIC_VIDEO_MERGE_NO_NEXT' });+ if (project.composition?.mode === 'document') {+ throw new ServerError("This video's shot order comes from its composition document — merge the shots in the shot manifest instead.", { status: 400, code: 'MUSIC_VIDEO_MERGE_DOCUMENT' });+ }+ const lane = backend || project.videoSettings?.backend || null;+ const startSec = scene.startSec;+ const endSec = timedSec(following.endSec) ? following.endSec : scene.endSec;+ const maxSec = shotSplitLimit(scene, lane);+ if (maxSec != null) {+ if (!timedSec(startSec) || !timedSec(endSec)) {+ throw new ServerError('Both scenes need a start and end time before they can be merged on this backend.', { status: 400, code: 'MUSIC_VIDEO_MERGE_UNTIMED' });+ }+ if (endSec - startSec > maxSec + 1e-6) {+ throw new ServerError(`The merged shot would run ${(endSec - startSec).toFixed(2)}s, longer than this backend renders in one take (${maxSec.toFixed(2)}s).`, { status: 400, code: 'MUSIC_VIDEO_MERGE_TOO_LONG' });+ }+ }++ const now = new Date().toISOString();+ let takes = ensureSceneTakes(scene, now);+ const sharedClip = scene.videoHistoryId && scene.videoHistoryId === following.videoHistoryId;+ if (sharedClip && !takes.some((t) => t.kind === 'video' && t.assetId === scene.videoHistoryId)) {+ const kept = ensureSceneTakes(following, now).find((t) => t.kind === 'video' && t.assetId === scene.videoHistoryId);+ if (kept) takes = [...takes, kept];+ }+ const lyricText = [scene.lyricText, following.lyricText].filter((t) => typeof t === 'string' && t.trim()).join(' / ').slice(0, 2000) || null;+ const merged = {+ ...scene, endSec, lyricText, takes,+ ...(isPerformanceScene(scene) ? { videoHistoryId: null } : {}),+ };++ const nextScenes = [...scenes.slice(0, idx), merged, ...scenes.slice(idx + 2)].map((s, i) => ({ ...s, order: i }));+ const extra = { scenes: nextScenes };+ const sceneReview = project.songRevision?.sceneReview;+ if (sceneReview && typeof sceneReview === 'object' && following.sceneId in sceneReview) {+ extra.songRevision = { ...project.songRevision,+ sceneReview: Object.fromEntries(Object.entries(sceneReview).filter(([id]) => id !== following.sceneId)) };+ }+ const draft = project.productionReview?.draft;+ if (Array.isArray(draft?.storyboard) && draft.storyboardSource !== 'document') {+ const second = draft.storyboard.find((shot) => shot?.sceneId === following.sceneId);+ const storyboard = draft.storyboard+ .filter((shot) => shot?.sceneId !== following.sceneId)+ .map((shot) => {+ if (shot?.sceneId !== scene.sceneId) return shot;+ const cueIds = [...new Set([...(shot.lyricCueIds || []), ...(second?.lyricCueIds || [])])];+ return { ...shot, endSec: timedSec(second?.endSec) ? second.endSec : endSec ?? shot.endSec, lyricCueIds: cueIds };+ });+ extra.productionReview = { ...project.productionReview, draft: { ...draft, storyboard } };+ }+ return { project: touch(project, extra), scene: nextScenes[idx] };+}+// ---- peer-sync federation (#1770) -----------------------------------------// Mirrors the Creative Director store (creativeDirector/projectsLogic.js): a// project is a whole-record LWW kind (no item-union, no ephemeral flag), so thediff --git a/server/services/musicVideo/projectsLogic.test.js b/server/services/musicVideo/projectsLogic.test.jsindex c4fb04f57d..3a8523f3c3 100644--- a/server/services/musicVideo/projectsLogic.test.js+++ b/server/services/musicVideo/projectsLogic.test.js@@ -10,6 +10,7 @@ import {applySceneUpdate,removeScene,reorderScenes,+ mergeNextScene,mirrorStatus,sanitizeProjectForSync,mergeProjectRecord,@@ -607,6 +608,46 @@ describe('scene board operations', () => {});});+describe('mergeNextScene', () => {+ const seed = (extra = {}) => {+ let p = baseProject();+ const ids = [];+ for (const [startSec, endSec, lyricText] of [[0, 4, 'line one'], [4, 9, 'line two'], [9, 12, 'line three']]) {+ const r = addScene(p, { startSec, endSec, lyricText, sectionLabel: 'Verse' });+ p = r.project; ids.push(r.scene.sceneId);+ }+ p = applySceneUpdate(p, ids[0], { videoHistoryId: 'clip-a' }).project;+ p = applySceneUpdate(p, ids[1], { videoHistoryId: 'clip-a' }).project;+ return { project: { ...p, ...extra }, ids };+ };++ it('joins two neighbours: span, lyric, kept take, order and the draft shot', () => {+ const { project, ids } = seed();+ const withDraft = { ...project, productionReview: { draft: { storyboard: [+ { sceneId: ids[0], startSec: 0, endSec: 4, lyricCueIds: ['c1'] },+ { sceneId: ids[1], startSec: 4, endSec: 9, lyricCueIds: ['c1', 'c2'] },+ { sceneId: ids[2], startSec: 9, endSec: 12, lyricCueIds: ['c3'] },+ ] } } };+ const { project: next, scene } = mergeNextScene(withDraft, ids[0]);+ expect(next.scenes.map((s) => [s.sceneId, s.order])).toEqual([[ids[0], 0], [ids[2], 1]]);+ expect(scene).toMatchObject({ startSec: 0, endSec: 9, lyricText: 'line one / line two', videoHistoryId: 'clip-a' });+ expect(scene.takes.filter((t) => t.kind === 'video' && t.assetId === 'clip-a')).toHaveLength(1);+ expect(next.productionReview.draft.storyboard).toEqual([+ { sceneId: ids[0], startSec: 0, endSec: 9, lyricCueIds: ['c1', 'c2'] },+ { sceneId: ids[2], startSec: 9, endSec: 12, lyricCueIds: ['c3'] },+ ]);+ });++ it('refuses a merge longer than the backend\'s longest clip, the last scene, and a document composition', () => {+ const { project, ids } = seed();+ expect(() => mergeNextScene(project, ids[0], { backend: 'grok' })).not.toThrow(); // 9s fits Grok's 10s+ const long = applySceneUpdate(project, ids[2], { endSec: 20 }).project; // 4–20s > 10s+ expect(() => mergeNextScene(long, ids[1], { backend: 'grok' })).toThrow(/longer than this backend/);+ expect(() => mergeNextScene(project, ids[2])).toThrow(/no next scene/);+ expect(() => mergeNextScene({ ...project, composition: { mode: 'document' } }, ids[0])).toThrow(/shot manifest/);+ });+});+describe('mirrorStatus', () => {it('bounds and defaults the status column value', () => {expect(mirrorStatus('rendering')).toBe('rendering');