AI media harness for planning, generating, and editing locally
TypeScript
Condition Single Shot endings on source latents
Bitti141c9ae1216f
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.mdindex a2c7ed4..9d51ad3 100644--- a/RELEASE_NOTES.md+++ b/RELEASE_NOTES.md@@ -20,6 +20,7 @@ Changes since 0.3.2.## Fixes and improvements+- Single Shot continuation conditions both generation passes on the previous clip's final latents to preserve continuity.- Updated First/Last Frame Fast to the eight-step FastH3 Omni model and corrected Omni and First/Last Frame weight fallbacks.- Image edits preserve source images, prompts and settings; queued results get separate entries, and whole-image edits disable feathering.- Imported images now expose steps, seed and resolution; new images use generator step defaults, and renamed image roots retain their names.diff --git a/docs/scene-types.md b/docs/scene-types.mdindex 754815c..3fbc546 100644--- a/docs/scene-types.md+++ b/docs/scene-types.md@@ -3,7 +3,7 @@The Scene panel saves a type on each scene:- **Prompt** is the default for ordinary video scenes. It supports shot descriptions, speech, Look, sound, music and references cited in prompts, without start- or last-frame selectors. Stored frame anchors and continuation links are inactive.-- **Single Shot** keeps its main prompt in the Shot panel and an optional **Ending prompt** in the Scene panel, both with reference support. It generates a short ending first, then uses those latents to anchor the full shot. A blank ending prompt uses the main prompt. **Starting video** can select any other generated scene; ending latents from its full clip guide the new shot's beginning. Generate all handles dependency order. Use matching resolution and latent-upscale settings, a duration of at least two seconds, and updated LAN workers.+- **Single Shot** keeps its main prompt in the Shot panel and an optional **Ending prompt** in the Scene panel, both with reference support. It generates a short ending first, then uses those latents to anchor the full shot. A blank ending prompt uses the main prompt. **Starting video** can select any other generated scene; its final latents condition both the ending pass and the full shot for continuity. Generate all handles dependency order. Use matching resolution and latent-upscale settings, a duration of at least two seconds, and updated LAN workers.- **First & Last Frame** adds optional start- and last-frame anchors to the same controls. Older scenes without a type retain this type when they have frame selections; otherwise they use Prompt. Switching types retains saved frame selections for later use.- **Backdrop** generates the described subject and action against a selected green, blue, black or white background (green by default). The compiled prompt requests a uniform color across all shots, with no scenery, floor, horizon, texture, gradients or backdrop shadows. Prompt references guide the subject; their original settings are replaced. Stored frame anchors and continuation links are inactive. Apply Chroma Key to the generated timeline clip and select the matching backdrop or Auto to remove it. Generation still produces ordinary video: transparency is applied by the effect. Choose a color absent from the subject and describe action that fits inside the frame.- **Continue** uses another scene's saved latents. Choose the source scene, beginning or end (default: end), and overlap in frames (default: 22; increments of 17 at 24 fps). Generate the source first, or use Generate All to render dependencies in order. Scene length controls the new segment. The saved video keeps Slopfab's full joined video and audio; adjacent source and continuation clips use that shared decode in preview and export, while trims remain relative to each scene. Regenerate older Continue scenes to preserve both sides of the decoded boundary. Old Previous scene selections become Continue scenes linked to their original source; reordering scenes keeps that link.diff --git a/docs/slopfab-compatibility.md b/docs/slopfab-compatibility.mdindex d7543fd..20b4ebc 100644--- a/docs/slopfab-compatibility.md+++ b/docs/slopfab-compatibility.md@@ -22,8 +22,12 @@ seed. Generate all orders starting scenes before their dependents and rejectscycles. Queued prompts remain captured while source latents resolve after thestarting scene finishes.-The worker generates a 22-frame ending into a temporary latent archive, releases-its decoded buffers, then attaches that archive with+The worker prepares a 22-frame ending in a temporary latent archive. With a+starting scene, the ending pass continues from its final 22 frames of video and+audio latents with locked overlap, then crops the generated tail to 22 frames.+This conditions both passes on the source instead of forcing a transition to an+independently generated ending. Without a starting scene, the ending is generated+directly. The worker releases its decoded buffers, then attaches the ending with`slopfab_request_set_end_anchor_file`. The full generation uses the requestedscene duration minus those 22 frames as its lead-in or gap. An optional startingarchive contributes its ending context; both boundaries are locked. MotionCachediff --git a/src-tauri/core/src/slopfab/continuation.rs b/src-tauri/core/src/slopfab/continuation.rsindex 1152f63..4771126 100644--- a/src-tauri/core/src/slopfab/continuation.rs+++ b/src-tauri/core/src/slopfab/continuation.rs@@ -1,4 +1,4 @@-//! Select opening latents without changing the source archive or runtime ABI.+//! Select boundary latents without changing the source archive or runtime ABI.//! The native setter owns its snapshot, so the temporary archive can be dropped//! immediately after attachment. End selection uses the original archive.use super::types::GenerationRequest;@@ -90,6 +90,20 @@ pub(super) fn opening_archive(if request.continuation_from.as_deref() != Some("start") {return Ok(None);}+ crop_archive(request, false).map(Some)+}++/// Keep the final video latents and both audio channels, without VAE re-encoding.+pub(super) fn tail_archive(path: &std::path::Path, frames: i32) -> Result<tempfile::TempPath, String> {+ let request = GenerationRequest {+ continuation_path: Some(path.to_path_buf()), continuation_overlap_frames: Some(frames),+ ..Default::default()+ };+ validate(&request)?;+ crop_archive(&request, true)+}++fn crop_archive(request: &GenerationRequest, from_end: bool) -> Result<tempfile::TempPath, String> {let path = request.continuation_path.as_ref()@@ -135,7 +149,9 @@ pub(super) fn opening_archive(let video_frames = latent_frames(frames);// Continued archives include earlier scenes. New frames add five latent// frames per 17 video frames; start at this scene's own latent contribution.- let first_video = if scene_frames == frames {+ let first_video = if from_end {+ video_frames - latent_frames(overlap)+ } else if scene_frames == frames {0} else {if scene_frames % 17 != 0 {@@ -159,8 +175,8 @@ pub(super) fn opening_archive(.and_then(|n| n.checked_add(1)).ok_or("Latent audio overflow.")?/ 3;- let first_audio = ((frames - scene_frames) * 5 + 1) / 3;let selected_audio = (overlap * 5 + 1) / 3;+ let first_audio = if from_end { audio_frames - selected_audio } else { ((frames - scene_frames) * 5 + 1) / 3 };let video = read_rows(&mut source,header_len + 8,@@ -210,16 +226,16 @@ pub(super) fn opening_archive(.and_then(|_| output.flush()).map_err(|e| e.to_string())?;// Close the file handle before the DLL opens it (Windows sharing rules).- Ok(Some(output.into_temp_path()))+ Ok(output.into_temp_path())}#[cfg(test)]-mod tests {+pub(super) mod tests {use super::super::{planning::resolve_plan, references::ReferenceVideos};use super::*;use std::collections::BTreeMap;- fn archive(frames: usize) -> tempfile::NamedTempFile {+ pub(crate) fn archive(frames: usize) -> tempfile::NamedTempFile {let video_rows = ((frames - 5) / 17 * 5 + 2) * 2;let audio_rows = ((frames * 5 + 1) / 3) * 2;let video_bytes = video_rows * 96 * 4;@@ -342,6 +358,36 @@ mod tests {assert!(!temporary.exists());}+ #[test]+ fn tail_crop_preserves_final_video_rows_and_each_audio_channel() {+ for (frames, first_video, first_audio, right_audio) in [(124, 60.0, 170.0, 377.0), (56, 20.0, 56.0, 149.0)] {+ let source = archive(frames).into_temp_path();+ let original = std::fs::read(&source).unwrap();+ let cropped = tail_archive(&source, 22).unwrap();+ let bytes = std::fs::read(&cropped).unwrap();+ let start = u64::from_le_bytes(bytes[..8].try_into().unwrap()) as usize + 8;+ let header: Value = serde_json::from_slice(&bytes[8..start]).unwrap();+ assert_eq!(header["__metadata__"]["frames"], "22");+ assert_eq!(header["video_rows"]["shape"], json!([14, 96]));+ assert_eq!(header["audio_rows"]["shape"], json!([74, 32]));+ let value = |at: usize| f32::from_le_bytes(bytes[at..at + 4].try_into().unwrap());+ assert_eq!(value(start), first_video);+ assert_eq!(value(start + 13 * 96 * 4), first_video + 13.0);+ let audio = start + header["audio_rows"]["data_offsets"][0].as_u64().unwrap() as usize;+ assert_eq!(value(audio), first_audio);+ assert_eq!(value(audio + 37 * 32 * 4), right_audio);+ assert_eq!(value(audio + 73 * 32 * 4), right_audio + 36.0);+ assert_eq!(std::fs::read(&source).unwrap(), original);+ assert!(tail_archive(&source, frames as i32 + 17).is_err());++ let request = GenerationRequest { prompt: "Continue walking".into(), frames: 22, steps: 4, seed: 1,+ canvas_width: 64, canvas_height: 32, continuation_path: Some(cropped.to_path_buf()),+ continuation_lock_overlap: true, ..Default::default() };+ let plan = resolve_plan(&request, &BTreeMap::new(), &ReferenceVideos::default()).unwrap();+ assert_eq!(plan.aligned_frames, 56); // 22-frame context + 34 newly generated frames.+ }+ }+#[test]fn continuation_plans_custom_overlap_from_either_edge_with_the_bundled_runtime() {let source = archive(124).into_temp_path();diff --git a/src-tauri/core/src/slopfab/generation.rs b/src-tauri/core/src/slopfab/generation.rsindex c32f498..0ef83c7 100644--- a/src-tauri/core/src/slopfab/generation.rs+++ b/src-tauri/core/src/slopfab/generation.rs@@ -38,8 +38,15 @@ fn run_single_shot(mut generate: impl FnMut(&QueueItem) -> Result<(OutputMetadata, rendered::RenderedVideo), String>,) -> Result<(OutputMetadata, rendered::RenderedVideo), String> {let single = item.request.single_shot.as_ref().ok_or("Missing Single Shot settings.")?;+ if item.cancel.load(Ordering::Acquire) { return Err("Single Shot generation cancelled.".into()); }let temporary = tempfile::tempdir().map_err(|error| format!("Could not prepare ending latents: {error}"))?;let ending_path = temporary.path().join("ending.safetensors");+ // Condition the ending on the same source as the full shot. An independent+ // ending can force a cut to an unrelated subject/scene despite a locked start.+ // Only its tail is needed here; avoid decoding the entire previous chain.+ let starting_tail = item.request.continuation_path.as_deref()+ .map(|path| super::continuation::tail_archive(path, 22)).transpose()?;+ let mut ending_tail = None;let mut elapsed = 0.0;let mut timings = [0.0; 4];let mut computed = 0;@@ -52,14 +59,15 @@ fn run_single_shot(request.prompt = single.ending_prompt.clone();request.frames = 22;request.continuation_relative_path = None;- request.continuation_path = None;- request.continuation_source_frames = None;- request.continuation_overlap_frames = None;- request.continuation_from = None;- request.continuation_lock_overlap = false;+ request.continuation_path = starting_tail.as_ref().map(|path| path.to_path_buf());+ request.continuation_source_frames = starting_tail.as_ref().map(|_| 22);+ request.continuation_overlap_frames = starting_tail.as_ref().map(|_| 22);+ request.continuation_from = starting_tail.as_ref().map(|_| "end".into());+ request.continuation_lock_overlap = starting_tail.is_some();request.save_latents_path = Some(ending_path.clone());} else {- request.single_shot.as_mut().unwrap().ending_path = Some(ending_path.clone());+ request.single_shot.as_mut().unwrap().ending_path = Some(ending_tail.as_ref()+ .map_or_else(|| ending_path.clone(), |path: &tempfile::TempPath| path.to_path_buf()));}let sink = item.events.clone();let offset = elapsed;@@ -102,6 +110,11 @@ fn run_single_shot(// Release its decoded buffers before allocating the full generation.drop(result);if !ending_path.is_file() { return Err("The ending generation did not save its latents.".into()); }+ if starting_tail.is_some() {+ // Continuation saves the joined source + generated clip. Anchor only+ // its generated ending, never the retained source at its beginning.+ ending_tail = Some(super::continuation::tail_archive(&ending_path, 22)?);+ }}unreachable!()}diff --git a/src-tauri/core/src/slopfab/generation_tests.rs b/src-tauri/core/src/slopfab/generation_tests.rsindex 2f76ae9..0de6a30 100644--- a/src-tauri/core/src/slopfab/generation_tests.rs+++ b/src-tauri/core/src/slopfab/generation_tests.rs@@ -73,59 +73,88 @@ fn item() -> QueueItem {events: Arc::new(|_| {}), cancel: Arc::new(AtomicBool::new(false)) }}-fn single_shot_item() -> QueueItem {+fn single_shot_item() -> (QueueItem, tempfile::TempPath) {+ let source = super::super::continuation::tests::archive(124).into_temp_path();let mut item = item();item.request.image_edit = None;item.request.still_image = false;item.request.frames = 48;item.request.single_shot = Some(crate::slopfab::types::SingleShotRequest { ending_prompt: "Waves goodbye".into(), ending_path: None });item.request.reference_paths = vec!["reference.png".into()];- item.request.continuation_path = Some("source.safetensors".into());+ item.request.continuation_path = Some(source.to_path_buf());item.request.continuation_relative_path = Some("latents/source.safetensors".into());item.request.continuation_source_frames = Some(124);item.request.continuation_overlap_frames = Some(22);item.request.continuation_lock_overlap = true;item.request.save_latents_path = Some("final.safetensors".into());- item+ (item, source)}#[test]fn single_shot_generates_ending_first_then_attaches_it_with_the_starting_source() {- let item = single_shot_item();- let mut calls = 0;- let mut ending_path = std::path::PathBuf::new();- let (metadata, _) = run_single_shot(&item, |stage| {- calls += 1;- assert_eq!(stage.request.reference_paths, item.request.reference_paths);- assert_eq!(stage.request.seed, item.request.seed);- if calls == 1 {- assert!(stage.request.single_shot.is_none());- assert_eq!(stage.request.prompt, "Waves goodbye");- assert_eq!(stage.request.frames, 22);- assert!(stage.request.continuation_path.is_none());- assert!(stage.request.continuation_relative_path.is_none());- ending_path = stage.request.save_latents_path.clone().unwrap();- std::fs::write(&ending_path, b"completed ending").unwrap();- } else {- assert_eq!(stage.request.prompt, item.request.prompt);- assert_eq!(stage.request.frames, 48);- assert_eq!(stage.request.continuation_path, item.request.continuation_path);- assert_eq!(stage.request.save_latents_path, item.request.save_latents_path);- assert_eq!(stage.request.single_shot.as_ref().unwrap().ending_path.as_ref(), Some(&ending_path));- assert!(ending_path.is_file());+ for continued in [false, true] {+ let (mut item, source) = single_shot_item();+ let original_source = std::fs::read(&source).unwrap();+ if !continued {+ item.request.continuation_path = None;+ item.request.continuation_relative_path = None;+ item.request.continuation_source_frames = None;}- Ok(result(1))- }).unwrap();- assert_eq!(calls, 2);- assert_eq!(metadata.seconds_total, 2.0);- assert_eq!(metadata.steps_computed, 4);- assert!(!ending_path.exists());+ let mut calls = 0;+ let mut ending_path = std::path::PathBuf::new();+ let generated_ending = super::super::continuation::tests::archive(if continued { 56 } else { 22 });+ let expected_anchor = super::super::continuation::tail_archive(generated_ending.path(), 22).unwrap();+ let expected_start = super::super::continuation::tail_archive(&source, 22).unwrap();+ let mut temporary_paths = Vec::new();+ let (metadata, _) = run_single_shot(&item, |stage| {+ calls += 1;+ assert_eq!(stage.request.reference_paths, item.request.reference_paths);+ assert_eq!(stage.request.seed, item.request.seed);+ if calls == 1 {+ assert!(stage.request.single_shot.is_none());+ assert_eq!(stage.request.prompt, "Waves goodbye");+ assert_eq!(stage.request.frames, 22);+ if continued {+ let path = stage.request.continuation_path.as_ref().unwrap();+ assert_ne!(path, &source.to_path_buf());+ assert_eq!(std::fs::read(path).unwrap(), std::fs::read(&expected_start).unwrap());+ temporary_paths.push(path.clone());+ assert_eq!(stage.request.continuation_from.as_deref(), Some("end"));+ assert_eq!(stage.request.continuation_source_frames, Some(22));+ assert_eq!(stage.request.continuation_overlap_frames, Some(22));+ assert!(stage.request.continuation_lock_overlap);+ } else {+ assert!(stage.request.continuation_path.is_none());+ }+ assert!(stage.request.continuation_relative_path.is_none());+ ending_path = stage.request.save_latents_path.clone().unwrap();+ std::fs::copy(generated_ending.path(), &ending_path).unwrap();+ } else {+ assert_eq!(stage.request.prompt, item.request.prompt);+ assert_eq!(stage.request.frames, 48);+ assert_eq!(stage.request.continuation_path, item.request.continuation_path);+ assert_eq!(stage.request.save_latents_path, item.request.save_latents_path);+ let anchor = stage.request.single_shot.as_ref().unwrap().ending_path.as_ref().unwrap();+ assert_eq!(std::fs::read(anchor).unwrap(), std::fs::read(&expected_anchor).unwrap());+ temporary_paths.push(anchor.clone());+ assert!(ending_path.is_file());+ }+ Ok(result(1))+ }).unwrap();+ assert_eq!(calls, 2);+ assert_eq!(metadata.seconds_total, 2.0);+ assert_eq!(metadata.steps_computed, 4);+ assert!(!ending_path.exists());+ assert!(temporary_paths.iter().all(|path| !path.exists()));+ assert_eq!(std::fs::read(&source).unwrap(), original_source);+ }}#[test]fn single_shot_stops_on_ending_failure_missing_latents_or_cancellation_and_cleans_up() {for mode in ["failure", "missing", "cancel-before", "cancel-between", "full-failure"] {- let item = single_shot_item();+ let (item, _source) = single_shot_item();+ let generated_ending = super::super::continuation::tests::archive(56);if mode == "cancel-before" { item.cancel.store(true, Ordering::Release); }let mut calls = 0;let mut path = None;@@ -134,7 +163,7 @@ fn single_shot_stops_on_ending_failure_missing_latents_or_cancellation_and_cleanif calls == 2 { return Err("full shot failed".into()); }let ending = stage.request.save_latents_path.clone().unwrap();path = Some(ending.clone());- if mode != "missing" { std::fs::write(&ending, b"ending").unwrap(); }+ if mode != "missing" { std::fs::copy(generated_ending.path(), &ending).unwrap(); }if mode == "failure" { return Err("ending failed".into()); }if mode == "cancel-between" { item.cancel.store(true, Ordering::Release); }Ok(result(1))