AI media harness for planning, generating, and editing locally
TypeScript
Keep image editing drafts in the image bar
Bitticeef1049a06a
diff --git a/README.md b/README.mdindex 138e316..311764b 100644--- a/README.md+++ b/README.md@@ -27,6 +27,8 @@ Image projects use **Agent**, **Editor**, and **References** tabs. In the EditorThe inspector offers **Prompt root** for a new composition and **Image root** to open an existing PNG or JPEG. You can also right-click a generated thumbnail and choose **Edit** to start an image root from it. Add Object nodes with descriptions and placement boxes, then Generate. In image-root mode, SlopFab applies each edit in hierarchy order using exact bounding-box inpainting, preserving pixels outside each box. The final PNG keeps the source resolution and becomes a clean image root for further edits. In prompt-root mode, placement boxes guide the prompt rather than acting as masks.+An **Editing** thumbnail holds the pending image version. Select other thumbnails to browse results, then select Editing to return to its hierarchy and prompts. Saving the project also saves this draft. Successful generation replaces the temporary thumbnail with the finished image; failed or cancelled generation keeps it available for retry.+The Agent can add, edit, reorder, reparent, duplicate and remove image nodes, and adjust prompts, style, placement, palettes, references, steps and seeds. Edits are transactional and preserve generated images. See the [image command guide](src-tauri/assets/agent-image.md) for the command vocabulary and examples.> **GPU recommendation:** A GPU with **24 GB of VRAM or more** is currently recommended for local video generation. We plan to reduce VRAM usage in future updates.diff --git a/src-tauri/src/project/commands/clips.rs b/src-tauri/src/project/commands/clips.rsindex 91692fc..a861981 100644--- a/src-tauri/src/project/commands/clips.rs+++ b/src-tauri/src/project/commands/clips.rs@@ -62,6 +62,7 @@ pub(super) fn apply(height: None,has_audio: None,image_generation: None,+ image_draft: None,created_at: job.created_at.clone(),});planned_iddiff --git a/src-tauri/src/project/model.rs b/src-tauri/src/project/model.rsindex 4feb7fa..87deec9 100644--- a/src-tauri/src/project/model.rs+++ b/src-tauri/src/project/model.rs@@ -95,6 +95,8 @@ pub(crate) struct ProjectAsset {pub(crate) has_audio: Option<bool>,#[serde(default, skip_serializing_if = "Option::is_none")]pub(crate) image_generation: Option<super::image::ImageGenerationSnapshot>,+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub(crate) image_draft: Option<bool>,pub(crate) created_at: String,}#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]diff --git a/src-tauri/src/project/validation/assets.rs b/src-tauri/src/project/validation/assets.rsindex 236332c..0af7cc5 100644--- a/src-tauri/src/project/validation/assets.rs+++ b/src-tauri/src/project/validation/assets.rs@@ -3,6 +3,9 @@ use crate::project::paths::*;use crate::project::*;pub(super) fn validate(config: &mut ProjectConfig) -> Result<(), String> {for asset in &mut config.assets {+ if asset.image_draft == Some(true) && (asset.kind != "image" || !asset.image_generation.as_ref().is_some_and(|snapshot| snapshot.scene.root_type.as_deref() == Some("image") && snapshot.scene.source_image.is_some())) {+ return Err("Image drafts require an image-root snapshot.".into());+ }if let Some(snapshot) = &mut asset.image_generation {snapshot.scene.validate()?;if asset.kind != "image"diff --git a/src-tauri/src/tests/images.rs b/src-tauri/src/tests/images.rsindex 59b3ce4..89fb9aa 100644--- a/src-tauri/src/tests/images.rs+++ b/src-tauri/src/tests/images.rs@@ -4,6 +4,25 @@ fn image_fixture() -> ProjectConfig {serde_json::from_str(include_str!("../../../fixtures/project-v1-image.json")).unwrap()}+#[test]+fn image_editing_draft_survives_save_and_reopen() {+ let mut config = image_fixture();+ let mut snapshot: serde_json::Value = serde_json::from_str(include_str!("../../../fixtures/image-generation-snapshot.json")).unwrap();+ snapshot["scene"]["rootType"] = serde_json::json!("image");+ snapshot["scene"]["sourceImage"] = serde_json::json!({"name":"Source", "relativePath":"media/imported/source.png", "width":65, "height":41});+ config.assets.push(serde_json::from_value(serde_json::json!({+ "id":"draft", "kind":"image", "name":"Editing Source", "relativePath":"media/imported/source.png", "mimeType":"image/png",+ "width":65, "height":41, "createdAt":config.created_at, "imageDraft":true, "imageGeneration":snapshot+ })).unwrap());+ let root = tempfile::tempdir().unwrap();+ let created = create_project_in(root.path(), &config).unwrap();+ let opened = read_project(Path::new(&created.folder_path)).unwrap();+ assert_eq!(opened.config.assets[0], config.assets[0]);+ let mut invalid = opened.config;+ invalid.assets[0].image_generation = None;+ assert!(validate_and_normalize_config(invalid).is_err());+}+#[test]fn edited_png_preserves_exact_pixels_and_exports_to_jpeg() {let folder = project_folder();diff --git a/src-tauri/src/tests/media_access.rs b/src-tauri/src/tests/media_access.rsindex 7de5c8b..5fecdaf 100644--- a/src-tauri/src/tests/media_access.rs+++ b/src-tauri/src/tests/media_access.rs@@ -112,6 +112,7 @@ fn external_media_is_readable_only_because_the_project_names_it() {height: None,has_audio: None,image_generation: None,+ image_draft: None,created_at: config.created_at.clone(),});let created = create_project_in(root.path(), &config).unwrap();@@ -284,6 +285,7 @@ fn a_project_the_user_only_opened_reads_any_media_file_it_names() {height: None,has_audio: None,image_generation: None,+ image_draft: None,created_at: config.created_at.clone(),});}diff --git a/src-tauri/src/tests/persistence.rs b/src-tauri/src/tests/persistence.rsindex 8e9cfa2..1aebce1 100644--- a/src-tauri/src/tests/persistence.rs+++ b/src-tauri/src/tests/persistence.rs@@ -352,6 +352,7 @@ fn a_project_file_only_yields_media_a_hand_edit_cannot_widen() {height: None,has_audio: None,image_generation: None,+ image_draft: None,created_at: config.created_at.clone(),});let created = create_project_in(root.path(), &config).unwrap();diff --git a/src/components/ProjectWorkspace.tsx b/src/components/ProjectWorkspace.tsxindex 39a28aa..ed673d5 100644--- a/src/components/ProjectWorkspace.tsx+++ b/src/components/ProjectWorkspace.tsx@@ -138,7 +138,7 @@ export function ProjectWorkspace({ project, initialView = "timeline", runtime =className="secondary-button"type="button"aria-current={!imageProject && view === "export" ? "page" : undefined}- disabled={imageProject && (!imageOutput?.relativePath || !isTauri() || exportingImage)}+ disabled={imageProject && (!imageOutput?.relativePath || imageOutput.imageDraft || !isTauri() || exportingImage)}onClick={() => imageProject ? void exportImage() : setView("export")}title={imageProject ? "Save the selected image as JPG or PNG" : "Render the timeline to a video file"}>diff --git a/src/components/workspace/ImageEditor.test.tsx b/src/components/workspace/ImageEditor.test.tsxindex 2375fbb..c79561e 100644--- a/src/components/workspace/ImageEditor.test.tsx+++ b/src/components/workspace/ImageEditor.test.tsx@@ -29,10 +29,21 @@ it("starts an image root from the thumbnail Edit menu and hides root text controconst current = setup(initial);fireEvent.contextMenu(screen.getByRole("button", { name: "View Saved" }));fireEvent.click(screen.getByRole("menuitem", { name: "Edit" }));- expect(current().imageScene).toMatchObject({ rootType: "image", sourceImage: { relativePath: "media/generated/saved.jpg", width: 101, height: 77 }, outputAssetId: null });+ expect(current().imageScene).toMatchObject({ rootType: "image", sourceImage: { relativePath: "media/generated/saved.jpg", width: 101, height: 77 }, outputAssetId: expect.stringMatching(/^image-draft-/) });expect(current().imageScene!.nodes).toHaveLength(1);expect(screen.queryByLabelText("Prompt (high-level description)")).not.toBeInTheDocument();expect(screen.getByRole("button", { name: "Open image" })).toBeInTheDocument();+ const draft = screen.getByRole("button", { name: "View Editing Saved" });+ expect(draft).toHaveAttribute("aria-pressed", "true");+ fireEvent.contextMenu(screen.getByRole("button", { name: "Image" }));+ fireEvent.click(screen.getByRole("menuitem", { name: "New Object" }));+ fireEvent.change(screen.getByLabelText("Description"), { target: { value: "A red balloon" } });+ fireEvent.click(screen.getByRole("button", { name: "View Saved" }));+ expect(draft).toHaveAttribute("aria-pressed", "false");+ fireEvent.click(draft);+ expect(current().imageScene!.nodes[1].description).toBe("A red balloon");+ expect(current().assets.filter((asset) => asset.imageDraft)).toHaveLength(1);+ expect(parseProjectConfig(JSON.parse(JSON.stringify(current()))).assets).toEqual(current().assets);expect(screen.getByLabelText("Image placement canvas").parentElement!.style.getPropertyValue("--image-ratio")).toBe(String(101 / 77));fireEvent.change(screen.getByLabelText("Root type"), { target: { value: "prompt" } });expect(screen.getByLabelText("Prompt (high-level description)")).toBeInTheDocument();diff --git a/src/components/workspace/ImageEditor.tsx b/src/components/workspace/ImageEditor.tsxindex 18a1c65..79e7d2d 100644--- a/src/components/workspace/ImageEditor.tsx+++ b/src/components/workspace/ImageEditor.tsx@@ -5,7 +5,7 @@ import { addImageNode, createImageEditScene, createImageScene, duplicateImageNodimport { compileImageEdits, editGeneratedImage, imageEditDebugPrompt } from "../../lib/imageEditing";import { outputDimensions } from "../../lib/export";import { compileImagePrompt } from "../../lib/imagePrompt";-import { restoreGeneratedImage } from "../../lib/imageHistory";+import { restoreGeneratedImage, saveImageDraft } from "../../lib/imageHistory";import { isTauri } from "../../lib/persistence";import { PROJECT_RESOLUTIONS, type ProjectConfig } from "../../lib/project";import { defaultGeneratorTemplate, loadDebugOptionsEnabled, loadGeneratorTemplateSettings, subscribeDebugOptions, subscribeGeneratorTemplates, templateNeedsDownload, type GeneratorTemplate } from "../../lib/settings";@@ -23,7 +23,7 @@ import "../../styles/image-editor.css";const MIN_IMAGE_ZOOM = 0.1;const MAX_IMAGE_ZOOM = 8;-export function ImageEditor({ config, folderPath, onChange, onGenerate, onCancel, work }: {+export function ImageEditor({ config, folderPath, onChange: changeConfig, onGenerate, onCancel, work }: {config: ProjectConfig; folderPath: string; onChange: (update: ConfigUpdate) => void;onGenerate: (template: GeneratorTemplate) => void; onCancel: (id: string) => Promise<void>; work?: WorkItem;}) {@@ -51,6 +51,11 @@ export function ImageEditor({ config, folderPath, onChange, onGenerate, onCancelconst [templateId, setTemplateId] = useState(() => localStorage.getItem("slopus.image-generator-template.v1") ?? defaultGeneratorTemplate().id);const imageTemplates = templates.templates.filter((template) => template.mode !== "animate");const template = imageTemplates.find((candidate) => candidate.id === templateId) ?? imageTemplates.find((candidate) => !templateNeedsDownload(candidate)) ?? imageTemplates[0];+ const onChange = (update: ConfigUpdate) => changeConfig((current) => {+ const next = typeof update === "function" ? update(current) : update;+ const selecting = next.imageScene?.outputAssetId && next.imageScene.outputAssetId !== current.imageScene?.outputAssetId;+ return saveImageDraft(next, selecting ? undefined : template?.id);+ });const [error, setError] = useState<string | null>(null);const debugEnabled = useSyncExternalStore(subscribeDebugOptions, loadDebugOptionsEnabled);const [debugPrompt, setDebugPrompt] = useState<string | null>(null);@@ -191,7 +196,7 @@ export function ImageEditor({ config, folderPath, onChange, onGenerate, onCancel: remaining.find((asset) => asset.id === currentScene.outputAssetId);const updated = { ...current,assets: current.assets.filter((asset) => asset.id !== id),- imageScene: { ...currentScene, outputAssetId: removingSelected ? next?.id ?? null : currentScene.outputAssetId },+ imageScene: removingSelected && removed.imageDraft && !next ? createImageEditScene(null, currentScene) : { ...currentScene, outputAssetId: removingSelected ? next?.id ?? null : currentScene.outputAssetId },thumbnail: removingSelected || current.thumbnail === removed.relativePath ? next?.relativePath ?? null : current.thumbnail,timeline: { ...current.timeline, tracks: current.timeline.tracks.map((track) => ({ ...track, clips: track.clips.filter((clip) => clip.assetId !== id) })) },};@@ -346,8 +351,8 @@ export function ImageEditor({ config, folderPath, onChange, onGenerate, onCancel{ label: "Delete", icon: <Trash2 size={15} />, shortcut: "Delete", separator: true, danger: true, disabled: selected.kind === "root", action: removeSelected },]} />}{imageMenu && <HierarchyContextMenu {...imageMenu} label="Generated image actions" onClose={closeImageMenu} items={[- { label: "Edit", icon: <Pencil size={15} />, action: () => attempt(() => replaceScene(editGeneratedImage(config, imageMenu.id).imageScene!)) },- { label: "Remove", icon: <Trash2 size={15} />, danger: true, action: () => removeImage(imageMenu.id) },+ { label: "Edit", icon: <Pencil size={15} />, action: () => attempt(() => config.assets.find((asset) => asset.id === imageMenu.id)?.imageDraft ? selectImage(imageMenu.id) : replaceScene(editGeneratedImage(config, imageMenu.id).imageScene!)) },+ { label: "Remove", icon: <Trash2 size={15} />, danger: true, disabled: Boolean(active && work.imageDraftId === imageMenu.id), action: () => removeImage(imageMenu.id) },]} />}<section className="image-center" aria-label="Image panel"><div className="image-canvas-tools">@@ -399,7 +404,7 @@ export function ImageEditor({ config, folderPath, onChange, onGenerate, onCancelsetContextMenu(null); setImageMenu({ id: asset.id, x: bounds.left, y: bounds.bottom });}}}- onClick={() => selectImage(asset.id)}><ReferenceImage folderPath={folderPath} relativePath={asset.relativePath} sourcePath={asset.sourcePath} alt={asset.name} /></button>)}</div>}+ onClick={() => selectImage(asset.id)}><ReferenceImage folderPath={folderPath} relativePath={asset.relativePath} sourcePath={asset.sourcePath} alt={asset.name} />{asset.imageDraft && <span className="image-draft-badge"><Pencil size={11} />Editing</span>}</button>)}</div>}</section><aside className="image-inspector" aria-label="Image node inspector"><header><strong>Inspector</strong><span>{selected.kind}</span></header><div className="image-inspector__fields">{selected.kind === "root" && <label>Root type<select value={imageRoot ? "image" : "prompt"} onChange={(event) => replaceScene(event.target.value === "image" ? createImageEditScene(null, scene) : { ...createImageScene(), steps: scene.steps, seed: scene.seed })}><option value="prompt">Prompt root</option><option value="image">Image root</option></select></label>}diff --git a/src/lib/imageHistory.ts b/src/lib/imageHistory.tsindex abc6636..77adeef 100644--- a/src/lib/imageHistory.ts+++ b/src/lib/imageHistory.ts@@ -1,5 +1,5 @@import { createImageEditScene, createImageScene } from "./imageScene";-import type { ImageGenerationSnapshot, ProjectConfig } from "./project";+import type { ImageGenerationSnapshot, ProjectAsset, ProjectConfig } from "./project";export function imageGenerationSnapshot(config: ProjectConfig, prompt: string, generatorTemplateId: string): ImageGenerationSnapshot {const scene = config.imageScene ?? createImageScene(config.brief.prompt);@@ -15,6 +15,37 @@ export function imageGenerationSnapshot(config: ProjectConfig, prompt: string, g});}+/** Keep the editable version in history without creating another image file. */+export function saveImageDraft(config: ProjectConfig, generatorTemplateId?: string): ProjectConfig {+ const scene = config.imageScene;+ if (config.generationType !== "image" || scene?.rootType !== "image" || !scene.sourceImage) return config;+ const selected = config.assets.find((asset) => asset.id === scene.outputAssetId);+ if (!selected?.imageDraft && scene.outputAssetId && scene.nodes.length === 1) return config;+ const existing = selected?.imageDraft ? selected : undefined;+ const id = existing?.id ?? `image-draft-${crypto.randomUUID()}`;+ const snapshot = imageGenerationSnapshot(config, "", generatorTemplateId || existing?.imageGeneration?.generatorTemplateId || selected?.imageGeneration?.generatorTemplateId || "image-draft");+ if (existing && JSON.stringify(existing.imageGeneration) === JSON.stringify(snapshot)) return config;+ const source = scene.sourceImage;+ const asset = { id, kind: "image" as const, ...source, name: existing?.name ?? `Editing ${source.name}`,+ imageDraft: true, mimeType: /\.png$/i.test(source.relativePath) ? "image/png" : "image/jpeg",+ imageGeneration: snapshot, createdAt: existing?.createdAt ?? new Date().toISOString() };+ return { ...config, imageScene: { ...scene, outputAssetId: id }, assets: existing ? config.assets.map((item) => item.id === id ? asset : item) : [...config.assets, asset] };+}++export function completeImageDraft(config: ProjectConfig, id: string, result: ProjectAsset): ProjectConfig {+ const draft = config.assets.find((asset) => asset.id === id && asset.imageDraft);+ const selected = config.imageScene?.outputAssetId === id;+ const changed = draft && JSON.stringify({ ...draft.imageGeneration, prompt: "" }) !== JSON.stringify({ ...result.imageGeneration, prompt: "" });+ // Edits made during generation remain a separate draft on the original source.+ const pending = changed ? { ...draft, id: `image-draft-${crypto.randomUUID()}` } : null;+ const asset = { ...result, id, imageDraft: false };+ const assets = config.assets.some((item) => item.id === id) ? config.assets.map((item) => item.id === id ? asset : item) : [...config.assets, asset];+ const next = { ...config, assets: pending ? [...assets, pending] : assets };+ if (!selected) return next;+ if (pending) return { ...next, imageScene: { ...config.imageScene!, outputAssetId: pending.id } };+ return restoreGeneratedImage(next, id);+}+/** Restore authored inputs without replacing other results or unrelated references. */export function restoreGeneratedImage(config: ProjectConfig, id: string): ProjectConfig {const asset = config.assets.find((candidate) => candidate.id === id && candidate.kind === "image");@@ -23,7 +54,7 @@ export function restoreGeneratedImage(config: ProjectConfig, id: string): Projecif (!snapshot) return { ...config, thumbnail: asset.relativePath ?? null,imageScene: { ...(config.imageScene?.rootType === "image" ? createImageScene() : config.imageScene ?? createImageScene(config.brief.prompt)), outputAssetId: id } };const restored = structuredClone(snapshot);- const scene = restored.scene.rootType === "image" && asset.relativePath && asset.width && asset.height+ const scene = !asset.imageDraft && restored.scene.rootType === "image" && asset.relativePath && asset.width && asset.height? createImageEditScene({ relativePath: asset.relativePath, name: asset.name, width: asset.width, height: asset.height }, restored.scene): restored.scene;const references = new Map(restored.references.map((reference) => [reference.id, reference]));diff --git a/src/lib/project.ts b/src/lib/project.tsindex 33c7b98..de72216 100644--- a/src/lib/project.ts+++ b/src/lib/project.ts@@ -179,9 +179,13 @@ export const projectAssetSchema = z.object({/** Whether the container has an audio stream. */hasAudio: z.boolean().nullish(),imageGeneration: imageGenerationSnapshotSchema.nullish(),+ imageDraft: z.boolean().nullish(),createdAt: isoDateSchema,}).superRefine((asset, context) => {checkOneLocation(asset, context, `Asset '${asset.id}'`);+ if (asset.imageDraft && (asset.kind !== "image" || !asset.imageGeneration?.scene.sourceImage || asset.imageGeneration.scene.rootType !== "image")) {+ context.addIssue({ code: z.ZodIssueCode.custom, message: "Image drafts require an image-root snapshot." });+ }if (asset.imageGeneration && asset.kind !== "image") {context.addIssue({ code: z.ZodIssueCode.custom, path: ["imageGeneration"], message: "Only image assets can store image generation history." });}diff --git a/src/lib/projectSession.ts b/src/lib/projectSession.tsindex e3dc2ff..088e7cd 100644--- a/src/lib/projectSession.ts+++ b/src/lib/projectSession.ts@@ -1,5 +1,6 @@import { describeDiagnosticError, writeDiagnostic } from "./diagnostics";import type { ProjectConfig, ProjectRecord } from "./project";+import { saveImageDraft } from "./imageHistory";export type ProjectUpdate = ProjectConfig | ((current: ProjectConfig) => ProjectConfig);export type ProjectWriter = (record: ProjectRecord) => Promise<ProjectRecord | void>;@@ -14,7 +15,8 @@ export class ProjectSession {private savedConfig: ProjectConfig;constructor(readonly record: ProjectRecord, private writer: ProjectWriter) {this.savedConfig = record.config;- this.state = { config: record.config, dirty: false, saving: false, saveError: null };+ const config = saveImageDraft(record.config);+ this.state = { config, dirty: config !== record.config, saving: false, saveError: null };}getSnapshot = () => this.state;subscribe = (listener: () => void) => { this.listeners.add(listener); return () => { this.listeners.delete(listener); }; };@@ -23,7 +25,7 @@ export class ProjectSession {this.listeners.forEach((listener) => listener());}update = (next: ProjectUpdate, dirty = true) => {- const config = typeof next === "function" ? next(this.state.config) : next;+ const config = saveImageDraft(typeof next === "function" ? next(this.state.config) : next);if (config === this.state.config) return;if (dirty) this.revision += 1;this.publish({ config, dirty: this.state.dirty || dirty });diff --git a/src/lib/workQueue.test.ts b/src/lib/workQueue.test.tsindex 5c7d014..475d2e3 100644--- a/src/lib/workQueue.test.ts+++ b/src/lib/workQueue.test.ts@@ -80,6 +80,8 @@ describe("image generation work", () => {expect(edit.prompt).toContain("<Picture 1> is the original source image");expect(edit.prompt).toContain("<Subject 1> is Balloon, providing appearance from <Picture 2>");}+ const draftId = session.getSnapshot().config.imageScene!.outputAssetId!;+ expect(session.getSnapshot().config.assets[0]).toMatchObject({ id: draftId, imageDraft: true });expect(request).toMatchObject({ stillImage: true, frames: 1, canvasWidth: 101, canvasHeight: 77, imageEdit: { sourceRelativePath: "media/generated/source.jpg", edits: [{ prompt: expect.stringContaining("A red balloon"), x: 25, y: 19, width: 51, height: 39 },{ prompt: expect.stringContaining("A blue boat"), x: 25, y: 19, width: 51, height: 39 },@@ -88,11 +90,52 @@ describe("image generation work", () => {expect(invoke).toHaveBeenCalledWith("save_generated_image", { folderPath: record.folderPath, jobId: request.jobId, format: "png" });const result = session.getSnapshot().config;expect(result.imageScene!.nodes).toHaveLength(1);+ expect(result.assets).toHaveLength(1);+ expect(result.assets[0]).toMatchObject({ id: draftId, imageDraft: false, relativePath: "media/generated/edited.png" });+ expect(result.imageScene!.outputAssetId).toBe(draftId);expect(result.imageScene).toMatchObject({ rootType: "image", sourceImage: { relativePath: "media/generated/edited.png", width: 101, height: 77 } });expect(result.assets[0]).toMatchObject({ mimeType: "image/png", imageGeneration: { scene, prompt: expect.stringContaining("Edit 2 (25, 19, 51, 39)") } });- expect(restoreGeneratedImage(result, request.jobId).imageScene!.nodes).toHaveLength(1);+ expect(restoreGeneratedImage(result, draftId).imageScene!.nodes).toHaveLength(1);expect(releaseRendered).toHaveBeenCalledWith(request.jobId);});+ it.each(["browse", "modify", "cancel"])("keeps editing versions available during generation: %s", async (action) => {+ const { queue } = setup();+ const record = imageProject();+ record.config.imageScene = addImageNode(createImageEditScene({ name: "Source", relativePath: "media/generated/source.jpg", width: 101, height: 77 }), "image-root", "object");+ record.config.imageScene.nodes[1].description = "A red balloon";+ record.config.assets = [{ id: "original", name: "Original", kind: "image", relativePath: "media/generated/source.jpg", width: 101, height: 77, mimeType: "image/jpeg", createdAt: record.config.createdAt }];+ const session = queue.project(record);+ vi.mocked(invoke).mockResolvedValue({ relativePath: "media/generated/edited.png", width: 101, height: 77 });+ queue.enqueueImage(session, template);+ await waitFor(() => expect(enqueueSlopfabGeneration).toHaveBeenCalledOnce());+ const id = vi.mocked(enqueueSlopfabGeneration).mock.calls[0][0].jobId;+ const draftId = session.getSnapshot().config.imageScene!.outputAssetId!;+ if (action === "modify") session.update((config) => ({ ...config, imageScene: { ...config.imageScene!, nodes: config.imageScene!.nodes.map((node) => node.kind === "object" ? { ...node, description: "A blue balloon" } : node) } }));+ else session.update((config) => restoreGeneratedImage(config, "original"));+ if (action === "cancel") {+ await queue.cancel(id);+ emit("slopfab-job", { jobId: id, state: "cancelled", detail: "Cancelled" });+ expect(session.getSnapshot().config.assets.find((asset) => asset.id === draftId)?.imageDraft).toBe(true);+ session.update((config) => restoreGeneratedImage(config, draftId));+ expect(session.getSnapshot().config.imageScene!.nodes[1].description).toBe("A red balloon");+ expect(invoke).not.toHaveBeenCalledWith("save_generated_image", expect.anything());+ return;+ }+ await finish(queue, id);+ const config = session.getSnapshot().config;+ expect(config.assets.find((asset) => asset.id === draftId)).toMatchObject({ imageDraft: false, relativePath: "media/generated/edited.png" });+ if (action === "browse") {+ expect(config.imageScene!.outputAssetId).toBe("original");+ expect(config.assets).toHaveLength(2);+ session.update((current) => restoreGeneratedImage(current, draftId));+ expect(session.getSnapshot().config.imageScene!.nodes).toHaveLength(1);+ } else {+ expect(config.imageScene!.outputAssetId).not.toBe(draftId);+ expect(config.assets.filter((asset) => asset.imageDraft)).toHaveLength(1);+ expect(config.imageScene!.nodes[1].description).toBe("A blue balloon");+ }+ expect(parseProjectConfig(JSON.parse(JSON.stringify(config))).assets).toEqual(config.assets);+ });it("forwards selected refmods to still-image planning and generation with their strength and copies", async () => {const { queue } = setup();const project = imageProject();diff --git a/src/lib/workQueue.ts b/src/lib/workQueue.tsindex ab8cf9d..8d3ba99 100644--- a/src/lib/workQueue.ts+++ b/src/lib/workQueue.ts@@ -3,7 +3,7 @@ import { invoke } from "@tauri-apps/api/core";import { createImageEditScene, createImageScene, imageScenePrompt } from "./imageScene";import { compileImageEdits, imageEditDebugPrompt } from "./imageEditing";import { compileImagePrompt } from "./imagePrompt";-import { imageGenerationSnapshot } from "./imageHistory";+import { completeImageDraft, imageGenerationSnapshot, saveImageDraft } from "./imageHistory";import type { ImageGenerationSnapshot } from "./project";import { outputDimensions } from "./export";import { projectItemPath, referenceImages, referenceRefmodInputs } from "./project";@@ -23,6 +23,7 @@ import { prepareReferenceVideos, releaseReferenceVideos } from "./referenceVideoexport type WorkStatus = "queued" | "preparing" | "generating" | "encoding" | "completed" | "failed" | "cancelled";export interface GenerationSubmission { job: GenerationJob; request: SlopfabGenerationRequest; snapshot: string }export interface WorkItem {+ imageDraftId?: string;kind?: "reference-icons" | "image";id: string;projectKey: string;@@ -41,6 +42,7 @@ export interface WorkItem {settings: { frames: number; steps: number; seed: number; canvasWidth: number; canvasHeight: number };}interface PendingWork {+ imageDraftId?: string;image?: boolean;imageGeneration?: ImageGenerationSnapshot;id: string;@@ -201,6 +203,7 @@ export class WorkQueue {enqueueImage(session: ProjectSession, template: GeneratorTemplate) {if (!isTauri()) throw new Error("Image generation requires the desktop app and MiniMax H3 weights.");if (template.mode === "animate") throw new Error("Choose a MiniMax H3 prompt template for images.");+ session.update((config) => saveImageDraft(config, template.id));const current = session.getSnapshot().config;if (current.generationType !== "image") throw new Error("Open an image project to generate images.");const scene = current.imageScene ?? createImageScene(current.brief.prompt);@@ -213,6 +216,7 @@ export class WorkQueue {const { prompt, references } = compileImagePrompt(current);const { width, height } = edit?.source ?? outputDimensions(current.settings.resolution, current.settings.aspectRatio);const id = `image-${crypto.randomUUID()}`;+ const imageDraftId = edit ? scene.outputAssetId ?? undefined : undefined;let finish!: () => void;const done = new Promise<void>((resolve) => { finish = resolve; });const request: SlopfabGenerationRequest = { jobId: id, stillImage: true, frames: 1, prompt: edit ? edit.edits[0].prompt : prompt,@@ -222,8 +226,8 @@ export class WorkQueue {...references.flatMap((reference) => referenceImages(reference).map((image) => projectItemPath(session.record.folderPath, image)!))],refmods: referenceRefmodInputs(session.record.folderPath, references),};- this.work.set(id, { id, image: true, imageGeneration: imageGenerationSnapshot(config, edit ? imageEditDebugPrompt(edit.edits) : prompt, template.id), session, sceneId: scene.nodes.find((node) => node.kind === "root")!.id, config, snapshot: JSON.stringify(scene), request, submitted: false, cancelled: false, done, finish });- this.items = [...this.items, { id, kind: "image", projectKey, folderPath: session.record.folderPath, projectName: config.name, sceneId: scene.nodes.find((node) => node.kind === "root")!.id,+ this.work.set(id, { id, image: true, imageDraftId, imageGeneration: imageGenerationSnapshot(config, edit ? imageEditDebugPrompt(edit.edits) : prompt, template.id), session, sceneId: scene.nodes.find((node) => node.kind === "root")!.id, config, snapshot: JSON.stringify(scene), request, submitted: false, cancelled: false, done, finish });+ this.items = [...this.items, { id, kind: "image", imageDraftId, projectKey, folderPath: session.record.folderPath, projectName: config.name, sceneId: scene.nodes.find((node) => node.kind === "root")!.id,title: "Image · " + config.name, submittedAt: new Date().toISOString(), status: "queued", progress: 0, detail: "Waiting to generate image", error: null, completionAt: null, cancelling: false, needsSave: false,settings: { frames: 1, steps: request.steps, seed: request.seed, canvasWidth: width, canvasHeight: height } }];this.publish(); this.icons.yieldToVideo(); void this.pump();@@ -403,7 +407,10 @@ export class WorkQueue {this.patch(work.id, { status: "encoding", progress: 0.9, detail: "Saving image", completionAt: null });try {const saved = await invoke<{ relativePath: string; width: number; height: number }>("save_generated_image", { folderPath: work.session.record.folderPath, jobId: work.id, ...(work.request.imageEdit ? { format: "png" } : {}) });- work.session.update((current) => ({ ...current, thumbnail: saved.relativePath,+ work.session.update((current) => work.imageDraftId ? completeImageDraft(current, work.imageDraftId, {+ id: work.imageDraftId, kind: "image", name: `Image ${current.assets.filter((asset) => asset.kind === "image" && !asset.imageDraft).length + 1}`,+ ...saved, imageGeneration: work.imageGeneration, mimeType: "image/png", createdAt: new Date().toISOString(),+ }) : ({ ...current, thumbnail: saved.relativePath,imageScene: { ...(work.request.imageEdit && JSON.stringify(current.imageScene) === work.snapshot ? createImageEditScene({ ...saved, name: "Edited image" }, current.imageScene ?? undefined) : current.imageScene ?? createImageScene()), outputAssetId: work.id },assets: [...current.assets, { id: work.id, kind: "image", name: `Image ${current.assets.filter((asset) => asset.kind === "image").length + 1}`, ...saved, imageGeneration: work.imageGeneration, mimeType: work.request.imageEdit ? "image/png" : "image/jpeg", createdAt: new Date().toISOString() }],}));diff --git a/src/styles/image-editor.css b/src/styles/image-editor.cssindex 0e655ff..74e73e4 100644--- a/src/styles/image-editor.css+++ b/src/styles/image-editor.css@@ -51,7 +51,8 @@.image-status progress { width: 100%; height: var(--space-1); accent-color: var(--accent); }.image-error { margin: 0; padding: var(--space-2) var(--space-3); color: var(--danger); }.image-results { display: flex; gap: var(--space-2); overflow-x: auto; padding: var(--space-2); border-top: 1px solid var(--line-solid); }-.image-results button { flex: 0 0 72px; height: 64px; padding: 0; overflow: hidden; border: 2px solid transparent; background: var(--panel); }+.image-results button { position: relative; flex: 0 0 72px; height: 64px; padding: 0; overflow: hidden; border: 2px solid transparent; background: var(--panel); }+.image-draft-badge { position: absolute; bottom: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: center; gap: 3px; padding: 2px; background: var(--glass); color: var(--text); font-size: 10px; }.image-results button[aria-pressed="true"] { border-color: var(--accent); }.image-results img { width: 100%; height: 100%; object-fit: cover; }.image-inspector__fields { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-3); }