44
55import asyncio
66import os
7+ from typing import Any
78
89try :
910 from code_review_env import CodeReviewAction , CodeReviewEnv , ReviewFinding
1516DEFAULT_BASE_URL = "https://rohan556-openenv-code-review-arena.hf.space"
1617
1718
19+ def emit_block (tag : str , ** fields : Any ) -> None :
20+ """Print a single structured stdout line for the hackathon validator."""
21+
22+ serialized = " " .join (f"{ key } ={ value } " for key , value in fields .items ())
23+ print (f"[{ tag } ] { serialized } " , flush = True )
24+
25+
1826async def main () -> None :
1927 base_url = os .getenv ("CODE_REVIEW_ENV_URL" , DEFAULT_BASE_URL )
2028
2129 async with CodeReviewEnv (base_url = base_url ) as env :
2230 result = await env .reset (task_id = "sql_injection_report_filters" )
23- print (f"task={ result .observation .task_id } " )
24- print (f"pr={ result .observation .pr_title } " )
31+ emit_block (
32+ "START" ,
33+ task = result .observation .task_id ,
34+ difficulty = result .observation .difficulty ,
35+ repo = result .observation .repo_name ,
36+ )
2537
26- await env .step (
38+ inspection = await env .step (
2739 CodeReviewAction (
2840 action_type = "inspect_file" ,
2941 file_path = "analytics/reporting.py" ,
@@ -32,6 +44,14 @@ async def main() -> None:
3244 end_line = 80 ,
3345 )
3446 )
47+ emit_block (
48+ "STEP" ,
49+ step = 1 ,
50+ action = "inspect_file" ,
51+ reward = inspection .reward ,
52+ done = inspection .done ,
53+ phase = inspection .observation .phase ,
54+ )
3555
3656 graded = await env .step (
3757 CodeReviewAction (
@@ -54,14 +74,27 @@ async def main() -> None:
5474 ],
5575 )
5676 )
77+ emit_block (
78+ "STEP" ,
79+ step = 2 ,
80+ action = "submit_review" ,
81+ reward = graded .reward ,
82+ done = graded .done ,
83+ phase = graded .observation .phase ,
84+ )
5785
5886 scorecard = graded .observation .scorecard
59- print (f"done={ graded .done } " )
6087 if scorecard is None :
6188 raise RuntimeError ("Expected a scorecard after submit_review" )
62- print (f"score={ scorecard .overall_score } " )
63- print (f"grade_band={ scorecard .grade_band } " )
64- print (scorecard .summary )
89+ emit_block (
90+ "END" ,
91+ task = result .observation .task_id ,
92+ score = scorecard .overall_score ,
93+ steps = 2 ,
94+ grade = scorecard .grade_band ,
95+ matched = scorecard .matched_findings ,
96+ expected = scorecard .expected_findings ,
97+ )
6598
6699
67100if __name__ == "__main__" :
0 commit comments