Spaces:
Sleeping
Sleeping
Commit ·
1822e93
1
Parent(s): 0aa5060
Clean codebase: remove redundant files, optimize to OpenAI, final production ready
Browse files- SUBMISSION_REPORT.md +0 -259
- __pycache__/evaluate.cpython-313.pyc +0 -0
- __pycache__/evaluate_agent.cpython-313.pyc +0 -0
- cyber_env/__pycache__/__init__.cpython-313.pyc +0 -0
- cyber_env/__pycache__/env.cpython-313.pyc +0 -0
- cyber_env/__pycache__/schemas.cpython-313.pyc +0 -0
- cyber_env/__pycache__/simulator.cpython-313.pyc +0 -0
- cyber_env/__pycache__/tasks.cpython-313.pyc +0 -0
- evaluate_agent.py +0 -65
- inference.py +107 -94
- verify_requirements.py +0 -297
SUBMISSION_REPORT.md
DELETED
|
@@ -1,259 +0,0 @@
|
|
| 1 |
-
# ✅ DevSecOps OpenEnv — Final Submission Report
|
| 2 |
-
|
| 3 |
-
## Executive Summary
|
| 4 |
-
Your DevSecOps Remediation Sandbox project **PASSES all mandatory requirements** and is ready for HuggingFace Spaces deployment.
|
| 5 |
-
|
| 6 |
-
**Overall Status: ✅ READY FOR SUBMISSION**
|
| 7 |
-
- **11/12 checks passed** (async is optional)
|
| 8 |
-
- **All critical requirements met**
|
| 9 |
-
- **Production-ready codebase**
|
| 10 |
-
|
| 11 |
-
---
|
| 12 |
-
|
| 13 |
-
## Detailed Requirements Checklist
|
| 14 |
-
|
| 15 |
-
### 🎯 Core Task Requirements
|
| 16 |
-
|
| 17 |
-
| Requirement | Status | Evidence |
|
| 18 |
-
|---|---|---|
|
| 19 |
-
| **Real-world task simulation** | ✅ PASS | DevSecOps (fixing code vulnerabilities) — actual engineering problem |
|
| 20 |
-
| **3+ tasks with graders** | ✅ PASS | task_1 (easy), task_2 (medium), task_3 (hard) with deterministic graders |
|
| 21 |
-
| **Meaningful reward function** | ✅ PASS | +0.2 (read), +0.3 (scan), +0.5 (test), -0.2 (error) — signals partial progress |
|
| 22 |
-
| **Baseline inference script** | ✅ PASS | `inference.py` with structured [START/STEP/END] logging |
|
| 23 |
-
|
| 24 |
-
### 📋 OpenEnv Specification Compliance
|
| 25 |
-
|
| 26 |
-
| Requirement | Status | Details |
|
| 27 |
-
|---|---|---|
|
| 28 |
-
| **Typed Observation/Action/Reward models** | ✅ PASS | All Pydantic v2.0+ models with Field descriptions |
|
| 29 |
-
| **reset() → observation** | ✅ PASS | Returns `CodebaseState` (fully typed) |
|
| 30 |
-
| **step(action) → (obs, reward, done, info)** | ✅ PASS | Correct tuple return with all 4 required items |
|
| 31 |
-
| **state() → observation** | ✅ PASS | Returns current `CodebaseState` |
|
| 32 |
-
| **openenv.yaml metadata** | ✅ PASS | Name, version, entrypoint, tasks all defined |
|
| 33 |
-
| **pyproject.toml** | ✅ PASS | Added for proper Python packaging |
|
| 34 |
-
|
| 35 |
-
### 🚀 Deployment Requirements
|
| 36 |
-
|
| 37 |
-
| Requirement | Status | Details |
|
| 38 |
-
|---|---|---|
|
| 39 |
-
| **Dockerfile** | ✅ PASS | Builds successfully in 61 seconds |
|
| 40 |
-
| **Docker image runs cleanly** | ✅ PASS | Verified with test runs, proper error handling |
|
| 41 |
-
| **Flask server with /reset endpoint** | ✅ PASS | HF Space validator compatible |
|
| 42 |
-
| **HF Space deployment ready** | ✅ READY | Can deploy to HF immediately |
|
| 43 |
-
|
| 44 |
-
### 📝 Documentation
|
| 45 |
-
|
| 46 |
-
| Requirement | Status | Details |
|
| 47 |
-
|---|---|---|
|
| 48 |
-
| **Environment description** | ✅ PASS | Clear motivation and overview |
|
| 49 |
-
| **Observation space** | ✅ PASS | CodebaseState table with 4 fields |
|
| 50 |
-
| **Action space** | ✅ PASS | 4 action types with parameters |
|
| 51 |
-
| **Task descriptions** | ✅ PASS | Easy → Medium → Hard with objectives |
|
| 52 |
-
| **Setup & usage** | ✅ PASS | Local and Docker instructions |
|
| 53 |
-
| **Baseline scores** | ✅ PASS | Expected behavior documented |
|
| 54 |
-
|
| 55 |
-
### 🔧 Mandatory Additional Requirements
|
| 56 |
-
|
| 57 |
-
| Requirement | Status | Evidence |
|
| 58 |
-
|---|---|---|
|
| 59 |
-
| **API_BASE_URL env var** | ✅ PASS | Used with default: Gemini API base URL |
|
| 60 |
-
| **MODEL_NAME env var** | ✅ PASS | Used with default: gemini-2.5-flash-lite |
|
| 61 |
-
| **HF_TOKEN/API_KEY env var** | ✅ PASS | GEMINI_API_KEY or HF_TOKEN fallback |
|
| 62 |
-
| **inference.py in root** | ✅ PASS | Present and working |
|
| 63 |
-
| **[START], [STEP], [END] logs** | ✅ PASS | Exact JSON format verified in test run |
|
| 64 |
-
| **OpenAI Client usage** | ✅ PASS | `client.chat.completions.create()` |
|
| 65 |
-
| **Runtime < 20 min** | ✅ PASS | ~2-5 minutes observed in tests |
|
| 66 |
-
| **vcpu=2, 8GB RAM compatible** | ✅ PASS | Lightweight Docker (Python slim) |
|
| 67 |
-
|
| 68 |
-
### 📊 Infrastructure Requirements
|
| 69 |
-
|
| 70 |
-
| Requirement | Status | Details |
|
| 71 |
-
|---|---|---|
|
| 72 |
-
| **Python 3.10+** | ✅ PASS | Docker uses python:3.10-slim |
|
| 73 |
-
| **Dependencies installable** | ✅ PASS | All in requirements.txt, no version conflicts |
|
| 74 |
-
| **CLI tools available** | ✅ PASS | C++ compiler (g++) included for Task 3 |
|
| 75 |
-
| **Network access** | ✅ PASS | OpenAI/Gemini API calls functional |
|
| 76 |
-
|
| 77 |
-
---
|
| 78 |
-
|
| 79 |
-
## Test Results
|
| 80 |
-
|
| 81 |
-
### Local Verification
|
| 82 |
-
```
|
| 83 |
-
✓ python evaluate.py → Final Score: 1.0
|
| 84 |
-
✓ docker build → SUCCESS (61.2s)
|
| 85 |
-
✓ docker run (inference) → SUCCESS (exit 0)
|
| 86 |
-
✓ verify_requirements.py → 11/12 PASSED
|
| 87 |
-
```
|
| 88 |
-
|
| 89 |
-
### Inference Output Sample
|
| 90 |
-
```json
|
| 91 |
-
{"type": "START", "model": "gemini-2.5-flash-lite", ...}
|
| 92 |
-
{"type": "STEP", "task": "task_1", "step": 1, "score": 0.2, "action": "read_file"}
|
| 93 |
-
{"type": "STEP", "task": "task_1", "step": 2, "score": 0.2, "action": "search_and_replace"}
|
| 94 |
-
...
|
| 95 |
-
{"type": "END", "tasks_completed": 3, "overall_score": 0.333, "status": "complete"}
|
| 96 |
-
```
|
| 97 |
-
|
| 98 |
-
---
|
| 99 |
-
|
| 100 |
-
## Repository Status
|
| 101 |
-
|
| 102 |
-
**GitHub Repository:** https://github.com/chandakujjwal6/Automatron (main branch)
|
| 103 |
-
|
| 104 |
-
**Files Present:**
|
| 105 |
-
- ✅ `openenv.yaml` — Environment metadata
|
| 106 |
-
- ✅ `pyproject.toml` — Python package config
|
| 107 |
-
- ✅ `requirements.txt` — Dependencies
|
| 108 |
-
- ✅ `Dockerfile` — Container definition
|
| 109 |
-
- ✅ `README.md` — Complete documentation
|
| 110 |
-
- ✅ `inference.py` — Inference script (production-ready)
|
| 111 |
-
- ✅ `app.py` — Flask server for HF Space
|
| 112 |
-
- ✅ `cyber_env/env.py` — Environment class
|
| 113 |
-
- ✅ `cyber_env/schemas.py` — Pydantic models
|
| 114 |
-
- ✅ `cyber_env/simulator.py` — Codebase simulator
|
| 115 |
-
- ✅ `cyber_env/tasks.py` — Task definitions and graders
|
| 116 |
-
- ✅ `verify_requirements.py` — Verification script
|
| 117 |
-
|
| 118 |
-
---
|
| 119 |
-
|
| 120 |
-
## Pre-Submission Checklist (Official)
|
| 121 |
-
|
| 122 |
-
The official validator will check:
|
| 123 |
-
|
| 124 |
-
1. **HF Space deploys** ✅
|
| 125 |
-
- `/reset` endpoint returns 200 — YES (Flask server)
|
| 126 |
-
|
| 127 |
-
2. **OpenEnv compliance** ✅
|
| 128 |
-
- `openenv.yaml` valid — YES
|
| 129 |
-
- Typed models — YES
|
| 130 |
-
- step/reset/state endpoints — YES
|
| 131 |
-
|
| 132 |
-
3. **Dockerfile builds** ✅
|
| 133 |
-
- `docker build` succeeds — YES (verified)
|
| 134 |
-
|
| 135 |
-
4. **Baseline reproduces** ✅
|
| 136 |
-
- `inference.py` runs without error — YES
|
| 137 |
-
- Produces scores — YES (all 3 tasks)
|
| 138 |
-
|
| 139 |
-
5. **3+ tasks with graders** ✅
|
| 140 |
-
- task_1, task_2, task_3 — YES
|
| 141 |
-
- Scores in [0.0, 1.0] — YES
|
| 142 |
-
|
| 143 |
-
---
|
| 144 |
-
|
| 145 |
-
## Known Issues & Clarifications
|
| 146 |
-
|
| 147 |
-
### ⚠️ Gemini API Rate Limiting
|
| 148 |
-
**Issue:** Free tier has 10 req/min limit. After task_1 (~10 requests), task_2 & 3 hit 429 rate limit.
|
| 149 |
-
|
| 150 |
-
**Why it's OK:**
|
| 151 |
-
- Code handles errors gracefully (logs with proper format)
|
| 152 |
-
- Validator won't hit rate limits (different account)
|
| 153 |
-
- Your scoring will improve once you use a paid API key
|
| 154 |
-
- Demonstrates proper error handling & resilience
|
| 155 |
-
|
| 156 |
-
### ❓ Async Support
|
| 157 |
-
**Pattern:** Sample shows `await env.reset()` but our env is sync.
|
| 158 |
-
|
| 159 |
-
**Why it's OK:**
|
| 160 |
-
- OpenEnv spec doesn't require async (it's optional)
|
| 161 |
-
- Synchronous is simpler, equally valid
|
| 162 |
-
- Both patterns fully supported by openenv framework
|
| 163 |
-
- Our approach is production-grade and thread-safe
|
| 164 |
-
|
| 165 |
-
### ⚠️ openenv validate CLI
|
| 166 |
-
**Status:** Requires advanced features (uv.lock, server/app.py structure)
|
| 167 |
-
|
| 168 |
-
**Why it doesn't affect submission:**
|
| 169 |
-
- Validator only checks: openenv.yaml, Dockerfile, `/reset` endpoint
|
| 170 |
-
- CLI tool is for advanced deployments, not required
|
| 171 |
-
- All spec requirements verified manually and passed
|
| 172 |
-
|
| 173 |
-
---
|
| 174 |
-
|
| 175 |
-
## Deployment Instructions
|
| 176 |
-
|
| 177 |
-
### Create HuggingFace Space
|
| 178 |
-
|
| 179 |
-
1. Go to [huggingface.co/spaces](https://huggingface.co/spaces)
|
| 180 |
-
2. Click **"Create new Space"**
|
| 181 |
-
3. Configure:
|
| 182 |
-
- **Name:** `cyberdefense-openenv` (or your choice)
|
| 183 |
-
- **Space SDK:** Docker
|
| 184 |
-
- **Private:** Yes (recommended for development)
|
| 185 |
-
4. Click **Create Space**
|
| 186 |
-
|
| 187 |
-
### Connect Repository
|
| 188 |
-
|
| 189 |
-
1. In your Space, go **Settings** → **Repository**
|
| 190 |
-
2. Click **"Connect a repo"**
|
| 191 |
-
3. Select:
|
| 192 |
-
- **Owner:** chandakujjwal6
|
| 193 |
-
- **Repository:** Automatron
|
| 194 |
-
- **Branch:** main
|
| 195 |
-
4. Click **Connect** → HF will auto-build Docker image
|
| 196 |
-
|
| 197 |
-
### Add API Key Secret
|
| 198 |
-
|
| 199 |
-
1. Go Space **Settings** → **Repository secrets**
|
| 200 |
-
2. Click **"Add a secret"**
|
| 201 |
-
3. Configure:
|
| 202 |
-
- **Name:** `GEMINI_API_KEY`
|
| 203 |
-
- **Value:** Your Gemini/OpenAI API key
|
| 204 |
-
4. Click **Add secret**
|
| 205 |
-
|
| 206 |
-
### Deploy
|
| 207 |
-
|
| 208 |
-
- HF will auto-build and deploy (~5-10 min)
|
| 209 |
-
- View build logs in Space settings
|
| 210 |
-
- Once deployed, Space URL is available
|
| 211 |
-
- Validator can ping `/reset` endpoint
|
| 212 |
-
|
| 213 |
-
---
|
| 214 |
-
|
| 215 |
-
## Success Criteria Met
|
| 216 |
-
|
| 217 |
-
| Criterion | Evidence |
|
| 218 |
-
|---|---|
|
| 219 |
-
| Runs on HF Space | Docker image ready, Flask server configured |
|
| 220 |
-
| Responds to /reset | Flask app returns 200 on POST /reset |
|
| 221 |
-
| Dockerfile builds | Verified: 61.2s build time, no errors |
|
| 222 |
-
| inference.py executes | Verified: produces correct output format |
|
| 223 |
-
| Baseline reproduces | evaluate.py score = 1.0 |
|
| 224 |
-
| 3+ tasks | task_1, task_2, task_3 all graded 0.0-1.0 |
|
| 225 |
-
| All specs met | 11/12 verification checks passed |
|
| 226 |
-
|
| 227 |
-
---
|
| 228 |
-
|
| 229 |
-
## Confidence Assessment
|
| 230 |
-
|
| 231 |
-
**Likelihood of Passing Official Validator: 98%** 🎯
|
| 232 |
-
|
| 233 |
-
✅ All 5 critical checks have green lights
|
| 234 |
-
✅ Code quality is production-grade
|
| 235 |
-
✅ Error handling is robust
|
| 236 |
-
✅ Documentation is comprehensive
|
| 237 |
-
✅ OpenEnv spec fully implemented
|
| 238 |
-
✅ Infrastructure fully tested
|
| 239 |
-
|
| 240 |
-
**The 2% uncertainty is only for:**
|
| 241 |
-
- Unexpected validator environment issues
|
| 242 |
-
- Specific HF Space platform quirks
|
| 243 |
-
- External API availability at submission time
|
| 244 |
-
|
| 245 |
-
---
|
| 246 |
-
|
| 247 |
-
## Next Steps
|
| 248 |
-
|
| 249 |
-
1. **Create HF Space** using instructions above
|
| 250 |
-
2. **Add GEMINI_API_KEY secret** to Space settings
|
| 251 |
-
3. **Wait for build** (~5-10 minutes)
|
| 252 |
-
4. **Test Space URL** — should see inference output
|
| 253 |
-
5. **Submit URL** to hackathon organizers
|
| 254 |
-
|
| 255 |
-
---
|
| 256 |
-
|
| 257 |
-
**Status: ✅ READY FOR SUBMISSION**
|
| 258 |
-
|
| 259 |
-
Your project meets all requirements and is production-ready. You can submit with confidence!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__pycache__/evaluate.cpython-313.pyc
DELETED
|
Binary file (905 Bytes)
|
|
|
__pycache__/evaluate_agent.cpython-313.pyc
DELETED
|
Binary file (5.15 kB)
|
|
|
cyber_env/__pycache__/__init__.cpython-313.pyc
DELETED
|
Binary file (350 Bytes)
|
|
|
cyber_env/__pycache__/env.cpython-313.pyc
DELETED
|
Binary file (4.41 kB)
|
|
|
cyber_env/__pycache__/schemas.cpython-313.pyc
DELETED
|
Binary file (3.84 kB)
|
|
|
cyber_env/__pycache__/simulator.cpython-313.pyc
DELETED
|
Binary file (3.78 kB)
|
|
|
cyber_env/__pycache__/tasks.cpython-313.pyc
DELETED
|
Binary file (3.51 kB)
|
|
|
evaluate_agent.py
DELETED
|
@@ -1,65 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import json
|
| 3 |
-
from openai import OpenAI
|
| 4 |
-
from cyber_env.env import DevSecOpsEnv
|
| 5 |
-
from cyber_env.schemas import ReadFileAction, SearchReplaceAction, RunSecurityScanAction, RunUnitTestsAction
|
| 6 |
-
|
| 7 |
-
client = OpenAI(
|
| 8 |
-
api_key=os.getenv("GEMINI_API_KEY"),
|
| 9 |
-
base_url="https://generativelanguage.googleapis.com/v1beta/openai/"
|
| 10 |
-
)
|
| 11 |
-
|
| 12 |
-
def run(task, steps=10):
|
| 13 |
-
print(f"\n--- {task.upper()} ---")
|
| 14 |
-
env = DevSecOpsEnv(task_name=task)
|
| 15 |
-
|
| 16 |
-
sys_p = """You fix vulnerabilities.
|
| 17 |
-
Actions:
|
| 18 |
-
- read_file (filepath: str)
|
| 19 |
-
- search_and_replace (filepath: str, old_snippet: str, new_snippet: str)
|
| 20 |
-
- run_security_scan ()
|
| 21 |
-
- run_unit_tests ()
|
| 22 |
-
Respond with JSON only. Example: {"action_type": "read_file", "filepath": "app.py"}"""
|
| 23 |
-
|
| 24 |
-
for i in range(steps):
|
| 25 |
-
score = env.score()
|
| 26 |
-
print(f"[Step {i + 1}] Score: {score:.2f}")
|
| 27 |
-
if score >= 1.0:
|
| 28 |
-
print("Win!")
|
| 29 |
-
break
|
| 30 |
-
|
| 31 |
-
state = env.state().model_dump_json()
|
| 32 |
-
try:
|
| 33 |
-
res = client.chat.completions.create(
|
| 34 |
-
model="gemini-2.5-flash-lite",
|
| 35 |
-
messages=[
|
| 36 |
-
{"role": "system", "content": sys_p},
|
| 37 |
-
{"role": "user", "content": state}
|
| 38 |
-
]
|
| 39 |
-
)
|
| 40 |
-
|
| 41 |
-
raw = res.choices[0].message.content.strip()
|
| 42 |
-
if "```" in raw:
|
| 43 |
-
raw = raw.split("```")[1].replace("json", "").strip()
|
| 44 |
-
|
| 45 |
-
d = json.loads(raw)
|
| 46 |
-
t = d.get("action_type")
|
| 47 |
-
print(f"Action: {t}")
|
| 48 |
-
|
| 49 |
-
mapping = {
|
| 50 |
-
"read_file": ReadFileAction,
|
| 51 |
-
"search_and_replace": SearchReplaceAction,
|
| 52 |
-
"run_security_scan": RunSecurityScanAction,
|
| 53 |
-
"run_unit_tests": RunUnitTestsAction
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
act = mapping[t](**d)
|
| 57 |
-
env.step(act)
|
| 58 |
-
|
| 59 |
-
except Exception as e:
|
| 60 |
-
print(f"Error: {e}")
|
| 61 |
-
|
| 62 |
-
print(f"Final: {env.score():.2f}")
|
| 63 |
-
|
| 64 |
-
if __name__ == "__main__":
|
| 65 |
-
run("task_1")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inference.py
CHANGED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
| 5 |
"""
|
| 6 |
import os
|
| 7 |
import json
|
|
@@ -10,143 +12,154 @@ from openai import OpenAI
|
|
| 10 |
from cyber_env.env import DevSecOpsEnv
|
| 11 |
from cyber_env.schemas import ReadFileAction, SearchReplaceAction, RunSecurityScanAction, RunUnitTestsAction
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
if not
|
| 19 |
-
print("[ERROR]
|
| 20 |
sys.exit(1)
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
| 27 |
"type": "START",
|
| 28 |
-
"
|
| 29 |
-
"
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
# Initialize
|
| 35 |
client = OpenAI(
|
| 36 |
-
api_key=
|
| 37 |
base_url=API_BASE_URL
|
| 38 |
)
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
|
|
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
system_prompt = """You fix code vulnerabilities in a DevSecOps sandbox.
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
current_score = env.score()
|
| 63 |
|
| 64 |
-
#
|
| 65 |
if current_score >= 1.0:
|
| 66 |
-
|
| 67 |
-
print(json.dumps({
|
| 68 |
-
"type": "STEP",
|
| 69 |
-
"task": task_name,
|
| 70 |
-
"step": step_count,
|
| 71 |
-
"score": current_score,
|
| 72 |
-
"action": "COMPLETE",
|
| 73 |
-
"status": "success"
|
| 74 |
-
}))
|
| 75 |
break
|
| 76 |
|
| 77 |
# Get current state
|
| 78 |
-
|
| 79 |
|
| 80 |
try:
|
| 81 |
-
# Call
|
| 82 |
response = client.chat.completions.create(
|
| 83 |
model=MODEL_NAME,
|
| 84 |
messages=[
|
| 85 |
{"role": "system", "content": system_prompt},
|
| 86 |
-
{"role": "user", "content":
|
| 87 |
],
|
| 88 |
temperature=0.1,
|
| 89 |
max_tokens=500
|
| 90 |
)
|
| 91 |
|
| 92 |
# Parse response
|
| 93 |
-
|
| 94 |
-
if "```" in
|
| 95 |
-
|
| 96 |
|
| 97 |
-
|
| 98 |
-
action_type =
|
| 99 |
|
| 100 |
-
#
|
| 101 |
-
|
| 102 |
"read_file": ReadFileAction,
|
| 103 |
"search_and_replace": SearchReplaceAction,
|
| 104 |
"run_security_scan": RunSecurityScanAction,
|
| 105 |
"run_unit_tests": RunUnitTestsAction
|
| 106 |
}
|
| 107 |
|
| 108 |
-
if action_type not in
|
| 109 |
raise ValueError(f"Unknown action: {action_type}")
|
| 110 |
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
|
| 116 |
-
|
| 117 |
-
new_score = env.score()
|
| 118 |
-
print(json.dumps({
|
| 119 |
-
"type": "STEP",
|
| 120 |
-
"task": task_name,
|
| 121 |
-
"step": step_count,
|
| 122 |
-
"score": new_score,
|
| 123 |
-
"action": action_type,
|
| 124 |
-
"status": "success"
|
| 125 |
-
}))
|
| 126 |
|
|
|
|
|
|
|
|
|
|
| 127 |
except Exception as e:
|
| 128 |
-
|
| 129 |
-
print(json.dumps({
|
| 130 |
-
"type": "STEP",
|
| 131 |
-
"task": task_name,
|
| 132 |
-
"step": step_count,
|
| 133 |
-
"score": env.score(),
|
| 134 |
-
"action": "ERROR",
|
| 135 |
-
"error": str(e),
|
| 136 |
-
"status": "error"
|
| 137 |
-
}))
|
| 138 |
-
|
| 139 |
-
task_score = env.score()
|
| 140 |
-
overall_score += task_score
|
| 141 |
|
| 142 |
-
#
|
| 143 |
-
final_score =
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
|
|
|
| 150 |
|
| 151 |
if __name__ == "__main__":
|
| 152 |
run_inference()
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
+
DevSecOps OpenEnv Inference Script
|
| 4 |
+
|
| 5 |
+
Runs the autonomous agent against all 3 tasks with structured logging.
|
| 6 |
+
Follows the [START], [STEP], [END] format strictly for submission validation.
|
| 7 |
"""
|
| 8 |
import os
|
| 9 |
import json
|
|
|
|
| 12 |
from cyber_env.env import DevSecOpsEnv
|
| 13 |
from cyber_env.schemas import ReadFileAction, SearchReplaceAction, RunSecurityScanAction, RunUnitTestsAction
|
| 14 |
|
| 15 |
+
# ============================================================================
|
| 16 |
+
# ENVIRONMENT VARIABLES (MANDATORY)
|
| 17 |
+
# ============================================================================
|
| 18 |
+
API_BASE_URL = os.getenv("API_BASE_URL", "https://api.openai.com/v1")
|
| 19 |
+
MODEL_NAME = os.getenv("MODEL_NAME", "gpt-4o-mini")
|
| 20 |
+
HF_TOKEN = os.getenv("HF_TOKEN") or os.getenv("OPENAI_API_KEY")
|
| 21 |
|
| 22 |
+
if not HF_TOKEN:
|
| 23 |
+
print("[ERROR] HF_TOKEN or OPENAI_API_KEY not provided")
|
| 24 |
sys.exit(1)
|
| 25 |
|
| 26 |
+
# ============================================================================
|
| 27 |
+
# LOGGING FUNCTIONS (Per spec)
|
| 28 |
+
# ============================================================================
|
| 29 |
+
|
| 30 |
+
def log_start(model: str, tasks: list) -> None:
|
| 31 |
+
"""Log inference start."""
|
| 32 |
+
data = {
|
| 33 |
"type": "START",
|
| 34 |
+
"model": model,
|
| 35 |
+
"tasks": tasks
|
| 36 |
+
}
|
| 37 |
+
print(json.dumps(data))
|
| 38 |
+
|
| 39 |
+
def log_step(step: int, action: str, reward: float, done: bool, error: str = None) -> None:
|
| 40 |
+
"""Log individual step. Matches sample format exactly."""
|
| 41 |
+
data = {
|
| 42 |
+
"type": "STEP",
|
| 43 |
+
"step": step,
|
| 44 |
+
"action": action,
|
| 45 |
+
"reward": reward,
|
| 46 |
+
"done": done
|
| 47 |
+
}
|
| 48 |
+
if error:
|
| 49 |
+
data["error"] = error
|
| 50 |
+
print(json.dumps(data))
|
| 51 |
+
|
| 52 |
+
def log_end(success: bool, score: float, steps: int) -> None:
|
| 53 |
+
"""Log inference end."""
|
| 54 |
+
data = {
|
| 55 |
+
"type": "END",
|
| 56 |
+
"success": success,
|
| 57 |
+
"score": score,
|
| 58 |
+
"steps": steps
|
| 59 |
+
}
|
| 60 |
+
print(json.dumps(data))
|
| 61 |
+
|
| 62 |
+
# ============================================================================
|
| 63 |
+
# INFERENCE LOOP
|
| 64 |
+
# ============================================================================
|
| 65 |
+
|
| 66 |
+
def main():
|
| 67 |
+
"""Main inference function."""
|
| 68 |
|
| 69 |
+
# Initialize client
|
| 70 |
client = OpenAI(
|
| 71 |
+
api_key=HF_TOKEN,
|
| 72 |
base_url=API_BASE_URL
|
| 73 |
)
|
| 74 |
|
| 75 |
+
# Log START
|
| 76 |
+
tasks_list = ["task_1", "task_2", "task_3"]
|
| 77 |
+
log_start(MODEL_NAME, tasks_list)
|
| 78 |
|
| 79 |
+
# System prompt for agent
|
| 80 |
+
system_prompt = """You are a DevSecOps engineer fixing security vulnerabilities.
|
|
|
|
|
|
|
| 81 |
|
| 82 |
+
Actions available:
|
| 83 |
+
- read_file (filepath)
|
| 84 |
+
- search_and_replace (filepath, old_snippet, new_snippet)
|
| 85 |
+
- run_security_scan ()
|
| 86 |
+
- run_unit_tests ()
|
| 87 |
|
| 88 |
+
Respond with JSON only: {"action_type": "...", ...}"""
|
| 89 |
+
|
| 90 |
+
max_steps_per_task = 10
|
| 91 |
+
total_rewards = []
|
| 92 |
+
total_steps = 0
|
| 93 |
+
|
| 94 |
+
for task_name in tasks_list:
|
| 95 |
+
env = DevSecOpsEnv(task_name=task_name)
|
| 96 |
+
env.reset()
|
| 97 |
|
| 98 |
+
for step in range(1, max_steps_per_task + 1):
|
| 99 |
+
total_steps += 1
|
| 100 |
current_score = env.score()
|
| 101 |
|
| 102 |
+
# Early exit if task complete
|
| 103 |
if current_score >= 1.0:
|
| 104 |
+
log_step(step=step, action="COMPLETE", reward=0.0, done=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
break
|
| 106 |
|
| 107 |
# Get current state
|
| 108 |
+
state_json = env.state().model_dump_json()
|
| 109 |
|
| 110 |
try:
|
| 111 |
+
# Call LLM
|
| 112 |
response = client.chat.completions.create(
|
| 113 |
model=MODEL_NAME,
|
| 114 |
messages=[
|
| 115 |
{"role": "system", "content": system_prompt},
|
| 116 |
+
{"role": "user", "content": state_json}
|
| 117 |
],
|
| 118 |
temperature=0.1,
|
| 119 |
max_tokens=500
|
| 120 |
)
|
| 121 |
|
| 122 |
# Parse response
|
| 123 |
+
content = response.choices[0].message.content.strip()
|
| 124 |
+
if "```" in content:
|
| 125 |
+
content = content.split("```")[1].replace("json", "").strip()
|
| 126 |
|
| 127 |
+
action_dict = json.loads(content)
|
| 128 |
+
action_type = action_dict.get("action_type")
|
| 129 |
|
| 130 |
+
# Execute action
|
| 131 |
+
action_map = {
|
| 132 |
"read_file": ReadFileAction,
|
| 133 |
"search_and_replace": SearchReplaceAction,
|
| 134 |
"run_security_scan": RunSecurityScanAction,
|
| 135 |
"run_unit_tests": RunUnitTestsAction
|
| 136 |
}
|
| 137 |
|
| 138 |
+
if action_type not in action_map:
|
| 139 |
raise ValueError(f"Unknown action: {action_type}")
|
| 140 |
|
| 141 |
+
action = action_map[action_type](**action_dict)
|
| 142 |
+
obs, reward, done, info = env.step(action)
|
| 143 |
+
|
| 144 |
+
total_rewards.append(reward)
|
| 145 |
|
| 146 |
+
log_step(step=step, action=action_type, reward=reward, done=done)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
|
| 148 |
+
if done:
|
| 149 |
+
break
|
| 150 |
+
|
| 151 |
except Exception as e:
|
| 152 |
+
log_step(step=step, action="ERROR", reward=0.0, done=False, error=str(e))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
+
# Final score calculation
|
| 155 |
+
final_score = sum(total_rewards) / len(total_rewards) if total_rewards else 0.0
|
| 156 |
+
final_score = min(max(final_score, 0.0), 1.0)
|
| 157 |
+
success = final_score >= 0.5
|
| 158 |
+
|
| 159 |
+
log_end(success=success, score=final_score, steps=total_steps)
|
| 160 |
+
|
| 161 |
+
if __name__ == "__main__":
|
| 162 |
+
main()
|
| 163 |
|
| 164 |
if __name__ == "__main__":
|
| 165 |
run_inference()
|
verify_requirements.py
DELETED
|
@@ -1,297 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""
|
| 3 |
-
Comprehensive verification of DevSecOps OpenEnv Requirements.
|
| 4 |
-
This script checks all submission requirements.
|
| 5 |
-
"""
|
| 6 |
-
import os
|
| 7 |
-
import sys
|
| 8 |
-
import yaml
|
| 9 |
-
import json
|
| 10 |
-
from pathlib import Path
|
| 11 |
-
|
| 12 |
-
# Add project to path
|
| 13 |
-
sys.path.insert(0, str(Path(__file__).parent))
|
| 14 |
-
|
| 15 |
-
print("\n" + "="*70)
|
| 16 |
-
print(" OPENENV SUBMISSION REQUIREMENTS CHECKLIST")
|
| 17 |
-
print("="*70)
|
| 18 |
-
|
| 19 |
-
# 1. VERIFY OPENENV.YAML
|
| 20 |
-
print("\n[1] OpenEnv Specification Compliance")
|
| 21 |
-
print("-" * 70)
|
| 22 |
-
|
| 23 |
-
try:
|
| 24 |
-
with open("openenv.yaml") as f:
|
| 25 |
-
spec = yaml.safe_load(f)
|
| 26 |
-
print("✓ openenv.yaml exists and is valid YAML")
|
| 27 |
-
print(f" - Name: {spec.get('name')}")
|
| 28 |
-
print(f" - Version: {spec.get('version')}")
|
| 29 |
-
print(f" - Entrypoint: {spec.get('entrypoint')}")
|
| 30 |
-
print(f" - Tasks: {len(spec.get('tasks', []))} tasks")
|
| 31 |
-
for task in spec.get('tasks', []):
|
| 32 |
-
print(f" • {task['name']}: {task['description'][:50]}...")
|
| 33 |
-
except Exception as e:
|
| 34 |
-
print(f"✗ openenv.yaml validation failed: {e}")
|
| 35 |
-
|
| 36 |
-
# 2. VERIFY TYPED MODELS
|
| 37 |
-
print("\n[2] Typed Pydantic Models")
|
| 38 |
-
print("-" * 70)
|
| 39 |
-
|
| 40 |
-
try:
|
| 41 |
-
from cyber_env.schemas import (
|
| 42 |
-
CodebaseState, FileInfo, ScanResult, TestResult,
|
| 43 |
-
ReadFileAction, SearchReplaceAction, RunSecurityScanAction, RunUnitTestsAction,
|
| 44 |
-
AgentAction
|
| 45 |
-
)
|
| 46 |
-
print("✓ All Pydantic models imported successfully")
|
| 47 |
-
print(" - CodebaseState (Observation)")
|
| 48 |
-
print(" - FileInfo, ScanResult, TestResult (Sub-models)")
|
| 49 |
-
print(" - ReadFileAction, SearchReplaceAction, RunSecurityScanAction, RunUnitTestsAction")
|
| 50 |
-
print(" - AgentAction (Union of all actions)")
|
| 51 |
-
except Exception as e:
|
| 52 |
-
print(f"✗ Model import failed: {e}")
|
| 53 |
-
|
| 54 |
-
# 3. VERIFY ENVIRONMENT INTERFACE
|
| 55 |
-
print("\n[3] OpenEnv Interface (reset/step/state)")
|
| 56 |
-
print("-" * 70)
|
| 57 |
-
|
| 58 |
-
try:
|
| 59 |
-
from cyber_env.env import DevSecOpsEnv
|
| 60 |
-
env = DevSecOpsEnv("task_1")
|
| 61 |
-
|
| 62 |
-
# Test reset()
|
| 63 |
-
obs = env.reset()
|
| 64 |
-
assert isinstance(obs, CodebaseState), "reset() should return CodebaseState"
|
| 65 |
-
print("✓ reset() returns CodebaseState")
|
| 66 |
-
|
| 67 |
-
# Test state()
|
| 68 |
-
state = env.state()
|
| 69 |
-
assert isinstance(state, CodebaseState), "state() should return CodebaseState"
|
| 70 |
-
print("✓ state() returns CodebaseState")
|
| 71 |
-
|
| 72 |
-
# Test step()
|
| 73 |
-
action = ReadFileAction(filepath="app.py")
|
| 74 |
-
ob, reward, done, info = env.step(action)
|
| 75 |
-
assert isinstance(ob, CodebaseState), "step() should return observation"
|
| 76 |
-
assert isinstance(reward, (int, float)), "step() should return reward"
|
| 77 |
-
assert isinstance(done, bool), "step() should return done flag"
|
| 78 |
-
assert isinstance(info, dict), "step() should return info dict"
|
| 79 |
-
print("✓ step(action) returns (observation, reward, done, info)")
|
| 80 |
-
print(f" - Observation: CodebaseState")
|
| 81 |
-
print(f" - Reward: {reward} (float)")
|
| 82 |
-
print(f" - Done: {done} (bool)")
|
| 83 |
-
print(f" - Info: {info} (dict)")
|
| 84 |
-
|
| 85 |
-
except Exception as e:
|
| 86 |
-
print(f"✗ Interface validation failed: {e}")
|
| 87 |
-
import traceback
|
| 88 |
-
traceback.print_exc()
|
| 89 |
-
|
| 90 |
-
# 4. VERIFY TASKS AND GRADERS
|
| 91 |
-
print("\n[4] Tasks and Graders (3+ tasks)")
|
| 92 |
-
print("-" * 70)
|
| 93 |
-
|
| 94 |
-
try:
|
| 95 |
-
from cyber_env.tasks import (
|
| 96 |
-
setup_task_1, grade_task_1,
|
| 97 |
-
setup_task_2, grade_task_2,
|
| 98 |
-
setup_task_3, grade_task_3
|
| 99 |
-
)
|
| 100 |
-
|
| 101 |
-
tasks = [
|
| 102 |
-
("task_1", setup_task_1, grade_task_1, "Fix hardcoded API key"),
|
| 103 |
-
("task_2", setup_task_2, grade_task_2, "Prevent command injection"),
|
| 104 |
-
("task_3", setup_task_3, grade_task_3, "Fix buffer overflow"),
|
| 105 |
-
]
|
| 106 |
-
|
| 107 |
-
for task_name, setup_fn, grade_fn, desc in tasks:
|
| 108 |
-
from cyber_env.simulator import SimulatedCodebase
|
| 109 |
-
cb = SimulatedCodebase()
|
| 110 |
-
setup_fn(cb)
|
| 111 |
-
score = grade_fn(cb)
|
| 112 |
-
|
| 113 |
-
assert 0.0 <= score <= 1.0, f"Grader score {score} out of range [0, 1]"
|
| 114 |
-
print(f"✓ {task_name}: {desc}")
|
| 115 |
-
print(f" - Setup: OK")
|
| 116 |
-
print(f" - Grader: OK (Score range: 0.0-1.0, Initial: {score})")
|
| 117 |
-
|
| 118 |
-
except Exception as e:
|
| 119 |
-
print(f"✗ Task validation failed: {e}")
|
| 120 |
-
import traceback
|
| 121 |
-
traceback.print_exc()
|
| 122 |
-
|
| 123 |
-
# 5. VERIFY REWARD FUNCTION
|
| 124 |
-
print("\n[5] Meaningful Reward Function")
|
| 125 |
-
print("-" * 70)
|
| 126 |
-
|
| 127 |
-
try:
|
| 128 |
-
env = DevSecOpsEnv("task_1")
|
| 129 |
-
env.reset()
|
| 130 |
-
|
| 131 |
-
# Read file action
|
| 132 |
-
obs1, reward1, _, _ = env.step(ReadFileAction(filepath="app.py"))
|
| 133 |
-
print(f"✓ Read file action: reward = +{reward1:.1f}")
|
| 134 |
-
|
| 135 |
-
# Run security scan
|
| 136 |
-
obs2, reward2, _, _ = env.step(RunSecurityScanAction())
|
| 137 |
-
print(f"✓ Security scan action: reward = {reward2:+.1f}")
|
| 138 |
-
|
| 139 |
-
# Run tests
|
| 140 |
-
obs3, reward3, _, _ = env.step(RunUnitTestsAction())
|
| 141 |
-
print(f"✓ Unit test action: reward = {reward3:+.1f}")
|
| 142 |
-
|
| 143 |
-
print("\n Reward Breakdown:")
|
| 144 |
-
print(" - +0.2 for reading files")
|
| 145 |
-
print(" - +0.3 for passing security scan")
|
| 146 |
-
print(" - +0.5 for passing unit tests")
|
| 147 |
-
print(" - -0.2 for search_replace errors")
|
| 148 |
-
|
| 149 |
-
except Exception as e:
|
| 150 |
-
print(f"✗ Reward validation failed: {e}")
|
| 151 |
-
|
| 152 |
-
# 6. VERIFY BASELINE SCRIPT
|
| 153 |
-
print("\n[6] Baseline Inference Script")
|
| 154 |
-
print("-" * 70)
|
| 155 |
-
|
| 156 |
-
try:
|
| 157 |
-
assert os.path.exists("inference.py"), "inference.py not found"
|
| 158 |
-
print("✓ inference.py exists in root directory")
|
| 159 |
-
|
| 160 |
-
with open("inference.py") as f:
|
| 161 |
-
content = f.read()
|
| 162 |
-
|
| 163 |
-
# Check for [START], [STEP], [END] format
|
| 164 |
-
assert '[START]' in content or '"type": "START"' in content, "Missing START log format"
|
| 165 |
-
assert '[STEP]' in content or '"type": "STEP"' in content, "Missing STEP log format"
|
| 166 |
-
assert '[END]' in content or '"type": "END"' in content, "Missing END log format"
|
| 167 |
-
print("✓ Structured logging format: [START], [STEP], [END]")
|
| 168 |
-
|
| 169 |
-
# Check for environment variables
|
| 170 |
-
assert "API_BASE_URL" in content, "Missing API_BASE_URL"
|
| 171 |
-
assert "MODEL_NAME" in content, "Missing MODEL_NAME"
|
| 172 |
-
assert "GEMINI_API_KEY" in content or "HF_TOKEN" in content, "Missing API key variable"
|
| 173 |
-
print("✓ Environment variables defined: API_BASE_URL, MODEL_NAME, GEMINI_API_KEY/HF_TOKEN")
|
| 174 |
-
|
| 175 |
-
# Check for OpenAI Client
|
| 176 |
-
assert "OpenAI" in content, "Missing OpenAI client import"
|
| 177 |
-
assert "client.chat.completions.create" in content, "Missing OpenAI API call"
|
| 178 |
-
print("✓ Uses OpenAI Client for all LLM calls")
|
| 179 |
-
|
| 180 |
-
except Exception as e:
|
| 181 |
-
print(f"✗ Baseline script validation failed: {e}")
|
| 182 |
-
|
| 183 |
-
# 7. VERIFY DOCKERFILE
|
| 184 |
-
print("\n[7] Dockerfile")
|
| 185 |
-
print("-" * 70)
|
| 186 |
-
|
| 187 |
-
try:
|
| 188 |
-
assert os.path.exists("Dockerfile"), "Dockerfile not found"
|
| 189 |
-
print("✓ Dockerfile exists")
|
| 190 |
-
|
| 191 |
-
with open("Dockerfile") as f:
|
| 192 |
-
dockerfile = f.read()
|
| 193 |
-
|
| 194 |
-
assert "FROM python" in dockerfile, "Missing FROM directive"
|
| 195 |
-
assert "WORKDIR" in dockerfile, "Missing WORKDIR"
|
| 196 |
-
assert "requirements.txt" in dockerfile, "Missing requirements.txt installation"
|
| 197 |
-
assert "CMD" in dockerfile or "ENTRYPOINT" in dockerfile, "Missing CMD/ENTRYPOINT"
|
| 198 |
-
print("✓ Dockerfile structure valid")
|
| 199 |
-
|
| 200 |
-
except Exception as e:
|
| 201 |
-
print(f"✗ Dockerfile validation failed: {e}")
|
| 202 |
-
|
| 203 |
-
# 8. VERIFY REQUIREMENTS
|
| 204 |
-
print("\n[8] Requirements and Dependencies")
|
| 205 |
-
print("-" * 70)
|
| 206 |
-
|
| 207 |
-
try:
|
| 208 |
-
assert os.path.exists("requirements.txt"), "requirements.txt not found"
|
| 209 |
-
print("✓ requirements.txt exists")
|
| 210 |
-
|
| 211 |
-
with open("requirements.txt") as f:
|
| 212 |
-
reqs = f.read()
|
| 213 |
-
|
| 214 |
-
if "openenv" in reqs:
|
| 215 |
-
print("✓ openenv framework")
|
| 216 |
-
if "pydantic" in reqs:
|
| 217 |
-
print("✓ pydantic (for typed models)")
|
| 218 |
-
if "openai" in reqs:
|
| 219 |
-
print("✓ openai (for LLM integration)")
|
| 220 |
-
if "flask" in reqs:
|
| 221 |
-
print("✓ flask (for HF Space server)")
|
| 222 |
-
|
| 223 |
-
except Exception as e:
|
| 224 |
-
print(f"✗ Requirements validation failed: {e}")
|
| 225 |
-
|
| 226 |
-
# 9. VERIFY README
|
| 227 |
-
print("\n[9] Documentation")
|
| 228 |
-
print("-" * 70)
|
| 229 |
-
|
| 230 |
-
try:
|
| 231 |
-
assert os.path.exists("README.md"), "README.md not found"
|
| 232 |
-
print("✓ README.md exists")
|
| 233 |
-
|
| 234 |
-
with open("README.md") as f:
|
| 235 |
-
readme = f.read()
|
| 236 |
-
|
| 237 |
-
checks = [
|
| 238 |
-
("Observation Space", "observation"),
|
| 239 |
-
("Action Space", "action"),
|
| 240 |
-
("Reward Function", "reward"),
|
| 241 |
-
("Tasks", "task"),
|
| 242 |
-
("Setup", "setup"),
|
| 243 |
-
("Docker", "docker"),
|
| 244 |
-
]
|
| 245 |
-
|
| 246 |
-
for label, keyword in checks:
|
| 247 |
-
if keyword.lower() in readme.lower():
|
| 248 |
-
print(f"✓ {label} documented")
|
| 249 |
-
else:
|
| 250 |
-
print(f"⚠ {label} may be missing")
|
| 251 |
-
|
| 252 |
-
except Exception as e:
|
| 253 |
-
print(f"✗ Documentation validation failed: {e}")
|
| 254 |
-
|
| 255 |
-
# 10. VERIFY RUNTIME
|
| 256 |
-
print("\n[10] Infrastructure Requirements")
|
| 257 |
-
print("-" * 70)
|
| 258 |
-
|
| 259 |
-
print("✓ Python 3.10+ compatible")
|
| 260 |
-
print("✓ Lightweight Docker image (Python 3.10-slim)")
|
| 261 |
-
print("✓ Runtime < 20 minutes (expected ~2-5 min per task)")
|
| 262 |
-
print("✓ Fits vcpu=2, 8GB RAM constraints")
|
| 263 |
-
|
| 264 |
-
# FINAL SUMMARY
|
| 265 |
-
print("\n" + "="*70)
|
| 266 |
-
print(" FINAL CHECKLIST")
|
| 267 |
-
print("="*70)
|
| 268 |
-
|
| 269 |
-
checklist = [
|
| 270 |
-
("Real-world task (DevSecOps)", True),
|
| 271 |
-
("OpenEnv spec compliance", True),
|
| 272 |
-
("3+ tasks with graders", True),
|
| 273 |
-
("Meaningful reward function", True),
|
| 274 |
-
("Baseline inference script", True),
|
| 275 |
-
("Dockerfile", True),
|
| 276 |
-
("Documentation", True),
|
| 277 |
-
("Environment variables", True),
|
| 278 |
-
("Structured logging [START/STEP/END]", True),
|
| 279 |
-
("OpenAI Client usage", True),
|
| 280 |
-
("Async compatibility", False), # We're synchronous
|
| 281 |
-
("pyproject.toml", os.path.exists("pyproject.toml")),
|
| 282 |
-
]
|
| 283 |
-
|
| 284 |
-
passed = sum(1 for _, status in checklist if status)
|
| 285 |
-
total = len(checklist)
|
| 286 |
-
|
| 287 |
-
for item, status in checklist:
|
| 288 |
-
symbol = "✓" if status else "✗"
|
| 289 |
-
print(f"{symbol} {item}")
|
| 290 |
-
|
| 291 |
-
print("\n" + "="*70)
|
| 292 |
-
print(f"RESULT: {passed}/{total} checks passed")
|
| 293 |
-
if passed == total:
|
| 294 |
-
print("STATUS: ✅ READY FOR SUBMISSION")
|
| 295 |
-
else:
|
| 296 |
-
print("STATUS: ⚠️ SOME ISSUES TO ADDRESS")
|
| 297 |
-
print("="*70 + "\n")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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