#!/bin/sh
# What the harness hooks call: tools/trace_ingest.py, run by the venv's Python.
#
#   tools/trace-hook --source claude-code --event prompt.submitted
#
# A hook command is a fixed string in a harness's config file (.claude/settings.json,
# .github/hooks/wiki-trace.json, .vibe/hooks.toml) and cannot read
# .wikitool-tools.json. The venv's Python can stand in for the recorded one: the
# preflight creates it from exactly that interpreter, and it sits at a fixed
# place - only its layout differs (bin/ everywhere but Windows, Scripts\ there,
# which is also what Git Bash sees). trace_ingest.py uses the standard library
# only, so the venv adds nothing it needs; it just makes the interpreter findable.
#
# Relying on the script's own shebang (`python3`) is what this replaces: in
# Git Bash on Windows, `python3` is the Microsoft Store alias.
#
# No venv yet - before the preflight has run - means no trace, silently. A hook
# must never fail the call it observes.
DIR=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P) || exit 0
if [ -x "$DIR/.venv/bin/python" ]; then
  exec "$DIR/.venv/bin/python" "$DIR/trace_ingest.py" "$@"
elif [ -f "$DIR/.venv/Scripts/python.exe" ]; then
  exec "$DIR/.venv/Scripts/python.exe" "$DIR/trace_ingest.py" "$@"
fi
exit 0
