Skip to content

Commit 4fef7d2

Browse files
derhallyclaude
andcommitted
fix: improve start_ui.sh compatibility for Linux environments
Fixes #168 This commit addresses several compatibility issues in start_ui.sh: - Auto-detect package manager (uv > pip3 > pip) for broader compatibility - Use detected $PYTHON_CMD variable consistently throughout script - Add Python 3.11+ version requirement check - Try multiple Python commands in priority order - Use portable shebang (#!/usr/bin/env bash) - Add set -e for better error handling - Improve error messages and diagnostics - Use exec for final Python invocation The script now works correctly on systems with only pip3 or uv available, and properly detects and uses the correct Python version. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent d65fa0c commit 4fef7d2

File tree

1 file changed

+82
-21
lines changed

1 file changed

+82
-21
lines changed

start_ui.sh

Lines changed: 82 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
#!/bin/bash
2-
cd "$(dirname "$0")"
1+
#!/usr/bin/env bash
2+
set -e # Exit on error
3+
4+
# Change to script directory
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
cd "$SCRIPT_DIR"
7+
38
# AutoForge UI Launcher for Unix/Linux/macOS
49
# This script launches the web UI for the autonomous coding agent.
510

@@ -30,18 +35,35 @@ else
3035
fi
3136
echo ""
3237

33-
# Check if Python is available
34-
if ! command -v python3 &> /dev/null; then
35-
if ! command -v python &> /dev/null; then
36-
echo "ERROR: Python not found"
37-
echo "Please install Python from https://python.org"
38-
exit 1
38+
# Check if Python is available and meet version requirements
39+
PYTHON_CMD=""
40+
for cmd in python3.13 python3.12 python3.11 python3 python; do
41+
if command -v "$cmd" &> /dev/null; then
42+
PYTHON_CMD="$cmd"
43+
break
3944
fi
40-
PYTHON_CMD="python"
41-
else
42-
PYTHON_CMD="python3"
45+
done
46+
47+
if [ -z "$PYTHON_CMD" ]; then
48+
echo "ERROR: Python not found"
49+
echo "Please install Python 3.11+ from https://python.org"
50+
exit 1
4351
fi
4452

53+
# Verify Python version is 3.11+
54+
PYTHON_VERSION=$($PYTHON_CMD -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
55+
PYTHON_MAJOR=$(echo "$PYTHON_VERSION" | cut -d. -f1)
56+
PYTHON_MINOR=$(echo "$PYTHON_VERSION" | cut -d. -f2)
57+
58+
if [ "$PYTHON_MAJOR" -lt 3 ] || ([ "$PYTHON_MAJOR" -eq 3 ] && [ "$PYTHON_MINOR" -lt 11 ]); then
59+
echo "ERROR: Python 3.11+ required (found $PYTHON_VERSION)"
60+
echo "Please upgrade Python or install a newer version"
61+
exit 1
62+
fi
63+
64+
echo "[OK] Using Python $PYTHON_VERSION ($PYTHON_CMD)"
65+
echo ""
66+
4567
# Check if venv exists with correct structure for this platform
4668
# Windows venvs have Scripts/, Linux/macOS have bin/
4769
if [ ! -f "venv/bin/activate" ]; then
@@ -55,30 +77,69 @@ if [ ! -f "venv/bin/activate" ]; then
5577
echo " rm -rf venv"
5678
exit 1
5779
fi
58-
else
59-
echo "Creating virtual environment..."
6080
fi
61-
$PYTHON_CMD -m venv venv
62-
if [ $? -ne 0 ]; then
81+
echo "Creating virtual environment..."
82+
if ! $PYTHON_CMD -m venv venv; then
6383
echo "[ERROR] Failed to create virtual environment"
6484
echo "Please ensure the venv module is installed:"
6585
echo " Ubuntu/Debian: sudo apt install python3-venv"
86+
echo " Fedora/RHEL: sudo dnf install python3-venv"
6687
echo " Or try: $PYTHON_CMD -m ensurepip"
6788
exit 1
6889
fi
90+
echo "[OK] Virtual environment created"
91+
fi
92+
93+
# Detect package manager preference (uv > pip3 > pip)
94+
PKG_MGR=""
95+
if command -v uv &> /dev/null; then
96+
PKG_MGR="uv"
97+
echo "[OK] Using uv package manager"
98+
elif command -v pip3 &> /dev/null; then
99+
PKG_MGR="pip3"
100+
echo "[OK] Using pip3 package manager"
101+
elif command -v pip &> /dev/null; then
102+
PKG_MGR="pip"
103+
echo "[OK] Using pip package manager"
104+
else
105+
echo "[ERROR] No package manager found (pip, pip3, or uv required)"
106+
exit 1
69107
fi
108+
echo ""
70109

71110
# Activate the virtual environment
72-
source venv/bin/activate
73-
if [ $? -ne 0 ]; then
74-
echo "[ERROR] Failed to activate virtual environment"
111+
if [ -f "venv/bin/activate" ]; then
112+
# shellcheck disable=SC1091
113+
source venv/bin/activate
114+
else
115+
echo "[ERROR] Virtual environment activation script not found"
75116
echo "The venv may be corrupted. Try: rm -rf venv && ./start_ui.sh"
76117
exit 1
77118
fi
78119

79-
# Install dependencies
120+
# Install dependencies based on package manager
80121
echo "Installing dependencies..."
81-
pip install -r requirements.txt --quiet
122+
if [ "$PKG_MGR" = "uv" ]; then
123+
if ! uv pip install -r requirements.txt --quiet; then
124+
echo "[ERROR] Failed to install dependencies with uv"
125+
echo "Try manually: uv pip install -r requirements.txt"
126+
exit 1
127+
fi
128+
else
129+
# Upgrade pip to avoid warnings (only for pip/pip3)
130+
echo "Ensuring pip is up to date..."
131+
$PKG_MGR install --upgrade pip --quiet 2>&1 | grep -v "Requirement already satisfied" || true
132+
133+
if ! $PKG_MGR install -r requirements.txt --quiet; then
134+
echo "[ERROR] Failed to install dependencies"
135+
echo "Try manually: source venv/bin/activate && $PKG_MGR install -r requirements.txt"
136+
exit 1
137+
fi
138+
fi
139+
140+
echo ""
141+
echo "Starting AutoForge UI server..."
142+
echo ""
82143

83144
# Ensure playwright-cli is available for browser automation
84145
if ! command -v playwright-cli &> /dev/null; then
@@ -90,4 +151,4 @@ if ! command -v playwright-cli &> /dev/null; then
90151
fi
91152

92153
# Run the Python launcher
93-
python start_ui.py "$@"
154+
exec $PYTHON_CMD start_ui.py "$@"

0 commit comments

Comments
 (0)