vinith17 commited on
Commit
eb32c3c
·
1 Parent(s): 06bcb61

fix: resolve Phase 2 validation failures (tasks with graders and score range)

Browse files
.vibecheck/last-score.json CHANGED
@@ -6,5 +6,5 @@
6
  "runtimeProof": 0,
7
  "contracts": 0,
8
  "mockData": 0,
9
- "lastUpdated": "2026-04-08T11:13:30.294Z"
10
  }
 
6
  "runtimeProof": 0,
7
  "contracts": 0,
8
  "mockData": 0,
9
+ "lastUpdated": "2026-04-12T13:11:48.624Z"
10
  }
.vibecheck/provenance/attestations.db CHANGED
Binary files a/.vibecheck/provenance/attestations.db and b/.vibecheck/provenance/attestations.db differ
 
.vibecheck/provenance/edits.jsonl CHANGED
@@ -29,3 +29,7 @@
29
  {"id":"prov-1775597065328-d59yla-1","file":"main.py","startLine":8,"endLine":9,"timestamp":"2026-04-08T11:14:38.761Z","editSource":"human-typing","linesAdded":1,"linesRemoved":1,"charsInserted":32,"editVelocity":0,"aiTool":"none","aiModel":"human","confidence":85,"ide":"vscode","gitAuthor":"vinith17-k","gitEmail":"vinitharidas6@gmail.com","contentHash":"0f547befe2909c85","preview":" env_cls=CodeBugEnvironment,\\n"}
30
  {"id":"prov-1775597065328-d59yla-2","file":"main.py","startLine":8,"endLine":12,"timestamp":"2026-04-08T11:16:01.548Z","editSource":"ai-completion","linesAdded":4,"linesRemoved":4,"charsInserted":93,"editVelocity":0,"aiTool":"none","aiModel":"unknown","confidence":50,"ide":"vscode","gitAuthor":"vinith17-k","gitEmail":"vinitharidas6@gmail.com","contentHash":"6be0fb36841e90c0","preview":" CodeBugEnvironment,\\n CodeReviewAction,\\n CodeReviewObservation,\\n CodeReviewState\\n"}
31
  {"id":"prov-1775597065328-d59yla-3","file":"frontend\\codebug (1).html","startLine":547,"endLine":862,"timestamp":"2026-04-08T14:21:06.864Z","editSource":"ai-completion","linesAdded":315,"linesRemoved":302,"charsInserted":14256,"editVelocity":0,"aiTool":"none","aiModel":"unknown","confidence":50,"ide":"vscode","gitAuthor":"vinith17-k","gitEmail":"vinitharidas6@gmail.com","contentHash":"b681b8ee26679d7f","preview":" <div id=\"bugNav\" style=\"display:none; margin-bottom:16px;\"></div>\\n <div id=\"bugList\"></div>\\n </div>\\n </div>\\n </div>\\n </div>\\n </div>\\n</section>\\n\\n<!-- ── "}
 
 
 
 
 
29
  {"id":"prov-1775597065328-d59yla-1","file":"main.py","startLine":8,"endLine":9,"timestamp":"2026-04-08T11:14:38.761Z","editSource":"human-typing","linesAdded":1,"linesRemoved":1,"charsInserted":32,"editVelocity":0,"aiTool":"none","aiModel":"human","confidence":85,"ide":"vscode","gitAuthor":"vinith17-k","gitEmail":"vinitharidas6@gmail.com","contentHash":"0f547befe2909c85","preview":" env_cls=CodeBugEnvironment,\\n"}
30
  {"id":"prov-1775597065328-d59yla-2","file":"main.py","startLine":8,"endLine":12,"timestamp":"2026-04-08T11:16:01.548Z","editSource":"ai-completion","linesAdded":4,"linesRemoved":4,"charsInserted":93,"editVelocity":0,"aiTool":"none","aiModel":"unknown","confidence":50,"ide":"vscode","gitAuthor":"vinith17-k","gitEmail":"vinitharidas6@gmail.com","contentHash":"6be0fb36841e90c0","preview":" CodeBugEnvironment,\\n CodeReviewAction,\\n CodeReviewObservation,\\n CodeReviewState\\n"}
