#!/usr/bin/env bash
# Plugin entry shim — delegates to the installed `tokenkeeper` binary.
#
# The Claude Code plugin bundle ships this thin wrapper so the plugin's hook
# bodies can invoke `tokenkeeper <subcommand>` regardless of where the user
# installed the actual binary. Run scripts/install.sh from a checkout to
# build and install it.
set -euo pipefail

self_path="${BASH_SOURCE[0]}"
self_real="$(cd "$(dirname "$self_path")" && pwd)/$(basename "$self_path")"

if command -v tokenkeeper >/dev/null 2>&1; then
    real="$(command -v tokenkeeper)"
    real_abs="$(cd "$(dirname "$real")" && pwd)/$(basename "$real")"
    if [ "$real_abs" != "$self_real" ]; then
        exec "$real" "$@"
    fi
fi

echo "tokenkeeper: no installed binary on PATH. Run scripts/install.sh." >&2
exit 127
