#!/bin/bash set -e # Start script for Hugging Face Space # Mounts the OpenSIN-Code repository if available echo "🚀 Starting A2A Cloud Coder Agent..." # Check for repo in common locations REPO_PATHS=( "/workspace/OpenSIN-Code" "/home/user/project/OpenSIN-Code" "/home/user/OpenSIN-Code" "/project/OpenSIN-Code" ) for path in "${REPO_PATHS[@]}"; do if [ -d "$path" ]; then echo "📁 Found repository at $path" REPO_DIR="$path" break fi done # If not found, clone it using GITHUB_TOKEN if [ -z "$REPO_DIR" ]; then echo "⚠️ No repository found. Cloning OpenSIN-Code..." mkdir -p /workspace if [ -n "$GITHUB_TOKEN" ]; then echo "🔑 Using GITHUB_TOKEN for authentication" git clone "https://x-access-token:${GITHUB_TOKEN}@github.com/OpenSIN-AI/OpenSIN-Code.git" /workspace/OpenSIN-Code else echo "❌ GITHUB_TOKEN not set - cannot clone repository" echo " Please set GITHUB_TOKEN in Space secrets" exit 1 fi REPO_DIR="/workspace/OpenSIN-Code" echo "✅ Repository cloned to $REPO_DIR" fi # Export for Python code export REPO_DIR # Create opencode config if not present (uses OCI fallback proxy) mkdir -p ~/.config/opencode if [ ! -f ~/.config/opencode/opencode.json ]; then cat > ~/.config/opencode/opencode.json << 'EOF' { "model": "opencode/qwen3.6-plus-free", "fallback": "opencode/minimax-m2.5-free", "provider": { "openai": { "options": { "baseUrl": "http://92.5.60.87:4100/v1" }, "models": { "qwen3.6-plus-free": { "name": "Qwen 3.5 Plus Free", "id": "qwen3.6-plus-free", "limit": { "context": 32000, "output": 8000 } }, "minimax-m2.5-free": { "name": "MiniMax M2.5 Free", "id": "minimax-m2.5-free", "limit": { "context": 32000, "output": 8000 } } } } } } EOF echo "✅ Created opencode config (using OCI fallback proxy)" fi # Check opencode availability if command -v opencode &> /dev/null; then echo "✅ opencode CLI found" opencode --version else echo "❌ opencode CLI not found. Agent will fail to generate code." fi # Check GitHub token if [ -z "$GITHUB_TOKEN" ]; then echo "⚠️ GITHUB_TOKEN not set - commits will fail" else echo "✅ GITHUB_TOKEN set" fi # Start the application with uvicorn directly echo "🎯 Starting uvicorn on port ${PORT:-7860}" exec python -m uvicorn main:app --host 0.0.0.0 --port ${PORT:-7860} --log-level info