VibeTunnel Documentation
repository·main·Indexed 26 days ago
https://github.com/amantus-ai/vibetunnelA terminal sharing server (version 1.0.0-beta.18) that proxies terminal sessions into a web browser for monitoring and interaction with terminals and AI agents. Supports macOS, Linux, and headless environments. Includes documentation for the native iOS and macOS clients, the vt command wrapper for TTY forwarding, and server configuration via environment variables and Tailscale integration.
What's inside VibeTunnel
- Tailscale integration provides secure, remote access to your terminal sessions without manual network configuration. It enables automatic server discovery and handles HTTPS/HTTP connection logic automatically using enterprise-grade encryption. This allows VibeTunnel iOS users to access their servers from any network location (local, public Wi-Fi, or traveling) seamlessly.
Overview of VibeTunnel Architecture
mainVibeTunnel is a macOS application that provides browser-based access to Mac terminals. It consists of a native macOS application (Swift/SwiftUI) that manages a Node.js/Bun server process. This server handles terminal sessions via
node-ptyand communicates with clients (Web Browsers or iOS apps) using a WebSocket-based binary buffer protocol.Key architectural components include:
- ServerManager: Manages the Bun server lifecycle and configuration.
- BunServer: The core process handling HTTP/WebSocket traffic and PTY allocation.
- SessionMonitor: Tracks active terminal sessions.
- TerminalManager: Integrates with macOS terminal applications like Terminal.app or iTerm2.
- NgrokService: Manages secure public tunnels for remote access.
Understand Asciicast Pruning Performance Improvements
mainVibeTunnel uses a centralized pruning logic to handle asciicast data more efficiently. The current implementation (post-commit
627309ebf) moves from a retroactive, playback-based detection model to a real-time, write-based model. This ensures that pruning sequences (like terminal clear operations) are detected once during the recording phase, allowing for immediate and precise playback without the need to re-scan large files when a client connects.Key Benefits:
- Reduced Latency: Client connections start streaming almost instantly (1-10ms) because offsets are pre-calculated, compared to 100-500ms in the old system.
- Lower Resource Usage: Single-pass detection reduces CPU and I/O overhead, especially for large files (10MB+).
- Scalability: Moves from $O(n)$ complexity per client connection to $O(1)$ lookup, making it suitable for multiple concurrent viewers.
Configure VibeTunnel Authentication modes
mainVibeTunnel supports four authentication modes:
- None: Localhost access only (default).
- Password: A simple shared secret.
- Token: JWT-based authentication.
- External: Integration with services like Tailscale or ngrok.
Security Settings Reference
Setting Default Options AuthenticationNoneNone,Password,TokenNetworkLocalhostLocalhost,LAN,PublicPassword- User-defined Token Expiry24h1h-7dPlatform requirements for VibeTunnel
mainVibeTunnel supports multiple platforms with specific requirements:
macOS
- OS Version: macOS 14.0+ (Sonoma or later)
- Hardware: Apple Silicon Mac (M1+)
- Build Requirements: Xcode 15+ and code signing for terminal permissions.
- CLI Tool: The
vtCLI tool is installed to/usr/local/bin/vton macOS.
iOS
- OS Version: iOS 17.0+
- Device: iPhone or iPad
- Connectivity: Requires network access to the VibeTunnel server.
Linux / Headless
- OS: Any Linux distribution
- Runtime: Node.js 22.12 through 24.x
- Deployment: Ideal for VPS/cloud environments via the
vibetunnelnpm package.
Browser
- Support: Modern browsers with WebSocket support.
- Rendering: Terminal rendering is handled via canvas/WebGL.
VibeTunnel Project Structure Overview
mainThe repository is organized into platform-specific directories and a core web implementation:
mac/: macOS native application built with Swift and SwiftUI.ios/: iOS companion application built with Swift and SwiftUI.web/: The core server and frontend implementation (TypeScript).web/src/server/: Node.js/Bun server logic.web/src/client/: Web UI built with Lit and TypeScript.
scripts/: Build and utility scripts (e.g., logging scripts).docs/: Project documentation.
Understand VibeTunnel Session Creation Flow
mainA session is created when the macOS App calls
ServerManager.createSession(). This triggers a Unix Socket IPC message to the server, which then performs the following steps:- Executes
POST /api/sessions. - Calls
TerminalManager.createTerminal(). - Spawns a PTY via
PtyManager.spawn()usingnode-pty. - Creates a control directory at
~/.vibetunnel/control/[sessionId]/. - Starts the
BufferAggregator. - Returns a response containing
{ sessionId, wsUrl }to the client. - The client connects via WebSocket for bidirectional terminal I/O.
- Executes
Understand VibeTunnel System Architecture
mainVibeTunnel follows a client-server-PTY architecture designed to stream terminal sessions to a web interface.
Core Components:
- Client: Browser or Electron application.
- Web Server: Handles HTTP endpoints and WebSocket connections.
- PTY Process: Manages the pseudo-terminal lifecycle.
- Terminal Manager: Responsible for binary buffer rendering (converting ANSI to binary cells).
- Stream Watcher: Monitors ascinema files and implements clear sequence truncation to prevent massive data transfers.
- vibetunnel-fwd: An external terminal forwarding component that mirrors stdout to a terminal.
Understand the VibeTunnel Native Forwarder architecture
mainvibetunnel-fwdis a per-session native process written in Rust. It acts as a bridge between a PTY (Pseudo-Terminal) and the VibeTunnel web server. Thevtwrapper launches the forwarder around a command, and the web server manages the session by watching session artifacts and sending control messages via a Unix socket.Architecture Flow:
vt$\rightarrow$vibetunnel-fwd$\rightarrow$PTY$\rightarrow$child commandNote that
vibetunnel-fwdsupports macOS and Linux; Windows is not supported.Understand the VibeTunnel project structure
mainVibeTunnel is a cross-platform terminal sharing application composed of three primary modules. Developers can interact with or extend the project based on their target platform:
- macOS Application (
mac/): A native macOS app using SwiftUI and the Bun runtime for server orchestration. - iOS Application (
ios/): A companion app for mobile terminal access, utilizing SwiftUI and WebSocket clients. - Web Server (
web/): A TypeScript-based web server (Express) that manages PTY processes and provides a web-based terminal interface.
The project uses separate build systems: Xcode for Apple platforms and Node.js/TypeScript for the web server.
- macOS Application (
Understand the VibeTunnel Socket Protocol architecture
mainVibeTunnel uses a binary framed message protocol over Unix domain sockets for all inter-process communication (IPC).
Components
- PTY Manager (Server): Creates a Unix domain socket at
{session_dir}/ipc.sock, manages PTY process I/O, and tracks session state. - Socket Client: Connects to the session's Unix socket to send stdin data and control commands, and receive errors/responses.
Socket Path
- Location:
{control_dir}/{session_id}/ipc.sock - macOS Limitation: macOS has a 104 character limit for Unix socket paths (103 usable). Keep control directories short to avoid
EINVALerrors.
- PTY Manager (Server): Creates a Unix domain socket at
Understand VibeTunnel package types
mainVibeTunnel is distributed in three primary formats:
- macOS Application Bundle: The main
VibeTunnel.appbundle. It is signed with a Developer ID Application certificate, notarized by Apple, and contains the embedded Bun server and CLI binaries. - DMG Distribution: A disk image (
VibeTunnel-{version}.dmg) intended for user downloads. It contains the app bundle and an/Applicationssymlink. - CLI Tools Package: Command line binaries installed to
/usr/local/bin. This includes thevibetunnelbinary and thevtwrapper script.
- macOS Application Bundle: The main