The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.
Rust ffmpegfree-video-editormodel-context-protocolnon-linear-editoroffline-firstopen-source-video-editorself-hostedvideo-editingvideo-editing-automationvideo-editing-softwarevideo-editing-toolsvideo-editorvoice-cloningyoutube-automationyoutube-shorts
fix(mcp): export_wait's progress follows the stages the exporter names (#337)
chiarorosa1a2c71ffe0b1
diff --git a/src/crates/concat-mcp/src/tools.rs b/src/crates/concat-mcp/src/tools.rsindex 97f68d6f..436bc779 100644--- a/src/crates/concat-mcp/src/tools.rs+++ b/src/crates/concat-mcp/src/tools.rs@@ -32,8 +32,23 @@ const POLL: Duration = Duration::from_millis(250);/// How long `export_wait` waits when told nothing, and at most.const WAIT_DEFAULT: f64 = 60.0;const WAIT_LONGEST: f64 = 600.0;-/// The stages of an export in order, for one progress figure across them.-const STAGES: [&str; 5] = ["cutout", "stabilize", "video", "audio", "mux"];+/// How many stages an export has, for one progress figure across them.+const STAGES: usize = 5;++/// Where a stage comes in an export, from 0. A job's status names the+/// stage the exporter reports - "rendering", "mixing audio", "muxing" -+/// and the API's documentation names them "video", "audio" and "mux"; both+/// are known here, and one this does not know counts as the first.+fn stage_place(stage: &str) -> usize {+ match stage {+ "cutout" => 0,+ "stabilize" => 1,+ "video" | "rendering" => 2,+ "audio" | "mixing audio" => 3,+ "mux" | "muxing" => 4,+ _ => 0,+ }+}/// What a tool does with its arguments.#[derive(Clone, Copy, Debug)]@@ -420,7 +435,7 @@ pub fn catalogue() -> Vec<Tool> {method("export_status","Export status",- "How an export job stands, at once: `state` (\"running\", \"done\", \"cancelled\" or \"failed\"), `stage` (\"cutout\", \"stabilize\", \"video\", \"audio\", \"mux\"), frames done of total, `fraction` of the stage (0-1), and once done the file and its size, or the error.",+ "How an export job stands, at once: `state` (\"running\", \"done\", \"cancelled\" or \"failed\"), `stage` (\"cutout\", \"stabilize\", \"rendering\", \"mixing audio\" or \"muxing\"), frames done of total, `fraction` of the stage (0-1), and once done the file and its size, or the error.","export.status",Raw,)@@ -810,10 +825,10 @@ fn export_wait(let running = current["state"] == "running";if let Some(progress) = progress {let stage = current["stage"].as_str().unwrap_or_default();- let place = STAGES.iter().position(|known| *known == stage).unwrap_or(0) as f64;+ let place = stage_place(stage) as f64;let fraction = current["fraction"].as_f64().unwrap_or(0.0).clamp(0.0, 1.0);let overall = if running {- ((place + fraction) / STAGES.len() as f64 * 100.0).min(99.9)+ ((place + fraction) / STAGES as f64 * 100.0).min(99.9)} else {100.0};@@ -988,6 +1003,61 @@ mod tests {}}+ /// A backend whose export reports the statuses it is given, in order,+ /// the last for ever.+ struct Statuses(std::collections::VecDeque<Value>);++ impl Backend for Statuses {+ fn call(&mut self, _request: Request) -> Result<Value, ApiError> {+ let status = if self.0.len() > 1 {+ self.0.pop_front()+ } else {+ self.0.front().cloned()+ };+ Ok(status.expect("a status"))+ }++ fn describe(&self) -> Value {+ json!({ "mode": "test" })+ }+ }++ /// An export that mixes sound and muxes it reports the stages the+ /// exporter names - "rendering", "mixing audio", "muxing" - and the+ /// wait's progress climbs through them to the end.+ #[test]+ fn export_wait_progress_follows_the_stages_the_exporter_reports() {+ let running = |stage: &str, frame: i64, total: i64| {+ json!({ "state": "running", "stage": stage, "frame": frame, "total": total,+ "fraction": if total > 0 { frame as f64 / total as f64 } else { 0.0 } })+ };+ let mut backend = Statuses(+ [+ running("rendering", 50, 100),+ running("mixing audio", 0, 100),+ running("muxing", 100, 100),+ json!({ "state": "done", "stage": "muxing", "frame": 100, "total": 100, "fraction": 1.0 }),+ ]+ .into(),+ );+ let seen = std::cell::RefCell::new(Vec::new());+ let report =+ |progress: f64, total: f64, _: String| seen.borrow_mut().push((progress, total));+ let cancelled = AtomicBool::new(false);+ let outcome = export_wait(+ json!({ "job": "j1" }),+ &mut backend,+ &cancelled,+ Some(&report),+ )+ .expect("waits");+ assert!(!outcome.is_error);+ assert_eq!(+ *seen.borrow(),+ vec![(50.0, 100.0), (60.0, 100.0), (99.9, 100.0), (100.0, 100.0)]+ );+ }+#[test]fn a_wrong_argument_is_refused_by_the_schema_and_by_the_type_alike() {let toolbox = Toolbox::new();