#!/usr/bin/env bash
set -euo pipefail

export PATH="${HOME}/.local/bin:/usr/local/bin:/usr/bin:/bin:${PATH:-}"
export HEADROOM_CONTEXT_TOOL="rtk"

if ! command -v headroom > /dev/null 2>&1; then
    echo "Headroom is unavailable; launching Codex directly." >&2
    exec codex "$@"
fi

if [ "$#" -eq 0 ]; then
    exec headroom wrap codex
fi
exec headroom wrap codex -- "$@"
