AI media harness for planning, generating, and editing locally
TypeScript
Confirm automatic icon generation
Bitti7edb575f9df3
diff --git a/README.md b/README.mdindex 7aa1231..b499b7c 100644--- a/README.md+++ b/README.md@@ -72,6 +72,13 @@ are saved under `references/icons/` in the project and are not sent to the videoengine as image attachments. Built-in presets are added as new references fromthe Add a reference dialog.+Before an automatic icon batch starts, Slopus asks whether to start or cancel it.+Select **Don't ask again** to remember Start as automatic generation without prompts,+or Cancel as disabling automatic generation. **Settings → Video engine → Automatic+reference icon generation** turns automation on or off; confirmation can also be+re-enabled there. Turning automation off skips waiting automatic icons but lets an+icon already rendering finish. Manual icon generation remains available.+`npm run reference-icons` renders every missing character, product, location, and style preset with MiniMax H3 at 768×768 and 20 steps. Its DLL backend uses the dedicated still-image mode, downsamples each 3×3 pixel block to produce a 256×256 icon, and encodes it at JPEG quality 95 without creating an intermediate video or audio file. Character entries use controlled headshot lighting; product and location entries use a complete-subject view; style entries use a representative composition with lighting and rendering tailored to the named style.SlopFab, Cargo, and FFmpeg must be installed. The script uses the development paths under `D:\Projects\slopfab` by default; `SLOPFAB_EXE`, `SLOPFAB_TRANSFORMER`, `SLOPFAB_TEXT_ENCODER`, `SLOPFAB_VIDEO_VAE`, `SLOPFAB_AUDIO_VAE`, `SLOPFAB_BACKEND`, `CARGO_EXE`, and `FFMPEG_EXE` can override them. Use `node scripts/generate-reference-icons.mjs --id=<preset-id> --force` to regenerate one entry.diff --git a/src/App.tsx b/src/App.tsxindex 155827d..5dbe36a 100644--- a/src/App.tsx+++ b/src/App.tsx@@ -1,5 +1,6 @@import { WorkQueue, isWorkActive, projectQueueKey } from "./lib/workQueue";import { WorkQueuePanel } from "./components/WorkQueuePanel";+import { ReferenceIconGenerationDialog } from "./components/ReferenceIconGenerationDialog";import { invoke } from "@tauri-apps/api/core";import { listen } from "@tauri-apps/api/event";import { FolderOpen, Grid2X2, List, ListTodo, Plus, Search, Settings } from "lucide-react";@@ -36,6 +37,7 @@ function App() {return saved;}));const workItems = useSyncExternalStore(workQueue.subscribe, workQueue.getSnapshot);+ const iconConfirmationCount = useSyncExternalStore(workQueue.subscribe, workQueue.getIconConfirmationCount);const [workQueueOpen, setWorkQueueOpen] = useState(false);useEffect(() => workQueue.start(), [workQueue]);const [activeProject, setActiveProject] = useState<ProjectRecord | null>(null);@@ -222,6 +224,8 @@ function App() {<ListTodo size={22} aria-hidden="true" />{ongoingGenerations.length > 0 && <b>{ongoingGenerations.length}</b>}</button>;const queuePanel = workQueueOpen ? <WorkQueuePanel queue={workQueue} items={workItems} onClose={() => setWorkQueueOpen(false)} /> : null;+ const iconConfirmation = iconConfirmationCount > 0 && !settingsOpen && !workQueueOpen && !closeRequested && !projectToDelete && !newProjectOpen+ ? <ReferenceIconGenerationDialog count={iconConfirmationCount} onAnswer={workQueue.answerIconConfirmation} /> : null;if (activeProject) {return <>@@ -230,6 +234,7 @@ function App() {{queueLauncher}{queuePanel}{settingsOpen && <SettingsView onClose={closeSettings} />}+ {iconConfirmation}{exitGuard}</>;}@@ -284,6 +289,7 @@ function App() {{newProjectOpen && <PromptComposer busy={busy} onCreate={createFromPrompt} onClose={() => setNewProjectOpen(false)} />}{settingsOpen && <SettingsView onClose={closeSettings} />}{projectToDelete && <DeleteProjectDialog project={projectToDelete} deleting={deletingProject} onConfirm={() => void confirmProjectDeletion()} onCancel={() => setProjectToDelete(null)} />}+ {iconConfirmation}{exitGuard}{error && <div className="toast" role="alert"><strong>{error.title}</strong><span>{error.detail}</span><button onClick={() => setError(null)}>Dismiss</button></div>}</div>diff --git a/src/WorkQueue.integration.test.tsx b/src/WorkQueue.integration.test.tsxindex 95e77d7..9004059 100644--- a/src/WorkQueue.integration.test.tsx+++ b/src/WorkQueue.integration.test.tsx@@ -8,6 +8,7 @@ import { saveGeneratedScene } from "./lib/generatedVideo";import { listRecentProjects, saveProject } from "./lib/persistence";import { createProjectConfig, type ProjectRecord } from "./lib/project";import { enqueueSlopfabGeneration, type SlopfabStatus } from "./lib/runtime";+import { loadReferenceIconAutomation } from "./lib/referenceIconSettings";vi.mock("@tauri-apps/api/core", () => ({ invoke: vi.fn(async () => undefined) }));vi.mock("@tauri-apps/api/event", () => ({ listen: vi.fn() }));@@ -30,6 +31,36 @@ beforeEach(() => {});afterEach(() => { cleanup(); vi.restoreAllMocks(); });+it("keeps icon confirmation available after returning to the library", async () => {+ const config = createProjectConfig({ name: "Icon project", prompt: "A quiet scene", aspectRatio: "16:9", resolution: "416p", targetDurationSeconds: 30 });+ config.references = [{ id: "hero", kind: "text", name: "Hero", description: "A friendly explorer", intendedUse: ["character"], createdAt: "2026-09-08T00:00:00.000Z" }];+ vi.mocked(listRecentProjects).mockResolvedValue({ projects: [{ folderPath: "C:/Icon project", config }], unreadable: [] });+ render(<App />);+ fireEvent.click(await screen.findByRole("button", { name: "Open Icon project" }));+ fireEvent.click(screen.getByRole("button", { name: "Back to project library" }));+ const dialog = await screen.findByRole("alertdialog", { name: "Generate reference icons?" }, { timeout: 5000 });+ expect(enqueueSlopfabGeneration).not.toHaveBeenCalled();+ fireEvent.click(within(dialog).getByRole("button", { name: "Start generation" }));+ await waitFor(() => expect(enqueueSlopfabGeneration).toHaveBeenCalledTimes(1));+ expect(vi.mocked(enqueueSlopfabGeneration).mock.calls[0][0]).toMatchObject({ stillImage: true, canvasWidth: 768, steps: 20 });+ expect(screen.queryByRole("alertdialog", { name: "Generate reference icons?" })).toBeNull();+});++it("cancels automatic generation and exposes the remembered choice in Video engine settings", async () => {+ const config = createProjectConfig({ name: "Cancel icons", prompt: "A quiet scene", aspectRatio: "16:9", resolution: "416p", targetDurationSeconds: 30 });+ config.references = [{ id: "hero", kind: "text", name: "Hero", description: "A friendly explorer", intendedUse: ["character"], createdAt: "2026-09-08T00:00:00.000Z" }];+ vi.mocked(listRecentProjects).mockResolvedValue({ projects: [{ folderPath: "C:/Cancel icons", config }], unreadable: [] });+ render(<App />);+ fireEvent.click(await screen.findByRole("button", { name: "Open Cancel icons" }));+ const dialog = await screen.findByRole("alertdialog", { name: "Generate reference icons?" }, { timeout: 5000 });+ fireEvent.click(within(dialog).getByRole("checkbox", { name: /Don't ask again/ }));+ fireEvent.click(within(dialog).getByRole("button", { name: "Cancel" }));+ expect(loadReferenceIconAutomation()).toBe("disabled");+ expect(enqueueSlopfabGeneration).not.toHaveBeenCalled();+ fireEvent.click(screen.getByRole("button", { name: "Settings" }));+ expect(screen.getByRole("checkbox", { name: "Automatic reference icon generation" })).not.toBeChecked();+});+it("keeps the application queue alive while switching projects and saves results to their original project", async () => {const record = (name: string): ProjectRecord => ({ folderPath: `C:/${name}`, config: createProjectConfig({ name, prompt: "A quiet scene", aspectRatio: "16:9", resolution: "416p", targetDurationSeconds: 30 }) });const first = record("First project"), second = record("Second project");diff --git a/src/components/ReferenceIconGenerationDialog.test.tsx b/src/components/ReferenceIconGenerationDialog.test.tsxnew file mode 100644index 0000000..dd10084--- /dev/null+++ b/src/components/ReferenceIconGenerationDialog.test.tsx@@ -0,0 +1,44 @@+// @vitest-environment jsdom+import { cleanup, fireEvent, render, screen } from "@testing-library/react";+import { afterEach, expect, it, vi } from "vitest";+import { ReferenceIconGenerationDialog } from "./ReferenceIconGenerationDialog";++afterEach(cleanup);++it("shows the batch and starts only after an explicit answer", () => {+ const answer = vi.fn();+ render(<ReferenceIconGenerationDialog count={3} onAnswer={answer} />);+ expect(screen.getByRole("alertdialog").textContent).toContain("3 references need icons");+ expect(answer).not.toHaveBeenCalled();+ expect(document.activeElement).toBe(screen.getByRole("button", { name: "Cancel" }));+ fireEvent.click(screen.getByRole("checkbox", { name: /Don't ask again/ }));+ fireEvent.click(screen.getByRole("button", { name: "Start generation" }));+ expect(answer).toHaveBeenCalledWith(true, true);+});++it("remembers Cancel only when the button is explicitly chosen", () => {+ const answer = vi.fn();+ render(<ReferenceIconGenerationDialog count={1} onAnswer={answer} />);+ fireEvent.click(screen.getByRole("checkbox", { name: /Don't ask again/ }));+ fireEvent.keyDown(window, { key: "Escape" });+ expect(answer).toHaveBeenLastCalledWith(false, false);+ fireEvent.click(screen.getByRole("button", { name: "Cancel" }));+ expect(answer).toHaveBeenLastCalledWith(false, true);+});++it("traps keyboard focus and returns it when dismissed", () => {+ const opener = document.createElement("button");+ document.body.append(opener);+ opener.focus();+ const view = render(<ReferenceIconGenerationDialog count={1} onAnswer={vi.fn()} />);+ const checkbox = screen.getByRole("checkbox");+ const start = screen.getByRole("button", { name: "Start generation" });+ start.focus();+ fireEvent.keyDown(window, { key: "Tab" });+ expect(document.activeElement).toBe(checkbox);+ fireEvent.keyDown(window, { key: "Tab", shiftKey: true });+ expect(document.activeElement).toBe(start);+ view.unmount();+ expect(document.activeElement).toBe(opener);+ opener.remove();+});diff --git a/src/components/ReferenceIconGenerationDialog.tsx b/src/components/ReferenceIconGenerationDialog.tsxnew file mode 100644index 0000000..8fd09f0--- /dev/null+++ b/src/components/ReferenceIconGenerationDialog.tsx@@ -0,0 +1,62 @@+import { ImagePlus } from "lucide-react";+import { useEffect, useRef, useState } from "react";++export function ReferenceIconGenerationDialog({ count, onAnswer }: {+ count: number;+ onAnswer: (confirmed: boolean, remember: boolean) => void;+}) {+ const [remember, setRemember] = useState(false);+ const dialog = useRef<HTMLDivElement>(null);+ const cancel = useRef<HTMLButtonElement>(null);++ useEffect(() => {+ const opener = document.activeElement as HTMLElement | null;+ cancel.current?.focus();+ return () => opener?.focus?.();+ }, []);++ useEffect(() => {+ const onKeyDown = (event: KeyboardEvent) => {+ if (event.key === "Escape") {+ event.preventDefault();+ event.stopImmediatePropagation();+ onAnswer(false, false);+ }+ if (event.key !== "Tab" || !dialog.current) return;+ const stops = Array.from(dialog.current.querySelectorAll<HTMLElement>("button, input"));+ const first = stops[0];+ const last = stops[stops.length - 1];+ const active = document.activeElement as HTMLElement | null;+ if (!event.shiftKey && (active === last || !dialog.current.contains(active))) {+ event.preventDefault();+ first.focus();+ } else if (event.shiftKey && (active === first || !dialog.current.contains(active))) {+ event.preventDefault();+ last.focus();+ }+ };+ window.addEventListener("keydown", onKeyDown, true);+ return () => window.removeEventListener("keydown", onKeyDown, true);+ }, [onAnswer]);++ return <div className="exit-guard-backdrop" onMouseDown={(event) => { if (event.target === event.currentTarget) onAnswer(false, false); }}>+ <div className="exit-guard" ref={dialog} role="alertdialog" aria-modal="true" aria-labelledby="reference-icon-generation-title" aria-describedby="reference-icon-generation-description">+ <div className="exit-guard__head">+ <span className="exit-guard__mark" aria-hidden="true"><ImagePlus size={20} /></span>+ <h2 id="reference-icon-generation-title">Generate reference icons?</h2>+ </div>+ <div className="exit-guard__body" id="reference-icon-generation-description">+ <p>{count} {count === 1 ? "reference needs an icon" : "references need icons"}. Generate them now using the video engine? This uses your GPU; waiting videos take priority.</p>+ <p>Cancel skips this batch. You can change automatic generation in Settings → Video engine.</p>+ </div>+ <label className="reference-icon-option">+ <input type="checkbox" checked={remember} onChange={(event) => setRemember(event.target.checked)} />+ <span><b>Don't ask again</b><small>Remember Start as automatic generation, or Cancel as turning it off.</small></span>+ </label>+ <div className="exit-guard__actions">+ <button className="secondary-button" type="button" ref={cancel} onClick={() => onAnswer(false, remember)}>Cancel</button>+ <button className="primary-button" type="button" onClick={() => onAnswer(true, remember)}>Start generation</button>+ </div>+ </div>+ </div>;+}diff --git a/src/components/SettingsView.test.tsx b/src/components/SettingsView.test.tsxindex c67a5d0..dadf6ce 100644--- a/src/components/SettingsView.test.tsx+++ b/src/components/SettingsView.test.tsx@@ -36,6 +36,24 @@ describe("the frame the tabs sit in", () => {});describe("the settings screen", () => {+ it("remembers automatic reference icon generation and confirmation preferences", () => {+ const view = open();+ const automatic = () => screen.getByRole("checkbox", { name: "Automatic reference icon generation" }) as HTMLInputElement;+ const confirmation = () => screen.getByRole("checkbox", { name: "Ask before automatic icon generation" }) as HTMLInputElement;+ expect(automatic().checked).toBe(true);+ expect(confirmation().checked).toBe(true);+ fireEvent.click(confirmation());+ expect(confirmation().checked).toBe(false);+ view.unmount();+ open();+ expect(confirmation().checked).toBe(false);+ fireEvent.click(automatic());+ expect(automatic().checked).toBe(false);+ expect(screen.queryByRole("checkbox", { name: "Ask before automatic icon generation" })).toBeNull();+ fireEvent.click(automatic());+ expect(confirmation().checked).toBe(true);+ });+it("keeps debug options off by default and remembers the Diagnostics choice", () => {const view = open();fireEvent.click(tab("Diagnostics"));diff --git a/src/components/SettingsView.tsx b/src/components/SettingsView.tsxindex a9d8ffb..b6db4f5 100644--- a/src/components/SettingsView.tsx+++ b/src/components/SettingsView.tsx@@ -13,6 +13,7 @@ import {type EnginePathField, type EnginePathId, type EngineSettings, type GeneratorTemplateSettings,} from "../lib/settings";import { MAX_GENERATION_STEPS } from "../lib/project";+import { loadReferenceIconAutomation, saveReferenceIconAutomation, subscribeReferenceIconAutomation } from "../lib/referenceIconSettings";import {applyTheme, loadTheme, saveTheme, systemTheme, watchSystemTheme,type ResolvedTheme, type ThemeChoice,@@ -51,6 +52,20 @@ const themeOptions: { id: ThemeChoice; label: string; icon: typeof Sun; detail:{ id: "dark", label: "Dark", icon: Moon, detail: () => "Always dark, whatever this computer is set to." },];+function ReferenceIconSetting() {+ const automation = useSyncExternalStore(subscribeReferenceIconAutomation, loadReferenceIconAutomation);+ return <>+ <label className="reference-icon-option">+ <input type="checkbox" checked={automation !== "disabled"} onChange={(event) => saveReferenceIconAutomation(event.target.checked ? "ask" : "disabled")} aria-labelledby="automatic-reference-icons-label" aria-describedby="automatic-reference-icons-description" />+ <span><b id="automatic-reference-icons-label">Automatic reference icon generation</b><small id="automatic-reference-icons-description">Generate icons for references without artwork. Turning this off skips waiting automatic icons; an icon already rendering can finish. Manual generation stays available.</small></span>+ </label>+ {automation !== "disabled" && <label className="reference-icon-option">+ <input type="checkbox" checked={automation === "ask"} onChange={(event) => saveReferenceIconAutomation(event.target.checked ? "ask" : "enabled")} />+ <span><b>Ask before automatic icon generation</b></span>+ </label>}+ </>;+}+function AppearanceSetting() {const [choice, setChoice] = useState<ThemeChoice>(loadTheme);const [system, setSystem] = useState<ResolvedTheme>(systemTheme);@@ -424,6 +439,7 @@ export function SettingsView({ onClose }: { onClose: () => void }) {role={editingTemplateId ? "region" : "tabpanel"}aria-labelledby={editingTemplateId ? "generator-editor-heading" : "settings-tab-engine"}>+ {!editingTemplateId && <ReferenceIconSetting />}{!editingTemplateId ? <section className="generator-templates" aria-labelledby="generators-heading"><header><div>diff --git a/src/lib/referenceIconSettings.test.ts b/src/lib/referenceIconSettings.test.tsnew file mode 100644index 0000000..127c8c8--- /dev/null+++ b/src/lib/referenceIconSettings.test.ts@@ -0,0 +1,37 @@+// @vitest-environment jsdom+import { beforeEach, expect, it, vi } from "vitest";+import { loadReferenceIconAutomation, saveReferenceIconAutomation, subscribeReferenceIconAutomation } from "./referenceIconSettings";++beforeEach(() => localStorage.clear());++it("defaults to confirmation and ignores invalid stored choices", () => {+ expect(loadReferenceIconAutomation()).toBe("ask");+ localStorage.setItem("slopus.reference-icon-automation.v1", "unexpected");+ expect(loadReferenceIconAutomation()).toBe("ask");+});++it("persists choices and notifies subscribers until disconnected", () => {+ const listener = vi.fn();+ const stop = subscribeReferenceIconAutomation(listener);+ saveReferenceIconAutomation("enabled");+ expect(loadReferenceIconAutomation()).toBe("enabled");+ expect(listener).toHaveBeenCalledTimes(1);+ saveReferenceIconAutomation("disabled");+ expect(loadReferenceIconAutomation()).toBe("disabled");+ window.dispatchEvent(new StorageEvent("storage", { key: "slopus.reference-icon-automation.v1" }));+ expect(listener).toHaveBeenCalledTimes(3);+ stop();+ saveReferenceIconAutomation("ask");+ expect(listener).toHaveBeenCalledTimes(3);+});++it("honors a disabled choice for the session when storage cannot be written", () => {+ const write = vi.spyOn(Storage.prototype, "setItem").mockImplementation(() => { throw new Error("Storage full"); });+ try {+ saveReferenceIconAutomation("disabled");+ expect(loadReferenceIconAutomation()).toBe("disabled");+ } finally {+ write.mockRestore();+ saveReferenceIconAutomation("ask");+ }+});diff --git a/src/lib/referenceIconSettings.ts b/src/lib/referenceIconSettings.tsnew file mode 100644index 0000000..ddaf06a--- /dev/null+++ b/src/lib/referenceIconSettings.ts@@ -0,0 +1,37 @@+export type ReferenceIconAutomation = "ask" | "enabled" | "disabled";++const STORAGE_KEY = "slopus.reference-icon-automation.v1";+const CHANGE_EVENT = "slopus:reference-icon-automation-changed";+let sessionOverride: ReferenceIconAutomation | undefined;++export function loadReferenceIconAutomation(): ReferenceIconAutomation {+ if (sessionOverride) return sessionOverride;+ try {+ const value = localStorage.getItem(STORAGE_KEY);+ return value === "enabled" || value === "disabled" ? value : "ask";+ } catch {+ return "ask";+ }+}++export function saveReferenceIconAutomation(value: ReferenceIconAutomation) {+ try {+ localStorage.setItem(STORAGE_KEY, value);+ sessionOverride = undefined;+ } catch {+ sessionOverride = value;+ }+ window.dispatchEvent(new Event(CHANGE_EVENT));+}++export function subscribeReferenceIconAutomation(listener: () => void) {+ const onStorage = (event: StorageEvent) => {+ if (event.key === STORAGE_KEY || event.key === null) listener();+ };+ window.addEventListener(CHANGE_EVENT, listener);+ window.addEventListener("storage", onStorage);+ return () => {+ window.removeEventListener(CHANGE_EVENT, listener);+ window.removeEventListener("storage", onStorage);+ };+}diff --git a/src/lib/referenceIconWork.test.ts b/src/lib/referenceIconWork.test.tsindex a48b677..804a352 100644--- a/src/lib/referenceIconWork.test.ts+++ b/src/lib/referenceIconWork.test.ts@@ -5,6 +5,7 @@ import { releaseRendered, saveGeneratedScene } from "./generatedVideo";import { createProjectConfig, parseProjectConfig, referenceImages, type ProjectRecord, type ProjectReference } from "./project";import { REFERENCE_PRESETS } from "./reference-presets";import { referenceIconPrompt } from "./referenceIcons";+import { loadReferenceIconAutomation, saveReferenceIconAutomation } from "./referenceIconSettings";import { cancelSlopfabGeneration, enqueueSlopfabGeneration, resolveSlopfabPlan, saveReferenceIcon } from "./runtime";import { WorkQueue } from "./workQueue";@@ -41,6 +42,7 @@ const video = (queue: WorkQueue, session: ReturnType<WorkQueue["project"]>) => qbeforeEach(() => {vi.useFakeTimers(); vi.clearAllMocks(); localStorage.clear(); handlers.clear();+ saveReferenceIconAutomation("enabled");Object.assign(window, { __TAURI_INTERNALS__: {} });vi.mocked(listen).mockImplementation((async (name: string, handler: (event: { payload: any }) => void) => { handlers.set(name, handler); return () => { handlers.delete(name); }; }) as typeof listen);vi.mocked(enqueueSlopfabGeneration).mockResolvedValue(undefined);@@ -51,6 +53,111 @@ beforeEach(() => {});afterEach(() => { stop?.(); vi.useRealTimers(); delete (window as any).__TAURI_INTERNALS__; });+it("waits for batch confirmation without blocking video generation", async () => {+ saveReferenceIconAutomation("ask");+ const { queue, session } = setup([reference("hero"), reference("place", "location")]);+ await vi.advanceTimersByTimeAsync(1001);+ expect(requests()).toHaveLength(0);+ expect(queue.getIconConfirmationCount()).toBe(2);+ video(queue, session);+ await flush();+ expect(requests()).toHaveLength(1);+ expect(requests()[0].stillImage).not.toBe(true);+ queue.answerIconConfirmation(true, false);+ expect(queue.getIconConfirmationCount()).toBe(0);+ await finish(requests()[0].jobId);+ expect(requests()[1].stillImage).toBe(true);+ await finish(requests()[1].jobId);+ expect(requests()[2].stillImage).toBe(true);+ await finish(requests()[2].jobId);+ expect(loadReferenceIconAutomation()).toBe("ask");+});++it("cancels a pending batch without repeatedly asking for the same icons", async () => {+ saveReferenceIconAutomation("ask");+ const { queue, session } = setup([reference("hero")]);+ await vi.advanceTimersByTimeAsync(1001);+ queue.answerIconConfirmation(false, false);+ session.update((current) => ({ ...current, references: [...current.references] }));+ await vi.advanceTimersByTimeAsync(1001);+ expect(requests()).toHaveLength(0);+ expect(queue.getIconConfirmationCount()).toBe(0);+ expect(loadReferenceIconAutomation()).toBe("ask");+ session.update((current) => ({ ...current, references: [...current.references, reference("new")] }));+ await vi.advanceTimersByTimeAsync(1001);+ expect(queue.getIconConfirmationCount()).toBe(1);+});++it("remembers Start and automatically generates subsequent references", async () => {+ saveReferenceIconAutomation("ask");+ const { queue, session } = setup([reference("hero")]);+ await vi.advanceTimersByTimeAsync(1001);+ queue.answerIconConfirmation(true, true);+ await flush();+ expect(loadReferenceIconAutomation()).toBe("enabled");+ await finish(requests()[0].jobId);+ session.update((current) => ({ ...current, references: [...current.references, reference("new")] }));+ await vi.advanceTimersByTimeAsync(1001);+ expect(queue.getIconConfirmationCount()).toBe(0);+ expect(requests()).toHaveLength(2);+ await finish(requests()[1].jobId);+});++it("remembers Cancel as disabled but still allows manual icon generation", async () => {+ saveReferenceIconAutomation("ask");+ const { queue, session } = setup([reference("hero")]);+ await vi.advanceTimersByTimeAsync(1001);+ queue.answerIconConfirmation(false, true);+ expect(loadReferenceIconAutomation()).toBe("disabled");+ session.update((current) => ({ ...current, references: [...current.references, reference("new")] }));+ await vi.advanceTimersByTimeAsync(1001);+ expect(queue.getIconConfirmationCount()).toBe(0);+ expect(requests()).toHaveLength(0);+ queue.regenerateReferenceIcon(session, "hero");+ await flush();+ expect(requests()).toHaveLength(1);+ await finish(requests()[0].jobId);+ expect(session.getSnapshot().config.references[0].iconRelativePath).toMatch(/\.jpg$/);+});++it("reacts immediately to disabling and re-enabling automatic generation", async () => {+ saveReferenceIconAutomation("disabled");+ const { queue } = setup([reference("hero")]);+ await vi.advanceTimersByTimeAsync(1001);+ expect(requests()).toHaveLength(0);+ expect(queue.getIconConfirmationCount()).toBe(0);+ saveReferenceIconAutomation("ask");+ expect(queue.getIconConfirmationCount()).toBe(1);+ saveReferenceIconAutomation("disabled");+ expect(queue.getIconConfirmationCount()).toBe(0);+ await flush();+ expect(requests()).toHaveLength(0);+ saveReferenceIconAutomation("ask");+ expect(queue.getIconConfirmationCount()).toBe(1);+});++it("disabling automation stops waiting icons but lets the active icon save", async () => {+ const { session } = setup([reference("hero"), reference("place")]);+ await vi.advanceTimersByTimeAsync(1001);+ saveReferenceIconAutomation("disabled");+ await finish(requests()[0].jobId);+ expect(requests()).toHaveLength(1);+ expect(session.getSnapshot().config.references[0].iconRelativePath).toMatch(/\.jpg$/);+ expect(session.getSnapshot().config.references[1].iconRelativePath).toBeUndefined();+});++it("checks automation again after waiting for the project to save", async () => {+ const { saved } = setup([reference("hero")]);+ let finishSave!: () => void;+ saved.mockImplementationOnce(() => new Promise<undefined>((resolve) => { finishSave = () => resolve(undefined); }));+ await vi.advanceTimersByTimeAsync(1001);+ expect(requests()).toHaveLength(0);+ saveReferenceIconAutomation("disabled");+ finishSave();+ await flush();+ expect(requests()).toHaveLength(0);+});+it("groups icons across projects and gives waiting videos priority between icons", async () => {const { queue, session } = setup([reference("hero")]);const second = queue.project(project("Second", [reference("place", "location")]));diff --git a/src/lib/referenceIconWork.ts b/src/lib/referenceIconWork.tsindex 4dfae4e..7a74117 100644--- a/src/lib/referenceIconWork.ts+++ b/src/lib/referenceIconWork.ts@@ -6,6 +6,7 @@ import { referenceImages, type ProjectReference } from "./project";import { needsReferenceIcon, referenceIconPrompt, REFERENCE_ICON_RENDER_SIZE, REFERENCE_ICON_STEPS } from "./referenceIcons";import { cancelSlopfabGeneration, enqueueSlopfabGeneration, saveReferenceIcon } from "./runtime";import { withEngineSettings } from "./settings";+import { loadReferenceIconAutomation, saveReferenceIconAutomation, subscribeReferenceIconAutomation } from "./referenceIconSettings";import type { WorkItem } from "./workQueue";type TaskStatus = "queued" | "generating" | "saving" | "completed" | "failed" | "cancelled" | "skipped";@@ -20,6 +21,7 @@ interface IconTask {submitted: boolean;cancelled: boolean;force?: boolean;+ approved?: boolean;error?: string;needsSave?: boolean;finish?: () => void;@@ -34,11 +36,16 @@ export class ReferenceIconWork {private progress = 0;private item?: WorkItem;private watches = new Map<ProjectSession, () => void>();+ private stopSettings?: () => void;constructor(private changed: (item: WorkItem) => void, private wake: () => void) {}watch(session: ProjectSession) {if (!isTauri() || this.watches.has(session)) return;+ this.stopSettings ??= subscribeReferenceIconAutomation(() => {+ this.watches.forEach((_stop, watched) => this.scan(watched));+ this.wake();+ });let references = session.getSnapshot().config.references;const schedule = () => {clearTimeout(this.timers.get(session));@@ -62,9 +69,12 @@ export class ReferenceIconWork {this.watches.get(session)?.();this.watches.delete(session);for (const [key, task] of this.tasks) if (task.session === session) this.tasks.delete(key);+ this.publish();}stop() {+ this.stopSettings?.();+ this.stopSettings = undefined;this.timers.forEach(clearTimeout);this.timers.clear();this.watches.forEach((stop) => stop());@@ -76,7 +86,7 @@ export class ReferenceIconWork {for (const task of this.tasks.values()) {if (task.session !== session || task.status !== "queued") continue;const reference = references.find((reference) => reference.id === task.referenceId);- if (!reference || !this.shouldGenerate(reference, task)) task.status = "skipped";+ if (!reference || !this.shouldGenerate(reference, task) || (!task.force && loadReferenceIconAutomation() === "disabled")) task.status = "skipped";}let added = false;for (const reference of references) {@@ -84,6 +94,7 @@ export class ReferenceIconWork {const prompt = referenceIconPrompt(reference);const previous = this.tasks.get(key);const force = previous?.force && previous.status === "skipped";+ if (!force && loadReferenceIconAutomation() === "disabled") continue;if (!this.shouldGenerate(reference, { force })) continue;if (previous && (previous === this.active || (previous.prompt === prompt && previous.status !== "skipped"))) continue;this.tasks.set(key, { key, session, referenceId: reference.id, name: reference.name, prompt, status: "queued", submitted: false, cancelled: false, force });@@ -111,6 +122,26 @@ export class ReferenceIconWork {}hasQueued() { return [...this.tasks.values()].some((task) => task.status === "queued"); }+ private canRun(task: IconTask) {+ const automation = loadReferenceIconAutomation();+ return task.status === "queued" && (task.force || automation === "enabled" || (automation === "ask" && task.approved));+ }+ hasRunnable() { return [...this.tasks.values()].some((task) => this.canRun(task)); }+ private awaitingConfirmation() {+ return loadReferenceIconAutomation() === "ask"+ ? [...this.tasks.values()].filter((task) => task.status === "queued" && !task.force && !task.approved)+ : [];+ }+ confirmationCount() { return this.awaitingConfirmation().length; }+ answerConfirmation(confirmed: boolean, remember: boolean) {+ for (const task of this.awaitingConfirmation()) {+ if (confirmed) task.approved = true;+ else { task.status = "cancelled"; task.cancelled = true; }+ }+ if (remember) saveReferenceIconAutomation(confirmed ? "enabled" : "disabled");+ this.publish();+ this.wake();+ }hasActiveProject(session: ProjectSession) {return [...this.tasks.values()].some((task) => task.session === session && ["queued", "generating", "saving"].includes(task.status));}@@ -139,6 +170,7 @@ export class ReferenceIconWork {status: this.active ? (this.active.status === "saving" ? "encoding" : "generating") : queued ? "queued" : failed.length ? "failed" : tasks.some((task) => task.status === "cancelled") ? "cancelled" : "completed",progress: tasks.length ? Math.min(1, (settled + (this.active ? this.progress : 0)) / tasks.length) : 1,detail: this.active ? `${this.active.cancelled ? "Cancelling" : this.active.status === "saving" ? "Saving" : "Generating"} ${this.active.name} · ${completed}/${tasks.length} icons saved`+ : this.confirmationCount() > 0 ? `${this.confirmationCount()} icons awaiting confirmation`: queued ? `${completed}/${tasks.length} icons saved · waiting behind videos` : `${completed}/${tasks.length} icons saved`,error: failed.length ? failed.map((task) => `${task.name}: ${task.error}`).join("\n") : null,cancelling: this.active?.cancelled ?? false,@@ -148,7 +180,7 @@ export class ReferenceIconWork {}async runNext(ready: Promise<void>, videoWaiting: () => boolean) {- const task = [...this.tasks.values()].find((task) => task.status === "queued");+ const task = [...this.tasks.values()].find((task) => this.canRun(task));if (!task) return;this.active = task;task.status = "generating";@@ -160,6 +192,8 @@ export class ReferenceIconWork {await task.session.save();if (task.cancelled) return;if (videoWaiting()) { task.status = "queued"; return; }+ if (!task.force && loadReferenceIconAutomation() === "disabled") { task.status = "skipped"; return; }+ if (!task.force && !task.approved && loadReferenceIconAutomation() === "ask") { task.status = "queued"; return; }const reference = task.session.getSnapshot().config.references.find((reference) => reference.id === task.referenceId);if (!reference || !this.shouldGenerate(reference, task)) { task.status = "skipped"; return; }task.prompt = referenceIconPrompt(reference);diff --git a/src/lib/workQueue.ts b/src/lib/workQueue.tsindex aa39da4..4cf868b 100644--- a/src/lib/workQueue.ts+++ b/src/lib/workQueue.ts@@ -72,6 +72,8 @@ export class WorkQueue {constructor(private writer: ProjectWriter = saveProject) {}getSnapshot = () => this.items;+ getIconConfirmationCount = () => this.icons.confirmationCount();+ answerIconConfirmation = (confirmed: boolean, remember: boolean) => this.icons.answerConfirmation(confirmed, remember);subscribe = (listener: () => void) => { this.listeners.add(listener); return () => { this.listeners.delete(listener); }; };private publish() { this.listeners.forEach((listener) => listener()); }private patch(id: string, patch: Partial<WorkItem>) {@@ -175,7 +177,7 @@ export class WorkQueue {while (true) {const next = this.items.find((item) => item.status === "queued" && item.kind !== "reference-icons");if (!next) {- if (!this.icons.hasQueued()) break;+ if (!this.icons.hasRunnable()) break;await this.icons.runNext(this.ready, () => this.items.some((item) => item.status === "queued" && item.kind !== "reference-icons"));continue;}diff --git a/src/styles/shell.css b/src/styles/shell.cssindex 0454312..c3343fc 100644--- a/src/styles/shell.css+++ b/src/styles/shell.css@@ -433,7 +433,8 @@/* --- Diagnostics ---------------------------------------------------------- */-.diagnostics-debug-option {+.diagnostics-debug-option,+.reference-icon-option {display: flex;align-items: center;gap: var(--space-3);@@ -445,19 +446,22 @@cursor: pointer;}-.diagnostics-debug-option input {+.diagnostics-debug-option input,+.reference-icon-option input {width: 16px;height: 16px;margin: 0;accent-color: var(--accent);}-.diagnostics-debug-option b {+.diagnostics-debug-option b,+.reference-icon-option b {color: var(--text-primary);font-size: var(--text-sm);}-.diagnostics-debug-option small {+.diagnostics-debug-option small,+.reference-icon-option small {display: block;margin-top: var(--space-1);color: var(--text-muted);