#!/bin/bash
# Codex launcher (/usr/local/bin/codex). Every entrypoint, including exec and
# direct process spawn, resolves this machine's sign-in mode
# (/etc/cmux/agent-auth.sh) before starting the pinned executable: team mode
# keeps the CodeRouter provider agent-config.sh generated, own mode starts
# codex on its built-in provider so `codex login` is what it uses.
# `cr use own|team` switches it; a switch applies to the next launch. No
# errexit: a HOME the config generators cannot write must still start codex.
if [ "$#" -eq 1 ]; then
  case "$1" in --version|-V|--help|-h) exec /usr/local/libexec/cmux-codex-real "$@" ;; esac
fi
. /etc/cmux/agent-config.sh
. /etc/cmux/agent-auth.sh
cmux_codex_apply_auth_mode
if [ "$cmux_codex_own_provider" = 1 ]; then
  # Ahead of the caller's arguments, so a -c the caller passes still wins.
  exec /usr/local/libexec/cmux-codex-real -c 'model_provider="openai"' "$@"
fi
exec /usr/local/libexec/cmux-codex-real "$@"
