vinith17 commited on
Commit
b395a8b
·
1 Parent(s): 96775ab

Use gpt-4o for vision support

Browse files
.vibecheck/provenance/attestations.db CHANGED
Binary files a/.vibecheck/provenance/attestations.db and b/.vibecheck/provenance/attestations.db differ
 
.vibecheck/provenance/edits.jsonl CHANGED
@@ -33,3 +33,4 @@
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"}
 
 
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"}
36
+ {"id":"prov-1775998400628-0g4k00-3","file":"server\\__init__.py","startLine":1,"endLine":2,"timestamp":"2026-04-12T14:48:52.806Z","editSource":"human-typing","linesAdded":1,"linesRemoved":1,"charsInserted":60,"editVelocity":0,"aiTool":"none","aiModel":"human","confidence":85,"ide":"vscode","gitAuthor":"vinith17-k","gitEmail":"vinitharidas6@gmail.com","contentHash":"497cd81d76c9fcb5","preview":"# Server package for OpenEnv-style layouts (server/app.py).\\n"}
agent.py CHANGED
@@ -11,9 +11,11 @@ logger = logging.getLogger(__name__)
11
  MAX_TOKENS = 1024
12
 
13
  API_BASE_URL = os.environ.get("API_BASE_URL", "https://api.openai.com/v1")
14
- MODEL_NAME = os.environ.get("MODEL_NAME", "gpt-4o-mini")
15
  # Hackathon / Spaces: HF_TOKEN; local dev may use OPENAI_API_KEY
16
- _LLM_KEY = (os.environ.get("HF_TOKEN") or os.environ.get("OPENAI_API_KEY") or "").strip()
 
 
17
  has_openai_client = bool(_LLM_KEY)
18
 
19
 
@@ -91,6 +93,7 @@ def build_user_message(code: str, retry: bool = False) -> str:
91
  # LLM call
92
  # ---------------------------------------------------------------------------
93
 
 
94
  def call_llm(prompt: str, *, system: str | None = None) -> str | None:
