#!/usr/bin/env bash
set -euo pipefail

REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"

usage() {
    cat <<'EOF'
Usage: ./jeannie ask QUESTION...

Search the homelab knowledge index for the closest docs, runbooks, scripts, and
Jeannie commands. Set LAB_AI_ASK_LLM=true to ask Ollama after retrieval.
EOF
}

case "${1:-}" in
    ""|-h|--help|help)
        usage
        exit 0
        ;;
esac

if [ "${LAB_AI_ASK_LLM:-false}" = "true" ]; then
    exec "${REPO_ROOT}/scripts/query-homelab-ai-index" --ask "$@"
fi

exec "${REPO_ROOT}/scripts/query-homelab-ai-index" --context-only "$@"
