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
"Human Directed" ending: generated vs used, a collage floor, a board card, and a reachable side dock (#11538)
[._.]/1b397ccc5902
diff --git a/client/src/components/musicVideo/EndingCard.jsx b/client/src/components/musicVideo/EndingCard.jsxnew file mode 100644index 0000000000..824df51d13--- /dev/null+++ b/client/src/components/musicVideo/EndingCard.jsx@@ -0,0 +1,115 @@+import { useEffect, useState } from 'react';+import { Play, RotateCcw, Scissors, Square, X } from 'lucide-react';+import FilmLookFrame from '../media/FilmLookFrame.jsx';+import StatsOutroCanvas from './StatsOutroCanvas.jsx';+import StatsOutroPanel from './StatsOutroPanel.jsx';+import useMusicVideoStatsOutro from '../../hooks/useMusicVideoStatsOutro.js';+import { getMusicVideoOutroStats } from '../../services/apiMusicVideo.js';+import { formatCount } from '../../utils/formatters.js';+import { STATS_OUTRO_DEFAULTS, normalizeStatsOutro, statsOutroDecisions, statsOutroRows } from '../../../../server/lib/musicVideoStatsOutro.js';++const PREVIEW_FPS = 24;++/** The ending's length: its own when on, else the length it would get when turned on. */+const endingSeconds = (project) => normalizeStatsOutro(project.statsOutro)?.durationSec ?? STATS_OUTRO_DEFAULTS.durationSec;++// The frame a still of the ending shows: every count landed, before it fades out.+const posterTime = (seconds) => Math.max(0, seconds - 1);++/**+ * The project's cutting room floor tally while the Ending card is open,+ * fetched each time it opens so it counts the latest choices. Null while it+ * loads or when it cannot be read.+ */+function useEndingStats(projectId) {+ const [stats, setStats] = useState(null);+ useEffect(() => {+ let active = true;+ getMusicVideoOutroStats(projectId, { silent: true })+ .then((next) => { if (active) setStats(next?.stats || null); })+ .catch(() => {});+ return () => { active = false; };+ }, [projectId]);+ return stats;+}++/** The Ending's thumbnail after the last shot on the board: its run time after the song, or Off. */+export function EndingThumbnail({ project, open, onOpen }) {+ const outro = normalizeStatsOutro(project.statsOutro);+ const seconds = endingSeconds(project);+ return (+ <button type="button" aria-pressed={open} onClick={onOpen} aria-label="Open the ending: cutting room floor"+ className={`min-w-0 rounded border p-2 text-left ${open ? 'border-port-accent bg-port-accent/10' : 'border-dashed border-port-border bg-port-card'}`}>+ <span className={`flex aspect-video w-full flex-col items-center justify-center gap-1 rounded bg-black text-[#e8c27a] ${outro?.enabled ? '' : 'opacity-50'}`}>+ <Scissors size={20} aria-hidden="true" />+ <span className="px-1 text-center font-mono text-[10px] uppercase tracking-wider">The cutting room floor</span>+ </span>+ <span className="mt-1 block truncate text-sm">Ending · Cutting room floor</span>+ <span className="block text-xs text-port-text-muted">+ {outro?.enabled+ ? <><span className="font-medium text-port-text">{seconds.toFixed(2)}s · </span>after the song</>+ : 'Off'}+ </span>+ </button>+ );+}++/**+ * The open Ending on the board: a preview of the scene (with the project's+ * film look, as the render grades it), its on/off and length, and the counts+ * it shows. The counts and the floor's stills come from the project itself.+ */+export default function EndingCard({ project, onEditLocal, onSave, onClose }) {+ const seconds = endingSeconds(project);+ const stats = useEndingStats(project.id);+ const preview = useMusicVideoStatsOutro({ projectId: project.id, seconds });+ const shown = preview.stats || stats;+ const t = preview.active ? preview.t : posterTime(seconds);+ const running = preview.active && preview.t < seconds;+ const rows = shown ? statsOutroRows(shown) : [];+ const decisions = shown ? statsOutroDecisions(shown) : 0;+ return (+ <section aria-label="Ending: cutting room floor" className="space-y-2 rounded-lg border border-port-accent bg-port-card p-2">+ <div className="flex items-center justify-between gap-2">+ <h3 className="inline-flex min-w-0 items-center gap-1.5 text-sm font-medium">+ <Scissors size={14} className="shrink-0 text-port-accent" aria-hidden="true" />+ <span className="truncate">Ending · Cutting room floor</span>+ </h3>+ <button type="button" onClick={onClose} aria-label="Close the ending"+ className="flex min-h-[44px] min-w-[44px] items-center justify-center rounded text-port-text-muted sm:min-h-0 sm:min-w-0 sm:p-1">+ <X size={16} aria-hidden="true" />+ </button>+ </div>+ <div className="grid gap-3 @2xl:grid-cols-[minmax(0,3fr)_minmax(0,2fr)]">+ <div className="space-y-1.5">+ <figure className="relative aspect-video w-full overflow-hidden rounded border border-port-border bg-black">+ <FilmLookFrame look={project.filmLook} frame={Math.round(t * PREVIEW_FPS)} playing={running} className="h-full w-full">+ <StatsOutroCanvas stats={shown} t={t} durationSec={seconds} />+ </FilmLookFrame>+ </figure>+ <button type="button" onClick={running ? preview.stop : preview.start}+ className="flex min-h-[44px] items-center gap-1 rounded border border-port-border px-2 text-xs sm:min-h-0 sm:py-1">+ {running ? <><Square size={14} aria-hidden="true" /> Stop</>+ : preview.active ? <><RotateCcw size={14} aria-hidden="true" /> Replay</>+ : <><Play size={14} aria-hidden="true" /> Play {seconds}s</>}+ </button>+ </div>+ <div className="min-w-0 space-y-2">+ <StatsOutroPanel project={project} onEditLocal={onEditLocal} onSave={onSave} />+ {rows.length > 0 && <p className="text-sm font-medium">Human directed · {formatCount(decisions, { fallback: '0' })} decisions</p>}+ {rows.length > 0 && (+ <dl aria-label="What the ending counts" className="space-y-0.5 text-xs">+ {rows.map((row) => (+ <div key={row.label} className={`flex justify-between gap-2 ${row.accent ? 'font-medium text-port-accent' : ''}`}>+ <dt className="min-w-0 truncate">{row.label}</dt>+ <dd className="tabular-nums">{formatCount(row.value, { fallback: '0' })}</dd>+ </div>+ ))}+ </dl>+ )}+ <p className="text-xs text-port-text-muted">Decisions are every shot, every image and video used, and every cut, move and effect. Unused stills fill the floor.</p>+ </div>+ </div>+ </section>+ );+}diff --git a/client/src/components/musicVideo/MusicVideoLayout.jsx b/client/src/components/musicVideo/MusicVideoLayout.jsxindex ae621bda8d..7d9d9abdc9 100644--- a/client/src/components/musicVideo/MusicVideoLayout.jsx+++ b/client/src/components/musicVideo/MusicVideoLayout.jsx@@ -84,7 +84,7 @@ function StepRail({ stages, stage, onStageChange, needsYouStage, notes }) {// From `xl` the preview is a sticky right column under the header. Below it,// it sits in the page above the step, one folded row until opened, rather than// a bar pinned over the content.-const DOCK_CLASSES = 'min-w-0 max-xl:order-first max-xl:col-span-full xl:sticky xl:top-[calc(var(--mv-header-h,9rem)-0.75rem)] xl:max-h-[calc(100vh-var(--mv-header-h,9rem)-2rem)] xl:overflow-y-auto';+const DOCK_CLASSES = 'min-w-0 max-xl:order-first max-xl:col-span-full xl:sticky xl:top-[calc(var(--mv-header-h,9rem)-0.75rem)] xl:max-h-[calc(var(--mv-scroll-h,100dvh)-var(--mv-header-h,9rem)-2rem)] xl:overflow-y-auto';/*** The Music Video project frame. A sticky header says where the project stands@@ -130,10 +130,17 @@ export default function MusicVideoLayout({const header = headerRef.current;const root = rootRef.current;if (!header || !root || typeof ResizeObserver === 'undefined') return undefined;- const apply = () => root.style.setProperty('--mv-header-h', `${Math.round(header.getBoundingClientRect().height)}px`);+ // The dock's height fits the page's scroll area, which is shorter than the window whenever+ // the app shows a bar above it; sized to the window, the dock's last panel sat out of reach.+ const scroller = root.closest('main');+ const apply = () => {+ root.style.setProperty('--mv-header-h', `${Math.round(header.getBoundingClientRect().height)}px`);+ if (scroller) root.style.setProperty('--mv-scroll-h', `${scroller.clientHeight}px`);+ };apply();const observer = new ResizeObserver(apply);observer.observe(header);+ if (scroller) observer.observe(scroller);return () => observer.disconnect();}, []);diff --git a/client/src/components/musicVideo/StatsOutro.test.jsx b/client/src/components/musicVideo/StatsOutro.test.jsxindex f9e55b7973..b656404700 100644--- a/client/src/components/musicVideo/StatsOutro.test.jsx+++ b/client/src/components/musicVideo/StatsOutro.test.jsx@@ -42,7 +42,7 @@ describe('cutting room floor ending', () => {act(() => { audio.dispatchEvent(new Event('ended')); });expect(screen.getByTestId('animatic-stats-outro')).toBeTruthy();await waitFor(() => expect(getMusicVideoOutroStats).toHaveBeenCalledWith('p', { silent: true }));- expect(canvas.texts).toContain('THE CUTTING ROOM FLOOR');+ expect(canvas.texts).toContain('HUMAN DIRECTED');fireEvent.play(audio);expect(screen.queryByTestId('animatic-stats-outro')).toBeNull();fireEvent.click(screen.getByRole('button', { name: /Ending/ }));diff --git a/client/src/components/musicVideo/StatsOutroCanvas.jsx b/client/src/components/musicVideo/StatsOutroCanvas.jsxindex 4d050f24a9..3a566adc39 100644--- a/client/src/components/musicVideo/StatsOutroCanvas.jsx+++ b/client/src/components/musicVideo/StatsOutroCanvas.jsx@@ -70,7 +70,7 @@ export default function StatsOutroCanvas({ stats, t, durationSec }) {width={WIDTH}height={HEIGHT}role="img"- aria-label="The cutting room floor: what was made, kept and left out of this video"+ aria-label="Human directed: the choices behind this video, and what was left on the cutting room floor"className="pointer-events-none absolute inset-0 h-full w-full"data-testid="animatic-stats-outro"/>diff --git a/client/src/components/musicVideo/StatsOutroPanel.jsx b/client/src/components/musicVideo/StatsOutroPanel.jsxindex 9378931649..c1f94b4f76 100644--- a/client/src/components/musicVideo/StatsOutroPanel.jsx+++ b/client/src/components/musicVideo/StatsOutroPanel.jsx@@ -41,7 +41,7 @@ export default function StatsOutroPanel({ project, onEditLocal, onSave }) {</select></div><p className="min-w-0 flex-1 basis-48 text-xs text-port-text-muted">- Stills and clips made against the ones in the cut, takes rejected, transitions, effects, camera moves and lip-syncs, over the unused stills. Ending plays it in the player.+ A “Human directed” card: renders reviewed, images and videos generated against the ones used, and cuts, moves and effects, over the unused stills. Ending plays it in the player.</p></div>)}diff --git a/client/src/components/musicVideo/StoryboardAnimatic.jsx b/client/src/components/musicVideo/StoryboardAnimatic.jsxindex 89cbe1b1ff..7da0cb2bbc 100644--- a/client/src/components/musicVideo/StoryboardAnimatic.jsx+++ b/client/src/components/musicVideo/StoryboardAnimatic.jsx@@ -4,7 +4,8 @@ import { safeReadStorage, safeWriteStorage } from '../../lib/safeStorage.js';import { isFilmLookNeutral } from '../../lib/filmLook.js';import { Captions, Film, Scissors } from 'lucide-react';import { formatDurationSec } from '../../utils/formatters.js';-import { getMusicVideoLyricOverlayPreview, getMusicVideoOutroStats } from '../../services/apiMusicVideo.js';+import { getMusicVideoLyricOverlayPreview } from '../../services/apiMusicVideo.js';+import useMusicVideoStatsOutro from '../../hooks/useMusicVideoStatsOutro.js';import { playthroughVersion } from './CompositionPreviewPlayer.jsx';import { useVideoFileSrc } from '../../hooks/useVideoFileSrc.js';import { selectedPerformanceInstruction } from '../../lib/musicVideoShotTiming.js';@@ -426,53 +427,6 @@ function FadeBlack({ fade, audioRef, time }) {return <div ref={ref} data-testid="fade-black" style={{ opacity: 0 }} className="pointer-events-none absolute inset-0 bg-black" />;}-/**- * The cutting room floor outro after the song (lib/musicVideoStatsOutro.js):- * when the song ends it plays for its own length on a clock of its own, and- * Ending plays it straight away. Playing or seeking the song leaves it. The- * tally is fetched each time it starts, so it counts the latest choices.- * Returns `{ seconds, t, active, start, stop }` (`t` null while it is off screen).- */-function useStatsOutro({ project, audioRef }) {- const seconds = statsOutroSeconds(project.statsOutro);- const [t, setT] = useState(null);- const [stats, setStats] = useState(null);- const run = useRef({ handle: 0, startedAt: 0, generation: 0 });- const stop = useCallback(() => {- cancelAnimationFrame(run.current.handle);- run.current.generation += 1;- setT(null);- }, []);- const start = useCallback(() => {- if (!(seconds > 0)) return;- cancelAnimationFrame(run.current.handle);- const generation = ++run.current.generation;- run.current.startedAt = performance.now();- setT(0);- getMusicVideoOutroStats(project.id, { silent: true })- .then((next) => { if (run.current.generation === generation) setStats(next?.stats || null); })- .catch(() => {});- const tick = () => {- if (run.current.generation !== generation) return;- const elapsed = (performance.now() - run.current.startedAt) / 1000;- // It holds on its last (black) frame once it has run its length.- setT(Math.min(elapsed, seconds));- if (elapsed < seconds) run.current.handle = requestAnimationFrame(tick);- };- run.current.handle = requestAnimationFrame(tick);- }, [seconds, project.id]);- // A different video, or the outro turned off, leaves it.- useEffect(() => { stop(); setStats(null); }, [project.id, seconds, stop]);- useEffect(() => () => cancelAnimationFrame(run.current.handle), []);- useEffect(() => {- const audio = audioRef.current;- if (!audio || !(seconds > 0)) return undefined;- audio.addEventListener('ended', start);- return () => audio.removeEventListener('ended', start);- }, [audioRef, seconds, start]);- return { seconds, t, stats, active: t != null, start, stop };-}-/*** Something to watch before anything is rendered: the master song under the* storyboard, showing each shot's selected video clip (muted, in step with the@@ -497,7 +451,8 @@ export default function StoryboardAnimatic({ project, audioUrl, seekRequest, colconst scenes = project.scenes || [];const lyricsAvailable = hasTimedLyrics(project);const { overlay, failed } = useLyricOverlay({ project, enabled: lyricsAvailable && lyricsOn, audioRef, time });- const outro = useStatsOutro({ project, audioRef });+ // The cutting room floor outro: it plays when the song ends, and Ending plays it straight away; playing or seeking the song leaves it.+ const outro = useMusicVideoStatsOutro({ projectId: project.id, seconds: statsOutroSeconds(project.statsOutro), audioRef });const songEndSec = Number(project.audioAnalysis?.durationSec) || 0;useEffect(() => {if (!seekRequest || applied.current === seekRequest.n || !audioRef.current) return;diff --git a/client/src/components/musicVideo/stages/BoardStage.jsx b/client/src/components/musicVideo/stages/BoardStage.jsxindex 552742d6da..dd80abcb12 100644--- a/client/src/components/musicVideo/stages/BoardStage.jsx+++ b/client/src/components/musicVideo/stages/BoardStage.jsx@@ -1,8 +1,9 @@import { useContext, useEffect, useLayoutEffect, useRef } from 'react';-import { useSearchParams } from 'react-router';+import { useNavigate, useSearchParams } from 'react-router';import { Plus, Image as ImageIcon, Film, Code2, Type, FlagTriangleRight, Lock, LockOpen } from 'lucide-react';import ContactSheetButton from '../ContactSheetButton.jsx';import SceneCard from '../SceneCard.jsx';+import EndingCard, { EndingThumbnail } from '../EndingCard.jsx';import ScenePoster from '../ScenePoster.jsx';import { ShotLockContext, SHOT_LOCK_LABELS, overallShotLock } from '../ShotLock.jsx';import { shotNumbers } from '../ShotStepper.jsx';@@ -66,6 +67,19 @@ export default function BoardStage({ board }) {if (next === 'all') params.delete('scenes'); else params.set('scenes', next);return params;}, { replace: true });+ // The ending after the song sits after the last shot; opening it is a search param on the board (a shot's route closes it).+ const navigate = useNavigate();+ const endingOpen = !activeSceneId && searchParams.get('ending') === '1';+ const openEnding = () => {+ const params = new URLSearchParams(searchParams);+ params.set('ending', '1');+ navigate({ pathname: `/music-video/${project.id}/produce`, search: `?${params}` }, { replace: true });+ };+ const closeEnding = () => setSearchParams((prev) => {+ const params = new URLSearchParams(prev);+ params.delete('ending');+ return params;+ }, { replace: true });const layered = isLayeredComposition(project);const lipSyncBackend = videoSettings.audioReactiveSelected ? 'local' : videoSettings.settings.backend;const songDurationSec = project.audioAnalysis?.durationSec ?? null;@@ -189,8 +203,14 @@ export default function BoardStage({ board }) {</span>{codesById.get(scene.sceneId).length > 0 && <span className="block text-xs text-port-warning">{SCENE_ATTENTION_LABELS[codesById.get(scene.sceneId)[0]]}</span>}</button>)}+ {scenes.length > 0 && filter === 'all' && (+ <EndingThumbnail project={project} open={endingOpen} onOpen={endingOpen ? closeEnding : openEnding} />+ )}</div><div ref={inspectorRef} className="mt-3">+ {endingOpen && (+ <EndingCard project={project} onEditLocal={board.editProjectLocal} onSave={board.saveProjectFields} onClose={closeEnding} />+ )}{scenes.map((scene, idx) => scene.sceneId !== activeSceneId ? null : (<SceneCardkey={scene.sceneId}diff --git a/client/src/components/musicVideo/stages/BoardStage.test.jsx b/client/src/components/musicVideo/stages/BoardStage.test.jsxindex ba86f517b1..f814f84b41 100644--- a/client/src/components/musicVideo/stages/BoardStage.test.jsx+++ b/client/src/components/musicVideo/stages/BoardStage.test.jsx@@ -1,6 +1,6 @@// @vitest-environment happy-domimport { describe, it, expect, vi } from 'vitest';-import { fireEvent, render, screen } from '@testing-library/react';+import { fireEvent, render, screen, waitFor } from '@testing-library/react';import { MemoryRouter, useLocation } from 'react-router';import BoardStage from './BoardStage.jsx';import { ShotLockContext } from '../ShotLock.jsx';@@ -10,6 +10,8 @@ vi.mock('../BeatTimeline.jsx', () => ({ default: () => null }));vi.mock('../ContactSheetButton.jsx', () => ({ default: () => null }));vi.mock('../TreatmentPanel.jsx', () => ({ default: () => null, treatmentSummary: () => '' }));vi.mock('../ProjectActionGroups.jsx', () => ({ PlanActions: () => null }));+vi.mock('../../../services/apiMusicVideo.js', async (load) => ({ ...await load(),+ getMusicVideoOutroStats: vi.fn(async () => ({ stats: { stills: { made: 30, kept: 12 }, clips: { made: 9, kept: 4 }, rejected: 5, shots: 3, transitions: 0, imageEffects: 0, cameraMoves: 0, lipSyncs: 0, floorImages: [] } })) }));const scene = (n, extra = {}) => ({ sceneId: `s${n}`, order: n - 1, label: `Part ${n}`, referenceImageId: 'f.png', videoHistoryId: 'v', startSec: (n - 1) * 3, endSec: n * 3, takes: [], ...extra });const board = (scenes, over = {}) => ({@@ -120,3 +122,33 @@ describe('BoardStage scene cards', () => {expect(screen.getByRole('button', { name: 'Open Shot 2 · Verse' }).textContent).not.toContain('Takes to review');});});++describe('BoardStage ending', () => {+ // Uniquely catches the ending after the song being unreachable from the board, where the shots are managed.+ it('lists the ending after the last shot and opens its preview and settings there', async () => {+ const scenes = [scene(1), scene(2)];+ const saveProjectFields = vi.fn(async () => {});+ const b = board(scenes, { editProjectLocal: vi.fn(), saveProjectFields });+ // happy-dom paints no canvas; the scene's drawing is covered by StatsOutro.test.jsx.+ const canvas = vi.spyOn(window.HTMLCanvasElement.prototype, 'getContext').mockReturnValue(null);+ renderBoard(b, '/?scenes=all');+ const thumbs = screen.getByLabelText('Storyboard thumbnails').querySelectorAll(':scope > button');+ const ending = thumbs[thumbs.length - 1];+ expect(ending.getAttribute('aria-label')).toBe('Open the ending: cutting room floor');+ expect(ending.textContent).toContain('Off');+ fireEvent.click(ending);+ expect(screen.getByTestId('search').textContent).toContain('ending=1');+ const card = screen.getByRole('region', { name: 'Ending: cutting room floor' });+ await waitFor(() => expect(card.textContent).toContain('Left on the floor'));+ expect(card.textContent).toContain('Renders reviewed39');+ // The 3 shots, the 12 stills and 4 clips used are the decisions; renders made are not.+ expect(card.textContent).toContain('Human directed · 19 decisions');+ expect(screen.getByRole('button', { name: /Play 8s/ })).toBeTruthy();+ fireEvent.click(screen.getByLabelText(/Off/));+ expect(saveProjectFields).toHaveBeenCalledWith({ statsOutro: { enabled: true, durationSec: 8 } });+ fireEvent.click(screen.getByRole('button', { name: 'Close the ending' }));+ expect(screen.getByTestId('search').textContent).not.toContain('ending');+ expect(screen.queryByRole('region', { name: 'Ending: cutting room floor' })).toBeNull();+ canvas.mockRestore();+ });+});diff --git a/client/src/hooks/README.md b/client/src/hooks/README.mdindex 9a34945f42..4d23083061 100644--- a/client/src/hooks/README.md+++ b/client/src/hooks/README.md@@ -264,6 +264,7 @@ grep -i "what you want to do" client/src/hooks/README.md| `useAutonomousMusicVideo` | Fully-autonomous run (prompt → lyrics → Suno song → video): applies the project pushed on `music-video:autonomous` and toasts the outcomes that need the director (checkpoint waiting, needs you, finished, failed). Returns `{ busy, resume(edits?, { inline }?), stop(), cancel() }` (an `inline` resume rejects instead of toasting, for errors shown next to the control). | The Music Video autonomous run panel. || `useMusicVideoProduction` | Server-owned production run (#9066): start a browserless plan → frames → clips → reviewed-draft run with an allowed provider/model pool and explicit limits, and Stop / Resume / Cancel it; applies the project pushed on `music-video:production` and toasts terminal outcomes. Returns `{ busy, start(body), resume(runId, body?), stop(runId), cancel(runId) }`. | The Music Video production panel. || `useMusicVideoRenderJob` | The final-render job (#1760 Phase 2): kickoff (409 → attach to the existing job), SSE progress, terminal-frame handling and non-terminal stream-close recovery. Thin `useSseJobSlot` adapter with 0–1 progress conversion; returns `{ active, pending, context, job, progress, start(projectId), cancel, reattach(projectId), reattaching }`; a project the server marks `rendering` re-attaches on load through a READ of the live job (`GET /:id/render`), never a POST (#9940); `onSettled(reason, projectId)` fires on every terminal frame; `onRendered(projectId, result)` / `onFailed(projectId)` key on the projectId captured at kickoff. | The Music Video "Render final" control. |+| `useMusicVideoStatsOutro` | The cutting room floor outro's clock: `start()` plays it for `seconds` on its own rAF clock and fetches the tally afresh; with `audioRef` it also starts when the song ends; a new project or length stops it. Returns `{ seconds, t, stats, active, start, stop }`. | The storyboard animatic's ending and the board's Ending card. || `useMusicVideoRevisions` | Selective section revision (#8987): open a revision from a reviewed draft excerpt (its flagged sections' takes are rejected, the rest kept), resume it from the server checkpoint — generating ONLY the sections the server reports as `needsGeneration` through the board's scene lanes, or adopting the draft re-render via `attachRender` once every revised section has a take — and cancel it. A server refusal toasts as a failure; a throw in the hook's own follow-up AFTER the server succeeded reloads the saved record instead (#9940), so an opened repair whose resume failed stays recoverable from the "Needs attention" banner. Returns `{ busy, revise(excerptId, sceneIds?), repair(basis), repairPerformance(sceneId, input), resume(revisionId), cancel(revisionId) }`. | The Music Video excerpt panel. || `useMusicVideoAutoReview` | Opt-in automatic review/retries (#8988): start a run over a draft window with explicit review (`maxAttempts`) and paid-generation (`maxGenerations`) limits plus a vision reviewer; applies the project pushed on `music-video:auto-review` and reports outcomes; the server generates a run's revised sections itself (#10014), so the board never submits them and a run completes with no tab open. Returns `{ busy, action, start(startSec, endSec, limits, reviewer), resume(runId, limits?), stop(runId), cancel(runId) }`. | The Music Video excerpt panel. || `useMusicVideoExcerpts` | Draft excerpt render + timecoded review notes (#8986): a `useSseJobSlot` render job over a chosen `[startSec, endSec)` window (any terminal frame reloads the project, since the persisted excerpt shape lives server-side) plus add/edit/delete review-note calls that apply the fresh whole project from each response. Returns `{ rendering, progress, deletingId, noteBusyId, startExcerpt(startSec, endSec), cancelExcerpt(excerptId), attachRender(jobId, projectId), deleteExcerpt(excerptId), addNote(excerptId, {atSec, note, verdict?}), editNote(excerptId, noteId, patch), deleteNote(excerptId, noteId) }`. | The Music Video excerpt panel. |diff --git a/client/src/hooks/index.js b/client/src/hooks/index.jsindex 281787891a..95eaede400 100644--- a/client/src/hooks/index.js+++ b/client/src/hooks/index.js@@ -78,6 +78,7 @@ export { default as useMusicVideoModelSettings } from './useMusicVideoModelSettiexport { default as useMusicVideoProduction } from './useMusicVideoProduction.js';export { default as useAutonomousMusicVideo } from './useAutonomousMusicVideo.js';export { default as useMusicVideoRenderJob } from './useMusicVideoRenderJob.js';+export { default as useMusicVideoStatsOutro } from './useMusicVideoStatsOutro.js';export { default as useMusicVideoRevisions } from './useMusicVideoRevisions.js';export { default as useMusicVideoSceneMedia } from './useMusicVideoSceneMedia.js';export { default as useMusicVideoTakes } from './useMusicVideoTakes.js';diff --git a/client/src/hooks/useMusicVideoStatsOutro.js b/client/src/hooks/useMusicVideoStatsOutro.jsnew file mode 100644index 0000000000..faa0f18a04--- /dev/null+++ b/client/src/hooks/useMusicVideoStatsOutro.js@@ -0,0 +1,47 @@+import { useCallback, useEffect, useRef, useState } from 'react';+import { getMusicVideoOutroStats } from '../services/apiMusicVideo.js';++/**+ * The cutting room floor outro's clock (lib/musicVideoStatsOutro.js): `start()`+ * plays it for `seconds` on a clock of its own and fetches the tally afresh, so+ * it counts the latest choices; it holds on its last frame once it has run.+ * With `audioRef`, it also starts when that song ends. A different project or+ * length stops it. Returns `{ seconds, t, stats, active, start, stop }`+ * (`t` null while it is off screen).+ */+export default function useMusicVideoStatsOutro({ projectId, seconds, audioRef = null }) {+ const [t, setT] = useState(null);+ const [stats, setStats] = useState(null);+ const run = useRef({ handle: 0, startedAt: 0, generation: 0 });+ const stop = useCallback(() => {+ cancelAnimationFrame(run.current.handle);+ run.current.generation += 1;+ setT(null);+ }, []);+ const start = useCallback(() => {+ if (!(seconds > 0)) return;+ cancelAnimationFrame(run.current.handle);+ const generation = ++run.current.generation;+ run.current.startedAt = performance.now();+ setT(0);+ getMusicVideoOutroStats(projectId, { silent: true })+ .then((next) => { if (run.current.generation === generation) setStats(next?.stats || null); })+ .catch(() => {});+ const tick = () => {+ if (run.current.generation !== generation) return;+ const elapsed = (performance.now() - run.current.startedAt) / 1000;+ setT(Math.min(elapsed, seconds));+ if (elapsed < seconds) run.current.handle = requestAnimationFrame(tick);+ };+ run.current.handle = requestAnimationFrame(tick);+ }, [seconds, projectId]);+ useEffect(() => { stop(); setStats(null); }, [projectId, seconds, stop]);+ useEffect(() => () => cancelAnimationFrame(run.current.handle), []);+ useEffect(() => {+ const audio = audioRef?.current;+ if (!audio || !(seconds > 0)) return undefined;+ audio.addEventListener('ended', start);+ return () => audio.removeEventListener('ended', start);+ }, [audioRef, seconds, start]);+ return { seconds, t, stats, active: t != null, start, stop };+}diff --git a/server/lib/musicVideoStatsOutro.js b/server/lib/musicVideoStatsOutro.jsindex ded9dc981d..c9e855a74f 100644--- a/server/lib/musicVideoStatsOutro.js+++ b/server/lib/musicVideoStatsOutro.js@@ -1,9 +1,9 @@/*** Music Video — the cutting room floor outro: an optional closing scene that- * plays after the song ends and tallies the human choices behind the video- * (stills and clips made against the ones in the cut, takes rejected,- * transitions, image effects, camera moves, lip-sync shots), over a floor of- * the stills that did not make it. One record on the project+ * plays after the song ends under the title "Human Directed" and tallies the+ * work behind the video (every render reviewed, the images and videos+ * generated against the ones used, the cuts, moves and effects placed), over+ * a floor of the stills that did not make it. One record on the project* (`project.statsOutro`, null = off) turns it on and sets how long it runs;* it adds that time after the song and never shortens it.*@@ -19,8 +19,8 @@export const STATS_OUTRO_LIMITS = Object.freeze({ durationMin: 4, durationMax: 20 });export const STATS_OUTRO_DEFAULTS = Object.freeze({ enabled: false, durationSec: 8 });-/** How many unused stills lie on the floor behind the tally. */-export const STATS_OUTRO_FLOOR_MAX = 14;+/** How many unused stills are piled into the floor collage behind the tally. */+export const STATS_OUTRO_FLOOR_MAX = 48;/** The fonts the scene draws in (bundled OFL faces, registered by each page). */export const STATS_OUTRO_FONTS = Object.freeze({head: Object.freeze({ family: 'MV Archivo', file: 'archivo-variable.woff2' }),@@ -119,9 +119,10 @@ export function musicVideoOutroStats(project, { collectionItems = [] } = {}) {* module scope, only to each other by name. *//**- * The tally's lines, in order: `{ label, value, accent? }`. Stills and clips- * always show; a choice the director never made (no transitions, say) is left- * out rather than shown as a zero. The last line is what was left on the floor.+ * The tally's lines, in order: `{ label, value, choice?, accent? }`. A+ * `choice` line counts calls the director made. The images and videos lines+ * always show; cuts, moves and effects are left out when there are none. The+ * last line is what was left on the floor.*/function statsOutroRows(stats) {const n = (v) => (typeof v === 'number' && Number.isFinite(v) && v > 0 ? Math.round(v) : 0);@@ -129,20 +130,24 @@ function statsOutroRows(stats) {const stills = s.stills || {};const clips = s.clips || {};const rows = [- { label: 'Stills made', value: n(stills.made) },- { label: 'Clips made', value: n(clips.made) },- { label: 'Takes rejected', value: n(s.rejected), optional: true },- { label: 'Transitions placed', value: n(s.transitions), optional: true },- { label: 'Image effects', value: n(s.imageEffects), optional: true },- { label: 'Camera moves', value: n(s.cameraMoves), optional: true },- { label: 'Lip-sync shots', value: n(s.lipSyncs), optional: true },- { label: 'Shots in the cut', value: n(s.shots) },- ].filter((row) => !row.optional || row.value > 0).map(({ label, value }) => ({ label, value }));+ { label: 'Renders reviewed', value: n(stills.made) + n(clips.made) },+ { label: 'Images generated', value: n(stills.made) },+ { label: 'Images used', value: n(stills.kept), choice: true },+ { label: 'Videos generated', value: n(clips.made) },+ { label: 'Videos used', value: n(clips.kept), choice: true },+ { label: 'Cuts, moves & effects', value: n(s.transitions) + n(s.imageEffects) + n(s.cameraMoves) + n(s.lipSyncs), choice: true, optional: true },+ ].filter((row) => !row.optional || row.value > 0).map(({ optional: _optional, ...row }) => row);const floor = Math.max(0, n(stills.made) - n(stills.kept)) + Math.max(0, n(clips.made) - n(clips.kept));rows.push({ label: 'Left on the floor', value: floor, accent: true });return rows;}+/** The decisions the heading counts: every shot dreamed up, plus each `choice` line. */+function statsOutroDecisions(stats) {+ const shots = stats && typeof stats.shots === 'number' && stats.shots > 0 ? Math.round(stats.shots) : 0;+ return shots + statsOutroRows(stats).reduce((sum, row) => sum + (row.choice ? row.value : 0), 0);+}+/*** Paint the outro at scene time `t` (0 = the song's last frame) on a* width × height 2D context. `images[i]` is the loaded still for@@ -171,24 +176,43 @@ function drawStatsOutro(ctx, { width, height, t, durationSec, stats, images = []ctx.fillStyle = floorGrad;ctx.fillRect(0, 0, width, height);- // Prints and film offcuts dropped on the floor, landing one after another.- const prints = Math.max(8, (stats && Array.isArray(stats.floorImages) ? stats.floorImages.length : 0));- for (let i = 0; i < prints; i++) {- const land = ease((t - 0.1 - i * 0.07) / 0.5);- if (land <= 0) continue;- const size = unit * (0.2 + hash(i, 1) * 0.1);+ // The floor is a collage: prints and film offcuts piled edge to edge over the whole frame,+ // dropping in one after another. A grid of overlapping, tilted prints leaves no floor showing,+ // and a second, sparser layer on top makes it read as a pile rather than a wall.+ const floorCount = stats && Array.isArray(stats.floorImages) ? stats.floorImages.length : 0;+ const cell = unit * 0.22;+ const cols = Math.ceil(width / cell) + 1;+ const rowsN = Math.ceil(height / (cell * 0.8)) + 1;+ const spots = [];+ for (let r = 0; r < rowsN; r++) {+ for (let c = 0; c < cols; c++) spots.push({ x: (c - 0.5 + (r % 2) * 0.5) * cell, y: (r - 0.5) * cell * 0.8, scale: 1.3 });+ }+ const base = spots.length;+ for (let k = 0; k < Math.ceil(base / 3); k++) spots.push({ x: hash(k, 7) * width, y: hash(k, 8) * height, scale: 1.1 });+ // Shuffled so the pile lands all over the frame rather than row by row.+ const order = spots.map((_, i) => i).sort((a, b) => hash(a, 9) - hash(b, 9));+ const landOrder = [...order.filter((i) => i < base), ...order.filter((i) => i >= base)];+ const dropGap = 1.6 / Math.max(1, landOrder.length);+ landOrder.forEach((spotIndex, i) => {+ const land = ease((t - 0.05 - i * dropGap) / 0.35);+ if (land <= 0) return;+ const spot = spots[spotIndex];+ const size = cell * spot.scale * (0.92 + hash(spotIndex, 1) * 0.2);const w = size * 1.25;const h = size;- const x = (((i * 0.618034) + hash(i, 2) * 0.2) % 1) * (width + w) - w / 2;- const y = (((i * 0.381966) + hash(i, 3) * 0.3) % 1) * (height + h) - h / 2 + (1 - land) * -unit * 0.05;- const drift = t * unit * 0.004 * (0.5 + hash(i, 4));- const angle = (hash(i, 5) - 0.5) * 0.7;+ const x = spot.x + (hash(spotIndex, 2) - 0.5) * cell * 0.35;+ const y = spot.y + (hash(spotIndex, 3) - 0.5) * cell * 0.3 + (1 - land) * -unit * 0.04;+ const drift = t * unit * 0.002 * (0.5 + hash(spotIndex, 4));+ const angle = (hash(spotIndex, 5) - 0.5) * 0.6;ctx.save();ctx.translate(x + drift, y);ctx.rotate(angle);- ctx.scale(1 + (1 - land) * 0.12, 1 + (1 - land) * 0.12);- ctx.globalAlpha = land * 0.85;- const img = images[i] || null;+ ctx.scale(1 + (1 - land) * 0.15, 1 + (1 - land) * 0.15);+ ctx.globalAlpha = land;+ // A soft shadow under each print gives the pile its depth.+ ctx.fillStyle = 'rgba(0, 0, 0, 0.45)';+ ctx.fillRect(-w / 2 - size * 0.02, -h / 2 + size * 0.04, w + size * 0.1, h + size * 0.14);+ const img = floorCount ? images[spotIndex % floorCount] || null : null;const iw = img ? img.naturalWidth || img.width : 0;const ih = img ? img.naturalHeight || img.height : 0;if (iw > 0 && ih > 0) {@@ -215,7 +239,7 @@ function drawStatsOutro(ctx, { width, height, t, durationSec, stats, images = []ctx.fillRect(-w / 2 + w * 0.06, -h / 2 + hole * 2, w * 0.88, h - hole * 4);}ctx.restore();- }+ });// The prints sit in shadow, under the tally.ctx.fillStyle = 'rgba(8, 6, 5, 0.5)';ctx.fillRect(0, 0, width, height);@@ -233,14 +257,18 @@ function drawStatsOutro(ctx, { width, height, t, durationSec, stats, images = []const lineH = 1.5;const headScale = 1.45;// Fit the block's height first, then its widest line.- // Plate: padding, heading, a gap, the rows, a foot, padding (in units of the row size).- const blockUnits = pad + headScale + 0.6 + rows.length * lineH + 0.5 + pad;+ // Plate: padding, heading, the decision line, a gap, the rows, a foot, padding (in units of the row size).+ const blockUnits = pad + headScale + 1.95 + rows.length * lineH + 0.5 + pad;let px = safeH / blockUnits;const rowFont = (size, weight = 500) => `${weight} ${Math.floor(size * 100) / 100}px ${body}`;const headFont = (size) => `800 ${Math.floor(size * 100) / 100}px ${head}`;- const headText = 'THE CUTTING ROOM FLOOR';+ const headText = 'HUMAN DIRECTED';+ const decisions = statsOutroDecisions(stats);+ const shots = stats && typeof stats.shots === 'number' && stats.shots > 0 ? Math.round(stats.shots) : 0;+ const subText = (v) => `${fmt(v)} DECISIONS${shots ? ` · ${fmt(shots)} SHOTS` : ''}`;const widest = (size) => Math.max(measure(headText, headFont(size * headScale)) + size * pad * 2,+ measure(subText(Math.max(decisions, 10000)), rowFont(size, 600)) + size * pad * 2,...rows.map((row) => measure(row.label.toUpperCase(), rowFont(size)) + measure(fmt(Math.max(row.value, 1000)), rowFont(size, 600)) + size * (2 + pad * 2)),);const wide = widest(px);@@ -262,9 +290,14 @@ function drawStatsOutro(ctx, { width, height, t, durationSec, stats, images = []ctx.fillStyle = '#f3ead7';const headY = top + px * pad + px * headScale;ctx.fillText(headText, width / 2, headY);+ // Under it, every call the director made, counting up with the rows.+ ctx.font = rowFont(px, 600);+ ctx.fillStyle = '#ff8a4c';+ const subY = headY + px * 1.25;+ ctx.fillText(subText(decisions * ease((t - 0.9) / Math.max(1, D * 0.5))), width / 2, subY);// A rule under the heading.ctx.fillStyle = 'rgba(243, 196, 107, 0.7)';- ctx.fillRect(left + px * pad, headY + px * 0.45, plateW - px * pad * 2, Math.max(1, px * 0.06));+ ctx.fillRect(left + px * pad, subY + px * 0.55, plateW - px * pad * 2, Math.max(1, px * 0.06));// Rows arrive one by one in the first half of the scene, each counting up to its number.const firstRow = 0.9;const stagger = Math.min(0.4, Math.max(0.12, (D * 0.5 - firstRow) / Math.max(1, rows.length)));@@ -273,7 +306,7 @@ function drawStatsOutro(ctx, { width, height, t, durationSec, stats, images = []const show = ease((t - start) / 0.35);if (show <= 0) return;const counted = row.value * ease((t - start) / 0.9);- const y = headY + px * 0.6 + px * lineH * (i + 1) + (1 - show) * px * 0.4;+ const y = subY + px * 0.7 + px * lineH * (i + 1) + (1 - show) * px * 0.4;ctx.globalAlpha = plateIn * show;if (row.accent) {ctx.fillStyle = 'rgba(255, 122, 61, 0.14)';@@ -304,7 +337,7 @@ function drawStatsOutro(ctx, { width, height, t, durationSec, stats, images = []ctx.restore();}-export { statsOutroRows, drawStatsOutro };+export { statsOutroRows, statsOutroDecisions, drawStatsOutro };/*** The render page's script: draws the outro full-frame on a canvas and@@ -317,6 +350,7 @@ export function statsOutroPageSource({ stats, imageSrcs = [], width, height, fpsconst json = (value) => JSON.stringify(value).replace(/</g, '\\u003c');return `(() => {${statsOutroRows.toString()}+ ${statsOutroDecisions.toString()}${drawStatsOutro.toString()}const STATS = ${json(stats)};const SRCS = ${json(imageSrcs)};diff --git a/server/lib/musicVideoStatsOutro.test.js b/server/lib/musicVideoStatsOutro.test.jsindex 68b7ecf5d0..9984ae2eae 100644--- a/server/lib/musicVideoStatsOutro.test.js+++ b/server/lib/musicVideoStatsOutro.test.js@@ -1,5 +1,5 @@import { describe, expect, it } from 'vitest';-import { STATS_OUTRO_FLOOR_MAX, musicVideoOutroStats, normalizeStatsOutro, statsOutroRows, statsOutroSeconds } from './musicVideoStatsOutro.js';+import { STATS_OUTRO_FLOOR_MAX, musicVideoOutroStats, statsOutroDecisions, normalizeStatsOutro, statsOutroRows, statsOutroSeconds } from './musicVideoStatsOutro.js';describe('cutting room floor outro', () => {it('is off unless turned on, and its length stays inside its limits', () => {@@ -44,17 +44,25 @@ describe('cutting room floor outro', () => {floorImages: ['bad.png', 'floor.png'],});const rows = statsOutroRows(stats);- expect(rows.at(-1)).toEqual({ label: 'Left on the floor', value: 4, accent: true });- expect(rows.map((row) => row.label)).toEqual(['Stills made', 'Clips made', 'Takes rejected', 'Transitions placed', 'Image effects',- 'Camera moves', 'Lip-sync shots', 'Shots in the cut', 'Left on the floor']);+ expect(rows).toEqual([+ { label: 'Renders reviewed', value: 8 },+ { label: 'Images generated', value: 5 },+ { label: 'Images used', value: 3, choice: true },+ { label: 'Videos generated', value: 3 },+ { label: 'Videos used', value: 1, choice: true },+ { label: 'Cuts, moves & effects', value: 5, choice: true },+ { label: 'Left on the floor', value: 4, accent: true },+ ]);+ // Every shot dreamed up is a decision, then each still and clip used and each cut, move and effect.+ expect(statsOutroDecisions(stats)).toBe(2 + 3 + 1 + 5);});it('leaves out the choices never made and spreads the floor over the whole pile', () => {- const collectionItems = Array.from({ length: 40 }, (_, i) => ({ kind: 'image', ref: `still-${String(i).padStart(2, '0')}.png` }));+ const collectionItems = Array.from({ length: 120 }, (_, i) => ({ kind: 'image', ref: `still-${String(i).padStart(3, '0')}.png` }));const stats = musicVideoOutroStats({ scenes: [{ sceneId: 's' }] }, { collectionItems });expect(stats.floorImages).toHaveLength(STATS_OUTRO_FLOOR_MAX);- expect(stats.floorImages[0]).toBe('still-00.png');- expect(stats.floorImages.at(-1) > 'still-35.png').toBe(true);- expect(statsOutroRows(stats).map((row) => row.label)).toEqual(['Stills made', 'Clips made', 'Shots in the cut', 'Left on the floor']);+ expect(stats.floorImages[0]).toBe('still-000.png');+ expect(stats.floorImages.at(-1) > 'still-110.png').toBe(true);+ expect(statsOutroRows(stats).map((row) => row.label)).toEqual(['Renders reviewed', 'Images generated', 'Images used', 'Videos generated', 'Videos used', 'Left on the floor']);});});