mirror of
https://github.com/samsonjs/vibetunnel.git
synced 2026-03-26 09:35:52 +00:00
4.3 KiB
4.3 KiB
Tauri App Node.js Subprocess Architecture
Overview
The VibeTunnel Tauri app has been redesigned to use a subprocess architecture that matches the Mac app's approach. Instead of embedding terminal management in Rust, the app spawns the same vibetunnel Node.js executable used by the Mac app.
Architecture Components
1. Backend Manager (backend_manager.rs)
- Purpose: Manages the lifecycle of the Node.js subprocess
- Key Features:
- Spawns
vibetunnelexecutable with proper arguments - Monitors process health and handles crashes
- Implements exponential backoff for crash recovery (2, 4, 8, 16, 32 seconds)
- Platform-specific signal handling (SIGTERM on Unix, kill on Windows)
- Authentication credential management from settings
- Spawns
2. API Client (api_client.rs)
- Purpose: HTTP client for communicating with the Node.js server
- Endpoints Implemented:
POST /api/sessions- Create terminal sessionGET /api/sessions- List sessionsDELETE /api/sessions/:id- Close sessionPOST /api/sessions/:id/input- Send terminal inputPOST /api/sessions/:id/resize- Resize terminalGET /api/sessions/:id/buffer- Get terminal output
3. Resource Management
- Bundled Resources:
vibetunnel- Node.js standalone executablepty.node- Native module for terminal emulationspawn-helper- Unix helper for process spawningweb/public/**/*- Static web assets
Key Changes from Embedded Server
Before (Rust Terminal Management)
Tauri App
├── Rust HTTP Server (Axum)
├── Rust Terminal Manager (portable-pty)
└── Direct PTY management
After (Node.js Subprocess)
Tauri App
├── Backend Manager (subprocess spawner)
├── API Client (HTTP proxy)
└── Node.js Server (subprocess)
├── Express HTTP Server
├── Node-pty terminal management
└── WebSocket/SSE streaming
Benefits
- Code Reuse: Uses the exact same server implementation as the Mac app
- Consistency: Identical terminal behavior across all platforms
- Maintainability: Single codebase for terminal operations
- Stability: Process isolation prevents crashes from affecting the main app
- Features: All Mac app features available (HQ mode, authentication, etc.)
Implementation Details
Process Spawning
// Spawn vibetunnel with arguments
let mut cmd = Command::new(&exe_path);
cmd.args(&["--port", "4020"])
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.kill_on_drop(true);
Crash Recovery
- Monitors process exit status
- Implements exponential backoff: 2^n seconds (max 5 retries)
- Resets crash counter on successful restart
- Can be disabled via
set_crash_recovery_enabled(false)
Authentication
- Reads dashboard password from settings
- Passes credentials via command line arguments
- Supports same authentication as Mac app
Port Configuration
- Reads port from settings on startup
- Supports dynamic port changes via
restart_server_with_port - Updates both backend manager and server on port change
Platform Considerations
Windows
- Uses
.exeextension for executable - Handles process termination via
kill() - No spawn-helper required
Unix (Linux/macOS)
- Uses SIGTERM for graceful shutdown
- Requires spawn-helper for PTY operations
- Sets executable permissions (0o755)
Development Workflow
- Build Node.js server:
cd ../web && npm run build - Run Tauri dev:
./dev.shorcargo tauri dev - Production build:
./build.shorcargo tauri build
Troubleshooting
Server Won't Start
- Check if vibetunnel executable exists in resources
- Verify port is not already in use
- Check executable permissions on Unix
Terminal Commands Fail
- Ensure server is running (check status)
- Verify API client can reach localhost:port
- Check authentication if password enabled
Crash Recovery Not Working
- Check logs for exit codes
- Verify crash recovery is enabled
- Look for port binding issues (exit code 9)
Future Improvements
- Dynamic API Client: Create new API client instance on port change
- Health Monitoring: Periodic health checks like Mac app
- Binary Protocol: Implement WebSocket binary buffer streaming
- Hot Reload: Support server updates without app restart