#!/usr/bin/env bash
# frozen_string_literal: false

# SPDX-License-Identifier: GPL-3.0-only
# Copyright (C) 2026 Hugo Antonio Sepulveda Manriquez / NeatNerds

# NeatNerds Code Companion - Development wrapper
# This script ensures nncc works from any directory by pinning the Ruby
# version and Bundler environment to the project's configuration.
#
# Usage: symlink this file from ~/.local/bin/raictlctl
#   ln -sf "$(pwd)/bin/rai-dev" ~/.local/bin/raictlctl
set -euo pipefail

# Resolve the real path of this script (follows symlinks)
REAL_PATH="$(readlink -f "${BASH_SOURCE[0]}")"
RAI_ROOT="$(cd "$(dirname "$REAL_PATH")/.." && pwd)"

# Pin Ruby version from project's .ruby-version (unless overridden)
export RBENV_VERSION="${RBENV_VERSION:-$(cat "$RAI_ROOT/.ruby-version")}"

# Pin Bundler to this project's Gemfile
export BUNDLE_GEMFILE="${BUNDLE_GEMFILE:-$RAI_ROOT/Gemfile}"

exec ruby "$RAI_ROOT/bin/raictl" "$@"
