vibetunnel/linux
Helmut Januschka a66620be52
fix: Go server CPU optimization & resize control flag (#32)
* fix: optimize Go server CPU usage from 500%+ to efficient levels

Major performance improvements to resolve excessive CPU consumption:

**Critical Fixes:**
- Remove WebSocket busy loop that caused continuous CPU spinning
- Fix microsecond-level polling (100μs → 10ms) reducing 100x operations
- Replace ps subprocess calls with efficient kill(pid,0) syscalls
- Increase timer intervals (1s → 30s) for session status checks

**Optimizations:**
- Control FIFO polling: 100ms → 1s intervals
- Select timeout: 100ms → 1s to reduce unnecessary wakeups
- Smart status caching: skip checks for already-exited sessions
- Remove unused imports (os/exec, strconv)

**Impact:**
- Eliminates tight loops causing 10,000+ operations per second
- Reduces subprocess overhead from frequent ps command executions
- Changes from polling-based to efficient event-driven architecture
- Expected CPU usage reduction from 500%+ to levels comparable with Node.js version

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: prevent WebSocket channel close panic with sync.Once

- Add sync.Once to prevent double-closing of done channel
- Update handleTextMessage signature to accept close function
- Use closeOnceFunc for safe channel closure across goroutines

Fixes panic: 'close of closed channel' in WebSocket handler

* feat: add --do-not-allow-column-set flag to disable resizing for spawned sessions

**New Flag:**
- `--do-not-allow-column-set` (default: true) - Disables terminal resizing for spawned shells
- Only affects sessions created with `spawn_terminal=true`
- Detached sessions (command-line, API without spawn) always allow resizing

**Implementation:**
- Add `IsSpawned` field to session.Config and session.Info structs
- Track whether session was spawned in terminal vs detached
- Server checks flag + spawn status before allowing resize operations
- Returns descriptive error for blocked resize attempts

**Behavior:**
- Spawned sessions: Resize blocked when flag enabled (default)
- Detached sessions: Always allow resizing regardless of flag
- Existing sessions preserve their resize capabilities

**API Response for blocked resize:**
```json
{
  "success": false,
  "message": "Resizing is disabled for spawned sessions",
  "error": "resize_disabled_for_spawned_sessions"
}
```

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: extend --do-not-allow-column-set flag to block ALL session resizing

**Breaking Change:** Flag now affects both spawned AND detached sessions

**Changes:**
- Remove `sess.IsSpawned()` check in resize handler
- Block resizing for ALL sessions when flag is enabled (default: true)
- Update flag description: "Disable terminal resizing for all sessions (spawned and detached)"
- Update error message: "Terminal resizing is disabled by server configuration"
- Update error code: "resize_disabled_by_server"

**New Behavior:**
- `--do-not-allow-column-set=true` (default): NO resizing for any session type
- `--do-not-allow-column-set=false`: Allow resizing for all session types
- Applies uniformly to both spawned terminal windows and detached CLI sessions

**API Response for blocked resize:**
```json
{
  "success": false,
  "message": "Terminal resizing is disabled by server configuration",
  "error": "resize_disabled_by_server"
}
```

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-06-20 11:37:54 +02:00
..
cmd/vibetunnel fix: Go server CPU optimization & resize control flag (#32) 2025-06-20 11:37:54 +02:00
pkg fix: Go server CPU optimization & resize control flag (#32) 2025-06-20 11:37:54 +02:00
build-universal.sh Add support for go in Mac app, implement missing features 2025-06-19 23:44:28 +02:00
build-vt-universal.sh move closer to rust server format 2025-06-20 07:17:15 +02:00
claude Add new vt binary that supports both rust and go 2025-06-20 00:48:33 +02:00
debug_pty.go Add support for go in Mac app, implement missing features 2025-06-19 23:44:28 +02:00
go.mod move closer to rust server format 2025-06-20 07:17:15 +02:00
go.sum move closer to rust server format 2025-06-20 07:17:15 +02:00
Makefile move closer to rust server format 2025-06-20 07:17:15 +02:00
README.md docs: add --no-spawn flag documentation 2025-06-20 08:27:19 +02:00
test-vt.sh Add new vt binary that supports both rust and go 2025-06-20 00:48:33 +02:00
vibetunnel-tls Add Go implementation of VibeTunnel server (#16) 2025-06-18 23:32:35 +02:00

VibeTunnel Linux

A Linux implementation of VibeTunnel that provides remote terminal access via web browser, fully compatible with the macOS VibeTunnel app.

Features

  • 🖥️ Remote Terminal Access: Access your Linux terminal from any web browser
  • 🔒 Secure: Optional password protection and localhost-only mode
  • 🌐 Network Ready: Support for both localhost and network access modes
  • 🔌 ngrok Integration: Easy external access via ngrok tunnels
  • 📱 Mobile Friendly: Responsive web interface works on phones and tablets
  • 🎬 Session Recording: All sessions recorded in asciinema format
  • Real-time: Live terminal streaming with proper escape sequence handling
  • 🛠️ CLI Compatible: Full command-line interface for session management

Quick Start

Build from Source

# Clone the repository (if not already done)
git clone <repository-url>
cd vibetunnel/linux

# Build web assets and binary
make web build

# Start the server
./build/vibetunnel --serve

Using the Pre-built Binary

# Download latest release
wget <release-url>
chmod +x vibetunnel

# Start server on localhost:4020
./vibetunnel --serve

# Or with password protection
./vibetunnel --serve --password mypassword

# Or accessible from network
./vibetunnel --serve --network

Installation

System-wide Installation

make install

User Installation

make install-user

As a Service (systemd)

make service-install
make service-enable
make service-start

Usage

Server Mode

Start the web server to access terminals via browser:

# Basic server (localhost only)
vibetunnel --serve

# Server with password protection
vibetunnel --serve --password mypassword

# Server accessible from network
vibetunnel --serve --network

# Custom port
vibetunnel --serve --port 8080

# With ngrok tunnel
vibetunnel --serve --ngrok --ngrok-token YOUR_TOKEN

# Disable terminal spawning (detached sessions only)
vibetunnel --serve --no-spawn

Access the dashboard at http://localhost:4020 (or your configured port).

Session Management

Create and manage terminal sessions:

# List all sessions
vibetunnel --list-sessions

# Create a new session
vibetunnel bash
vibetunnel --session-name "dev" zsh

# Send input to a session
vibetunnel --session-name "dev" --send-text "ls -la\n"
vibetunnel --session-name "dev" --send-key "C-c"

# Kill a session
vibetunnel --session-name "dev" --kill

# Clean up exited sessions
vibetunnel --cleanup-exited

Configuration

VibeTunnel supports configuration files for persistent settings:

# Show current configuration
vibetunnel config

# Use custom config file
vibetunnel --config ~/.config/vibetunnel.yaml --serve

Example configuration file (~/.vibetunnel/config.yaml):

control_path: /home/user/.vibetunnel/control
server:
  port: "4020"
  access_mode: "localhost"  # or "network"
  static_path: ""
  mode: "native"
security:
  password_enabled: true
  password: "mypassword"
ngrok:
  enabled: false
  auth_token: ""
advanced:
  debug_mode: false
  cleanup_startup: true
  preferred_terminal: "auto"
update:
  channel: "stable"
  auto_check: true

Command Line Options

Server Options

  • --serve: Start HTTP server mode
  • --port, -p: Server port (default: 4020)
  • --localhost: Bind to localhost only (127.0.0.1)
  • --network: Bind to all interfaces (0.0.0.0)
  • --static-path: Custom path for web UI files

Security Options

  • --password: Dashboard password for Basic Auth
  • --password-enabled: Enable password protection

ngrok Integration

  • --ngrok: Enable ngrok tunnel
  • --ngrok-token: ngrok authentication token

Session Management

  • --list-sessions: List all sessions
  • --session-name: Specify session name
  • --send-key: Send key sequence to session
  • --send-text: Send text to session
  • --signal: Send signal to session
  • --stop: Stop session (SIGTERM)
  • --kill: Kill session (SIGKILL)
  • --cleanup-exited: Clean up exited sessions

Advanced Options

  • --debug: Enable debug mode
  • --cleanup-startup: Clean up sessions on startup
  • --server-mode: Server mode (native, rust)
  • --no-spawn: Disable terminal spawning (creates detached sessions only)
  • --control-path: Control directory path
  • --config, -c: Configuration file path

Web Interface

The web interface provides:

  • Dashboard: Overview of all terminal sessions
  • Terminal View: Real-time terminal interaction
  • Session Management: Start, stop, and manage sessions
  • File Browser: Browse filesystem (if enabled)
  • Session Recording: Playback of recorded sessions

Compatibility

VibeTunnel Linux is designed to be 100% compatible with the macOS VibeTunnel app:

  • Same API: Identical REST API and WebSocket endpoints
  • Same Web UI: Uses the exact same web interface
  • Same Session Format: Compatible asciinema recording format
  • Same Configuration: Similar configuration options and structure

Development

Prerequisites

  • Go 1.21 or later
  • Node.js and npm (for web UI)
  • Make

Building

# Install dependencies
make deps

# Build web assets
make web

# Build binary
make build

# Run in development mode
make dev

# Run tests
make test

# Format and lint code
make check

Project Structure

linux/
├── cmd/vibetunnel/     # Main application
├── pkg/
│   ├── api/           # HTTP server and API endpoints
│   ├── config/        # Configuration management
│   ├── protocol/      # Asciinema protocol implementation
│   └── session/       # Terminal session management
├── scripts/           # Build and utility scripts
├── Makefile          # Build system
└── README.md         # This file

License

This project is part of the VibeTunnel ecosystem. See the main repository for license information.

Contributing

Contributions are welcome! Please see the main VibeTunnel repository for contribution guidelines.

Support

For support and questions:

  1. Check the main VibeTunnel documentation
  2. Open an issue in the main repository
  3. Check existing issues for known problems