AI media harness for planning, generating, and editing locally
TypeScript
Show render estimates
Bitti3e8bdc66b479
diff --git a/src/components/ProjectWorkspace.tsx b/src/components/ProjectWorkspace.tsxindex e53192e..fc9e3c5 100644--- a/src/components/ProjectWorkspace.tsx+++ b/src/components/ProjectWorkspace.tsx@@ -55,6 +55,7 @@ export function ProjectWorkspace({ project, initialView = "timeline", runtime =const [dirty, setDirty] = useState(false);const [saveError, setSaveError] = useState<string | null>(null);const [leaveGuard, setLeaveGuard] = useState(false);+ const [generationCompletionTimes, setGenerationCompletionTimes] = useState<Readonly<Record<string, number>>>({});/** Every save is ordered. Without this, an older manual save and a generation* completion save could race and whichever disk write happened to finish* last would win, even if it held the older project. */@@ -107,6 +108,16 @@ export function ProjectWorkspace({ project, initialView = "timeline", runtime =folderPath: project.folderPath,onChange: (update) => { applyConfig(update); dirtyRevision.current += 1; setDirty(true); },onCompleted: () => { void persist({ ...project, config: configRef.current }); },+ onEstimate: (jobId, completionAt) => setGenerationCompletionTimes((current) => {+ if (completionAt === null) {+ if (!(jobId in current)) return current;+ const next = { ...current };+ delete next[jobId];+ return next;+ }+ if (current[jobId] === completionAt) return current;+ return { ...current, [jobId]: completionAt };+ }),});/* Derived through a key of identity and status rather than from the job@@ -210,8 +221,8 @@ export function ProjectWorkspace({ project, initialView = "timeline", runtime =</header><div className={`project-content project-content--${view}`}>- {view === "timeline" && <TimelineView config={config} folderPath={project.folderPath} onChange={changeConfig} onMeasured={recordMeasurement} onOpenGenerator={(jobId) => { setSelectedGenerationJobId(jobId); setView("generator"); }} />}- {view === "generator" && <GeneratorView config={config} folderPath={project.folderPath} runtime={runtime?.vidfab ?? null} onChange={changeConfig} selectedJobId={selectedGenerationJobId} onOpenTimeline={() => setView("timeline")} />}+ {view === "timeline" && <TimelineView config={config} folderPath={project.folderPath} generationCompletionTimes={generationCompletionTimes} onChange={changeConfig} onMeasured={recordMeasurement} onOpenGenerator={(jobId) => { setSelectedGenerationJobId(jobId); setView("generator"); }} />}+ {view === "generator" && <GeneratorView config={config} folderPath={project.folderPath} generationCompletionTimes={generationCompletionTimes} runtime={runtime?.vidfab ?? null} onChange={changeConfig} selectedJobId={selectedGenerationJobId} onOpenTimeline={() => setView("timeline")} />}{view === "references" && <ReferencesView config={config} folderPath={project.folderPath} onChange={changeConfig} />}{view === "export" && <ExportView config={config} folderPath={project.folderPath} />}</div>diff --git a/src/components/workspace/GeneratorView.tsx b/src/components/workspace/GeneratorView.tsxindex b31bce9..fefec43 100644--- a/src/components/workspace/GeneratorView.tsx+++ b/src/components/workspace/GeneratorView.tsx@@ -10,6 +10,7 @@ interface GeneratorViewProps {config: ProjectConfig;folderPath: string;runtime?: VidfabStatus | null;+ generationCompletionTimes?: Readonly<Record<string, number>>;onChange: (next: ProjectConfig) => void;onOpenTimeline: () => void;selectedJobId?: string;@@ -30,7 +31,7 @@ type RemovalTarget =* The panel is whatever is open — one shot, or the scene itself. Nothing is* edited on the board, and nothing is duplicated in the panel: there is exactly* one place to change any given thing. */-export function GeneratorView({ config, folderPath, runtime = null, onChange, selectedJobId }: GeneratorViewProps) {+export function GeneratorView({ config, folderPath, runtime = null, generationCompletionTimes = {}, onChange, selectedJobId }: GeneratorViewProps) {const jobs = config.generationJobs;const configRef = useRef(config);configRef.current = config;@@ -429,6 +430,7 @@ export function GeneratorView({ config, folderPath, runtime = null, onChange, se{jobs.length > 0 && <SceneBoardjobs={jobs}folderPath={folderPath}+ generationCompletionTimes={generationCompletionTimes}references={config.references}selection={{ jobId: selected?.id ?? "", shotId: openShot?.id ?? null }}onSelect={setSelection}diff --git a/src/components/workspace/SceneBoard.tsx b/src/components/workspace/SceneBoard.tsxindex bb2eaf2..8fab18f 100644--- a/src/components/workspace/SceneBoard.tsx+++ b/src/components/workspace/SceneBoard.tsx@@ -46,6 +46,7 @@ const readShotDrag = (value: string): ShotDragData | null => {export function SceneBoard({jobs,folderPath,+ generationCompletionTimes,references,selection,onSelect,@@ -61,6 +62,7 @@ export function SceneBoard({}: {jobs: GenerationJob[];folderPath: string;+ generationCompletionTimes?: Readonly<Record<string, number>>;references: ProjectReference[];selection: GeneratorSelection;onSelect: (selection: GeneratorSelection) => void;@@ -200,6 +202,7 @@ export function SceneBoard({index={index}endsAt={index + 1 < shots.length ? shots[index + 1].startSeconds : duration}folderPath={folderPath}+ estimatedCompletionAt={generationCompletionTimes?.[job.id] ?? null}order={order}named={named}cancelling={cancellingJobIds.has(job.id) && cancellable}@@ -243,12 +246,13 @@ export function SceneBoard({</div>;}-function ShotCard({ job, shot, index, endsAt, folderPath, order, named, cancelling, open, draggable, onOpen, onDragStart }: {+function ShotCard({ job, shot, index, endsAt, folderPath, estimatedCompletionAt, order, named, cancelling, open, draggable, onOpen, onDragStart }: {job: GenerationJob;shot: SceneShot;index: number;endsAt: number;folderPath: string;+ estimatedCompletionAt: number | null;order: string[];named: Map<string, string>;cancelling: boolean;@@ -268,7 +272,7 @@ function ShotCard({ job, shot, index, endsAt, folderPath, order, named, cancellidraggable={draggable}onDragStart={onDragStart}>- <ShotThumbnail folderPath={folderPath} job={job} seconds={shot.startSeconds} endSeconds={endsAt} shotNumber={index + 1} cancelling={cancelling} />+ <ShotThumbnail folderPath={folderPath} job={job} seconds={shot.startSeconds} endSeconds={endsAt} shotNumber={index + 1} estimatedCompletionAt={estimatedCompletionAt} cancelling={cancelling} /><buttontype="button"className="shot-card__open-control"diff --git a/src/components/workspace/ShotThumbnail.test.tsx b/src/components/workspace/ShotThumbnail.test.tsxindex 18a7d97..79ee4d4 100644--- a/src/components/workspace/ShotThumbnail.test.tsx+++ b/src/components/workspace/ShotThumbnail.test.tsx@@ -178,6 +178,17 @@ describe("a shot's picture", () => {});});+ it("shows the render ETA on its own line beneath the percentage", () => {+ const fresh = createProjectConfig({ name: "Draft", prompt: "A quiet product film", aspectRatio: "16:9", resolution: "1080p", targetDurationSeconds: 30 });+ const job: GenerationJob = { ...fresh.generationJobs[0], status: "generating", stage: "generating", progress: 0.42 };+ render(<ShotThumbnail folderPath="C:\\Rendering" job={job} seconds={0} shotNumber={1} estimatedCompletionAt={Date.now() + 90_000} />);++ const rendering = screen.getByText("Rendering 42%");+ expect(rendering.tagName).toBe("EM");+ expect(rendering.nextElementSibling?.classList.contains("shot-thumb__eta")).toBe(true);+ expect(rendering.nextElementSibling?.textContent).toMatch(/^About 1m 30s left$/);+ });+it("says a finished scene could not be previewed rather than showing nothing", async () => {const folder = "C:\\Unreadable";const job = rendered(folder);diff --git a/src/components/workspace/ShotThumbnail.tsx b/src/components/workspace/ShotThumbnail.tsxindex f0d160c..596d7ec 100644--- a/src/components/workspace/ShotThumbnail.tsx+++ b/src/components/workspace/ShotThumbnail.tsx@@ -236,7 +236,17 @@ function placeholder(job: GenerationJob, failed: boolean, cancelling: boolean):}}-export function ShotThumbnail({ folderPath, job, seconds, endSeconds = sceneDurationSeconds(job), shotNumber, posterOffsetSeconds = 0, cancelling = false }: {+export function formatEstimatedTimeLeft(milliseconds: number): string {+ const totalSeconds = Math.max(1, Math.ceil(milliseconds / 1_000));+ if (totalSeconds < 60) return `About ${totalSeconds}s left`;+ const hours = Math.floor(totalSeconds / 3_600);+ const minutes = Math.floor((totalSeconds % 3_600) / 60);+ const seconds = totalSeconds % 60;+ if (hours > 0) return `About ${hours}h ${minutes}m left`;+ return `About ${minutes}m ${seconds}s left`;+}++export function ShotThumbnail({ folderPath, job, seconds, endSeconds = sceneDurationSeconds(job), shotNumber, estimatedCompletionAt = null, cancelling = false }: {folderPath: string;/** The scene this shot belongs to: it owns the file and the status. */job: GenerationJob;@@ -245,13 +255,13 @@ export function ShotThumbnail({ folderPath, job, seconds, endSeconds = sceneDura/** The next cut (or scene end). Playback never crosses this point. */endSeconds?: number;shotNumber: number;- /** Optional caller-selected offset from the exact cut. */- posterOffsetSeconds?: number;+ /** Live rendering estimate derived from observed progress; never persisted. */+ estimatedCompletionAt?: number | null;/** Cancel was requested but the engine has not reported its terminal state. */cancelling?: boolean;}) {const relativePath = job.status === "completed" ? job.outputRelativePath : null;- const at = seconds + posterOffsetSeconds;+ const at = seconds;const playbackId = `${job.id}@${seconds}`;const [result, setResult] = useState<PosterResult>(() =>relativePath ? { poster: POSTERS.get(posterKey(fileKey(folderPath, relativePath), at)) ?? null, failed: false } : NOTHING);@@ -259,6 +269,7 @@ export function ShotThumbnail({ folderPath, job, seconds, endSeconds = sceneDuraconst [loadingPlayback, setLoadingPlayback] = useState(false);const [playing, setPlaying] = useState(false);const [playFailed, setPlayFailed] = useState(false);+ const [estimateNow, setEstimateNow] = useState(() => Date.now());const videoRef = useRef<HTMLVideoElement>(null);const requestRef = useRef(0);const cutTimerRef = useRef<number | null>(null);@@ -316,6 +327,13 @@ export function ShotThumbnail({ folderPath, job, seconds, endSeconds = sceneDuraif (playbackUrl) URL.revokeObjectURL(playbackUrl);}, [playbackUrl]);+ useEffect(() => {+ if (job.status !== "generating" || estimatedCompletionAt === null || cancelling) return;+ setEstimateNow(Date.now());+ const timer = window.setInterval(() => setEstimateNow(Date.now()), 1_000);+ return () => window.clearInterval(timer);+ }, [job.status, estimatedCompletionAt, cancelling]);+const stopAtCut = () => {const video = videoRef.current;if (!video || video.currentTime + 0.02 < endSeconds) return;@@ -386,9 +404,15 @@ export function ShotThumbnail({ folderPath, job, seconds, endSeconds = sceneDura</button>;}const { icon, word } = placeholder(job, result.failed, cancelling);- return <span className={`shot-thumb shot-thumb--${job.status}`} role="img" aria-label={`Shot ${shotNumber} — ${word}`}>+ const estimateLine = job.status === "generating" && !cancelling+ ? estimatedCompletionAt === null+ ? "Estimating time left…"+ : formatEstimatedTimeLeft(estimatedCompletionAt - estimateNow)+ : null;+ return <span className={`shot-thumb shot-thumb--${job.status}`} role="img" aria-label={`Shot ${shotNumber} — ${word}${estimateLine ? `. ${estimateLine}` : ""}`}>{icon}<em>{word}</em>+ {estimateLine && <small className="shot-thumb__eta">{estimateLine}</small>}{job.status === "generating" && <span className="shot-thumb__progress" aria-hidden="true"><i style={{ width: `${Math.max(0, Math.min(100, job.progress * 100))}%` }} /></span>}diff --git a/src/components/workspace/TimelineView.tsx b/src/components/workspace/TimelineView.tsxindex ecc1a78..3c0e6fe 100644--- a/src/components/workspace/TimelineView.tsx+++ b/src/components/workspace/TimelineView.tsx@@ -131,9 +131,10 @@ const parseDuration = (value: string, frameRate: number): number | null => {* previous one having already come back down as a prop. */export type ConfigUpdate = ProjectConfig | ((current: ProjectConfig) => ProjectConfig);-export function TimelineView({ config, folderPath, onChange, onMeasured, onOpenGenerator }: {+export function TimelineView({ config, folderPath, generationCompletionTimes = {}, onChange, onMeasured, onOpenGenerator }: {config: ProjectConfig;folderPath: string;+ generationCompletionTimes?: Readonly<Record<string, number>>;onChange: (next: ConfigUpdate) => void;/** What a decode learned about a file the project already had — a length, a* size. Worth keeping, but the user did not edit anything by looking at the@@ -743,7 +744,7 @@ export function TimelineView({ config, folderPath, onChange, onMeasured, onOpenGtitle={`${job.title} — drag onto a video track below`}><span className="scene-card__thumb">- <ShotThumbnail folderPath={folderPath} job={job} seconds={0} shotNumber={1} posterOffsetSeconds={0} />+ <ShotThumbnail folderPath={folderPath} job={job} seconds={0} shotNumber={1} estimatedCompletionAt={generationCompletionTimes[job.id] ?? null} /><i>{String(index + 1).padStart(2, "0")}</i><em>{sceneDurationSeconds(job).toFixed(1)}s</em></span><span><b>{job.title}</b><small>{STATUS_WORD[job.status]}{placements > 0 ? ` · ${placements} on timeline` : ""}</small><small>{sceneShape(job)}</small></span>diff --git a/src/components/workspace/useGenerationEvents.test.tsx b/src/components/workspace/useGenerationEvents.test.tsxindex 2170834..b9fe636 100644--- a/src/components/workspace/useGenerationEvents.test.tsx+++ b/src/components/workspace/useGenerationEvents.test.tsx@@ -33,11 +33,11 @@ afterEach(() => {/** A project with one draft scene, and a harness that keeps whatever the hook* writes — the same shape the workspace holds it in. */-function harness(onCompleted?: (jobId: string) => void) {+function harness(onCompleted?: (jobId: string) => void, onEstimate?: (jobId: string, completionAt: number | null) => void) {const fresh = createProjectConfig({ name: "Ceramic lamp", prompt: "A quiet product film", aspectRatio: "16:9", resolution: "1080p", targetDurationSeconds: 30 });const state = { config: fresh };function Harness() {- useGenerationEvents({ folderPath: "C:\\Ceramic Lamp", onChange: (update) => { state.config = update(state.config); }, onCompleted });+ useGenerationEvents({ folderPath: "C:\\Ceramic Lamp", onChange: (update) => { state.config = update(state.config); }, onCompleted, onEstimate });return null;}render(<Harness />);@@ -154,6 +154,26 @@ describe("what the app does with the engine's events", () => {expect(job().progress).toBeGreaterThan(0.7);});+ it("estimates render completion from observed progress and clears it when rendering ends", async () => {+ const onEstimate = vi.fn();+ const now = vi.spyOn(Date, "now").mockReturnValue(1_000);+ const { jobId } = harness(undefined, onEstimate);++ await emit("vidfab-progress", { jobId, stage: "denoising", step: 10, totalSteps: 100 });+ expect(onEstimate).toHaveBeenLastCalledWith(jobId, null);++ now.mockReturnValue(11_000);+ await emit("vidfab-progress", { jobId, stage: "denoising", step: 20, totalSteps: 100 });+ const completionAt = onEstimate.mock.lastCall?.[1];+ expect(completionAt).toBeTypeOf("number");+ expect(completionAt).toBeGreaterThan(11_000);++ vi.mocked(saveGeneratedScene).mockResolvedValue({ relativePath: "media/generated/job-01.mp4", bytes: 1, note: null });+ await emit("vidfab-job", { jobId, state: "framesReady", detail: "" });+ expect(onEstimate).toHaveBeenLastCalledWith(jobId, null);+ now.mockRestore();+ });+it("passes queued, failed and cancelled through as themselves", async () => {const { jobId, job } = harness();await emit("vidfab-job", { jobId, state: "queued", detail: "Queued behind any active vidfab generation." });diff --git a/src/components/workspace/useGenerationEvents.ts b/src/components/workspace/useGenerationEvents.tsindex 2aabbfd..3bd23c9 100644--- a/src/components/workspace/useGenerationEvents.ts+++ b/src/components/workspace/useGenerationEvents.ts@@ -38,8 +38,17 @@ interface ProgressEvent {* looking stalled while the encoder works. */const RENDER_CEILING = 0.9;const ENCODE_FLOOR = 0.9;+const RENDER_PROGRESS_END = RENDER_CEILING - 0.02;+const MAX_ESTIMATE_MS = 24 * 60 * 60 * 1_000;-export function useGenerationEvents({ folderPath, onChange, onCompleted }: {+interface ProgressTiming {+ at: number;+ progress: number;+ /** Overall render progress gained per millisecond. */+ rate: number | null;+}++export function useGenerationEvents({ folderPath, onChange, onCompleted, onEstimate }: {folderPath: string;/** The updater form, always: every write here happens after an await, so the* config this component last saw is not the one to build from. */@@ -49,6 +58,10 @@ export function useGenerationEvents({ folderPath, onChange, onCompleted }: {* exact boundary to persist the finished generation without waiting for the* user to click Save. */onCompleted?: (jobId: string) => void;+ /** A transient prediction of when rendering (not file encoding) will finish.+ * It is deliberately kept out of ProjectConfig: an estimate is live UI+ * telemetry, not project data worth saving. */+ onEstimate?: (jobId: string, completionAt: number | null) => void;}) {/* Held in refs so the subscription is made ONCE. It has to be: re-subscribingon every progress tick would drop events in the gap, and these events are@@ -57,11 +70,14 @@ export function useGenerationEvents({ folderPath, onChange, onCompleted }: {write.current = onChange;const completed = useRef(onCompleted);completed.current = onCompleted;+ const estimate = useRef(onEstimate);+ estimate.current = onEstimate;const folder = useRef(folderPath);folder.current = folderPath;/** Scenes already being encoded, so a repeated event — or a remount in* StrictMode — cannot start a second encode of the same frames. */const saving = useRef(new Set<string>());+ const progressTimings = useRef(new Map<string, ProgressTiming>());useEffect(() => {if (!isTauri()) return;@@ -89,6 +105,37 @@ export function useGenerationEvents({ folderPath, onChange, onCompleted }: {}),}));};+ const clearEstimate = (jobId: string) => {+ progressTimings.current.delete(jobId);+ estimate.current?.(jobId, null);+ };+ const updateEstimate = (jobId: string, progress: number) => {+ const now = Date.now();+ const previous = progressTimings.current.get(jobId);+ if (!previous) {+ progressTimings.current.set(jobId, { at: now, progress, rate: null });+ // Also clears an estimate left by an earlier run of the same scene.+ estimate.current?.(jobId, null);+ return;+ }++ const nextProgress = Math.max(previous.progress, progress);+ const elapsed = now - previous.at;+ if (nextProgress <= previous.progress || elapsed < 250) return;++ const measuredRate = (nextProgress - previous.progress) / elapsed;+ const rate = previous.rate === null+ ? measuredRate+ : previous.rate * 0.65 + measuredRate * 0.35;+ progressTimings.current.set(jobId, { at: now, progress: nextProgress, rate });++ const remainingMs = (RENDER_PROGRESS_END - nextProgress) / rate;+ if (!Number.isFinite(remainingMs) || remainingMs <= 0 || remainingMs > MAX_ESTIMATE_MS) {+ estimate.current?.(jobId, null);+ return;+ }+ estimate.current?.(jobId, now + remainingMs);+ };/** Encode the frames the engine just finished, and write the file.*@@ -158,8 +205,9 @@ export function useGenerationEvents({ folderPath, onChange, onCompleted }: {listen<ProgressEvent>("vidfab-progress", ({ payload }) => {if (disposed) return;const progress = payload.totalSteps > 0- ? Math.min(RENDER_CEILING - 0.02, 0.12 + (Math.max(0, payload.step) / payload.totalSteps) * (RENDER_CEILING - 0.14))- : payload.stage === "delivering" ? RENDER_CEILING - 0.02 : 0.08;+ ? Math.min(RENDER_PROGRESS_END, 0.12 + (Math.max(0, payload.step) / payload.totalSteps) * (RENDER_CEILING - 0.14))+ : payload.stage === "delivering" ? RENDER_PROGRESS_END : 0.08;+ updateEstimate(payload.jobId, progress);updateProgress(payload.jobId,progress,@@ -169,9 +217,11 @@ export function useGenerationEvents({ folderPath, onChange, onCompleted }: {listen<JobEvent>("vidfab-job", ({ payload }) => {if (disposed) return;if (payload.state === "framesReady") {+ clearEstimate(payload.jobId);void save(payload.jobId);return;}+ clearEstimate(payload.jobId);updateJob(payload.jobId, payload.state === "failed"? { status: "failed", stage: "failed", error: payload.detail }: payload.state === "cancelled"diff --git a/src/styles/generator.css b/src/styles/generator.cssindex 28f73f4..a5ea905 100644--- a/src/styles/generator.css+++ b/src/styles/generator.css@@ -701,6 +701,14 @@text-align: center;}+.shot-thumb__eta {+ padding: 0 var(--space-2);+ color: var(--text-muted);+ font-size: var(--text-2xs);+ line-height: var(--leading-tight);+ text-align: center;+}+.shot-thumb--generating,.shot-thumb--ready {color: var(--accent-bright);