Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Add icon prompt debugging

Bittif4955f28babd
diff --git a/src/components/SettingsView.tsx b/src/components/SettingsView.tsx
index b6db4f5..4f9a2eb 100644
--- a/src/components/SettingsView.tsx
+++ b/src/components/SettingsView.tsx
@@ -219,7 +219,7 @@ function DiagnosticsSetting({ desktop }: { desktop: boolean }) {
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>
+ <span><b id="debug-options-label">Enable debug options</b><small id="debug-options-description">Show Debug Prompt in scene settings and Debug Icon Prompt in reference details.</small></span>
</label>
<div className="diagnostics-setting">
<div className="diagnostics-setting__icon"><FileText size={22} aria-hidden="true" /></div>
diff --git a/src/components/workspace/DebugPromptDialog.tsx b/src/components/workspace/DebugPromptDialog.tsx
index 4856fdc..9e24400 100644
--- a/src/components/workspace/DebugPromptDialog.tsx
+++ b/src/components/workspace/DebugPromptDialog.tsx
@@ -3,10 +3,12 @@ import { useEffect, useRef } from "react";
import { createPortal } from "react-dom";
import type { PromptSegment } from "../../lib/project";
-export function DebugPromptDialog({ sceneTitle, segments, onClose }: {
+export function DebugPromptDialog({ sceneTitle, segments, onClose, title = "Debug Prompt", promptLabel = "The compiled MiniMax H3 prompt" }: {
sceneTitle: string;
segments: PromptSegment[];
onClose: () => void;
+ title?: string;
+ promptLabel?: string;
}) {
const closeButton = useRef<HTMLButtonElement>(null);
const prompt = useRef<HTMLPreElement>(null);
@@ -37,11 +39,11 @@ export function DebugPromptDialog({ sceneTitle, segments, 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>
+ <div><h2 id="debug-prompt-title">{title}</h2><p id="debug-prompt-scene">{sceneTitle}</p></div>
+ <button ref={closeButton} type="button" className="icon-button icon-button--strong" aria-label={`Close ${title.toLowerCase()}`} 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) =>
+ <pre ref={prompt} tabIndex={0} className="compiled-prompt__text" aria-label={promptLabel}>{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/ReferencesView.test.tsx b/src/components/workspace/ReferencesView.test.tsx
index 3c646ff..90ee008 100644
--- a/src/components/workspace/ReferencesView.test.tsx
+++ b/src/components/workspace/ReferencesView.test.tsx
@@ -1,15 +1,19 @@
// @vitest-environment jsdom
import "@testing-library/jest-dom/vitest";
-import { cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
+import { act, cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
import { invoke } from "@tauri-apps/api/core";
import { useState } from "react";
-import { afterEach, describe, expect, it, vi } from "vitest";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { createProjectConfig, parseProjectConfig, type ProjectConfig } from "../../lib/project";
import { ReferencesView } from "./ReferencesView";
+import { referenceIconPrompt } from "../../lib/referenceIcons";
+import { saveDebugOptionsEnabled } from "../../lib/settings";
vi.mock("@tauri-apps/api/core", () => ({ invoke: vi.fn() }));
+beforeEach(() => localStorage.clear());
+
afterEach(() => {
cleanup();
delete (window as unknown as Record<string, unknown>).__TAURI_INTERNALS__;
@@ -50,6 +54,54 @@ function setup(initial = project(), onRegenerateIcon = vi.fn(), pendingIconIds =
}
describe("Reference type presets", () => {
+ it("shows the exact icon regeneration prompt in a debug-only footer dialog", () => {
+ const regenerate = vi.fn();
+ const state = setup(project(), regenerate);
+ expect(screen.queryByRole("button", { name: "Debug Icon Prompt" })).not.toBeInTheDocument();
+ act(() => saveDebugOptionsEnabled(true));
+ const button = screen.getByRole("button", { name: "Debug Icon Prompt" });
+ expect(button.closest(".reference-inspector")?.lastElementChild).toBe(button.parentElement);
+ button.focus();
+ fireEvent.click(button);
+ const dialog = screen.getByRole("dialog", { name: "Debug Icon Prompt" });
+ expect(dialog.closest("aside")).toBeNull();
+ expect(within(dialog).getByLabelText("The reference icon generation prompt").textContent).toBe(referenceIconPrompt(state.latest().references[0]));
+ expect(within(dialog).getByRole("button", { name: "Close debug icon prompt" })).toHaveFocus();
+ expect(regenerate).not.toHaveBeenCalled();
+ fireEvent.keyDown(window, { key: "Tab" });
+ expect(within(dialog).getByLabelText("The reference icon generation prompt")).toHaveFocus();
+ fireEvent.keyDown(window, { key: "Escape" });
+ expect(screen.queryByRole("dialog", { name: "Debug Icon Prompt" })).not.toBeInTheDocument();
+ expect(button).toHaveFocus();
+ fireEvent.click(button);
+ act(() => saveDebugOptionsEnabled(false));
+ expect(screen.queryByRole("dialog", { name: "Debug Icon Prompt" })).not.toBeInTheDocument();
+ expect(screen.queryByRole("button", { name: "Debug Icon Prompt" })).not.toBeInTheDocument();
+ });
+
+ it("uses the selected reference's latest name, category, subcategory and description", () => {
+ saveDebugOptionsEnabled(true);
+ const initial = project();
+ initial.references.push({ ...initial.references[0], id: "ref-animal", name: "Pet", intendedUse: ["animal"], subcategory: "Pets", description: "A golden retriever." });
+ const state = setup(initial);
+ fireEvent.click(screen.getByRole("button", { name: /Pet A golden retriever/ }));
+ fireEvent.change(screen.getByRole("textbox", { name: "Reference name" }), { target: { value: "Buddy" } });
+ fireEvent.change(screen.getByRole("textbox", { name: "Prompt" }), { target: { value: "A sleepy golden retriever.\nSoft light." } });
+ fireEvent.click(screen.getByRole("button", { name: "Debug Icon Prompt" }));
+ const prompt = screen.getByLabelText("The reference icon generation prompt");
+ expect(prompt.textContent).toBe(referenceIconPrompt(state.latest().references[1]));
+ expect(prompt.textContent).toContain("animal with its whole body visible");
+ expect(prompt.textContent).toContain("Subcategory: Pets");
+ fireEvent.click(screen.getByRole("button", { name: "Close debug icon prompt" }));
+ expect(screen.queryByRole("dialog", { name: "Debug Icon Prompt" })).not.toBeInTheDocument();
+ });
+
+ it("does not show icon debugging without a selected reference", () => {
+ saveDebugOptionsEnabled(true);
+ setup({ ...project(), references: [] });
+ expect(screen.queryByRole("button", { name: "Debug Icon Prompt" })).not.toBeInTheDocument();
+ });
+
it("requests an icon refresh for the selected reference and disables duplicate requests", () => {
const regenerate = vi.fn();
const initial = project();
diff --git a/src/components/workspace/ReferencesView.tsx b/src/components/workspace/ReferencesView.tsx
index f5a7a93..6f8e8d3 100644
--- a/src/components/workspace/ReferencesView.tsx
+++ b/src/components/workspace/ReferencesView.tsx
@@ -1,6 +1,6 @@
import { BookOpen, ChevronRight, FileText, ImagePlus, Plus, RefreshCw, Search, Trash2, Users, X } from "lucide-react";
import { invoke } from "@tauri-apps/api/core";
-import { useMemo, useState } from "react";
+import { useEffect, useMemo, useState, useSyncExternalStore } from "react";
import { isReferenceDescribed, referenceImages, type ProjectConfig, type ProjectReference, type ProjectReferenceImage } from "../../lib/project";
import {
composeLocationPrompt,
@@ -17,6 +17,9 @@ import {
import { LOCATION_SETTING_GROUPS } from "../../lib/expanded-reference-options";
import { isTauri } from "../../lib/persistence";
import { ReferenceImage } from "./ReferenceImage";
+import { DebugPromptDialog } from "./DebugPromptDialog";
+import { referenceIconPrompt } from "../../lib/referenceIcons";
+import { loadDebugOptionsEnabled, subscribeDebugOptions } from "../../lib/settings";
/** What a reference IS, in a word. This replaced the file path in both places
* it used to be printed: a path is a fact about the disk, not about the
@@ -36,6 +39,9 @@ export function ReferencesView({ config, folderPath, onChange, onRegenerateIcon,
onOpenGenerator?: (jobId: string) => void;
}) {
const [selectedId, setSelectedId] = useState<string | undefined>(config.references[0]?.id);
+ const debugEnabled = useSyncExternalStore(subscribeDebugOptions, loadDebugOptionsEnabled);
+ const [showDebugIconPrompt, setShowDebugIconPrompt] = useState(false);
+ useEffect(() => setShowDebugIconPrompt(false), [selectedId, debugEnabled]);
const [importError, setImportError] = useState<string | null>(null);
const [iconError, setIconError] = useState<string | null>(null);
const [presetDialog, setPresetDialog] = useState(false);
@@ -226,7 +232,17 @@ export function ReferencesView({ config, folderPath, onChange, onRegenerateIcon,
</section>
</> : <div className="reference-empty"><BookOpen size={26} /><b>Select a reference</b><p>Pick one from the library, or add a new one, to edit its definition and see which generations use it.</p></div>}
</div>
+ {debugEnabled && selected && <div className="debug-prompt">
+ <button type="button" className="secondary-button debug-prompt__toggle" aria-haspopup="dialog" aria-expanded={showDebugIconPrompt} onClick={() => setShowDebugIconPrompt(true)}>Debug Icon Prompt</button>
+ </div>}
</aside>
+ {debugEnabled && showDebugIconPrompt && selected && <DebugPromptDialog
+ title="Debug Icon Prompt"
+ promptLabel="The reference icon generation prompt"
+ sceneTitle={selected.name}
+ segments={[{ kind: "brief", value: referenceIconPrompt(selected) }]}
+ onClose={() => setShowDebugIconPrompt(false)}
+ />}
{presetDialog && <div className="reference-dialog-backdrop"><div className="reference-preset-dialog" role="dialog" aria-modal="true" aria-labelledby="reference-preset-title">
<header>
<div><h2 id="reference-preset-title">Add a reference</h2><p>Choose a preset or create a new reference, then add a prompt and images.</p></div>