#!/bin/bash
# QwenClaw Complete Startup Script
# Starts both Rig service and QwenClaw daemon

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR/.."

echo "🐾 Starting QwenClaw with Rig Integration..."

# Start Rig service in background
echo "🦀 Starting Rig service..."
./scripts/start-rig.sh &
RIG_PID=$!

# Wait for Rig to start
echo "⏳ Waiting for Rig service to be ready..."
sleep 5

# Check if Rig is healthy
if curl -s http://127.0.0.1:8080/health > /dev/null 2>&1; then
    echo "✅ Rig service is ready!"
else
    echo "⚠️  Rig service may not be ready yet, continuing anyway..."
fi

# Start QwenClaw daemon
echo "🐾 Starting QwenClaw daemon..."
exec bun run start --web
