#!/usr/bin/env bash
# agentloop gate -- one command, and the exit code IS the verdict.
#
#   0  every leg passed
#   1  a graded fault (a leg reported one)
#   2  could not grade (no python3, the package will not import, ...)
#
# Resolves its own directory, so the copy in a clone grades that clone.
#
# The last line is `exit "$rc"`, not a constant: a gate whose exit code is a
# literal cannot fail, and a gate that cannot fail is not evidence.
set -u

here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

py=""
if command -v python3 >/dev/null 2>&1; then
    py="python3"
fi

if [ -z "$py" ]; then
    echo "COULD NOT GRADE: no python3 on PATH"
    rc=2
else
    "$py" "$here/check.py"
    rc=$?
fi

exit "$rc"
