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
Separate shot clip playback and coverage from render controls (#11523)
[._.]/10ffb581247d
diff --git a/client/src/components/musicVideo/SceneCard.jsx b/client/src/components/musicVideo/SceneCard.jsxindex 6add13df90..f2f0a9f563 100644--- a/client/src/components/musicVideo/SceneCard.jsx+++ b/client/src/components/musicVideo/SceneCard.jsx@@ -6,18 +6,19 @@ import SceneClipTiming from './SceneClipTiming.jsx';import SceneRejectUnused from './SceneRejectUnused.jsx';import { MUSIC_VIDEO_MEDIUM_LABELS } from '../../../../server/lib/musicVideoMediumPlan.js';import { useEffect, useRef, useState } from 'react';-import { Trash2, Activity, ArrowUp, ArrowDown, ChevronLeft, ChevronRight, Video, Maximize2, AlertTriangle, Clapperboard, Shuffle } from 'lucide-react';+import { Trash2, Activity, ArrowUp, ArrowDown, ChevronLeft, ChevronRight, Video, AlertTriangle, Clapperboard, Shuffle } from 'lucide-react';import OverflowMenu from '../ui/OverflowMenu.jsx';import SceneTakePicker from './SceneTakePicker.jsx';-import VideoStartTrimControl from '../media/VideoStartTrimControl.jsx';import { formatTimecode } from '../../utils/formatters.js';-import { useVideoFileSrc } from '../../hooks/useVideoFileSrc.js';+import useSceneClipPlayback from '../../hooks/useSceneClipPlayback.js';+import SceneClipPreview from './SceneClipPreview.jsx';+import SceneClipCoverageNotice from './SceneClipCoverageNotice.jsx';import PerformanceEvidence from './PerformanceEvidence.jsx';import { isPerformanceScene, planPerformanceRepair } from '../../lib/musicVideoShotTiming.js';import SceneTakeStrip from './SceneTakeStrip.jsx';import { sceneEndFramePlanFor } from './SceneEndFrame.jsx';import SceneFrames from './SceneFrames.jsx';-import { CLIP_TIMING_FPS, MUSIC_VIDEO_LYRIC_ROLES, MUSIC_VIDEO_TEXT_ZONES, MUSIC_VIDEO_VISUAL_LAYERS, clipOffsetSec, clipReversed, clipSpeedRate, sceneHasAuthoredSpan } from '../../lib/musicVideoLayers.js';+import { CLIP_TIMING_FPS, MUSIC_VIDEO_LYRIC_ROLES, MUSIC_VIDEO_TEXT_ZONES, MUSIC_VIDEO_VISUAL_LAYERS, clipReversed, sceneHasAuthoredSpan } from '../../lib/musicVideoLayers.js';// #8985: what a composed render shows for this scene's span.const LAYER_LABELS = { footage: 'Footage', still: 'Still image', card: 'Title card', code: 'Code-drawn' };@@ -31,12 +32,12 @@ const SECONDARY_BUTTON = 'flex items-center gap-1 bg-port-bg border border-port-import { buildSceneTimingPresentation } from '../../lib/musicVideoSceneTiming.js';import SceneTimingPlan from './SceneTimingPlan.jsx';import SceneRenderProgress from './SceneRenderProgress.jsx';-import { COVERAGE_TOLERANCE_SEC, SCENE_ATTENTION_LABELS, sceneAttention } from '../../lib/musicVideoSceneAttention.js';+import { SCENE_ATTENTION_LABELS, sceneAttention } from '../../lib/musicVideoSceneAttention.js';import { ShotLockButton, useShotLock } from './ShotLock.jsx';import ScenePoster from './ScenePoster.jsx';import SceneRenderTarget, { lastRenderTarget, renderTargetOverrides } from './SceneRenderTarget.jsx';import SceneRenderInputs, { shotCardRenderRequest, shotCardRequestProblem } from './SceneRenderInputs.jsx';-import SceneFrameFit, { sceneFrameFit } from './SceneFrameFit.jsx';+import SceneFrameFit from './SceneFrameFit.jsx';import SceneCutEffect from './SceneCutEffect.jsx';import { plannedTransitions } from '../../lib/musicVideoCutEffects.js';import SceneGlitches from './SceneGlitches.jsx';@@ -131,41 +132,13 @@ export default function SceneCard({}}, [expanded]);- // Pause the inline clip before opening the lightbox so the user can't hear- // two desynced copies — MediaLightbox autoplays unmuted, and the thumb's- // native controls let the user unmute it first (muted is only initial).- const clipPlayerRef = useRef(null);- // Resolve the clip's real stored filename rather than assuming `<id>.mp4` —- // an imported .mov/.webm keeps its own container (videoUpload.js), so the- // reconstructed path 404s for it (#8978). Falls back to the historical- // reconstruction while the lookup is in flight or if it fails, same as- // useVideoFileSrc's other ScenePreview-style callers.- const clipFile = useVideoFileSrc(scene.videoHistoryId, { enabled: !!scene.videoHistoryId });- const clipSrc = scene.videoHistoryId- ? (clipFile.src || `/data/videos/${scene.videoHistoryId}.mp4`)- : null;- // Source-clip length, read from the inline player's metadata and keyed to- // the clip it was measured from so a regenerated clip is re-measured.+ // Keep playback mounted even when this shot shows a still or performance evidence.+ const clipPlayback = useSceneClipPlayback(scene);+ const { clipSrc, clipSec, clipSize, loops, playedSec } = clipPlayback;const [speakerDirty, setSpeakerDirty] = useState(false);const [speakerSaving, setSpeakerSaving] = useState(false);- const [clipMeta, setClipMeta] = useState(null);// Which slot's "Swap from unused" picker is open: 'image', 'video' or null.const [swapKind, setSwapKind] = useState(null);- const clipSec = clipMeta && clipMeta.id === scene.videoHistoryId ? clipMeta.sec : null;- const clipSize = clipMeta && clipMeta.id === scene.videoHistoryId && clipMeta.width > 0 ? { width: clipMeta.width, height: clipMeta.height } : null;- // Pre-#8964 scenes have no `loop` key and keep the legacy loop-to-fill render.- // A reversed clip is read once, backwards, so it holds rather than loops.- const loops = scene.loop !== false && !clipReversed(scene);- const spanSec = scene.beatAligned && typeof scene.startSec === 'number' && typeof scene.endSec === 'number'- ? scene.endSec - scene.startSec- : null;- // The clip's playing length with its hand-set speed and offset, as the render times it.- const clipRate = clipSpeedRate(scene);- const clipLead = clipOffsetSec(scene);- const playedSec = clipSec != null ? Math.max(0, -clipLead) + Math.max(0, clipSec - Math.max(0, clipLead)) / clipRate : null;- const shortBySec = !loops && spanSec != null && playedSec != null ? spanSec - playedSec : 0;- const underCovered = shortBySec > COVERAGE_TOLERANCE_SEC;- useEffect(() => { if (clipPlayerRef.current) clipPlayerRef.current.playbackRate = clipRate; }, [clipRate]);const applyPatch = (patch) => { onEditLocal(scene.sceneId, patch); onSave(scene.sceneId, patch); };const layer = MUSIC_VIDEO_VISUAL_LAYERS.includes(scene.visualLayer) ? scene.visualLayer : 'footage';const fieldId = (name) => `mv-scene-${scene.sceneId}-${name}`;@@ -474,21 +447,7 @@ export default function SceneCard({<p className="break-words text-[11px] text-port-warning">{songChange.status === 'new' ? 'New shot for lines the revised song added.' : `Before the song revision: ${songChange.previousLyricText ? `♪ ${songChange.previousLyricText}` : 'instrumental'}`}</p>)}{(layer !== 'footage' || codeShot) && promptField}- {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" />- <span className="min-w-0 flex-1 basis-48">- Shot runs {spanSec.toFixed(1)}s but its clip is {playedSec.toFixed(1)}s — the render won't repeat it.- Trim the shot, continue or regenerate a longer clip, or loop it on purpose.- </span>- <button type="button" onClick={() => applyPatch({ endSec: Math.round((scene.startSec + playedSec) * 1000) / 1000 })}- className="rounded bg-port-bg border border-port-border px-2 py-1 min-h-[44px] sm:min-h-0 text-port-text">Trim to clip</button>- {!clipReversed(scene) && (- <button type="button" onClick={() => applyPatch({ loop: true })}- className="rounded bg-port-bg border border-port-border px-2 py-1 min-h-[44px] sm:min-h-0 text-port-text">Loop clip</button>- )}- </div>- )}+ <SceneClipCoverageNotice scene={scene} playback={clipPlayback} onChange={applyPatch} />{layer !== 'footage' && layered && !sceneHasAuthoredSpan(scene) && (<p role="alert" className="text-[11px] text-port-warning">Set a start and end — a {{ card: 'title card', code: 'code-drawn shot' }[layer] || 'still'} runs for exactly its span.@@ -530,50 +489,9 @@ export default function SceneCard({excerptId: performanceReview.excerptId, sourceAssetId: repairPlan.sourceAssetId, boundarySec: repairPlan.boundarySec,}) : null} />)}- {scene.videoHistoryId && !performance && (- <div className="relative w-full">- <video- ref={clipPlayerRef}- src={clipSrc}- className={`block w-full aspect-video ${sceneFrameFit(scene) === 'fill' ? 'object-cover' : 'object-contain'} rounded border border-port-border bg-black`}- muted- playsInline- preload="metadata"- controls- onLoadedMetadata={(e) => {- e.currentTarget.playbackRate = clipRate;- const sec = e.currentTarget.duration;- const { videoWidth: width, videoHeight: height } = e.currentTarget;- if (Number.isFinite(sec) && sec > 0) setClipMeta({ id: scene.videoHistoryId, sec, width, height });- }}- />- {/* This thumbnail plays the file as is; the player and the render play it backwards. */}- {clipReversed(scene) && (- <span className="port-media-overlay pointer-events-none absolute left-1 top-1 rounded px-1.5 py-0.5 text-[10px]">Reversed in the player</span>- )}- {/* Corner expand — do not put the open handler on <video> itself;- that would fight native play/pause controls. Pause first so the- lightbox's unmuted autoplay doesn't double-play the audio. */}- <button- type="button"- onClick={() => {- clipPlayerRef.current?.pause();- onOpenPreview?.(`video:${scene.videoHistoryId}`);- }}- aria-label={`View scene ${index + 1} clip full size`}- title={`View scene ${index + 1} clip full size`}- className="always-dark absolute top-1 right-1 min-h-[44px] min-w-[44px] sm:min-h-0 sm:min-w-0 p-1 flex items-center justify-center rounded bg-black/50 text-white hover:bg-black/80 focus:outline-none focus:ring-2 focus:ring-port-accent"- >- <Maximize2 className="w-3 h-3" />- </button>- </div>- )}- {/* Step to a later frame and keep the clip from there, as a new take of this shot. */}- {scene.videoHistoryId && !performance && onTrimClip && (- <VideoStartTrimControl videoRef={clipPlayerRef} sourceKey={scene.videoHistoryId}- disabled={takeBusy || !!generatingVideo || shotLock?.clip === 'locked'}- onTrim={(startSec) => onTrimClip(scene, startSec)} />- )}+ <SceneClipPreview scene={scene} index={index} performance={performance} playback={clipPlayback}+ onOpenPreview={onOpenPreview} onTrimClip={onTrimClip}+ takeBusy={takeBusy} generatingVideo={generatingVideo} clipLocked={shotLock?.clip === 'locked'} />{/* Speed and offset by hand, from the same clip file, in the player and the final render. */}{scene.videoHistoryId && layer === 'footage' && (<SceneClipTiming fieldId={fieldId} scene={scene} onChange={applyPatch}diff --git a/client/src/components/musicVideo/SceneCard.test.jsx b/client/src/components/musicVideo/SceneCard.test.jsxindex 646ba792a7..2415dc94d5 100644--- a/client/src/components/musicVideo/SceneCard.test.jsx+++ b/client/src/components/musicVideo/SceneCard.test.jsx@@ -1,14 +1,18 @@import { useState } from 'react';import { beforeEach, describe, expect, it, vi } from 'vitest';import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';-vi.mock('../../hooks/useVideoFileSrc.js', () => ({ useVideoFileSrc: () => ({}) }));+vi.mock('../../hooks/useVideoFileSrc.js', () => ({ useVideoFileSrc: vi.fn(() => ({})) }));vi.mock('../../services/apiMusicVideo.js', async (importOriginal) => ({ ...(await importOriginal()), getMusicVideoMediaPool: vi.fn(async () => ({ items: [] })) }));import SceneCard from './SceneCard.jsx';import { GROK_VIDEO_DURATIONS } from '../../lib/grokVideoClip.js';+import { useVideoFileSrc } from '../../hooks/useVideoFileSrc.js';const GROK_MAX = GROK_VIDEO_DURATIONS.at(-1);// A card opens on the last Render on pick, so each test starts from the project setting.-beforeEach(() => localStorage.clear());+beforeEach(() => {+ localStorage.clear();+ useVideoFileSrc.mockReturnValue({});+});describe('code shot (#10297)', () => {it('offers no frame or clip generation for a code shot in a layered composition', () => {@@ -454,6 +458,120 @@ describe('frame fit for an off-shape clip', () => {});});+describe('clip playback and coverage', () => {+ const scene = { sceneId: 's1', referenceImageId: 'still.png', videoHistoryId: 'clip-1', beatAligned: true,+ startSec: 1.234, endSec: 10, loop: false, takes: [] };+ const metadata = (video, sec, width = 768, height = 512) => {+ Object.defineProperties(video, {+ duration: { value: sec, configurable: true },+ videoWidth: { value: width, configurable: true },+ videoHeight: { value: height, configurable: true },+ });+ fireEvent.loadedMetadata(video);+ };+ const coverage = () => screen.queryByText(/Shot runs .* but its clip is/);++ // Catches coverage based on raw file length, a stale clip's measurement, or a trim+ // save that loses millisecond rounding; also pins metadata lifetime across hidden previews.+ it('measures adjusted playback, retains it while hidden, invalidates a replacement, and trims the shot', () => {+ const onSave = vi.fn();+ const onEditLocal = vi.fn();+ const props = { index: 0, expanded: true, layered: true, onSave, onEditLocal };+ const adjusted = { ...scene, speedFps: 8, offsetFrames: 12 };+ const { container, rerender } = render(<SceneCard {...props} scene={adjusted} />);+ expect(coverage()).toBeNull();+ metadata(container.querySelector('video'), NaN);+ expect(coverage()).toBeNull();+ metadata(container.querySelector('video'), 4.567);+ expect(container.querySelector('video').playbackRate).toBeCloseTo(32 / 24);+ expect(coverage().textContent).toContain('clip is 3.1s');+ expect(screen.getByLabelText('Not 16:9')).toBeTruthy();+ rerender(<SceneCard {...props} scene={{ ...adjusted, visualLayer: 'still' }} />);+ expect(container.querySelector('section[aria-label="Render"] video')).toBeNull();+ expect(coverage()).toBeTruthy();+ rerender(<SceneCard {...props} scene={{ ...adjusted, videoHistoryId: 'clip-2' }} />);+ expect(coverage()).toBeNull();+ expect(screen.queryByLabelText('Not 16:9')).toBeNull();+ metadata(container.querySelector('video'), 4.567);+ fireEvent.click(screen.getByRole('button', { name: 'Trim to clip' }));+ expect(onEditLocal).toHaveBeenLastCalledWith('s1', { endSec: 4.284 });+ expect(onSave).toHaveBeenLastCalledWith('s1', { endSec: 4.284 });+ // Negative offset delays the clip rather than cutting its beginning.+ rerender(<SceneCard {...props} scene={{ ...adjusted, videoHistoryId: 'clip-2', offsetFrames: -12 }} />);+ expect(coverage().textContent).toContain('clip is 3.9s');+ });++ // Catches a changed tolerance, legacy absent-loop scenes no longer looping,+ // or a reversed shot being offered a loop the renderer cannot use.+ it('warns only beyond the tolerance, preserves legacy looping, and treats reverse as one pass', () => {+ const onSave = vi.fn();+ const props = { index: 0, expanded: true, onSave, onEditLocal: vi.fn() };+ const bounded = { ...scene, startSec: 0, endSec: 4.25 };+ const { container, rerender } = render(<SceneCard {...props} scene={bounded} />);+ metadata(container.querySelector('video'), 4);+ expect(coverage()).toBeNull();+ rerender(<SceneCard {...props} scene={{ ...bounded, endSec: 4.251 }} />);+ expect(coverage()).toBeTruthy();+ fireEvent.click(screen.getByRole('button', { name: 'Loop clip' }));+ expect(onSave).toHaveBeenLastCalledWith('s1', { loop: true });+ rerender(<SceneCard {...props} scene={{ ...bounded, endSec: 6, loop: undefined }} />);+ expect(coverage()).toBeNull();+ expect(screen.getByLabelText('Loop clip')).toBeChecked();+ rerender(<SceneCard {...props} scene={{ ...bounded, endSec: 6, loop: undefined, reverse: true }} />);+ expect(coverage()).toBeTruthy();+ expect(screen.queryByRole('button', { name: 'Loop clip' })).toBeNull();+ expect(screen.getByLabelText('Loop clip')).toBeDisabled();+ expect(screen.getByText('Reversed in the player')).toBeTruthy();+ });++ // Catches reconstructed URLs replacing imported filenames, native controls+ // losing their playback ownership, or the lightbox opening before pause.+ it('keeps the resolved container and fallback, and pauses before opening the clip lightbox', () => {+ useVideoFileSrc.mockReturnValue({ src: '/data/videos/imported.webm' });+ const onOpenPreview = vi.fn();+ const props = { scene, index: 1, expanded: true, onEditLocal: vi.fn(), onSave: vi.fn(), onOpenPreview };+ const { container, rerender } = render(<SceneCard {...props} />);+ const video = container.querySelector('video');+ expect(video.getAttribute('src')).toBe('/data/videos/imported.webm');+ expect(video.controls).toBe(true);+ const pause = vi.spyOn(video, 'pause').mockImplementation(() => {+ expect(onOpenPreview).not.toHaveBeenCalled();+ });+ fireEvent.click(video);+ expect(onOpenPreview).not.toHaveBeenCalled();+ fireEvent.click(screen.getByRole('button', { name: 'View scene 2 clip full size' }));+ expect(pause).toHaveBeenCalledOnce();+ expect(onOpenPreview).toHaveBeenCalledWith('video:clip-1');+ useVideoFileSrc.mockReturnValue({ src: null });+ rerender(<SceneCard {...props} scene={{ ...scene, videoHistoryId: 'clip-2' }} />);+ expect(video.getAttribute('src')).toBe('/data/videos/clip-2.mp4');+ });++ // Catches source trim losing its scene argument or becoming enabled during+ // take/render work or a clip lock after the preview moves out of SceneCard.+ it('trims the source at the chosen frame and preserves every busy gate', async () => {+ const { ShotLockContext } = await import('./ShotLock.jsx');+ const onTrimClip = vi.fn();+ const props = { scene, index: 0, expanded: true, onEditLocal: vi.fn(), onSave: vi.fn(), onTrimClip };+ const { container, rerender } = render(<SceneCard {...props} />);+ const video = container.querySelector('video');+ vi.spyOn(video, 'pause').mockImplementation(() => {});+ expect(screen.getByRole('button', { name: 'Start clip here' })).toBeDisabled();+ fireEvent.click(screen.getByRole('button', { name: 'Next frame' }));+ fireEvent.click(screen.getByRole('button', { name: 'Start clip here' }));+ expect(onTrimClip).toHaveBeenCalledWith(scene, 1 / 24);+ await waitFor(() => expect(screen.getByRole('button', { name: 'Start clip here' })).toBeEnabled());+ rerender(<SceneCard {...props} takeBusy />);+ expect(screen.getByRole('button', { name: 'Next frame' })).toBeDisabled();+ rerender(<SceneCard {...props} generatingVideo />);+ expect(screen.getByRole('button', { name: 'Next frame' })).toBeDisabled();+ rerender(<ShotLockContext.Provider value={{ locks: { s1: 'locked' }, clips: { s1: 'locked' }, toggle: () => {}, busy: false }}>+ <SceneCard {...props} />+ </ShotLockContext.Provider>);+ expect(screen.getByRole('button', { name: 'Next frame' })).toBeDisabled();+ });+});+describe('Sent to the model', () => {// Uniquely catches the card's Render sending anything other than what the card shows, or dropping the Song audio toggle.it('shows the prompt Render sends and hands it, with the song audio pick, to the render', () => {diff --git a/client/src/components/musicVideo/SceneClipCoverageNotice.jsx b/client/src/components/musicVideo/SceneClipCoverageNotice.jsxnew file mode 100644index 0000000000..81e7b9918e--- /dev/null+++ b/client/src/components/musicVideo/SceneClipCoverageNotice.jsx@@ -0,0 +1,22 @@+import { AlertTriangle } from 'lucide-react';+import { clipReversed } from '../../lib/musicVideoLayers.js';++/** The native clip's usable duration compared with the authored shot span. */+export default function SceneClipCoverageNotice({ scene, playback, onChange }) {+ const { underCovered, spanSec, playedSec } = playback;+ return 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" />+ <span className="min-w-0 flex-1 basis-48">+ Shot runs {spanSec.toFixed(1)}s but its clip is {playedSec.toFixed(1)}s — the render won't repeat it.+ Trim the shot, continue or regenerate a longer clip, or loop it on purpose.+ </span>+ <button type="button" onClick={() => onChange({ endSec: Math.round((scene.startSec + playedSec) * 1000) / 1000 })}+ className="rounded bg-port-bg border border-port-border px-2 py-1 min-h-[44px] sm:min-h-0 text-port-text">Trim to clip</button>+ {!clipReversed(scene) && (+ <button type="button" onClick={() => onChange({ loop: true })}+ className="rounded bg-port-bg border border-port-border px-2 py-1 min-h-[44px] sm:min-h-0 text-port-text">Loop clip</button>+ )}+ </div>+ );+}diff --git a/client/src/components/musicVideo/SceneClipPreview.jsx b/client/src/components/musicVideo/SceneClipPreview.jsxnew file mode 100644index 0000000000..a3087c6428--- /dev/null+++ b/client/src/components/musicVideo/SceneClipPreview.jsx@@ -0,0 +1,51 @@+import { Maximize2 } from 'lucide-react';+import VideoStartTrimControl from '../media/VideoStartTrimControl.jsx';+import { clipReversed } from '../../lib/musicVideoLayers.js';+import { sceneFrameFit } from './SceneFrameFit.jsx';++/** Native playback and source trim; metadata lifetime belongs to the card's hook. */+export default function SceneClipPreview({ scene, index, performance, playback, onOpenPreview, onTrimClip, takeBusy, generatingVideo, clipLocked }) {+ const { clipPlayerRef, clipSrc, onLoadedMetadata } = playback;+ return (+ <>+ {scene.videoHistoryId && !performance && (+ <div className="relative w-full">+ <video+ ref={clipPlayerRef}+ src={clipSrc}+ className={`block w-full aspect-video ${sceneFrameFit(scene) === 'fill' ? 'object-cover' : 'object-contain'} rounded border border-port-border bg-black`}+ muted+ playsInline+ preload="metadata"+ controls+ onLoadedMetadata={onLoadedMetadata}+ />+ {/* This thumbnail plays the file as is; the player and the render play it backwards. */}+ {clipReversed(scene) && (+ <span className="port-media-overlay pointer-events-none absolute left-1 top-1 rounded px-1.5 py-0.5 text-[10px]">Reversed in the player</span>+ )}+ {/* Keep native play/pause ownership on the video. Pause before the+ lightbox's unmuted autoplay so both players cannot play together. */}+ <button+ type="button"+ onClick={() => {+ clipPlayerRef.current?.pause();+ onOpenPreview?.(`video:${scene.videoHistoryId}`);+ }}+ aria-label={`View scene ${index + 1} clip full size`}+ title={`View scene ${index + 1} clip full size`}+ className="always-dark absolute top-1 right-1 min-h-[44px] min-w-[44px] sm:min-h-0 sm:min-w-0 p-1 flex items-center justify-center rounded bg-black/50 text-white hover:bg-black/80 focus:outline-none focus:ring-2 focus:ring-port-accent"+ >+ <Maximize2 className="w-3 h-3" />+ </button>+ </div>+ )}+ {/* Keep the clip from a later frame as a new take of this shot. */}+ {scene.videoHistoryId && !performance && onTrimClip && (+ <VideoStartTrimControl videoRef={clipPlayerRef} sourceKey={scene.videoHistoryId}+ disabled={takeBusy || !!generatingVideo || clipLocked}+ onTrim={(startSec) => onTrimClip(scene, startSec)} />+ )}+ </>+ );+}diff --git a/client/src/hooks/README.md b/client/src/hooks/README.mdindex a050d1b770..9a34945f42 100644--- a/client/src/hooks/README.md+++ b/client/src/hooks/README.md@@ -55,6 +55,7 @@ grep -i "what you want to do" client/src/hooks/README.md| `useProcessLogs` | Live PM2 log tail for one process over the shared socket: owns the `logs:subscribe`/`line`/`subscribed`/`error` lifecycle, per-`processName` frame filtering, and a 1000-line ring buffer. Pass `appId` so an app with its own PM2_HOME streams from the right home. Returns `{ logs, subscribed, status, statusDetail, retry, clear }`; `status` is `connecting`/`live`/`closed`/`error`/`disconnected`, shared by every consumer — a closed/errored/disconnected stream keeps its lines and `retry()` resubscribes once (#9959). | Any surface showing a PM2 process's live output (Processes tab, desktop-app launch progress). || `useMediaJobProgress` | Live progress for a single `mediaJobQueue` job. | Subscribing to a known media-job id. || `useSceneBatch` | Counter for one Music Video "generate every missing frame / clip" batch (#10153): `{ state, begin, register, kickoffFailed, completedWithoutJob, settled, cancel, dismiss }`. Fed by a lane's `onSettled`; `cancel()` cancels the batch's queued and running jobs through the media-job cancel API (spinners clear via the lane's canceled event). | A batch of per-scene renders that needs "N of M done · K failed" and "Cancel remaining". |+| `useSceneClipPlayback` | `useSceneClipPlayback(scene)` owns the native clip ref, filename resolution, clip-ID-keyed metadata, dimensions, legacy loop state and speed/offset-adjusted coverage; returns those values and `onLoadedMetadata`. | Keep unconditional in SceneCard so hiding its preview preserves measurements, while a replacement clip invalidates them. || `useSceneRenderLifecycle` | One Music Video board lane's async-render lifecycle: owns the per-scene spinner state (`genScenes`), job-id→scene correlation, orphan-terminal reconcile, and the durable-attach + `*-gen:completed/failed/canceled` socket subscription (with running-cancel toast disambiguation). Optional `startedEvent` / `progressEvent` feed `sceneProgress` (queued → running + fraction) and `onSettled({ jobId, sceneId, outcome })` reports each tracked job's terminal outcome; failure toasts name the scene + the failed event's `error` and a batch collapses into one summary toast; `restoreJobs([{ jobId, sceneId }])` re-lights spinners after a reload (#10154). Returns `{ genScenes, sceneProgress, failedScenes, startScene, clearScene, trackJob, restoreJobs }`. | A board lane that kicks media-job renders per scene and clears spinners from terminal events (reference frame, i2v clip). One call per lane. || `useSlotInFlight` | Whether a render slot (`{ jobId, filename }`) has an in-flight render; returns `{ inFlight, setStatus }`. A present `filename` (or 5s grace on a stale/expired job) clears `inFlight` so the render button never sticks "loading". | A render button that should disable + spin only while its own slot is actually rendering (comic pages, covers). Wire `setStatus` to the slot's `MediaJobThumb` `onStatus`. || `useMediaJobSse` | The one owner of a displayed media render's lifecycle: `start(kickoff, handlers, { jobIdOf, ifIdle, onKickoffError })` runs the POST (or an active-job read), adopts the acknowledged job and awaits its `/{kind}-gen/:id/events` terminal frame; `cancel()` cancels only that job (before the acknowledgement it cancels the eventual job once, opening no stream); `dispose()` (also on unmount) detaches without cancelling durable work. A cancelled/detached/superseded run settles once with an error `isMediaRunEnded()` recognises. `attach()` stays the bare transport. | POST-then-attach (or resume-then-attach) media render flows — Video Gen, Image Gen, Settings Test Render. Don't keep a page-local job id / run token / reject ref / raw `EventSource` close. |diff --git a/client/src/hooks/index.js b/client/src/hooks/index.jsindex ade1771b98..281787891a 100644--- a/client/src/hooks/index.js+++ b/client/src/hooks/index.js@@ -61,6 +61,7 @@ export * from './useKeyboardShortcuts.js';export { default as useMediaJobProgress } from './useMediaJobProgress.js';export * from './useMediaJobSse.js';export { default as useSceneBatch } from './useSceneBatch.js';+export { default as useSceneClipPlayback } from './useSceneClipPlayback.js';export { default as useSceneRenderLifecycle } from './useSceneRenderLifecycle.js';export { default as useMusicVideoAutoReview } from './useMusicVideoAutoReview.js';export { default as useMusicVideoCastAndSets } from './useMusicVideoCastAndSets.js';diff --git a/client/src/hooks/useSceneClipPlayback.js b/client/src/hooks/useSceneClipPlayback.jsnew file mode 100644index 0000000000..a52e9402c6--- /dev/null+++ b/client/src/hooks/useSceneClipPlayback.js@@ -0,0 +1,40 @@+import { useEffect, useRef, useState } from 'react';+import { useVideoFileSrc } from './useVideoFileSrc.js';+import { clipOffsetSec, clipReversed, clipSpeedRate } from '../lib/musicVideoLayers.js';+import { COVERAGE_TOLERANCE_SEC } from '../lib/musicVideoSceneAttention.js';++/** A shot's native clip metadata and render-adjusted coverage. Keep mounted with the card. */+export default function useSceneClipPlayback(scene) {+ const clipPlayerRef = useRef(null);+ // Imported .mov/.webm files keep their container. Preserve the historical+ // fallback while the existing filename lookup is in flight or has failed.+ const clipFile = useVideoFileSrc(scene.videoHistoryId, { enabled: !!scene.videoHistoryId });+ const clipSrc = scene.videoHistoryId+ ? (clipFile.src || `/data/videos/${scene.videoHistoryId}.mp4`)+ : null;+ // Key measurements to their source so replacing a clip invalidates them+ // immediately, even when the native preview is currently hidden.+ const [clipMeta, setClipMeta] = useState(null);+ const clipSec = clipMeta && clipMeta.id === scene.videoHistoryId ? clipMeta.sec : null;+ const clipSize = clipMeta && clipMeta.id === scene.videoHistoryId && clipMeta.width > 0 ? { width: clipMeta.width, height: clipMeta.height } : null;+ // Absent loop preserves legacy loop-to-fill; reverse always plays once.+ const loops = scene.loop !== false && !clipReversed(scene);+ const spanSec = scene.beatAligned && typeof scene.startSec === 'number' && typeof scene.endSec === 'number'+ ? scene.endSec - scene.startSec+ : null;+ const clipRate = clipSpeedRate(scene);+ const clipLead = clipOffsetSec(scene);+ const playedSec = clipSec != null ? Math.max(0, -clipLead) + Math.max(0, clipSec - Math.max(0, clipLead)) / clipRate : null;+ const shortBySec = !loops && spanSec != null && playedSec != null ? spanSec - playedSec : 0;+ const underCovered = shortBySec > COVERAGE_TOLERANCE_SEC;+ useEffect(() => { if (clipPlayerRef.current) clipPlayerRef.current.playbackRate = clipRate; }, [clipRate]);++ const onLoadedMetadata = (e) => {+ e.currentTarget.playbackRate = clipRate;+ const sec = e.currentTarget.duration;+ const { videoWidth: width, videoHeight: height } = e.currentTarget;+ if (Number.isFinite(sec) && sec > 0) setClipMeta({ id: scene.videoHistoryId, sec, width, height });+ };++ return { clipPlayerRef, clipSrc, clipSec, clipSize, loops, spanSec, playedSec, underCovered, onLoadedMetadata };+}