95
  """
96
  Call the OpenAI-compatible Chat Completions API (HF_TOKEN or OPENAI_API_KEY).
@@ -120,6 +123,7 @@ def call_llm(prompt: str, *, system: str | None = None) -> str | None:
120
  # JSON parsing helper
121
  # ---------------------------------------------------------------------------
122
 
 
123
  def _parse_json(raw: str) -> dict | None:
124
  """Try direct parse, then regex-extracted substring."""
125
  if not raw:
@@ -151,65 +155,81 @@ def mock_review(code: str) -> list:
151
 
152
  # SQL injection
153
  if 'f"select' in code_lower or "f'select" in code_lower:
154
- bugs.append({
155
- "type": "bug",
156
- "category": "security",
157
- "severity": 5,
158
- "comment": "SQL injection: f-string with variable interpolation in SQL query.",
159
- "fix": "Use parameterized queries: cursor.execute('SELECT * FROM users WHERE id = ?', (uid,))",
160
- "confidence": 0.95,
161
- "line_hint": "database query line"
162
- })
 
 
163
 
164
  # Hardcoded password
165
  if "hashed = password" in code_lower or (
166
- "password" in code_lower and "hash" not in code_lower and "bcrypt" not in code_lower
 
 
167
  ):
168
- bugs.append({
169
- "type": "bug",
170
- "category": "security",
171
- "severity": 5,
172
- "comment": "Hardcoded password/credential detected.",
173
- "fix": "Use environment variables: os.getenv('DB_PASSWORD')",
174
- "confidence": 0.98,
175
- "line_hint": "password assignment line"
176
- })
 
 
177
 
178
  # Off-by-one
179
  if "range(len(" in code_lower and "- 1" in code_lower:
180
- bugs.append({
181
- "type": "bug",
182
- "category": "logic",
183
- "severity": 3,
184
- "comment": "Off-by-one error: range(len(x)-1) skips the last element.",
185
- "fix": "Use range(len(arr)) or check bounds: if i+1 < len(arr)",
186
- "confidence": 0.85,
187
- "line_hint": "loop range call"
188
- })
 
 
189
 
190
  # Division by zero
191
  if "/ 0" in code_lower:
192
- bugs.append({
193
- "type": "bug",
194
- "category": "logic",
195
- "severity": 3,
196
- "comment": "Potential division by zero. Check denominator is non-zero.",
197
- "fix": "Add check: if denominator != 0: result = numerator / denominator",
198
- "confidence": 0.99,
199
- "line_hint": "division line"
200
- })
 
 
201
 
202
  # Strict comparison
203
- if ("> amount" in code_lower or "< amount" in code_lower) and ">=" not in code_lower and "<=" not in code_lower:
204
- bugs.append({
205
- "type": "bug",
206
- "category": "logic",
207
- "severity": 4,
208
- "comment": "Strict > / < in balance check; may miss the equality edge case.",
209
- "fix": "Use >= or <= to include equality edge case.",
210
- "confidence": 0.8,
211
- "line_hint": "comparison check"
212
- })
 
 
 
 
 
 
213
 
214
  return bugs
215
 
@@ -219,7 +239,13 @@ def mock_review(code: str) -> list:
219
  # ---------------------------------------------------------------------------
220
 
221
  _REQUIRED_KEYS = {"type", "category", "line_hint", "comment", "severity"}
222
- _DEFAULTS = {"type": "approve", "category": "ok", "line_hint": "", "comment": "", "severity": 0}
 
 
 
 
 
 
223
 
224
 
225
  def review(code: str) -> list:
@@ -239,7 +265,9 @@ def review(code: str) -> list:
239
 
240
  if result is None or not isinstance(result, list):
241
  # One retry: tell the model its output was invalid
242
- logger.warning("LLM returned malformed JSON or not a list — retrying with correction hint.")
 
 
243
  user_msg_retry = build_user_message(code, retry=True)
244
  raw_retry = call_llm(user_msg_retry, system=_SYSTEM_PROMPT)
245
  result = _parse_json(raw_retry)
@@ -262,10 +290,19 @@ def review(code: str) -> list:
262
 
263
  if __name__ == "__main__":
264
  _TESTS = [
265
- ("SQL injection", "def login(u, p, db):\n q = f\"SELECT * FROM users WHERE username='{u}'\"\n return db.execute(q)"),
266
- ("Off-by-one", "def find_max(nums):\n mx = nums[0]\n for i in range(len(nums) - 1):\n if nums[i] > mx: mx = nums[i]\n return mx"),
267
- ("Plain password", "def save(u, pw, db):\n db.insert('users', {'username': u, 'password': pw})"),
268
- ("Clean code", "def add(a: int, b: int) -> int:\n return a + b"),
 
 
 
 
 
 
 
 
 
269
  ]
270
 
271
  print("=== Agent Tests ===\n")
 
11
  MAX_TOKENS = 1024
12
 
13
  API_BASE_URL = os.environ.get("API_BASE_URL", "https://api.openai.com/v1")
14
+ MODEL_NAME = os.environ.get("MODEL_NAME", "gpt-4o")
15
  # Hackathon / Spaces: HF_TOKEN; local dev may use OPENAI_API_KEY
16
+ _LLM_KEY = (
17
+ os.environ.get("HF_TOKEN") or os.environ.get("OPENAI_API_KEY") or ""
18
+ ).strip()
19
  has_openai_client = bool(_LLM_KEY)
20
 
21
 
 
93
  # LLM call
94
  # ---------------------------------------------------------------------------
95
 
96
+
97
  def call_llm(prompt: str, *, system: str | None = None) -> str | None:
98
  """
99
  Call the OpenAI-compatible Chat Completions API (HF_TOKEN or OPENAI_API_KEY).
 
123
  # JSON parsing helper
124
  # ---------------------------------------------------------------------------
125
 
126
+
127
  def _parse_json(raw: str) -> dict | None:
128
  """Try direct parse, then regex-extracted substring."""
129
  if not raw:
 
155
 
156
  # SQL injection
157
  if 'f"select' in code_lower or "f'select" in code_lower:
158
+ bugs.append(
159
+ {
160
+ "type": "bug",
161
+ "category": "security",
162
+ "severity": 5,
163
+ "comment": "SQL injection: f-string with variable interpolation in SQL query.",
164
+ "fix": "Use parameterized queries: cursor.execute('SELECT * FROM users WHERE id = ?', (uid,))",
165
+ "confidence": 0.95,
166
+ "line_hint": "database query line",
167
+ }
168
+ )
169
 
