Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Save and display generated image seeds

Bitti6fa84710ddd4
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 48def75..f152121 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -16,6 +16,7 @@ This alpha update adds still image projects, new scene types, and a rebuilt Wind
## Fixes and improvements
+- Generated still images retain their used seed, shown as a read-only field with a copy button in Image generation.
- Interrupted weight and LoRA downloads retain their progress and can resume on retry or after reopening the app.
- Updated the bundled SlopFab runtime.
- Smoother previews: clips are preloaded and pixels are kept across cuts.
diff --git a/src-tauri/src/project/image.rs b/src-tauri/src/project/image.rs
index eec60dc..2d171f3 100644
--- a/src-tauri/src/project/image.rs
+++ b/src-tauri/src/project/image.rs
@@ -11,6 +11,8 @@ pub(crate) struct ImageGenerationSnapshot {
pub brief_prompt: String,
pub prompt: String,
pub generator_template_id: String,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub used_seed: Option<u64>,
pub references: Vec<super::references::ReusableReference>,
}
diff --git a/src-tauri/src/project/validation/assets.rs b/src-tauri/src/project/validation/assets.rs
index 768f189..f070c34 100644
--- a/src-tauri/src/project/validation/assets.rs
+++ b/src-tauri/src/project/validation/assets.rs
@@ -13,6 +13,7 @@ pub(super) fn validate(config: &mut ProjectConfig) -> Result<(), String> {
|| !is_supported_aspect_ratio(&snapshot.aspect_ratio)
|| snapshot.default_look.as_deref().is_some_and(|look| !is_shot_tag_id(look))
|| snapshot.generator_template_id.is_empty()
+ || snapshot.used_seed.is_some_and(|seed| seed > 9_007_199_254_740_991)
|| snapshot.references.len() > 100
{
return Err("Invalid image generation snapshot settings.".into());
diff --git a/src-tauri/src/tests/images.rs b/src-tauri/src/tests/images.rs
index e2bb4b1..86464cb 100644
--- a/src-tauri/src/tests/images.rs
+++ b/src-tauri/src/tests/images.rs
@@ -168,6 +168,7 @@ fn image_tree_survives_folder_creation_save_and_reopen() {
#[test]
fn image_generation_history_survives_native_save_and_reopen_and_validates_snapshots() {
let mut snapshot: serde_json::Value = serde_json::from_str(include_str!("../../../fixtures/image-generation-snapshot.json")).unwrap();
+ snapshot["usedSeed"] = serde_json::json!(9_007_199_254_740_991_u64);
snapshot["scene"]["nodes"][1]["referenceIds"] = snapshot["scene"]["referenceIds"].clone();
snapshot["scene"]["referenceIds"] = serde_json::json!([]);
let expected: crate::project::image::ImageGenerationSnapshot = serde_json::from_value(snapshot.clone()).unwrap();
@@ -187,12 +188,13 @@ fn image_generation_history_survives_native_save_and_reopen_and_validates_snapsh
write_project(Path::new(&created.folder_path), &updated).unwrap();
let reopened = read_project(Path::new(&created.folder_path)).unwrap();
assert_eq!(reopened.config.assets[0].image_generation.as_ref(), Some(&expected));
- for invalid in ["tree", "reference", "resolution"] {
+ for invalid in ["tree", "reference", "resolution", "seed"] {
let mut bad = reopened.config.clone();
let history = bad.assets[0].image_generation.as_mut().unwrap();
match invalid {
"tree" => history.scene.nodes[1].parent_id = Some("missing".into()),
"reference" => history.references.clear(),
+ "seed" => history.used_seed = Some(9_007_199_254_740_992),
_ => history.resolution = "invalid".into(),
}
assert!(validate_and_normalize_config(bad).is_err(), "{invalid}");
diff --git a/src/components/workspace/ImageEditor.test.tsx b/src/components/workspace/ImageEditor.test.tsx
index df12859..1d93cc4 100644
--- a/src/components/workspace/ImageEditor.test.tsx
+++ b/src/components/workspace/ImageEditor.test.tsx
@@ -9,7 +9,7 @@ import { choose, comboValue } from "./comboTestUtils";
import { imageGenerationSnapshotSchema, parseProjectConfig, type ProjectConfig } from "../../lib/project";
import { imageGenerationSnapshot } from "../../lib/imageHistory";
import { createGeneratorTemplate, defaultGeneratorTemplate, saveGeneratorTemplateSettings } from "../../lib/settings";
-import { imageScenePrompt } from "../../lib/imageScene";
+import { createImageEditScene, imageScenePrompt } from "../../lib/imageScene";
import { compileImageEdits } from "../../lib/imageEditing";
import { invoke } from "@tauri-apps/api/core";
import * as persistence from "../../lib/persistence";
@@ -17,7 +17,7 @@ import fixture from "../../../fixtures/project-v1-image.json";
import snapshotFixture from "../../../fixtures/image-generation-snapshot.json";
vi.mock("@tauri-apps/api/core", () => ({ invoke: vi.fn() }));
-afterEach(() => { cleanup(); localStorage.clear(); vi.restoreAllMocks(); });
+afterEach(() => { cleanup(); localStorage.clear(); vi.restoreAllMocks(); vi.unstubAllGlobals(); });
function setup(initial = parseProjectConfig(fixture)) {
let latest: ProjectConfig = initial;
function Harness() {
@@ -32,6 +32,48 @@ function setup(initial = parseProjectConfig(fixture)) {
/* Undo lives in the title bar; inside the editor it is Ctrl+Z. */
const undoImageEdit = () => fireEvent.keyDown(screen.getByRole("tree", { name: "Image nodes" }), { key: "z", code: "KeyZ", ctrlKey: true });
+it.each([false, true])("shows and copies the selected result's exact seed as read-only (image edits: %s)", async (imageRoot) => {
+ const writeText = vi.fn().mockResolvedValue(undefined);
+ vi.stubGlobal("navigator", Object.assign(Object.create(navigator), { clipboard: { writeText } }));
+ const initial = parseProjectConfig(fixture);
+ if (imageRoot) initial.imageScene = createImageEditScene({ relativePath: "media/source.png", name: "Source", width: 768, height: 768 });
+ initial.assets = [Number.MAX_SAFE_INTEGER, 0].map((usedSeed, index) => ({
+ id: `seed-result-${index}`, name: `Seed result ${index}`, kind: "image", relativePath: `media/result-${index}.png`,
+ width: 768, height: 768, mimeType: "image/png", createdAt: initial.createdAt,
+ imageGeneration: { ...imageGenerationSnapshot(initial, "Submitted prompt", defaultGeneratorTemplate().id), usedSeed },
+ }));
+ initial.imageScene!.outputAssetId = "seed-result-0";
+ const current = setup(initial);
+ const seed = screen.getByLabelText("Used seed");
+ expect(seed).toHaveValue(String(Number.MAX_SAFE_INTEGER));
+ expect(seed).toHaveAttribute("readonly");
+ expect(seed).not.toBeDisabled();
+ fireEvent.click(screen.getByRole("button", { name: "Copy used seed" }));
+ await waitFor(() => expect(writeText).toHaveBeenLastCalledWith(String(Number.MAX_SAFE_INTEGER)));
+ fireEvent.click(screen.getByRole("button", { name: "View Seed result 1" }));
+ expect(screen.getByLabelText("Used seed")).toHaveValue("0");
+ fireEvent.click(screen.getByRole("button", { name: "Copy used seed" }));
+ await waitFor(() => expect(writeText).toHaveBeenLastCalledWith("0"));
+ expect(current().assets.map((asset) => asset.imageGeneration?.usedSeed)).toEqual([Number.MAX_SAFE_INTEGER, 0]);
+ writeText.mockRejectedValueOnce(new Error("Clipboard unavailable"));
+ fireEvent.click(screen.getByRole("button", { name: "Copy used seed" }));
+ await screen.findByText("Could not copy the seed. Select and copy it from the field.");
+});
+
+it("does not invent a used seed for an older random result or show one for drafts", () => {
+ const initial = parseProjectConfig(fixture);
+ initial.imageScene!.seed = -1;
+ const snapshot = imageGenerationSnapshot(initial, "Old prompt", defaultGeneratorTemplate().id);
+ initial.assets = [false, true].map((imageDraft, index) => ({ id: `old-${index}`, name: `Old ${index}`, kind: "image", imageDraft,
+ relativePath: `media/old-${index}.jpg`, mimeType: "image/jpeg", createdAt: initial.createdAt, imageGeneration: snapshot }));
+ initial.imageScene!.outputAssetId = "old-0";
+ setup(initial);
+ expect(screen.getByLabelText("Used seed")).toHaveValue("Not recorded");
+ expect(screen.getByRole("button", { name: "Copy used seed" })).toBeDisabled();
+ fireEvent.click(screen.getByRole("button", { name: "View Old 1" }));
+ expect(screen.queryByLabelText("Used seed")).not.toBeInTheDocument();
+});
+
it("hides placement and palette controls by model type while preserving boxes and palettes", () => {
const h3 = createGeneratorTemplate("Renamed H3");
const future = createGeneratorTemplate("Future generator", "future-model");
diff --git a/src/components/workspace/ImageEditor.tsx b/src/components/workspace/ImageEditor.tsx
index 1b27bb4..7169a77 100644
--- a/src/components/workspace/ImageEditor.tsx
+++ b/src/components/workspace/ImageEditor.tsx
@@ -28,6 +28,16 @@ import "../../styles/image-editor.css";
const MIN_IMAGE_ZOOM = 0.1;
const MAX_IMAGE_ZOOM = 8;
+function UsedImageSeed({ id, seed, onError }: { id: string; seed: number | undefined; onError: (message: string) => void }) {
+ return <PropRow label="Used seed" htmlFor={id}>
+ <input id={id} className="text-field" readOnly value={seed ?? "Not recorded"} />
+ <button type="button" className="icon-button" aria-label="Copy used seed" data-tooltip="Copy used seed" disabled={seed === undefined} onClick={async () => {
+ try { await navigator.clipboard.writeText(String(seed)); }
+ catch { onError("Could not copy the seed. Select and copy it from the field."); }
+ }}><Copy16 aria-hidden="true" /></button>
+ </PropRow>;
+}
+
export function ImageEditor({ config, folderPath, onChange: changeConfig, onGenerate, onCancel, workItems = [] }: {
config: ProjectConfig; folderPath: string; onChange: (update: ConfigUpdate) => void;
onGenerate: (template: GeneratorTemplate) => void; onCancel: (id: string) => Promise<void>; workItems?: readonly WorkItem[];
@@ -35,6 +45,9 @@ export function ImageEditor({ config, folderPath, onChange: changeConfig, onGene
const scene = useMemo(() => config.imageScene ?? createImageScene(config.brief.prompt), [config.imageScene, config.brief.prompt]);
const root = scene.nodes.find((node) => node.kind === "root")!;
const imageRoot = scene.rootType === "image";
+ const generatedImage = config.assets.find((asset) => asset.id === scene.outputAssetId && !asset.imageDraft && asset.imageGeneration);
+ const recordedSeed = generatedImage?.imageGeneration?.usedSeed ?? generatedImage?.imageGeneration?.scene.seed;
+ const usedSeed = recordedSeed !== undefined && recordedSeed >= 0 ? recordedSeed : undefined;
const editPlan = useMemo(() => {
if (!imageRoot) return null;
try { return { ...compileImageEdits(config), error: null }; }
@@ -595,6 +608,7 @@ export function ImageEditor({ config, folderPath, onChange: changeConfig, onGene
<PropSection title="Image generation" persistKey="image.generation">
<PropRow label="Steps" htmlFor={rootField("steps")}><input id={rootField("steps")} className="text-field" type="number" min="2" max="1000" value={scene.steps} onChange={(event) => { const value = Number(event.target.value); if (Number.isInteger(value) && value >= 2 && value <= 1000) commit({ ...scene, steps: value }); }} /></PropRow>
<PropRow label="Seed" htmlFor={rootField("seed")}><input id={rootField("seed")} className="text-field" type="number" min="-1" max={Number.MAX_SAFE_INTEGER} value={scene.seed} data-tooltip="-1 picks a random seed" onChange={(event) => { const value = Number(event.target.value); if (Number.isSafeInteger(value) && value >= -1) commit({ ...scene, seed: value }); }} /></PropRow>
+ {generatedImage && <UsedImageSeed id={rootField("used-seed")} seed={usedSeed} onError={setError} />}
<PropRow label="Aspect ratio" htmlFor={rootField("ratio")}><ComboBox id={rootField("ratio")} aria-label="Aspect ratio" value={config.settings.aspectRatio} options={["16:9", "9:16", "1:1", "4:5"].map((ratio) => ({ value: ratio, label: ratio }))} onChange={(value) => { const aspectRatio = value as ProjectConfig["settings"]["aspectRatio"]; onChange((current) => ({ ...current, settings: { ...current.settings, aspectRatio }, brief: { ...current.brief, aspectRatio } })); }} /></PropRow>
<PropRow label="Resolution" htmlFor={rootField("resolution")}><ComboBox id={rootField("resolution")} aria-label="Resolution" value={config.settings.resolution} options={[...new Set([...PROJECT_RESOLUTIONS, config.settings.resolution])].map((resolution) => { const size = outputDimensions(resolution, config.settings.aspectRatio); return { value: resolution, label: `${size.width} × ${size.height}` }; })} onChange={(value) => { const resolution = value as ProjectConfig["settings"]["resolution"]; onChange((current) => ({ ...current, settings: { ...current.settings, resolution }, brief: { ...current.brief, resolution } })); }} /></PropRow>
</PropSection>
@@ -606,6 +620,9 @@ export function ImageEditor({ config, folderPath, onChange: changeConfig, onGene
<TagEditor key={scene.style.mode} label={scene.style.mode === "photo" ? "Camera / lens" : "Art style"} value={scene.style.detail} suggestions={scene.style.mode === "photo" ? styleSuggestions.PhotoSuggestions : styleSuggestions.ArtSuggestions} onChange={(detail) => commit({ ...scene, style: { ...scene.style, detail } })} />
</PropSection>
</>}
+ {selected.kind === "root" && imageRoot && generatedImage && <PropSection title="Image generation" persistKey="image.generation">
+ <UsedImageSeed id={rootField("used-seed")} seed={usedSeed} onError={setError} />
+ </PropSection>}
{!isMiniMaxH3 && selected.kind !== "root" && <PropSection title="Placement (0–1000)" persistKey="image.placement">
<label className="image-check"><input type="checkbox" checked={Boolean(selected.box)} onChange={(event) => patchNode({ box: event.target.checked ? { x: 250, y: 250, width: 500, height: 500 } : null })} />Explicit placement</label>
{selected.box && (["x", "y", "width", "height"] as const).map((field) => <PropRow key={field} label={field === "x" ? "X" : field === "y" ? "Y" : field === "width" ? "Width" : "Height"} htmlFor={rootField(field)}>
diff --git a/src/lib/imageHistory.test.ts b/src/lib/imageHistory.test.ts
index d4c6571..9c724e8 100644
--- a/src/lib/imageHistory.test.ts
+++ b/src/lib/imageHistory.test.ts
@@ -91,8 +91,10 @@ describe("generated image history", () => {
const draft = drafted.assets.find((asset) => asset.imageDraft)!;
expect(draft.parentAssetId).toBe("original");
// Generating it keeps the family.
- const done = completeImageDraft(drafted, draft.id, { ...image(draft.id), imageGeneration: draft.imageGeneration });
+ const done = completeImageDraft(drafted, draft.id, { ...image(draft.id), imageGeneration: { ...draft.imageGeneration!, usedSeed: 91234 } });
expect(done.assets.find((asset) => asset.id === draft.id)).toMatchObject({ imageDraft: false, parentAssetId: "original" });
+ expect(done.assets.some((asset) => asset.imageDraft)).toBe(false);
+ expect(done.assets.find((asset) => asset.id === draft.id)!.imageGeneration!.usedSeed).toBe(91234);
expect(parseProjectConfig(JSON.parse(JSON.stringify(done))).assets).toEqual(done.assets);
// An imported file starts a family of its own.
config.imageScene = createImageEditScene({ relativePath: "media/imported/photo.png", name: "photo", width: 101, height: 77 });
diff --git a/src/lib/imageHistory.ts b/src/lib/imageHistory.ts
index d5dbcf1..9c1bbe1 100644
--- a/src/lib/imageHistory.ts
+++ b/src/lib/imageHistory.ts
@@ -76,7 +76,7 @@ export function createEmptyImage(config: ProjectConfig, generatorTemplateId?: st
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: "" });
+ const changed = draft && JSON.stringify({ ...draft.imageGeneration, prompt: "", usedSeed: undefined }) !== JSON.stringify({ ...result.imageGeneration, prompt: "", usedSeed: undefined });
// 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, ...(draft?.parentAssetId ? { parentAssetId: draft.parentAssetId } : {}) };
diff --git a/src/lib/project.ts b/src/lib/project.ts
index d896af6..ada6504 100644
--- a/src/lib/project.ts
+++ b/src/lib/project.ts
@@ -146,6 +146,7 @@ export const imageGenerationSnapshotSchema = z.object({
briefPrompt: z.string(),
prompt: z.string(),
generatorTemplateId: z.string().min(1),
+ usedSeed: z.number().int().min(0).max(Number.MAX_SAFE_INTEGER).optional(),
references: z.array(z.lazy(() => projectReferenceSchema)).max(100),
}).superRefine((snapshot, context) => {
const ids = new Set(snapshot.references.map((reference) => reference.id));
diff --git a/src/lib/workQueue.test.ts b/src/lib/workQueue.test.ts
index 04185d6..cc77567 100644
--- a/src/lib/workQueue.test.ts
+++ b/src/lib/workQueue.test.ts
@@ -58,6 +58,25 @@ const finish = async (queue: WorkQueue, id: string) => {
describe("image generation work", () => {
const template: GeneratorTemplate = { id: "image-test", name: "MiniMax H3", modelType: "minimax-h3", defaultSteps: 20, attention: "sage2", paths: { ...EMPTY_ENGINE_SETTINGS, transformer: "C:/h3.safetensors" } };
const imageProject = (): ProjectRecord => ({ folderPath: "C:/Image", config: createProjectConfig({ name: "Poster", prompt: "An ocean poster", generationType: "image", aspectRatio: "1:1", resolution: "768p", targetDurationSeconds: 60 }) });
+ it.each([-1, 0, Number.MAX_SAFE_INTEGER])("saves the exact submitted image seed without changing the authored seed (%s)", async (seed) => {
+ const { queue, saved } = setup();
+ const record = imageProject();
+ record.config.imageScene!.seed = seed;
+ const session = queue.project(record);
+ vi.mocked(invoke).mockResolvedValue({ relativePath: "media/generated/seed.jpg", width: 768, height: 768 });
+ queue.enqueueImage(session, template);
+ await waitFor(() => expect(enqueueSlopfabGeneration).toHaveBeenCalledOnce());
+ const request = vi.mocked(enqueueSlopfabGeneration).mock.calls[0][0];
+ expect(Number.isSafeInteger(request.seed)).toBe(true);
+ expect(request.seed).toBeGreaterThanOrEqual(0);
+ if (seed !== -1) expect(request.seed).toBe(seed);
+ expect(queue.getSnapshot()[0].settings.seed).toBe(request.seed);
+ await finish(queue, request.jobId);
+ const reopened = parseProjectConfig(JSON.parse(JSON.stringify(session.getSnapshot().config)));
+ expect(reopened.assets[0].imageGeneration).toMatchObject({ usedSeed: request.seed, scene: { seed } });
+ expect(reopened.imageScene!.seed).toBe(seed);
+ expect(saved.mock.calls.at(-1)![0].config.assets[0].imageGeneration!.usedSeed).toBe(request.seed);
+ });
it.each([false, true])("queues distinct images in order without changing the viewed image (draft: %s)", async (imageDraft) => {
const { queue } = setup();
const record = imageProject();
diff --git a/src/lib/workQueue.ts b/src/lib/workQueue.ts
index 5639fb7..add98d8 100644
--- a/src/lib/workQueue.ts
+++ b/src/lib/workQueue.ts
@@ -22,6 +22,14 @@ import { prepareReferenceVideos, releaseReferenceVideos } from "./referenceVideo
export type WorkStatus = "queued" | "preparing" | "generating" | "encoding" | "completed" | "failed" | "cancelled";
export interface GenerationSubmission { job: GenerationJob; request: SlopfabGenerationRequest; snapshot: string }
+
+function imageGenerationSeed(seed: number): number {
+ if (seed !== -1) return seed;
+ // Resolve before submission so history stores exactly what the engine uses.
+ // Keep all 53 bits exactly representable in JSON and the editable seed field.
+ const [high, low] = crypto.getRandomValues(new Uint32Array(2));
+ return (high & 0x1fffff) * 0x100000000 + low;
+}
export interface WorkItem {
imageAssetId?: string | null;
imageDraftId?: string;
@@ -232,11 +240,11 @@ export class WorkQueue {
...(edit ? { imageEdit: { sourceRelativePath: edit.source.relativePath, edits: edit.edits.map(({ references, ...step }) => ({
...step, referencePaths: referencePaths(references), refmods: referenceRefmodInputs(session.record.folderPath, references),
})) } } : {}),
- canvasWidth: width, canvasHeight: height, steps: generationStepsWithLoras(scene.steps, config), seed: scene.seed,
+ canvasWidth: width, canvasHeight: height, steps: generationStepsWithLoras(scene.steps, config), seed: imageGenerationSeed(scene.seed),
referencePaths: referencePaths(references),
refmods: referenceRefmodInputs(session.record.folderPath, references),
};
- this.work.set(id, { id, image: true, imageDraftId, imageParentId, 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.work.set(id, { id, image: true, imageDraftId, imageParentId, imageGeneration: { ...imageGenerationSnapshot(config, edit ? imageEditDebugPrompt(edit.edits) : prompt, template.id), usedSeed: request.seed }, 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", imageAssetId: scene.outputAssetId, 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 } }];