#!/usr/bin/env sh
# Wrapper so the question tree skills can call tree_check from an INSTALLED plugin.
# See bin/catalog_io and docs/adr/0006-plugin-execution-model.md.
# Read-only: unlike the other wrappers it creates no directory.
set -e

proj="${CLAUDE_PROJECT_DIR:-$PWD}"
# Claude Code puts bin/ on the Bash tool's PATH but does not export CLAUDE_PLUGIN_ROOT
# there, so fall back to this script's own plugin (bin/ sits directly under the root).
cd "${CLAUDE_PLUGIN_ROOT:-$(dirname "$0")/..}"

# Exit 2, not 1: for this command 1 means "violations found".
[ -d "$proj" ] || { echo "tree_check: project dir '$proj' does not exist" >&2; exit 2; }
export INSIGHT_BASE_DIR="$proj/.insight"
case "$INSIGHT_BASE_DIR" in
  */.insight) ;;
  *) echo "tree_check: refusing base '$INSIGHT_BASE_DIR' (must end in /.insight)" >&2; exit 2;;
esac

if [ -n "${CLAUDE_PLUGIN_DATA:-}" ]; then
  export UV_PROJECT_ENVIRONMENT="$CLAUDE_PLUGIN_DATA/uv-venv"
fi

exec uv run python -m skills._shared.tree_check "$@"
