Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Say the binding rule the code implements; undo an overwritten description

Bitti0d390e168f9e
diff --git a/src/App.test.tsx b/src/App.test.tsx
index d7f0bb7..f2a56a4 100644
--- a/src/App.test.tsx
+++ b/src/App.test.tsx
@@ -9,6 +9,30 @@ describe("project library controls", () => {
beforeEach(() => localStorage.clear());
afterEach(cleanup);
+ it("can put back words an example chip overwrote", async () => {
+ const { container } = render(<App />);
+ await screen.findByText("Northern Light — Brand Film");
+ const box = screen.getByRole("textbox", { name: "Describe your video" }) as HTMLTextAreaElement;
+ fireEvent.change(box, { target: { value: "a rocket launch over the ocean at dawn" } });
+ // While the box holds the user's own words the row says what a click costs.
+ expect(container.querySelector(".idea-row__label")!.textContent).toBe("Replace what you’ve written with an example");
+ expect(screen.queryByRole("button", { name: /put my words back/ })).toBeNull();
+
+ fireEvent.click(screen.getByRole("button", { name: "Product reveal" }));
+ expect(box.value).toContain("wristwatch");
+ // A controlled textarea gives no native undo after a programmatic set, so
+ // the only route back is the one the app offers.
+ fireEvent.click(screen.getByRole("button", { name: /put my words back/ }));
+ expect(box.value).toBe("a rocket launch over the ocean at dawn");
+ expect(screen.queryByRole("button", { name: /put my words back/ })).toBeNull();
+
+ // Replacing an untouched example is not a loss, so nothing is offered.
+ fireEvent.change(box, { target: { value: "" } });
+ fireEvent.click(screen.getByRole("button", { name: "Social ad" }));
+ fireEvent.click(screen.getByRole("button", { name: "Mini documentary" }));
+ expect(screen.queryByRole("button", { name: /put my words back/ })).toBeNull();
+ });
+
it("focuses search with Ctrl/Cmd+K and switches between grid and list", async () => {
const { container } = render(<App />);
await screen.findByText("Northern Light — Brand Film");
diff --git a/src/components/ProjectWorkspace.test.ts b/src/components/ProjectWorkspace.test.ts
index ee103b1..a24fb8e 100644
--- a/src/components/ProjectWorkspace.test.ts
+++ b/src/components/ProjectWorkspace.test.ts
@@ -240,6 +240,22 @@ describe("project workspace timecode", () => {
expect(compiled).not.toContain("IMG_4821");
expect(compiled).not.toContain("Visual reference");
expect(compiled).toContain("fully_preserved - the referenced characteristics are retained.");
+
+ // The screen must describe the rule the code implements. isReferenceUsable
+ // qualifies an image on its FILE alone, so this imported picture IS bound
+ // and IS sent — nothing on the page may say it is skipped or waiting on a
+ // definition. Three sentences here once said exactly that while the card
+ // beside them correctly said the file was sent.
+ cleanup();
+ const withImport = onChange.mock.calls[0][0];
+ expect(withImport.references[0].relativePath).toBeTruthy();
+ const { container } = render(createElement(ReferencesView, { config: withImport, folderPath: "C:\\Ceramic Lamp", onChange: () => undefined }));
+ const screenText = container.textContent ?? "";
+ for (const staleRule of ["you’ve described", "described references", "skipped", "is skipped until you write"]) {
+ expect(screenText, `stale binding rule on screen: ${staleRule}`).not.toContain(staleRule);
+ }
+ expect(screenText).toContain("An image counts as soon as you import it");
+ expect(screenText).toContain("Not described yet — the picture is sent, but nothing tells the engine what to keep.");
});
it("labels a cancelled preview as cancelled instead of queued", () => {
diff --git a/src/components/PromptComposer.tsx b/src/components/PromptComposer.tsx
index ae2609c..8404f94 100644
--- a/src/components/PromptComposer.tsx
+++ b/src/components/PromptComposer.tsx
@@ -1,4 +1,4 @@
-import { ChevronDown, Clapperboard, Clock3, ImagePlus, Monitor, Sparkles, WandSparkles, X } from "lucide-react";
+import { ChevronDown, Clapperboard, Clock3, ImagePlus, Monitor, Sparkles, Undo2, WandSparkles, X } from "lucide-react";
import { useEffect, useRef, useState } from "react";
import { chooseInitialReferenceImages, isTauri } from "../lib/persistence";
import type { AspectRatio, CreateProjectInput, Resolution } from "../lib/project";
@@ -56,6 +56,15 @@ export function PromptComposer({ busy, onCreate }: PromptComposerProps) {
/* The box holds words the user typed, not an untouched example, so a chip
click would throw them away. */
const replacesUserText = prompt.trim().length > 0 && !ideas.some((idea) => idea.prompt === prompt);
+ /* What a chip click overwrote, kept so it can be put back. The textarea is
+ React-controlled, so Ctrl+Z cannot recover a programmatic set — without
+ this, the words are simply gone. Held until the user types again or
+ submits, rather than on a timer that could expire mid-read. */
+ const [replacedText, setReplacedText] = useState<string | null>(null);
+ const useIdea = (ideaPrompt: string) => {
+ setReplacedText(replacesUserText ? prompt : null);
+ setPrompt(ideaPrompt);
+ };
/* The description box is the first thing you use, so start in it — saving a
click on the headline flow. Runs once, and only while focus is still on the
@@ -104,7 +113,7 @@ export function PromptComposer({ busy, onCreate }: PromptComposerProps) {
<textarea
ref={promptInput}
value={prompt}
- onChange={(event) => setPrompt(event.target.value)}
+ onChange={(event) => { setPrompt(event.target.value); setReplacedText(null); }}
onKeyDown={(event) => {
if ((event.metaKey || event.ctrlKey) && event.key === "Enter") void submit();
}}
@@ -180,7 +189,10 @@ export function PromptComposer({ busy, onCreate }: PromptComposerProps) {
click will do. */}
<div className="idea-row">
<span className="idea-row__label">{replacesUserText ? "Replace what you’ve written with an example" : "Not sure where to start?"}</span>
- {ideas.map((idea) => <button key={idea.label} onClick={() => setPrompt(idea.prompt)} title={replacesUserText ? `Replace your description with the “${idea.label}” example` : `Use the “${idea.label}” example`}>{idea.label}</button>)}
+ {ideas.map((idea) => <button key={idea.label} onClick={() => useIdea(idea.prompt)} title={replacesUserText ? `Replace your description with the “${idea.label}” example` : `Use the “${idea.label}” example`}>{idea.label}</button>)}
+ {replacedText !== null && <button className="idea-row__undo" onClick={() => { setPrompt(replacedText); setReplacedText(null); }}>
+ <Undo2 size={15} /> Undo — put my words back
+ </button>}
</div>
</section>
);
diff --git a/src/components/workspace/ReferencesView.tsx b/src/components/workspace/ReferencesView.tsx
index 9cedd53..63cb9fe 100644
--- a/src/components/workspace/ReferencesView.tsx
+++ b/src/components/workspace/ReferencesView.tsx
@@ -68,7 +68,7 @@ export function ReferencesView({ config, folderPath, onChange }: { config: Proje
<div>
<span className="eyebrow">Consistency library</span>
<h1>References</h1>
- <p>Keep the people, places, products, and visual rules for this project in one place. Each new shot uses the first two you’ve described.</p>
+ <p>Keep the people, places, products, and visual rules for this project in one place. Each new shot uses the first two in this list.</p>
</div>
<div>
<button className="secondary-button" onClick={() => addTextReference()}><FileText size={16} /> New definition</button>
@@ -91,7 +91,12 @@ export function ReferencesView({ config, folderPath, onChange }: { config: Proje
</button>)}
<button className="reference-add-card" onClick={() => void addImage()}><span><Plus size={22} /></span><b>Add a reference</b><small>Import an image or write a definition</small></button>
</div>
- <div className="reference-explainer"><Sparkles size={18} /><div><b>References guide new shots, not your timeline</b><p>Each new shot uses the first two references in this list that you’ve described — an empty one is skipped until you write its definition. Image files are copied into the project’s <code>references/</code> folder and sent to the video engine; text definitions are written into the shot’s prompt. Newest additions go to the top.</p></div></div>
+ <div className="reference-explainer"><Sparkles size={18} /><div><b>References guide new shots, not your timeline</b>{/* The rule the code actually implements: isReferenceUsable qualifies an
+ image on its FILE alone, so an imported picture is bound and sent
+ whether or not it has been described. Saying it was "skipped until
+ you write its definition" contradicted the card 30px away, which
+ correctly says the picture is sent. */}
+ <p>Each new shot uses the first two references in this list. An image counts as soon as you import it: its file is copied into the project’s <code>references/</code> folder and sent to the video engine, and describing it tells the engine what to keep about it. A text definition isn’t used until you write it, and then it reaches the engine as words in the shot’s prompt. Newest additions go to the top.</p></div></div>
</section>
<aside className="reference-inspector">
@@ -109,7 +114,7 @@ export function ReferencesView({ config, folderPath, onChange }: { config: Proje
</section>
<section className="reference-used-by">
<h3>Used by <span>{jobs.length}</span></h3>
- {jobs.length ? jobs.map((job) => <div key={job.id}><span className={`job-link-dot job-link-dot--${job.status}`} /><div><b>{job.title}</b><small>{job.status} · {job.stage}</small></div><Link2 size={16} /></div>) : <p>No shots use this reference yet. Each new shot picks up the first two described references in this list, so it will be used once it reaches the top two of those.</p>}
+ {jobs.length ? jobs.map((job) => <div key={job.id}><span className={`job-link-dot job-link-dot--${job.status}`} /><div><b>{job.title}</b><small>{job.status} · {job.stage}</small></div><Link2 size={16} /></div>) : <p>No shots use this reference yet. Each new shot picks up the first two it can use from this list, so it will be used once it reaches the top two of those.</p>}
</section>
<section className="portable-path"><BookOpen size={16} /><div><b>Where this lives</b><code>{selected.relativePath ?? "Stored in polstudio.project.json"}</code></div></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>}
diff --git a/src/lib/project.test.ts b/src/lib/project.test.ts
index 9138160..5bd2d08 100644
--- a/src/lib/project.test.ts
+++ b/src/lib/project.test.ts
@@ -265,10 +265,18 @@ describe("project schema", () => {
// nine rounds. A diff in `git status` after cargo test means the wire
// format moved and this test is the frontend's verdict on it.
for (const [name, wire] of Object.entries(wireFixtures)) {
- const parsed = parseProjectConfig(wire);
- expect(parsed.schemaVersion, name).toBe(1);
- // No `null` may reach a field zod spells `.optional()` without `.nullable()`.
- expect(JSON.stringify(wire), name).not.toMatch(/"(clipId|durationMs|width|height|color)":\s*null/);
+ // Deep equality, not a hand-maintained key list. This closes THREE
+ // directions at once and needs no upkeep:
+ // - a null reaching a field zod spells bare `.optional()` throws here;
+ // - a field Rust writes that zod does not know is silently STRIPPED by
+ // the non-strict schema, so `parsed` loses it and this comparison
+ // fails — previously nothing caught that, and the frontend would then
+ // re-save and quietly drop the field from the user's file;
+ // - a default zod applies that Rust does not send shows up as an added
+ // key and fails too.
+ // The previous version listed five key names by hand, which is exactly
+ // the kind of remembering this fixture pair was introduced to replace.
+ expect(parseProjectConfig(wire), name).toEqual(wire);
}
});
diff --git a/src/styles/library.css b/src/styles/library.css
index 4d05bc1..2023af8 100644
--- a/src/styles/library.css
+++ b/src/styles/library.css
@@ -414,6 +414,18 @@
font-size: var(--text-sm);
}
+/* Offered only after a chip overwrote words the user typed. It is the recovery
+ path a controlled textarea takes away from Ctrl+Z, so it reads as an action
+ rather than another example. */
+.idea-row__undo {
+ display: inline-flex;
+ gap: var(--space-2);
+ align-items: center;
+ margin-left: auto;
+ border-color: var(--accent) !important;
+ color: var(--text-primary) !important;
+}
+
.idea-row button {
min-height: var(--control-sm);
padding: 0 var(--space-4);