#!/usr/bin/env bash
# gnosislab — repo-checkout shim for the Python lifecycle CLI.
#
# The lifecycle implementation lives in src/gnosislab/cli.py (the
# `gnosislab` console script). This file exists only so a source
# checkout can run `./gnosislab` — and for the `labloop` transition
# symlink. Every command delegates; nothing is reimplemented here.
#
# `run-ml-*.sh` stay the foreground launchers (Ctrl-C, interactive
# debugging); gnosislab is the lifecycle layer on top.

set -euo pipefail

self=$(readlink -f "$0")
cd "$(dirname "$self")"

if [ "$(basename "$0")" = "labloop" ]; then
    echo "note: 'labloop' is being renamed to 'gnosislab' — this symlink will be removed after the transition" >&2
fi

# In the repo checkout, uv runs the CLI straight from source.
if command -v uv >/dev/null 2>&1 && [ -f pyproject.toml ]; then
    exec uv run --quiet gnosislab "$@"
fi

# Fallback: an installed gnosislab on PATH — unless it resolves to
# this very script (a PATH entry pointing here would recurse).
if command -v gnosislab >/dev/null 2>&1 \
    && [ "$(readlink -f "$(command -v gnosislab)")" != "$self" ]; then
    exec gnosislab "$@"
fi

echo "gnosislab: no Python CLI available — install uv (for this checkout)" >&2
echo "           or 'pip install gnosislab'" >&2
exit 2
