#!/bin/bash set -e SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" cd "$SCRIPT_DIR" echo "=== Kipinä Studio Local Development ===" # Tapetaan vanhat prosessit portissa 3000 if lsof -ti:3000 >/dev/null 2>&1; then echo "[0] Vapautetaan portti 3000..." lsof -ti:3000 | xargs kill -9 2>/dev/null || true sleep 1 fi # Frontend echo "[1/3] Rakennetaan frontend..." cd "$SCRIPT_DIR/frontend" [ -d node_modules ] || npm install --silent npm run build 2>&1 | tail -1 cd "$SCRIPT_DIR" # Hub echo "[2/3] Käynnistetään hub..." STATIC_DIR="$SCRIPT_DIR/frontend/dist" cargo run -p hub 2>&1 & HUB_PID=$! # Odotetaan että hub on pystyssä for i in $(seq 1 10); do if curl -s -o /dev/null http://localhost:3000 2>/dev/null; then break; fi sleep 1 done # Native-node (jos Ollama on käynnissä) NODE_PID="" if curl -s http://localhost:11434/api/tags >/dev/null 2>&1; then MODEL=$(curl -s http://localhost:11434/api/tags | python3 -c " import sys, json models = json.load(sys.stdin).get('models', []) # Priorisoi: 7b > 3b > mikä tahansa coder > mikä tahansa best = None for m in models: name = m['name'] if '7b' in name and 'coder' in name: best = name; break if 'coder' in name and not best: best = name if not best and models: best = models[0]['name'] if best: print(best) " 2>/dev/null) if [ -n "$MODEL" ]; then echo "[3/3] Ollama: $MODEL — käynnistetään native-node..." HUB_URL=ws://localhost:3000/ws OLLAMA_MODEL="$MODEL" cargo run -p native-node --no-default-features 2>&1 & NODE_PID=$! else echo "[3/3] Ollama käynnissä mutta ei malleja — asenna: ollama pull qwen2.5-coder:7b" fi else echo "[3/3] Ollama ei käynnissä — käytetään selaimen Wasm-laskentaa" fi echo "" echo "=== http://localhost:3000 ===" echo " Ctrl+C pysäyttää" open http://localhost:3000 2>/dev/null || xdg-open http://localhost:3000 2>/dev/null || true trap 'echo ""; echo "Pysäytetään..."; kill $HUB_PID $NODE_PID 2>/dev/null; exit 0' INT TERM wait $HUB_PID