""" AI Programmer Agent - Main Entry Point Runs on HuggingFace Space (Docker) with an integrated Health Check Server """ import asyncio import logging import os from aiohttp import web from dotenv import load_dotenv from core.bot import AICoderBot load_dotenv() logging.basicConfig( level=logging.INFO, format="%(asctime)s [%(levelname)s] %(name)s: %(message)s" ) log = logging.getLogger("main") async def handle_health_check(request): return web.Response(text="🟢 AI Programming Agent Status: ACTIVE & LISTENING") async def start_health_server(): app = web.Application() app.router.add_get("/", handle_health_check) port = int(os.getenv("PORT", "7860")) runner = web.AppRunner(app) await runner.setup() site = web.TCPSite(runner, "0.0.0.0", port) await site.start() log.info(f"Health check server successfully bound to port {port}") async def main(): log.info("Starting AI Programmer Agent...") required = ["TELEGRAM_BOT_TOKEN", "TELEGRAM_OWNER_ID"] missing = [k for k in required if not os.getenv(k)] if missing: raise RuntimeError(f"Missing env vars: {missing}") await start_health_server() bot = AICoderBot() await bot.start() if __name__ == "__main__": try: asyncio.run(main()) except (KeyboardInterrupt, SystemExit): log.info("Agent shut down cleanly.")