31
  {"id":"prov-1775597065328-d59yla-3","file":"frontend\\codebug (1).html","startLine":547,"endLine":862,"timestamp":"2026-04-08T14:21:06.864Z","editSource":"ai-completion","linesAdded":315,"linesRemoved":302,"charsInserted":14256,"editVelocity":0,"aiTool":"none","aiModel":"unknown","confidence":50,"ide":"vscode","gitAuthor":"vinith17-k","gitEmail":"vinitharidas6@gmail.com","contentHash":"b681b8ee26679d7f","preview":" <div id=\"bugNav\" style=\"display:none; margin-bottom:16px;\"></div>\\n <div id=\"bugList\"></div>\\n </div>\\n </div>\\n </div>\\n </div>\\n </div>\\n</section>\\n\\n<!-- ── "}
32
+ {"id":"prov-1775597065328-d59yla-4","file":"main.py","startLine":5,"endLine":6,"timestamp":"2026-04-08T16:57:15.506Z","editSource":"human-typing","linesAdded":1,"linesRemoved":1,"charsInserted":53,"editVelocity":0,"aiTool":"none","aiModel":"human","confidence":85,"ide":"vscode","gitAuthor":"vinith17-k","gitEmail":"vinitharidas6@gmail.com","contentHash":"d9cfe9bdbb9f1467","preview":"from fastapi import FastAPI, Request, HTTPException\r\\n"}
33
+ {"id":"prov-1775597065328-d59yla-5","file":"main.py","startLine":582,"endLine":583,"timestamp":"2026-04-08T17:19:29.839Z","editSource":"human-typing","linesAdded":1,"linesRemoved":1,"charsInserted":17,"editVelocity":0,"aiTool":"none","aiModel":"human","confidence":85,"ide":"vscode","gitAuthor":"vinith17-k","gitEmail":"vinitharidas6@gmail.com","contentHash":"47d050b814b477b9","preview":" return bugs\r\\n"}
34
+ {"id":"prov-1775998400628-0g4k00-1","file":"environment.py","startLine":65,"endLine":66,"timestamp":"2026-04-12T13:01:47.747Z","editSource":"human-typing","linesAdded":1,"linesRemoved":1,"charsInserted":25,"editVelocity":0,"aiTool":"none","aiModel":"human","confidence":85,"ide":"vscode","gitAuthor":"vinith17-k","gitEmail":"vinitharidas6@gmail.com","contentHash":"b86323de97bd6fd0","preview":" reward=None,\\n"}
35
+ {"id":"prov-1775998400628-0g4k00-2","file":"environment.py","startLine":88,"endLine":89,"timestamp":"2026-04-12T13:12:10.182Z","editSource":"human-typing","linesAdded":1,"linesRemoved":1,"charsInserted":61,"editVelocity":0,"aiTool":"none","aiModel":"human","confidence":85,"ide":"vscode","gitAuthor":"vinith17-k","gitEmail":"vinitharidas6@gmail.com","contentHash":"c00d563b4e8024ae","preview":" reward=0.01, # Start with a baseline safe score\\n"}
.vibecheck/sync-queue.json CHANGED
@@ -1,5 +1,5 @@
1
  {
2
  "version": 1,
3
  "entries": [],
4
- "updatedAt": "2026-04-05T17:51:55.096Z"
5
  }
 
1
  {
2
  "version": 1,
3
  "entries": [],
4
+ "updatedAt": "2026-04-08T18:24:14.158Z"
5
  }
environment.py CHANGED
@@ -8,6 +8,7 @@ class CodeBugEnvironment(Environment):
8
 
