From fc162ad55c98ad863a2a4b73306d9fbe74ffd894 Mon Sep 17 00:00:00 2001 From: Helmut Januschka Date: Fri, 27 Jun 2025 21:05:36 +0200 Subject: [PATCH] Prevent recursive VibeTunnel sessions (GitHub #95) (#104) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Prevent recursive VibeTunnel sessions (GitHub #95) Added detection and prevention of nested VibeTunnel sessions to avoid recursive 'vt' command execution. Changes: - Set INSIDE_VIBETUNNEL and VIBETUNNEL_SESSION environment variables when creating PTY sessions - Added check in vt script to detect if already inside a VibeTunnel session - Shows helpful error message when recursive session is attempted This prevents the confusing behavior where users could run 'vt' inside a VibeTunnel session, creating nested terminal instances. Now users get a clear error message explaining they're already in a VibeTunnel session. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude * Improve recursive session prevention based on PR feedback - Consolidate to single environment variable VIBETUNNEL_SESSION_ID - Add session ID for debugging purposes as requested - Show session ID in error message for better user feedback - Remove redundant environment variables (INSIDE_VIBETUNNEL, VIBETUNNEL_SESSION) This addresses feedback from PR #104 to use a single, more informative environment variable that serves both purposes: preventing recursion and providing debugging information. --------- Co-authored-by: Claude --- mac/VibeTunnel/vt | 7 +++++++ web/src/server/pty/pty-manager.ts | 2 ++ 2 files changed, 9 insertions(+) diff --git a/mac/VibeTunnel/vt b/mac/VibeTunnel/vt index 4683dd3e..74ff2db0 100755 --- a/mac/VibeTunnel/vt +++ b/mac/VibeTunnel/vt @@ -1,6 +1,13 @@ #!/bin/bash # VibeTunnel CLI wrapper +# Check if we're already inside a VibeTunnel session +if [ -n "$VIBETUNNEL_SESSION_ID" ]; then + echo "Error: Already inside a VibeTunnel session (ID: $VIBETUNNEL_SESSION_ID). Recursive VibeTunnel sessions are not supported." >&2 + echo "If you need to run commands, use them directly without the 'vt' prefix." >&2 + exit 1 +fi + # Try standard locations first, but verify the binary exists APP_PATH="" for TRY_PATH in "/Applications/VibeTunnel.app" "$HOME/Applications/VibeTunnel.app"; do diff --git a/web/src/server/pty/pty-manager.ts b/web/src/server/pty/pty-manager.ts index 36d1e2c6..a24ae9e1 100644 --- a/web/src/server/pty/pty-manager.ts +++ b/web/src/server/pty/pty-manager.ts @@ -237,6 +237,8 @@ export class PtyManager extends EventEmitter { const ptyEnv = { ...process.env, TERM: term, + // Set session ID to prevent recursive vt calls and for debugging + VIBETUNNEL_SESSION_ID: sessionId, }; // Debug log the spawn parameters