#!/usr/bin/env bash
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LOG_DIR="${ROOT_DIR}/logs"
LOG_FILE="${LOG_DIR}/local_restart.log"
mkdir -p "${LOG_DIR}"

if ! command -v pnpm >/dev/null 2>&1; then
  echo "pnpm not found"
  exit 1
fi

cd "${ROOT_DIR}"

echo "Starting Memind local stack via pnpm dev..."
nohup pnpm dev >"${LOG_FILE}" 2>&1 &
echo $! > "${LOG_DIR}/local_restart.pid"

echo "Started."
echo "Log: ${LOG_FILE}"
echo "MindSpace: http://127.0.0.1:5173/?preview=mindspace"
echo "API / Portal: http://127.0.0.1:8081"
echo "Ops: http://127.0.0.1:3002/ops/"
echo "Admin: http://127.0.0.1:8082"
