Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Ask before an exit that would kill a generation

Bitti2799ce795223
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index f853608..b028149 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -1773,11 +1773,100 @@ fn cancel_vidfab_generation(
state.cancel(&job_id)
}
+/* ── Exit guard ──────────────────────────────────────────────────────────────
+ The video engine runs inside this process, so closing the window ends a
+ generation outright — and vidfab writes no file of its own, so an unfinished
+ run leaves nothing behind. The webview therefore has to be able to answer the
+ close request before the window goes away.
+
+ The window is held open ONLY while the frontend has said something is
+ generating (`set_generation_active`). A webview that never loaded, or one
+ with nothing to lose, closes on the first click exactly as before: the guard
+ can never be the reason a user is stuck in a window that will not shut.
+ -------------------------------------------------------------------------- */
+
+#[derive(Default)]
+struct ExitGuard {
+ /// Set by the frontend whenever the number of running or queued generations
+ /// changes. False means "close without asking".
+ generation_active: std::sync::atomic::AtomicBool,
+ /// True between putting the question to the webview and its answer, so a
+ /// second click on the close button does not stack a second dialog.
+ asking: std::sync::atomic::AtomicBool,
+}
+
+#[derive(Debug, PartialEq, Eq)]
+enum CloseDecision {
+ /// Nothing is generating: let the window close.
+ Close,
+ /// Hold the window open and ask the webview.
+ Ask,
+ /// Hold the window open; the question is already on screen.
+ Waiting,
+}
+
+impl ExitGuard {
+ fn on_close_requested(&self) -> CloseDecision {
+ if !self.generation_active.load(Ordering::Acquire) {
+ return CloseDecision::Close;
+ }
+ if self.asking.swap(true, Ordering::AcqRel) {
+ CloseDecision::Waiting
+ } else {
+ CloseDecision::Ask
+ }
+ }
+
+ /// Records the webview's answer. `true` also clears the active flag, so the
+ /// close that follows is not stopped by the guard a second time.
+ fn answered(&self, confirmed: bool) {
+ self.asking.store(false, Ordering::Release);
+ if confirmed {
+ self.generation_active.store(false, Ordering::Release);
+ }
+ }
+}
+
+#[tauri::command]
+fn set_generation_active(state: tauri::State<'_, ExitGuard>, active: bool) {
+ state.generation_active.store(active, Ordering::Release);
+}
+
+#[tauri::command]
+fn answer_app_close(window: tauri::Window, state: tauri::State<'_, ExitGuard>, confirmed: bool) {
+ state.answered(confirmed);
+ if confirmed {
+ let _ = window.destroy();
+ }
+}
+
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.manage(agent::AgentRuntime::default())
.manage(vidfab::VidfabRuntime::default())
+ .manage(ExitGuard::default())
+ .on_window_event(|window, event| {
+ use tauri::{Emitter as _, Manager as _};
+ let tauri::WindowEvent::CloseRequested { api, .. } = event else {
+ return;
+ };
+ let guard = window.state::<ExitGuard>();
+ match guard.on_close_requested() {
+ CloseDecision::Close => {}
+ CloseDecision::Waiting => api.prevent_close(),
+ CloseDecision::Ask => {
+ api.prevent_close();
+ // If the question cannot even be delivered there is nobody
+ // to answer it, and refusing to close would be worse than
+ // closing unasked.
+ if window.emit("app-close-requested", ()).is_err() {
+ guard.answered(true);
+ let _ = window.destroy();
+ }
+ }
+ }
+ })
.plugin(tauri_plugin_dialog::init())
.invoke_handler(tauri::generate_handler![
open_project,
@@ -1797,6 +1886,8 @@ pub fn run() {
resolve_vidfab_plan,
enqueue_vidfab_generation,
cancel_vidfab_generation,
+ set_generation_active,
+ answer_app_close,
export::choose_export_destination,
export::write_export_file
])
@@ -3294,3 +3385,60 @@ mod tests {
assert!(validate_and_normalize_config(config.clone()).is_ok());
}
}
+
+/* ── Exit guard tests ─────────────────────────────────────────────────────── */
+#[cfg(test)]
+mod exit_guard_tests {
+ use super::{CloseDecision, ExitGuard};
+ use std::sync::atomic::Ordering;
+
+ fn generating() -> ExitGuard {
+ let guard = ExitGuard::default();
+ guard.generation_active.store(true, Ordering::Release);
+ guard
+ }
+
+ #[test]
+ fn a_window_with_nothing_generating_closes_without_asking() {
+ let guard = ExitGuard::default();
+ assert_eq!(guard.on_close_requested(), CloseDecision::Close);
+ // And it keeps closing: the guard must never latch on its own.
+ assert_eq!(guard.on_close_requested(), CloseDecision::Close);
+ }
+
+ #[test]
+ fn a_generation_holds_the_window_and_asks_once() {
+ let guard = generating();
+ assert_eq!(guard.on_close_requested(), CloseDecision::Ask);
+ // Clicking the close button again while the question is on screen must
+ // still hold the window, but must not stack a second dialog.
+ assert_eq!(guard.on_close_requested(), CloseDecision::Waiting);
+ }
+
+ #[test]
+ fn keeping_generating_leaves_the_guard_ready_to_ask_again() {
+ let guard = generating();
+ assert_eq!(guard.on_close_requested(), CloseDecision::Ask);
+ guard.answered(false);
+ // The run is still going, so the next attempt is a fresh question and
+ // not a silent close.
+ assert_eq!(guard.on_close_requested(), CloseDecision::Ask);
+ }
+
+ #[test]
+ fn confirming_lets_the_window_go() {
+ let guard = generating();
+ assert_eq!(guard.on_close_requested(), CloseDecision::Ask);
+ guard.answered(true);
+ // destroy() can itself raise a close request; if the flag were still
+ // set the guard would ask again and the window would never shut.
+ assert_eq!(guard.on_close_requested(), CloseDecision::Close);
+ }
+
+ #[test]
+ fn a_run_that_finishes_first_takes_the_guard_back_out_of_the_way() {
+ let guard = generating();
+ guard.generation_active.store(false, Ordering::Release);
+ assert_eq!(guard.on_close_requested(), CloseDecision::Close);
+ }
+}
diff --git a/src/App.tsx b/src/App.tsx
index 2dccd27..420b6d4 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -1,11 +1,14 @@
+import { invoke } from "@tauri-apps/api/core";
+import { listen } from "@tauri-apps/api/event";
import { FolderOpen, Grid2X2, List, Search, Settings } from "lucide-react";
-import { useEffect, useMemo, useRef, useState } from "react";
+import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { Brand } from "./components/Brand";
+import { ExitGuardDialog, type OngoingGeneration } from "./components/ExitGuardDialog";
import { ProjectCard } from "./components/ProjectCard";
import { ProjectWorkspace, type ProjectView } from "./components/ProjectWorkspace";
import { PromptComposer } from "./components/PromptComposer";
import { SettingsView } from "./components/SettingsView";
-import { chooseAndOpenProject, createProject, listRecentProjects, saveProject } from "./lib/persistence";
+import { chooseAndOpenProject, createProject, isTauri, listRecentProjects, saveProject } from "./lib/persistence";
import type { CreateProjectInput, ProjectRecord } from "./lib/project";
import { getRuntimeStatus, type RuntimeStatus } from "./lib/runtime";
@@ -43,6 +46,43 @@ function App() {
const [runtime, setRuntime] = useState<RuntimeStatus | null>(null);
const searchInput = useRef<HTMLInputElement>(null);
+ /* ── Exit guard: the window's close button ───────────────────────────────
+ The video engine runs inside this process, so closing the window ends a
+ generation outright, and nothing partial is written on the way. The open
+ project reports what it has running; Rust holds the close request back
+ only while that list is non-empty, and this is where the question is put
+ and answered. See the fenced block in src-tauri/src/lib.rs. */
+ const [ongoingGenerations, setOngoingGenerations] = useState<OngoingGeneration[]>([]);
+ const [closeRequested, setCloseRequested] = useState(false);
+
+ const answerClose = useCallback((confirmed: boolean) => {
+ setCloseRequested(false);
+ if (isTauri()) void invoke("answer_app_close", { confirmed }).catch(() => undefined);
+ }, []);
+
+ useEffect(() => {
+ if (!isTauri()) return;
+ void invoke("set_generation_active", { active: ongoingGenerations.length > 0 }).catch(() => undefined);
+ }, [ongoingGenerations.length]);
+
+ useEffect(() => {
+ if (!isTauri()) return;
+ let disposed = false;
+ const subscription = listen("app-close-requested", () => { if (!disposed) setCloseRequested(true); });
+ return () => { disposed = true; void subscription.then((stop) => stop()).catch(() => undefined); };
+ }, []);
+
+ /* The last shot can finish between the click on the close button and this
+ question reaching the screen. There is then nothing to warn about, and a
+ dialog listing no shots would be the app refusing to close for no reason. */
+ useEffect(() => {
+ if (closeRequested && ongoingGenerations.length === 0) answerClose(true);
+ }, [closeRequested, ongoingGenerations.length, answerClose]);
+
+ const exitGuard = closeRequested && ongoingGenerations.length > 0
+ ? <ExitGuardDialog jobs={ongoingGenerations} destination="quit" onConfirm={() => answerClose(true)} onCancel={() => answerClose(false)} />
+ : null;
+
useEffect(() => {
void listRecentProjects()
.then(({ projects: loaded, unreadable }) => {
@@ -133,13 +173,14 @@ function App() {
if (activeProject) {
return <>
- <ProjectWorkspace project={activeProject} initialView={activeProjectInitialView} runtime={runtime} onBack={() => setActiveProject(null)} onSave={async (project) => {
+ <ProjectWorkspace project={activeProject} initialView={activeProjectInitialView} runtime={runtime} onOngoingGenerationsChange={setOngoingGenerations} onBack={() => setActiveProject(null)} onSave={async (project) => {
const saved = await saveProject(project);
setActiveProject(saved);
setProjects((current) => [saved, ...current.filter((item) => item.config.id !== saved.config.id)]);
}} />
{settingsLauncher}
{settingsOpen && <SettingsView onClose={closeSettings} />}
+ {exitGuard}
</>;
}
@@ -190,6 +231,7 @@ function App() {
</main>
{settingsLauncher}
{settingsOpen && <SettingsView onClose={closeSettings} />}
+ {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/components/ExitGuardDialog.test.tsx b/src/components/ExitGuardDialog.test.tsx
new file mode 100644
index 0000000..0eb3cfd
--- /dev/null
+++ b/src/components/ExitGuardDialog.test.tsx
@@ -0,0 +1,153 @@
+// @vitest-environment jsdom
+
+import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
+import { createElement } from "react";
+import { afterEach, describe, expect, it, vi } from "vitest";
+import { createProjectConfig, type GenerationJob, type ProjectConfig } from "../lib/project";
+import { ExitGuardDialog, summary } from "./ExitGuardDialog";
+import { isGenerationOngoing, ProjectWorkspace } from "./ProjectWorkspace";
+
+vi.mock("@tauri-apps/api/core", () => ({ invoke: vi.fn() }));
+
+afterEach(cleanup);
+
+const base = () => createProjectConfig({ name: "Ceramic lamp", prompt: "A quiet product film", aspectRatio: "16:9", resolution: "1080p", targetDurationSeconds: 30 });
+
+/** A project with `statuses.length` extra shots, one per status. */
+function withJobs(statuses: GenerationJob["status"][]): ProjectConfig {
+ const config = base();
+ const now = new Date().toISOString();
+ const jobs: GenerationJob[] = statuses.map((status, index) => ({
+ id: `job-${index}`, title: `Shot ${index + 1}`, prompt: "a slow push across the launch pad",
+ status, stage: status === "generating" ? "generating" : "queued", progress: 0,
+ providerId: "minimax-h3", creativeBrief: "a slow push across the launch pad",
+ compiledPrompt: "a slow push across the launch pad", referenceIds: [], createdAt: now, updatedAt: now,
+ }));
+ return { ...config, generationJobs: [...jobs, ...config.generationJobs] };
+}
+
+const workspace = (config: ProjectConfig, onBack: () => void) =>
+ render(createElement(ProjectWorkspace, { project: { folderPath: "C:\\Ceramic Lamp", config }, initialView: "timeline", onBack, onSave: async () => undefined }));
+
+describe("the one definition of an ongoing generation", () => {
+ it("is the pair of statuses the Generator queues shots through, and nothing else", () => {
+ const statuses: GenerationJob["status"][] = ["draft", "queued", "generating", "ready", "completed", "failed", "cancelled"];
+ const ongoing = statuses.filter((status) => isGenerationOngoing({ status } as GenerationJob));
+ expect(ongoing).toEqual(["queued", "generating"]);
+ });
+
+ it("counts what is happening without rounding a queued shot up into a rendering one", () => {
+ expect(summary(1, 0)).toBe("1 shot is rendering now.");
+ expect(summary(0, 2)).toBe("2 shots are waiting in the queue.");
+ expect(summary(1, 3)).toBe("1 shot is rendering now and 3 shots are waiting in the queue.");
+ });
+});
+
+describe("leaving a project", () => {
+ it("goes straight back when nothing is generating", () => {
+ const onBack = vi.fn();
+ workspace(withJobs(["draft", "completed", "failed", "cancelled", "ready"]), onBack);
+ fireEvent.click(screen.getByRole("button", { name: "Back to project library" }));
+ expect(onBack).toHaveBeenCalledTimes(1);
+ expect(screen.queryByRole("alertdialog")).toBeNull();
+ });
+
+ it("asks first mid-generation, and stays put until the answer comes", () => {
+ const onBack = vi.fn();
+ workspace(withJobs(["generating", "queued"]), onBack);
+ fireEvent.click(screen.getByRole("button", { name: "Back to project library" }));
+
+ const dialog = screen.getByRole("alertdialog");
+ expect(onBack).not.toHaveBeenCalled();
+ // It says what is running and what confirming costs — both checkable
+ // claims about this codebase, not a vague warning.
+ expect(dialog.textContent).toContain("1 shot is rendering now and 1 shot is waiting in the queue.");
+ expect(dialog.textContent).toContain("No video file is written until a shot finishes");
+ expect(dialog.textContent).toContain("can’t pick one back up");
+ });
+
+ it("puts the user back exactly where they were when they cancel", () => {
+ const onBack = vi.fn();
+ workspace(withJobs(["generating"]), onBack);
+ const back = screen.getByRole("button", { name: "Back to project library" });
+ // jsdom does not move focus on a click the way a browser does, and the
+ // whole point of this test is where focus goes back TO.
+ back.focus();
+ fireEvent.click(back);
+ fireEvent.click(screen.getByRole("button", { name: "Keep generating" }));
+
+ expect(onBack).not.toHaveBeenCalled();
+ expect(screen.queryByRole("alertdialog")).toBeNull();
+ // Still in the project, on the same view, with the same shot generating.
+ expect(screen.getByRole("heading", { name: "Timeline", level: 2 })).toBeTruthy();
+ // And focus is back on the control that opened the question.
+ expect(document.activeElement).toBe(back);
+ });
+
+ it("closes on Escape without leaving", () => {
+ const onBack = vi.fn();
+ workspace(withJobs(["queued"]), onBack);
+ fireEvent.click(screen.getByRole("button", { name: "Back to project library" }));
+ fireEvent.keyDown(window, { key: "Escape" });
+ expect(screen.queryByRole("alertdialog")).toBeNull();
+ expect(onBack).not.toHaveBeenCalled();
+ });
+
+ it("leaves once, and only once, when the answer is yes", () => {
+ const onBack = vi.fn();
+ workspace(withJobs(["generating"]), onBack);
+ fireEvent.click(screen.getByRole("button", { name: "Back to project library" }));
+ fireEvent.click(screen.getByRole("button", { name: "Stop and leave" }));
+ expect(onBack).toHaveBeenCalledTimes(1);
+ });
+
+ it("reports what is generating to the app around it, and reports nothing once it unmounts", async () => {
+ const reported: string[][] = [];
+ const { unmount } = render(createElement(ProjectWorkspace, {
+ project: { folderPath: "C:\\Ceramic Lamp", config: withJobs(["generating", "queued", "draft"]) },
+ initialView: "timeline",
+ onBack: () => undefined,
+ onSave: async () => undefined,
+ onOngoingGenerationsChange: (jobs) => reported.push(jobs.map((job) => job.id)),
+ }));
+ await waitFor(() => expect(reported.length).toBeGreaterThan(0));
+ // The draft is not ongoing — a shot nobody has started costs nothing to
+ // walk away from.
+ expect(reported.at(-1)).toEqual(["job-0", "job-1"]);
+ unmount();
+ expect(reported.at(-1)).toEqual([]);
+ });
+});
+
+describe("the dialog on its own", () => {
+ const jobs = [
+ { id: "a", title: "Macro model details", running: true },
+ { id: "b", title: "Hands sketching elevation", running: false },
+ ];
+
+ it("keeps Tab inside itself and starts on the answer that changes nothing", () => {
+ render(createElement(ExitGuardDialog, { jobs, destination: "quit", onConfirm: () => undefined, onCancel: () => undefined }));
+ const keep = screen.getByRole("button", { name: "Keep generating" });
+ const stop = screen.getByRole("button", { name: "Stop and close" });
+ expect(document.activeElement).toBe(keep);
+
+ // Forward from the last stop wraps to the first; the browser handles the
+ // step in between, so what is under test is the wrap.
+ stop.focus();
+ fireEvent.keyDown(window, { key: "Tab" });
+ expect(document.activeElement).toBe(keep);
+ fireEvent.keyDown(window, { key: "Tab", shiftKey: true });
+ expect(document.activeElement).toBe(stop);
+ });
+
+ it("names the shots at stake and says which are only queued", () => {
+ const { container } = render(createElement(ExitGuardDialog, { jobs, destination: "quit", onConfirm: () => undefined, onCancel: () => undefined }));
+ const rows = Array.from(container.querySelectorAll(".exit-guard__jobs li")).map((row) => row.textContent);
+ expect(rows).toEqual(["Macro model detailsRendering now", "Hands sketching elevationWaiting to render"]);
+ });
+
+ it("says the window is what ends the run when that is the exit", () => {
+ render(createElement(ExitGuardDialog, { jobs, destination: "quit", onConfirm: () => undefined, onCancel: () => undefined }));
+ expect(screen.getByRole("alertdialog").textContent).toContain("The video engine runs inside PolStudio, so closing the window stops them.");
+ });
+});
diff --git a/src/components/ExitGuardDialog.tsx b/src/components/ExitGuardDialog.tsx
new file mode 100644
index 0000000..52533cb
--- /dev/null
+++ b/src/components/ExitGuardDialog.tsx
@@ -0,0 +1,141 @@
+import { AlertCircle, Clock3, LoaderCircle } from "lucide-react";
+import { useEffect, useRef } from "react";
+
+/** One generation the app is still working on, as the exit guard needs it.
+ * `running` separates the shot the engine is rendering right now from the ones
+ * behind it in the queue — the same split the Generator shows. */
+export interface OngoingGeneration {
+ id: string;
+ title: string;
+ running: boolean;
+}
+
+/** Where the user was heading when the guard stopped them. */
+export type ExitDestination = "library" | "quit";
+
+const FOCUSABLE = "button:not([disabled]), [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])";
+
+/** Asks before an exit that would throw away work the engine is still doing.
+ *
+ * Every claim it makes is a claim about this codebase, not a hedge:
+ * • vidfab writes no file of its own (see `run_generation` in vidfab.rs) and
+ * the finished frames only reach the app through the `vidfab-job` event,
+ * which is listened for inside the Generator. Leave the project or close
+ * the window and there is nothing on disk to come back to.
+ * • Nothing resumes. The only route back to a stopped shot is the Generator's
+ * "Run it again", which starts the whole render from the first step.
+ */
+export function ExitGuardDialog({ jobs, destination, onConfirm, onCancel }: {
+ jobs: OngoingGeneration[];
+ destination: ExitDestination;
+ onConfirm: () => void;
+ onCancel: () => void;
+}) {
+ const dialog = useRef<HTMLDivElement>(null);
+ const keepGenerating = useRef<HTMLButtonElement>(null);
+
+ /* Focus goes to "Keep generating" — the answer that changes nothing — and
+ comes back to whatever opened the dialog when it closes, so a keyboard user
+ is not dropped at the top of the document. */
+ useEffect(() => {
+ const opener = document.activeElement as HTMLElement | null;
+ keepGenerating.current?.focus();
+ return () => opener?.focus?.();
+ }, []);
+
+ useEffect(() => {
+ const onKeyDown = (event: KeyboardEvent) => {
+ if (event.key === "Escape") {
+ event.preventDefault();
+ onCancel();
+ return;
+ }
+ if (event.key !== "Tab" || !dialog.current) return;
+ // Tab must not walk out into the screen behind the dialog: it is still
+ // rendered, and a focus ring on a control the user cannot see is the same
+ // as losing focus altogether.
+ const stops = Array.from(dialog.current.querySelectorAll<HTMLElement>(FOCUSABLE));
+ if (stops.length === 0) return;
+ 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);
+ }, [onCancel]);
+
+ const rendering = jobs.filter((job) => job.running);
+ const queued = jobs.filter((job) => !job.running);
+ const leaving = destination === "library";
+
+ return (
+ <div className="exit-guard-backdrop" onMouseDown={(event) => { if (event.target === event.currentTarget) onCancel(); }}>
+ <div
+ className="exit-guard"
+ ref={dialog}
+ role="alertdialog"
+ aria-modal="true"
+ aria-labelledby="exit-guard-title"
+ aria-describedby="exit-guard-body"
+ >
+ <div className="exit-guard__head">
+ <span className="exit-guard__mark" aria-hidden="true"><AlertCircle size={20} /></span>
+ <h2 id="exit-guard-title">
+ {leaving ? "Leave the project and stop generating?" : "Close PolStudio and stop generating?"}
+ </h2>
+ </div>
+
+ <div className="exit-guard__body" id="exit-guard-body">
+ <p>{summary(rendering.length, queued.length)}</p>
+ <p>
+ {leaving
+ ? "Going back to your projects stops them. "
+ : "The video engine runs inside PolStudio, so closing the window stops them. "}
+ No video file is written until a shot finishes, so an unfinished run leaves nothing behind — and PolStudio
+ can’t pick one back up. You would run those shots again from the beginning.
+ </p>
+ </div>
+
+ {jobs.length > 0 && (
+ <ul className="exit-guard__jobs">
+ {jobs.slice(0, 4).map((job) => (
+ <li key={job.id}>
+ {job.running ? <LoaderCircle size={15} aria-hidden="true" /> : <Clock3 size={15} aria-hidden="true" />}
+ <b>{job.title}</b>
+ <em>{job.running ? "Rendering now" : "Waiting to render"}</em>
+ </li>
+ ))}
+ {jobs.length > 4 && <li className="exit-guard__more">and {jobs.length - 4} more</li>}
+ </ul>
+ )}
+
+ <div className="exit-guard__actions">
+ <button className="secondary-button" type="button" ref={keepGenerating} onClick={onCancel}>
+ Keep generating
+ </button>
+ <button className="exit-guard__confirm" type="button" onClick={onConfirm}>
+ {leaving ? "Stop and leave" : "Stop and close"}
+ </button>
+ </div>
+ </div>
+ </div>
+ );
+}
+
+/** Counts what is actually happening, in the words the Generator uses for the
+ * same two states. Never rounds a queued shot up into a rendering one. */
+export function summary(rendering: number, queued: number): string {
+ const parts: string[] = [];
+ if (rendering > 0) parts.push(`${rendering} ${rendering === 1 ? "shot is" : "shots are"} rendering now`);
+ if (queued > 0) parts.push(`${queued} ${queued === 1 ? "shot is" : "shots are"} waiting in the queue`);
+ if (parts.length === 0) return "Nothing is generating right now.";
+ const sentence = parts.join(" and ");
+ return `${sentence.charAt(0).toUpperCase()}${sentence.slice(1)}.`;
+}
diff --git a/src/components/ProjectWorkspace.tsx b/src/components/ProjectWorkspace.tsx
index e420ed6..30f5b57 100644
Binary files a/src/components/ProjectWorkspace.tsx and b/src/components/ProjectWorkspace.tsx differ
diff --git a/src/styles/exit-guard.css b/src/styles/exit-guard.css
new file mode 100644
index 0000000..5887df2
--- /dev/null
+++ b/src/styles/exit-guard.css
@@ -0,0 +1,172 @@
+/* ============================================================================
+ exit-guard.css — the confirmation shown before an exit that would throw away
+ a generation the engine is still working on.
+
+ Colours come from tokens.css only. The scrim is painted by a ::before layer
+ rather than an rgba() literal so it follows whatever --bg becomes: a hard
+ -coded dark wash would be a white-on-white bug the day a light theme lands.
+ ========================================================================== */
+
+.exit-guard-backdrop {
+ position: fixed;
+ z-index: 200; /* above the settings overlay and toasts */
+ inset: 0;
+ display: grid;
+ place-items: center;
+ padding: var(--space-5);
+}
+
+.exit-guard-backdrop::before {
+ content: "";
+ position: absolute;
+ inset: 0;
+ background: var(--bg);
+ opacity: 0.82;
+ backdrop-filter: blur(5px);
+}
+
+.exit-guard {
+ position: relative; /* clears the scrim */
+ width: min(520px, 100%);
+ display: grid;
+ gap: var(--space-4);
+ padding: var(--space-6);
+ border: 1px solid var(--line-strong);
+ border-radius: var(--radius-lg);
+ background: var(--panel-2);
+ box-shadow: var(--shadow);
+}
+
+.exit-guard__head {
+ display: flex;
+ align-items: center;
+ gap: var(--space-3);
+}
+
+.exit-guard__mark {
+ width: var(--control-sm);
+ height: var(--control-sm);
+ flex: none;
+ display: grid;
+ place-items: center;
+ border-radius: var(--radius-md);
+ border: 1px solid var(--danger);
+ color: var(--danger);
+ background: var(--panel-3);
+}
+
+.exit-guard__head h2 {
+ margin: 0;
+ color: var(--text-primary);
+ font-size: var(--text-lg);
+ font-weight: var(--weight-semibold);
+ line-height: var(--leading-snug);
+}
+
+.exit-guard__body {
+ display: grid;
+ gap: var(--space-3);
+}
+
+.exit-guard__body p {
+ margin: 0;
+ color: var(--text-secondary);
+ font-size: var(--text-base);
+ line-height: var(--leading-normal);
+}
+
+.exit-guard__body p:first-child {
+ color: var(--text-primary);
+ font-weight: var(--weight-semibold);
+}
+
+.exit-guard__jobs {
+ max-height: 40vh;
+ overflow-y: auto;
+ margin: 0;
+ padding: 0;
+ list-style: none;
+ display: grid;
+ gap: var(--space-1);
+}
+
+.exit-guard__jobs li {
+ min-height: var(--control-sm);
+ display: flex;
+ align-items: center;
+ gap: var(--space-2);
+ padding: var(--space-2) var(--space-3);
+ border: 1px solid var(--line);
+ border-radius: var(--radius-md);
+ background: var(--panel-3);
+ color: var(--text-muted);
+}
+
+.exit-guard__jobs b {
+ min-width: 0;
+ flex: 1;
+ overflow: hidden;
+ white-space: nowrap;
+ text-overflow: ellipsis;
+ color: var(--text-secondary);
+ font-size: var(--text-sm);
+ font-weight: var(--weight-medium);
+}
+
+.exit-guard__jobs em {
+ flex: none;
+ color: var(--text-faint);
+ font-size: var(--text-2xs);
+ font-style: normal;
+ font-family: var(--font-mono);
+ letter-spacing: var(--tracking-label);
+ text-transform: uppercase;
+}
+
+.exit-guard__jobs .exit-guard__more {
+ border: 0;
+ background: none;
+ color: var(--text-faint);
+ font-size: var(--text-xs);
+}
+
+.exit-guard__actions {
+ display: flex;
+ justify-content: flex-end;
+ gap: var(--space-3);
+}
+
+/* The destructive answer. .danger-button is a full-width block used inside the
+ Generator's inspector column, so it cannot sit in a row of two; this is the
+ same colour contract at button-row proportions. */
+.exit-guard__confirm {
+ min-height: var(--control-lg);
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ gap: var(--space-2);
+ padding: 0 var(--space-5);
+ border: 1px solid var(--danger);
+ border-radius: var(--radius-md);
+ color: var(--danger);
+ background: var(--panel-3);
+ font-size: var(--text-base);
+ font-weight: var(--weight-semibold);
+ line-height: var(--leading-snug);
+ transition: 0.18s ease;
+}
+
+.exit-guard__confirm:hover {
+ color: var(--text-primary);
+ background: var(--panel);
+}
+
+@media (max-width: 560px) {
+ .exit-guard__actions {
+ flex-direction: column-reverse;
+ }
+
+ .exit-guard__actions > * {
+ width: 100%;
+ }
+}
diff --git a/src/styles/index.css b/src/styles/index.css
index 327a654..8e3c1d1 100644
--- a/src/styles/index.css
+++ b/src/styles/index.css
@@ -23,3 +23,4 @@
@import "./timeline.css";
@import "./references.css";
@import "./export.css";
+@import "./exit-guard.css";