Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Allow removing scene drafts

Bitti4f8513979209
diff --git a/src/components/workspace/GeneratorView.test.tsx b/src/components/workspace/GeneratorView.test.tsx
index a33b3de..408c272 100644
--- a/src/components/workspace/GeneratorView.test.tsx
+++ b/src/components/workspace/GeneratorView.test.tsx
@@ -1375,6 +1375,30 @@ it("shows template shifts and locks active LoRA overrides without replacing save
});
+it.each(["mouse", "keyboard"])("removes the Draft through its %s context menu and restores the primary Take", method => {
+ let config = project();
+ const job = config.generationJobs[0];
+ config = completeSceneGeneration(config, job.id, { id: "one", scene: sceneInput(job), createdAt: config.createdAt,
+ media: { id: `asset-${job.id}`, kind: "generated", name: job.title, mimeType: "video/mp4", relativePath: "media/one.mp4", createdAt: config.createdAt } });
+ const state = setup(config);
+ fireEvent.change(screen.getByLabelText("The music of this scene"), { target: { value: "Discard this draft" } });
+ const draft = screen.getByRole("button", { name: "Draft of First scene" });
+ if (method === "mouse") fireEvent.contextMenu(draft);
+ else fireEvent.keyDown(draft, { key: "F10", shiftKey: true });
+ fireEvent.click(screen.getByRole("menuitem", { name: "Remove draft" }));
+ expect(screen.queryByRole("button", { name: "Draft of First scene" })).toBeNull();
+ expect(state.latest().generationJobs[0].music).toBe(job.music);
+ expect(state.latest().generationJobs[0]).toMatchObject({ outputRelativePath: "media/one.mp4",
+ generationHistory: { selectedId: "one", primaryId: "one", draft: null } });
+ expect(screen.getByRole("button", { name: "Generation 1 (Primary) of First scene" })).toHaveAttribute("aria-pressed", "true");
+});
+
+it("disables removing the scene's only Draft", () => {
+ setup();
+ fireEvent.contextMenu(screen.getByRole("button", { name: "Draft of First scene" }));
+ expect(screen.getByRole("menuitem", { name: "Remove draft" })).toBeDisabled();
+});
+
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;
diff --git a/src/components/workspace/GeneratorView.tsx b/src/components/workspace/GeneratorView.tsx
index 3c7191b..4ac12e4 100644
--- a/src/components/workspace/GeneratorView.tsx
+++ b/src/components/workspace/GeneratorView.tsx
@@ -2,7 +2,7 @@ import { generatorOptions } from "../generatorOptions";
import { sceneUpscaleSubmission, selectedUpscaleTake } from "../../lib/sceneUpscale";
import { Flyout } from "../ui";
import { ChevronDown14 } from "../ui/icons";
-import { duplicateScene, makeSceneGenerationPrimary, removeSceneGeneration, saveSceneDrafts, selectSceneGeneration } from "../../lib/sceneHistory";
+import { duplicateScene, makeSceneGenerationPrimary, removeSceneDraft, 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";
@@ -589,6 +589,10 @@ export function GeneratorView({ config, sceneIds, toolbarStart, folderPath, runt
onChange(removeSceneGeneration(configRef.current, job.id, versionId));
void purgeSceneThumbnails(job);
}}
+ onRemoveDraft={(job) => {
+ onChange(removeSceneDraft(configRef.current, job.id));
+ setSelection({ jobId: job.id, shotId: null });
+ }}
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.tsx
index e0c203b..f93ead9 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, onRemoveGeneration, onDuplicate,
+ onRemoveShot, onHistorySelect, onMakePrimary, onRemoveGeneration, onRemoveDraft, onDuplicate,
}: {
jobs: GenerationJob[];
assets?: ProjectAsset[];
@@ -109,6 +109,7 @@ export function SceneBoard({
onHistorySelect?: (job: GenerationJob, id: string | null) => void;
onMakePrimary?: (job: GenerationJob, id: string) => void;
onRemoveGeneration?: (job: GenerationJob, id: string) => void;
+ onRemoveDraft?: (job: GenerationJob) => void;
onDuplicate?: (job: GenerationJob) => void;
}) {
const [collapsed, setCollapsed] = useState<ReadonlySet<string>>(new Set());
@@ -468,7 +469,7 @@ export function SceneBoard({
</li>;
})}
</ol>
- <SceneHistoryBar job={job} assets={assets} folderPath={folderPath} onSelect={onHistorySelect} onMakePrimary={onMakePrimary} onRemove={onRemoveGeneration} />
+ <SceneHistoryBar job={job} assets={assets} folderPath={folderPath} onSelect={onHistorySelect} onMakePrimary={onMakePrimary} onRemove={onRemoveGeneration} onRemoveDraft={onRemoveDraft} />
</div>}
</section>;
})}
diff --git a/src/components/workspace/SceneHistoryBar.tsx b/src/components/workspace/SceneHistoryBar.tsx
index e3dcd6f..c163cf0 100644
--- a/src/components/workspace/SceneHistoryBar.tsx
+++ b/src/components/workspace/SceneHistoryBar.tsx
@@ -16,15 +16,19 @@ function TakePoster({ folderPath, media }: { folderPath: string; media: ProjectA
return url ? <img src={url} alt="" draggable={false} /> : <Film16 aria-hidden="true" />;
}
-export function SceneHistoryBar({ job, assets, folderPath, onSelect, onMakePrimary, onRemove }: {
+export function SceneHistoryBar({ job, assets, folderPath, onSelect, onMakePrimary, onRemove, onRemoveDraft }: {
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;
+ onRemoveDraft?: (job: GenerationJob) => void;
}) {
const history = sceneHistory(job, assets);
const busy = ["queued", "generating", "ready"].includes(job.status);
const menu = useContextMenu();
+ const draftMenu = (source: Parameters<typeof menu.open>[0]) => menu.open(source, [{ id: "remove-draft", label: "Remove draft", icon: <Delete16 />, danger: true,
+ disabled: busy || !onRemoveDraft || !history.versions.length,
+ onSelect: () => onRemoveDraft?.(job) }], { "aria-label": `Draft actions for ${job.title}` });
return <aside className="scene-history" aria-label={`Generation history for ${job.title}`}>
{history.versions.map((version, index) => {
const primary = version.id === history.primaryId;
@@ -42,7 +46,8 @@ export function SceneHistoryBar({ job, assets, folderPath, onSelect, onMakePrima
</button>;
})}
{(history.draft || !history.versions.length) && <button type="button" className="scene-history__take scene-history__draft" disabled={busy || !onSelect}
- aria-label={`Draft of ${job.title}`} aria-pressed={!history.selectedId} onClick={() => onSelect?.(job, null)}>
+ aria-label={`Draft of ${job.title}`} aria-pressed={!history.selectedId} onClick={() => onSelect?.(job, null)}
+ onContextMenu={draftMenu} onKeyDown={event => { if (event.key === "ContextMenu" || event.key === "F10" && event.shiftKey) { event.preventDefault(); draftMenu(event); } }}>
<span className="scene-history__picture"><Edit16 aria-hidden="true" /></span><span>Draft</span>
</button>}
{menu.element}
diff --git a/src/lib/sceneHistory.test.ts b/src/lib/sceneHistory.test.ts
index 9faa3b7..9fb031f 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, removeSceneGeneration, saveSceneDrafts, sceneInput, selectSceneGeneration, SCENE_GENERATION_HISTORY_LIMIT } from "./sceneHistory";
+import { completeSceneGeneration, duplicateScene, makeSceneGenerationPrimary, removeSceneDraft, 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 });
@@ -29,6 +29,44 @@ const edit = (config: ProjectConfig, music: string) => saveSceneDrafts({ ...conf
shots: j.shots!.map(shot => ({ ...shot, action: music, speech: `${music} speech` })) })) }, config);
describe("scene generation history", () => {
+ it("removes a selected draft, restores primary settings and supports undo and redo", () => {
+ const config = edit(finish(edit(initial(), "First"), "one"), "Pending");
+ const id = config.generationJobs[0].id;
+ config.generationJobs[0].title = "Renamed scene";
+ const session = new ProjectSession({ folderPath: "C:/history", config }, vi.fn(async () => {}));
+ session.edit(current => removeSceneDraft(current, id));
+ const removed = parseProjectConfig(JSON.parse(JSON.stringify(session.getSnapshot().config)));
+ expect(removed.generationJobs[0]).toMatchObject({ title: "Renamed scene", music: "First", steps: 4, seed: 10,
+ outputRelativePath: "media/one.mp4", latentRelativePath: "latents/one.safetensors", generationHistory: { draft: null, primaryId: "one", selectedId: "one" } });
+ expect(removed.generationJobs[0].generationHistory!.versions).toEqual(config.generationJobs[0].generationHistory!.versions);
+ expect(session.getSnapshot().config.assets).toBe(config.assets);
+ expect(session.getSnapshot().config.timeline).toBe(config.timeline);
+ expect(session.undo()).toBe(true);
+ expect(session.getSnapshot().config.generationJobs[0]).toMatchObject({ music: "Pending", generationHistory: { selectedId: null, draft: { music: "Pending" } } });
+ expect(session.redo()).toBe(true);
+ expect(session.getSnapshot().config.generationJobs[0].generationHistory!.draft).toBeNull();
+ });
+
+ it("removes an unselected draft without switching the selected or primary Take", () => {
+ let config = edit(finish(edit(finish(edit(initial(), "First"), "one"), "Second"), "two"), "Pending");
+ const id = config.generationJobs[0].id;
+ config = selectSceneGeneration(config, id, "one");
+ config = saveSceneDrafts(removeSceneDraft(config, id));
+ expect(config.generationJobs[0]).toMatchObject({ music: "First", outputRelativePath: "media/two.mp4",
+ generationHistory: { draft: null, primaryId: "two", selectedId: "one" } });
+ expect(edit(config, "New draft").generationJobs[0].generationHistory!.draft?.music).toBe("New draft");
+ });
+
+ it("keeps the only draft and blocks draft removal during generation", () => {
+ const empty = initial();
+ expect(removeSceneDraft(empty, empty.generationJobs[0].id)).toBe(empty);
+ const config = edit(finish(initial(), "one"), "Pending");
+ for (const status of ["queued", "generating", "ready"] as const) {
+ const busy = { ...config, generationJobs: config.generationJobs.map(job => ({ ...job, status })) };
+ expect(removeSceneDraft(busy, busy.generationJobs[0].id)).toBe(busy);
+ }
+ });
+
it.each([false, true])("renames a scene without creating a draft, including legacy history %s", legacy => {
const config = finish(initial(), "one");
if (legacy) delete config.generationJobs[0].generationHistory;
diff --git a/src/lib/sceneHistory.ts b/src/lib/sceneHistory.ts
index 7e6ebc7..bb8e66f 100644
--- a/src/lib/sceneHistory.ts
+++ b/src/lib/sceneHistory.ts
@@ -64,6 +64,20 @@ export function selectSceneGeneration(config: ProjectConfig, sceneId: string, ve
}) };
}
+/** Discard pending settings, keeping the selected saved take or restoring the primary. */
+export function removeSceneDraft(config: ProjectConfig, sceneId: string): ProjectConfig {
+ const current = config.generationJobs.find(job => job.id === sceneId);
+ if (!current || ["queued", "generating", "ready"].includes(current.status)) return config;
+ const saved = saveSceneDrafts(config);
+ const job = saved.generationJobs.find(job => job.id === sceneId)!;
+ const history = sceneHistory(job, saved.assets);
+ const selected = history.versions.find(version => version.id === history.selectedId)
+ ?? history.versions.find(version => version.id === history.primaryId) ?? history.versions.at(-1);
+ if (!history.draft || !selected) return config;
+ return { ...saved, generationJobs: saved.generationJobs.map(item => item.id === sceneId
+ ? { ...applyInput(item, selected.scene), generationHistory: { ...history, selectedId: selected.id, draft: null } } : item) };
+}
+
/** Browsing changes the board's preview, never the primary output used by
* timeline clips, continuations and generation references. */
export function scenePreviewJob(job: GenerationJob, assets: readonly ProjectAsset[]): GenerationJob {