AI media harness for planning, generating, and editing locally
TypeScript
Gate debug prompts behind settings
Bitti2190b7bd4f8b
diff --git a/src/components/ProjectWorkspace.test.ts b/src/components/ProjectWorkspace.test.tsindex 22df265..7fffd53 100644--- a/src/components/ProjectWorkspace.test.ts+++ b/src/components/ProjectWorkspace.test.ts@@ -13,12 +13,16 @@ import { GeneratorView } from "./workspace/GeneratorView";import { REFERENCE_DRAG_TYPE } from "./workspace/SceneEditor";import { ReferencesView } from "./workspace/ReferencesView";import { TimelineView } from "./workspace/TimelineView";+import { saveDebugOptionsEnabled } from "../lib/settings";vi.mock("@tauri-apps/api/core", () => ({ invoke: vi.fn() }));vi.mock("@tauri-apps/api/event", () => ({ listen: vi.fn(async () => () => undefined) }));vi.mock("../lib/generatedVideo", () => ({ saveGeneratedScene: vi.fn() }));-afterEach(cleanup);+afterEach(() => {+ cleanup();+ saveDebugOptionsEnabled(false);+});/** Runs `body` with the app believing it is inside the desktop shell, so the* REAL Tauri import path executes instead of the browser fallback. */@@ -995,6 +999,7 @@ describe("project workspace timecode", () => {});it("counts only the references that actually reach the compiled prompt", () => {+ saveDebugOptionsEnabled(true);const fresh = createProjectConfig({ name: "Ceramic lamp", prompt: "A quiet product film", aspectRatio: "16:9", resolution: "1080p", targetDurationSeconds: 30 });const createdAt = fresh.createdAt;const references = [@@ -1006,9 +1011,9 @@ describe("project workspace timecode", () => {];const config = parseProjectConfig({ ...fresh, references, generationJobs: [{ ...fresh.generationJobs[0], referenceIds: ["ref-lamp", "ref-blank", "ref-score"] }] });render(createElement(GeneratorView, { config, folderPath: "C:\\Ceramic Lamp", onChange: () => undefined, onOpenTimeline: () => undefined, selectedJobId: config.generationJobs[0].id }));- expect(document.querySelector(".debug-prompt .compiled-prompt__text")).toBeNull();+ expect(document.querySelector(".debug-prompt-dialog .compiled-prompt__text")).toBeNull();fireEvent.click(screen.getByRole("button", { name: "Debug Prompt" }));- const prompt = document.querySelector(".debug-prompt .compiled-prompt__text")!.textContent!;+ const prompt = document.querySelector(".debug-prompt-dialog .compiled-prompt__text")!.textContent!;expect(prompt).toContain("<Subject 1>");expect(prompt).not.toContain("Lead character");expect(prompt).not.toContain("Score idea");@@ -1239,6 +1244,7 @@ describe("project workspace timecode", () => {/** Opens the exact prompt preview without accidentally closing it when a* test returns to the scene panel more than once. */const openDebugPrompt = () => {+ act(() => saveDebugOptionsEnabled(true));const button = screen.getByRole("button", { name: "Debug Prompt" });if (button.getAttribute("aria-expanded") === "false") fireEvent.click(button);};diff --git a/src/components/SettingsView.test.tsx b/src/components/SettingsView.test.tsxindex 3c96d34..c67a5d0 100644--- a/src/components/SettingsView.test.tsx+++ b/src/components/SettingsView.test.tsx@@ -36,6 +36,21 @@ describe("the frame the tabs sit in", () => {});describe("the settings screen", () => {+ it("keeps debug options off by default and remembers the Diagnostics choice", () => {+ const view = open();+ fireEvent.click(tab("Diagnostics"));+ const toggle = screen.getByRole("checkbox", { name: "Enable debug options" }) as HTMLInputElement;+ expect(toggle.checked).toBe(false);+ fireEvent.click(toggle);+ view.unmount();+ open();+ fireEvent.click(tab("Diagnostics"));+ const restored = screen.getByRole("checkbox", { name: "Enable debug options" }) as HTMLInputElement;+ expect(restored.checked).toBe(true);+ fireEvent.click(restored);+ expect(restored.checked).toBe(false);+ });+it("opens on the engine, because that is what has to be set before anything renders", async () => {open();expect(tab("Video engine").getAttribute("aria-selected")).toBe("true");diff --git a/src/components/SettingsView.tsx b/src/components/SettingsView.tsxindex d984f3c..a9d8ffb 100644--- a/src/components/SettingsView.tsx+++ b/src/components/SettingsView.tsx@@ -1,5 +1,5 @@import { AlertCircle, Check, ChevronLeft, FileText, FolderOpen, FolderSearch, LoaderCircle, Monitor, Moon, Plus, RefreshCw, RotateCcw, Sun, Trash2, X } from "lucide-react";-import { useCallback, useEffect, useState } from "react";+import { useCallback, useEffect, useState, useSyncExternalStore } from "react";import { getDiagnosticLogInfo, revealDiagnosticLog, type DiagnosticLogInfo } from "../lib/diagnostics";import { isTauri } from "../lib/persistence";import { chooseEnginePath, getAgentModels, getEngineStatus, type ModelStatus, type SlopfabStatus } from "../lib/runtime";@@ -8,6 +8,7 @@ import {createGeneratorTemplate, defaultGeneratorTemplate,isEndpointProviderConfigured, loadAgentEndpointSettings,loadGeneratorTemplateSettings, saveAgentEndpointSettings, saveGeneratorTemplateSettings,+ loadDebugOptionsEnabled, saveDebugOptionsEnabled, subscribeDebugOptions,type AgentEndpointSettings, type EndpointProviderId, type EndpointProviderSettings,type EnginePathField, type EnginePathId, type EngineSettings, type GeneratorTemplateSettings,} from "../lib/settings";@@ -177,6 +178,7 @@ function PromptLlmSetting({ desktop }: { desktop: boolean }) {}function DiagnosticsSetting({ desktop }: { desktop: boolean }) {+ const debugEnabled = useSyncExternalStore(subscribeDebugOptions, loadDebugOptionsEnabled);const [info, setInfo] = useState<DiagnosticLogInfo | null>(null);const [opening, setOpening] = useState(false);const [error, setError] = useState<string | null>(null);@@ -199,20 +201,26 @@ function DiagnosticsSetting({ desktop }: { desktop: boolean }) {}};- return <div className="diagnostics-setting">- <div className="diagnostics-setting__icon"><FileText size={22} aria-hidden="true" /></div>- <div>- <h2>Application log</h2>- <p>Slopus records startup, runtime checks, generation stages, encoding, file writes, and unexpected errors in a readable text log. The file rotates at 5 MB and keeps one previous file.</p>- <p>Prompt text and credentials are not recorded. Sensitive fields are redacted again when each record is written.</p>- <code title={info?.path}>{desktop ? info?.path ?? "Locating the log…" : "Available in the desktop app"}</code>- {info?.previousPath && <small>A previous rotated log is stored beside this file.</small>}- <button type="button" className="secondary-button" disabled={!desktop || opening} onClick={() => void reveal()}>- {opening ? <LoaderCircle className="spin" size={16} /> : <FolderOpen size={16} />} Show log file- </button>- {error && <p className="diagnostics-setting__error" role="alert">{error}</p>}+ return <>+ <label className="diagnostics-debug-option">+ <input type="checkbox" checked={debugEnabled} onChange={(event) => saveDebugOptionsEnabled(event.target.checked)} aria-labelledby="debug-options-label" aria-describedby="debug-options-description" />+ <span><b id="debug-options-label">Enable debug options</b><small id="debug-options-description">Show the Debug Prompt button in scene settings.</small></span>+ </label>+ <div className="diagnostics-setting">+ <div className="diagnostics-setting__icon"><FileText size={22} aria-hidden="true" /></div>+ <div>+ <h2>Application log</h2>+ <p>Slopus records startup, runtime checks, generation stages, encoding, file writes, and unexpected errors in a readable text log. The file rotates at 5 MB and keeps one previous file.</p>+ <p>Prompt text and credentials are not recorded. Sensitive fields are redacted again when each record is written.</p>+ <code title={info?.path}>{desktop ? info?.path ?? "Locating the log…" : "Available in the desktop app"}</code>+ {info?.previousPath && <small>A previous rotated log is stored beside this file.</small>}+ <button type="button" className="secondary-button" disabled={!desktop || opening} onClick={() => void reveal()}>+ {opening ? <LoaderCircle className="spin" size={16} /> : <FolderOpen size={16} />} Show log file+ </button>+ {error && <p className="diagnostics-setting__error" role="alert">{error}</p>}+ </div></div>- </div>;+ </>;}/* Two things live on this screen and they have nothing to do with each other:diff --git a/src/components/workspace/DebugPromptDialog.tsx b/src/components/workspace/DebugPromptDialog.tsxnew file mode 100644index 0000000..4856fdc--- /dev/null+++ b/src/components/workspace/DebugPromptDialog.tsx@@ -0,0 +1,48 @@+import { X } from "lucide-react";+import { useEffect, useRef } from "react";+import { createPortal } from "react-dom";+import type { PromptSegment } from "../../lib/project";++export function DebugPromptDialog({ sceneTitle, segments, onClose }: {+ sceneTitle: string;+ segments: PromptSegment[];+ onClose: () => void;+}) {+ const closeButton = useRef<HTMLButtonElement>(null);+ const prompt = useRef<HTMLPreElement>(null);++ useEffect(() => {+ const opener = document.activeElement as HTMLElement | null;+ closeButton.current?.focus();+ return () => { if (opener?.isConnected) opener.focus(); };+ }, []);++ useEffect(() => {+ const keyDown = (event: KeyboardEvent) => {+ if (event.key === "Escape") {+ event.preventDefault();+ event.stopPropagation();+ onClose();+ } else if (event.key === "Tab") {+ event.preventDefault();+ (document.activeElement === closeButton.current ? prompt.current : closeButton.current)?.focus();+ }+ };+ window.addEventListener("keydown", keyDown, true);+ return () => window.removeEventListener("keydown", keyDown, true);+ }, [onClose]);++ return createPortal(<div className="debug-prompt-backdrop" onMouseDown={(event) => {+ if (event.target === event.currentTarget) onClose();+ }}>+ <section className="debug-prompt-dialog" role="dialog" aria-modal="true" aria-labelledby="debug-prompt-title" aria-describedby="debug-prompt-scene">+ <header className="debug-prompt-dialog__header">+ <div><h2 id="debug-prompt-title">Debug Prompt</h2><p id="debug-prompt-scene">{sceneTitle}</p></div>+ <button ref={closeButton} type="button" className="icon-button icon-button--strong" aria-label="Close debug prompt" onClick={onClose}><X size={18} /></button>+ </header>+ {/* Render compiler segments directly to preserve the exact engine prompt. */}+ <pre ref={prompt} tabIndex={0} className="compiled-prompt__text" aria-label="The compiled MiniMax H3 prompt">{segments.map((segment, index) =>+ <span key={index} className={`prompt-part prompt-part--${segment.kind}`}>{segment.value}</span>)}</pre>+ </section>+ </div>, document.body);+}diff --git a/src/components/workspace/GeneratorView.test.tsx b/src/components/workspace/GeneratorView.test.tsxindex f001396..bfb185e 100644--- a/src/components/workspace/GeneratorView.test.tsx+++ b/src/components/workspace/GeneratorView.test.tsx@@ -7,6 +7,7 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "viteimport { createDraftGenerationJob, createProjectConfig, parseProjectConfig, sceneShots, type ProjectConfig } from "../../lib/project";import { cancelSlopfabGeneration, getEngineStatus, type SlopfabStatus } from "../../lib/runtime";import { GeneratorView } from "./GeneratorView";+import { saveDebugOptionsEnabled } from "../../lib/settings";vi.mock("../../lib/runtime", async (importOriginal) => ({...await importOriginal<typeof import("../../lib/runtime")>(),@@ -107,6 +108,34 @@ async function finishFirst(state: ReturnType<typeof setup>) {}describe("Generator scene controls", () => {+ it("only shows debug prompts when enabled, in a closable popup outside the inspector", () => {+ setup();+ expect(screen.queryByRole("button", { name: "Debug Prompt" })).not.toBeInTheDocument();+ act(() => saveDebugOptionsEnabled(true));+ const button = screen.getByRole("button", { name: "Debug Prompt" });+ button.focus();+ fireEvent.click(button);+ const dialog = screen.getByRole("dialog", { name: "Debug Prompt" });+ expect(dialog.closest("aside")).toBeNull();+ expect(within(dialog).getByLabelText("The compiled MiniMax H3 prompt")).toHaveTextContent("Opening action");+ expect(within(dialog).getByRole("button", { name: "Close debug prompt" })).toHaveFocus();+ fireEvent.keyDown(window, { key: "Tab" });+ expect(within(dialog).getByLabelText("The compiled MiniMax H3 prompt")).toHaveFocus();+ fireEvent.keyDown(window, { key: "Escape" });+ expect(screen.queryByRole("dialog", { name: "Debug Prompt" })).not.toBeInTheDocument();+ expect(button).toHaveFocus();+ fireEvent.click(button);+ fireEvent.click(screen.getByRole("button", { name: "Close debug prompt" }));+ expect(screen.queryByRole("dialog", { name: "Debug Prompt" })).not.toBeInTheDocument();+ fireEvent.click(button);+ fireEvent.mouseDown(screen.getByRole("dialog", { name: "Debug Prompt" }).parentElement!);+ expect(screen.queryByRole("dialog", { name: "Debug Prompt" })).not.toBeInTheDocument();+ fireEvent.click(button);+ act(() => saveDebugOptionsEnabled(false));+ expect(screen.queryByRole("button", { name: "Debug Prompt" })).not.toBeInTheDocument();+ expect(screen.queryByRole("dialog", { name: "Debug Prompt" })).not.toBeInTheDocument();+ });+it("offers no inferred Look and sends a selected image as the scene's first frame", async () => {const initial = project();initial.references = [{diff --git a/src/components/workspace/GeneratorView.tsx b/src/components/workspace/GeneratorView.tsxindex 965469c..7dc0075 100644--- a/src/components/workspace/GeneratorView.tsx+++ b/src/components/workspace/GeneratorView.tsx@@ -1,8 +1,8 @@import { ChevronDown, Plus, Sparkles, Square, Trash2, WandSparkles } from "lucide-react";import { invoke } from "@tauri-apps/api/core";-import { useEffect, useMemo, useRef, useState } from "react";+import { useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";import { describeDiagnosticError, errorContext, writeDiagnostic } from "../../lib/diagnostics";-import { actionReferenceIds, compileGenerationJobPrompt, compileGenerationJobSegments, createDraftGenerationJob, danglingReferenceTokens, GENERATION_FRAME_RATE, RANDOM_GENERATION_SEED, sceneDurationSeconds, sceneGenerationReferences, sceneGenerationSeed, sceneGenerationSnapshot, sceneGenerationSteps, sceneShots, SCENE_MAX_SECONDS, SCENE_MIN_SECONDS, projectItemPath, usableReferenceImages, type GenerationJob, type ProjectConfig, type ProjectReference, type PromptSegment, type SceneShot } from "../../lib/project";+import { actionReferenceIds, compileGenerationJobPrompt, compileGenerationJobSegments, createDraftGenerationJob, danglingReferenceTokens, GENERATION_FRAME_RATE, RANDOM_GENERATION_SEED, sceneDurationSeconds, sceneGenerationReferences, sceneGenerationSeed, sceneGenerationSnapshot, sceneGenerationSteps, sceneShots, SCENE_MAX_SECONDS, SCENE_MIN_SECONDS, projectItemPath, usableReferenceImages, type GenerationJob, type ProjectConfig, type ProjectReference, type SceneShot } from "../../lib/project";import { generationDimensions } from "../../lib/export";import { isTauri } from "../../lib/persistence";import { cancelSlopfabGeneration, enqueueSlopfabGeneration, getEngineStatus, resolveSlopfabPlan, type SlopfabGenerationRequest, type SlopfabStatus } from "../../lib/runtime";@@ -11,7 +11,8 @@ import { SceneInspector, ShotInspector, STEP_SECONDS, writeShots } from "./Sceneimport { statusIcon } from "./sceneStatus";import { forgetShotPosters } from "./ShotThumbnail";import { purgeTimelineThumbnails } from "../../lib/timelineThumbnails";-import { defaultGeneratorTemplate, loadGeneratorTemplateSettings, saveGeneratorTemplateSettings, type GeneratorTemplate } from "../../lib/settings";+import { defaultGeneratorTemplate, loadDebugOptionsEnabled, loadGeneratorTemplateSettings, saveGeneratorTemplateSettings, subscribeDebugOptions, type GeneratorTemplate } from "../../lib/settings";+import { DebugPromptDialog } from "./DebugPromptDialog";interface GeneratorViewProps {config: ProjectConfig;@@ -65,8 +66,13 @@ export function GeneratorView({ config, folderPath, runtime = null, generationCoconst [, setPlanNotes] = useState<Record<string, string>>({});const [removalTarget, setRemovalTarget] = useState<RemovalTarget | null>(null);const [showDebugPrompt, setShowDebugPrompt] = useState(false);+ const debugEnabled = useSyncExternalStore(subscribeDebugOptions, loadDebugOptionsEnabled);const [startFrameError, setStartFrameError] = useState<string | null>(null);+ useEffect(() => {+ if (!debugEnabled) setShowDebugPrompt(false);+ }, [debugEnabled]);+useEffect(() => {setTemplateSettings(loadGeneratorTemplateSettings());setGeneratorRuntime(runtime);@@ -683,18 +689,24 @@ export function GeneratorView({ config, folderPath, runtime = null, generationCo/></div>- <div className="debug-prompt">- {showDebugPrompt && <CompiledPrompt segments={compileGenerationJobSegments(selected, boundRefs)} />}+ {debugEnabled && <div className="debug-prompt"><buttontype="button"className="secondary-button debug-prompt__toggle"aria-expanded={showDebugPrompt}- onClick={() => setShowDebugPrompt((visible) => !visible)}+ aria-haspopup="dialog"+ onClick={() => setShowDebugPrompt(true)}>Debug Prompt</button>- </div>+ </div>}</>}</aside>}+ {debugEnabled && showDebugPrompt && selected && !openShot && <DebugPromptDialog+ sceneTitle={selected.title}+ segments={compileGenerationJobSegments(selected, boundRefs)}+ onClose={() => setShowDebugPrompt(false)}+ />}+{removalTarget && <div className="remove-dialog-backdrop"><div className="remove-dialog" role="alertdialog" aria-modal="true" aria-labelledby="remove-dialog-title"><h2 id="remove-dialog-title">Remove {removalTarget.kind}?</h2>@@ -733,16 +745,6 @@ function sendBlocker(job: GenerationJob, references: ProjectReference[]): stringreturn null;}-/* The compiled prompt, shown before anything is sent and coloured by who wrote- which part. The segments come from the compiler itself, so this panel is the- string slopfab receives — not a re-rendering of it that could drift. */-function CompiledPrompt({ segments }: { segments: PromptSegment[] }) {- return <section className="compiled-prompt" aria-label="The compiled MiniMax H3 prompt">- <pre className="compiled-prompt__text">{segments.map((segment, index) =>- <span key={index} className={`prompt-part prompt-part--${segment.kind}`}>{segment.value}</span>)}</pre>- </section>;-}-const boardSummary = (active: number, waiting: number, total: number) => {if (total === 0) return "Nothing here yet";if (active > 0) return `${active} rendering · ${waiting} waiting`;diff --git a/src/lib/settings.ts b/src/lib/settings.tsindex 36ffa5a..09f9b82 100644--- a/src/lib/settings.ts+++ b/src/lib/settings.ts@@ -309,6 +309,40 @@ export function saveAgentProvider(provider: ProviderId): void {}}+/* --- Debug options --------------------------------------------------------- */++const DEBUG_OPTIONS_KEY = "slopus.debug-options.v1";+const DEBUG_OPTIONS_EVENT = "slopus:debug-options-changed";++export function loadDebugOptionsEnabled(): boolean {+ try {+ return localStorage.getItem(DEBUG_OPTIONS_KEY) === "true";+ } catch {+ return false;+ }+}++export function saveDebugOptionsEnabled(enabled: boolean): void {+ try {+ localStorage.setItem(DEBUG_OPTIONS_KEY, String(enabled));+ } catch {+ return;+ }+ window.dispatchEvent(new Event(DEBUG_OPTIONS_EVENT));+}++export function subscribeDebugOptions(listener: () => void): () => void {+ const onStorage = (event: StorageEvent) => {+ if (event.key === DEBUG_OPTIONS_KEY || event.key === null) listener();+ };+ window.addEventListener(DEBUG_OPTIONS_EVENT, listener);+ window.addEventListener("storage", onStorage);+ return () => {+ window.removeEventListener(DEBUG_OPTIONS_EVENT, listener);+ window.removeEventListener("storage", onStorage);+ };+}+/* --- Panel layout ----------------------------------------------------------How the media panel lays its footage out. A working habit, not a property ofany one project, so it lives beside the engine paths rather than indiff --git a/src/styles/generator.css b/src/styles/generator.cssindex 1d2a686..5c37a63 100644--- a/src/styles/generator.css+++ b/src/styles/generator.css@@ -1642,14 +1642,61 @@background: var(--panel);}-.debug-prompt .compiled-prompt {- margin: 0 0 var(--space-3);-}-.debug-prompt__toggle {width: 100%;}+.debug-prompt-backdrop {+ position: fixed;+ z-index: 120;+ inset: 0;+ display: grid;+ place-items: center;+ padding: var(--space-5);+ background: var(--scrim);+ backdrop-filter: blur(5px);+}++.debug-prompt-dialog {+ width: min(880px, 100%);+ max-height: calc(100dvh - 2 * var(--space-5));+ min-height: 0;+ display: flex;+ flex-direction: column;+ padding: var(--space-5);+ border: 1px solid var(--line-strong);+ border-radius: var(--radius-lg);+ background: var(--panel);+ box-shadow: var(--shadow);+}++.debug-prompt-dialog__header {+ flex: 0 0 auto;+ display: flex;+ align-items: flex-start;+ justify-content: space-between;+ gap: var(--space-4);+ margin-bottom: var(--space-4);+}++.debug-prompt-dialog__header h2 {+ margin: 0;+ color: var(--text-primary);+ font-size: var(--text-xl);+}++.debug-prompt-dialog__header p {+ margin: var(--space-1) 0 0;+ color: var(--text-muted);+ overflow-wrap: anywhere;+}++.debug-prompt-dialog .compiled-prompt__text {+ min-height: 0;+ max-height: none;+ padding: var(--space-4);+}+.remove-dialog-backdrop {position: fixed;z-index: 120;diff --git a/src/styles/shell.css b/src/styles/shell.cssindex c4d0664..0454312 100644--- a/src/styles/shell.css+++ b/src/styles/shell.css@@ -433,6 +433,37 @@/* --- Diagnostics ---------------------------------------------------------- */+.diagnostics-debug-option {+ display: flex;+ align-items: center;+ gap: var(--space-3);+ margin-bottom: var(--space-4);+ padding: var(--space-4) var(--space-5);+ border: 1px solid var(--line);+ border-radius: var(--radius-lg);+ background: var(--wash-1);+ cursor: pointer;+}++.diagnostics-debug-option input {+ width: 16px;+ height: 16px;+ margin: 0;+ accent-color: var(--accent);+}++.diagnostics-debug-option b {+ color: var(--text-primary);+ font-size: var(--text-sm);+}++.diagnostics-debug-option small {+ display: block;+ margin-top: var(--space-1);+ color: var(--text-muted);+ font-size: var(--text-sm);+}+.diagnostics-setting {display: grid;grid-template-columns: auto minmax(0, 1fr);