#!/usr/bin/env bash
set -euo pipefail
PROFILE="$HOME/.profile"
BASHRC="$HOME/.bashrc"
LINE='export PATH="$HOME/.npm-global/bin:$HOME/.local/bin:$PATH"'
changed=0
if ! grep -Fxq "$LINE" "$PROFILE" 2>/dev/null; then
  echo "$LINE" >> "$PROFILE"
  echo "Appended PATH to $PROFILE"
  changed=1
fi
if ! grep -Fxq "$LINE" "$BASHRC" 2>/dev/null; then
  echo "$LINE" >> "$BASHRC"
  echo "Appended PATH to $BASHRC"
  changed=1
fi
export PATH="$HOME/.npm-global/bin:$HOME/.local/bin:$PATH"
echo "PATH set to: $PATH"

echo
for cmd in claude codex devin agy; do
  echo "=== $cmd presence ==="
  if command -v "$cmd" >/dev/null 2>&1; then
    echo "FOUND: $(command -v $cmd)"
  else
    echo "NOT FOUND"
  fi
done

echo
# Help and login hint extraction
if command -v claude >/dev/null 2>&1; then
  echo '--- claude --help (first 120 lines) ---'
  claude --help 2>&1 | sed -n '1,120p' || true
  echo '--- claude help grep login/auth ---'
  claude --help 2>&1 | grep -i -E 'login|auth|configure|token|key|signin|sign-in' || true
else
  echo 'claude not installed'
fi

echo
if command -v codex >/dev/null 2>&1; then
  echo '--- codex --help (first 120 lines) ---'
  codex --help 2>&1 | sed -n '1,120p' || true
  echo '--- codex help grep login/auth ---'
  codex --help 2>&1 | grep -i -E 'login|auth|configure|token|key|signin|sign-in' || true
else
  echo 'codex not installed'
fi

echo
if command -v devin >/dev/null 2>&1; then
  echo '--- devin --help (first 120 lines) ---'
  devin --help 2>&1 | sed -n '1,120p' || true
  echo '--- devin help grep login/auth ---'
  devin --help 2>&1 | grep -i -E 'login|auth|configure|token|key|signin|sign-in' || true
else
  echo 'devin not installed'
fi

echo
# Antigravity docs inspection
echo '--- Antigravity page snippet (first 300 lines) ---'
curl -fsSL https://antigravity.google/product/antigravity-cli 2>/dev/null | sed -n '1,300p' || echo 'failed to fetch antigravity page'

echo
# Versions
for cmd in claude codex devin agy; do
  echo "--- $cmd version/path ---"
  if command -v "$cmd" >/dev/null 2>&1; then
    echo "path: $(command -v $cmd)"
    $cmd --version 2>/dev/null || echo 'no --version output'
  else
    echo 'not installed'
  fi
done

echo
if [ "$changed" -eq 1 ]; then
  echo 'Please start a new shell or run: source ~/.profile'
fi
