#!/bin/sh
# Nuramem CLI installer — https://get.nuramem.ai
#
#   curl -fsSL https://get.nuramem.ai | sh
#
# Installs the `nura` command-line client (cross-model memory from the terminal).
# Prefers an isolated tool install (uv → pipx); falls back to pip --user. The
# `nura` CLI also carries the Nuramem skill (`nura skill install`) and the
# multi-client MCP installer (`nura connect`), so this one script bootstraps the
# whole local surface. No sudo; nothing installed system-wide.
set -eu

PKG="nuramem"   # PyPI distribution name (import package: nuramem_cli)
GRN=''; YLW=''; DIM=''; RST=''
if [ -t 1 ] && command -v tput >/dev/null 2>&1 && [ "$(tput colors 2>/dev/null || echo 0)" -ge 8 ]; then
  GRN="$(tput setaf 2)"; YLW="$(tput setaf 3)"; DIM="$(tput dim)"; RST="$(tput sgr0)"
fi
say() { printf '%s\n' "$*"; }
ok()  { printf '%s✓%s %s\n' "$GRN" "$RST" "$*"; }
warn(){ printf '%s!%s %s\n' "$YLW" "$RST" "$*" >&2; }
die() { printf 'install failed: %s\n' "$*" >&2; exit 1; }

say "${DIM}Installing the Nuramem CLI (nura)…${RST}"

INSTALLED=""
if command -v uv >/dev/null 2>&1; then
  uv tool install --quiet "$PKG" && INSTALLED="uv tool"
elif command -v pipx >/dev/null 2>&1; then
  pipx install "$PKG" && INSTALLED="pipx"
elif command -v python3 >/dev/null 2>&1; then
  warn "no uv or pipx found — using 'pip install --user' (a venv via uv/pipx is cleaner)."
  python3 -m pip install --user --upgrade "$PKG" && INSTALLED="pip --user"
else
  die "need one of: uv (https://docs.astral.sh/uv/), pipx, or python3. Install uv and re-run."
fi
[ -n "$INSTALLED" ] || die "the package manager reported an error."

if command -v nura >/dev/null 2>&1; then
  ok "installed nura via ${INSTALLED} ($(nura --version 2>/dev/null || echo "$PKG"))."
else
  ok "installed via ${INSTALLED}."
  warn "the 'nura' command isn't on your PATH yet. For pipx/pip --user add ~/.local/bin to PATH,"
  warn "then open a new terminal. (uv tool: run 'uv tool update-shell'.)"
fi

cat <<EOF

Next:
  ${GRN}nura login${RST}            sign in (opens your browser)
  ${GRN}nura connect${RST}          wire Nuramem into your AI clients (Claude/Cursor/VS Code/…)
  ${GRN}nura skill install${RST}    teach a coding assistant the memory gesture
  ${GRN}nura this "…"${RST}         save something;  ${GRN}nura search "…"${RST}  to recall

Docs: https://nuramem.ai
EOF