170
  # Hardcoded password
171
  if "hashed = password" in code_lower or (
172
+ "password" in code_lower
173
+ and "hash" not in code_lower
174
+ and "bcrypt" not in code_lower
175
  ):
176
+ bugs.append(
177
+ {
178
+ "type": "bug",
179
+ "category": "security",
180
+ "severity": 5,
181
+ "comment": "Hardcoded password/credential detected.",
182
+ "fix": "Use environment variables: os.getenv('DB_PASSWORD')",
183
+ "confidence": 0.98,
184
+ "line_hint": "password assignment line",
185
+ }
186
+ )
187
 
188
  # Off-by-one
189
  if "range(len(" in code_lower and "- 1" in code_lower:
190
+ bugs.append(
191
+ {
192
+ "type": "bug",
193
+ "category": "logic",
194
+ "severity": 3,
195
+ "comment": "Off-by-one error: range(len(x)-1) skips the last element.",
196
+ "fix": "Use range(len(arr)) or check bounds: if i+1 < len(arr)",
197
+ "confidence": 0.85,
198
+ "line_hint": "loop range call",
199
+ }
200
+ )
201
 
202
  # Division by zero
203
  if "/ 0" in code_lower:
204
+ bugs.append(
205
+ {
206
+ "type": "bug",
207
+ "category": "logic",
208
+ "severity": 3,
209
+ "comment": "Potential division by zero. Check denominator is non-zero.",
210
+ "fix": "Add check: if denominator != 0: result = numerator / denominator",
211
+ "confidence": 0.99,
212
+ "line_hint": "division line",
213
+ }
214
+ )
215
 
216
  # Strict comparison
217
+ if (
218
+ ("> amount" in code_lower or "< amount" in code_lower)
219
+ and ">=" not in code_lower
220
+ and "<=" not in code_lower
221
+ ):
222
+ bugs.append(
223
+ {
224
+ "type": "bug",
225
+ "category": "logic",
226
+ "severity": 4,
227
+ "comment": "Strict > / < in balance check; may miss the equality edge case.",
228
+ "fix": "Use >= or <= to include equality edge case.",
229
+ "confidence": 0.8,
230
+ "line_hint": "comparison check",
231
+ }
232
+ )
233
 
234
  return bugs
235
 
 
239
  # ---------------------------------------------------------------------------
240
 
241
  _REQUIRED_KEYS = {"type", "category", "line_hint", "comment", "severity"}
242
+ _DEFAULTS = {
243
+ "type": "approve",
244
+ "category": "ok",
245
+ "line_hint": "",
246
+ "comment": "",
247
+ "severity": 0,
248
+ }
249
 
250
 
251
  def review(code: str) -> list:
 
265
 
266
  if result is None or not isinstance(result, list):
267
  # One retry: tell the model its output was invalid
268
+ logger.warning(
269
+ "LLM returned malformed JSON or not a list — retrying with correction hint."
270
+ )
271
  user_msg_retry = build_user_message(code, retry=True)
272
  raw_retry = call_llm(user_msg_retry, system=_SYSTEM_PROMPT)
273
  result = _parse_json(raw_retry)
 
290
 
291
  if __name__ == "__main__":
292
  _TESTS = [
293
+ (
294
+ "SQL injection",
295
+ "def login(u, p, db):\n q = f\"SELECT * FROM users WHERE username='{u}'\"\n return db.execute(q)",
296
+ ),
297
+ (
298
+ "Off-by-one",
299
+ "def find_max(nums):\n mx = nums[0]\n for i in range(len(nums) - 1):\n if nums[i] > mx: mx = nums[i]\n return mx",
300
+ ),
301
+ (
302
+ "Plain password",
303
+ "def save(u, pw, db):\n db.insert('users', {'username': u, 'password': pw})",
304
+ ),
305
+ ("Clean code", "def add(a: int, b: int) -> int:\n return a + b"),
306
  ]
307
 
308
  print("=== Agent Tests ===\n")
inference.py CHANGED
@@ -27,7 +27,7 @@ from tasks.medium.grader import grade as grade_task_medium_002
27
  from grader import grade as root_rubric_grade
28
 
29
  API_BASE_URL = os.environ.get("API_BASE_URL", "https://api.openai.com/v1")
