#!/bin/bash
# Sand Stream Toolkit - macOS launcher
# Double-click in Finder, or run from Terminal:
#   ./install-macos.command            interactive menu
#   ./install-macos.command install    enable Stream mode
#   ./install-macos.command uninstall  restore Cursor
set -euo pipefail

here="$(cd "$(dirname "$0")" && pwd)"
core="$here/../cursor_sand_core.py"
if [ ! -f "$core" ]; then
  core="$here/cursor_sand_core.py"
fi
if [ ! -f "$core" ]; then
  echo "cursor_sand_core.py not found next to this launcher" >&2
  exit 1
fi

if ! command -v python3 >/dev/null 2>&1; then
  echo "python3 not found. Install Xcode Command Line Tools: xcode-select --install" >&2
  exit 1
fi

# Cursor.app lives in /Applications and its files are root-owned when
# installed for all users; re-run with sudo if we cannot write to it.
app="/Applications/Cursor.app"
if [ -d "$app" ] && [ ! -w "$app/Contents/Resources/app/product.json" ]; then
  exec sudo python3 "$core" "$@"
fi
exec python3 "$core" "$@"
