Skip to content

Open source CapCut alternative.

TypeScript

docs(cut): document the app-hosted Cut engine

David Le9fdf74f82475
diff --git a/docs/guides/cut.md b/docs/guides/cut.md
index b1b2f367..e96d11f3 100644
--- a/docs/guides/cut.md
+++ b/docs/guides/cut.md
@@ -1,6 +1,6 @@
# Cut
-Cut (publicly "Donkey Cut") is a standalone, free video editor. The hosted domain `cut.donkeyuse.com` serves only its client bundle — every page is client-rendered — and the page does all real work against the engine running on the user's own Mac: local disk, local ffmpeg, on-device speech, and the user's own Claude/Codex CLI logins. Cut shares the site's Next.js app for hosting only — it does not touch Donkey's accounts, credits, sign-in, database, or hosted models.
+Cut (publicly "Donkey Cut") is a standalone, free video editor. The hosted domain `cut.donkeyuse.com` serves only its client bundle — every page is client-rendered — and the page does all real work against the Cut engine: a local server the Donkey Mac app ships and supervises on the user's own Mac. The engine uses local disk, the app's bundled ffmpeg, on-device speech, and the user's own Claude/Codex CLI logins. Cut shares Donkey's hosting and distribution only — it does not touch Donkey's accounts, credits, sign-in, database, or hosted models.
**The one rule:** Cut's server side runs only on the user's Mac. On a hosted deploy every Cut API answers 404 before any handler runs, so the unauthenticated routes are unreachable there and nothing can execute off-Mac — including any path to Donkey's production models, which Cut has none of. Don't wrap Cut's API routes in the Donkey auth helper, reach for Prisma, or bill against credits to "harden" them; local-only is the design.
@@ -13,41 +13,48 @@ page from cut.donkeyuse.com (hosted) page from cut.localhost (local dev)
│ client bundle only; │ one local server:
│ every Cut API 404s there │ pages + APIs, same origin
▼ ▼
-browser ──────────── API calls ──────────▶ engine on the user's Mac (127.0.0.1)
- │
- ▼
- local disk · ffmpeg · on-device speech
- · the user's own claude/codex CLI logins
+browser ── API calls ──▶ Cut engine on 127.0.0.1 (spawned by the Donkey app)
+ │
+ ▼
+ local disk · bundled ffmpeg · on-device speech
+ · the user's own claude/codex CLI logins
```
-The engine grants the hosted origin cross-origin access, and only that origin. Loading the page from the hosted domain without a running engine shows a "start Donkey Cut on this Mac" state instead of a broken editor.
+The client probes the engine's health endpoint (dedicated port first, dev server second) and remembers the winner. The engine grants the hosted origin cross-origin access, and only that origin. Without a running engine the page shows a "get Donkey / open Donkey" state that connects by itself as soon as the engine appears. Engine updates ride the Donkey app's own auto-updater, so the client never prompts to update.
-## Boundary with Donkey
+## One API surface, one router
+
+Every Cut API route is a framework-free handler (web-standard request in, response out) registered once in a route table (`matchCutRoute`), namespaced under `/api/cut/*` to keep it clear of Donkey's own APIs. Both surfaces dispatch through that one table: the packaged engine mounts it directly, and the Next dev server reaches it through a single optional-catch-all route (`/api/cut/[[...slug]]`). They are the same router — static-over-dynamic precedence, HEAD, and 405s behave identically, and there is nowhere for the two to drift. The hosted 404 is applied once, in that shared dispatch.
+
+## The engine
+
+The engine is a single compiled binary built from the site's Cut code (`npm run engine:build` in `site/`) and version-locked to the app: the app stamps its own release version into the engine's environment, and 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.
-Cut lives in the same repo and app but shares nothing with the Donkey product yet.
+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.
+
+## Boundary with Donkey
| Concern | Donkey | Cut |
| --- | --- | --- |
| Sign-in | Required account | None |
| Billing | Credits | Free |
| Storage | Database | Local disk |
-| Runtime | Hosted routes + Mac app | Local machine only |
+| Model access | Hosted routes | The user's own CLI logins |
+| Distribution | The Mac app | Rides the same app |
-The only shared code runs one way: Cut uses a few site UI utilities. Nothing in the Donkey site imports Cut, and Cut adds no database models.
+The only shared code runs one way: Cut uses a few site UI utilities, and the engine rides the app's process-environment helpers. Nothing in the Donkey product imports Cut, and Cut adds no database models.
## Local resources
-Cut assumes the machine serving it is a Mac with these tools present. Missing tools disable the matching feature; they don't affect the rest of the site.
+Missing tools disable the matching feature; they never affect the rest of the site or app.
| Feature | Needs |
| --- | --- |
-| Encode, probe, thumbnails | `ffmpeg`, `ffprobe` |
-| Transcription / subtitles | `swiftc` and Apple's on-device speech (recent macOS) |
-| AI assistant | the operator's own `claude` and `codex` CLI logins |
-| Projects, library, exports | writable local disk under the app's working directory |
-
-Because storage is local disk and AI rides the user's own CLI logins, the engine runs where those resources live — never on hosted infrastructure. That boundary is enforced twice: the site's proxy 404s every Cut API path on a hosted deploy, and the engine's disk and process-spawning code refuses to run there.
+| Encode, probe, thumbnails | the app's bundled `ffmpeg`/`ffprobe` |
+| Transcription / subtitles | prebuilt `cut-stt` from the bundled tools (dev 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) |
## Where it lives
-The editor and its engine code sit under the site app's Cut folder; its pages and API handlers mount under the shared route tree. Host routing, the hosted API shut-off, and the CORS grant all live in the site's proxy file (`src/proxy.ts`, the Next 16 successor to middleware), with the engine-side guard beside the Cut server code.
+The editor, its handlers, and the engine entry sit under the site app's Cut folder; host routing, the hosted API shut-off, and the CORS grant live in the site's proxy file (`src/proxy.ts`, the Next 16 successor to middleware). The app-side supervisor lives with the Donkey runtime code, and the packaging scripts stage the engine binary into the app bundle.
diff --git a/plans/cut-engine.md b/plans/cut-engine.md
new file mode 100644
index 00000000..bf56e239
--- /dev/null
+++ b/plans/cut-engine.md
@@ -0,0 +1,41 @@
+# Cut Engine: Hosted Client, Engine Inside the Donkey App
+
+Make cut.donkeyuse.com work for a visitor on a Mac by riding what Donkey already ships. The page serves the whole UI; the Cut engine — the local server doing disk, ffmpeg, on-device speech, and the user's own claude/codex logins — runs on `127.0.0.1:41417`, spawned and supervised by the Donkey Mac app. The app already has signing, notarization, bundled ffmpeg, and a release/update channel; Cut reuses all of it instead of shipping a second artifact.
+
+**The governing principle: zero-ask lifecycle.** The web client drives everything — connection, reconnection, update nudges — and the user is asked nothing beyond what macOS mandates (app install, permission dialogs). Engine updates ride Donkey app releases; no separate updater, no prompts.
+
+## Supported so far
+
+- **Client**: probes `/api/cut/engine/health` on `127.0.0.1:41417` then `:3000` (dev), memoizes the winner, `localStorage["cut-engine-origin"]` override; engine-down screen auto-polls every 3s; all Cut pages client-rendered; chat transport resolves its URL per send; hosted deploys 404 every Cut API; CORS granted to `https://cut.donkeyuse.com` only.
+- **Slice 1 — handler core (done)**: every Cut API route's logic lives in framework-free handlers under the Cut server's `http/` folder (web-standard Request/Response), with one route table (`CUT_ROUTES` + `matchCutRoute`) under `/api/cut/*` that both surfaces dispatch through — the engine mounts it directly, and the Next dev server reaches it via a single optional-catch-all route (`/api/cut/[[...slug]]`) that delegates to the shared table. `matchCutRoute` mirrors Next's routing (static-over-dynamic precedence, HEAD via the GET handler, 405 for a known path with no handler for the method), so dev and engine cannot diverge. Data roots are engine-aware: dev keeps `projects/`/`library/` at the checkout cwd; with `DONKEY_CUT_ENGINE` set they move to `~/Library/Application Support/DonkeyCut` (`DONKEY_CUT_DATA_DIR` overrides).
+- **Slice 2 — engine binary (done)**: `npm run engine:build` (bun is a devDependency) compiles the engine entry into a single ~62MB Mac binary that mounts the route table on `127.0.0.1:41417`, widens PATH from the app's tools dir + a login shell + common bins, resolves the user's Claude Code install for the Agent SDK, and serves the MCP proxy as its own `mcp-proxy` subcommand. The HTTP layer refuses any browser Origin that isn't the hosted Cut page before a handler runs (a no-Origin same-machine caller is allowed), grants that one origin CORS, aborts a turn only on real client disconnect, and tears down file streams when a download is cut off. The bind port validates `DONKEY_CUT_PORT` and fails loud rather than binding a random port. Health reports `DONKEY_CUT_VERSION` (stamped by the app; "dev" otherwise). Verified end-to-end: health, CORS preflight and origin allowlist, foreign-origin refusal, HEAD/405 parity with Next, project CRUD on the engine data dir, models probe, and the MCP proxy tool-catalog round trip.
+- **Slice 4 — speech tool lookup (done)**: transcription resolves a prebuilt `cut-stt` from PATH (the app's bundled tools) first and compiles from source only in dev; a missing tool degrades with a clear message. CI prebuild of `cut-stt` still pends with app packaging below.
+- **Slice 5 — install funnel (done)**: the engine-down screen offers "Get Donkey for Mac" and auto-connects when the engine appears. Engine updates ride the Donkey app's own auto-updater — the client shows no update prompt.
+
+## Target
+
+```
+cut.donkeyuse.com (static client) user's Mac
+ │ Donkey.app (signed, auto-updating)
+ │ engine-down screen: └─ spawns + supervises
+ │ "Get Donkey" / "Open Donkey" donkey-cut-engine (:41417)
+ ▼ ├─ mounts CUT_ROUTES
+page polls → connects → works ├─ data: ~/Library/App Support/DonkeyCut
+ ├─ tools: the app's bundled ffmpeg/ffprobe
+ ├─ AI: user's claude/codex logins
+ └─ version in /api/cut/engine/health
+```
+
+- **Slice 3 — app-side supervision (done)**: the Donkey app spawns the engine at launch regardless of sign-in (Cut is free and standalone), via a supervisor in the runtime module: shell environment from the app's existing helper plus the engine flag, app version stamp, and tools dir; crash restarts with backoff; a health preflight skips spawning when another engine already owns the port; the app's quit path stops it. Engine logs go to the user's Logs folder, size-capped. Staging: dev builds symlink the built binary into the app bundle; release packaging copies and signs it with the JIT entitlements a bun binary needs under the hardened runtime; the nightly workflow builds the engine and passes it to packaging. The app builds clean with all of it.
+- **Slice 6 — docs (done)**: `docs/guides/cut.md` describes the app-hosted engine as supported behavior.
+
+## Verification left
+
+Code-complete and verified as far as this machine allows (engine smoke-tested end-to-end standalone; app + site compile clean; scripts and workflow lint clean). Outstanding before moving this plan to done:
+
+- First nightly run bundles the engine into the dmg — confirm the packaged app spawns it and cut.donkeyuse.com connects.
+- `cut-stt` is still compiled on demand in dev; adding a prebuilt to the published tools bundle (publish-bundled-tools workflow) removes the Xcode CLT need on user machines. The engine already prefers a prebuilt from PATH when present.
+
+## What Should Be Done Next
+
+Run a nightly (or local `package-donkey-app.sh` with `DONKEY_CUT_ENGINE_BIN` set), install the dmg, and verify the live path: app launch → engine on 41417 → cut.donkeyuse.com connects and edits. Then move this plan to `plans/done/`.