#!/usr/bin/env sh
# AgentSync installer — installs the published CLI from npm.
#   curl -fsSL https://install.agentsync.trailmark.online | sh
set -e

PKG="@juli_p/agentsync"

echo "Installing AgentSync CLI ($PKG)…"

if ! command -v node >/dev/null 2>&1; then
  echo "Error: Node.js (>=20) is required but was not found."
  echo "Install Node from https://nodejs.org/ (or via nvm), then re-run this installer."
  exit 1
fi

if ! command -v npm >/dev/null 2>&1; then
  echo "Error: npm is required but was not found (it ships with Node.js)."
  exit 1
fi

NODE_MAJOR=$(node -p "process.versions.node.split('.')[0]" 2>/dev/null || echo 0)
if [ "$NODE_MAJOR" -lt 20 ]; then
  echo "Warning: Node $(node -v) detected; AgentSync needs Node >=20. Attempting install anyway…"
fi

npm install -g "$PKG"

echo ""
echo "✓ AgentSync installed. Try:"
echo "    agentsync list"
echo "    agentsync --help"
