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
refactor(ipc): route every command through lib/engine.ts and test the boundary
Jareer4fe2b4ad4d15
diff --git a/desktop/package-lock.json b/desktop/package-lock.jsonindex 36c2f935..cdc652df 100644--- a/desktop/package-lock.json+++ b/desktop/package-lock.json@@ -7,6 +7,7 @@"": {"name": "wolfcut-desktop","version": "0.1.0",+ "license": "MPL-2.0","dependencies": {"@tauri-apps/api": "^2","@tauri-apps/plugin-dialog": "^2.7.2",@@ -17,12 +18,14 @@"devDependencies": {"@tailwindcss/vite": "^4","@tauri-apps/cli": "^2",+ "@types/node": "^26.4.0","@types/react": "^19.1.8","@types/react-dom": "^19.1.6","@vitejs/plugin-react": "^4.6.0","tailwindcss": "^4","typescript": "~5.8.3",- "vite": "^7.0.4"+ "vite": "^7.0.4",+ "vitest": "^4.1.11"}},"node_modules/@babel/code-frame": {@@ -1173,6 +1176,13 @@"win32"]},+ "node_modules/@standard-schema/spec": {+ "version": "1.1.0",+ "resolved": "https://registry.npmjs.org/@standard-schema/spec/-/spec-1.1.0.tgz",+ "integrity": "sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w==",+ "dev": true,+ "license": "MIT"+ },"node_modules/@tailwindcss/node": {"version": "4.3.3","resolved": "https://registry.npmjs.org/@tailwindcss/node/-/node-4.3.3.tgz",@@ -1735,6 +1745,24 @@"@babel/types": "^7.28.2"}},+ "node_modules/@types/chai": {+ "version": "5.2.3",+ "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz",+ "integrity": "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@types/deep-eql": "*",+ "assertion-error": "^2.0.1"+ }+ },+ "node_modules/@types/deep-eql": {+ "version": "4.0.2",+ "resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz",+ "integrity": "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==",+ "dev": true,+ "license": "MIT"+ },"node_modules/@types/estree": {"version": "1.0.9","resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.9.tgz",@@ -1742,6 +1770,16 @@"dev": true,"license": "MIT"},+ "node_modules/@types/node": {+ "version": "26.4.0",+ "resolved": "https://registry.npmjs.org/@types/node/-/node-26.4.0.tgz",+ "integrity": "sha512-faiGnoIrLH/V8cibOMEAZ8pMw6oXqSukl29ra4mN8GdaB2ZewzeaLj+INpV5N+Z1eKWzY+IzaIZH2EIR6YZRNQ==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "undici-types": "~8.3.0"+ }+ },"node_modules/@types/react": {"version": "19.2.18","resolved": "https://registry.npmjs.org/@types/react/-/react-19.2.18.tgz",@@ -1783,6 +1821,129 @@"vite": "^4.2.0 || ^5.0.0 || ^6.0.0 || ^7.0.0"}},+ "node_modules/@vitest/expect": {+ "version": "4.1.11",+ "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-4.1.11.tgz",+ "integrity": "sha512-VX2x5vNJXET47KAFzwERI+KRMtTTCSWTfSMKsW7JsUsXV4psq++e3DvZpuTDOpHcxytiDs6p2nhVb2tVDiiUYw==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@standard-schema/spec": "^1.1.0",+ "@types/chai": "^5.2.2",+ "@vitest/spy": "4.1.11",+ "@vitest/utils": "4.1.11",+ "chai": "^6.2.2",+ "tinyrainbow": "^3.1.0"+ },+ "funding": {+ "url": "https://opencollective.com/vitest"+ }+ },+ "node_modules/@vitest/mocker": {+ "version": "4.1.11",+ "resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-4.1.11.tgz",+ "integrity": "sha512-2XJVD55d1o5AZous5CCGKS74g/riOj9odEt2bQpCVZeblHyHdnMeFl4jl0XjU21stf4mbjUkew2eXQZt65g5CQ==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@vitest/spy": "4.1.11",+ "estree-walker": "^3.0.3",+ "magic-string": "^0.30.21"+ },+ "funding": {+ "url": "https://opencollective.com/vitest"+ },+ "peerDependencies": {+ "msw": "^2.4.9",+ "vite": "^6.0.0 || ^7.0.0 || ^8.0.0"+ },+ "peerDependenciesMeta": {+ "msw": {+ "optional": true+ },+ "vite": {+ "optional": true+ }+ }+ },+ "node_modules/@vitest/pretty-format": {+ "version": "4.1.11",+ "resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-4.1.11.tgz",+ "integrity": "sha512-yiZzPbGTS9Sr/JpFl8zHrcIkAofNbFV6k21vIgQN/cY/oxZeXhJv5sc/MBJ5jFKWmWs+oJHw0UXLZjmf931+Vw==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "tinyrainbow": "^3.1.0"+ },+ "funding": {+ "url": "https://opencollective.com/vitest"+ }+ },+ "node_modules/@vitest/runner": {+ "version": "4.1.11",+ "resolved": "https://registry.npmjs.org/@vitest/runner/-/runner-4.1.11.tgz",+ "integrity": "sha512-LztvUgdwMNJMIkj3hQnnxiC2Xy1zNxq928W/xhjCLaNCzqTZOudjwbQf6v9IntZGPw132i2Lq2rgTRZHD3JHNw==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@vitest/utils": "4.1.11",+ "pathe": "^2.0.3"+ },+ "funding": {+ "url": "https://opencollective.com/vitest"+ }+ },+ "node_modules/@vitest/snapshot": {+ "version": "4.1.11",+ "resolved": "https://registry.npmjs.org/@vitest/snapshot/-/snapshot-4.1.11.tgz",+ "integrity": "sha512-pN7ikn1ON7h8ee4gIAp4AzyK+zBtJPzVbqOgu5LCEh4VaJVbPQcgYQYJIMGQPXVeJJq1fnfazis7a5pFNPahog==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@vitest/pretty-format": "4.1.11",+ "@vitest/utils": "4.1.11",+ "magic-string": "^0.30.21",+ "pathe": "^2.0.3"+ },+ "funding": {+ "url": "https://opencollective.com/vitest"+ }+ },+ "node_modules/@vitest/spy": {+ "version": "4.1.11",+ "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-4.1.11.tgz",+ "integrity": "sha512-apNa/prQy2qCeywhnixOHPRCgGNhvg7T4Dapfl1GahLp/R+uhBm5cPyFoNVyqsNd2h1nJxL6BqqdIjiABL60YA==",+ "dev": true,+ "license": "MIT",+ "funding": {+ "url": "https://opencollective.com/vitest"+ }+ },+ "node_modules/@vitest/utils": {+ "version": "4.1.11",+ "resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-4.1.11.tgz",+ "integrity": "sha512-zTCVGpyFsGWBhllOyKlTw/vnr6D9qxsfSDyfbyZmTyjHw5N/VuvzHpHoQjm2ZJzn4RJgx5w4r7V0er69CmLgPQ==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@vitest/pretty-format": "4.1.11",+ "convert-source-map": "^2.0.0",+ "tinyrainbow": "^3.1.0"+ },+ "funding": {+ "url": "https://opencollective.com/vitest"+ }+ },+ "node_modules/assertion-error": {+ "version": "2.0.1",+ "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz",+ "integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=12"+ }+ },"node_modules/baseline-browser-mapping": {"version": "2.11.19","resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.11.19.tgz",@@ -1851,6 +2012,16 @@],"license": "CC-BY-4.0"},+ "node_modules/chai": {+ "version": "6.2.2",+ "resolved": "https://registry.npmjs.org/chai/-/chai-6.2.2.tgz",+ "integrity": "sha512-NUPRluOfOiTKBKvWPtSD4PhFvWCqOi0BGStNWs57X9js7XGTprSmFoz5F0tWhR4WPjNeR9jXqdC7/UpSJTnlRg==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=18"+ }+ },"node_modules/convert-source-map": {"version": "2.0.0","resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz",@@ -1914,6 +2085,13 @@"node": ">=10.13.0"}},+ "node_modules/es-module-lexer": {+ "version": "2.3.2",+ "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-2.3.2.tgz",+ "integrity": "sha512-poHGpORABojJJucnV9KbOavETW8lBVnphkW77ER5/BQ5Fz7oXSoCNek7IH3vR5nRjdsEz926ibFYX8KtLQmdyw==",+ "dev": true,+ "license": "MIT"+ },"node_modules/esbuild": {"version": "0.28.2","resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.2.tgz",@@ -1966,6 +2144,26 @@"node": ">=6"}},+ "node_modules/estree-walker": {+ "version": "3.0.3",+ "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz",+ "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@types/estree": "^1.0.0"+ }+ },+ "node_modules/expect-type": {+ "version": "1.4.0",+ "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.4.0.tgz",+ "integrity": "sha512-KfYbmpRm0VbLjEvVa9yGwCi9GI34xvi7A/HXYWQO65CSD2u3MczUJSuwXKFIxlGsgBQizV9q5J9NHj4VG0n+pA==",+ "dev": true,+ "license": "Apache-2.0",+ "engines": {+ "node": ">=12.0.0"+ }+ },"node_modules/fdir": {"version": "6.5.0","resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz",@@ -2376,6 +2574,27 @@"node": ">=18"}},+ "node_modules/obug": {+ "version": "2.1.4",+ "resolved": "https://registry.npmjs.org/obug/-/obug-2.1.4.tgz",+ "integrity": "sha512-4a+OsYv9UktOJKE+l1A4OufDgdRF9PifWj+tJnHURo/P+WOxpG4GzUFL9qCalmWauao6ogiG+QvnCovwPoyAWA==",+ "dev": true,+ "funding": [+ "https://github.com/sponsors/sxzz",+ "https://opencollective.com/debug"+ ],+ "license": "MIT",+ "engines": {+ "node": ">=12.20.0"+ }+ },+ "node_modules/pathe": {+ "version": "2.0.3",+ "resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz",+ "integrity": "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==",+ "dev": true,+ "license": "MIT"+ },"node_modules/picocolors": {"version": "1.1.1","resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",@@ -2518,6 +2737,13 @@"semver": "bin/semver.js"}},+ "node_modules/siginfo": {+ "version": "2.0.0",+ "resolved": "https://registry.npmjs.org/siginfo/-/siginfo-2.0.0.tgz",+ "integrity": "sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==",+ "dev": true,+ "license": "ISC"+ },"node_modules/source-map-js": {"version": "1.2.1","resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz",@@ -2528,6 +2754,20 @@"node": ">=0.10.0"}},+ "node_modules/stackback": {+ "version": "0.0.2",+ "resolved": "https://registry.npmjs.org/stackback/-/stackback-0.0.2.tgz",+ "integrity": "sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==",+ "dev": true,+ "license": "MIT"+ },+ "node_modules/std-env": {+ "version": "4.2.0",+ "resolved": "https://registry.npmjs.org/std-env/-/std-env-4.2.0.tgz",+ "integrity": "sha512-oCUKSupKTHX53EyjDtuZQ64pjLJ6yYCtpmEw0goYxtjG9KpbRe8KAsl2tBUGU9DyMcJ0RwJ8GqJAFzMXcXW1Rw==",+ "dev": true,+ "license": "MIT"+ },"node_modules/tailwindcss": {"version": "4.3.3","resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-4.3.3.tgz",@@ -2549,6 +2789,23 @@"url": "https://opencollective.com/webpack"}},+ "node_modules/tinybench": {+ "version": "2.9.0",+ "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.9.0.tgz",+ "integrity": "sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg==",+ "dev": true,+ "license": "MIT"+ },+ "node_modules/tinyexec": {+ "version": "1.3.0",+ "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-1.3.0.tgz",+ "integrity": "sha512-QKAl9m8gWWGHV8jZcPeym6j+XULi6tOf1mT83WYJ4Lk2ytW/uwAWkrP0uFsdoYMdueVJ0qs26wZ+23xeB4ibNQ==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=18"+ }+ },"node_modules/tinyglobby": {"version": "0.2.17","resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.17.tgz",@@ -2566,6 +2823,16 @@"url": "https://github.com/sponsors/SuperchupuDev"}},+ "node_modules/tinyrainbow": {+ "version": "3.1.1",+ "resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-3.1.1.tgz",+ "integrity": "sha512-yau8yJdTt989Mm0Bd/236QnzEiPf2xLLTqUZRUJOo/3CB078LSwzei343DgtJVmfJKJE3TMINY1u42SQsP6mXw==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=14.0.0"+ }+ },"node_modules/typescript": {"version": "5.8.3","resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.3.tgz",@@ -2580,6 +2847,13 @@"node": ">=14.17"}},+ "node_modules/undici-types": {+ "version": "8.3.0",+ "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-8.3.0.tgz",+ "integrity": "sha512-j375ScV60dom+YkPFIfTLcOiPxkN/buHz5GobjLhixFuANaNs3C9l4GmrWqejgXWJ7BbJcFYpTEUkS1Ge8bpZQ==",+ "dev": true,+ "license": "MIT"+ },"node_modules/update-browserslist-db": {"version": "1.3.1","resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.3.1.tgz",@@ -2686,6 +2960,113 @@}}},+ "node_modules/vitest": {+ "version": "4.1.11",+ "resolved": "https://registry.npmjs.org/vitest/-/vitest-4.1.11.tgz",+ "integrity": "sha512-fhACrNXUidIbGSBr5FlbuBkO7VWC1ZyLl0DO4CU2DrQoAPxX84Ysxs+HeGQpii5lZWV1Q4gBZTTu49mF+A6Edw==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@vitest/expect": "4.1.11",+ "@vitest/mocker": "4.1.11",+ "@vitest/pretty-format": "4.1.11",+ "@vitest/runner": "4.1.11",+ "@vitest/snapshot": "4.1.11",+ "@vitest/spy": "4.1.11",+ "@vitest/utils": "4.1.11",+ "es-module-lexer": "^2.0.0",+ "expect-type": "^1.3.0",+ "magic-string": "^0.30.21",+ "obug": "^2.1.1",+ "pathe": "^2.0.3",+ "picomatch": "^4.0.3",+ "std-env": "^4.0.0-rc.1",+ "tinybench": "^2.9.0",+ "tinyexec": "^1.0.2",+ "tinyglobby": "^0.2.15",+ "tinyrainbow": "^3.1.0",+ "vite": "^6.0.0 || ^7.0.0 || ^8.0.0",+ "why-is-node-running": "^2.3.0"+ },+ "bin": {+ "vitest": "vitest.mjs"+ },+ "engines": {+ "node": "^20.0.0 || ^22.0.0 || >=24.0.0"+ },+ "funding": {+ "url": "https://opencollective.com/vitest"+ },+ "peerDependencies": {+ "@edge-runtime/vm": "*",+ "@opentelemetry/api": "^1.9.0",+ "@types/node": "^20.0.0 || ^22.0.0 || >=24.0.0",+ "@vitest/browser-playwright": "4.1.11",+ "@vitest/browser-preview": "4.1.11",+ "@vitest/browser-webdriverio": "4.1.11",+ "@vitest/coverage-istanbul": "4.1.11",+ "@vitest/coverage-v8": "4.1.11",+ "@vitest/ui": "4.1.11",+ "happy-dom": "*",+ "jsdom": "*",+ "vite": "^6.0.0 || ^7.0.0 || ^8.0.0"+ },+ "peerDependenciesMeta": {+ "@edge-runtime/vm": {+ "optional": true+ },+ "@opentelemetry/api": {+ "optional": true+ },+ "@types/node": {+ "optional": true+ },+ "@vitest/browser-playwright": {+ "optional": true+ },+ "@vitest/browser-preview": {+ "optional": true+ },+ "@vitest/browser-webdriverio": {+ "optional": true+ },+ "@vitest/coverage-istanbul": {+ "optional": true+ },+ "@vitest/coverage-v8": {+ "optional": true+ },+ "@vitest/ui": {+ "optional": true+ },+ "happy-dom": {+ "optional": true+ },+ "jsdom": {+ "optional": true+ },+ "vite": {+ "optional": false+ }+ }+ },+ "node_modules/why-is-node-running": {+ "version": "2.3.0",+ "resolved": "https://registry.npmjs.org/why-is-node-running/-/why-is-node-running-2.3.0.tgz",+ "integrity": "sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "siginfo": "^2.0.0",+ "stackback": "0.0.2"+ },+ "bin": {+ "why-is-node-running": "cli.js"+ },+ "engines": {+ "node": ">=8"+ }+ },"node_modules/yallist": {"version": "3.1.1","resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",diff --git a/desktop/package.json b/desktop/package.jsonindex 6c404ae4..b7ee8d5f 100644--- a/desktop/package.json+++ b/desktop/package.json@@ -10,7 +10,8 @@"tauri": "tauri","app": "tauri dev","app:build": "tauri build",- "typecheck": "tsc --noEmit"+ "typecheck": "tsc --noEmit",+ "test": "vitest run"},"dependencies": {"@tauri-apps/api": "^2",@@ -22,12 +23,14 @@"devDependencies": {"@tailwindcss/vite": "^4","@tauri-apps/cli": "^2",+ "@types/node": "^26.4.0","@types/react": "^19.1.8","@types/react-dom": "^19.1.6","@vitejs/plugin-react": "^4.6.0","tailwindcss": "^4","typescript": "~5.8.3",- "vite": "^7.0.4"+ "vite": "^7.0.4",+ "vitest": "^4.1.11"},"license": "MPL-2.0"}diff --git a/desktop/src-tauri/src/lib.rs b/desktop/src-tauri/src/lib.rsindex 9cab8651..00afb6ca 100644--- a/desktop/src-tauri/src/lib.rs+++ b/desktop/src-tauri/src/lib.rs@@ -131,10 +131,10 @@ fn engine_version() -> &'static str {/// Reads a whole file and returns it as raw bytes.///-/// This exists only as the audio preview's fallback for when the asset-/// protocol is unavailable. `tauri::ipc::Response` puts the bytes on the wire-/// as an ArrayBuffer rather than a JSON array of numbers, which for a few-/// megabytes of audio is the difference between instant and unusable.+/// Two callers: the waveform peak decode in `lib/assets.ts`, and custom font+/// registration. `tauri::ipc::Response` puts the bytes on the wire as an+/// ArrayBuffer rather than a JSON array of numbers, which for a few+/// megabytes is the difference between instant and unusable.////// It loads the entire file into memory, so it is not a general-purpose/// reader and must not become one.@@ -411,22 +411,6 @@ async fn open_project(app: tauri::AppHandle, path: String) -> Result<projects::P.map_err(|error| format!("open_project task failed: {error}"))?}-/// Writes the project to disk.-#[tauri::command]-async fn save_project(path: String, document: serde_json::Value) -> Result<(), String> {- tauri::async_runtime::spawn_blocking(move || projects::save(&path, &document))- .await- .map_err(|error| format!("save task failed: {error}"))?-}--/// Reads the whole project document back.-#[tauri::command]-async fn load_project(path: String) -> Result<serde_json::Value, String> {- tauri::async_runtime::spawn_blocking(move || projects::read_document(&path))- .await- .map_err(|error| format!("load task failed: {error}"))?-}-/// The recents list, most recent first, with vanished folders left out.#[tauri::command]fn recent_projects(app: tauri::AppHandle) -> Result<Vec<projects::ProjectInfo>, String> {@@ -654,8 +638,6 @@ pub fn run() {create_project,open_project,project_preview,- save_project,- load_project,recent_projects,forget_project,export_project,diff --git a/desktop/src/lib/assets.ts b/desktop/src/lib/assets.tsindex 22380db6..be43e163 100644--- a/desktop/src/lib/assets.ts+++ b/desktop/src/lib/assets.ts@@ -11,9 +11,13 @@* the timeline down with it.*/-import { invoke } from "@tauri-apps/api/core";-import { readMediaBytes } from "./engine";+import {+ extractFilmstrip,+ readArtwork as readArtworkFile,+ readMediaBytes,+ writeArtwork as writeArtworkFile,+} from "./engine";/** Min/max sample pairs, bucketed at a fixed rate. */export interface Peaks {@@ -196,7 +200,7 @@ function artworkKey(path: string): string {async function readArtwork(project: string | null, key: string): Promise<ArrayBuffer | null> {if (!project) return null;try {- return await invoke<ArrayBuffer>("read_artwork", { project, key });+ return await readArtworkFile(project, key);} catch {return null;}@@ -207,10 +211,7 @@ function writeArtwork(project: string | null, key: string, bytes: Uint8Array): v// Serialising the payload for IPC is main-thread work, and nothing about a// cache write is urgent - it waits for an idle moment so it never competes// with playback.- const send = () =>- void invoke("write_artwork", { project, key, bytes: Array.from(bytes) }).catch(- () => undefined,- );+ const send = () => void writeArtworkFile(project, key, bytes).catch(() => undefined);if (typeof window.requestIdleCallback === "function") window.requestIdleCallback(() => send());else window.setTimeout(send, 500);}@@ -321,11 +322,7 @@ async function loadStrip(}try {- const bytes = await invoke<ArrayBuffer>("extract_filmstrip", {- path,- count: STRIP_FRAMES,- height: STRIP_HEIGHT,- });+ const bytes = await extractFilmstrip(path, STRIP_FRAMES, STRIP_HEIGHT);writeArtwork(project, key, new Uint8Array(bytes));// createImageBitmap decodes off the main thread, so a slow JPEG does not// stall the timeline.diff --git a/desktop/src/lib/editor.test.ts b/desktop/src/lib/editor.test.tsnew file mode 100644index 00000000..9c719dfe--- /dev/null+++ b/desktop/src/lib/editor.test.ts@@ -0,0 +1,179 @@+/**+ * The gesture echo's arithmetic against the engine's.+ *+ * `lib/editor.ts` deliberately duplicates a handful of the engine's rules so+ * a drag can preview locally before its one command commits. That mirror is+ * the architecture's soft spot: if the two drift, the preview lies and the+ * commit "jumps". Every expectation here is copied from the corresponding+ * test or clamp in `engine/crates/relay-project/src/commands.rs` - when one+ * of these fails, read the engine first and fix whichever side moved.+ */+import { describe, expect, test } from "vitest";++import {+ snapTime,+ speedPatch,+ transformPatch,+ trimPatch,+ whyNotMerge,+ type Clip,+ type EditorProject,+} from "./editor";++function clip(overrides: Partial<Clip> = {}): Clip {+ return {+ id: "c1",+ trackId: "T1",+ mediaId: "m1",+ name: "a.mp4",+ kind: "video",+ start: 0,+ duration: 10,+ sourceStart: 0,+ volume: 1,+ fadeIn: 0,+ fadeOut: 0,+ scale: 1,+ offsetX: 0,+ offsetY: 0,+ rotation: 0,+ opacity: 1,+ speed: 1,+ preservePitch: true,+ filters: [],+ videoEffects: [],+ ...overrides,+ };+}++function project(clips: Clip[]): EditorProject {+ return {+ media: [],+ fonts: [],+ timelines: [+ {+ id: "TL1",+ name: "Timeline 1",+ tracks: [{ id: "T1", name: "Track 1", visible: true, muted: false }],+ clips,+ },+ ],+ activeTimelineId: "TL1",+ };+}++const MIN_CLIP_DURATION = 1 / 60;++describe("trimPatch mirrors TrimClip", () => {+ test("an end trim grows and shrinks with the duration floor", () => {+ expect(trimPatch(clip(), "end", 2)).toEqual({ duration: 12 });+ expect(trimPatch(clip(), "end", -20)).toEqual({ duration: MIN_CLIP_DURATION });+ });++ test("a head trim moves the in-point with speed", () => {+ // The engine's a_head_trim_moves_the_in_point_with_speed: 10s of source+ // at 2x occupies 5s; trimming 1s off the head covers 2 source seconds.+ const fast = clip({ duration: 5, speed: 2 });+ expect(trimPatch(fast, "start", 1)).toEqual({+ start: 1,+ duration: 4,+ sourceStart: 2,+ });+ });++ test("a head trim clamps at the timeline's start", () => {+ const placed = clip({ start: 1 });+ // Dragging 3s left only travels the 1s that exists before zero.+ expect(trimPatch(placed, "start", -3)).toEqual({+ start: 0,+ duration: 11,+ sourceStart: 0,+ });+ });++ test("a head trim cannot consume the whole clip", () => {+ const patch = trimPatch(clip(), "start", 99);+ expect(patch.duration).toBeCloseTo(MIN_CLIP_DURATION, 10);+ expect(patch.start).toBeCloseTo(10 - MIN_CLIP_DURATION, 10);+ });+});++describe("speedPatch mirrors SetClipSpeed", () => {+ test("the source covered is held constant", () => {+ // 10 timeline seconds at 1x cover 10 source seconds; at 2x they fit in 5.+ expect(speedPatch(clip(), 2)).toEqual({ speed: 2, duration: 5 });+ expect(speedPatch(clip({ duration: 5, speed: 2 }), 0.5)).toEqual({+ speed: 0.5,+ duration: 20,+ });+ });++ test("speed clamps to the engine range", () => {+ expect(speedPatch(clip(), 100).speed).toBe(16);+ expect(speedPatch(clip(), 0).speed).toBe(0.0625);+ });+});++describe("transformPatch mirrors SetClipTransform", () => {+ test("scale and offsets clamp to the engine bounds", () => {+ expect(transformPatch({ scale: 100 })).toEqual({ scale: 8 });+ expect(transformPatch({ scale: 0 })).toEqual({ scale: 0.05 });+ expect(transformPatch({ offsetX: 5, offsetY: -5 })).toEqual({ offsetX: 3, offsetY: -3 });+ });++ test("rotation wraps into (-180, 180], never accumulating turns", () => {+ expect(transformPatch({ rotation: 190 })).toEqual({ rotation: -170 });+ expect(transformPatch({ rotation: -190 })).toEqual({ rotation: 170 });+ expect(transformPatch({ rotation: 540 })).toEqual({ rotation: 180 });+ // The engine maps the -180 boundary to 180; the echo must agree.+ expect(transformPatch({ rotation: -180 })).toEqual({ rotation: 180 });+ });+});++describe("whyNotMerge phrases the engine's refusals", () => {+ // The strings are the contract: the engine re-validates on the command and+ // its error becomes the toast, so the tooltip and the toast must match.+ const halves = [+ clip({ id: "a", duration: 4 }),+ clip({ id: "b", start: 4, duration: 6, sourceStart: 4 }),+ ];++ test("source-continuous neighbours merge", () => {+ expect(whyNotMerge(project(halves), ["a", "b"])).toBeNull();+ });++ test("each refusal uses the engine's own sentence", () => {+ expect(whyNotMerge(project(halves), ["a"])).toBe("Select two or more clips to merge.");+ expect(+ whyNotMerge(project([halves[0], { ...halves[1], trackId: "T2" }]), ["a", "b"]),+ ).toBe("Merged clips must be on the same track.");+ expect(+ whyNotMerge(project([halves[0], { ...halves[1], mediaId: "m2" }]), ["a", "b"]),+ ).toBe("Merged clips must come from the same file.");+ expect(+ whyNotMerge(project([halves[0], { ...halves[1], speed: 2 }]), ["a", "b"]),+ ).toBe("Merged clips must play at the same speed.");+ expect(+ whyNotMerge(project([halves[0], { ...halves[1], start: 5 }]), ["a", "b"]),+ ).toBe("Merged clips must touch, with no gap or overlap.");+ expect(+ whyNotMerge(project([halves[0], { ...halves[1], sourceStart: 0 }]), ["a", "b"]),+ ).toBe("These pieces are no longer in their original order.");+ });+});++describe("snapTime", () => {+ test("snaps to clip edges and the playhead within the threshold", () => {+ const timeline = project([clip({ start: 2, duration: 3 })]);+ const options = { threshold: 0.25, playhead: 9 };+ expect(snapTime(timeline, 2.1, options)).toBe(2);+ expect(snapTime(timeline, 4.9, options)).toBe(5);+ expect(snapTime(timeline, 8.8, options)).toBe(9);+ expect(snapTime(timeline, 3.5, options)).toBe(3.5);+ });++ test("a clip does not snap to itself", () => {+ const timeline = project([clip({ id: "me", start: 2, duration: 3 })]);+ expect(snapTime(timeline, 2.1, { threshold: 0.25, playhead: 99, exclude: "me" })).toBe(2.1);+ });+});diff --git a/desktop/src/lib/engine.ts b/desktop/src/lib/engine.tsindex dfb5886d..763523ca 100644--- a/desktop/src/lib/engine.ts+++ b/desktop/src/lib/engine.ts@@ -71,8 +71,8 @@ export async function engineVersion(): Promise<string> {/*** Reads a whole file into memory as bytes.*- * Only used as the audio fallback when the asset protocol is unavailable - see- * `lib/audio.ts`. It loads the entire file, so do not reach for it as a+ * Two callers: the waveform peak decode in `lib/assets.ts`, and custom font+ * registration. It loads the entire file, so do not reach for it as a* general-purpose reader.*/export async function readMediaBytes(path: string): Promise<ArrayBuffer> {@@ -114,6 +114,76 @@ export async function openProject(path: string): Promise<ProjectInfo> {return invoke<ProjectInfo>("open_project", { path });}+// ── playback, transport and artwork ────────────────────────────────────────++/** One audible clip, as `playback.rs` mixes it. */+export interface AudioClipSpec {+ path: string;+ /** Timeline seconds. */+ start: number;+ duration: number;+ /** Seconds into the source file. */+ sourceStart: number;+ volume: number;+ fadeIn: number;+ fadeOut: number;+ speed: number;+ preservePitch: boolean;+ /** FFmpeg audio filter chain, or empty. */+ chain: string;+}++/** Replaces the engine mixer's audible clip set wholesale. */+export async function audioSetClips(project: string, clips: AudioClipSpec[]): Promise<void> {+ return invoke<void>("audio_set_clips", { project, clips });+}++export async function transportPlay(position: number): Promise<void> {+ return invoke<void>("transport_play", { position });+}++export async function transportPause(): Promise<void> {+ return invoke<void>("transport_pause");+}++export async function transportSeek(position: number): Promise<void> {+ return invoke<void>("transport_seek", { position });+}++/**+ * Subscribes to playback failures the engine would otherwise swallow - a+ * missing output device, a clip whose audio would not decode. Resolves to an+ * unsubscribe function.+ */+export async function onAudioError(handler: (message: string) => void): Promise<UnlistenFn> {+ return listen<string>("audio://error", (event) => handler(event.payload));+}++/** One cached artwork file from the project's cache, or a throw the caller+ * treats as a miss. */+export async function readArtwork(project: string, key: string): Promise<ArrayBuffer> {+ return invoke<ArrayBuffer>("read_artwork", { project, key });+}++/** Stores one artwork file in the project's cache. Fire-and-forget shaped:+ * a failed write only means regenerating next launch. */+export async function writeArtwork(+ project: string,+ key: string,+ bytes: Uint8Array,+): Promise<void> {+ return invoke<void>("write_artwork", { project, key, bytes: Array.from(bytes) });+}++/** A strip of evenly spaced frames as one JPEG, for timeline filmstrips. */+export async function extractFilmstrip(+ path: string,+ count: number,+ height: number,+): Promise<ArrayBuffer> {+ return invoke<ArrayBuffer>("extract_filmstrip", { path, count, height });+}+// ── the editing session ────────────────────────────────────────────────────// The engine owns the edit (see engine decision 0007): the UI opens a// session, sends commands, and renders the state that comes back.diff --git a/desktop/src/lib/ipc-registry.test.ts b/desktop/src/lib/ipc-registry.test.tsnew file mode 100644index 00000000..87c45a6e--- /dev/null+++ b/desktop/src/lib/ipc-registry.test.ts@@ -0,0 +1,75 @@+/**+ * The IPC boundary's two halves against each other.+ *+ * The boundary is JSON, so nothing at compile time checks that a wrapper in+ * `lib/engine.ts` names a command the host actually registered, or that every+ * registered command has a wrapper. This test closes the gap the desktop+ * README used to flag ("nothing checks steps 1 and 3 against each other"),+ * and enforces the standing rule that `lib/engine.ts` is the only file that+ * calls `invoke` at all.+ */+import { readFileSync, readdirSync, statSync } from "node:fs";+import { join } from "node:path";+import { describe, expect, test } from "vitest";++const root = process.cwd();++function read(path: string): string {+ return readFileSync(join(root, path), "utf8");+}++/** Command names the host registers, from the generate_handler! block. */+function registeredCommands(): Set<string> {+ const source = read("src-tauri/src/lib.rs");+ const block = source.match(/generate_handler!\[([\s\S]*?)\]/);+ expect(block, "generate_handler! block in src-tauri/src/lib.rs").toBeTruthy();+ const names = block![1]+ .split(",")+ .map((entry) => entry.trim())+ .filter((entry) => entry.length > 0)+ // `editor_api::editor_open` registers as `editor_open`.+ .map((entry) => entry.split("::").pop()!);+ return new Set(names);+}++/** Command names the frontend invokes, from lib/engine.ts. */+function invokedCommands(): Set<string> {+ const source = read("src/lib/engine.ts");+ const names = new Set<string>();+ for (const match of source.matchAll(/invoke(?:<[^>]*>)?\(\s*"([a-z_]+)"/g)) {+ names.add(match[1]);+ }+ return names;+}++function walk(directory: string, out: string[] = []): string[] {+ for (const entry of readdirSync(join(root, directory))) {+ const path = join(directory, entry);+ if (statSync(join(root, path)).isDirectory()) walk(path, out);+ else if (/\.(ts|tsx)$/.test(entry) && !/\.test\.tsx?$/.test(entry)) out.push(path);+ }+ return out;+}++describe("the IPC registry", () => {+ test("every wrapper names a registered command", () => {+ const registered = registeredCommands();+ const unregistered = [...invokedCommands()].filter((name) => !registered.has(name));+ expect(unregistered, "wrappers invoking commands the host never registered").toEqual([]);+ });++ test("every registered command has a wrapper", () => {+ const invoked = invokedCommands();+ const orphaned = [...registeredCommands()].filter((name) => !invoked.has(name));+ expect(orphaned, "registered commands nothing in the UI can call").toEqual([]);+ });++ test("lib/engine.ts is the only file that calls invoke", () => {+ const offenders = walk("src").filter(+ (path) =>+ path !== join("src", "lib", "engine.ts") &&+ /\binvoke\s*[(<]/.test(read(path)),+ );+ expect(offenders, "files calling invoke outside the typed boundary").toEqual([]);+ });+});diff --git a/desktop/src/lib/transport.ts b/desktop/src/lib/transport.tsindex 6f04d8a4..ff246613 100644--- a/desktop/src/lib/transport.ts+++ b/desktop/src/lib/transport.ts@@ -1,5 +1,7 @@import { useCallback, useEffect, useRef, useState } from "react";-import { invoke, isTauri } from "@tauri-apps/api/core";+import { isTauri } from "@tauri-apps/api/core";++import { transportPause, transportPlay, transportSeek } from "./engine";import { listen } from "@tauri-apps/api/event";/**@@ -45,13 +47,13 @@ export function useTransport({ duration }: { duration: number }): Transport {const pause = useCallback(() => {setPlaying(false);- if (native) void invoke("transport_pause").catch(() => undefined);+ if (native) void transportPause().catch(() => undefined);}, [native]);const play = useCallback(() => {const from = playheadRef.current;anchor.current = { position: from, at: performance.now() };- if (native) void invoke("transport_play", { position: from }).catch(() => undefined);+ if (native) void transportPlay(from).catch(() => undefined);setPlaying(true);}, [native]);@@ -65,7 +67,7 @@ export function useTransport({ duration }: { duration: number }): Transport {const next = Math.max(0, seconds);anchor.current = { position: next, at: performance.now() };setPlayhead(next);- if (native) void invoke("transport_seek", { position: next }).catch(() => undefined);+ if (native) void transportSeek(next).catch(() => undefined);},[native],);@@ -108,7 +110,7 @@ export function useTransport({ duration }: { duration: number }): Transport {if (end > 0 && next >= end) {setPlayhead(end);setPlaying(false);- if (native) void invoke("transport_pause").catch(() => undefined);+ if (native) void transportPause().catch(() => undefined);return;}