Skip to content

Open source CapCut alternative.

TypeScript

fix(site): ship the cut-stt speech tool beside the Cut engine

David Le01358c5244d5
diff --git a/docs/guides/cut.md b/docs/guides/cut.md
index da64a74c..a255f7e9 100644
--- a/docs/guides/cut.md
+++ b/docs/guides/cut.md
@@ -30,7 +30,7 @@ Every Cut API route is a framework-free handler (web-standard request in, respon
The engine is a single compiled binary built from the site's Cut code and version-locked to the app: the app's dev run script and release packaging build and bundle it automatically (no separate step), and the app stamps its own release version into the engine's environment, so updates ride app releases. The Donkey app spawns it at launch — regardless of sign-in, since Cut is free and standalone — restarts it with backoff if it dies, skips spawning when another engine already answers on the port, and stops it on quit. Its data lives under the user's Application Support; its logs under the user's Logs folder.
-Because a GUI-spawned process inherits a bare PATH, the engine rebuilds it: the app's bundled tools first (bundled tool always wins), then the user's login-shell PATH and common install dirs. That is how it finds ffmpeg, the user's `claude` and `codex`, and the prebuilt speech tool.
+Because a GUI-spawned process inherits a bare PATH, the engine rebuilds it: tools shipped beside the engine binary first (they version with the app), then the app's bundled tools (bundled tool always wins), then the user's login-shell PATH and common install dirs. That is how it finds the speech tool, ffmpeg, and the user's `claude` and `codex`.
## Boundary with Donkey
@@ -51,7 +51,7 @@ Missing tools disable the matching feature; they never affect the rest of the si
| Feature | Needs |
| --- | --- |
| Encode, probe, thumbnails | the app's bundled `ffmpeg`/`ffprobe` |
-| Transcription / subtitles | prebuilt `cut-stt` from the bundled tools (dev falls back to compiling it) |
+| Transcription / subtitles | prebuilt `cut-stt` shipped beside the engine binary (the plain dev server falls back to compiling it) |
| AI assistant | the user's own `claude` and `codex` CLI logins |
| Projects, library, exports | writable local disk (Application Support when run as the engine) |
diff --git a/scripts/package-donkey-app.sh b/scripts/package-donkey-app.sh
index e81cd13b..7e6fd08c 100755
--- a/scripts/package-donkey-app.sh
+++ b/scripts/package-donkey-app.sh
@@ -327,10 +327,10 @@ stage_bundled_tools() {
# app and built here as part of packaging, so one command produces a complete app. Set
# DONKEY_CUT_ENGINE_BIN to reuse a prebuilt binary (e.g. a cross-arch or cached CI build) instead.
stage_cut_engine() {
+ local arch
+ arch="$(uname -m)"; [ "$arch" = "x86_64" ] && arch="x64"
local source_bin="${DONKEY_CUT_ENGINE_BIN:-}"
if [ -z "$source_bin" ]; then
- local arch
- arch="$(uname -m)"; [ "$arch" = "x86_64" ] && arch="x64"
echo "Building the Donkey Cut engine..."
bash "$ROOT_DIR/site/scripts/build-cut-engine.sh"
source_bin="$ROOT_DIR/site/dist/cut-engine/donkey-cut-engine-$arch"
@@ -361,6 +361,23 @@ PLIST
codesign "${sopts[@]}" "$dest_dir/donkey-cut-engine" >/dev/null 2>&1 || true
rm -f "$ents"
echo "Bundled the Donkey Cut engine from $source_bin."
+
+ # The on-device speech tool ships beside the engine binary — the engine puts
+ # its own directory on PATH — so transcription works out of the box and the
+ # tool updates in lockstep with the app. Plain Swift binary: hardened runtime,
+ # no JIT entitlements.
+ local source_stt="${DONKEY_CUT_STT_BIN:-$(dirname "$source_bin")/cut-stt-$arch}"
+ if [ ! -f "$source_stt" ]; then
+ echo "Donkey Cut speech tool not found at $source_stt." >&2
+ exit 1
+ fi
+ cp "$source_stt" "$dest_dir/cut-stt"
+ chmod +x "$dest_dir/cut-stt"
+ local topts=(--force --sign "$APP_SIGN_IDENTITY")
+ [ "$APP_SIGN_IDENTITY" != "-" ] && topts+=(--options runtime --timestamp)
+ [ -n "${DONKEY_SIGN_KEYCHAIN:-}" ] && topts+=(--keychain "$DONKEY_SIGN_KEYCHAIN")
+ codesign "${topts[@]}" "$dest_dir/cut-stt" >/dev/null 2>&1 || true
+ echo "Bundled the Donkey Cut speech tool from $source_stt."
}
rm -rf "$APP_DIR"
diff --git a/site/scripts/build-cut-engine.sh b/site/scripts/build-cut-engine.sh
index 51f76b70..deb8624e 100755
--- a/site/scripts/build-cut-engine.sh
+++ b/site/scripts/build-cut-engine.sh
@@ -27,4 +27,20 @@ for arch in "${arches[@]}"; do
src/cut/engine/main.ts \
--outfile "$out"
echo "==> built $out ($(du -h "$out" | cut -f1))"
+
+ # The on-device speech tool rides beside the engine binary: the engine puts
+ # its own directory on PATH, so transcription works out of the box and the
+ # tool updates in lockstep with the app.
+ swift_arch="$arch"
+ [ "$swift_arch" = "x64" ] && swift_arch="x86_64"
+ stt="dist/cut-engine/cut-stt-$arch"
+ echo "==> swiftc cut-stt ($arch)"
+ swiftc -O -parse-as-library -target "$swift_arch-apple-macos26" \
+ src/cut/server/native/cut-stt.swift -o "$stt"
done
+
+# Dev runs the host-arch engine straight out of dist (the dev app symlinks it),
+# so give the speech tool its bare name here for the beside-the-binary lookup.
+if [ -f "dist/cut-engine/cut-stt-$host_arch" ]; then
+ ln -sf "cut-stt-$host_arch" dist/cut-engine/cut-stt
+fi
diff --git a/site/src/cut/engine/paths.ts b/site/src/cut/engine/paths.ts
index 1b446b36..b26d1b7d 100644
--- a/site/src/cut/engine/paths.ts
+++ b/site/src/cut/engine/paths.ts
@@ -32,9 +32,10 @@ function loginShellPath(): Promise<string | null> {
/**
* The engine is spawned by an app, not a terminal, so it inherits a bare
- * PATH. Rebuild it: the app's bundled tools first (bundled tool always wins),
- * then the user's login-shell PATH, common install dirs, and whatever was
- * already there.
+ * PATH. Rebuild it: tools shipped beside the engine binary first (they
+ * version with the app), then the app's bundled tools (bundled tool always
+ * wins), then the user's login-shell PATH, common install dirs, and whatever
+ * was already there.
*/
export async function widenPath(): Promise<void> {
const parts: string[] = [];
@@ -44,6 +45,7 @@ export async function widenPath(): Promise<void> {
if (dir && !parts.includes(dir)) parts.push(dir);
}
};
+ push(path.dirname(process.execPath));
push(process.env.DONKEY_CUT_TOOLS_DIR);
push(await loginShellPath());
for (const dir of COMMON_BIN_DIRS) push(dir);
diff --git a/site/src/cut/server/transcribe.ts b/site/src/cut/server/transcribe.ts
index ed0fe43e..ed5ef591 100644
--- a/site/src/cut/server/transcribe.ts
+++ b/site/src/cut/server/transcribe.ts
@@ -81,13 +81,17 @@ function run(cmd: string, args: string[], notFound?: string, timeoutMs = 600_000
/**
* The speech engine: Apple's on-device SpeechAnalyzer (macOS 26+), wrapped by
- * a tiny Swift CLI. A prebuilt cut-stt (shipped with the app's bundled tools,
- * on PATH) wins; the dev fallback compiles the source on first use into
- * ~/.cache/cut. Nothing ever leaves the machine.
+ * a tiny Swift CLI. The packaged engine ships cut-stt beside its own binary
+ * (that directory leads PATH) and resolves it exclusively from PATH, so a dev
+ * machine exercises the exact prod lookup; the plain dev server compiles the
+ * source on first use into ~/.cache/cut. Nothing ever leaves the machine.
*/
async function ensureStt(): Promise<string> {
const prebuilt = await findOnPath("cut-stt");
if (prebuilt) return prebuilt;
+ if (process.env.DONKEY_CUT_ENGINE) {
+ throw new Error("The speech tool is missing. Update Donkey to restore transcription.");
+ }
const src = path.join(process.cwd(), "src", "cut", "server", "native", "cut-stt.swift");
const bin = path.join(os.homedir(), ".cache", "cut", "cut-stt");