AI media harness for planning, generating, and editing locally
TypeScript
Continue final unpaired Long Shot scenes
Bitti2b98c33ad307
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.mdindex f8d8dde..83df072 100644--- a/RELEASE_NOTES.md+++ b/RELEASE_NOTES.md@@ -42,6 +42,7 @@ This alpha update adds LAN generation workers, Linux support, expanded color gra## Fixes and improvements+- Generate all now includes the final scene in an even-length Long Shot sequence, continuing from the preceding scene and preserving earlier joined video and audio.- Long Shot timeline playback keeps the same video player running across adjacent scenes in a joined generation, avoiding a playback restart at bridge boundaries.- Reduced memory retained between generations: release Slopfab samples and handles after consumption, discard completed queue snapshots, close encoders on errors, and clean up abandoned LAN generation results.- Inspector instructions now appear as tooltips on field labels, keeping the right-side panels compact.diff --git a/docs/slopfab-compatibility.md b/docs/slopfab-compatibility.mdindex dcf45e4..9acdd4a 100644--- a/docs/slopfab-compatibility.md+++ b/docs/slopfab-compatibility.md@@ -26,7 +26,10 @@ to load the new library and logging code.Consecutive **Long Shot** scenes alternate fresh anchors and bridges. Generateall queues 1, 3, 2, 5, 4, 7, 6. A bridge requires completed neighbors with saved-latents; an unfinished final bridge needs another Long Shot scene after it.+latents. With an even number of scenes, the final scene continues from the+previous anchor using the latest compatible joined archive. Four scenes run+in 1, 3, 2, 4 order. Adding a following Long Shot scene turns that continuation+into a bridge on its next generation.The two margin controls replace the previous anchor's ending and the followinganchor's beginning in multiples of 17 frames (default 17, zero allowed).Each anchor must also provide 22 preserved context frames. Use the same canvas,diff --git a/src/components/workspace/GeneratorView.test.tsx b/src/components/workspace/GeneratorView.test.tsxindex 7c98f6c..d28122e 100644--- a/src/components/workspace/GeneratorView.test.tsx+++ b/src/components/workspace/GeneratorView.test.tsx@@ -44,6 +44,7 @@ it("queues Long Shot anchors before their intervening bridges", () => {it("persists Long Shot boundary controls and inherits the scene type for new scenes", () => {const initial = project();+ initial.generationJobs.push(createDraftGenerationJob("Keep walking", { id: "third" }));initial.generationJobs.forEach((job) => { job.sceneType = "long-shot"; });const state = setup(initial);fireEvent.click(screen.getByRole("button", { name: "Select scene Second scene" }));@@ -55,6 +56,20 @@ it("persists Long Shot boundary controls and inherits the scene type for new sceexpect(state.latest().generationJobs.at(-1)?.sceneType).toBe("long-shot");});+it.each([2, 4, 6])("queues every scene in a %s-scene Long Shot, ending with a continuation", (count) => {+ const initial = project();+ initial.generationJobs = Array.from({ length: count }, (_, i) => createDraftGenerationJob("Keep walking", { id: String(i + 1), sceneType: "long-shot" }));+ const submitted = vi.fn();+ render(<GeneratorView config={initial} folderPath="C:/project" runtime={readyRuntime}+ onChange={vi.fn()} onGenerate={submitted} onOpenTimeline={() => undefined} />);+ fireEvent.click(screen.getByRole("button", { name: "Generate all" }));+ const items = submitted.mock.calls[0][0];+ expect(items.map((item: { job: { id: string } }) => item.job.id)).toEqual(+ count === 2 ? ["1", "2"] : count === 4 ? ["1", "3", "2", "4"] : ["1", "3", "2", "5", "4", "6"]);+ expect(items.at(-1).request).toMatchObject({ previousSceneId: String(count - 1), continuationFrom: "end", continuationOverlapFrames: 22 });+ expect(items.at(-1).request.latentBridge).toBeUndefined();+});+it("hides unfinished templates from the generator picker", () => {setup();fireEvent.click(screen.getByRole("combobox", { name: /Video generator template/ }));diff --git a/src/components/workspace/SceneEditor.tsx b/src/components/workspace/SceneEditor.tsxindex 5261132..3ce2e17 100644--- a/src/components/workspace/SceneEditor.tsx+++ b/src/components/workspace/SceneEditor.tsx@@ -332,7 +332,9 @@ export function SceneInspector({ job, shots, references, folderPath = "", scenes...(value === "animate" ? { endFrameReferenceId: undefined } : {}) })} /></PropRow>{longShot && <>- <p className="prop-caption">{longShot.bridge+ <p className="prop-caption">{longShot.continuation+ ? `Continue from ${longShot.left?.title ?? "the previous scene"}. Generate all completes the preceding scenes first. Adding a following Long Shot scene turns this scene into a bridge.`+ : longShot.bridge? `Bridge between ${longShot.left?.title ?? "the previous scene"} and ${longShot.right?.title ?? "a following Long Shot scene (add one first)"}. Both neighbors must be generated first. Generate all handles this order.`: "Generate a fresh clip. The next Long Shot scene bridges this clip to the following fresh clip."}</p>{longShot.bridge && ([['bridgeLeftMargin', 'Edit previous ending'], ['bridgeRightMargin', 'Edit following beginning']] as const).map(([key, label]) =>diff --git a/src/lib/continuationMedia.ts b/src/lib/continuationMedia.tsindex a5c0203..fe7bf21 100644--- a/src/lib/continuationMedia.ts+++ b/src/lib/continuationMedia.ts@@ -76,6 +76,8 @@ export function continuationPlaybackTracks(config: ProjectConfig) {// dependencies. Never revive a stale archive through legacy adjacency.const joinedOwnIndex = joined?.sceneSegments?.findIndex((part) => generationAssetId(part.sceneId) === joined.id) ?? -1;if (joinedOwnIndex >= 0 && joinedOwnIndex < joined!.sceneSegments!.length - 1) continue;+ if ((joined?.sceneSegments?.length ?? 0) > 1+ && config.generationJobs.some((job) => generationAssetId(job.id) === joined!.id && job.sceneType === "long-shot")) continue;const matching = joined?.sceneSegments?.find((part) => part.sceneId === own.sceneId && part.latentRelativePath === own.latentRelativePath);// A Start continuation contains only the opening overlap, so do// not pretend that its source file contains the whole original scene.diff --git a/src/lib/longShot.test.ts b/src/lib/longShot.test.tsindex 896c301..1ca2c50 100644--- a/src/lib/longShot.test.ts+++ b/src/lib/longShot.test.ts@@ -1,7 +1,7 @@import { expect, it } from "vitest";import { bridgedSceneSegments, currentLongShotArchives, longShotBlocker, longShotInputs, longShotPosition } from "./longShot";import { createDraftGenerationJob, createProjectConfig, parseProjectConfig, sceneOutputFrames } from "./project";-import { continuationPlaybackTracks, sceneMediaDurationMs, sceneMediaStartSeconds } from "./continuationMedia";+import { continuationPlaybackTracks, joinedSceneSegments, sceneMediaDurationMs, sceneMediaStartSeconds } from "./continuationMedia";import { sceneGenerationRequest } from "./sceneGeneration";import { buildExportPlan, defaultExportSettings } from "./export";@@ -30,10 +30,41 @@ it("alternates within consecutive runs and blocks missing, failed and short anchconfig.generationJobs[1].bridgeRightMargin = 119;expect(longShotBlocker(config.generationJobs[1], config)).toContain("141 frames");config.generationJobs[2].sceneType = "backdrop";- expect(longShotBlocker(config.generationJobs[1], config)).toContain("following Long Shot");+ expect(longShotBlocker(config.generationJobs[1], config)).toBeNull();+ expect(longShotPosition(config.generationJobs[1], config.generationJobs)?.continuation).toBe(true);expect(longShotPosition(config.generationJobs[3], config.generationJobs)?.bridge).toBe(false);});+it("continues the last scene from the joined archive and invalidates it when a following anchor is added", () => {+ const config = project();+ const fifth = config.generationJobs.pop()!;+ const last = config.generationJobs[3];+ expect(longShotBlocker(last, config)).toBeNull();+ const request = sceneGenerationRequest(last, config, "C:/project", 8);+ expect(request.latentBridge).toBeUndefined();+ expect(request).toMatchObject({ previousSceneId: "3", continuationRelativePath: "latents/2.safetensors",+ continuationSourceFrames: 124, continuationOverlapFrames: 22, continuationFrom: "end" });+ config.assets[3].sceneSegments = joinedSceneSegments("4", last.latentRelativePath!, 345, 51, {+ sceneId: "3", latentRelativePath: request.continuationRelativePath!, frameCount: 124, segments: config.assets[1].sceneSegments!,+ });+ const parts = config.assets[3].sceneSegments;+ expect(currentLongShotArchives(config).map((asset) => asset.id)).toEqual(["asset-4", "asset-2"]);+ let startMs = 0;+ config.timeline.tracks[0].clips = parts.map((part) => {+ const durationMs = Math.round(part.frameCount * 1000 / 24);+ const clip = { id: part.sceneId, assetId: `asset-${part.sceneId}`, trackId: config.timeline.tracks[0].id,+ label: part.sceneId, startMs, durationMs, sourceStartMs: 0, status: "generated" as const };+ startMs += durationMs;+ return clip;+ });+ expect(continuationPlaybackTracks(config)[0].clips.map((clip) => clip.assetId)).toEqual(Array(4).fill("asset-4"));+ expect(buildExportPlan(config, defaultExportSettings(config)).audio.map((part) => part.assetId)).toEqual(Array(4).fill("asset-4"));+ config.generationJobs.push(fifth);+ expect(currentLongShotArchives(config).map((asset) => asset.id)).toEqual(["asset-2"]);+ expect(sceneGenerationRequest(last, config, "C:/project", 8).latentBridge).toBeDefined();+ expect(continuationPlaybackTracks(config)[0].clips.map((clip) => clip.assetId)).toEqual(["asset-2", "asset-2", "asset-2", "asset-4"]);+});+it("chains complete archives to preserve both ends of shared anchors", () => {const config = project();const next = longShotInputs(config.generationJobs[3], config)!;diff --git a/src/lib/longShot.ts b/src/lib/longShot.tsindex c008d5f..6788bef 100644--- a/src/lib/longShot.ts+++ b/src/lib/longShot.ts@@ -10,25 +10,26 @@ export function longShotPosition(job: GenerationJob, jobs: readonly GenerationJoif (index < 0) return null;let start = index;while (start > 0 && jobs[start - 1].sceneType === "long-shot") start--;- const bridge = (index - start) % 2 === 1;- return { index, start, bridge,- left: bridge ? jobs[index - 1] : undefined,- right: bridge && jobs[index + 1]?.sceneType === "long-shot" ? jobs[index + 1] : undefined,- previousBridge: bridge && index - start > 1 ? jobs[index - 2] : undefined };+ const between = (index - start) % 2 === 1;+ const right = between && jobs[index + 1]?.sceneType === "long-shot" ? jobs[index + 1] : undefined;+ return { index, start, bridge: between && !!right, continuation: between && !right,+ left: between ? jobs[index - 1] : undefined, right,+ previousBridge: between && index - start > 1 ? jobs[index - 2] : undefined };}export function longShotDependencies(job: GenerationJob, jobs: readonly GenerationJob[]): GenerationJob[] {const position = longShotPosition(job, jobs);- return position?.bridge ? [position.left, position.right].filter((source): source is GenerationJob => !!source) : [];+ return position?.left ? [position.left, position.right].filter((source): source is GenerationJob => !!source) : [];}export function longShotBlocker(job: GenerationJob, config: ProjectConfig, requireCompleted = true): string | null {const position = longShotPosition(job, config.generationJobs);- if (!position?.bridge) return null;- if (!position.left || !position.right) return "Add a following Long Shot scene before generating this bridge.";- for (const [source, margin] of [[position.left, job.bridgeLeftMargin ?? 17], [position.right, job.bridgeRightMargin ?? 17]] as const) {+ if (!position?.left) return null;+ const neighbors: [GenerationJob, number][] = [[position.left, position.continuation ? 0 : job.bridgeLeftMargin ?? 17]];+ if (position.right) neighbors.push([position.right, job.bridgeRightMargin ?? 17]);+ for (const [source, margin] of neighbors) {if (requireCompleted && (source.status !== "completed" || !source.latentRelativePath || !source.outputRelativePath))- return `Generate “${source.title}” first, or use Generate all. Both neighboring clips need saved latents.`;+ return `Generate “${source.title}” first, or use Generate all. ${position.continuation ? "The previous clip needs saved latents." : "Both neighboring clips need saved latents."}`;const sourceAsset = config.assets.find((asset) => asset.id === generationAssetId(source.id));if (requireCompleted && (sourceAsset?.sceneSegments?.length ?? 0) > 1)return `Regenerate “${source.title}” as a fresh Long Shot anchor first.`;@@ -44,13 +45,14 @@ export function currentLongShotArchives(config: Pick<ProjectConfig, "assets" | "const candidates = config.assets.filter((asset) => {const parts = asset.sceneSegments;const own = parts?.findIndex((part) => generationAssetId(part.sceneId) === asset.id) ?? -1;- if (!parts || own <= 0 || own >= parts.length - 1) return false;+ if (!parts || own <= 0) return false;const first = config.generationJobs.findIndex((job) => job.id === parts[0].sceneId);if (first < 0 || !parts.every((part, offset) => config.generationJobs[first + offset]?.id === part.sceneId && config.generationJobs[first + offset]?.sceneType === "long-shot")) return false;if (!parts.every((part) => config.generationJobs.some((job) => job.id === part.sceneId && job.status === "completed" && job.latentRelativePath === part.latentRelativePath))) return false;const owner = config.generationJobs.find((job) => generationAssetId(job.id) === asset.id)!;const position = longShotPosition(owner, config.generationJobs);- if (!position?.bridge || position.left?.id !== parts[own - 1].sceneId || position.right?.id !== parts[own + 1].sceneId) return false;+ if (!position?.left || position.left.id !== parts[own - 1].sceneId) return false;+ if (position.continuation ? own !== parts.length - 1 : !position.bridge || position.right?.id !== parts[own + 1]?.sceneId) return false;return true;}).sort((a, b) => config.generationJobs.findIndex((job) => generationAssetId(job.id) === a.id)- config.generationJobs.findIndex((job) => generationAssetId(job.id) === b.id));@@ -79,6 +81,24 @@ export function longShotPlaybackSource(job: GenerationJob, config: Pick<ProjectCreturn source && segment ? { source, segment } : null;}+/** A final unpaired scene extends the latest joined archive, so earlier+ * bridge edits to the preceding anchor survive in its video and audio. */+export function longShotContinuationInputs(job: GenerationJob, config: ProjectConfig) {+ const position = longShotPosition(job, config.generationJobs);+ if (!position?.continuation || !position.left) return null;+ const { left, previousBridge } = position;+ const prefix = previousBridge && currentLongShotArchives(config).find((asset) => asset.id === generationAssetId(previousBridge.id)+ && asset.sceneSegments?.at(-1)?.sceneId === left.id);+ const segments = prefix?.sceneSegments ?? (left.latentRelativePath ? [{ sceneId: left.id, latentRelativePath: left.latentRelativePath,+ startFrame: 0, frameCount: sceneOutputFrames(left, config) ?? 0 }] : undefined);+ return { segments: segments ?? undefined, request: {+ previousSceneId: left.id,+ continuationRelativePath: (prefix ? previousBridge!.latentRelativePath : left.latentRelativePath) ?? undefined,+ continuationSourceFrames: sceneOutputFrames(left, config),+ continuationOverlapFrames: LONG_SHOT_CONTEXT, continuationFrom: "end" as const, continuationLockOverlap: false,+ } };+}+export function longShotInputs(job: GenerationJob, config: ProjectConfig): { bridge: NonNullable<SceneGenerationInput["latentBridge"]>; leftSegments?: SceneMediaSegment[] } | null {const position = longShotPosition(job, config.generationJobs);if (!position?.bridge) return null;diff --git a/src/lib/sceneGeneration.ts b/src/lib/sceneGeneration.tsindex 4422528..b97c6db 100644--- a/src/lib/sceneGeneration.ts+++ b/src/lib/sceneGeneration.ts@@ -1,5 +1,5 @@import { generationDimensions } from "./export";-import { longShotInputs } from "./longShot";+import { longShotContinuationInputs, longShotInputs } from "./longShot";import {audioReferenceBlocker, characterReplaceBlocker, poseBlocker, isVideoTransition, videoTransitionBlocker,usableAudioReferences, usableVideoReferences, referenceRefmodInputs, compileGenerationJobPrompt,@@ -15,7 +15,7 @@ export function sceneGenerationRequest(job: GenerationJob, config: ProjectConfig// ordered list drives the <Subject N> / <Picture N> numbering inside the// compiled prompt, because slopfab.rs adds reference_paths sequentially — so// array index 0 must be the asset the prompt calls <Picture 1>.- const inputs = sceneFrameInputs(job, config);+ const inputs = { ...sceneFrameInputs(job, config), ...longShotContinuationInputs(job, config)?.request };const bound = inputs.references;const canvas = generationDimensions(config.settings.resolution, config.settings.aspectRatio);const longShot = longShotInputs(job, config);diff --git a/src/lib/workQueue.test.ts b/src/lib/workQueue.test.tsindex c159a2e..c92f019 100644--- a/src/lib/workQueue.test.ts+++ b/src/lib/workQueue.test.ts@@ -18,7 +18,7 @@ import { compileImagePrompt } from "./imagePrompt";import { addImageNode, createImageEditScene } from "./imageScene";import { createEmptyImage, makeImagePrimary, restoreGeneratedImage } from "./imageHistory";import { sceneGenerationRequest } from "./sceneGeneration";-import { bridgeGapFrames } from "./longShot";+import { bridgeGapFrames, currentLongShotArchives } from "./longShot";vi.mock("@tauri-apps/api/core", () => ({ invoke: vi.fn() }));vi.mock("@tauri-apps/api/event", () => ({ listen: vi.fn() }));@@ -125,6 +125,52 @@ it.each(["failure", "reorder"])("refuses a queued Long Shot bridge after anchorexpect(queue.getSnapshot().find((item) => item.id === ids[2])?.error).toMatch(reason === "failure" ? /Generate/ : /neighbors changed/);});+it.each([2, 4])("completes all %s Long Shot scenes and continues their freshly joined archive", async (count) => {+ const { queue, first } = setup();+ first.update((config) => ({ ...config, generationJobs: Array.from({ length: count }, (_, i) => ({ ...config.generationJobs[0], id: String(i + 1), sceneType: "long-shot" as const })) }));+ vi.mocked(resolveSlopfabPlan).mockImplementation(async (request) => {+ const live = first.getSnapshot().config;+ const owner = live.generationJobs.find((job) => job.latentRelativePath === request.continuationRelativePath);+ const tail = live.assets.find((asset) => asset.id === `asset-${owner?.id}`)?.sceneSegments?.at(-1);+ return { ...plan, alignedFrames: request.latentBridge+ ? request.latentBridge.leftFrames! + bridgeGapFrames(request.frames) + request.latentBridge.rightFrames!+ : request.continuationRelativePath ? tail!.startFrame + tail!.frameCount + Math.ceil(request.frames / 17) * 17 : 124+ } as Awaited<ReturnType<typeof resolveSlopfabPlan>>;+ });+ const config = first.getSnapshot().config;+ const order = count === 2 ? [0, 1] : [0, 2, 1, 3];+ const ids = queue.enqueue(first, order.map((i) => ({ job: config.generationJobs[i], snapshot: "queued",+ request: sceneGenerationRequest(config.generationJobs[i], config, first.record.folderPath, 8) })));+ for (let index = 0; index < ids.length; index++) {+ await waitFor(() => expect(enqueueSlopfabGeneration).toHaveBeenCalledTimes(index + 1));+ await finish(queue, ids[index]);+ }+ const request = vi.mocked(enqueueSlopfabGeneration).mock.calls.at(-1)![0];+ expect(request).toMatchObject({ previousSceneId: String(count - 1), continuationRelativePath: `latents/${ids.at(-2)}.safetensors`,+ continuationSourceFrames: 124, continuationFrom: "end", continuationOverlapFrames: 22 });+ expect(request.latentBridge).toBeUndefined();+ const saved = parseProjectConfig(JSON.parse(JSON.stringify(first.getSnapshot().config)));+ expect(saved.generationJobs.every((job) => job.status === "completed")).toBe(true);+ const joined = currentLongShotArchives(saved)[0];+ expect(joined.id).toBe(`asset-${count}`);+ expect(joined.sceneSegments?.map((part) => part.sceneId)).toEqual(Array.from({ length: count }, (_, i) => String(i + 1)));+ expect(JSON.parse(saved.generationJobs.at(-1)!.generationSnapshot!).continuationRelativePath).toBe(request.continuationRelativePath);+});++it("rejects a queued final Long Shot continuation when a following anchor is added", async () => {+ const { queue, first } = setup();+ first.update((config) => ({ ...config, generationJobs: Array.from({ length: 2 }, (_, i) => ({ ...config.generationJobs[0], id: String(i + 1), sceneType: "long-shot" as const })) }));+ const config = first.getSnapshot().config;+ const ids = queue.enqueue(first, config.generationJobs.map((job) => ({ job, snapshot: "queued",+ request: sceneGenerationRequest(job, config, first.record.folderPath, 8) })));+ await waitFor(() => expect(enqueueSlopfabGeneration).toHaveBeenCalledOnce());+ first.update((current) => ({ ...current, generationJobs: [...current.generationJobs, { ...config.generationJobs[0], id: "3" }] }));+ await finish(queue, ids[0]);+ await waitFor(() => expect(queue.getSnapshot().find((item) => item.id === ids[1])?.status).toBe("failed"));+ expect(enqueueSlopfabGeneration).toHaveBeenCalledOnce();+ expect(queue.getSnapshot().find((item) => item.id === ids[1])?.error).toContain("neighbors changed");+});+it("releases a cancelled queued snapshot before the running job finishes", async () => {const { queue, first, second } = setup();const [running] = queue.enqueue(first, [submission(first)]);diff --git a/src/lib/workQueue.ts b/src/lib/workQueue.tsindex 6da0d93..c656559 100644--- a/src/lib/workQueue.ts+++ b/src/lib/workQueue.ts@@ -25,7 +25,7 @@ import { ReferenceIconWork } from "./referenceIconWork";import { prepareReferenceVideos, releaseReferenceVideos } from "./referenceVideo";import { prepareReferenceAudios, releaseReferenceAudios } from "./referenceAudio";import { joinedSceneSegments, sceneArchiveSegments } from "./continuationMedia";-import { bridgedSceneSegments, longShotBlocker, longShotInputs } from "./longShot";+import { bridgedSceneSegments, longShotBlocker, longShotContinuationInputs, longShotInputs } from "./longShot";import type { SceneMediaSegment } from "./project";import { exportReferenceRefmod, refmodExportBlocker, refmodExportRequest, type RefmodExportTarget } from "./refmodExport";@@ -458,14 +458,26 @@ export class WorkQueue {this.updateScene(work, { generationSnapshot: work.snapshot });}if (work.request.previousSceneId) {- const previous = work.session.getSnapshot().config.generationJobs.find((job) => job.id === work.request.previousSceneId);+ const live = work.session.getSnapshot().config;+ const previous = live.generationJobs.find((job) => job.id === work.request.previousSceneId);if (!previous?.latentRelativePath || previous.status !== "completed") {throw new Error("Generate the selected source scene successfully to save its latents before continuing it. You can also use Generate All.");}- work.request.continuationRelativePath = previous.latentRelativePath;- work.request.continuationSourceFrames = sceneOutputFrames(previous, work.session.getSnapshot().config);- work.continuationSegments = sceneArchiveSegments(work.session.getSnapshot().config, previous);const captured = work.config.generationJobs.find((job) => job.id === work.sceneId)!;+ if (captured.sceneType === "long-shot") {+ const current = live.generationJobs.find((job) => job.id === work.sceneId);+ const inputs = current && longShotContinuationInputs(current, live);+ if (!inputs || inputs.request.previousSceneId !== work.request.previousSceneId)+ throw new Error("The Long Shot neighbors changed while queued. Queue this scene again.");+ const blocker = longShotBlocker({ ...captured, latentUpscale: work.request.latentUpscale }, live);+ if (blocker) throw new Error(blocker);+ Object.assign(work.request, inputs.request);+ work.continuationSegments = inputs.segments;+ } else {+ work.request.continuationRelativePath = previous.latentRelativePath;+ work.request.continuationSourceFrames = sceneOutputFrames(previous, live);+ work.continuationSegments = sceneArchiveSegments(live, previous);+ }work.snapshot = sceneGenerationSnapshot(captured, work.request);this.updateScene(work, { generationSnapshot: work.snapshot });}