#!/bin/bash # ── CowAgent entrypoint for Hugging Face Spaces ─────────────────────────────── # Reads env vars (set as Secrets in HF Space settings) and writes config.json, # then launches the app on port 7860 (required by HF Spaces). set -e cd /app WORKSPACE="${AGENT_WORKSPACE:-/data/cow}" CONFIG_PATH="${WORKSPACE}/config.json" mkdir -p "${WORKSPACE}" # ── Build config.json from environment variables ────────────────────────────── python3 - <, after console.css # so our !important rules load last and win on cascade order too. sed -i "s|| ${MOBILE_CSS_LINK}\n|" "${CHAT_HTML}" echo "[entrypoint] Mobile CSS patch link injected into chat.html" else echo "[entrypoint] Mobile CSS patch link already present, file refreshed" fi else echo "[entrypoint] WARNING: ${CHAT_HTML} not found, mobile CSS patch skipped" fi # Make sure mobile-fix.css also gets the same cache-busting query param as # console.css/console.js, so browsers never serve a stale cached copy after # we update the file on a redeploy. if [ -f "${WEB_CHANNEL_PY}" ] && ! grep -q "mobile-fix.css'," "${WEB_CHANNEL_PY}"; then python3 - <<'PYEOF' path = "/app/channel/web/web_channel.py" with open(path, "r", encoding="utf-8") as f: content = f.read() marker = "html = html.replace('assets/css/console.css', f'assets/css/console.css?v={cache_bust}')" addition = "\n html = html.replace('assets/css/mobile-fix.css', f'assets/css/mobile-fix.css?v={cache_bust}')" if marker in content and "mobile-fix.css', f'assets/css/mobile-fix.css" not in content: content = content.replace(marker, marker + addition, 1) with open(path, "w", encoding="utf-8") as f: f.write(content) print("[entrypoint] Cache-busting patch applied to web_channel.py") else: print("[entrypoint] Cache-busting patch not applicable or already present") PYEOF fi # ── Start CowAgent ──────────────────────────────────────────────────────────── echo "[entrypoint] Starting CowAgent..." exec python3 /app/app.py