#!/usr/bin/env bash
#
# harness-init — the harness's harness-init entry point.
#
# SELF-CONTAINED BY CONSTRUCTION: it resolves its own real path and reaches
# the implementation RELATIVELY, so this tree can be copied, rendered from a
# template, or installed anywhere without an absolute path following it. The
# symlink resolution matters — a `bin/` on $PATH is usually reached through
# one, and `dirname $0` on a symlink points at the link, not the tool.
#
# Doc: docs/configuring-the-harness.md
set -euo pipefail

self="${BASH_SOURCE[0]}"
while [ -L "$self" ]; do
  target="$(readlink "$self")"
  case "$target" in
    /*) self="$target" ;;
    *)  self="$(cd "$(dirname "$self")" && pwd)/$target" ;;
  esac
done
here="$(cd "$(dirname "$self")" && pwd)"
impl="$here/../scripts/harness-init.py"

if [ ! -f "$impl" ]; then
  echo "harness-init: FAIL — implementation missing: $impl" >&2
  echo "harness-init: this install is incomplete; bin/ and scripts/ ship together" >&2
  exit 1
fi

exec python3 "$impl" "$@"
