#!/bin/bash
# omarchy:summary=List AI profiles and the current default
# omarchy:examples=omarchycn ai profile list

set -euo pipefail

source "$OMARCHY_PATH/cn/lib/ai.sh"

current=""
if [[ -f $CN_AI_CURRENT ]]; then
  current=$(<"$CN_AI_CURRENT")
fi

found="false"
for f in "$CN_AI_PROFILE_DIR"/*.toml; do
  [[ -f $f ]] || continue
  found="true"
  name="${f##*/}"
  name="${name%.toml}"
  marker=" "
  [[ $name == "$current" ]] && marker="*"
  printf '%s %-14s %s x %s x %s\n' "$marker" "$name" \
    "$(cn_ai_profile_field "$name" harness)" \
    "$(cn_ai_profile_field "$name" provider)" \
    "$(cn_ai_profile_field "$name" model)"
done

if [[ $found == "false" ]]; then
  echo "No profiles (create: omarchycn ai profile create <name> <harness> <provider> <model>)"
fi
