#!/usr/bin/env bash set -euo pipefail # CODEX_HOME is on fast LOCAL disk; AUTH_PERSIST_DIR is the /data bucket where the # login persists across restarts. Seed the local home from the bucket on boot. # Default to /tmp (always writable on HF Spaces) if the env var is missing. : "${CODEX_HOME:=/tmp/.codex}" export CODEX_HOME AUTH_PERSIST_DIR="${AUTH_PERSIST_DIR:-/data/.codex}" mkdir -p "${CODEX_HOME}" "${AUTH_PERSIST_DIR}" /data/sessions # Global safety rules (refresh every boot). cp -f /app/AGENTS.global.md "${CODEX_HOME}/AGENTS.md" # Seed auth.json from the persistent bucket into the local CODEX_HOME. if [ -f "${AUTH_PERSIST_DIR}/auth.json" ]; then cp -f "${AUTH_PERSIST_DIR}/auth.json" "${CODEX_HOME}/auth.json" echo "[start] Seeded auth.json from ${AUTH_PERSIST_DIR} — Codex login ready." else echo "[start] WARNING: ${AUTH_PERSIST_DIR}/auth.json is MISSING." echo "[start] Run 'codex login' locally and upload ~/.codex/auth.json there." echo "[start] The API returns 503 until it exists." fi # Write the config deterministically: ChatGPT auth + native web search enabled. cat > "${CODEX_HOME}/config.toml" <<'EOF' preferred_auth_method = "chatgpt" [tools] web_search = true EOF exec uvicorn app:app --host 0.0.0.0 --port "${PORT:-7860}"