#!/usr/bin/env bash
# cielara-code shell integration
# Source this from ~/.zshrc or ~/.bashrc:
#   source "$(cielara shell-integration-path 2>/dev/null)" 2>/dev/null
#
# Wraps codex, agy, and cursor to auto-enable cielara-code in git repos
# before launching the tool. The auto-enable is silent and non-blocking.

if ! command -v cielara-code >/dev/null 2>&1; then
  return 0 2>/dev/null || exit 0
fi

_cielara_auto_enable() {
  cielara-code auto-enable </dev/null >/dev/null 2>&1 &
  disown 2>/dev/null || true
}

for _cielara_cmd in codex agy cursor; do
  if command -v "$_cielara_cmd" >/dev/null 2>&1; then
    eval "${_cielara_cmd}() { _cielara_auto_enable; command ${_cielara_cmd} \"\$@\"; }"
  fi
done
unset _cielara_cmd
