File size: 1,703 Bytes
a5c9fd4 c103bfa a5c9fd4 c103bfa a5c9fd4 c103bfa a5c9fd4 c103bfa a5c9fd4 c103bfa a5c9fd4 c103bfa a5c9fd4 c103bfa a5c9fd4 c103bfa a5c9fd4 c103bfa a5c9fd4 c103bfa a5c9fd4 c103bfa a5c9fd4 c103bfa a5c9fd4 c103bfa a5c9fd4 c103bfa a5c9fd4 c103bfa a5c9fd4 c103bfa a5c9fd4 c103bfa a5c9fd4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | # π§ 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
|