#!/usr/bin/env bash
set -euo pipefail
SESSION_ID=""
echo "Hermes -> Gemma4 via local Ollama"
echo "Type /exit to quit. Type /session to see the current Hermes session id."
echo
while true; do
  printf 'gemma4-hermes ❯ '
  IFS= read -r user || exit 0
  [ -z "$user" ] && continue
  if [ "$user" = "/exit" ] || [ "$user" = "/quit" ]; then
    echo "Goodbye."
    exit 0
  fi
  if [ "$user" = "/session" ]; then
    echo "${SESSION_ID:-'(no session yet)'}"
    echo
    continue
  fi
  if [ -n "$SESSION_ID" ]; then
    OUT=$(/Users/apayne/.timmy/scripts/hermes_gemma4_ollama_once.py "$user" "$SESSION_ID")
  else
    OUT=$(/Users/apayne/.timmy/scripts/hermes_gemma4_ollama_once.py "$user")
  fi
  NEW_SESSION=$(printf '%s
' "$OUT" | awk -F= '/^SESSION_ID=/{print $2}')
  [ -n "$NEW_SESSION" ] && SESSION_ID="$NEW_SESSION"
  printf '%s
' "$OUT" | sed '1,/^---RESPONSE---$/d'
  echo
 done
