Drive Google Flow from Claude, Codex or a local control panel, on Mac or Windows — using your Google AI subscription credits instead of the pay-per-use video API. No browser extension.
Flow: stop mistaking our own uploads for finished clips; make the second reference attach reliably
GTAI-106ceeab230da
diff --git a/CLAUDE.md b/CLAUDE.mdindex 25f285f..010474f 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -244,6 +244,23 @@ The preview tool could not read the project while it lived in ~/Desktop; check tnewer clip could not be found by name and flow_assets looked unchanged. runGeneration now renames each finishedtile to `<project>-<file_stem>` through the tile menu's `Rename` (renameTile, best effort - a failed rename mustnever lose the clip). The user asked for this; it removes a whole class of confusion.+- FALSE "FAILED" CLIPS (2026-10-09, 31 in one session, every clip that used first/last frames): the job grabbed its+ OWN UPLOAD instead of the clip. Frames and reference files are uploaded as `fm-<job>-<label>`; the upload tile+ appears at once ("image 0%") and only gets its media id when processing ends, which was after the "before"+ snapshot, so it looked new. Its menu offers only Delete, hence "tile menu has no Download item. It offered: Delete",+ while the real clip sat finished in the grid (flow_download by title always worked). Now: freshMedia() skips+ `fm-` tiles, tiles still showing "NN%", and tiles of the wrong kind (a video job only accepts flow-video-tile, an+ image job flow-image-tile; edit and continue jobs accept videos only, so "Save frame" stills are ignored too), and+ uploadAsset waits for its own tile by name until it carries data-media-id. Replayed against the live grid: the old+ logic picked fm-db88e712-end.png, the new one waits and then picks the clip. Then verified on a paid clip (4 credits,+ the user's OK): Omni 1.1 Flash 4 s 360p from an uploaded first frame -> job "done" in 63 s, the clip downloaded,+ opening on the frame, progress readout working ("14%").+- SECOND REFERENCE (2026-10-09, twice: a character, then an uploaded still): the click on "Add ingredients" produced+ no picker at all and the job died after 10 s. Not reproducible on demand (character + upload, even mid-processing,+ all opened fine), so attachAsset now retries the opener three times with Escape in between, and always switches+ the picker to its All tab (it reopens on the last tab used, e.g. Characters). Verified with a real free still:+ "asset:Juno" + an uploaded file -> both attached, the generated still (not the upload) downloaded.+ Also noted: getByRole("button", { name: "Ingredient" }) also counts a hidden button outside the composer.- Gemini TTS: a LONG `style` note makes the model ramble - a 45-word line with a 25-word delivery note produced 674SECONDS of audio. The same line with no style note is 20.5 s, with a short note 32 s. Keep style notes to a fewwords, and sanity-check the returned duration against the expected one before using it.diff --git a/src/flow.ts b/src/flow.tsindex 54f3f9d..8b36c58 100644--- a/src/flow.ts+++ b/src/flow.ts@@ -188,13 +188,38 @@ export async function retryNewErrorTiles(return { errors, reachedKnown, retried };}-async function waitForNewMedia(page: Page, before: string[], count: number, timeoutMs: number, job?: Job): Promise<string[]> {+type MediaKind = "image" | "video";++// New tiles that can be the result we are waiting for. Three things looked "new" here without being it (2026-10-09:+// 31 finished clips reported failed with "tile menu has no Download item. It offered: Delete"):+// - our OWN uploads (first/last frames, references - always named fm-<job>-...): an upload's tile shows up while it is+// still processing and only gets its final id a moment later, after the "before" snapshot, so it read as new;+// - a tile of the wrong kind, such as the still that "Save frame" makes on the way to a continuation clip;+// - a tile still rendering ("NN%").+export async function freshMedia(page: Page, before: string[], kind?: MediaKind): Promise<string[]> {+ const tiles = await page.evaluate(+ (js) => {+ const idOf = eval(js) as (t: Element) => string | undefined;+ return [...document.querySelectorAll("flow-grid-tile-container")].map((t) => ({+ id: idOf(t),+ kind: t.querySelector("flow-video-tile") ? "video" : t.querySelector("flow-image-tile") ? "image" : "other",+ label: t.getAttribute("aria-label") ?? "",+ busy: /\d+%/.test((t as HTMLElement).innerText),+ }));+ },+ TILE_ID_JS,+ );+ const ours = tiles.filter((t) => t.id && !before.includes(t.id) && !t.label.startsWith("fm-") && !t.busy && (!kind || t.kind === kind));+ return [...new Set(ours.map((t) => t.id!))];+}++async function waitForNewMedia(page: Page, before: string[], count: number, timeoutMs: number, job?: Job, kind?: MediaKind): Promise<string[]> {const deadline = Date.now() + timeoutMs;let retriesLeft = job?.params.retries ?? 1;let failures = 0;while (Date.now() < deadline) {await pause(page, 2000);- const fresh = [...new Set((await mediaIds(page)).filter((id) => !before.includes(id)))];+ const fresh = await freshMedia(page, before, kind);// New tiles are listed first, so anything beyond the requested count is not ours.if (fresh.length >= count) return fresh.slice(0, count);const progress = await page.evaluate(() =>@@ -276,6 +301,19 @@ async function applySettings(page: Page, job: Job): Promise<number> {const ASSET_PREFIX = "asset:";+// Waits for THIS upload by its own name until Flow has finished processing it (its picture carries a media id), so+// a half-processed upload can never be taken for the next generation's result.+async function waitForUpload(page: Page, name: string, timeoutMs: number): Promise<void> {+ const tile = page.locator(`flow-grid-tile-container[aria-label="${name.replace(/"/g, '\\"')}"]:has([data-media-id])`);+ await tile+ .first()+ .waitFor({ state: "attached", timeout: timeoutMs })+ .catch(() => {+ throw new Error(`Flow did not finish processing the upload "${name}" within ${Math.round(timeoutMs / 1000)}s.`);+ });+ await pause(page, 1000);+}+// Uploads under a unique filename so the asset can be picked unambiguously afterwards.// "asset:<name>" refers to something already in the Flow project (image, video, character) and skips the upload.async function uploadAsset(page: Page, job: Job, file: string, label: string): Promise<string> {@@ -285,12 +323,11 @@ async function uploadAsset(page: Page, job: Job, file: string, label: string): Pconst staged = join(mkdtempSync(join(tmpdir(), "flow-mcp-")), name);copyFileSync(file, staged);await scrollToTop(page);- const before = await mediaIds(page);await page.getByRole("button", { name: "Add media menu" }).click();const chooser = page.waitForEvent("filechooser", { timeout: 10_000 });await page.getByRole("menuitem", { name: "Upload", exact: true }).click();await (await chooser).setFiles(staged);- await waitForNewMedia(page, before, 1, 90_000);+ await waitForUpload(page, name, 90_000);return name;}@@ -302,9 +339,29 @@ const optionByName = (list: Locator, name: string) =>// The frame pickers attach on click; the ingredients picker only previews and needs "Add to prompt".// Option names are "<asset name>" or "<asset name> Image|Video", so match on the prefix.-async function attachAsset(page: Page, opener: Locator, assetName: string): Promise<void> {- await opener.click();+export async function attachAsset(page: Page, opener: Locator, assetName: string): Promise<void> {const list = page.getByRole("listbox", { name: "Asset list" });+ const all = page.getByRole("tab", { name: "All", exact: true });+ const shows = (l: Locator, ms: number) => l.waitFor({ state: "visible", timeout: ms }).then(() => true, () => false);+ // Twice on 2026-10-09 (a character, then an uploaded still) the click on the opener produced no picker at all, and+ // the job died waiting for it. It never reproduced when replayed, so it was something transient in the way - most+ // likely the upload menu still closing. Like the settings popover, the picker gets three tries, with Escape in+ // between to clear whatever caught the click. The Start/End frame pickers have no tabs, hence list OR All tab.+ let opened = false;+ for (let attempt = 0; attempt < 3 && !opened; attempt++) {+ if (attempt) {+ await page.keyboard.press("Escape");+ await pause(page, 800);+ }+ await opener.click();+ opened = await Promise.race([shows(list, 5000), shows(all, 5000)]);+ }+ if (!opened) throw new Error(`Flow's media picker did not open (three tries) while attaching "${assetName}". Nothing was generated.`);+ // The picker reopens on whichever tab was used last (Characters, after a character), so start from All each time.+ if ((await all.isVisible().catch(() => false)) && (await all.getAttribute("aria-selected")) !== "true") {+ await all.click();+ await pause(page, 1000);+ }await list.waitFor({ state: "visible", timeout: 10_000 });let option = optionByName(list, assetName);// Voices, characters and avatars live behind their own tabs, so look there when "All" does not have it.@@ -613,7 +670,7 @@ export async function runGeneration(job: Job): Promise<string[]> {await start.click();const variants = s.variants ?? 1;- const fresh = await waitForNewMedia(page, before, variants, s.type === "image" ? IMAGE_TIMEOUT_MS : VIDEO_TIMEOUT_MS, job);+ const fresh = await waitForNewMedia(page, before, variants, s.type === "image" ? IMAGE_TIMEOUT_MS : VIDEO_TIMEOUT_MS, job, s.type === "image" ? "image" : "video");job.progress = undefined;mkdirSync(s.output_dir, { recursive: true });@@ -1048,7 +1105,7 @@ export async function runEdit(job: Job): Promise<string[]> {await page.getByRole("button", { name: "Back button to go to previous page" }).click();await pause(page, 2500);await ensureProjectGrid(page);- const fresh = await waitForNewMedia(page, before, 1, 90_000);+ const fresh = await waitForNewMedia(page, before, 1, 90_000, undefined, "video");mkdirSync(s.output_dir, { recursive: true });const saved = await downloadMedia(page, fresh[0], join(s.output_dir, s.file_stem), s.download_quality);const after = await readCredits(page).catch(() => undefined);@@ -1335,7 +1392,7 @@ export async function runContinue(job: Job): Promise<string[]> {break;}- const fresh = await waitForNewMedia(page, before, 1, VIDEO_TIMEOUT_MS, job);+ const fresh = await waitForNewMedia(page, before, 1, VIDEO_TIMEOUT_MS, job, "video");job.progress = undefined;mkdirSync(s.output_dir, { recursive: true });const saved = await downloadMedia(page, fresh[0], join(s.output_dir, s.file_stem), s.download_quality);