#!/bin/bash
# Jarvis Dashboard — local dev server
# Starts static file server (port 8080) + Jarvis API (port 3001)
# Then opens the dashboard in your browser.

STATIC_PORT=8080
API_PORT=3001
DIR="$(cd "$(dirname "$0")" && pwd)"

# ── Start Jarvis API ─────────────────────────────────────────
echo "Starting Jarvis API on port $API_PORT..."
source ~/.claude/skills/.venv/bin/activate
python3 ~/.claude/skills/jarvis-api.py &
API_PID=$!

# ── Start static file server ─────────────────────────────────
echo "Starting dashboard on http://localhost:$STATIC_PORT/code.html"
echo "Jarvis API at http://localhost:$API_PORT"
echo "Press Ctrl+C to stop both."
echo ""

sleep 0.5
open "http://localhost:$STATIC_PORT/code.html"

python3 -m http.server $STATIC_PORT --directory "$DIR"

# ── Cleanup ───────────────────────────────────────────────────
echo "Shutting down..."
kill $API_PID 2>/dev/null
