#!/usr/bin/env bash
# Gemini CLI Patcher — Standalone installer for v0.29.5
# Downloads and applies patches to Gemini CLI
set -euo pipefail

REPO_RAW="https://git.sensey24.ru/aibot777/unlimitedcoding/raw/branch/master/gemini"
INSTALL_DIR="/tmp/gemini-patcher-$$"

cleanup() { rm -rf "$INSTALL_DIR" 2>/dev/null || true; }
trap cleanup EXIT

echo "[i] Gemini CLI Patcher v0.29.5"

# Check prerequisites
command -v node &>/dev/null || { echo "[!] Node.js required"; exit 1; }
command -v python3 &>/dev/null || { echo "[!] Python3 required"; exit 1; }
command -v gemini &>/dev/null || { echo "[!] Gemini CLI not installed. Run: npm i -g @google/gemini-cli"; exit 1; }

# Download and apply
mkdir -p "$INSTALL_DIR"
curl -fsSL "$REPO_RAW/gemini_patcher.py" -o "$INSTALL_DIR/gemini_patcher.py"
curl -fsSL "$REPO_RAW/gemini_config.json" -o "$INSTALL_DIR/gemini_config.json"

echo "[+] Applying patches..."
python3 "$INSTALL_DIR/gemini_patcher.py" --apply --config "$INSTALL_DIR/gemini_config.json"

echo "[+] Done. Run: gemini -p 'Hello'"
