From d79463a5ca3f59df5b9080e545f689986e85b794 Mon Sep 17 00:00:00 2001 From: digital-garbage <133010426+digital-garbage@users.noreply.github.com> Date: Mon, 15 Jun 2026 13:03:46 +0300 Subject: [PATCH] Editor: materialize a just-typed global prompt before generate (screen = truth) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Root of the 'same video despite a different prompt' bug: editing the global prompt is debounced 500ms (scheduleGlobalPromptApply) before it distributes into scene.text. Hit Generate within that window ('thought runs faster than quicksave') and _flushSaveForGenerate saved the OLD scene text while the screen showed the new prompt — so generation (which reads the saved scenes) used stale text, persisted, and survived restart. Track the latest typed global prompt and add flushGlobalPromptApply(); call it at the top of _flushSaveForGenerate so any pending global-prompt edit is distributed into scenes (which also reconciles ghosts via _alignScenesFromParsed) BEFORE save and generate. The file stays a faithful snapshot of the screen at generate time. Co-Authored-By: Claude Opus 4.8 --- movie_editor/frontend/store.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/movie_editor/frontend/store.js b/movie_editor/frontend/store.js index 62de325f..ebef0ed2 100644 --- a/movie_editor/frontend/store.js +++ b/movie_editor/frontend/store.js @@ -221,13 +221,27 @@ } let _globalApplyTimer = null; + let _pendingGlobalPromptText = null; // latest typed global prompt awaiting distribution function scheduleGlobalPromptApply(text) { + _pendingGlobalPromptText = text; clearTimeout(_globalApplyTimer); _globalApplyTimer = setTimeout(() => { - applyGlobalPromptQuiet(text).catch((e) => console.warn("Global prompt apply failed:", e)); + _globalApplyTimer = null; + const t = _pendingGlobalPromptText; _pendingGlobalPromptText = null; + applyGlobalPromptQuiet(t).catch((e) => console.warn("Global prompt apply failed:", e)); }, 500); } + // Materialize a still-debounced global-prompt edit into scene.text NOW (screen = truth). Called + // before generate/save so a prompt typed faster than the 500ms debounce isn't left undistributed + // — otherwise we'd save (and generate from) stale scene text while the screen shows the new prompt. + async function flushGlobalPromptApply() { + if (_globalApplyTimer) { clearTimeout(_globalApplyTimer); _globalApplyTimer = null; } + if (_pendingGlobalPromptText == null) return; + const t = _pendingGlobalPromptText; _pendingGlobalPromptText = null; + await applyGlobalPromptQuiet(t); + } + function _normalizeSceneText(t) { return String(t || "").trim().replace(/\s+/g, " "); } @@ -2371,6 +2385,7 @@ } async function _flushSaveForGenerate() { + await flushGlobalPromptApply(); // distribute any just-typed global prompt into scenes first await flushSave(); if (_localDirty) { throw new Error(