Native Helper
The Native Helper is a local companion application that provides Firefox project persistence, external AI control, yt-dlp-based downloads, and isolated local-AI runtimes.
Overview
Section titled “Overview”The Native Helper is a lightweight Rust binary that runs locally and communicates with the MasterSelects web app over WebSocket and HTTP. Its main capabilities are:
- Downloads: YouTube, TikTok, Instagram, Twitter/X, and other platforms via yt-dlp
- File System Access: Read/write files, create directories, folder picker — primarily used for Firefox project persistence (since Firefox lacks the File System Access API)
- AI Bridge: Forward AI tool calls from local agents to the running MasterSelects editor session
- Local AI Providers: Provision and supervise isolated MatAnyone2 and MuScriptor Python sidecars
The browser client can discover the auth token automatically from GET /startup-token on the local HTTP server, then authenticate over WebSocket/HTTP as needed.
Note: The browser-side code (
src/services/nativeHelper/) contains protocol types for video decode/encode commands (open,decode,prefetch,start_encode, etc.) and aNativeDecoderclass. The shipped helper handles downloads, file system operations, and the MatAnyone2 and MuScriptor job protocols. It does not expose editor tools to external agents.
Features
Section titled “Features”- YouTube downloads — Fast downloads via yt-dlp integration
- Multi-platform downloads — TikTok, Instagram, Twitter/X, and other platforms via yt-dlp
- Format selection — List available formats and choose quality/codec before downloading
- File system operations — Write files, create directories, list/delete/rename, check existence
- Folder picker — Native OS folder picker dialog (for Firefox project folder selection)
- Picked-folder grants — Folder picker and restore paths are registered as allowed roots so projects outside the default Documents folder can be opened and served through the helper
- Manual path fallback — If the helper cannot show a native folder picker on the current platform, the web app prompts for the project folder path instead
- Firefox persistence — Enables full project save/load on Firefox via file system commands
- MatAnyone2 video matting — Pinned local runtime, model cache, persistent inference sidecar, transparent VP9/WebM output, progress, and cancellation
- MuScriptor music-to-MIDI — Pinned isolated runtime, gated model variants, persistent transcription sidecar, instrument constraints, progress, and cancellation
- System tray — On Windows, runs as a system tray app with auto-start and self-update support
- Temp download dir — yt-dlp writes to the helper’s local download folder (
temp/masterselects-downloads) before files are copied into a project - Default project root — projects are created under
Documents/MasterSelectswhen available, otherwiseHome/MasterSelects, unlessMASTERSELECTS_PROJECT_ROOTis set to an absolute path
Architecture
Section titled “Architecture”Browser (MasterSelects App) | | WebSocket (ws://127.0.0.1:9876) | HTTP server (http://127.0.0.1:9877) | vNative Helper (Rust) | | bundled or system yt-dlp (subprocess) | File system (direct) | MatAnyone2 / MuScriptor sidecar control | vLocal file systemInstallation
Section titled “Installation”- Download the helper from the Native Helper lightning-icon dialog in the toolbar or from GitHub Releases
- Make it executable:
chmod +x masterselects-helper - Run it:
./masterselects-helper
The helper will automatically be detected by the app.
Windows
Section titled “Windows”- Download the latest Windows MSI from the Native Helper lightning-icon dialog in the toolbar or GitHub Releases
- Run the MSI installer. It installs
yt-dlp.exenext tomasterselects-helper.exe, so downloads do not need a separatepip install yt-dlp - Launch
masterselects-helper.exeif it does not auto-start - Use
--consoleflag to run in terminal mode instead of tray mode
- Download from the Native Helper lightning-icon dialog in the toolbar or GitHub Releases
- Follow the platform-specific release instructions; the current UI describes moving a macOS app to Applications and launching it once.
Options
Section titled “Options”masterselects-helper [OPTIONS]
Options: -p, --port <PORT> Port to listen on [default: 9876] --background Run in background (minimal output) --allowed-origins <LIST> Additional allowed origins (comma-separated) --generate-token Generate and print auth token, then exit --log-level <LEVEL> Log level (trace/debug/info/warn/error) [default: info] --console Run in console mode (Windows only; Linux/macOS always console) --no-auth Disable authentication (not recommended) -h, --help Print help -V, --version Print versionEnabling the Native Helper
Section titled “Enabling the Native Helper”- Run the Native Helper
- Enable Native Helper in its dialog; the toolbar lightning icon becomes active when connected
- Downloads and Firefox file system operations are available
- If the helper starts with auth enabled, the browser can usually discover the token automatically from
/startup-token
Status Indicator
Section titled “Status Indicator”The toolbar uses a lightning icon. Its dialog shows one of:
- Disabled — Native Helper is disabled in settings
- Not running — Native Helper is enabled but disconnected
- Connected — Native Helper is connected and active
Click the indicator for details:
- Helper version
- yt-dlp availability (bundled next to the helper or installed on PATH)
- Project and MatAnyone2 capability status
- Published-release and app-target version status
Protocol
Section titled “Protocol”WebSocket Commands
Section titled “WebSocket Commands”The helper communicates via WebSocket (port 9876) with JSON commands:
| Command | Purpose |
|---|---|
auth | Authenticate with token |
info | Get system info (version, yt-dlp status, etc.) |
ping | Connection keepalive |
download_youtube | Download video via yt-dlp |
download | Generic download via yt-dlp (all platforms) |
list_formats | List available formats for a video URL |
get_file | Get a file from local filesystem |
locate | Locate a file by name in common directories |
write_file | Write data to a file (text or base64) |
create_dir | Create a directory |
list_dir | List directory contents |
delete | Delete a file or directory |
exists | Check if a path exists |
rename | Rename or move a file/directory |
grant_path | Register an absolute project path as an allowed root |
pick_folder | Open native OS folder picker dialog |
mat_anyone_* | GPU-only MatAnyone2 setup, model download, inference, cancel, uninstall (NVIDIA CUDA required; no CPU fallback) |
muscriptor_* | MuScriptor status, setup, gated model download, start/stop, transcribe, cancel, uninstall |
HTTP Server
Section titled “HTTP Server”An HTTP server runs on port 9877 (WebSocket port + 1).
| Endpoint | Purpose |
|---|---|
GET /file?path=... | Serve local files to the browser (auth required) |
POST /upload?path=... | Upload/write local files efficiently (auth required) |
GET /project-root | Return the default project root (no auth) |
GET /startup-token | Return the current auth token for local discovery (no auth) |
Security
Section titled “Security”- Localhost only — Binds to 127.0.0.1
- Origin validation — Only accepts connections from allowed origins
- Auth token — Token-based authentication for HTTP and WebSocket bridge operations
- Scoped external access — Network access is used only for requested downloads such as yt-dlp, pinned provider source, and model weights; inference stays local
- Allowed origins — WebSocket connections accept localhost and Cloudflare Pages origins; the configured defaults additionally list the MasterSelects production, staging, and local-development origins. Add preview origins with
--allowed-originswhen HTTP CORS requires them. - Sidecar path policy — Local-AI inputs and outputs are checked against project/granted roots or the exact provider temp root before subprocess access
- Transient model credentials — Gated HuggingFace tokens are passed only to the model-download subprocess and are excluded from command logging
Technical Details
Section titled “Technical Details”Source Code
Section titled “Source Code”The helper is a unified Rust binary:
tools/native-helper/ Cargo.toml src/ main.rs # Entry point, CLI args, platform setup server.rs # Server orchestration and shared state http_server.rs # Authenticated HTTP health and local-file routes websocket_server.rs # Authenticated WebSocket command dispatch session.rs # Session state and command coordination session/ file_commands.rs # File grants, reads, and staging matanyone_commands.rs # MatAnyone2 command routing utils.rs # Shared utilities download/ mod.rs ytdlp.rs # yt-dlp integration protocol/ mod.rs commands.rs # Command/Response types, error codes matanyone/ # MatAnyone2 model, process, and inference env.rs # Environment orchestration env/ # Platform, source, and bootstrap stages muscriptor/ # MuScriptor environment, process, control, inference python/ matanyone2_server.py muscriptor_server.pyWindows-specific modules:
tray.rs # System tray icon and menu updater.rs # Self-update from GitHub ReleasesBrowser Client Code
Section titled “Browser Client Code”src/services/nativeHelper/ NativeHelperClient.ts # WebSocket client (singleton) NativeDecoder.ts # Video decoder wrapper protocol.ts # Message types nativeHelper*Commands.ts # Download, file, MatAnyone2, MuScriptor, and video command adapters nativeHelperMessageHandler.ts # Response and progress dispatch releases.ts # Helper release target and release lookup index.ts # Re-exportsMatAnyone2 and MuScriptor use their own job protocols and local sidecars.
Dependencies (Cargo.toml)
Section titled “Dependencies (Cargo.toml)”- tokio — Async runtime
- tokio-tungstenite — WebSocket
- warp — HTTP file server
- clap — CLI argument parsing
- serde/serde_json — JSON serialization
- rfd — Native file dialog (folder picker)
- tray-icon (Windows) — System tray
- winreg (Windows) — Registry for auto-start
- ureq — HTTP client for model downloads and Windows self-update
- tracing/tracing-subscriber — Structured logging
- windows-sys (Windows) — Windows console, shell, and process APIs
Build with:
cd tools/native-helpercargo build --releaseTroubleshooting
Section titled “Troubleshooting”Helper not detected
Section titled “Helper not detected”- Check if running:
ps aux | grep masterselects-helper - Check port:
ss -tlnp | grep 9876 - Try restart: Kill and run again
- Check browser console for WebSocket errors
Downloads not working
Section titled “Downloads not working”- On Windows, reinstall or update the helper MSI so the bundled
yt-dlp.exeis present in the install folder - For source builds and non-Windows archive installs, check that
yt-dlpis installed on PATH or placed next to the helper binary - Run
yt-dlp --versionor<helper install folder>\yt-dlp.exe --versionto verify - Check helper log output for errors
- If YouTube reports bot or sign-in blocking, close Chrome completely and retry so yt-dlp can read cookies
Connection errors
Section titled “Connection errors”- Check firewall allows localhost:9876
- Ensure only one instance running
- On Windows, try
--consoleflag to see log output - If Firefox reports the helper as disconnected after refresh, press Check connection; the web client refreshes the helper startup token on every reconnect, times out stalled reconnects, and retries every few seconds after disconnection
The helper has Rust unit tests for protocol normalization, path-policy behavior, provider state, token redaction, archive selection, process helpers, and inference parsing. Browser protocol adapters and provider stores/mappers have focused Vitest coverage in tests/unit/.
Related Documents
Section titled “Related Documents”- Media Downloads — Media panel download UI powered by the Native Helper
- Project Persistence — Firefox project persistence via Native Helper file system ops
- MuScriptor Music-to-MIDI — Local audio-to-MIDI provider and timeline workflow