vibetunnel/mac/VibeTunnel/vt
Helmut Januschka fc162ad55c
Prevent recursive VibeTunnel sessions (GitHub #95) (#104)
* 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 <noreply@anthropic.com>

* 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 <noreply@anthropic.com>
2025-06-27 21:05:36 +02:00

54 lines
No EOL
1.9 KiB
Bash
Executable file

#!/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
if [ -d "$TRY_PATH" ] && [ -f "$TRY_PATH/Contents/Resources/vibetunnel" ]; then
APP_PATH="$TRY_PATH"
break
fi
done
# If not found in standard locations with valid binary, search for it
if [ -z "$APP_PATH" ]; then
# First try DerivedData (for development)
for CANDIDATE in $(find ~/Library/Developer/Xcode/DerivedData -name "VibeTunnel.app" -type d 2>/dev/null | grep -v "\.dSYM" | grep -v "Index\.noindex"); do
if [ -f "$CANDIDATE/Contents/Resources/vibetunnel" ]; then
APP_PATH="$CANDIDATE"
break
fi
done
# If still not found, use mdfind as last resort
if [ -z "$APP_PATH" ]; then
for CANDIDATE in $(mdfind -name "VibeTunnel.app" 2>/dev/null | grep -v "\.dSYM"); do
if [ -f "$CANDIDATE/Contents/Resources/vibetunnel" ]; then
APP_PATH="$CANDIDATE"
break
fi
done
fi
if [ -z "$APP_PATH" ]; then
echo "Error: VibeTunnel.app with vibetunnel binary not found anywhere on the system" >&2
exit 1
fi
fi
# Execute vibetunnel from app bundle
VIBETUNNEL_BIN="$APP_PATH/Contents/Resources/vibetunnel"
if [ ! -f "$VIBETUNNEL_BIN" ]; then
echo "Error: vibetunnel binary not found in app bundle at $VIBETUNNEL_BIN" >&2
exit 1
fi
# Run with fwd command
exec "$VIBETUNNEL_BIN" fwd "$@"