AI media harness for planning, generating, and editing locally
TypeScript
Preserve joined continuation video and audio
Bitti5e079b61edc3
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.mdindex 9c25894..bbf7710 100644--- a/RELEASE_NOTES.md+++ b/RELEASE_NOTES.md@@ -26,6 +26,7 @@ This alpha update adds DMAD LoRA support, resumable model downloads, and improve## Fixes and improvements+- Continue preserves the full joined video and audio from Slopfab. Adjacent source and continuation scenes use that shared decode in preview and export, preserving context across the cut. Regenerate older Continue scenes to apply the fix.- The timeline playhead follows playback without waiting for editor updates.- Copy and paste effect settings between matching effects from their **…** menus, including bypass state and LUT data.- Add voice reference chips directly in a shot's Speech field. Voice guidance stays separate from the words spoken.diff --git a/docs/scene-types.md b/docs/scene-types.mdindex 1e33e49..4f05a7a 100644--- a/docs/scene-types.md+++ b/docs/scene-types.md@@ -3,7 +3,7 @@The Scene panel saves a type on each scene:- **First & Last Frame** keeps the existing shot descriptions, speech, Look, sound, music and optional frame anchors. Older scenes without a type use this type.-- **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. Old Previous scene selections become Continue scenes linked to their original source; reordering scenes keeps that link.+- **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.- **Animate** uses an Animate generator, one driving video and one repainted scene frame. It does not send a text prompt.- **Pose** uses a selected video for body pose, movement and timing. The Scene panel places the video selector above the shot prompts, where optional references can define the target subject and setting. It uses the video's saved clip range without its soundtrack, attached stills or refmods. Only the selected pose video and references cited in the prompts are sent; frame anchors and previous-scene continuation are inactive. Pose requires a nonempty prompt and reference-capable MiniMax weights (References or Singularity), with the existing limits of three videos, nine images and 15 seconds of reference video.- **Character Replace** gives each shot a source video selector, a new character reference selector and an optional description identifying the character to replace. The character reference must contain an image. Blank target descriptions mean the main character.diff --git a/src-tauri/core/src/slopfab/continuation.rs b/src-tauri/core/src/slopfab/continuation.rsindex 2375f67..e6d139e 100644--- a/src-tauri/core/src/slopfab/continuation.rs+++ b/src-tauri/core/src/slopfab/continuation.rs@@ -296,8 +296,9 @@ mod tests {};let plan =resolve_plan(&request, &BTreeMap::new(), &ReferenceVideos::default()).unwrap();- assert_eq!(plan.aligned_frames, 34);- assert!((plan.duration_seconds - 34.0 / 24.0).abs() < 0.0001);+ let total = if edge == "start" { overlap + 34 } else { 124 + 34 };+ assert_eq!(plan.aligned_frames, total);+ assert!((plan.duration_seconds - total as f64 / 24.0).abs() < 0.0001);let wire = serde_json::to_value(&request).unwrap();assert_eq!(wire["continuationFrom"], edge);assert_eq!(wire["continuationOverlapFrames"], overlap);diff --git a/src-tauri/core/src/slopfab/ffi/mod.rs b/src-tauri/core/src/slopfab/ffi/mod.rsindex a959b78..6074396 100644--- a/src-tauri/core/src/slopfab/ffi/mod.rs+++ b/src-tauri/core/src/slopfab/ffi/mod.rs@@ -2,7 +2,7 @@ mod handles;mod raw;#[cfg(test)]mod tests;-pub use handles::{FinishedGeneration, GenerationHandle, ProgressSink};+pub use handles::{FinishedGeneration, GenerationHandle, ProgressSink, Output};pub use raw::{cuda_device_names, gpu_devices, has_cuda_device, Plan, Progress};use std::{path::{Path, PathBuf},diff --git a/src-tauri/core/src/slopfab/generation.rs b/src-tauri/core/src/slopfab/generation.rsindex a538599..0c2aa88 100644--- a/src-tauri/core/src/slopfab/generation.rs+++ b/src-tauri/core/src/slopfab/generation.rs@@ -2,7 +2,7 @@ use super::{events::{progress_sink, CallbackContext},ffi::{self, RequestHandle},h3::configure_request,- planning::{scene_audio_offset, scene_frame_window, RequestPurpose},+ planning::{scene_frame_window, RequestPurpose},platform::detect_platform,runtime::QueueItem,types::OutputMetadata,@@ -16,13 +16,9 @@ mod tests;struct FrameSource {generation: ffi::FinishedGeneration,- frame_offset: u32,}impl rendered::FrameSource for FrameSource {fn frame_rgba(&self, index: u32, width: u32, height: u32) -> Result<Vec<u8>, String> {- let index = index- .checked_add(self.frame_offset)- .ok_or("Continuation frame index overflow.")?;self.generation.frame_rgba8(index, width, height)}}@@ -156,20 +152,15 @@ fn run_single_generation(}let generation = generation.finish()?;let output = generation.output()?;- let (frame_offset, frames) = scene_frame_window(&item.request, output.frames)?;- let source = Box::new(FrameSource {- generation,- frame_offset: frame_offset as u32,- });- let audio_offset = scene_audio_offset(- frame_offset,- output.fps,- output.audio_channels,- output.audio_sample_rate,- output.audio.len(),- )?;- let mut audio = output.audio;- audio.drain(..audio_offset);+ let source = Box::new(FrameSource { generation });+ collect_output(item, output, source, timing_profile)+}++fn collect_output(item: &QueueItem, output: ffi::Output, source: Box<dyn rendered::FrameSource>, timing_profile: String) -> Result<(OutputMetadata, rendered::RenderedVideo), String> {+ let (_, frames) = scene_frame_window(&item.request, output.frames)?;+ // The VAE decoded both sides of the boundary together. Keep that complete+ // output, including the source-side pixels and soundtrack near the join.+ let audio = output.audio;let metadata = OutputMetadata {frames, width: output.width, height: output.height, fps: output.fps,audio_channels: output.audio_channels, audio_sample_rate: output.audio_sample_rate,@@ -188,7 +179,7 @@ fn run_single_generation(} else {0.0},- boundary: "Latents are saved in the project. Decoded buffers remain owned by slopfab; the webview encodes the new scene's frames on demand.",+ boundary: "Latents are saved in the project. Decoded buffers remain owned by slopfab; the webview encodes the full joined video and audio on demand.",};let pictures = rendered::from_source(&item.request.job_id,diff --git a/src-tauri/core/src/slopfab/generation_tests.rs b/src-tauri/core/src/slopfab/generation_tests.rsindex 952b800..2814201 100644--- a/src-tauri/core/src/slopfab/generation_tests.rs+++ b/src-tauri/core/src/slopfab/generation_tests.rs@@ -6,6 +6,29 @@ struct Pixels(u8);impl rendered::FrameSource for Pixels {fn frame_rgba(&self, _: u32, _: u32, _: u32) -> Result<Vec<u8>, String> { Ok(vec![self.0, 20, 30, 255]) }}++#[test]+fn continuation_handoff_keeps_every_joined_frame_and_audio_sample() {+ struct IndexedFrames;+ impl rendered::FrameSource for IndexedFrames {+ fn frame_rgba(&self, index: u32, _: u32, _: u32) -> Result<Vec<u8>, String> { Ok(vec![index as u8, 0, 0, 255]) }+ }+ let mut item = item();+ item.request.frames = 119;+ item.request.continuation_path = Some("source.safetensors".into());+ item.request.image_edit = None;+ let audio: Vec<f32> = (0..486).map(|n| n as f32).collect();+ let expected_audio: Vec<u8> = audio.iter().flat_map(|n| n.to_le_bytes()).collect();+ let output = ffi::Output { frames: 243, video_float_count: 243 * 3, width: 1, height: 1, channels: 3,+ fps: 24.0, audio, audio_channels: 2, audio_sample_rate: 24, seconds_conditioning: 0.0, seconds_denoise: 0.0,+ seconds_video_decode: 0.0, seconds_audio_decode: 0.0, seconds_total: 0.0, steps_computed: 2, steps_skipped: 0 };+ let (metadata, video) = collect_output(&item, output, Box::new(IndexedFrames), "test".into()).unwrap();+ assert_eq!(metadata.frames, 243);+ assert_eq!(metadata.audio_samples, 486);+ assert_eq!(video.frame_count, 243);+ for index in [0, 123, 124, 242] { assert_eq!(video.frame(index).unwrap().unwrap()[0], index as u8); }+ assert_eq!(video.audio_bytes(), expected_audio);+}fn result(value: u8) -> (OutputMetadata, rendered::RenderedVideo) {let metadata = OutputMetadata { frames: 1, width: 1, height: 1, fps: 1.0, audio_channels: 0, audio_sample_rate: 0, audio_samples: 0,reference_count: 0, timing_profile: "test".into(), seconds_conditioning: 0.0, seconds_denoise: 1.0, seconds_video_decode: 0.0,diff --git a/src-tauri/core/src/slopfab/planning.rs b/src-tauri/core/src/slopfab/planning.rsindex 9ab4a59..4aed9e9 100644--- a/src-tauri/core/src/slopfab/planning.rs+++ b/src-tauri/core/src/slopfab/planning.rs@@ -101,8 +101,8 @@ pub(super) fn generation_seed(value: i64) -> Result<u64, String> {}}-/// Continuation output is cumulative. Expose only the new scene to the editor,-/// while the DLL saves the full archive for the next continuation.+/// Keep the full joined decode. Timeline scene ranges are resolved by the+/// editor; discarding the prefix here loses the source side of the VAE join.pub(super) fn scene_frame_window(request: &GenerationRequest,total: i32,@@ -123,30 +123,9 @@ pub(super) fn scene_frame_window(.ok_or("Continuation frame count overflow.")?/ limits.frame_stride* limits.frame_stride;- let offset = total+ total.checked_sub(frames).filter(|offset| *offset >= request.continuation_overlap_frames.unwrap_or(limits.continuation_overlap)).ok_or("Slopfab continuation output is missing its source frames.".to_string())?;- Ok((offset, frames))-}--pub(super) fn scene_audio_offset(- frame_offset: i32,- fps: f64,- channels: i32,- sample_rate: i32,- total: usize,-) -> Result<usize, String> {- if total == 0 || frame_offset == 0 {- return Ok(0);- }- if !fps.is_finite() || fps <= 0.0 || channels <= 0 || sample_rate <= 0 {- return Err("Slopfab returned invalid continuation audio timing.".into());- }- let samples = (frame_offset as f64 * sample_rate as f64 / fps).round();- let offset = (samples as usize)- .checked_mul(channels as usize)- .filter(|offset| *offset <= total)- .ok_or("Slopfab continuation audio is shorter than its source scene.")?;- Ok(offset)+ Ok((0, total))}diff --git a/src-tauri/core/src/slopfab/tests.rs b/src-tauri/core/src/slopfab/tests.rsindex a69235a..8c3ed13 100644--- a/src-tauri/core/src/slopfab/tests.rs+++ b/src-tauri/core/src/slopfab/tests.rs@@ -452,7 +452,7 @@ fn animate_reports_missing_runtime_api() {}#[test]-fn continuation_uses_22_frames_and_plans_only_the_new_scene() {+fn continuation_uses_22_overlap_frames_and_preserves_the_joined_output() {let references = ReferenceVideos::default();// An independent 39-frame, 64x32 archive exercises the real DLL without// loading model weights. Its sampling window should be 22 + 34 frames.@@ -504,12 +504,12 @@ fn continuation_uses_22_frames_and_plans_only_the_new_scene() {assert_eq!(raw.latent_frames, 17); // 56-frame window, including 22 overlap.assert_eq!(scene_frame_window(&request, raw.aligned_frames).unwrap(),- (39, 34)+ (0, 73));}let plan = resolve_plan(&request, &settings, &references).unwrap();- assert_eq!(plan.aligned_frames, 34);- assert!((plan.duration_seconds - 34.0 / 24.0).abs() < 1e-6);+ assert_eq!(plan.aligned_frames, 73);+ assert!((plan.duration_seconds - 73.0 / 24.0).abs() < 1e-6);assert!(!request.save_latents_path.as_ref().unwrap().exists()); // Planning never writes.request.canvas_width = 128;assert!(resolve_plan(&request, &settings, &references).is_err());@@ -519,25 +519,14 @@ fn continuation_uses_22_frames_and_plans_only_the_new_scene() {}#[test]-fn continuation_video_and_audio_skip_the_cumulative_source() {+fn continuation_frame_window_keeps_the_cumulative_source() {let mut request = GenerationRequest {frames: 119,continuation_path: Some("source".into()),..Default::default()};- assert_eq!(scene_frame_window(&request, 243).unwrap(), (124, 119));- // A further continuation skips the full joined source, not just its last scene.- assert_eq!(scene_frame_window(&request, 362).unwrap(), (243, 119));- assert_eq!(- scene_audio_offset(124, 24.0, 2, 48_000, 972_000).unwrap(),- 496_000- );- assert_eq!(- scene_audio_offset(243, 24.0, 2, 44_100, 2_000_000).unwrap(),- 893_026- );- assert_eq!(scene_audio_offset(124, 24.0, 0, 0, 0).unwrap(), 0);- assert!(scene_audio_offset(124, 24.0, 2, 48_000, 100).is_err());+ assert_eq!(scene_frame_window(&request, 243).unwrap(), (0, 243));+ assert_eq!(scene_frame_window(&request, 362).unwrap(), (0, 362));assert!(scene_frame_window(&request, 120).is_err());request.continuation_path = None;assert_eq!(scene_frame_window(&request, 124).unwrap(), (0, 124));diff --git a/src-tauri/src/project/commands/clips.rs b/src-tauri/src/project/commands/clips.rsindex d3e5794..7d1fe9a 100644--- a/src-tauri/src/project/commands/clips.rs+++ b/src-tauri/src/project/commands/clips.rs@@ -47,6 +47,8 @@ pub(super) fn apply(true,)?.max(frame_ms.max(1));+ let scene_ms = existing.and_then(|index| project.assets[index].scene_segments.as_ref()+ .and_then(|segments| segments.last()).map(|part| (f64::from(part.frame_count) * 1000.0 / 24.0).round() as u64)).unwrap_or(scene_ms);let asset_id = if let Some(index) = existing {project.assets[index].id.clone()} else {@@ -62,6 +64,7 @@ pub(super) fn apply(height: None,has_audio: None,image_generation: None,+ scene_segments: None,image_draft: None,parent_asset_id: None,created_at: job.created_at.clone(),@@ -90,7 +93,7 @@ pub(super) fn apply((media.id.clone(),media.name.clone(),- media.duration_ms.unwrap_or(5_000).max(1),+ media.clip_duration_ms().unwrap_or(5_000).max(1),"approved",false,)@@ -307,7 +310,7 @@ pub(super) fn validate_source_range(if asset.kind == "image" {return Ok(());}- if let Some(source_duration_ms) = asset.duration_ms {+ if let Some(source_duration_ms) = asset.clip_duration_ms() {let end = source_start_ms.checked_add(duration_ms).ok_or_else(|| "clip source range is too large".to_string())?;diff --git a/src-tauri/src/project/commands/tests.rs b/src-tauri/src/project/commands/tests.rsindex 15d3511..8de0145 100644--- a/src-tauri/src/project/commands/tests.rs+++ b/src-tauri/src/project/commands/tests.rs@@ -40,6 +40,25 @@ fn fixture() -> ProjectConfig {.unwrap()}+#[test]+fn joined_video_clip_commands_use_scene_relative_lengths_and_trims() {+ let mut config = fixture();+ let mut asset = config.assets[0].clone();+ asset.id = "joined-video".into();+ asset.kind = "generated".into();+ asset.duration_ms = Some(10125);+ asset.scene_segments = Some(vec![SceneMediaSegment { scene_id: "continued".into(),+ latent_relative_path: "latents/continued.safetensors".into(), start_frame: 124, frame_count: 119 }]);+ config.assets.push(asset);+ let command: ProjectCommand = serde_json::from_value(serde_json::json!({ "op": "clip.add", "id": "joined-clip", "asset": "joined-video" })).unwrap();+ let next = execute_commands_at(&config, &[command], "2026-10-03T00:00:00.000Z").unwrap();+ let clip = next.timeline.tracks.iter().flat_map(|track| &track.clips).find(|clip| clip.id == "joined-clip").unwrap();+ assert_eq!(clip.source_start_ms, 0);+ assert_eq!(clip.duration_ms, 4958);+ let invalid: ProjectCommand = serde_json::from_value(serde_json::json!({ "op": "clip.set", "id": "joined-clip", "seconds": 6 })).unwrap();+ assert!(execute_commands_at(&next, &[invalid], "2026-10-03T00:00:00.000Z").is_err());+}+#[test]fn parses_jsonl_and_preserves_explicit_null_patches() {let batch = parse_jsonl_commands(diff --git a/src-tauri/src/project/model.rs b/src-tauri/src/project/model.rsindex 97b9f20..7a32158 100644--- a/src-tauri/src/project/model.rs+++ b/src-tauri/src/project/model.rs@@ -65,6 +65,15 @@ pub(crate) struct GenerationBrief {pub(crate) resolution: String,}+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]+#[serde(rename_all = "camelCase")]+pub(crate) struct SceneMediaSegment {+ pub(crate) scene_id: String,+ pub(crate) latent_relative_path: String,+ pub(crate) start_frame: u32,+ pub(crate) frame_count: u32,+}+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub(crate) struct ProjectAsset {@@ -95,6 +104,8 @@ pub(crate) struct ProjectAsset {#[serde(skip_serializing_if = "Option::is_none")]pub(crate) has_audio: Option<bool>,#[serde(default, skip_serializing_if = "Option::is_none")]+ pub(crate) scene_segments: Option<Vec<SceneMediaSegment>>,+ #[serde(default, skip_serializing_if = "Option::is_none")]pub(crate) image_generation: Option<super::image::ImageGenerationSnapshot>,#[serde(default, skip_serializing_if = "Option::is_none")]pub(crate) image_draft: Option<bool>,@@ -110,6 +121,14 @@ pub(crate) struct AgentConversation {pub(crate) messages: Vec<AgentMessage>,}+impl ProjectAsset {+ pub(crate) fn clip_duration_ms(&self) -> Option<u64> {+ self.scene_segments.as_ref().and_then(|segments| segments.last())+ .map(|segment| (f64::from(segment.frame_count) * 1000.0 / 24.0).round() as u64)+ .or(self.duration_ms)+ }+}+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub(crate) struct AgentMessage {diff --git a/src-tauri/src/project/validation/assets.rs b/src-tauri/src/project/validation/assets.rsindex f070c34..8ff405e 100644--- a/src-tauri/src/project/validation/assets.rs+++ b/src-tauri/src/project/validation/assets.rs@@ -3,6 +3,22 @@ use crate::project::paths::*;use crate::project::*;pub(super) fn validate(config: &mut ProjectConfig) -> Result<(), String> {for asset in &mut config.assets {+ if let Some(segments) = &mut asset.scene_segments {+ if asset.kind != "generated" || segments.is_empty() {+ return Err("Scene ranges require a generated video.".into());+ }+ let mut end = 0u64;+ for segment in segments {+ if segment.scene_id.trim().is_empty() || segment.frame_count == 0 || u64::from(segment.start_frame) < end {+ return Err("Invalid joined scene ranges.".into());+ }+ segment.latent_relative_path = normalize_project_path(&segment.latent_relative_path)?;+ end = u64::from(segment.start_frame) + u64::from(segment.frame_count);+ if asset.duration_ms.is_some_and(|duration| end as f64 > duration as f64 * 24.0 / 1000.0 + 1.0) {+ return Err("Joined scene range exceeds its video.".into());+ }+ }+ }if asset.image_draft == Some(true) && (asset.kind != "image" || !asset.image_generation.as_ref().is_some_and(|snapshot| snapshot.scene.root_type.as_deref() != Some("image") || snapshot.scene.source_image.is_some())) {return Err("Image drafts require a scene snapshot and image roots require a source.".into());}diff --git a/src-tauri/src/tests/media_access.rs b/src-tauri/src/tests/media_access.rsindex 1e5949c..0b9edbe 100644--- a/src-tauri/src/tests/media_access.rs+++ b/src-tauri/src/tests/media_access.rs@@ -111,7 +111,7 @@ fn external_media_is_readable_only_because_the_project_names_it() {width: None,height: None,has_audio: None,- image_generation: None,+ image_generation: None, scene_segments: None,image_draft: None,parent_asset_id: None,created_at: config.created_at.clone(),@@ -285,7 +285,7 @@ fn a_project_the_user_only_opened_reads_any_media_file_it_names() {width: None,height: None,has_audio: None,- image_generation: None,+ image_generation: None, scene_segments: None,image_draft: None,parent_asset_id: None,created_at: config.created_at.clone(),diff --git a/src-tauri/src/tests/persistence.rs b/src-tauri/src/tests/persistence.rsindex cd8d366..6b6d8cf 100644--- a/src-tauri/src/tests/persistence.rs+++ b/src-tauri/src/tests/persistence.rs@@ -388,7 +388,7 @@ fn a_project_file_only_yields_media_a_hand_edit_cannot_widen() {width: None,height: None,has_audio: None,- image_generation: None,+ image_generation: None, scene_segments: None,image_draft: None,parent_asset_id: None,created_at: config.created_at.clone(),diff --git a/src-tauri/src/tests/scenes.rs b/src-tauri/src/tests/scenes.rsindex c45ec87..e0635fa 100644--- a/src-tauri/src/tests/scenes.rs+++ b/src-tauri/src/tests/scenes.rs@@ -1,5 +1,23 @@use super::*;+#[test]+fn joined_scene_ranges_survive_save_and_validate_bounds() {+ let mut value = serde_json::to_value(fixture()).unwrap();+ value["assets"][0]["kind"] = serde_json::json!("generated");+ value["assets"][0]["durationMs"] = serde_json::json!(10125);+ value["assets"][0]["sceneSegments"] = serde_json::json!([+ { "sceneId": "a", "latentRelativePath": "latents/a.safetensors", "startFrame": 0, "frameCount": 124 },+ { "sceneId": "b", "latentRelativePath": "latents/b.safetensors", "startFrame": 124, "frameCount": 119 }+ ]);+ let config: ProjectConfig = serde_json::from_value(value).unwrap();+ let folder = tempfile::tempdir().unwrap();+ write_project(folder.path(), &config).unwrap();+ let mut restored = read_project(folder.path()).unwrap().config;+ assert_eq!(restored.assets[0].scene_segments, config.assets[0].scene_segments);+ restored.assets[0].scene_segments.as_mut().unwrap()[1].frame_count = 1200;+ assert!(validate_and_normalize_config(restored).is_err());+}+#[test]fn continuation_settings_migrate_and_survive_reordering_and_save() {let mut config = fixture();diff --git a/src/components/workspace/GeneratorView.test.tsx b/src/components/workspace/GeneratorView.test.tsxindex 6692a9e..d8a42f8 100644--- a/src/components/workspace/GeneratorView.test.tsx+++ b/src/components/workspace/GeneratorView.test.tsx@@ -555,6 +555,15 @@ describe("Generator scene controls", () => {fireEvent.click(screen.getByRole("button", { name: "Generate all" }));state.replace({ ...state.latest(), generationJobs: state.latest().generationJobs.map((job) => ({ ...job, status: "completed" })) });expect(screen.getByRole("button", { name: "Generate all" })).toHaveAttribute("data-tooltip", "Every fixed-seed scene is already up to date.");+ // Suffix-only renders from older versions must regenerate even with an+ // unchanged seed and prompt, so the source side of the join is recovered.+ const legacy = JSON.parse(state.latest().generationJobs[1].generationSnapshot!);+ delete legacy.continuationOutput;+ state.replace({ ...state.latest(), generationJobs: state.latest().generationJobs.map((job, index) => index === 1 ? { ...job, generationSnapshot: JSON.stringify(legacy) } : job) });+ expect(within(screen.getByRole("region", { name: "Second scene" })).getByText("Changed")).toBeInTheDocument();+ fireEvent.click(screen.getByRole("button", { name: "Generate all" }));+ expect(state.latest().generationJobs.map((job) => job.status)).toEqual(["completed", "queued"]);+ state.replace({ ...state.latest(), generationJobs: state.latest().generationJobs.map((job) => ({ ...job, status: "completed" })) });fireEvent.change(screen.getByRole("textbox", { name: "The sound of this scene" }), { target: { value: "Rain" } });fireEvent.click(screen.getByRole("button", { name: "Generate all" }));expect(state.latest().generationJobs.map((job) => job.status)).toEqual(["queued", "queued"]);diff --git a/src/components/workspace/GeneratorView.tsx b/src/components/workspace/GeneratorView.tsxindex c927d05..bc33707 100644--- a/src/components/workspace/GeneratorView.tsx+++ b/src/components/workspace/GeneratorView.tsx@@ -570,6 +570,7 @@ export function GeneratorView({ config, folderPath, runtime = null, generationCo<div className="generator-board">{jobs.length > 0? <SceneBoard+ assets={config.assets}jobs={jobs}folderPath={folderPath}generationCompletionTimes={generationCompletionTimes}diff --git a/src/components/workspace/ProgramMonitor.tsx b/src/components/workspace/ProgramMonitor.tsxindex 2075595..e805e80 100644--- a/src/components/workspace/ProgramMonitor.tsx+++ b/src/components/workspace/ProgramMonitor.tsx@@ -10,6 +10,7 @@ import { PreviewSources } from "../../lib/exportPipeline";import { preparedPreviewClips, previewSegmentIndex, previewSegments } from "../../lib/timelinePreview";import { PreviewMedia } from "../../lib/previewPresentation";import { PLAYBACK_SAMPLE_MS, previewEngine } from "../../lib/previewEngine";+import { continuationPlaybackTracks } from "../../lib/continuationMedia";/* The monitor owns a continuous timeline clock. Each visible or upcoming clip* owns a persistent media element: loading, decoding the first frame and seeking@@ -69,7 +70,7 @@ export function ProgramMonitor({ config, folderPath, playheadMs, playing, rate =onSelectClip?: (clipId: string) => void;onTransformChange?: (clipId: string, transform: ClipTransform) => void;}) {- const tracks = config.timeline.tracks;+ const tracks = useMemo(() => continuationPlaybackTracks(config), [config.timeline.tracks, config.assets, config.generationJobs]);const assetsById = useMemo(() => new Map(config.assets.map((candidate) => [candidate.id, candidate])), [config.assets]);const segments = useMemo(() => previewSegments(tracks, assetsById), [tracks, assetsById]);const segmentIndex = previewSegmentIndex(segments, playheadMs);diff --git a/src/components/workspace/SceneBoard.tsx b/src/components/workspace/SceneBoard.tsxindex 80cdd57..d4b7cbb 100644--- a/src/components/workspace/SceneBoard.tsx+++ b/src/components/workspace/SceneBoard.tsx@@ -15,6 +15,8 @@ import { useContextMenu, type MenuEntry } from "../ui";import { referenceOrder, STEP_SECONDS } from "./SceneEditor";import { statusIcon, STATUS_BADGE } from "./sceneStatus";import { ShotThumbnail } from "./ShotThumbnail";+import { sceneMediaStartSeconds } from "../../lib/continuationMedia";+import { generationAssetId, type ProjectAsset } from "../../lib/project";export interface GeneratorSelection {jobId: string;@@ -62,6 +64,7 @@ export const isMenuKey = (event: KeyboardEvent): boolean =>* targets, and both carry a right-click menu. */export function SceneBoard({jobs,+ assets = [],folderPath,generationCompletionTimes,references,@@ -81,6 +84,7 @@ export function SceneBoard({onRemoveShot,}: {jobs: GenerationJob[];+ assets?: ProjectAsset[];folderPath: string;generationCompletionTimes?: Readonly<Record<string, number>>;references: ProjectReference[];@@ -419,6 +423,7 @@ export function SceneBoard({}}><ShotCard+ sourceOffsetSeconds={sceneMediaStartSeconds(assets.find((asset) => asset.id === generationAssetId(job.id)))}job={job}shot={shot}index={index}@@ -476,11 +481,12 @@ function HeaderButton({ label, tooltip, className = "", disabled, onClick, child><span aria-hidden="true">{children}</span></button>;}-function ShotCard({ job, shot, index, endsAt, folderPath, estimatedCompletionAt, order, named, density, cancelling, open, dragSource, tabbable, onOpen, onMenu, onDragStart, onDragEnd }: {+function ShotCard({ job, shot, index, endsAt, sourceOffsetSeconds, folderPath, estimatedCompletionAt, order, named, density, cancelling, open, dragSource, tabbable, onOpen, onMenu, onDragStart, onDragEnd }: {job: GenerationJob;shot: SceneShot;index: number;endsAt: number;+ sourceOffsetSeconds: number;folderPath: string;estimatedCompletionAt: number | null;order: string[];@@ -514,7 +520,7 @@ function ShotCard({ job, shot, index, endsAt, folderPath, estimatedCompletionAt,onDragEnd={onDragEnd}onContextMenu={onMenu}>- {density === "tiles" && <ShotThumbnail folderPath={folderPath} job={job} seconds={shot.startSeconds} endSeconds={endsAt} shotNumber={index + 1} estimatedCompletionAt={estimatedCompletionAt} cancelling={cancelling} onPlay={onOpen} />}+ {density === "tiles" && <ShotThumbnail folderPath={folderPath} job={job} seconds={shot.startSeconds} endSeconds={endsAt} sourceOffsetSeconds={sourceOffsetSeconds} shotNumber={index + 1} estimatedCompletionAt={estimatedCompletionAt} cancelling={cancelling} onPlay={onOpen} />}<buttontype="button"className="shot-card__open-control"diff --git a/src/components/workspace/ShotThumbnail.test.tsx b/src/components/workspace/ShotThumbnail.test.tsxindex 68db228..0df7479 100644--- a/src/components/workspace/ShotThumbnail.test.tsx+++ b/src/components/workspace/ShotThumbnail.test.tsx@@ -100,6 +100,23 @@ const rendered = (folder: string): GenerationJob => {};describe("a shot's picture", () => {+ it("previews the new scene inside its joined file and stops at the offset cut", async () => {+ const folder = "C:\\Joined scene playback";+ const job = rendered(folder);+ await withFakeFile({ seconds: 20 }, async (seen) => {+ render(<ShotThumbnail folderPath={folder} job={job} seconds={0} endSeconds={2} sourceOffsetSeconds={5} shotNumber={1} />);+ fireEvent.click(await screen.findByRole("button", { name: "Play shot 1 of First scene" }));+ await waitFor(() => expect(screen.getByRole("button", { name: "Pause shot 1 of First scene" })).not.toBeNull());+ expect(seen.seeks).toContain(5);+ const video = document.querySelector("video")!;+ video.currentTime = 6;+ fireEvent.timeUpdate(video);+ expect(screen.getByRole("button", { name: "Pause shot 1 of First scene" })).not.toBeNull();+ video.currentTime = 7;+ fireEvent.timeUpdate(video);+ expect(screen.getByRole("button", { name: "Play shot 1 of First scene" })).not.toBeNull();+ });+ });it("can draw the exact first frame for a scene card", async () => {const folder = "C:\\Exact first frame";const job = rendered(folder);diff --git a/src/components/workspace/ShotThumbnail.tsx b/src/components/workspace/ShotThumbnail.tsxindex 0b960c5..f0ab707 100644--- a/src/components/workspace/ShotThumbnail.tsx+++ b/src/components/workspace/ShotThumbnail.tsx@@ -261,7 +261,7 @@ export function formatEstimatedTimeLeft(milliseconds: number): string {return `${minutes}m ${seconds}s left`;}-export function ShotThumbnail({ folderPath, job, seconds, endSeconds = sceneDurationSeconds(job), shotNumber, estimatedCompletionAt = null, cancelling = false, onPlay }: {+export function ShotThumbnail({ folderPath, job, seconds, endSeconds = sceneDurationSeconds(job), sourceOffsetSeconds = 0, shotNumber, estimatedCompletionAt = null, cancelling = false, onPlay }: {folderPath: string;/** The scene this shot belongs to: it owns the file and the status. */job: GenerationJob;@@ -269,6 +269,7 @@ export function ShotThumbnail({ folderPath, job, seconds, endSeconds = sceneDuraseconds: number;/** The next cut (or scene end). Playback never crosses this point. */endSeconds?: number;+ sourceOffsetSeconds?: number;shotNumber: number;/** Live rendering estimate derived from slopfab timing; never persisted. */estimatedCompletionAt?: number | null;@@ -278,7 +279,8 @@ export function ShotThumbnail({ folderPath, job, seconds, endSeconds = sceneDuraonPlay?: () => void;}) {const relativePath = job.status === "completed" ? job.outputRelativePath : null;- const at = seconds;+ const at = seconds + sourceOffsetSeconds;+ const endAt = endSeconds + sourceOffsetSeconds;const playbackId = `${job.id}@${seconds}`;const [result, setResult] = useState<PosterResult>(() =>relativePath ? { poster: POSTERS.get(posterKey(fileKey(folderPath, relativePath), at)) ?? null, failed: false } : NOTHING);@@ -311,7 +313,7 @@ export function ShotThumbnail({ folderPath, job, seconds, endSeconds = sceneDuraawait video.play();setPlaying(true);const rate = video.playbackRate > 0 ? video.playbackRate : 1;- cutTimerRef.current = window.setTimeout(finishPlayback, Math.max(0, (endSeconds - video.currentTime) * 1_000 / rate));+ cutTimerRef.current = window.setTimeout(finishPlayback, Math.max(0, (endAt - video.currentTime) * 1_000 / rate));} catch {setPlayFailed(true);}@@ -355,7 +357,7 @@ export function ShotThumbnail({ folderPath, job, seconds, endSeconds = sceneDuraconst stopAtCut = () => {const video = videoRef.current;- if (!video || video.currentTime + 0.02 < endSeconds) return;+ if (!video || video.currentTime + 0.02 < endAt) return;finishPlayback();};@@ -371,7 +373,7 @@ export function ShotThumbnail({ folderPath, job, seconds, endSeconds = sceneDura} else {onPlay?.();window.dispatchEvent(new CustomEvent<string>(PLAY_EVENT, { detail: playbackId }));- if (video.currentTime < seconds || video.currentTime >= endSeconds) video.currentTime = seconds;+ if (video.currentTime < at || video.currentTime >= endAt) video.currentTime = at;await playToCut(video);}return;@@ -416,7 +418,7 @@ export function ShotThumbnail({ folderPath, job, seconds, endSeconds = sceneDurasrc={playbackUrl}playsInlineonLoadedMetadata={(event) => {- event.currentTarget.currentTime = Math.min(seconds, Math.max(0, event.currentTarget.duration - 0.01));+ event.currentTarget.currentTime = Math.min(at, Math.max(0, event.currentTarget.duration - 0.01));void playToCut(event.currentTarget);}}onTimeUpdate={stopAtCut}diff --git a/src/components/workspace/TimelineView.tsx b/src/components/workspace/TimelineView.tsxindex b2b1d50..eea70c8 100644--- a/src/components/workspace/TimelineView.tsx+++ b/src/components/workspace/TimelineView.tsx@@ -1,4 +1,5 @@import { clipEffectCount, ClipEffects } from "./ClipEffects";+import { continuationPlaybackTracks, sceneMediaDurationMs, sceneMediaStartSeconds } from "../../lib/continuationMedia";import { ProjectStatus } from "./ProjectStatus";import { PreviewEngineStatus } from "./PreviewEngineStatus";import {@@ -311,6 +312,7 @@ export function TimelineView({ config, folderPath, generationCompletionTimes = {const generatedJobsByAssetId = useMemo(() => new Map(config.generationJobs.map((job) => [generationAssetId(job.id), job]),), [config.generationJobs]);+ const playbackClips = useMemo(() => new Map(continuationPlaybackTracks(config).flatMap((track) => track.clips).map((clip) => [clip.id, clip])), [config.timeline.tracks, config.assets, config.generationJobs]);/* V1, V2… and A1, A2… — the track's kind and its place among its kind, thelabel every NLE puts on a track header. */const trackLabels = useMemo(() => {@@ -791,7 +793,7 @@ export function TimelineView({ config, folderPath, generationCompletionTimes = {is only bounded from below. */const selectedAsset = selected ? assetById(selected.assetId) : undefined;const sourceLimitMs = selected && selectedAsset?.kind !== "image" && selectedAsset?.durationMs- ? Math.max(1, selectedAsset.durationMs - selected.sourceStartMs)+ ? Math.max(1, (sceneMediaDurationMs(selectedAsset) ?? selectedAsset.durationMs) - selected.sourceStartMs): null;const minClipMs = Math.max(1, Math.round(1000 / fps));/** What the FILE has left at each end of a clip. A still image and a file@@ -799,7 +801,7 @@ export function TimelineView({ config, folderPath, generationCompletionTimes = {* limit rather than a guessed one. */const roomFor = (clip: TimelineClip) => {const asset = assetById(clip.assetId);- return sourceRoom(clip, asset && asset.kind !== "image" ? asset.durationMs ?? null : null);+ return sourceRoom(clip, asset && asset.kind !== "image" ? sceneMediaDurationMs(asset) ?? null : null);};/* Typing a length is trimming the tail, so it is the same operation theright-hand handle performs — same floor of one frame, same ceiling in the@@ -891,7 +893,7 @@ export function TimelineView({ config, folderPath, generationCompletionTimes = {assetId: asset.id,trackId,startMs,- durationMs: sceneLengthMs,+ durationMs: existing?.sceneSegments?.length ? sceneMediaDurationMs(existing)! : sceneLengthMs,sourceStartMs: 0,label: currentJob.title,color: null,@@ -1230,7 +1232,7 @@ export function TimelineView({ config, folderPath, generationCompletionTimes = {{...tooltipProps(`${job.title} · ${sceneShape(job)}. Drag onto a track to use it.`)}><span className="scene-card__thumb">- {job.status !== "draft" ? <ShotThumbnail folderPath={folderPath} job={job} seconds={0} shotNumber={1} estimatedCompletionAt={generationCompletionTimes[job.id] ?? null} />+ {job.status !== "draft" ? <ShotThumbnail folderPath={folderPath} job={job} seconds={0} sourceOffsetSeconds={sceneMediaStartSeconds(assetsById.get(generationAssetId(job.id)))} shotNumber={1} estimatedCompletionAt={generationCompletionTimes[job.id] ?? null} />: <Film20 aria-hidden="true" />}<i>{String(index + 1).padStart(2, "0")}</i><em>{sceneDurationSeconds(job).toFixed(1)}s</em></span>@@ -1534,6 +1536,7 @@ export function TimelineView({ config, folderPath, generationCompletionTimes = {folderPath={folderPath}generatedJobsByAssetId={generatedJobsByAssetId}assetsById={assetsById}+ playbackClips={playbackClips}selectedId={selectedId}draggingId={dragging ? dragRef.current?.clipId : undefined}dropActive={dropTrackId === track.id}@@ -1641,7 +1644,7 @@ const TimeRuler = memo(function TimeRuler({ rulerRef, scrollRef, durationMs, lan</div>;});-const TrackRow = memo(function TrackRow({ track, alt, label, duration, folderPath, generatedJobsByAssetId, assetsById, selectedId, draggingId, dropActive, dropBlocked, actions }: {+const TrackRow = memo(function TrackRow({ track, alt, label, duration, folderPath, generatedJobsByAssetId, assetsById, playbackClips, selectedId, draggingId, dropActive, dropBlocked, actions }: {track: ProjectConfig["timeline"]["tracks"][number];/** Every other lane sits a step lighter on the well. */alt: boolean;@@ -1651,6 +1654,7 @@ const TrackRow = memo(function TrackRow({ track, alt, label, duration, folderPatfolderPath: string;generatedJobsByAssetId: ReadonlyMap<string, GenerationJob>;assetsById: ReadonlyMap<string, ProjectAsset>;+ playbackClips: ReadonlyMap<string, TimelineClip>;selectedId: string;/** The clip currently being dragged, so it can be drawn as the thing under* the pointer rather than as one more clip sitting on the lane. */@@ -1692,9 +1696,10 @@ const TrackRow = memo(function TrackRow({ track, alt, label, duration, folderPatonContextMenu={(event) => { if (event.target === event.currentTarget) actions.current.laneMenu(event, track); }}>{track.clips.map((clip) => {- const asset = assetsById.get(clip.assetId);+ const playbackClip = playbackClips.get(clip.id) ?? clip;+ const asset = assetsById.get(playbackClip.assetId);const audioOnly = asset?.kind === "audio";- const generation = generatedJobsByAssetId.get(clip.assetId);+ const generation = generatedJobsByAssetId.get(playbackClip.assetId);/* Current renders record this exactly. Completed files from projectssaved before that metadata existed use the successful saved outputas the compatibility signal; an explicit false always wins. */@@ -1742,12 +1747,12 @@ const TrackRow = memo(function TrackRow({ track, alt, label, duration, folderPat{!audioOnly && generation && <TimelineClipThumbnailsfolderPath={folderPath}job={generation}- clip={clip}+ clip={playbackClip}/>}{hasAudio && asset && <TimelineClipWaveformfolderPath={folderPath}asset={asset}- clip={clip}+ clip={playbackClip}cacheVersion={generation?.updatedAt}/>}</div>diff --git a/src/lib/continuationMedia.test.ts b/src/lib/continuationMedia.test.tsnew file mode 100644index 0000000..bbac25d--- /dev/null+++ b/src/lib/continuationMedia.test.ts@@ -0,0 +1,105 @@+import { expect, it } from "vitest";+import { assetSceneSegment, continuationPlaybackTracks, joinedSceneSegments, sceneArchiveSegments, sceneMediaDurationMs } from "./continuationMedia";+import { createDraftGenerationJob, createProjectConfig, generationAssetId, parseProjectConfig, sceneOutputFrames, type SceneMediaSegment } from "./project";+import { buildExportPlan, defaultExportSettings } from "./export";++function project() {+ const config = createProjectConfig({ name: "Joined", prompt: "Ride", aspectRatio: "16:9", resolution: "416p", targetDurationSeconds: 15 });+ const segments: SceneMediaSegment[] = [+ { sceneId: "a", latentRelativePath: "latents/a.safetensors", startFrame: 0, frameCount: 124 },+ { sceneId: "b", latentRelativePath: "latents/b.safetensors", startFrame: 124, frameCount: 119 },+ { sceneId: "c", latentRelativePath: "latents/c.safetensors", startFrame: 243, frameCount: 119 },+ ];+ config.generationJobs = segments.map((part) => ({ ...createDraftGenerationJob("Ride", { id: part.sceneId }), status: "completed" as const, latentRelativePath: part.latentRelativePath }));+ config.assets = segments.map((part, index) => ({ id: generationAssetId(part.sceneId), kind: "generated", mimeType: "video/mp4", name: part.sceneId,+ relativePath: `media/${part.sceneId}.mp4`, hasAudio: true, createdAt: config.createdAt,+ durationMs: Math.round((part.startFrame + part.frameCount) * 1000 / 24), sceneSegments: segments.slice(0, index + 1),+ }));+ let startMs = 0;+ config.timeline.tracks[0].clips = segments.map((part) => {+ const durationMs = Math.round(part.frameCount * 1000 / 24);+ const clip = { id: part.sceneId, assetId: generationAssetId(part.sceneId), trackId: config.timeline.tracks[0].id, label: part.sceneId,+ startMs, sourceStartMs: 0, durationMs, status: "generated" as const, transform: { scale: 80, rotation: 0, positionX: 0, positionY: 0 } };+ startMs += durationMs;+ return clip;+ });+ return parseProjectConfig(config);+}++it("uses one joined source for both sides of every boundary in a chain, including exported audio", () => {+ const config = project();+ const authored = JSON.stringify(config.timeline);+ const clips = continuationPlaybackTracks(config)[0].clips;+ expect(clips.map((clip) => clip.assetId)).toEqual(["asset-c", "asset-c", "asset-c"]);+ expect(clips.map((clip) => clip.sourceStartMs)).toEqual([0, 124 * 1000 / 24, 243 * 1000 / 24]);+ expect(clips.map((clip) => clip.transform)).toEqual(config.timeline.tracks[0].clips.map((clip) => clip.transform));+ const plan = buildExportPlan(config, defaultExportSettings(config));+ expect(plan.segments.filter((segment) => segment.kind === "clip").map((segment) => segment.assetId)).toEqual(["asset-c", "asset-c", "asset-c"]);+ expect(plan.audio.map((segment) => segment.assetId)).toEqual(["asset-c", "asset-c", "asset-c"]);+ expect(plan.audio.map((segment) => segment.sourceStartMs)).toEqual(clips.map((clip) => clip.sourceStartMs));+ expect(JSON.stringify(config.timeline)).toBe(authored);+ expect(sceneOutputFrames(config.generationJobs[2], config)).toBe(119);+ expect(sceneMediaDurationMs(config.assets[2])).toBe(4958);+ expect(parseProjectConfig(JSON.parse(JSON.stringify(config))).assets[2].sceneSegments).toEqual(config.assets[2].sceneSegments);+});++it("keeps standalone scenes and trims in scene coordinates", () => {+ const config = project();+ const b = config.timeline.tracks[0].clips[1];+ b.sourceStartMs = 500;+ b.durationMs -= 500;+ config.timeline.tracks[0].clips = [b];+ const resolved = continuationPlaybackTracks(config)[0].clips[0];+ expect(resolved).toMatchObject({ assetId: "asset-b", sourceStartMs: 124 * 1000 / 24 + 500, durationMs: b.durationMs });+});++it("shares joined sources across a cut between different tracks", () => {+ const config = project();+ const b = config.timeline.tracks[0].clips.splice(1, 1)[0];+ config.timeline.tracks[1].clips = [{ ...b, trackId: config.timeline.tracks[1].id }];+ expect(continuationPlaybackTracks(config).flatMap((track) => track.clips).map((clip) => clip.assetId)).toEqual(["asset-c", "asset-c", "asset-c"]);+});++it("does not silently switch to a different source generation or bridge gaps", () => {+ const config = project();+ config.assets[0].sceneSegments![0] = { ...config.assets[0].sceneSegments![0], latentRelativePath: "latents/a-rerender.safetensors" };+ expect(continuationPlaybackTracks(config)[0].clips[0].assetId).toBe("asset-a");+ config.timeline.tracks[0].clips[2].startMs += 100;+ expect(continuationPlaybackTracks(config)[0].clips[1].assetId).toBe("asset-b");+});++it("preserves branch identity when the same source appears before different continuations", () => {+ const config = project();+ const [a, b, c] = config.timeline.tracks[0].clips;+ config.assets[2].sceneSegments = joinedSceneSegments("c", "latents/c.safetensors", 243, 119, {+ sceneId: "a", latentRelativePath: "latents/a.safetensors", frameCount: 124, segments: config.assets[0].sceneSegments!,+ });+ config.timeline.tracks[0].clips = [a, b, { ...a, id: "a-again", startMs: c.startMs }, { ...c, startMs: c.startMs + a.durationMs }];+ expect(continuationPlaybackTracks(config)[0].clips.map((clip) => clip.assetId)).toEqual(["asset-b", "asset-b", "asset-c", "asset-c"]);+});++it("reconstructs old suffix-only archives from saved generations, not edited scene settings", () => {+ const config = project();+ config.assets.forEach((asset) => { asset.durationMs = sceneMediaDurationMs(asset); delete asset.sceneSegments; });+ config.generationJobs[1].generationSnapshot = JSON.stringify({ continuationRelativePath: "latents/a.safetensors", previousSceneId: "a", frames: 119 });+ config.generationJobs[1].continuationSceneId = "c";+ const prefix = sceneArchiveSegments(config, config.generationJobs[1])!;+ expect(prefix.map((part) => part.startFrame)).toEqual([0, 124]);+ config.assets[2].durationMs = Math.round(362 * 1000 / 24);+ config.assets[2].sceneSegments = joinedSceneSegments("c", "latents/c.safetensors", 362, 119, {+ sceneId: "b", latentRelativePath: "latents/b.safetensors", frameCount: 119, segments: prefix,+ });+ expect(continuationPlaybackTracks(config)[0].clips.map((clip) => clip.assetId)).toEqual(["asset-c", "asset-c", "asset-c"]);+ expect(assetSceneSegment(config.assets[1], config.generationJobs)?.startFrame).toBe(0);+});++it("keeps Beginning overlap ranges separate and rejects suffix-only worker results", () => {+ const config = project();+ config.assets[1].sceneSegments = joinedSceneSegments("b", "latents/b.safetensors", 141, 119, {+ sceneId: "a", latentRelativePath: "latents/a.safetensors", frameCount: 124, from: "start",+ });+ config.timeline.tracks[0].clips.pop();+ expect(continuationPlaybackTracks(config)[0].clips.map((clip) => clip.assetId)).toEqual(["asset-a", "asset-b"]);+ expect(config.assets[1].sceneSegments.map((part) => [part.startFrame, part.frameCount])).toEqual([[0, 22], [22, 119]]);+ expect(() => joinedSceneSegments("b", "latents/b.safetensors", 119, 119, { sceneId: "a", latentRelativePath: "latents/a.safetensors", frameCount: 124 })).toThrow("Update the worker");+});diff --git a/src/lib/continuationMedia.ts b/src/lib/continuationMedia.tsnew file mode 100644index 0000000..9238d1e--- /dev/null+++ b/src/lib/continuationMedia.ts@@ -0,0 +1,93 @@+import { GENERATION_FRAME_RATE, generationAssetId, sceneOutputFrames, type GenerationJob, type ProjectAsset, type ProjectConfig, type SceneMediaSegment, type TimelineClip } from "./project";++const milliseconds = (frames: number) => frames * 1000 / GENERATION_FRAME_RATE;+export const sceneMediaStartSeconds = (asset?: ProjectAsset) => (asset?.sceneSegments?.at(-1)?.startFrame ?? 0) / GENERATION_FRAME_RATE;++/** Editing coordinates stay relative to the scene, even when its file contains+ * the whole chain. Old, suffix-only assets need no offset. */+export const sceneMediaDurationMs = (asset: ProjectAsset): number | null | undefined =>+ asset.sceneSegments?.length ? Math.round(milliseconds(asset.sceneSegments.at(-1)!.frameCount)) : asset.durationMs;++export function assetSceneSegment(asset: ProjectAsset, jobs: readonly GenerationJob[]): SceneMediaSegment | undefined {+ if (asset.sceneSegments?.length) return asset.sceneSegments.at(-1);+ const job = jobs.find((candidate) => generationAssetId(candidate.id) === asset.id);+ return job?.latentRelativePath && asset.durationMs ? {+ sceneId: job.id, latentRelativePath: job.latentRelativePath, startFrame: 0,+ frameCount: Math.round(asset.durationMs * GENERATION_FRAME_RATE / 1000),+ } : undefined;+}++/** Reconstruct old suffix-only generations when their saved snapshots still+ * identify the exact ancestors. Current editable continuation settings are+ * deliberately ignored: they may describe a different, unrendered branch. */+export function sceneArchiveSegments(config: ProjectConfig, job: GenerationJob, seen = new Set<string>()): SceneMediaSegment[] | undefined {+ if (!job.latentRelativePath || seen.has(job.id)) return undefined;+ seen.add(job.id);+ const asset = config.assets.find((candidate) => candidate.id === generationAssetId(job.id));+ if (asset?.sceneSegments?.at(-1)?.latentRelativePath === job.latentRelativePath) return asset.sceneSegments;+ const frames = sceneOutputFrames(job, config);+ if (!frames) return undefined;+ try {+ const snapshot = JSON.parse(job.generationSnapshot ?? "null");+ if (snapshot?.continuationRelativePath) {+ const source = config.generationJobs.find((candidate) => candidate.id === snapshot.previousSceneId && candidate.latentRelativePath === snapshot.continuationRelativePath);+ if (!source) return undefined;+ const prefix = snapshot.continuationFrom === "start"+ ? [{ sceneId: source.id, latentRelativePath: source.latentRelativePath!, startFrame: 0, frameCount: snapshot.continuationOverlapFrames ?? 22 }]+ : sceneArchiveSegments(config, source, seen);+ if (!prefix?.length) return undefined;+ const last = prefix.at(-1)!;+ return [...prefix, { sceneId: job.id, latentRelativePath: job.latentRelativePath, startFrame: last.startFrame + last.frameCount, frameCount: frames }];+ }+ } catch { return undefined; }+ return [{ sceneId: job.id, latentRelativePath: job.latentRelativePath, startFrame: 0, frameCount: frames }];+}++/** Map adjacent scene clips to one jointly decoded source, without rewriting+ * authored trims, effects, placement or asset identity. Resolve backwards so+ * A -> B -> C uses C's joined decode throughout the chain. */+export function continuationPlaybackTracks(config: ProjectConfig) {+ const assets = new Map(config.assets.map((asset) => [asset.id, asset]));+ const resolved = new Map<string, TimelineClip>();+ const sorted = config.timeline.tracks.flatMap((track) => track.clips).sort((a, b) => a.startMs - b.startMs);+ for (let index = sorted.length - 1; index >= 0; index--) {+ const clip = sorted[index];+ const asset = assets.get(clip.assetId);+ const own = asset && assetSceneSegment(asset, config.generationJobs);+ let source = asset;+ let segment = own;+ if (own) {+ const following = sorted.filter((next) => next.id !== clip.id && Math.abs(clip.startMs + clip.durationMs - next.startMs) <= 1)+ .sort((a, b) => Number(b.trackId === clip.trackId) - Number(a.trackId === clip.trackId));+ for (const next of following) {+ const nextClip = resolved.get(next.id);+ const joined = nextClip && assets.get(nextClip.assetId);+ const matching = joined?.sceneSegments?.find((part) => part.sceneId === own.sceneId && part.latentRelativePath === own.latentRelativePath);+ // A Beginning continuation contains only the opening overlap, so do+ // not pretend that its source file contains the whole original scene.+ if (matching && clip.sourceStartMs + clip.durationMs <= milliseconds(matching.frameCount) + 1) {+ source = joined;+ segment = matching;+ break;+ }+ }+ }+ resolved.set(clip.id, source && segment ? { ...clip, assetId: source.id, sourceStartMs: clip.sourceStartMs + milliseconds(segment.startFrame) } : clip);+ }+ return config.timeline.tracks.map((track) => ({ ...track, clips: track.clips.map((clip) => resolved.get(clip.id)!) }));+}++/** Called with the source metadata captured when the queue attaches latents,+ * rather than with settings that the user may have edited during generation. */+export function joinedSceneSegments(sceneId: string, latentRelativePath: string, totalFrames: number, newFrames: number,+ source?: { sceneId: string; latentRelativePath: string; frameCount: number; segments?: readonly SceneMediaSegment[]; from?: "start" | "end" }): SceneMediaSegment[] {+ const prefix = source ? totalFrames - newFrames : 0;+ if (prefix < 0 || newFrames <= 0 || (source && prefix <= 0)) throw new Error("The continuation output is missing its joined source frames. Update the worker and regenerate.");+ let segments: SceneMediaSegment[] = [];+ if (source) {+ if (source.from === "start") segments = [{ sceneId: source.sceneId, latentRelativePath: source.latentRelativePath, startFrame: 0, frameCount: prefix }];+ else if (source.segments?.length && source.segments.at(-1)!.startFrame + source.segments.at(-1)!.frameCount === prefix) segments = [...source.segments];+ else segments = [{ sceneId: source.sceneId, latentRelativePath: source.latentRelativePath, startFrame: Math.max(0, prefix - source.frameCount), frameCount: Math.min(prefix, source.frameCount) }];+ }+ return [...segments, { sceneId, latentRelativePath, startFrame: prefix, frameCount: source ? newFrames : totalFrames }];+}diff --git a/src/lib/export.ts b/src/lib/export.tsindex 21627f7..7bcd5c2 100644--- a/src/lib/export.ts+++ b/src/lib/export.ts@@ -27,6 +27,7 @@ import {type TimelineClip,type TimelineTrack,} from "./project";+import { continuationPlaybackTracks } from "./continuationMedia";export type FrameRate = ProjectConfig["settings"]["frameRate"];export type OutputCodecId = "h264" | "vp9" | "av1";@@ -482,6 +483,7 @@ export function videoDurationMs(config: ProjectConfig): number {}export function buildExportPlan(config: ProjectConfig, settings: ExportSettings): ExportPlan {+ config = { ...config, timeline: { tracks: continuationPlaybackTracks(config) } };const { width, height } = settings;const frameRate = settings.frameRate;const tracks = config.timeline.tracks;diff --git a/src/lib/project.ts b/src/lib/project.tsindex 6f2e741..c73b5b3 100644--- a/src/lib/project.ts+++ b/src/lib/project.ts@@ -156,6 +156,14 @@ export const imageGenerationSnapshotSchema = z.object({});export type ImageGenerationSnapshot = z.infer<typeof imageGenerationSnapshotSchema>;+export const sceneMediaSegmentSchema = z.object({+ sceneId: idSchema,+ latentRelativePath: projectRelativePathSchema,+ startFrame: z.number().int().nonnegative(),+ frameCount: z.number().int().positive(),+});+export type SceneMediaSegment = z.infer<typeof sceneMediaSegmentSchema>;+export const projectAssetSchema = z.object({id: idSchema,kind: z.enum(["video", "audio", "image", "caption", "generated"]),@@ -179,6 +187,9 @@ export const projectAssetSchema = z.object({height: z.number().int().positive().nullish(),/** Whether the container has an audio stream. */hasAudio: z.boolean().nullish(),+ /** Ranges in a joined 24 fps decode; the final range is this asset's scene.+ * Latent paths identify the exact source generations, including branches. */+ sceneSegments: z.array(sceneMediaSegmentSchema).min(1).nullish(),imageGeneration: imageGenerationSnapshotSchema.nullish(),imageDraft: z.boolean().nullish(),/** The family's primary image. Always its first image, never another child,@@ -187,6 +198,15 @@ export const projectAssetSchema = z.object({createdAt: isoDateSchema,}).superRefine((asset, context) => {checkOneLocation(asset, context, `Asset '${asset.id}'`);+ if (asset.sceneSegments) {+ let end = 0;+ for (const segment of asset.sceneSegments) {+ if (asset.kind !== "generated" || segment.startFrame < end || (asset.durationMs != null && segment.startFrame + segment.frameCount > asset.durationMs * 24 / 1000 + 1)) {+ context.addIssue({ code: z.ZodIssueCode.custom, path: ["sceneSegments"], message: "Invalid joined scene ranges." });+ }+ end = segment.startFrame + segment.frameCount;+ }+ }if (asset.imageDraft && (asset.kind !== "image" || !asset.imageGeneration || (asset.imageGeneration.scene.rootType === "image" && !asset.imageGeneration.scene.sourceImage))) {context.addIssue({ code: z.ZodIssueCode.custom, message: "Image drafts require a scene snapshot and image roots require a source." });}@@ -979,6 +999,8 @@ export function continuationBlocker(job: GenerationJob, jobs: readonly Generatio/** The saved scene's output length, not the current editable duration. */export function sceneOutputFrames(job: GenerationJob, config: ProjectConfig): number | undefined {const asset = config.assets.find((candidate) => candidate.id === generationAssetId(job.id));+ const segment = asset?.sceneSegments?.at(-1);+ if (segment?.sceneId === job.id) return segment.frameCount;if (asset?.durationMs) return Math.round(asset.durationMs * GENERATION_FRAME_RATE / 1000);try {const snapshot = JSON.parse(job.generationSnapshot ?? "null");@@ -1130,7 +1152,7 @@ export function sceneGenerationSnapshot(job: GenerationJob, input: SceneGenerati...(input.refmods?.length ? { refmods: input.refmods } : {}),...(input.previousSceneId ? { previousSceneId: input.previousSceneId } : {}),...(input.continuationRelativePath ? { continuationRelativePath: input.continuationRelativePath } : {}),- ...(input.previousSceneId ? { continuationOverlapFrames: input.continuationOverlapFrames ?? DEFAULT_CONTINUATION_OVERLAP,+ ...(input.previousSceneId ? { continuationOutput: "joined", continuationOverlapFrames: input.continuationOverlapFrames ?? DEFAULT_CONTINUATION_OVERLAP,continuationFrom: input.continuationFrom ?? "end", ...(input.continuationSourceFrames ? { continuationSourceFrames: input.continuationSourceFrames } : {}) } : {}),shots,});diff --git a/src/lib/runtime.ts b/src/lib/runtime.tsindex 9618201..c3cc7ee 100644--- a/src/lib/runtime.ts+++ b/src/lib/runtime.ts@@ -4,6 +4,7 @@ import { applyImageCommand, type ImageCommand } from "./imageCommands";import { isTauri } from "./persistence";import type { TemplateLora } from "./loras";import { refreshDownloadedLoras, refreshDownloadedWeights } from "./weightDownloads";+import { sceneArchiveSegments, sceneMediaDurationMs } from "./continuationMedia";import {actionReferenceIds, createDraftGenerationJob, GENERATION_FRAME_RATE, parseProjectConfig,sceneBriefText, type AgentMessage, type GenerationJob, type ProjectAsset, type ProjectConfig,@@ -235,7 +236,11 @@ export async function cancelAgentTurn(requestId: string): Promise<boolean> {export async function resolveSlopfabPlan(request: SlopfabGenerationRequest, config: ProjectConfig, folderPath?: string): Promise<ResolvedPlan> {request = { ...request, steps: generationStepsWithLoras(request.steps, config) };if (isTauri()) return invoke<ResolvedPlan>("resolve_slopfab_plan", { request, config, folderPath });- const alignedFrames = request.continuationRelativePath ? Math.ceil(request.frames / 17) * 17+ const source = config.generationJobs.find((job) => job.latentRelativePath === request.continuationRelativePath);+ const tail = source && sceneArchiveSegments(config, source)?.at(-1);+ const prefix = request.continuationFrom === "start" ? request.continuationOverlapFrames ?? 22+ : tail ? tail.startFrame + tail.frameCount : request.continuationSourceFrames ?? 22;+ const alignedFrames = request.continuationRelativePath ? prefix + Math.ceil(request.frames / 17) * 17: Math.ceil(Math.max(5, request.frames - 5) / 17) * 17 + 5;return {canvasWidth: request.canvasWidth,@@ -311,7 +316,8 @@ function executeDemoCommands(config: ProjectConfig, commands: ProjectCommand[]):const validateSource = (clip: TimelineClip) => {const asset = next.assets.find((candidate) => candidate.id === clip.assetId);if (!asset) throw new Error(`Asset '${clip.assetId}' was not found.`);- if (asset.kind !== "image" && asset.durationMs && clip.sourceStartMs + clip.durationMs > asset.durationMs) {+ const durationMs = sceneMediaDurationMs(asset);+ if (asset.kind !== "image" && durationMs && clip.sourceStartMs + clip.durationMs > durationMs) {throw new Error(`Clip source range extends past asset '${asset.id}'.`);}};@@ -455,6 +461,7 @@ function executeDemoCommands(config: ProjectConfig, commands: ProjectCommand[]):const existing = next.assets.find((candidate) => candidate.id === plannedId)?? next.assets.find((candidate) => Boolean(job.outputRelativePath) && candidate.kind === "generated" && candidate.relativePath === job.outputRelativePath);defaultDurationMs = Math.max(Math.round(1000 / next.settings.frameRate), Math.round((job.durationSeconds ?? 6) * 1000));+ if (existing?.sceneSegments?.length) defaultDurationMs = sceneMediaDurationMs(existing)!;asset = existing ?? {id: plannedId,kind: "generated",@@ -474,7 +481,7 @@ function executeDemoCommands(config: ProjectConfig, commands: ProjectCommand[]):if (!existing) throw new Error(`Asset '${command.asset}' was not found.`);asset = existing;if (asset.kind === "caption") throw new Error(`Asset '${asset.id}' cannot be placed on an audiovisual track.`);- defaultDurationMs = Math.max(1, asset.durationMs ?? 5_000);+ defaultDurationMs = Math.max(1, sceneMediaDurationMs(asset) ?? 5_000);status = "approved";}const track = targetTrack(command.track);diff --git a/src/lib/workQueue.test.ts b/src/lib/workQueue.test.tsindex aa90752..1644133 100644--- a/src/lib/workQueue.test.ts+++ b/src/lib/workQueue.test.ts@@ -32,7 +32,9 @@ beforeEach(() => {vi.clearAllMocks();Object.assign(window, { __TAURI_INTERNALS__: {} });vi.mocked(listen).mockImplementation((async (name: string, handler: (event: { payload: unknown }) => void) => { handlers.set(name, handler); return () => { handlers.delete(name); }; }) as typeof listen);- vi.mocked(resolveSlopfabPlan).mockResolvedValue(plan as Awaited<ReturnType<typeof resolveSlopfabPlan>>);+ vi.mocked(resolveSlopfabPlan).mockImplementation(async (request) => ({ ...plan,+ alignedFrames: request.continuationRelativePath ? (request.continuationFrom === "start" ? request.continuationOverlapFrames ?? 22 : request.continuationSourceFrames ?? 120) + Math.ceil(request.frames / 17) * 17 : plan.alignedFrames,+ }) as Awaited<ReturnType<typeof resolveSlopfabPlan>>);vi.mocked(enqueueSlopfabGeneration).mockResolvedValue(undefined);vi.mocked(cancelSlopfabGeneration).mockResolvedValue(true);vi.mocked(saveGeneratedScene).mockResolvedValue({ relativePath: "media/generated/result.mp4", bytes: 100, hasAudio: true, note: null });@@ -432,6 +434,30 @@ describe("application work queue", () => {expect(enqueueSlopfabGeneration).not.toHaveBeenCalled();});+ it("saves the full End continuation and its exact scene ranges without replacing the original source", async () => {+ const { queue, first } = setup();+ first.update((config) => ({ ...config, generationJobs: [config.generationJobs[0], { ...config.generationJobs[0], id: "continued" }] }));+ const source = submission(first);+ vi.mocked(resolveSlopfabPlan).mockResolvedValueOnce({ ...plan, alignedFrames: 124 } as Awaited<ReturnType<typeof resolveSlopfabPlan>>);+ vi.mocked(saveGeneratedScene).mockResolvedValueOnce({ relativePath: "media/source.mp4", durationMs: 5167, bytes: 10, hasAudio: true, note: null })+ .mockResolvedValueOnce({ relativePath: "media/joined.mp4", durationMs: 10125, bytes: 20, hasAudio: true, note: null });+ queue.enqueue(first, [source, { ...source, job: first.getSnapshot().config.generationJobs[1], request: {+ ...source.request, frames: 119, previousSceneId: source.job.id, continuationFrom: "end", continuationOverlapFrames: 39,+ } }]);+ await waitFor(() => expect(enqueueSlopfabGeneration).toHaveBeenCalledTimes(1));+ await finish(queue, queue.getSnapshot()[0].id);+ await waitFor(() => expect(enqueueSlopfabGeneration).toHaveBeenCalledTimes(2));+ const sourceLatents = `latents/${queue.getSnapshot()[0].id}.safetensors`;+ expect(vi.mocked(enqueueSlopfabGeneration).mock.calls[1][0]).toMatchObject({ continuationRelativePath: sourceLatents, continuationFrom: "end", continuationOverlapFrames: 39 });+ await finish(queue, queue.getSnapshot()[1].id);+ const saved = parseProjectConfig(JSON.parse(JSON.stringify(first.getSnapshot().config)));+ expect(saved.assets[0]).toMatchObject({ relativePath: "media/source.mp4", durationMs: 5167 });+ expect(saved.assets[1]).toMatchObject({ relativePath: "media/joined.mp4", durationMs: 10125, hasAudio: true, sceneSegments: [+ { sceneId: source.job.id, latentRelativePath: sourceLatents, startFrame: 0, frameCount: 124 },+ { sceneId: "continued", startFrame: 124, frameCount: 119 },+ ] });+ });+it("fails a dependent scene if the previous generation fails, even when an older video exists", async () => {const { queue, first } = setup();first.update((config) => ({ ...config, generationJobs: [{ ...config.generationJobs[0], outputRelativePath: "media/generated/old.mp4" }, { ...config.generationJobs[0], id: "linked", usePreviousSceneLastFrame: true }] }));diff --git a/src/lib/workQueue.ts b/src/lib/workQueue.tsindex 08c9879..33910ca 100644--- a/src/lib/workQueue.ts+++ b/src/lib/workQueue.ts@@ -21,6 +21,8 @@ import { purgeTimelineThumbnails } from "./timelineThumbnails";import { ReferenceIconWork } from "./referenceIconWork";import { prepareReferenceVideos, releaseReferenceVideos } from "./referenceVideo";import { prepareReferenceAudios, releaseReferenceAudios } from "./referenceAudio";+import { joinedSceneSegments, sceneArchiveSegments } from "./continuationMedia";+import type { SceneMediaSegment } from "./project";export type WorkStatus = "queued" | "preparing" | "generating" | "encoding" | "completed" | "failed" | "cancelled";export interface GenerationSubmission { job: GenerationJob; request: SlopfabGenerationRequest; snapshot: string }@@ -53,6 +55,8 @@ export interface WorkItem {settings: { frames: number; steps: number; seed: number; canvasWidth: number; canvasHeight: number };}interface PendingWork {+ outputFrames?: number;+ continuationSegments?: SceneMediaSegment[];imageDraftId?: string;/** The family a regenerated image joins. */imageParentId?: string;@@ -284,6 +288,7 @@ export class WorkQueue {}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)!;work.snapshot = sceneGenerationSnapshot(captured, work.request);this.updateScene(work, { generationSnapshot: work.snapshot });@@ -301,6 +306,7 @@ export class WorkQueue {if (work.cancelled) continue;const plan = await resolveSlopfabPlan(work.request, work.config, next.folderPath);if (work.cancelled) continue;+ work.outputFrames = plan.alignedFrames;this.patch(work.id, { status: "generating", detail: `Generating ${work.image ? "image" : `${plan.alignedFrames} frames`} at ${plan.canvasWidth} × ${plan.canvasHeight}` });this.updateScene(work, { status: "generating", stage: "preparing" }, false);await enqueueSlopfabGeneration(work.request, work.config, next.folderPath);@@ -411,7 +417,14 @@ export class WorkQueue {},});const assetId = generationAssetId(work.sceneId);- const media = { kind: "generated" as const, relativePath: saved.relativePath, sourcePath: null, mimeType: "video/mp4", hasAudio: saved.hasAudio ?? null, width: saved.width ?? work.request.canvasWidth, height: saved.height ?? work.request.canvasHeight, durationMs: saved.durationMs ?? Math.round(work.request.frames / GENERATION_FRAME_RATE * 1000) };+ const totalFrames = saved.durationMs ? Math.round(saved.durationMs * GENERATION_FRAME_RATE / 1000) : work.outputFrames ?? work.request.frames;+ const sceneSegments = joinedSceneSegments(work.sceneId, generationLatentPath(work.id), totalFrames,+ Math.ceil(work.request.frames / 17) * 17, work.request.previousSceneId ? {+ sceneId: work.request.previousSceneId, latentRelativePath: work.request.continuationRelativePath!,+ frameCount: work.request.continuationSourceFrames ?? totalFrames - Math.ceil(work.request.frames / 17) * 17,+ segments: work.continuationSegments, from: work.request.continuationFrom,+ } : undefined);+ const media = { kind: "generated" as const, relativePath: saved.relativePath, sourcePath: null, mimeType: "video/mp4", hasAudio: saved.hasAudio ?? null, width: saved.width ?? work.request.canvasWidth, height: saved.height ?? work.request.canvasHeight, durationMs: saved.durationMs ?? Math.round(totalFrames / GENERATION_FRAME_RATE * 1000), sceneSegments };work.session.update((current) => ({...current,generationJobs: current.generationJobs.map((job) => job.id === work.sceneId ? { ...job, status: "completed", stage: "completed", progress: 1, generationSnapshot: work.snapshot, outputRelativePath: saved.relativePath, latentRelativePath: generationLatentPath(work.id), error: saved.note, updatedAt: new Date().toISOString() } : job),