#!/bin/sh
# Copyright (c) 2026 Jiaxing Hu <gahing@gahingwoo.com>
# SPDX-License-Identifier: GPL-2.0
# `charsiu show [MODEL]`
#
# THE POINT OF THIS COMMAND IS THE VERDICT. A gguf's name lies in both
# directions, measured: ...-Q4_0_4_4.gguf is type 31 in 210 tensors, a Q4_0
# repacked for ARM dotprod that passes any name test, and ...-Q6_K_L.gguf is
# perfectly runnable although the suffix looks exotic. Only the contents decide,
# so this reads them with the runtime's own parser.
set -eu
CHARSIU_HERE=$(dirname "$0")
for _l in ${CHARSIU_LIB:+"$CHARSIU_LIB/charsiu-lib.sh"} \
	  "$CHARSIU_HERE/charsiu-lib.sh" \
	  "$CHARSIU_HERE/../scripts/charsiu-lib.sh" \
	  "$CHARSIU_HERE/../../opt/charsiu/charsiu-lib.sh" \
	  /opt/charsiu/charsiu-lib.sh; do
	[ -r "$_l" ] && { . "$_l"; break; }
done
command -v ini_get >/dev/null 2>&1 \
	|| { echo "$(basename "$0"): charsiu-lib.sh not found" >&2; exit 1; }

M="${1:-}"
[ -n "$M" ] || M=$(current_model)
[ -n "$M" ] || { echo "charsiu show: no model set and none named" >&2; exit 2; }
M=$(resolve_model "$M")
[ -n "$M" ] || { echo "charsiu show: no such model: ${1:-$(current_model)}" >&2; exit 2; }

R=$(find_bin charsiu_run);   [ -n "$R" ] && "$R" "$M" --info 2>/dev/null
C=$(find_bin charsiu_check)
if [ -n "$C" ]; then
	echo
	"$C" "$M"
	exit $?
fi
exit 0
