AI media harness for planning, generating, and editing locally
TypeScript
Allow removing video generation history takes
Bitti10fc2fcac161
diff --git a/src/components/workspace/GeneratorView.test.tsx b/src/components/workspace/GeneratorView.test.tsxindex afa0c7b..0b6ffaf 100644--- a/src/components/workspace/GeneratorView.test.tsx+++ b/src/components/workspace/GeneratorView.test.tsx@@ -1253,7 +1253,7 @@ it("shows template shifts and locks active LoRA overrides without replacing save});-it("restores older takes and drafts, makes a take primary, and duplicates a scene", () => {+it("restores older takes and drafts, makes a take primary, removes history and duplicates a scene", () => {let config = project();const id = config.generationJobs[0].id;const saveTake = (takeId: string) => {@@ -1278,6 +1278,15 @@ it("restores older takes and drafts, makes a take primary, and duplicates a scenconst copy = state.latest().generationJobs[1];expect(copy).toMatchObject({ title: "First scene copy", music: "Draft music", steps: 8, status: "draft" });expect(copy.generationHistory).toBeUndefined(); expect(copy.outputRelativePath).toBeFalsy();+ fireEvent.contextMenu(screen.getByRole("button", { name: "Generation 1 (Primary) of First scene" }));+ fireEvent.click(screen.getByRole("menuitem", { name: "Remove generation" }));+ expect(state.latest().generationJobs[0]).toMatchObject({ music: "Draft music", outputRelativePath: "media/two.mp4", generationHistory: { primaryId: "two", selectedId: null } });+ expect(state.latest().generationJobs[0].generationHistory!.versions.map(version => version.id)).toEqual(["two"]);+ fireEvent.keyDown(screen.getByRole("button", { name: "Generation 1 (Primary) of First scene" }), { key: "ContextMenu" });+ fireEvent.click(screen.getByRole("menuitem", { name: "Remove generation" }));+ expect(state.latest().generationJobs[0]).toMatchObject({ status: "draft", outputRelativePath: null, music: "Draft music" });+ expect(screen.queryByRole("button", { name: /Generation .* of First scene/ })).not.toBeInTheDocument();+ expect(screen.getByRole("button", { name: "Draft of First scene" })).toBeInTheDocument();});diff --git a/src/components/workspace/GeneratorView.tsx b/src/components/workspace/GeneratorView.tsxindex 77c1525..2f8a9a4 100644--- a/src/components/workspace/GeneratorView.tsx+++ b/src/components/workspace/GeneratorView.tsx@@ -1,5 +1,5 @@import { generatorOptions } from "../generatorOptions";-import { duplicateScene, makeSceneGenerationPrimary, saveSceneDrafts, selectSceneGeneration } from "../../lib/sceneHistory";+import { duplicateScene, makeSceneGenerationPrimary, removeSceneGeneration, saveSceneDrafts, selectSceneGeneration } from "../../lib/sceneHistory";import { sceneGenerationRequest, sendBlocker, templateSceneBlocker } from "../../lib/sceneGeneration";import { longShotBlocker, longShotDependencies, longShotPosition } from "../../lib/longShot";export { templateSceneBlocker } from "../../lib/sceneGeneration";@@ -566,6 +566,10 @@ export function GeneratorView({ config, folderPath, runtime = null, generationCoonChange(makeSceneGenerationPrimary(configRef.current, job.id, versionId));void purgeSceneThumbnails(job);}}+ onRemoveGeneration={(job, versionId) => {+ onChange(removeSceneGeneration(configRef.current, job.id, versionId));+ void purgeSceneThumbnails(job);+ }}onDuplicate={(job) => {const duplicated = duplicateScene(configRef.current, job.id);if (duplicated) { onChange(duplicated.config); setSelection({ jobId: duplicated.id, shotId: null }); }diff --git a/src/components/workspace/SceneBoard.tsx b/src/components/workspace/SceneBoard.tsxindex 51c250a..4a8632b 100644--- a/src/components/workspace/SceneBoard.tsx+++ b/src/components/workspace/SceneBoard.tsx@@ -84,7 +84,7 @@ export function SceneBoard({onMoveShot,onRename,onRemoveScene,- onRemoveShot, onHistorySelect, onMakePrimary, onDuplicate,+ onRemoveShot, onHistorySelect, onMakePrimary, onRemoveGeneration, onDuplicate,}: {jobs: GenerationJob[];assets?: ProjectAsset[];@@ -108,6 +108,7 @@ export function SceneBoard({onRemoveShot?: (job: GenerationJob, shotId: string) => void;onHistorySelect?: (job: GenerationJob, id: string | null) => void;onMakePrimary?: (job: GenerationJob, id: string) => void;+ onRemoveGeneration?: (job: GenerationJob, id: string) => void;onDuplicate?: (job: GenerationJob) => void;}) {const [collapsed, setCollapsed] = useState<ReadonlySet<string>>(new Set());@@ -467,7 +468,7 @@ export function SceneBoard({</li>;})}</ol>- <SceneHistoryBar job={job} assets={assets} folderPath={folderPath} onSelect={onHistorySelect} onMakePrimary={onMakePrimary} />+ <SceneHistoryBar job={job} assets={assets} folderPath={folderPath} onSelect={onHistorySelect} onMakePrimary={onMakePrimary} onRemove={onRemoveGeneration} /></div>}</section>;})}diff --git a/src/components/workspace/SceneHistoryBar.tsx b/src/components/workspace/SceneHistoryBar.tsxindex 174175a..d56449d 100644--- a/src/components/workspace/SceneHistoryBar.tsx+++ b/src/components/workspace/SceneHistoryBar.tsx@@ -1,5 +1,5 @@import { useEffect, useState } from "react";-import { Film16, Edit16 } from "../ui/icons";+import { Film16, Edit16, Delete16 } from "../ui/icons";import { useContextMenu } from "../ui";import { sceneHistory } from "../../lib/sceneHistory";import { sceneMediaStartSeconds } from "../../lib/continuationMedia";@@ -16,10 +16,11 @@ function TakePoster({ folderPath, media }: { folderPath: string; media: ProjectAreturn url ? <img src={url} alt="" draggable={false} /> : <Film16 aria-hidden="true" />;}-export function SceneHistoryBar({ job, assets, folderPath, onSelect, onMakePrimary }: {+export function SceneHistoryBar({ job, assets, folderPath, onSelect, onMakePrimary, onRemove }: {job: GenerationJob; assets: ProjectAsset[]; folderPath: string;onSelect?: (job: GenerationJob, id: string | null) => void;onMakePrimary?: (job: GenerationJob, id: string) => void;+ onRemove?: (job: GenerationJob, id: string) => void;}) {const history = sceneHistory(job, assets);const busy = ["queued", "generating", "ready"].includes(job.status);@@ -28,7 +29,9 @@ export function SceneHistoryBar({ job, assets, folderPath, onSelect, onMakePrima{history.versions.map((version, index) => {const primary = version.id === history.primaryId;const open = (source: Parameters<typeof menu.open>[0]) => menu.open(source, [{ id: "primary", label: "Make Primary", disabled: busy || primary || !onMakePrimary,- onSelect: () => onMakePrimary?.(job, version.id) }], { "aria-label": `Generation ${index + 1} actions` });+ onSelect: () => onMakePrimary?.(job, version.id) }, { separator: true },+ { id: "remove", label: "Remove generation", icon: <Delete16 />, danger: true, disabled: busy || !onRemove,+ onSelect: () => onRemove?.(job, version.id) }], { "aria-label": `Generation ${index + 1} actions` });return <button key={version.id} type="button" className="scene-history__take" disabled={busy || !onSelect}aria-label={`Generation ${index + 1}${primary ? " (Primary)" : ""} of ${job.title}`} aria-pressed={history.selectedId === version.id}data-tooltip={`Generation ${index + 1}${primary ? " - Primary" : ""} - ${new Date(version.createdAt).toLocaleString()}`}diff --git a/src/lib/sceneHistory.test.ts b/src/lib/sceneHistory.test.tsindex 05f5570..9c848bd 100644--- a/src/lib/sceneHistory.test.ts+++ b/src/lib/sceneHistory.test.ts@@ -1,6 +1,6 @@import { describe, expect, it, vi } from "vitest";import { createProjectConfig, generationAssetId, parseProjectConfig, type ProjectConfig, type SceneGenerationVersion } from "./project";-import { completeSceneGeneration, duplicateScene, makeSceneGenerationPrimary, saveSceneDrafts, sceneInput, selectSceneGeneration, SCENE_GENERATION_HISTORY_LIMIT } from "./sceneHistory";+import { completeSceneGeneration, duplicateScene, makeSceneGenerationPrimary, removeSceneGeneration, saveSceneDrafts, sceneInput, selectSceneGeneration, SCENE_GENERATION_HISTORY_LIMIT } from "./sceneHistory";import { ProjectSession } from "./projectSession";const initial = () => createProjectConfig({ name: "History", prompt: "A quiet scene", aspectRatio: "16:9", resolution: "416p", targetDurationSeconds: 5 });@@ -14,6 +14,55 @@ const edit = (config: ProjectConfig, music: string) => saveSceneDrafts({ ...confshots: j.shots!.map(shot => ({ ...shot, action: music, speech: `${music} speech` })) })) }, config);describe("scene generation history", () => {+ it("removes an unselected take without changing the primary or current draft", () => {+ let config = finish(edit(initial(), "First"), "one");+ config = edit(finish(edit(config, "Second"), "two"), "Pending");+ const id = config.generationJobs[0].id;+ const removed = removeSceneGeneration(config, id, "one");+ expect(removed.generationJobs[0]).toMatchObject({ music: "Pending", outputRelativePath: "media/two.mp4",+ generationHistory: { primaryId: "two", selectedId: null, draft: { music: "Pending" } } });+ expect(removed.generationJobs[0].generationHistory!.versions.map(v => v.id)).toEqual(["two"]);+ expect(removed.assets).toEqual(config.assets);+ expect(removeSceneGeneration(removed, id, "one")).toBe(removed);+ for (const status of ["queued", "generating", "ready"] as const) {+ const busy = { ...config, generationJobs: config.generationJobs.map(job => ({ ...job, status })) };+ expect(removeSceneGeneration(busy, id, "one")).toBe(busy);+ }+ });+ it("promotes the newest remaining take when removing the primary and restores selected inputs", () => {+ let config = finish(edit(initial(), "First"), "one");+ config = finish(edit(config, "Second"), "two");+ const id = config.generationJobs[0].id;+ const removed = parseProjectConfig(removeSceneGeneration(config, id, "two"));+ expect(removed.generationJobs[0]).toMatchObject({ music: "First", steps: 4, seed: 10, outputRelativePath: "media/one.mp4",+ latentRelativePath: "latents/one.safetensors", generationSnapshot: "one", generationHistory: { primaryId: "one", selectedId: "one" } });+ expect(removed.assets.find(a => a.id === generationAssetId(id))?.relativePath).toBe("media/one.mp4");+ const selectedOlder = selectSceneGeneration(config, id, "one");+ expect(removeSceneGeneration(selectedOlder, id, "one").generationJobs[0]).toMatchObject({ music: "Second", generationHistory: { primaryId: "two", selectedId: "two" } });+ });+ it("returns the last take to a draft with timeline placeholders and supports undo and redo", () => {+ const config = edit(finish(edit(initial(), "First"), "one"), "Pending");+ const id = config.generationJobs[0].id, assetId = generationAssetId(id), track = config.timeline.tracks[0];+ track.clips = [{ id: "clip", assetId, trackId: track.id, label: "Scene", startMs: 0, sourceStartMs: 0, durationMs: 5000, status: "generated" }];+ const session = new ProjectSession({ folderPath: "C:/history", config }, vi.fn(async () => {}));+ session.edit(current => removeSceneGeneration(current, id, "one"));+ const removed = parseProjectConfig(session.getSnapshot().config);+ expect(removed.generationJobs[0]).toMatchObject({ status: "draft", stage: "queued", music: "Pending", outputRelativePath: null, latentRelativePath: null,+ generationSnapshot: null, generationHistory: { versions: [], selectedId: null, primaryId: null, draft: { music: "Pending" } } });+ expect(removed.assets.find(a => a.id === assetId)?.relativePath).toBeNull();+ expect(removed.timeline.tracks[0].clips[0]).toMatchObject({ id: "clip", assetId, status: "draft" });+ expect(session.undo()).toBe(true);+ expect(session.getSnapshot().config.generationJobs[0].outputRelativePath).toBe("media/one.mp4");+ expect(session.redo()).toBe(true);+ expect(session.getSnapshot().config.generationJobs[0].generationHistory!.versions).toHaveLength(0);+ });+ it("can remove a legacy generation without re-adopting the old output", () => {+ const config = initial(); config.generationJobs[0].outputRelativePath = "media/legacy.mp4"; config.generationJobs[0].status = "completed";+ const id = config.generationJobs[0].id;+ const removed = saveSceneDrafts(removeSceneGeneration(config, id, `legacy-${id}`), config);+ expect(removed.generationJobs[0].generationHistory!.versions).toHaveLength(0);+ expect(removed.generationJobs[0].outputRelativePath).toBeNull();+ });it("restores complete scene inputs while retaining a separate primary output and editable draft", () => {let config = finish(edit(initial(), "First"), "one");config = finish(edit(config, "Second"), "two");diff --git a/src/lib/sceneHistory.ts b/src/lib/sceneHistory.tsindex 1cd76ce..d2829da 100644--- a/src/lib/sceneHistory.ts+++ b/src/lib/sceneHistory.ts@@ -91,6 +91,37 @@ export function makeSceneGenerationPrimary(config: ProjectConfig, sceneId: strin};}+/** Remove history metadata, keeping media files available to Undo and references. */+export function removeSceneGeneration(config: ProjectConfig, sceneId: string, versionId: string): ProjectConfig {+ const current = config.generationJobs.find(job => job.id === sceneId);+ if (!current || ["queued", "generating", "ready"].includes(current.status)+ || !sceneHistory(current, config.assets).versions.some(version => version.id === versionId)) return config;+ const saved = saveSceneDrafts(config);+ const job = saved.generationJobs.find(job => job.id === sceneId)!;+ const history = sceneHistory(job, saved.assets);+ const versions = history.versions.filter(version => version.id !== versionId);+ const primaryId = history.primaryId === versionId ? versions.at(-1)?.id ?? null : history.primaryId;+ const selectedId = history.selectedId === versionId ? primaryId : history.selectedId;+ const draft = versions.length ? history.draft : history.draft ?? sceneInput(job);+ const input = versions.length ? versions.find(version => version.id === selectedId)?.scene ?? draft : draft;+ const nextJob = { ...(input ? applyInput(job, input) : job), generationHistory: { ...history, versions, primaryId, selectedId, draft } };+ const next = { ...saved, generationJobs: saved.generationJobs.map(item => item.id === sceneId ? nextJob : item) };+ if (versions.length) return history.primaryId === versionId && primaryId ? makeSceneGenerationPrimary(next, sceneId, primaryId) : next;++ // Keep timeline placements as draft placeholders so a new generation can+ // fill them again, without retaining a preview of the removed last take.+ const assetIds = new Set(saved.assets.filter(asset => asset.id === generationAssetId(sceneId)+ || asset.kind === "generated" && job.outputRelativePath && asset.relativePath === job.outputRelativePath).map(asset => asset.id));+ return { ...next,+ generationJobs: next.generationJobs.map(item => item.id !== sceneId ? item : { ...item, status: "draft", stage: "queued", progress: 0,+ outputRelativePath: null, latentRelativePath: null, generationSnapshot: null, error: null }),+ assets: next.assets.map(asset => assetIds.has(asset.id) ? { ...asset, relativePath: null, sourcePath: null, sceneSegments: undefined, hasAudio: false,+ durationMs: Math.round((nextJob.durationSeconds ?? 5) * 1000) } : asset),+ timeline: { ...next.timeline, tracks: next.timeline.tracks.map(track => ({ ...track,+ clips: track.clips.map(clip => assetIds.has(clip.assetId) ? { ...clip, status: "draft" } : clip) })) },+ };+}+/** Replay-safe background result: keep live edits and never duplicate a take* when an undo replays this callback. Completed takes become primary. */export function completeSceneGeneration(config: ProjectConfig, sceneId: string, version: SceneGenerationVersion, note?: string | null): ProjectConfig {