#!/bin/bash # Installation script for UltraThink Path-Aware Analyzer set -e # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Functions print_status() { echo -e "${BLUE}[INFO]${NC} $1" } print_success() { echo -e "${GREEN}[SUCCESS]${NC} $1" } print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } print_error() { echo -e "${RED}[ERROR]${NC} $1" } # Check Python version check_python() { if command -v python3 &> /dev/null; then PYTHON_VERSION=$(python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')") PYTHON_CMD="python3" elif command -v python &> /dev/null; then PYTHON_VERSION=$(python -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')") PYTHON_CMD="python" else print_error "Python not found. Please install Python 3.8 or later." exit 1 fi # Check version if [[ $(echo "$PYTHON_VERSION >= 3.8" | bc -l) -eq 1 ]]; then print_success "Python $PYTHON_VERSION found" else print_error "Python 3.8 or later required. Found Python $PYTHON_VERSION" exit 1 fi } # Install dependencies install_dependencies() { print_status "Installing core dependencies..." # Install core requirements $PYTHON_CMD -m pip install --user -r requirements.txt if [ $? -eq 0 ]; then print_success "Core dependencies installed" else print_error "Failed to install core dependencies" exit 1 fi } # Install optional dependencies install_optional() { read -p "Install RAG/embedding features? (requires ~200MB download) [y/N]: " install_rag if [[ $install_rag =~ ^[Yy]$ ]]; then print_status "Installing RAG dependencies..." $PYTHON_CMD -m pip install --user sentence-transformers numpy if [ $? -eq 0 ]; then print_success "RAG dependencies installed" else print_warning "Failed to install RAG dependencies (optional)" fi fi read -p "Install development tools? [y/N]: " install_dev if [[ $install_dev =~ ^[Yy]$ ]]; then print_status "Installing development dependencies..." $PYTHON_CMD -m pip install --user pytest pytest-cov black flake8 if [ $? -eq 0 ]; then print_success "Development dependencies installed" else print_warning "Failed to install development dependencies (optional)" fi fi } # Create wrapper script create_wrapper() { SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)" WRAPPER_PATH="$HOME/.local/bin/ultrathink" # Create .local/bin if it doesn't exist mkdir -p "$HOME/.local/bin" # Create wrapper script cat > "$WRAPPER_PATH" << EOF #!/bin/bash # UltraThink Path-Aware Analyzer Wrapper # Auto-generated by install.sh SCRIPT_DIR="$SCRIPT_DIR" export PYTHONPATH="\$SCRIPT_DIR:\$PYTHONPATH" exec $PYTHON_CMD "\$SCRIPT_DIR/path_aware_analyzer.py" "\$@" EOF chmod +x "$WRAPPER_PATH" if [ -f "$WRAPPER_PATH" ]; then print_success "Wrapper script created at $WRAPPER_PATH" else print_error "Failed to create wrapper script" exit 1 fi } # Update configuration setup_config() { print_status "Setting up configuration..." # Create cache directory mkdir -p .claude/cache/embeddings # Check if config needs updating if [ ! -f config.yaml ]; then print_error "Configuration file config.yaml not found" exit 1 fi print_success "Configuration ready" } # Test installation test_installation() { print_status "Testing installation..." # Test basic functionality if $PYTHON_CMD path_aware_analyzer.py --stats &> /dev/null; then print_success "Installation test passed" else print_warning "Installation test failed - but this might be normal for first run" fi } # Add to PATH instructions show_path_instructions() { if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then print_warning "Add $HOME/.local/bin to your PATH to use 'ultrathink' command globally" echo "" echo "Add this line to your ~/.bashrc or ~/.zshrc:" echo "export PATH=\"\$HOME/.local/bin:\$PATH\"" echo "" echo "Or run: echo 'export PATH=\"\$HOME/.local/bin:\$PATH\"' >> ~/.bashrc" echo "Then: source ~/.bashrc" fi } # Main installation main() { print_status "Installing UltraThink Path-Aware Analyzer..." echo "" check_python install_dependencies install_optional create_wrapper setup_config test_installation echo "" print_success "Installation complete!" echo "" print_status "Usage examples:" echo " ./path_aware_analyzer.py \"analyze authentication flow\"" echo " ultrathink \"implement user login feature\"" echo " ultrathink --tool gemini \"review API endpoints\"" echo "" show_path_instructions } # Run main function main "$@"