30
- MODEL_NAME = os.environ.get("MODEL_NAME", "gpt-4o-mini")
31
 
32
  _TASK_GRADERS = {
33
  "task_easy_001": grade_task_easy_001,
@@ -81,7 +81,7 @@ TASKS = [
81
  "task_id": "task_extra_004",
82
  "difficulty": "hard",
83
  "code": (
84
- "API_KEY = \"sk-1234567890abcdef\"\n"
85
  "def process_data(data):\n"
86
  " return data.upper()"
87
  ),
@@ -89,11 +89,7 @@ TASKS = [
89
  {
90
  "task_id": "task_extra_005",
91
  "difficulty": "medium",
92
- "code": (
93
- "def divide(a, b):\n"
94
- " # Potential bug here\n"
95
- " return a / b"
96
- ),
97
  },
98
  ]
99
 
@@ -173,12 +169,19 @@ def run_task(client: OpenAI, task: dict) -> dict:
173
  user = f"Difficulty: {task['difficulty']}\n\nReview this code:\n\n{task['code']}"
174
  data = _chat_json(client, user)
175
  if not data:
176
- return {"category": "approve", "severity": 1, "line_hint": None, "comment": "parse_error"}
 
 
 
 
 
177
  return data
178
 
179
 
180
  def run_inference() -> None:
181
- llm_key = (os.environ.get("HF_TOKEN") or os.environ.get("OPENAI_API_KEY") or "").strip()
 
 
182
  if not llm_key:
183
  print(
184
  "[ERROR] Set HF_TOKEN or OPENAI_API_KEY to your OpenAI-compatible API key.",
@@ -190,7 +193,13 @@ def run_inference() -> None:
190
 
191
  # Ensure grader.py rubric returns (0,1); does not change [STEP] scores (those use manifest graders).
192
  _san = root_rubric_grade(
193
- {"type": "approve", "category": "ok", "line_hint": "", "comment": "", "severity": 0},
 
 
 
 
 
 
194
  {"bug": {"type": "none", "severity": 0, "description": "", "line_hint": ""}},
195
  )
196
  if not (isinstance(_san.reward, float) and 0.0 < _san.reward < 1.0):
 
27
  from grader import grade as root_rubric_grade
28
 
29
  API_BASE_URL = os.environ.get("API_BASE_URL", "https://api.openai.com/v1")
30
+ MODEL_NAME = os.environ.get("MODEL_NAME", "gpt-4o")
31
 
32
  _TASK_GRADERS = {
33
  "task_easy_001": grade_task_easy_001,
 
81
  "task_id": "task_extra_004",
82
  "difficulty": "hard",
83
  "code": (
84
+ 'API_KEY = "sk-1234567890abcdef"\n'
85
  "def process_data(data):\n"
86
  " return data.upper()"
87
  ),
 
89
  {
90
  "task_id": "task_extra_005",
91
  "difficulty": "medium",
92
+ "code": ("def divide(a, b):\n # Potential bug here\n return a / b"),
 
 
 
 
93
  },
94
  ]
95
 
 
169
  user = f"Difficulty: {task['difficulty']}\n\nReview this code:\n\n{task['code']}"
170
  data = _chat_json(client, user)
171
  if not data:
172
+ return {
173
+ "category": "approve",
174
+ "severity": 1,
175
+ "line_hint": None,
176
+ "comment": "parse_error",
177
+ }
178
  return data
179
 
180
 
181
  def run_inference() -> None:
182
+ llm_key = (
183
+ os.environ.get("HF_TOKEN") or os.environ.get("OPENAI_API_KEY") or ""
184
+ ).strip()
185
  if not llm_key:
186
  print(
187
  "[ERROR] Set HF_TOKEN or OPENAI_API_KEY to your OpenAI-compatible API key.",
 
193
 
194
  # Ensure grader.py rubric returns (0,1); does not change [STEP] scores (those use manifest graders).
195
  _san = root_rubric_grade(
196
+ {
197
+ "type": "approve",
198
+ "category": "ok",
199
+ "line_hint": "",
200
+ "comment": "",
201
+ "severity": 0,
202
+ },
203
  {"bug": {"type": "none", "severity": 0, "description": "", "line_hint": ""}},
204
  )
205
  if not (isinstance(_san.reward, float) and 0.0 < _san.reward < 1.0):