9
  TASKS = [
10
  {
 
11
  "difficulty": "easy",
12
  "snippet": (
13
  "def transfer(from_account, to_account, amount):\n"
@@ -20,6 +21,7 @@ class CodeBugEnvironment(Environment):
20
  "truth": {"category": "logic", "severity": 4, "line_hint": 2},
21
  },
22
  {
 
23
  "difficulty": "medium",
24
  "snippet": (
25
  "def find_max(numbers):\n"
@@ -34,6 +36,7 @@ class CodeBugEnvironment(Environment):
34
  "truth": {"category": "logic", "severity": 3, "line_hint": 5},
35
  },
36
  {
 
37
  "difficulty": "hard",
38
  "snippet": (
39
  "def login(username, password):\n"
@@ -46,6 +49,26 @@ class CodeBugEnvironment(Environment):
46
  ),
47
  "truth": {"category": "security", "severity": 5, "line_hint": 2},
48
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  ]
50
 
51
  def __init__(self):
@@ -62,7 +85,7 @@ class CodeBugEnvironment(Environment):
62
  task = self.TASKS[0]
63
  return CodeReviewObservation(
64
  done=False,
65
- reward=0.0,
66
  code_snippet=task["snippet"],
67
  difficulty=task["difficulty"],
68
  feedback=(
@@ -71,6 +94,11 @@ class CodeBugEnvironment(Environment):
71
  ),
72
  )
73
 
 
 
 
 
 
74
  def step(self, action: CodeReviewAction, timeout_s=None, **kwargs) -> CodeReviewObservation:
75
  """Grade the agent's action and advance to the next task."""
76
  self._state.step_count += 1
@@ -79,18 +107,30 @@ class CodeBugEnvironment(Environment):
79
  task = self.TASKS[idx]
80
  truth = task["truth"]
81
 
82
- # Reward: 0.0 → 1.0
83
- reward = 0.0
84
  if action.category.strip().lower() == truth["category"]:
85
- reward += 0.5
86
- sev_diff = abs(action.severity - truth["severity"])
 
 
 
 
 
 
87
  if sev_diff == 0:
88
- reward += 0.3
89
  elif sev_diff == 1:
90
- reward += 0.15
91
- if action.line_hint is not None and action.line_hint == truth["line_hint"]:
92
- reward += 0.2
 
 
 
 
 
93
 
 
94
  self._state.total_score += reward
95
  self._state.current_task_idx += 1
96
 
 
8
 
9
  TASKS = [
10
  {
11
+ "id": "task_easy_001",
12
  "difficulty": "easy",
13
  "snippet": (
14
  "def transfer(from_account, to_account, amount):\n"
 
21
  "truth": {"category": "logic", "severity": 4, "line_hint": 2},
22
  },
23
  {
24
+ "id": "task_medium_002",
25
  "difficulty": "medium",
26
  "snippet": (
27
  "def find_max(numbers):\n"
 
36
  "truth": {"category": "logic", "severity": 3, "line_hint": 5},
37
  },
38
  {
39
+ "id": "task_hard_003",
40
  "difficulty": "hard",
41
  "snippet": (
42
  "def login(username, password):\n"
 
49
  ),
50
  "truth": {"category": "security", "severity": 5, "line_hint": 2},
51
  },
52
+ {
53
+ "id": "task_extra_004",
54
+ "difficulty": "hard",
55
+ "snippet": (
56
+ "API_KEY = \"sk-1234567890abcdef\"\n"
57
+ "def process_data(data):\n"
58
+ " return data.upper()"
59
+ ),
60
+ "truth": {"category": "security", "severity": 5, "line_hint": 1},
61
+ },
62
+ {
63
+ "id": "task_extra_005",
64
+ "difficulty": "medium",
65
+ "snippet": (
66
+ "def divide(a, b):\n"
67
+ " # Potential bug here\n"
68
+ " return a / b"
69
+ ),
70
+ "truth": {"category": "logic", "severity": 3, "line_hint": 3},
71
+ },
72
  ]
73
 
74
  def __init__(self):
 
85
  task = self.TASKS[0]
86
  return CodeReviewObservation(
87
  done=False,
88
+ reward=0.01, # Start with a baseline safe score
89
  code_snippet=task["snippet"],
90
  difficulty=task["difficulty"],
91
  feedback=(
 
94
  ),
95
  )
96
 
97
+ @staticmethod
98
+ def _clamp_reward(raw: float) -> float:
99
+ """Clamp to (0, 1) exclusive — required by hackathon task validator."""
100
+ return max(0.01, min(0.99, raw))
101
+
102
  def step(self, action: CodeReviewAction, timeout_s=None, **kwargs) -> CodeReviewObservation:
103
  """Grade the agent's action and advance to the next task."""
104
  self._state.step_count += 1
 
107
  task = self.TASKS[idx]
108
  truth = task["truth"]
109
 
110
+ # Compute raw reward, then clamp to (0, 1) exclusive
111
+ raw_reward = 0.0
112
  if action.category.strip().lower() == truth["category"]:
113
+ raw_reward += 0.5
114
+
115
+ try:
116
+ sev = int(action.severity)
117
+ sev_diff = abs(sev - truth["severity"])
118
+ except (ValueError, TypeError):
119
+ sev_diff = 99
120
+
121
  if sev_diff == 0:
122
+ raw_reward += 0.3
123
  elif sev_diff == 1:
124
+ raw_reward += 0.15
125
+
126
+ if action.line_hint is not None:
127
+ try:
128
+ if int(action.line_hint) == truth["line_hint"]:
129
+ raw_reward += 0.2
130
+ except (ValueError, TypeError):
131
+ pass
132
 
133
+ reward = self._clamp_reward(raw_reward)
134
  self._state.total_score += reward
135
  self._state.current_task_idx += 1
136
 
inference.py CHANGED
@@ -35,7 +35,7 @@ client = OpenAI(
35
  )
36
 
37
  # ─────────────────────────────────────────────────────────────
38
- # Code review tasks (3 difficulty levels: easy → medium → hard)
39
  # ─────────────────────────────────────────────────────────────
40
  TASKS = [
41
  {
@@ -49,7 +49,7 @@ TASKS = [
49
  " return True\n"
50
  " return False"
51
  ),
52
- "truth": {"category": "logic", "severity": 4},
53
  },
54
  {
55
  "id": "task_medium_002",
@@ -64,7 +64,7 @@ TASKS = [
64
  " max_val = numbers[i]\n"
65
  " return max_val"
66
  ),
67
- "truth": {"category": "logic", "severity": 3},
68
  },
69
  {
70
  "id": "task_hard_003",
@@ -78,7 +78,27 @@ TASKS = [
78
  " return True\n"
79
  " return False"
80
  ),
81
- "truth": {"category": "security", "severity": 5},
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  },
83
  ]
84
 
@@ -123,21 +143,31 @@ def score_action(action: dict, truth: dict) -> float:
123
  reward = 0.0
124
 
125
  # Category match → 0.5
126
- if action.get("category", "").lower() == truth["category"]:
127
  reward += 0.5
128
 
129
  # Severity accuracy → up to 0.3
130
- sev_diff = abs(int(action.get("severity", 0)) - truth["severity"])
 
 
 
 
 
131
  if sev_diff == 0:
132
  reward += 0.3
133
  elif sev_diff == 1:
134
  reward += 0.15
135
 
136
- # Any non-None line hint when a bug exists → 0.2
137
- if action.get("line_hint") is not None and truth["category"] != "approve":
138
- reward += 0.2
 
 
 
 
 
139
 
140
- # Clamp to (0.0, 1.0) exclusive: 0.0 → 0.01, 1.0 → 0.99, others scale proportionally
141
  clamped = 0.01 + (min(reward, 1.0) * 0.98)
142
  return round(clamped, 4)
143
 
 
35
  )
36
 
37
  # ─────────────────────────────────────────────────────────────
38
+ # Code review tasks (5 tasks)
39
  # ─────────────────────────────────────────────────────────────
40
  TASKS = [
41
  {
 
49
  " return True\n"
50
  " return False"
51
  ),
52
+ "truth": {"category": "logic", "severity": 4, "line_hint": 2},
53
  },
54
  {
55
  "id": "task_medium_002",
 
64
  " max_val = numbers[i]\n"
65
  " return max_val"
66
  ),
67
+ "truth": {"category": "logic", "severity": 3, "line_hint": 5},
68
  },
69
  {
70
  "id": "task_hard_003",
 
78
  " return True\n"
79
  " return False"
80
  ),
81
+ "truth": {"category": "security", "severity": 5, "line_hint": 2},
82
+ },
83
+ {
84
+ "id": "task_extra_004",
85
+ "difficulty": "hard",
86
+ "code": (
87
+ "API_KEY = \"sk-1234567890abcdef\"\n"
88
+ "def process_data(data):\n"
89
+ " return data.upper()"
90
+ ),
91
+ "truth": {"category": "security", "severity": 5, "line_hint": 1},
92
+ },
93
+ {
94
+ "id": "task_extra_005",
95
+ "difficulty": "medium",
96
+ "code": (
97
+ "def divide(a, b):\n"
98
+ " # Potential bug here\n"
99
+ " return a / b"
100
+ ),
101
+ "truth": {"category": "logic", "severity": 3, "line_hint": 3},
102
  },
103
  ]
104
 
 
143
  reward = 0.0
144
 
145
  # Category match → 0.5
146
+ if str(action.get("category", "")).lower() == truth["category"]:
147
  reward += 0.5
148
 
149
  # Severity accuracy → up to 0.3
150
+ try:
151
+ sev = int(action.get("severity", 0))
152
+ sev_diff = abs(sev - truth["severity"])
153
+ except:
154
+ sev_diff = 99
155
+
156
  if sev_diff == 0:
157
  reward += 0.3
158
  elif sev_diff == 1:
159
  reward += 0.15
160
 
161
+ # Line hint match → 0.2
162
+ lh = action.get("line_hint")
163
+ if lh is not None:
164
+ try:
165
+ if int(lh) == truth["line_hint"]:
166
+ reward += 0.2
167
+ except:
168
+ pass
169
 
170
+ # Clamp to (0.0, 1.0) exclusive: 0.0 → 0.01, 1.0 → 0.99
171
  clamped = 0.01 + (min(reward, 1.0) * 0.98)
172
  return round(clamped, 4)
173
 
openenv.yaml CHANGED
@@ -1,9 +1,40 @@
1
  name: "CodeBug Review Environment"
2
  version: "1.0.0"
3
- description: "RL environment where an AI agent reviews code snippets to identify bugs. Three tasks: easy (logic/boundary), medium (off-by-one), hard (SQL injection). Reward 0-1 per step."
4
  entry_point: "main:app"
5
  author: "vinith17"
6
  tags: ["rl", "code-review", "security", "agent", "pytorch-hackathon"]
7
  environment_class: "environment.CodeBugEnvironment"
8
  action_class: "models.CodeReviewAction"
9
  observation_class: "models.CodeReviewObservation"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  name: "CodeBug Review Environment"
2
  version: "1.0.0"
3
+ description: "RL environment where an AI agent reviews code snippets to identify bugs. Five tasks covering logic and security. Reward strictly in (0,1) per step."
4
  entry_point: "main:app"
5
  author: "vinith17"
6
  tags: ["rl", "code-review", "security", "agent", "pytorch-hackathon"]
7
  environment_class: "environment.CodeBugEnvironment"
8
  action_class: "models.CodeReviewAction"
9
  observation_class: "models.CodeReviewObservation"
10
+
11
+ tasks:
12
+ - id: "task_easy_001"
13
+ name: "Balance Transfer Boundary Bug"
14
+ description: "Detect strict > instead of >= in balance check."
15
+ difficulty: "easy"
16
+ grader: "tasks.easy.grader:grade"
17
+
18
+ - id: "task_medium_002"
19
+ name: "Find Max Off-by-One"
20
+ description: "Detect range(len(x)-1) skipping the last element."
21
+ difficulty: "medium"
22
+ grader: "tasks.medium.grader:grade"
23
+
24
+ - id: "task_hard_003"
25
+ name: "SQL Injection Detection"
26
+ description: "Detect f-string SQL injection."
27
+ difficulty: "hard"
28
+ grader: "tasks.hard.grader:grade"
29
+
30
+ - id: "task_extra_004"
31
+ name: "Hardcoded API Key"
32
+ description: "Detect hardcoded secrets."
33
+ difficulty: "hard"
34
+ grader: "tasks.extra1.grader:grade"
35
+
36
+ - id: "task_extra_005"
37
+ name: "Division by Zero"
38
+ description: "Detect division without zero-check."
39
+ difficulty: "medium"
40
+ grader: "tasks.extra2.grader:grade"
requirements.txt CHANGED
@@ -31,3 +31,4 @@ typing-inspection==0.4.2
31
  typing_extensions==4.15.0
32
  Werkzeug==3.1.8
33
  wrapt==2.1.2
 
 
31
  typing_extensions==4.15.0
32
  Werkzeug==3.1.8
33
  wrapt==2.1.2
34
+ openenv-core>=0.2.2
tasks/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ # tasks package — one grader per task for OpenEnv submission validation
tasks/easy/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ # easy task package
tasks/easy/grader.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Grader for task_easy_001 — Balance Transfer boundary bug.
3
+ """
4
+
5
+ TRUTH = {"category": "logic", "severity": 4, "line_hint": 2}
6
+
7
+ def _clamp(score: float) -> float:
8
+ return max(0.01, min(0.99, score))
9
+
10
+ def grade(action: any) -> float:
11
+ reward = 0.0
12
+
13
+ # Handle dict or Pydantic model
14
+ def get_attr(obj, attr, default=None):
15
+ if isinstance(obj, dict):
16
+ return obj.get(attr, default)
17
+ return getattr(obj, attr, default)
18
+
19
+ # Category match → 0.5
20
+ cat = str(get_attr(action, "category", "")).strip().lower()
21
+ if cat == TRUTH["category"]:
22
+ reward += 0.5
23
+
24
+ # Severity accuracy → up to 0.3
25
+ try:
26
+ sev = int(get_attr(action, "severity", 0))
27
+ sev_diff = abs(sev - TRUTH["severity"])
28
+ except (ValueError, TypeError):
29
+ sev_diff = 99
30
+
31
+ if sev_diff == 0:
32
+ reward += 0.3
33
+ elif sev_diff == 1:
34
+ reward += 0.15
35
+
36
+ # Line hint → 0.2
37
+ lh = get_attr(action, "line_hint")
38
+ if lh is not None:
39
+ try:
40
+ if int(lh) == TRUTH["line_hint"]:
41
+ reward += 0.2
42
+ except (ValueError, TypeError):
43
+ pass
44
+
45
+ return _clamp(reward)
tasks/extra1/__init__.py ADDED
File without changes
tasks/extra1/grader.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Grader for task_extra_004 — Hardcoded API key.
3
+ """
4
+
5
+ TRUTH = {"category": "security", "severity": 5, "line_hint": 1}
6
+
7
+ def _clamp(score: float) -> float:
8
+ return max(0.01, min(0.99, score))
9
+
10
+ def grade(action: any) -> float:
11
+ reward = 0.0
12
+ def get_attr(obj, attr, default=None):
13
+ if isinstance(obj, dict): return obj.get(attr, default)
14
+ return getattr(obj, attr, default)
15
+
16
+ cat = str(get_attr(action, "category", "")).strip().lower()
17
+ if cat == TRUTH["category"]: reward += 0.5
18
+
19
+ try:
20
+ sev = int(get_attr(action, "severity", 0))
21
+ sev_diff = abs(sev - TRUTH["severity"])
22
+ except: sev_diff = 99
23
+
24
+ if sev_diff == 0: reward += 0.3
25
+ elif sev_diff == 1: reward += 0.15
26
+
27
+ lh = get_attr(action, "line_hint")
28
+ if lh is not None:
29
+ try:
30
+ if int(lh) == TRUTH["line_hint"]: reward += 0.2
31
+ except: pass
32
+
33
+ return _clamp(reward)
tasks/extra2/__init__.py ADDED
File without changes
tasks/extra2/grader.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Grader for task_extra_005 — Division by zero.
3
+ """
4
+
5
+ TRUTH = {"category": "logic", "severity": 3, "line_hint": 3}
6
+
7
+ def _clamp(score: float) -> float:
8
+ return max(0.01, min(0.99, score))
9
+
10
+ def grade(action: any) -> float:
11
+ reward = 0.0
12
+ def get_attr(obj, attr, default=None):
13
+ if isinstance(obj, dict): return obj.get(attr, default)
14
+ return getattr(obj, attr, default)
15
+
16
+ cat = str(get_attr(action, "category", "")).strip().lower()
17
+ if cat == TRUTH["category"]: reward += 0.5
18
+
19
+ try:
20
+ sev = int(get_attr(action, "severity", 0))
21
+ sev_diff = abs(sev - TRUTH["severity"])
22
+ except: sev_diff = 99
23
+
24
+ if sev_diff == 0: reward += 0.3
25
+ elif sev_diff == 1: reward += 0.15
26
+
27
+ lh = get_attr(action, "line_hint")
28
+ if lh is not None:
29
+ try:
30
+ if int(lh) == TRUTH["line_hint"]: reward += 0.2
31
+ except: pass
32
+
33
+ return _clamp(reward)
tasks/hard/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ # hard task package
tasks/hard/grader.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Grader for task_hard_003 — SQL injection detection.
3
+ """
4
+
5
+ TRUTH = {"category": "security", "severity": 5, "line_hint": 2}
6
+
7
+ def _clamp(score: float) -> float:
8
+ return max(0.01, min(0.99, score))
9
+
10
+ def grade(action: any) -> float:
11
+ reward = 0.0
12
+
13
+ def get_attr(obj, attr, default=None):
14
+ if isinstance(obj, dict):
15
+ return obj.get(attr, default)
16
+ return getattr(obj, attr, default)
17
+
18
+ cat = str(get_attr(action, "category", "")).strip().lower()
19
+ if cat == TRUTH["category"]:
20
+ reward += 0.5
21
+
22
+ try:
23
+ sev = int(get_attr(action, "severity", 0))
24
+ sev_diff = abs(sev - TRUTH["severity"])
25
+ except (ValueError, TypeError):
26
+ sev_diff = 99
27
+
28
+ if sev_diff == 0:
29
+ reward += 0.3
30
+ elif sev_diff == 1:
31
+ reward += 0.15
32
+
33
+ lh = get_attr(action, "line_hint")
34
+ if lh is not None:
35
+ try:
36
+ if int(lh) == TRUTH["line_hint"]:
37
+ reward += 0.2
38
+ except (ValueError, TypeError):
39
+ pass
40
+
41
+ return _clamp(reward)
tasks/medium/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ # medium task package
tasks/medium/grader.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Grader for task_medium_002 — find_max off-by-one bug.
3
+ """
4
+
5
+ TRUTH = {"category": "logic", "severity": 3, "line_hint": 5}
6
+
7
+ def _clamp(score: float) -> float:
8
+ return max(0.01, min(0.99, score))
9
+
10
+ def grade(action: any) -> float:
11
+ reward = 0.0
12
+
13
+ def get_attr(obj, attr, default=None):
14
+ if isinstance(obj, dict):
15
+ return obj.get(attr, default)
16
+ return getattr(obj, attr, default)
17
+
18
+ cat = str(get_attr(action, "category", "")).strip().lower()
19
+ if cat == TRUTH["category"]:
20
+ reward += 0.5
21
+
22
+ try:
23
+ sev = int(get_attr(action, "severity", 0))
24
+ sev_diff = abs(sev - TRUTH["severity"])
25
+ except (ValueError, TypeError):
26
+ sev_diff = 99
27
+
28
+ if sev_diff == 0:
29
+ reward += 0.3
30
+ elif sev_diff == 1:
31
+ reward += 0.15
32
+
33
+ lh = get_attr(action, "line_hint")
34
+ if lh is not None:
35
+ try:
36
+ if int(lh) == TRUTH["line_hint"]:
37
+ reward += 0.2
38
+ except (ValueError, TypeError):
39
+ pass
40
+
41
+ return _clamp(reward)