Skip to content

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

feat: preview produced media on Creative Director cards and Overview tab (#2702)

[._.]/ Adam Eivy6ae94cb28673
diff --git a/client/src/components/creative-director/OverviewTab.jsx b/client/src/components/creative-director/OverviewTab.jsx
index 6eb566d172..41f784792c 100644
--- a/client/src/components/creative-director/OverviewTab.jsx
+++ b/client/src/components/creative-director/OverviewTab.jsx
@@ -2,6 +2,9 @@ import { Link } from 'react-router-dom';
import { useState, useEffect, useRef } from 'react';
import { Sparkles, Loader2 } from 'lucide-react';
import { updateCreativeDirectorProject, applyCreativeDirectorAutoCast } from '../../services/apiCreativeDirector.js';
+import { selectProjectPreview, previewAspectClass } from '../../lib/creativeDirectorPreview.js';
+import MediaImage from '../MediaImage.jsx';
+import ScenePreview from './ScenePreview.jsx';
import toast from '../ui/Toast';
export default function OverviewTab({ project, onProjectUpdate, onAsyncWorkQueued }) {
@@ -156,8 +159,44 @@ export default function OverviewTab({ project, onProjectUpdate, onAsyncWorkQueue
? <Link to={`/media/history?selected=${project.finalVideoId}`} className="text-port-accent">{project.finalVideoId}</Link>
: <span className="text-port-text-muted">not yet rendered</span>;
+ // Inline render of the produced media (#2702). The final cut is the only thing
+ // this section claims to show — a mid-production scene render deliberately
+ // does NOT surface here (the Segments tab already previews those, and framing
+ // one as the deliverable would misrepresent an unfinished project). A
+ // directive plan that emits images rather than video shows its produced image
+ // instead. When nothing is produced the section is omitted entirely, so the
+ // configuration stays above the fold and the "not yet rendered" copy on the
+ // Final video field remains the single honest signal.
+ const preview = selectProjectPreview(project);
+ const aspectClass = previewAspectClass(project.aspectRatio);
+ const inlineImage = !project.finalVideoId && preview.kind === 'image' ? preview : null;
+
return (
<div className="space-y-4 max-w-3xl">
+ {(project.finalVideoId || inlineImage) && (
+ <section className="bg-port-card border border-port-border rounded p-4 space-y-2">
+ <h2 className="text-sm font-semibold text-port-text-muted uppercase tracking-wide">
+ {project.finalVideoId ? 'Final video' : inlineImage.label}
+ </h2>
+ <div className={`${aspectClass} rounded overflow-hidden bg-port-bg max-h-[60vh] mx-auto`}>
+ {project.finalVideoId
+ ? <ScenePreview jobId={project.finalVideoId} label="Final video" aspectClass={aspectClass} />
+ : (
+ <MediaImage
+ src={inlineImage.src}
+ alt={`${inlineImage.label} — ${project.name || 'project'}`}
+ className="w-full h-full object-contain"
+ />
+ )}
+ </div>
+ {project.finalVideoId && (
+ <Link to={`/media/history?selected=${project.finalVideoId}`} className="text-port-accent text-xs">
+ Open in Media History
+ </Link>
+ )}
+ </section>
+ )}
+
<section className="bg-port-card border border-port-border rounded p-4 space-y-2">
<h2 className="text-sm font-semibold text-port-text-muted uppercase tracking-wide">Configuration</h2>
<Field label="Aspect ratio" value={project.aspectRatio} />
diff --git a/client/src/components/creative-director/ProjectPreview.jsx b/client/src/components/creative-director/ProjectPreview.jsx
new file mode 100644
index 0000000000..2a48f4cd1d
--- /dev/null
+++ b/client/src/components/creative-director/ProjectPreview.jsx
@@ -0,0 +1,91 @@
+import { useState } from 'react';
+import { Link } from 'react-router-dom';
+import { Play, Film } from 'lucide-react';
+import MediaImage from '../MediaImage.jsx';
+import ScenePreview from './ScenePreview.jsx';
+import { selectProjectPreview, previewAspectClass } from '../../lib/creativeDirectorPreview.js';
+
+/**
+ * Compact media preview for a Creative Director list card (#2702) — shows what
+ * the director actually produced instead of another line of metadata.
+ *
+ * Grid-weight contract: the card NEVER fetches an mp4 on its own. A video
+ * preview renders as its poster <img> only; the mp4 is fetched exclusively when
+ * the user hits the play affordance, which swaps in <ScenePreview> (the shared
+ * player — missing-media fallback, Retry, cache-bust, open-in-new-tab all live
+ * there, so this component hand-rolls nothing).
+ *
+ * Click targets are deliberately split. The poster sits INSIDE the card's
+ * <Link>, so clicking the artwork navigates to the project like the rest of the
+ * card. The play button is a SIBLING of that link, not a descendant: nesting a
+ * <button> inside an <a> is invalid HTML and would make "play" ambiguous with
+ * "navigate". It's a small centered badge, so the bulk of the poster still
+ * navigates.
+ */
+export default function ProjectPreview({ project, to }) {
+ const [playing, setPlaying] = useState(false);
+ const [posterMissing, setPosterMissing] = useState(false);
+ const preview = selectProjectPreview(project);
+ const aspectClass = previewAspectClass(project?.aspectRatio);
+
+ if (playing) {
+ return (
+ <ScenePreview
+ jobId={preview.jobId}
+ label={`${project?.name || 'Project'} — ${preview.label}`}
+ aspectClass={aspectClass}
+ autoPlay
+ />
+ );
+ }
+
+ return (
+ <div className={`relative ${aspectClass} rounded overflow-hidden bg-port-bg border border-port-border`}>
+ <Link to={to} className="block w-full h-full" aria-label={`Open ${project?.name || 'project'}`}>
+ {preview.kind === 'image' && (
+ <MediaImage
+ src={preview.src}
+ alt={`${preview.label} — ${project?.name || 'project'}`}
+ className="w-full h-full object-cover"
+ />
+ )}
+ {preview.kind === 'video' && !posterMissing && (
+ <img
+ src={preview.poster}
+ alt={`${preview.label} — ${project?.name || 'project'}`}
+ loading="lazy"
+ // A stitched final has no generated thumbnail today (#2702 leaves
+ // that out of scope), so a 404 here is expected, not exceptional —
+ // degrade to the placeholder rather than a broken-image icon. The
+ // play affordance stays either way: the mp4 can be fine even when
+ // its poster isn't.
+ onError={() => setPosterMissing(true)}
+ className="w-full h-full object-cover"
+ />
+ )}
+ {(preview.kind === 'none' || (preview.kind === 'video' && posterMissing)) && (
+ <div className="w-full h-full flex flex-col items-center justify-center gap-1 text-port-text-muted text-xs">
+ <Film className="w-4 h-4 opacity-50" aria-hidden="true" />
+ <span>{preview.kind === 'none' ? 'no render yet' : preview.label}</span>
+ </div>
+ )}
+ </Link>
+ {preview.kind === 'video' && (
+ <button
+ type="button"
+ onClick={() => setPlaying(true)}
+ aria-label={`Play ${preview.label}`}
+ title={`Play ${preview.label}`}
+ className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-10 h-10 flex items-center justify-center rounded-full bg-black/60 text-white hover:bg-black/80 focus:outline-none focus:ring-2 focus:ring-port-accent"
+ >
+ <Play className="w-4 h-4" aria-hidden="true" />
+ </button>
+ )}
+ {preview.kind !== 'none' && (
+ <span className="absolute bottom-1 left-1 px-1.5 py-0.5 rounded bg-black/60 text-white text-[10px] pointer-events-none">
+ {preview.label}
+ </span>
+ )}
+ </div>
+ );
+}
diff --git a/client/src/components/creative-director/ScenePreview.jsx b/client/src/components/creative-director/ScenePreview.jsx
index 24f22b2e33..38c33e367b 100644
--- a/client/src/components/creative-director/ScenePreview.jsx
+++ b/client/src/components/creative-director/ScenePreview.jsx
@@ -1,9 +1,11 @@
import { useState, useEffect } from 'react';
import { ExternalLink } from 'lucide-react';
+import { videoSrcForJob, videoPosterForJob } from '../../lib/creativeDirectorPreview.js';
/**
* Inline <video> preview for a single rendered scene. Used by SegmentsTab
- * (CD detail page) and by EpisodeVideoStage (Pipeline issue page).
+ * (CD detail page), EpisodeVideoStage (Pipeline issue page), the CD list
+ * cards (via ProjectPreview) and the CD Overview tab (#2702).
*
* Behavior notes:
* - `renderedJobId` survives even after the underlying mp4 is deleted from
@@ -16,8 +18,21 @@ import { ExternalLink } from 'lucide-react';
* error response.
* - `controls` + `preload="none"` keeps the thumbnail-driven idle state
* without ever fetching the full mp4 until the user hits Play.
+ *
+ * Props:
+ * jobId, label
+ * aspectClass? — Tailwind aspect class for the frame (default `aspect-video`).
+ * Lets a caller honor a project's locked 9:16 / 1:1 ratio.
+ * Applied to the empty + missing states too, so the box never
+ * changes shape as the media resolves.
+ * autoPlay? — start playing on mount. Used by the list card's play
+ * affordance, which swaps this in on click: the user already
+ * expressed intent, so a second click on the native controls
+ * would be redundant. Off by default — the grid must never
+ * fetch mp4s on its own (`preload="none"` only holds while
+ * this is false).
*/
-export default function ScenePreview({ jobId, label }) {
+export default function ScenePreview({ jobId, label, aspectClass = 'aspect-video', autoPlay = false }) {
const [missing, setMissing] = useState(false);
const [attempt, setAttempt] = useState(0);
useEffect(() => {
@@ -26,14 +41,14 @@ export default function ScenePreview({ jobId, label }) {
}, [jobId]);
if (!jobId) {
- return <div className="bg-port-bg aspect-video flex items-center justify-center text-port-text-muted text-xs">no render yet</div>;
+ return <div className={`bg-port-bg ${aspectClass} flex items-center justify-center text-port-text-muted text-xs`}>no render yet</div>;
}
const cacheBust = attempt > 0 ? `?retry=${attempt}` : '';
- const videoSrc = `/data/videos/${jobId}.mp4${cacheBust}`;
- const posterSrc = `/data/video-thumbnails/${jobId}.jpg${cacheBust}`;
+ const videoSrc = `${videoSrcForJob(jobId)}${cacheBust}`;
+ const posterSrc = `${videoPosterForJob(jobId)}${cacheBust}`;
if (missing) {
return (
- <div className="bg-port-bg aspect-video flex flex-col items-center justify-center text-port-text-muted text-xs gap-2">
+ <div className={`bg-port-bg ${aspectClass} flex flex-col items-center justify-center text-port-text-muted text-xs gap-2`}>
<span>media missing</span>
<button
type="button"
@@ -46,13 +61,14 @@ export default function ScenePreview({ jobId, label }) {
);
}
return (
- <div className="relative bg-port-bg aspect-video">
+ <div className={`relative bg-port-bg ${aspectClass}`}>
<video
key={attempt}
src={videoSrc}
poster={posterSrc}
controls
- preload="none"
+ preload={autoPlay ? 'metadata' : 'none'}
+ autoPlay={autoPlay}
playsInline
aria-label={label}
onError={() => setMissing(true)}
diff --git a/client/src/lib/README.md b/client/src/lib/README.md
index 79b713a802..fb53fe5b3a 100644
--- a/client/src/lib/README.md
+++ b/client/src/lib/README.md
@@ -39,6 +39,7 @@ grep -i "what you want to do" client/src/lib/README.md
| `bibleLimits.js` | Mirror of `server/lib/storyBible.js` `BIBLE_LIMITS`. |
| `catalogTypes.js` | Client mirror of `server/lib/catalogTypes.js` — catalog ingredient type registry (label, badge color, primary-content key/label, snippet fallback chain, per-type editor field list) for the Catalog list/picker/editor. |
| `creativeDirectorPlan.js` | Pure presentation helpers for the CD studio Plan board (CDO Phase 4) — annotate `plan.steps[]` with tool cost-class/timing/approval flags, cost/status summaries, owning-surface deep links, status/cost badge tone maps. |
+| `creativeDirectorPreview.js` | `selectProjectPreview(project)` → `{ kind: 'video'\|'image'\|'none', jobId?, src?, poster?, label }` — picks a CD project's representative produced asset (finalVideoId → last rendered scene → last done plan video/image step → startingImageFile) for the list cards + Overview tab (#2702). Pure, computed off the already-returned project payload (no fetch). Plus `previewAspectClass(aspectRatio)` (literal Tailwind classes — a computed `aspect-[w/h]` never lands in the build), `startingImageSrc()` (client mirror of `localImageFilename`), and the `videoSrcForJob`/`videoPosterForJob`/`imageSrcForJob` path builders — the one client-side definition of the `<jobId>`-named asset convention, shared with `ScenePreview.jsx`. |
| `editorialRoadmap.js` | `projectAnalyzedPoints` (aggregate roadmap → analyzed chart points with arc-position `frac`) + `dominant` (most-frequent string). Shared by EditorialRoadmapPanel and the Reader Map page. |
| `imageCleaners.js` | Mirror of `resolveCleanersFromConfig` from `server/lib/imageClean.js`. Reads `{cleanC2PA, denoise}` off a per-mode settings record. `cleanC2PA` defaults are mode-aware (on for `codex` + `external` — the backends that emit C2PA chunks today — off otherwise, as an allow-list rather than a deny-list); `denoise` defaults off everywhere (lossy, opt-in only). |
| `runnerFamilies.js` | Mirror of `server/lib/runners.js`. |
diff --git a/client/src/lib/creativeDirectorPreview.js b/client/src/lib/creativeDirectorPreview.js
new file mode 100644
index 0000000000..0877227dae
--- /dev/null
+++ b/client/src/lib/creativeDirectorPreview.js
@@ -0,0 +1,160 @@
+/**
+ * Pick the representative produced asset for a Creative Director project (#2702)
+ * so the list cards and the Overview tab can show *what the director made*
+ * rather than a wall of text.
+ *
+ * Pure + side-effect-free: everything it needs is already on the project payload
+ * returned by `GET /api/creative-director` (the list route does not slim), so a
+ * card renders a preview with no extra fetch.
+ *
+ * Selection priority (first match wins):
+ * 1. `finalVideoId` — the stitched final cut, or a directive
+ * plan's promoted last render.
+ * 2. last `treatment.scenes[]` render — a mid-production scene (last-wins, so a
+ * part-rendered treatment shows its latest).
+ * 3. last done video-render plan step — a directive plan's video BEFORE the
+ * advance loop promotes it to finalVideoId
+ * on completion (mid-flight commissions).
+ * 4. last done image-render plan step — a plan that emits images (e.g. a comic)
+ * rather than video.
+ * 5. `startingImageFile` — no render yet, but the project has a
+ * reference image. Labeled distinctly so
+ * the UI never passes an INPUT off as output.
+ * 6. `{ kind: 'none' }` — nothing to show.
+ *
+ * NOTE ON CAST PORTRAITS: #2702 also floated "first cast portrait" as a fallback.
+ * A project's `cast[]` member is `{ ingredientId, name, type, role, summary }` —
+ * it carries no image ref (portraits live on the catalog ingredient, attached via
+ * `catalogAttach`). Resolving one would need a per-card catalog fetch, which the
+ * issue puts out of scope ("compute previews from the already-returned project
+ * payload"), so that branch is intentionally absent.
+ */
+
+// A media history entry's id IS its jobId, and both workers name their output
+// after it — `data/videos/<jobId>.mp4` (videoGen/local.js) and
+// `data/images/<jobId>.png` (imageGen/local.js). These builders are the ONE
+// definition of that convention on the client; ScenePreview imports them too.
+export const videoSrcForJob = (jobId) => `/data/videos/${jobId}.mp4`;
+export const videoPosterForJob = (jobId) => `/data/video-thumbnails/${jobId}.jpg`;
+export const imageSrcForJob = (jobId) => `/data/images/${jobId}.png`;
+
+// The registry tools a plan step uses to render media. Mirrors
+// `VIDEO_RENDER_TOOL_NAME` in server/services/creativeDirector/planAdvance.js;
+// both settle with a `{ jobId }` result digest.
+const VIDEO_RENDER_TOOL = 'media_enqueueVideoJob';
+const IMAGE_RENDER_TOOL = 'media_enqueueImageJob';
+
+// Tailwind needs to SEE each class as a literal to emit it — a computed
+// `aspect-[${w}/${h}]` silently never lands in the build. Hence a static map.
+const ASPECT_CLASSES = Object.freeze({
+ '16:9': 'aspect-video',
+ '9:16': 'aspect-[9/16]',
+ '1:1': 'aspect-square',
+});
+
+/**
+ * Tailwind aspect class for a project's locked aspect ratio, falling back to
+ * `aspect-video` for an unset/legacy/hand-edited value.
+ */
+export function previewAspectClass(aspectRatio) {
+ return ASPECT_CLASSES[aspectRatio] || 'aspect-video';
+}
+
+const nonEmptyString = (v) => (typeof v === 'string' && v.trim() ? v.trim() : null);
+
+/**
+ * The jobId of the last `done` step for `toolName` (or null). Last-wins so a
+ * multi-render plan resolves to its most recent output — mirrors
+ * `lastRenderedVideoJobId` in planAdvance.js.
+ */
+function lastDoneStepJobId(plan, toolName) {
+ const steps = Array.isArray(plan?.steps) ? plan.steps : [];
+ for (let i = steps.length - 1; i >= 0; i -= 1) {
+ const step = steps[i];
+ if (step?.toolName === toolName && step.status === 'done') {
+ const jobId = nonEmptyString(step.result?.jobId);
+ if (jobId) return jobId;
+ }
+ }
+ return null;
+}
+
+/**
+ * The last treatment scene carrying a render (or null) as `{ jobId, label }`.
+ * Scene numbering follows `order` (SegmentsTab renders `order + 1`), falling
+ * back to the array index for a scene missing it.
+ */
+function lastRenderedScene(project) {
+ const scenes = Array.isArray(project?.treatment?.scenes) ? project.treatment.scenes : [];
+ for (let i = scenes.length - 1; i >= 0; i -= 1) {
+ const jobId = nonEmptyString(scenes[i]?.renderedJobId);
+ if (jobId) {
+ const order = Number.isInteger(scenes[i]?.order) ? scenes[i].order : i;
+ return { jobId, label: `Scene ${order + 1}` };
+ }
+ }
+ return null;
+}
+
+/**
+ * Resolve a project's `startingImageFile` to a servable `/data/images/` src, or
+ * null when it isn't a local gallery image. Client mirror of
+ * `localImageFilename` (server/lib/localImageFilename.js): remote/inline schemes
+ * and non-gallery absolute paths are rejected rather than rendered, and the
+ * value is reduced to its basename so a traversal-ish value can't escape the
+ * mount.
+ */
+export function startingImageSrc(startingImageFile) {
+ const raw = nonEmptyString(startingImageFile);
+ if (!raw) return null;
+ if (/^(https?:|data:|blob:)/i.test(raw)) return null;
+ const IMAGES_PREFIX = '/data/images/';
+ let name;
+ if (raw.startsWith(IMAGES_PREFIX)) name = raw.slice(IMAGES_PREFIX.length);
+ else if (raw.startsWith('/')) return null; // some other absolute path → not a gallery image
+ else name = raw;
+ const base = nonEmptyString(name.split('/').pop());
+ if (!base || base === '.' || base === '..') return null;
+ return `${IMAGES_PREFIX}${base}`;
+}
+
+/**
+ * Normalized preview descriptor for a project:
+ * `{ kind: 'video', jobId, src, poster, label }`
+ * `{ kind: 'image', src, jobId?, label }`
+ * `{ kind: 'none', label }`
+ */
+export function selectProjectPreview(project) {
+ const none = { kind: 'none', label: 'No render yet' };
+ if (!project || typeof project !== 'object') return none;
+
+ const video = (jobId, label) => ({
+ kind: 'video',
+ jobId,
+ src: videoSrcForJob(jobId),
+ poster: videoPosterForJob(jobId),
+ label,
+ });
+
+ const finalVideoId = nonEmptyString(project.finalVideoId);
+ if (finalVideoId) return video(finalVideoId, 'Final video');
+
+ const scene = lastRenderedScene(project);
+ if (scene) return video(scene.jobId, scene.label);
+
+ // A directive plan's video before completion promotes it to finalVideoId.
+ const planVideoId = lastDoneStepJobId(project.plan, VIDEO_RENDER_TOOL);
+ if (planVideoId) return video(planVideoId, 'Latest render');
+
+ const planImageId = lastDoneStepJobId(project.plan, IMAGE_RENDER_TOOL);
+ if (planImageId) {
+ return { kind: 'image', jobId: planImageId, src: imageSrcForJob(planImageId), label: 'Produced image' };
+ }
+
+ // Last resort: the project's own reference image. Distinct label — this is an
+ // INPUT the user supplied, not something the director produced.
+ const starting = startingImageSrc(project.startingImageFile);
+ if (starting) return { kind: 'image', src: starting, label: 'Starting image' };
+
+ return none;
+}
diff --git a/client/src/lib/creativeDirectorPreview.test.js b/client/src/lib/creativeDirectorPreview.test.js
new file mode 100644
index 0000000000..f04f6465a8
--- /dev/null
+++ b/client/src/lib/creativeDirectorPreview.test.js
@@ -0,0 +1,210 @@
+import { describe, it, expect } from 'vitest';
+import {
+ selectProjectPreview,
+ previewAspectClass,
+ startingImageSrc,
+ videoSrcForJob,
+ videoPosterForJob,
+ imageSrcForJob,
+} from './creativeDirectorPreview.js';
+
+// Obviously-fake ids/filenames throughout — never real records from an install.
+const scene = (order, renderedJobId = null) => ({ order, renderedJobId, status: 'accepted' });
+const step = (toolName, status, result) => ({ stepId: `s-${toolName}-${status}`, toolName, status, result });
+
+describe('previewAspectClass', () => {
+ it('maps each locked aspect ratio to a literal Tailwind class', () => {
+ expect(previewAspectClass('16:9')).toBe('aspect-video');
+ expect(previewAspectClass('9:16')).toBe('aspect-[9/16]');
+ expect(previewAspectClass('1:1')).toBe('aspect-square');
+ });
+
+ it('falls back to aspect-video for unset/legacy/unknown values', () => {
+ expect(previewAspectClass(undefined)).toBe('aspect-video');
+ expect(previewAspectClass(null)).toBe('aspect-video');
+ expect(previewAspectClass('21:9')).toBe('aspect-video');
+ });
+});
+
+describe('asset path builders', () => {
+ it('mirror the worker naming conventions', () => {
+ expect(videoSrcForJob('job-1')).toBe('/data/videos/job-1.mp4');
+ expect(videoPosterForJob('job-1')).toBe('/data/video-thumbnails/job-1.jpg');
+ expect(imageSrcForJob('job-1')).toBe('/data/images/job-1.png');
+ });
+});
+
+describe('startingImageSrc', () => {
+ it('accepts a bare gallery filename', () => {
+ expect(startingImageSrc('sample.png')).toBe('/data/images/sample.png');
+ });
+
+ it('accepts an already-mounted gallery path', () => {
+ expect(startingImageSrc('/data/images/sample.png')).toBe('/data/images/sample.png');
+ });
+
+ it('rejects remote and inline schemes', () => {
+ expect(startingImageSrc('https://example.com/x.png')).toBeNull();
+ expect(startingImageSrc('http://example.com/x.png')).toBeNull();
+ expect(startingImageSrc('data:image/png;base64,AAAA')).toBeNull();
+ expect(startingImageSrc('blob:abc')).toBeNull();
+ });
+
+ it('rejects a non-gallery absolute path', () => {
+ expect(startingImageSrc('/data/videos/x.mp4')).toBeNull();
+ expect(startingImageSrc('/etc/passwd')).toBeNull();
+ });
+
+ it('reduces a traversal-ish value to its basename', () => {
+ expect(startingImageSrc('../../secret.png')).toBe('/data/images/secret.png');
+ expect(startingImageSrc('/data/images/../../secret.png')).toBe('/data/images/secret.png');
+ });
+
+ it('returns null for empty/blank/non-string input', () => {
+ expect(startingImageSrc('')).toBeNull();
+ expect(startingImageSrc(' ')).toBeNull();
+ expect(startingImageSrc(null)).toBeNull();
+ expect(startingImageSrc(42)).toBeNull();
+ });
+});
+
+describe('selectProjectPreview', () => {
+ it('returns none for a non-object', () => {
+ expect(selectProjectPreview(null)).toEqual({ kind: 'none', label: 'No render yet' });
+ expect(selectProjectPreview(undefined).kind).toBe('none');
+ expect(selectProjectPreview('nope').kind).toBe('none');
+ });
+
+ it('returns none for a bare project with nothing produced', () => {
+ expect(selectProjectPreview({ id: 'cd-1', name: 'Example Project' }).kind).toBe('none');
+ });
+
+ it('prefers finalVideoId above everything else', () => {
+ const preview = selectProjectPreview({
+ finalVideoId: 'final-1',
+ treatment: { scenes: [scene(0, 'scene-1')] },
+ plan: { steps: [step('media_enqueueVideoJob', 'done', { jobId: 'plan-vid' })] },
+ startingImageFile: 'start.png',
+ });
+ expect(preview).toEqual({
+ kind: 'video',
+ jobId: 'final-1',
+ src: '/data/videos/final-1.mp4',
+ poster: '/data/video-thumbnails/final-1.jpg',
+ label: 'Final video',
+ });
+ });
+
+ it('falls back to the LAST rendered scene, labeled by its order', () => {
+ const preview = selectProjectPreview({
+ finalVideoId: null,
+ treatment: { scenes: [scene(0, 'scene-a'), scene(1, 'scene-b'), scene(2, null)] },
+ });
+ expect(preview.kind).toBe('video');
+ expect(preview.jobId).toBe('scene-b');
+ expect(preview.label).toBe('Scene 2'); // order 1 → "Scene 2"
+ });
+
+ it('labels a scene missing `order` by its array index', () => {
+ const preview = selectProjectPreview({
+ treatment: { scenes: [{ renderedJobId: 'scene-x' }] },
+ });
+ expect(preview.label).toBe('Scene 1');
+ });
+
+ it('ignores scenes with no render and tolerates a missing treatment', () => {
+ expect(selectProjectPreview({ treatment: { scenes: [scene(0), scene(1)] } }).kind).toBe('none');
+ expect(selectProjectPreview({ treatment: null }).kind).toBe('none');
+ expect(selectProjectPreview({ treatment: { scenes: 'bogus' } }).kind).toBe('none');
+ });
+
+ it('uses a directive plan\'s last done video step before completion promotes it', () => {
+ const preview = selectProjectPreview({
+ finalVideoId: null,
+ plan: {
+ steps: [
+ step('media_enqueueVideoJob', 'done', { jobId: 'plan-vid-1' }),
+ step('media_enqueueVideoJob', 'done', { jobId: 'plan-vid-2' }),
+ step('media_enqueueVideoJob', 'running', null),
+ ],
+ },
+ });
+ expect(preview.kind).toBe('video');
+ expect(preview.jobId).toBe('plan-vid-2'); // last-wins
+ expect(preview.label).toBe('Latest render');
+ });
+
+ it('skips plan steps that are not done or carry no jobId', () => {
+ expect(selectProjectPreview({
+ plan: {
+ steps: [
+ step('media_enqueueVideoJob', 'failed', { jobId: 'nope' }),
+ step('media_enqueueVideoJob', 'done', { error: 'boom' }),
+ step('media_enqueueVideoJob', 'running', { jobId: 'not-yet' }),
+ ],
+ },
+ }).kind).toBe('none');
+ });
+
+ it('falls back to a produced image for an image-emitting plan (e.g. a comic)', () => {
+ const preview = selectProjectPreview({
+ plan: {
+ steps: [
+ step('media_enqueueImageJob', 'done', { jobId: 'img-1' }),
+ step('media_enqueueImageJob', 'done', { jobId: 'img-2' }),
+ ],
+ },
+ });
+ expect(preview).toEqual({
+ kind: 'image',
+ jobId: 'img-2',
+ src: '/data/images/img-2.png',
+ label: 'Produced image',
+ });
+ });
+
+ it('prefers a plan video over a plan image', () => {
+ const preview = selectProjectPreview({
+ plan: {
+ steps: [
+ step('media_enqueueImageJob', 'done', { jobId: 'img-1' }),
+ step('media_enqueueVideoJob', 'done', { jobId: 'vid-1' }),
+ ],
+ },
+ });
+ expect(preview.kind).toBe('video');
+ expect(preview.jobId).toBe('vid-1');
+ });
+
+ it('prefers a rendered scene over a plan step', () => {
+ const preview = selectProjectPreview({
+ treatment: { scenes: [scene(0, 'scene-a')] },
+ plan: { steps: [step('media_enqueueVideoJob', 'done', { jobId: 'plan-vid' })] },
+ });
+ expect(preview.jobId).toBe('scene-a');
+ });
+
+ it('falls back to the starting image, labeled as an input not a render', () => {
+ const preview = selectProjectPreview({ startingImageFile: 'start.png' });
+ expect(preview).toEqual({ kind: 'image', src: '/data/images/start.png', label: 'Starting image' });
+ });
+
+ it('does not use an unservable starting image', () => {
+ expect(selectProjectPreview({ startingImageFile: 'https://example.com/x.png' }).kind).toBe('none');
+ });
+
+ it('never resolves a cast portrait — cast members carry no image ref', () => {
+ // Guards the documented gap: portraits live on the catalog ingredient, and
+ // resolving one would need a per-card fetch (out of scope for #2702).
+ const preview = selectProjectPreview({
+ cast: [{ ingredientId: 'ing-1', name: 'Example Character', type: 'character', role: 'lead' }],
+ });
+ expect(preview.kind).toBe('none');
+ });
+
+ it('tolerates a malformed plan', () => {
+ expect(selectProjectPreview({ plan: null }).kind).toBe('none');
+ expect(selectProjectPreview({ plan: { steps: 'bogus' } }).kind).toBe('none');
+ expect(selectProjectPreview({ plan: { steps: [null, undefined] } }).kind).toBe('none');
+ });
+});
diff --git a/client/src/lib/index.js b/client/src/lib/index.js
index 400ce4086a..86ced3fec2 100644
--- a/client/src/lib/index.js
+++ b/client/src/lib/index.js
@@ -23,6 +23,7 @@ export * from './beatGrid.js';
export * from './bibleLimits.js';
export * from './catalogTypes.js';
export * from './creativeDirectorPlan.js';
+export * from './creativeDirectorPreview.js';
export * from './editorialRoadmap.js';
export * from './imageCleaners.js';
export * from './imageGenBackends.js';
diff --git a/client/src/pages/CreativeDirector.jsx b/client/src/pages/CreativeDirector.jsx
index 8b12e85670..c6883dca8d 100644
--- a/client/src/pages/CreativeDirector.jsx
+++ b/client/src/pages/CreativeDirector.jsx
@@ -19,6 +19,7 @@ import PageHeader from '../components/PageHeader';
import Drawer from '../components/Drawer';
import DirectiveComposer from '../components/creative-director/DirectiveComposer.jsx';
import CreativeDirectorModelsDrawer from '../components/creative-director/CreativeDirectorModelsDrawer.jsx';
+import ProjectPreview from '../components/creative-director/ProjectPreview.jsx';
const ASPECT_RATIOS = ['16:9', '9:16', '1:1'];
const QUALITIES = ['draft', 'standard', 'high'];
@@ -423,6 +424,7 @@ export default function CreativeDirector() {
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3">
{projects.map((p) => (
<div key={p.id} className="bg-port-card border border-port-border rounded p-3 flex flex-col gap-2">
+ <ProjectPreview project={p} to={`/creative-director/${p.id}/overview`} />
<div className="flex items-start justify-between gap-2">
<Link to={`/creative-director/${p.id}/overview`} className="flex-1 min-w-0">
<div className="font-medium truncate">{p.name}</div>