import os import sys """ FastAPI application for the Git Commit Reviewer Environment. This module creates an HTTP server that exposes the GitCommitReviewerEnvironment over HTTP and WebSocket endpoints, compatible with EnvClient. Endpoints: - POST /reset: Reset the environment - POST /step: Execute an action - GET /state: Get current environment state - GET /schema: Get action/observation schemas - WS /ws: WebSocket endpoint for persistent sessions Usage: # Development (with auto-reload): uvicorn server.app:app --reload --host 0.0.0.0 --port 7860 # Production: uvicorn server.app:app --host 0.0.0.0 --port 7860 --workers 4 # Or run directly: python -m server.app """ try: from openenv.core.env_server.http_server import create_app from fastapi.staticfiles import StaticFiles from fastapi.responses import FileResponse except Exception as e: # pragma: no cover raise ImportError( "openenv and fastapi are required for the web interface. Install dependencies with '\n uv sync\n'" ) from e try: from ..models import GitCommitReviewerAction, GitCommitReviewerObservation from .git_commit_reviewer_environment import GitCommitReviewerEnvironment except (ImportError, ValueError): try: from models import GitCommitReviewerAction, GitCommitReviewerObservation from server.git_commit_reviewer_environment import GitCommitReviewerEnvironment except ImportError: sys.path.append(os.getcwd()) from models import GitCommitReviewerAction, GitCommitReviewerObservation from server.git_commit_reviewer_environment import GitCommitReviewerEnvironment # Create the app with web interface and README integration app = create_app( GitCommitReviewerEnvironment, GitCommitReviewerAction, GitCommitReviewerObservation, env_name="git_commit_reviewer", max_concurrent_envs=10, # increased to allow automated sequential runs ) # Path to our UI assets static_dir = os.path.join(os.path.dirname(__file__), "static") if os.path.exists(static_dir): app.mount("/static", StaticFiles(directory=static_dir), name="static") @app.get("/", response_class=FileResponse) async def root(): """Serves the premium interactive dashboard.""" index_path = os.path.join(static_dir, "index.html") if os.path.exists(index_path): return FileResponse(index_path) return { "message": "Git Commit Reviewer Environment is running!", "status": "healthy", "docs": "/docs" } @app.get("/health") async def health(): return {"status": "ok"} @app.get("/debug") async def debug_info(): """Diagnostic endpoint to verify session persistence.""" try: from server.git_commit_reviewer_environment import GLOBAL_SESSION_STORE return { "active_sessions": len(GLOBAL_SESSION_STORE), "sessions": {k: {"steps": v["step_count"], "rewards": v["total_rewards"]} for k, v in GLOBAL_SESSION_STORE.items()} } except Exception as e: return {"error": str(e)} def main(host: str = "0.0.0.0", port: int = 7860): """ Entry point for direct execution via uv run or python -m. This function enables running the server without Docker: uv run --project . server uv run --project . server --port 7861 python -m git_commit_reviewer.server.app Args: host: Host address to bind to (default: "0.0.0.0") port: Port number to listen on (default: 7860) For production deployments, consider using uvicorn directly with multiple workers: uvicorn git_commit_reviewer.server.app:app --workers 4 """ import uvicorn uvicorn.run(app, host=host, port=port) if __name__ == '__main__': main()