AI media harness for planning, generating, and editing locally
TypeScript
Add character sheet template
Bitti2d0d84c6a683
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.mdindex d5120ef..9bbb1ef 100644--- a/RELEASE_NOTES.md+++ b/RELEASE_NOTES.md@@ -4,6 +4,7 @@ This alpha update adds DMAD LoRA support, resumable model downloads, and improve## What's new+- Generate a character sheet from the Image toolbar's Template menu: four matching views of the selected image, combined into one PNG in the image bar.- Continue scenes from a selected scene's saved latents, with adjustable overlap and a choice of beginning or end. This replaces Previous scene in First & last frame.- Export any reference with images, a video or a sound as a refmod `.safetensors` file from References. Exported refmods can be attached to other references and projects.- Copying or cutting prompts preserves reference chips when pasted into other prompt fields.diff --git a/src-tauri/src/app.rs b/src-tauri/src/app.rsindex 8e628a3..8a8bd84 100644--- a/src-tauri/src/app.rs+++ b/src-tauri/src/app.rs@@ -187,6 +187,9 @@ pub fn run() {.plugin(tauri_plugin_process::init()).invoke_handler(tauri::generate_handler![commands::artifacts::save_generated_image,+ commands::character_sheet::save_character_sheet_view,+ commands::character_sheet::combine_character_sheet,+ commands::character_sheet::discard_character_sheet_views,commands::artifacts::open_image_source,commands::artifacts::export_generated_image,app_updater_mode,diff --git a/src-tauri/src/commands/character_sheet.rs b/src-tauri/src/commands/character_sheet.rsnew file mode 100644index 0000000..6583e22--- /dev/null+++ b/src-tauri/src/commands/character_sheet.rs@@ -0,0 +1,169 @@+use crate::media::artifacts::generated_file_stem;+use crate::project::paths::ProjectRoot;+use crate::rendered;+use image::{ImageEncoder, RgbaImage};++fn cache_directory(sheet_id: &str) -> Result<String, String> {+ Ok(format!(+ "cache/character-sheets/{}",+ generated_file_stem(sheet_id)?+ ))+}++#[tauri::command]+pub(crate) fn save_character_sheet_view(+ folder_path: String,+ sheet_id: String,+ job_id: String,+ index: usize,+) -> Result<(), String> {+ let summary = rendered::summary(&job_id).ok_or("The character view is no longer in memory.")?;+ if summary.frame_count != 1 {+ return Err("Expected one character view.".into());+ }+ let pixels = rendered::frame(&job_id, 0)?.ok_or("The character view has no pixels.")?;+ write_view(+ &folder_path,+ &sheet_id,+ index,+ summary.width,+ summary.height,+ &pixels,+ )+}++fn write_view(+ folder: &str,+ sheet_id: &str,+ index: usize,+ width: u32,+ height: u32,+ pixels: &[u8],+) -> Result<(), String> {+ if index >= 4+ || width == 0+ || width > 2048+ || height == 0+ || height > 8192+ || pixels.len() != width as usize * height as usize * 4+ {+ return Err("Invalid character sheet view dimensions or pixels.".into());+ }+ let root = ProjectRoot::open(folder)?;+ let directory = root.directory(&cache_directory(sheet_id)?)?;+ let mut png = Vec::new();+ image::codecs::png::PngEncoder::new(&mut png)+ .write_image(pixels, width, height, image::ExtendedColorType::Rgba8)+ .map_err(|error| error.to_string())?;+ crate::storage::atomic::write_atomically(&directory.join(format!("{index}.png")), &png)+}++/// The four independent renders are assembled losslessly, in view order.+#[tauri::command]+pub(crate) fn combine_character_sheet(+ folder_path: String,+ sheet_id: String,+) -> Result<super::artifacts::GeneratedImageFile, String> {+ let root = ProjectRoot::open(&folder_path)?;+ let directory = cache_directory(&sheet_id)?;+ let mut sheet: Option<RgbaImage> = None;+ for index in 0..4 {+ let path = root.existing(&format!("{directory}/{index}.png"))?;+ let (width, height) = image::image_dimensions(&path).map_err(|error| error.to_string())?;+ if width == 0 || width > 2048 || height == 0 || height > 8192 {+ return Err("Invalid character sheet view dimensions.".into());+ }+ let canvas = sheet.get_or_insert_with(|| RgbaImage::new(width * 4, height));+ if canvas.width() != width * 4 || canvas.height() != height {+ return Err("Character sheet views must have matching dimensions.".into());+ }+ let view = image::open(path)+ .map_err(|error| error.to_string())?+ .to_rgba8();+ image::imageops::replace(canvas, &view, i64::from(index * width), 0);+ }+ let sheet = sheet.ok_or("The character sheet has no views.")?;+ super::artifacts::write_generated_png_frame(+ &folder_path,+ &sheet_id,+ sheet.width(),+ sheet.height(),+ sheet.as_raw(),+ )+}++#[tauri::command]+pub(crate) fn discard_character_sheet_views(+ folder_path: String,+ sheet_id: String,+) -> Result<(), String> {+ let root = ProjectRoot::open(&folder_path)?;+ let directory = cache_directory(&sheet_id)?;+ if root.path().join(&directory).exists() {+ // Canonical containment is checked before removing the job's own cache.+ std::fs::remove_dir_all(root.existing(&directory)?).map_err(|error| error.to_string())?;+ }+ Ok(())+}++#[cfg(test)]+mod tests {+ use super::*;++ fn project_folder() -> tempfile::TempDir {+ let folder = tempfile::tempdir().unwrap();+ crate::project::storage::write_project(folder.path(), &crate::tests::created_fixture())+ .unwrap();+ folder+ }++ #[test]+ fn character_sheet_combines_four_views_in_order_and_cleans_only_its_cache() {+ let folder = project_folder();+ let path = folder.path().to_string_lossy().into_owned();+ let colors = [+ [255, 0, 0, 255],+ [0, 255, 0, 255],+ [0, 0, 255, 255],+ [255, 255, 0, 255],+ ];+ for (index, color) in colors.iter().enumerate() {+ write_view(&path, "sheet-test", index, 2, 3, &color.repeat(6)).unwrap();+ }+ write_view(&path, "other-sheet", 0, 2, 3, &colors[0].repeat(6)).unwrap();+ let saved = combine_character_sheet(path.clone(), "sheet-test".into()).unwrap();+ assert_eq!((saved.width, saved.height), (8, 3));+ let image = image::open(folder.path().join(&saved.relative_path))+ .unwrap()+ .to_rgba8();+ for (index, color) in colors.iter().enumerate() {+ assert_eq!(image.get_pixel(index as u32 * 2, 1).0, *color);+ }+ discard_character_sheet_views(path.clone(), "sheet-test".into()).unwrap();+ assert!(!folder+ .path()+ .join("cache/character-sheets/sheet-test")+ .exists());+ assert!(folder+ .path()+ .join("cache/character-sheets/other-sheet/0.png")+ .exists());+ assert!(folder.path().join(saved.relative_path).exists());+ assert!(discard_character_sheet_views(path, "../other-sheet".into()).is_err());+ }++ #[test]+ fn character_sheet_rejects_missing_mismatched_and_oversized_views() {+ let folder = project_folder();+ let path = folder.path().to_string_lossy().into_owned();+ assert!(write_view(&path, "sheet", 4, 1, 1, &[0; 4]).is_err());+ assert!(write_view(&path, "sheet", 0, 2049, 1, &[0; 4]).is_err());+ write_view(&path, "sheet", 0, 1, 1, &[0; 4]).unwrap();+ assert!(combine_character_sheet(path.clone(), "sheet".into()).is_err());+ for index in 1..4 {+ write_view(&path, "sheet", index, 2, 1, &[0; 8]).unwrap();+ }+ assert!(combine_character_sheet(path, "sheet".into()).is_err());+ assert!(!folder.path().join("media/generated/sheet.png").exists());+ }+}diff --git a/src-tauri/src/commands/mod.rs b/src-tauri/src/commands/mod.rsindex d6a4934..3b18b4a 100644--- a/src-tauri/src/commands/mod.rs+++ b/src-tauri/src/commands/mod.rs@@ -1,6 +1,7 @@pub(crate) mod agent;pub(crate) mod artifacts;pub(crate) mod binary;+pub(crate) mod character_sheet;pub(crate) mod diagnostics;pub(crate) mod generation;pub(crate) mod media;diff --git a/src/components/ImageProject.integration.test.tsx b/src/components/ImageProject.integration.test.tsxindex 6d52741..7dc5984 100644--- a/src/components/ImageProject.integration.test.tsx+++ b/src/components/ImageProject.integration.test.tsx@@ -23,6 +23,27 @@ vi.mock("@tauri-apps/api/event", () => ({ listen: vi.fn(async () => () => undefiafterEach(() => { cleanup(); localStorage.clear(); vi.restoreAllMocks(); });const record = (): ProjectRecord => ({ folderPath: "D:/Images", config: parseProjectConfig(fixture) });+it("runs the character sheet template on the selected image and requires an image file", () => {+ vi.spyOn(persistence, "isTauri").mockReturnValue(true);+ vi.spyOn(persistence, "readMediaFileUrl").mockResolvedValue(null);+ const template = { id: "test", name: "Test", modelType: "minimax-h3" as const, defaultSteps: 20, attention: "sage2" as const, paths: { ...EMPTY_ENGINE_SETTINGS, transformer: "D:/h3.safetensors" } };+ saveGeneratorTemplateSettings({ defaultTemplateId: "test", templates: [template] });+ const project = record();+ project.config.assets = ["First", "Selected"].map((id) => ({ id, name: id, kind: "image", relativePath: `media/${id}.png`, mimeType: "image/png", createdAt: project.config.createdAt }));+ const queue = new WorkQueue(vi.fn(async (record) => record));+ const generate = vi.spyOn(queue, "enqueueCharacterSheet").mockImplementation(() => undefined);+ render(<ProjectWorkspace project={project} workQueue={queue} onBack={vi.fn()} onSave={vi.fn()} />);+ const toolbar = within(screen.getByRole("toolbar", { name: "Image tools" }));+ expect(toolbar.getByRole("button", { name: "Template" })).toBeDisabled();+ fireEvent.click(screen.getByRole("button", { name: "View Selected" }));+ toolbar.getByRole("button", { name: "Template" }).focus();+ fireEvent.click(toolbar.getByRole("button", { name: "Template" }));+ fireEvent.click(screen.getByRole("menuitem", { name: "Character sheet" }));+ expect(generate).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({ id: "test" }), "Selected");+ expect(screen.queryByRole("menu", { name: "Image templates" })).not.toBeInTheDocument();+ expect(toolbar.getByRole("button", { name: "Template" })).toHaveFocus();+});+it.each(["Create Scene", "Create Reference"])("opens and saves the item created by %s in the image bar", async (action) => {const project = record();project.config.assets = [{ id: "poster", name: "Poster", kind: "image", relativePath: "media/generated/poster.png", mimeType: "image/png", createdAt: project.config.createdAt }];diff --git a/src/components/ProjectWorkspace.tsx b/src/components/ProjectWorkspace.tsxindex fcf40a8..d4e1a75 100644--- a/src/components/ProjectWorkspace.tsx+++ b/src/components/ProjectWorkspace.tsx@@ -286,7 +286,7 @@ export function ProjectWorkspace({ project, initialView, runtime = null, onBack,<ProjectStatusSlot.Provider value={statusSlot}><div className={`project-body${agentOpen ? " project-body--agent" : ""}`} style={agentPane.style}><div id={`${panelId}-view`} role="tabpanel" aria-label={VIEW_LABELS[view]} className={`project-content project-content--${view}`}>- {view === "editor" && <ImageEditor config={config} folderPath={project.folderPath} onChange={changeConfig} onGenerate={(template) => queue.enqueueImage(session, template)} onCancel={(id) => queue.cancel(id)} workItems={projectItems.filter((item) => item.kind === "image")} onOpenGenerator={(jobId) => { setSelectedGenerationJobId(jobId); setView("generator"); }} onOpenReferences={() => setView("references")} />}+ {view === "editor" && <ImageEditor config={config} folderPath={project.folderPath} onChange={changeConfig} onGenerate={(template) => queue.enqueueImage(session, template)} onGenerateCharacterSheet={(template, sourceId) => queue.enqueueCharacterSheet(session, template, sourceId)} onCancel={(id) => queue.cancel(id)} workItems={projectItems.filter((item) => item.kind === "image")} onOpenGenerator={(jobId) => { setSelectedGenerationJobId(jobId); setView("generator"); }} onOpenReferences={() => setView("references")} />}{view === "timeline" && <TimelineView config={config} openSceneId={selectedGenerationJobId} folderPath={project.folderPath} generationCompletionTimes={generationCompletionTimes} onChange={changeConfig} onMeasured={recordMeasurement} onOpenGenerator={(jobId) => { setSelectedGenerationJobId(jobId); setView("generator"); }} />}{view === "generator" && <GeneratorView onGenerate={(submissions) => queue.enqueue(session, submissions)} onCancelGeneration={(ids) => queue.cancelScenes(session, ids)} cancellingJobIds={cancellingJobIds} config={config} folderPath={project.folderPath} generationCompletionTimes={generationCompletionTimes} runtime={runtime?.slopfab ?? null} onRuntimeChange={onGeneratorRuntimeChange} onChange={changeConfig} selectedJobId={selectedGenerationJobId} onSelectedJobChange={setSelectedGenerationJobId} onOpenTimeline={() => setView("timeline")} />}{view === "references" && <ReferencesView config={config} folderPath={project.folderPath} onChange={changeConfig} onRegenerateIcon={(id) => queue.regenerateReferenceIcon(session, id)} onExportRefmod={(id, outputPath) => queue.exportReferenceRefmod(session, id, outputPath)} onGenerateBuiltinIcons={() => queue.generateBuiltinReferenceIcons(session)} onRegenerateBuiltinIcon={(id) => queue.regenerateBuiltinReferenceIcon(session, id)} pendingBuiltinIconIds={queue.pendingBuiltinIconIds()} pendingIconIds={new Set(config.references.filter((reference) => queue.isReferenceIconPending(session, reference.id)).map((reference) => reference.id))} onOpenGenerator={(jobId) => { setSelectedGenerationJobId(jobId); setView("generator"); }} />}diff --git a/src/components/workspace/ImageEditor.tsx b/src/components/workspace/ImageEditor.tsxindex a3b4658..1228e4c 100644--- a/src/components/workspace/ImageEditor.tsx+++ b/src/components/workspace/ImageEditor.tsx@@ -22,7 +22,7 @@ import { applyImageCommand } from "../../lib/imageCommands";import { copyImageNode, getImageNodeClipboard, pasteImageNode, subscribeImageNodeClipboard } from "../../lib/imageNodeClipboard";import { HierarchyContextMenu } from "./HierarchyContextMenu";import { useShortcut } from "../../lib/commands";-import { ComboBox, InfoBar, ItemHeader, PaneHeader, ProgressBar, PropRow, PropSection, Splitter, tooltipProps, usePaneSize } from "../ui";+import { ComboBox, InfoBar, ItemHeader, PaneHeader, ProgressBar, PropRow, PropSection, Splitter, tooltipProps, useContextMenu, usePaneSize } from "../ui";import "../../styles/image-editor.css";const MIN_IMAGE_ZOOM = 0.1;@@ -38,9 +38,10 @@ function UsedImageSeed({ id, seed, onError }: { id: string; seed: number | undef</PropRow>;}-export function ImageEditor({ config, folderPath, onChange: changeConfig, onGenerate, onCancel, onOpenGenerator, onOpenReferences, workItems = [] }: {+export function ImageEditor({ config, folderPath, onChange: changeConfig, onGenerate, onGenerateCharacterSheet, onCancel, onOpenGenerator, onOpenReferences, workItems = [] }: {config: ProjectConfig; folderPath: string; onChange: (update: ConfigUpdate) => void;onGenerate: (template: GeneratorTemplate) => void; onCancel: (id: string) => Promise<void>; workItems?: readonly WorkItem[];+ onGenerateCharacterSheet?: (template: GeneratorTemplate, sourceId: string) => void;onOpenGenerator?: (jobId: string) => void;onOpenReferences?: () => void;}) {@@ -62,6 +63,7 @@ export function ImageEditor({ config, folderPath, onChange: changeConfig, onGeneconst [treeDrop, setTreeDrop] = useState<{ id: string; placement: "before" | "inside" | "after" } | null>(null);const [contextMenu, setContextMenu] = useState<{ x: number; y: number } | null>(null);const [imageMenu, setImageMenu] = useState<{ id: string | null; x: number; y: number; inFamily: boolean; source: "bar" | "canvas" } | null>(null);+ const templateMenu = useContextMenu();const imageResults = useRef<HTMLDivElement>(null);const [renaming, setRenaming] = useState<{ id: string; value: string } | null>(null);const renameEnding = useRef(false);@@ -542,7 +544,17 @@ export function ImageEditor({ config, folderPath, onChange: changeConfig, onGeneonChange={(value) => { if (value === "fit") fit(); else zoomTo(Number(value)); }}/></div>+ <div className="image-tools__end">+ <button type="button" className="secondary-button" aria-haspopup="menu" aria-expanded={templateMenu.isOpen}+ disabled={!isTauri() || !onGenerateCharacterSheet || !output || (!output.relativePath && !output.sourcePath) || Boolean(active) || !template || !templateUsable(template)}+ onClick={(event) => templateMenu.open(event.currentTarget, [{ label: "Character sheet", icon: <Image16 />,+ onSelect: () => attempt(() => onGenerateCharacterSheet?.(template!, output!.id)),+ }], { "aria-label": "Image templates", placement: "bottom-end" })}>+ Template <ChevronDown14 aria-hidden="true" />+ </button>+ </div></div>+ {templateMenu.element}<aside ref={hierarchy} className="image-tree" aria-label="Image hierarchy" onContextMenu={(event) => { if ((event.target as HTMLElement).closest("input, textarea, [contenteditable=true]")) return; event.preventDefault(); setSelection(root.id); setContextMenu({ x: event.clientX, y: event.clientY }); }} onKeyDown={treeKeys}>{/* Undo and Redo live in the title bar; Ctrl+Z / Ctrl+Y still step the image edits here. */}<PaneHeader title="Scene" />diff --git a/src/lib/characterSheet.test.ts b/src/lib/characterSheet.test.tsnew file mode 100644index 0000000..1ee5f47--- /dev/null+++ b/src/lib/characterSheet.test.ts@@ -0,0 +1,143 @@+// @vitest-environment jsdom+import { waitFor } from "@testing-library/react";+import { invoke } from "@tauri-apps/api/core";+import { listen } from "@tauri-apps/api/event";+import { afterEach, beforeEach, expect, it, vi } from "vitest";+import { releaseRendered } from "./generatedVideo";+import { createProjectConfig, parseProjectConfig, type ProjectRecord } from "./project";+import { cancelSlopfabGeneration, enqueueSlopfabGeneration, resolveSlopfabPlan } from "./runtime";+import { EMPTY_ENGINE_SETTINGS, type GeneratorTemplate } from "./settings";+import { WorkQueue } from "./workQueue";++vi.mock("@tauri-apps/api/core", () => ({ invoke: vi.fn() }));+vi.mock("@tauri-apps/api/event", () => ({ listen: vi.fn() }));+vi.mock("./generatedVideo", () => ({ releaseRendered: vi.fn(async () => true), saveGeneratedScene: vi.fn() }));+vi.mock("./runtime", () => ({ cancelSlopfabGeneration: vi.fn(), enqueueSlopfabGeneration: vi.fn(), resolveSlopfabPlan: vi.fn() }));+const handlers = new Map<string, (event: { payload: unknown }) => void>();+let stop: (() => void) | undefined;+const template: GeneratorTemplate = { id: "h3", name: "H3", modelType: "minimax-h3", defaultSteps: 20, attention: "sage2", paths: { ...EMPTY_ENGINE_SETTINGS, transformer: "C:/h3.safetensors" } };+const result = { relativePath: "media/generated/sheet.png", width: 3072, height: 960 };+beforeEach(() => {+ localStorage.clear(); vi.resetAllMocks(); handlers.clear();+ Object.assign(window, { __TAURI_INTERNALS__: {} });+ vi.mocked(listen).mockImplementation((async (name: string, handler: (event: { payload: unknown }) => void) => { handlers.set(name, handler); return () => {}; }) as typeof listen);+ vi.mocked(resolveSlopfabPlan).mockResolvedValue({ alignedFrames: 1, canvasWidth: 768, canvasHeight: 960 } as Awaited<ReturnType<typeof resolveSlopfabPlan>>);+ vi.mocked(enqueueSlopfabGeneration).mockResolvedValue(undefined);+ vi.mocked(cancelSlopfabGeneration).mockResolvedValue(true);+ vi.mocked(releaseRendered).mockResolvedValue(true);+ vi.mocked(invoke).mockImplementation(async (command) => command === "combine_character_sheet" ? result : undefined);+});+afterEach(() => { stop?.(); delete (window as unknown as Record<string, unknown>).__TAURI_INTERNALS__; });+function setup() {+ const config = createProjectConfig({ name: "Character", prompt: "A character", generationType: "image", aspectRatio: "1:1", resolution: "768p", targetDurationSeconds: 60 });+ config.assets = [{ id: "source", kind: "image", name: "Hero", relativePath: "media/hero.png", mimeType: "image/png", createdAt: config.createdAt }];+ config.imageScene!.outputAssetId = "source";+ const writer = vi.fn(async (record: ProjectRecord) => record);+ const queue = new WorkQueue(writer);+ stop = queue.start();+ const session = queue.project({ folderPath: "C:/Character", config });+ return { queue, session, writer };+}+const emit = (state: string, jobId: string, detail = state) => handlers.get("slopfab-job")?.({ payload: { state, jobId, detail } });+async function requestAt(index: number) {+ await waitFor(() => expect(enqueueSlopfabGeneration).toHaveBeenCalledTimes(index + 1));+ return vi.mocked(enqueueSlopfabGeneration).mock.calls[index][0];+}++it.each([false, true])("generates four source-conditioned views and adds only the combined sheet (source changed: %s)", async (changed) => {+ const { queue, session } = setup();+ const original = structuredClone(session.getSnapshot().config);+ queue.enqueueCharacterSheet(session, template, "source");+ queue.enqueueCharacterSheet(session, template, "source");+ expect(queue.getSnapshot()).toHaveLength(1);+ const id = queue.getSnapshot()[0].id;+ let seed: number | undefined;+ for (let index = 0; index < 4; index++) {+ const request = await requestAt(index);+ seed ??= request.seed;+ expect(request).toMatchObject({ stillImage: true, frames: 1, referencePaths: ["C:/Character/media/hero.png"], seed });+ expect(request.imageEdit).toBeUndefined();+ expect(request.prompt).toContain(["frontal close-up portrait", "full body front view", "full body side view", "full body back view"][index]);+ expect(request.prompt).toContain("clothing, footwear, accessories");+ expect(request.prompt).toContain("<Picture 1>");+ expect(request.prompt).not.toContain("A still photograph");+ expect(session.getSnapshot().config.assets).toEqual(original.assets);+ if (changed && index === 0) session.update((current) => ({ ...current, imageScene: { ...current.imageScene!, nodes: current.imageScene!.nodes.map((node) => ({ ...node, description: "Changed during generation" })) } }));+ emit("framesReady", request.jobId);+ if (index < 3) {+ await waitFor(() => expect(releaseRendered).toHaveBeenCalledWith(request.jobId));+ expect(invoke).toHaveBeenCalledWith("save_character_sheet_view", { folderPath: "C:/Character", sheetId: id, jobId: request.jobId, index });+ }+ }+ await waitFor(() => expect(queue.getSnapshot()[0].status).toBe("completed"));+ const reopened = parseProjectConfig(JSON.parse(JSON.stringify(session.getSnapshot().config)));+ expect(reopened.assets).toHaveLength(2);+ expect(reopened.assets[0]).toEqual(original.assets[0]);+ expect(reopened.assets[1]).toMatchObject({ id, name: "Character sheet - Hero", mimeType: "image/png", ...result, imageGeneration: { usedSeed: seed } });+ expect(reopened.assets[1].parentAssetId).toBeUndefined();+ expect(reopened.imageScene!.outputAssetId).toBe(changed ? "source" : id);+ expect(reopened.generationJobs).toEqual(original.generationJobs);+ expect(reopened.timeline).toEqual(original.timeline);+ await waitFor(() => expect(invoke).toHaveBeenCalledWith("discard_character_sheet_views", { folderPath: "C:/Character", sheetId: id }));+});++it.each(["cancelled", "failed"])("discards partial views after the second render is %s", async (state) => {+ const { queue, session } = setup();+ queue.enqueueCharacterSheet(session, template, "source");+ const id = queue.getSnapshot()[0].id;+ emit("framesReady", (await requestAt(0)).jobId);+ const second = await requestAt(1);+ if (state === "cancelled") {+ await queue.cancel(id);+ expect(cancelSlopfabGeneration).toHaveBeenCalledWith(second.jobId);+ }+ emit(state, second.jobId, "Stopped second view");+ await waitFor(() => expect(queue.getSnapshot()[0].status).toBe(state));+ expect(session.getSnapshot().config.assets).toHaveLength(1);+ expect(enqueueSlopfabGeneration).toHaveBeenCalledTimes(2);+ expect(invoke).not.toHaveBeenCalledWith("combine_character_sheet", expect.anything());+ expect(invoke).toHaveBeenCalledWith("discard_character_sheet_views", { folderPath: "C:/Character", sheetId: id });+ expect(releaseRendered).toHaveBeenCalledWith(second.jobId);+});++it("keeps the finished sheet available when project saving fails and retries without regenerating", async () => {+ const { queue, session, writer } = setup();+ queue.enqueueCharacterSheet(session, template, "source");+ const id = queue.getSnapshot()[0].id;+ for (let index = 0; index < 4; index++) {+ const request = await requestAt(index);+ if (index === 3) writer.mockRejectedValueOnce(new Error("Disk full"));+ emit("framesReady", request.jobId);+ }+ await waitFor(() => expect(queue.getSnapshot()[0]).toMatchObject({ status: "failed", needsSave: true }));+ expect(session.getSnapshot().config.assets).toHaveLength(2);+ await queue.retrySave(id);+ expect(queue.getSnapshot()[0]).toMatchObject({ status: "completed", needsSave: false });+ expect(enqueueSlopfabGeneration).toHaveBeenCalledTimes(4);+});++it("rejects an empty source without queuing work", () => {+ const { queue, session } = setup();+ session.update((current) => ({ ...current, assets: current.assets.map((asset) => ({ ...asset, relativePath: null })) }));+ expect(() => queue.enqueueCharacterSheet(session, template, "source")).toThrow("saved file");+ expect(queue.getSnapshot()).toHaveLength(0);+});++it("does not publish a partial result when combining fails and lets the next job run", async () => {+ const { queue, session } = setup();+ vi.mocked(invoke).mockImplementation(async (command) => {+ if (command === "combine_character_sheet") throw new Error("Could not combine views");+ });+ queue.enqueueCharacterSheet(session, template, "source");+ const id = queue.getSnapshot()[0].id;+ session.update((current) => ({ ...current, assets: [...current.assets, { ...current.assets[0], id: "another", name: "Another" }] }));+ queue.enqueueCharacterSheet(session, template, "another");+ for (let index = 0; index < 4; index++) emit("framesReady", (await requestAt(index)).jobId);+ await waitFor(() => expect(queue.getSnapshot()[0]).toMatchObject({ status: "failed", error: "Could not combine views" }));+ expect(session.getSnapshot().config.assets.map((asset) => asset.id)).toEqual(["source", "another"]);+ expect(invoke).toHaveBeenCalledWith("discard_character_sheet_views", { folderPath: "C:/Character", sheetId: id });+ const next = await requestAt(4);+ await queue.cancel(queue.getSnapshot()[1].id);+ emit("cancelled", next.jobId);+ await waitFor(() => expect(queue.getSnapshot()[1].status).toBe("cancelled"));+});diff --git a/src/lib/characterSheet.ts b/src/lib/characterSheet.tsnew file mode 100644index 0000000..5340798--- /dev/null+++ b/src/lib/characterSheet.ts@@ -0,0 +1,27 @@+import { createImageScene } from "./imageScene";+import { compileImagePrompt } from "./imagePrompt";+import type { ProjectAsset, ProjectConfig, ProjectReference } from "./project";++export const CHARACTER_SHEET_VIEWS = [+ { label: "Frontal portrait", description: "A frontal close-up portrait, showing the head and shoulders, looking straight at the camera." },+ { label: "Full body front", description: "A full body front view, facing directly toward the camera, standing in a neutral pose. Show the entire figure from head to feet without cropping." },+ { label: "Full body side", description: "A full body side view, in strict left-facing profile, standing in a neutral pose. Show the entire figure from head to feet without cropping." },+ { label: "Full body back", description: "A full body back view, facing directly away from the camera, standing in a neutral pose. Show the entire figure from head to feet without cropping." },+] as const;++export function characterSheetPrompts(config: ProjectConfig, source: ProjectAsset): string[] {+ const reference: ProjectReference = {+ id: "character-sheet-source", kind: "text", name: source.name,+ description: "The character in the source image. Preserve the exact identity, facial features, body proportions, skin tone, hairstyle and hair color, clothing, footwear, accessories, materials and colors. Preserve the source's visual medium and rendering style. Do not redesign or change the outfit.",+ intendedUse: ["character"], createdAt: source.createdAt,+ images: [{ id: "character-sheet-source-image", name: source.name, relativePath: source.relativePath, sourcePath: source.sourcePath }],+ };+ return CHARACTER_SHEET_VIEWS.map((view) => {+ const scene = createImageScene(`Create a character reference view of @[ref:${reference.id}]. ${view.description} Keep the same clothing, appearance and every identifying detail from the source image. Use a plain light gray background, soft even studio lighting, and no text, labels, borders, additional characters or multiple views. Match the source image's visual style.`);+ scene.style = { mode: "art", medium: "the same visual medium and rendering style as <Picture 1>", aesthetics: "", lighting: "", detail: "" };+ return compileImagePrompt({+ ...config, settings: { ...config.settings, defaultLook: null }, references: [reference],+ imageScene: scene,+ }).prompt;+ });+}diff --git a/src/lib/workQueue.ts b/src/lib/workQueue.tsindex 022ec0f..e0072f5 100644--- a/src/lib/workQueue.ts+++ b/src/lib/workQueue.ts@@ -3,6 +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 { CHARACTER_SHEET_VIEWS, characterSheetPrompts } from "./characterSheet";import { completeImageDraft, imageFamilyRoot, imageGenerationSnapshot, saveImageDraft } from "./imageHistory";import type { ImageGenerationSnapshot } from "./project";import { outputDimensions } from "./export";@@ -56,6 +57,10 @@ export interface WorkItem {settings: { frames: number; steps: number; seed: number; canvasWidth: number; canvasHeight: number };}interface PendingWork {+ characterSheet?: {+ prompts: string[]; sourceId: string; name: string; index: number;+ ready?: { resolve: () => void; reject: (reason: Error) => void };+ };outputFrames?: number;continuationSegments?: SceneMediaSegment[];imageDraftId?: string;@@ -257,6 +262,38 @@ export class WorkQueue {settings: { frames: 1, steps: request.steps, seed: request.seed, canvasWidth: width, canvasHeight: height } }];this.publish(); this.icons.yieldToVideo(); void this.pump();}+ enqueueCharacterSheet(session: ProjectSession, template: GeneratorTemplate, sourceId: string) {+ if (!isTauri()) throw new Error("Character sheet generation requires the desktop app.");+ if (template.mode === "animate") throw new Error("Choose a prompt generator for the character sheet.");+ const current = session.getSnapshot().config;+ const source = current.assets.find((asset) => asset.id === sourceId && asset.kind === "image");+ if (!source || (!source.relativePath && !source.sourcePath)) throw new Error("Select an image with a saved file first.");+ const projectKey = projectQueueKey(session.record);+ if (this.items.some((item) => item.projectKey === projectKey && item.kind === "image" && item.imageAssetId === sourceId && isWorkActive(item))) return;+ const config = structuredClone({ ...current, providerSettings: { ...current.providerSettings,+ slopfab: engineProviderSetting(template.paths, current.providerSettings.slopfab, template.attention, template.loras, "prompt", template.additionalSafetensors, false, template.sources) } });+ const prompts = characterSheetPrompts(config, source);+ // Portrait panels leave room for head-to-toe views. Bound each panel so+ // the four-column PNG remains within the image editor's 8192px limit.+ const size = outputDimensions(config.settings.resolution, "4:5");+ const width = Math.min(2048, size.width);+ const height = Math.round(width * size.height / size.width);+ const id = `character-sheet-${crypto.randomUUID()}`;+ let finish!: () => void;+ const done = new Promise<void>((resolve) => { finish = resolve; });+ const request: SlopfabGenerationRequest = { jobId: `${id}-view-1`, stillImage: true, frames: 1, prompt: prompts[0],+ canvasWidth: width, canvasHeight: height, steps: generationStepsWithLoras(current.imageScene?.steps ?? template.defaultSteps, config),+ seed: imageGenerationSeed(current.imageScene?.seed ?? -1), referencePaths: [projectItemPath(session.record.folderPath, source)!] };+ this.work.set(id, { id, image: true, characterSheet: { prompts, sourceId, name: `Character sheet - ${source.name}`, index: 0 },+ imageGeneration: { ...imageGenerationSnapshot(config, prompts.join("\n\n"), template.id), usedSeed: request.seed },+ session, sceneId: current.imageScene?.nodes[0].id ?? "image-root", config, snapshot: JSON.stringify(current.imageScene),+ request, submitted: false, cancelled: false, done, finish });+ this.items = [...this.items, { id, kind: "image", imageAssetId: sourceId, projectKey, folderPath: session.record.folderPath, projectName: config.name,+ sceneId: this.work.get(id)!.sceneId, title: `Character sheet · ${source.name}`, submittedAt: new Date().toISOString(),+ status: "queued", progress: 0, detail: "Waiting to generate character sheet", error: null, completionAt: null, cancelling: false, needsSave: false,+ settings: { frames: 4, steps: request.steps, seed: request.seed, canvasWidth: width, canvasHeight: height } }];+ this.publish(); this.icons.yieldToVideo(); void this.pump();+ }/** Queues encoding one reference's images, video or sound into a refmod file. */exportReferenceRefmod(session: ProjectSession, referenceId: string, outputPath: string) {if (!isTauri()) throw new Error("Refmod export is available in the desktop app.");@@ -307,6 +344,7 @@ export class WorkQueue {// background result can be attached to this project.await work.session.save();if (work.cancelled) continue;+ if (work.characterSheet) { await this.generateCharacterSheet(work); continue; }if (work.request.previousSceneId) {const previous = work.session.getSnapshot().config.generationJobs.find((job) => job.id === work.request.previousSceneId);if (!previous?.latentRelativePath || previous.status !== "completed") {@@ -371,14 +409,14 @@ export class WorkQueue {if (item.status === "queued" || item.status === "preparing") {this.cancelled(work);// Stops files that are still being sent to a LAN worker for this job.- if (item.status === "preparing" && remoteWorkerSelected()) void cancelSlopfabGeneration(work.id).catch(() => undefined);+ if (item.status === "preparing" && remoteWorkerSelected()) void cancelSlopfabGeneration(work.request.jobId).catch(() => undefined);return;}this.patch(id, { cancelling: true, detail: "Cancelling generation" });if (work.submitted) await this.requestNativeCancellation(work);}private async requestNativeCancellation(work: PendingWork) {- try { await cancelSlopfabGeneration(work.id); }+ try { await cancelSlopfabGeneration(work.request.jobId); }catch (reason) {work.cancelled = false;this.patch(work.id, { cancelling: false, detail: work.image ? "Generating image" : "Generating video", error: `Could not cancel: ${describeDiagnosticError(reason)}` });@@ -410,8 +448,8 @@ export class WorkQueue {}private progress(event: GenerationTimingProgress) {if (this.icons.progressEvent(event)) return;- const work = this.work.get(event.jobId);- const item = this.items.find((candidate) => candidate.id === event.jobId);+ const work = this.nativeWork(event.jobId);+ const item = this.items.find((candidate) => candidate.id === work?.id);// A refmod export sends its files to a LAN worker while it is encoding.if (!work || !item || !(["preparing", "generating"].includes(item.status) || (work.refmod && item.status === "encoding" && isWorkerTransfer(event)))) return;if (isWorkerTransfer(event)) {@@ -420,17 +458,32 @@ export class WorkQueue {if (!item.cancelling) this.patch(work.id, { detail: workerTransferDetail(event) });return;}+ if (work.characterSheet) {+ const sheet = work.characterSheet;+ const fraction = event.totalSteps > 0 ? Math.max(0, Math.min(1, event.step / event.totalSteps)) : 0;+ this.patch(work.id, { progress: Math.max(item.progress, (sheet.index + fraction) / 4 * 0.9),+ detail: item.cancelling ? "Cancelling generation" : `Character sheet ${sheet.index + 1}/4 · ${CHARACTER_SHEET_VIEWS[sheet.index].label}` });+ return;+ }const progress = Math.max(item.progress, event.totalSteps > 0 ? Math.min(0.88, 0.12 + Math.max(0, event.step) / event.totalSteps * 0.76) : event.stage === "delivering" ? 0.88 : 0.08);this.patch(work.id, { status: "generating", progress, completionAt: this.timing.update(event), detail: item.cancelling ? "Cancelling generation" : work.request.imageEdit ? `Applying image edits (${Math.min(work.request.imageEdit.edits.length, Math.floor(event.step / Math.max(1, event.totalSteps) * work.request.imageEdit.edits.length) + 1)} of ${work.request.imageEdit.edits.length})` : event.stage === "starting" || event.stage === "transformerLoad" ? "Loading MiniMax H3" : work.image ? "Generating image" : "Generating video" });this.updateScene(work, { status: "generating", stage: event.stage === "starting" || event.stage === "transformerLoad" ? "preparing" : "generating", progress }, false);}private event(event: JobEvent) {if (this.icons.event(event)) return;- const work = this.work.get(event.jobId);- const item = this.items.find((candidate) => candidate.id === event.jobId);+ const work = this.nativeWork(event.jobId);+ const item = this.items.find((candidate) => candidate.id === work?.id);if (!work || !item) return;- if (!isWorkActive(item)) { if (event.state === "framesReady") void releaseRendered(work.id); return; }+ if (!isWorkActive(item)) { if (event.state === "framesReady") void releaseRendered(event.jobId); return; }if (item.status === "encoding") return;+ if (work.characterSheet) {+ if (event.state === "framesReady") work.characterSheet.ready?.resolve();+ else if (event.state === "failed" || event.state === "cancelled") {+ if (event.state === "cancelled") work.cancelled = true;+ work.characterSheet.ready?.reject(new Error(event.detail));+ }+ return;+ }if (event.state === "framesReady") {if (event.output) this.timing.record(event.output);this.timing.clear(work.id);@@ -440,6 +493,56 @@ export class WorkQueue {else if (event.state === "cancelled") this.cancelled(work, event.detail);// A queued acknowledgement can arrive after progress. It must not rewind it.}+ private nativeWork(jobId: string) {+ return [...this.work.values()].find((work) => work.request.jobId === jobId);+ }+ private async generateCharacterSheet(work: PendingWork) {+ const sheet = work.characterSheet!;+ const folderPath = work.session.record.folderPath;+ try {+ for (let index = 0; index < sheet.prompts.length; index++) {+ if (work.cancelled) return;+ sheet.index = index;+ work.submitted = false;+ work.request = { ...work.request, jobId: `${work.id}-view-${index + 1}`, prompt: sheet.prompts[index] };+ this.patch(work.id, { status: "preparing", detail: `Preparing character sheet view ${index + 1}/4` });+ await resolveSlopfabPlan(work.request, work.config, folderPath);+ if (work.cancelled) return;+ const ready = new Promise<void>((resolve, reject) => { sheet.ready = { resolve, reject }; });+ // Events can arrive before native submission returns.+ void ready.catch(() => undefined);+ this.patch(work.id, { status: "generating", detail: `Character sheet ${index + 1}/4 · ${CHARACTER_SHEET_VIEWS[index].label}` });+ await enqueueSlopfabGeneration(work.request, work.config, folderPath);+ work.submitted = true;+ if (work.cancelled) await this.requestNativeCancellation(work);+ await ready;+ sheet.ready = undefined;+ if (work.cancelled) { this.cancelled(work); return; }+ this.patch(work.id, { status: "encoding", detail: `Saving character sheet view ${index + 1}/4` });+ await invoke("save_character_sheet_view", { folderPath, sheetId: work.id, jobId: work.request.jobId, index });+ await releaseRendered(work.request.jobId);+ }+ this.patch(work.id, { status: "encoding", progress: 0.95, detail: "Combining character sheet", completionAt: null });+ const saved = await invoke<{ relativePath: string; width: number; height: number }>("combine_character_sheet", { folderPath, sheetId: work.id });+ const scene = createImageEditScene({ ...saved, name: sheet.name }, work.config.imageScene ?? undefined);+ scene.referenceIds = [];+ const generation = { ...work.imageGeneration!, scene };+ work.session.update((current) => ({ ...current,+ ...(current.imageScene?.outputAssetId === sheet.sourceId && JSON.stringify(current.imageScene) === work.snapshot+ ? { thumbnail: saved.relativePath, imageScene: { ...scene, outputAssetId: work.id } } : {}),+ assets: [...current.assets, { id: work.id, kind: "image", name: sheet.name, ...saved, mimeType: "image/png",+ imageGeneration: generation, createdAt: new Date().toISOString() }],+ }));+ try { await work.session.save(); this.patch(work.id, { status: "completed", progress: 1, detail: "Character sheet saved" }); }+ catch (reason) { this.patch(work.id, { status: "failed", progress: 1, needsSave: true, detail: "Character sheet created; project save failed", error: describeDiagnosticError(reason) }); }+ } finally {+ sheet.ready = undefined;+ await releaseRendered(work.request.jobId).catch(() => undefined);+ await invoke("discard_character_sheet_views", { folderPath, sheetId: work.id }).catch((reason) =>+ writeDiagnostic("error", "work-queue", "character-sheet.cleanup_failed", describeDiagnosticError(reason), { workId: work.id }));+ work.finish();+ }+ }private async encode(work: PendingWork) {if (work.image) { await this.saveImage(work); return; }this.patch(work.id, { status: "encoding", progress: 0.9, detail: "Saving video", completionAt: null });diff --git a/src/styles/image-editor.css b/src/styles/image-editor.cssindex 699e076..b38fab2 100644--- a/src/styles/image-editor.css+++ b/src/styles/image-editor.css@@ -41,7 +41,8 @@.image-center { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--layer); }.image-canvas-tools { grid-column: 1 / -1; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: var(--space-2); min-height: var(--space-7); padding: var(--space-1) var(--space-2); border-bottom: 1px solid var(--line); }.image-generate-button { flex-shrink: 0; white-space: nowrap; }-.image-tools__start, .image-tools__center { min-width: 0; display: flex; align-items: center; gap: var(--space-1); }+.image-tools__start, .image-tools__center, .image-tools__end { min-width: 0; display: flex; align-items: center; gap: var(--space-1); }+.image-tools__end { justify-content: flex-end; }.image-generator { width: 160px; min-width: 0; flex-shrink: 1; }/* Editable: typed percentages up to "800%" plus the 32px drop-down button. */.image-zoom { width: 112px; min-width: 112px; }