# ๐Ÿง  CodeGuard Environment ## ๐Ÿ“Œ Overview CodeGuard is a deterministic RL-style environment for evaluating code-fixing agents. It simulates tasks like lint fixing, vulnerability patching, and structural refactoring with strict reward and grading rules. --- ## ๐Ÿงฉ Environment Schema ### State ```json { "score": "float", "history": [ { "step": "int", "action": "str", "reward": "float" } ] } ``` ### Action - Type: `str` - Constraints: - Non-empty - Max length: 1000 chars ### Reward - Range: `[-2.5, 1.0]` - Components: - Task score (grader) - `-0.02` step penalty - `-2.0` destructive penalty ## ๐Ÿงช Tasks & Difficulty ### ๐ŸŸข Easy โ€” Lint Fix - Goal: Fix syntax errors - Grader: `ast.parse()` - Output: `0.0` or `1.0` ### ๐ŸŸก Medium โ€” Vulnerability Patch - Goal: Remove unsafe calls (`eval`, `exec`, etc.) - Checks: - Unsafe calls removed - Function structure preserved - Output: `0.0 โ€“ 1.0` ### ๐Ÿ”ด Hard โ€” Refactor + Type Hints - Goal: Improve structure + add typing - Checks: - Structural preservation - Type annotations present - Output: `0.0 โ€“ 1.0` ## โš™๏ธ Setup & Usage ### Install Dependencies ```bash pip install -r requirements.txt ``` ### Run API Server ```bash uvicorn src.env:app --host 0.0.0.0 --port 7860 ``` ### Run Inference Loop ```bash export HF_TOKEN=your_token python inference.py ``` ## ๐Ÿ“Š Baseline Scores (Mock) | Task | Score | |---|---:| | Easy | 0.88 | | Medium | 0.71 | | Hard | 0.54 | Model: `gpt-4.1-mini` ## ๐Ÿงช Testing Run validation tests: ```bash pytest tests/ ``` ## ๐Ÿ“Œ Notes - All graders are deterministic & stateless - Execution time per grading <50ms - No randomness in reward or evaluation