-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathtools.py
More file actions
59 lines (50 loc) · 1.68 KB
/
Copy pathtools.py
File metadata and controls
59 lines (50 loc) · 1.68 KB
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
"""Code review tools: review code, save results to database."""
import sqlite3
import json
from datetime import datetime
DB_PATH = "code_reviews.db"
def _get_db():
conn = sqlite3.connect(DB_PATH)
conn.execute("""
CREATE TABLE IF NOT EXISTS reviews (
id INTEGER PRIMARY KEY AUTOINCREMENT,
file_path TEXT,
summary TEXT,
bugs TEXT,
improvements TEXT,
score INTEGER,
created_at TEXT
)
""")
return conn
def review_code(code: str, file_path: str = "") -> dict:
"""Analyze code and return structured review.
This is a tool the agent calls — the actual LLM analysis happens
through the agent's model. The returned dict is the structured
output template.
"""
return {
"code_snippet": code[:500],
"file_path": file_path,
"needs_review": True,
}
def save_review(file_path: str, summary: str, bugs: str,
improvements: str, score: int = 0) -> str:
"""Save a code review to the SQLite database.
Args:
file_path: Path to the reviewed file
summary: One-sentence summary
bugs: Bug findings
improvements: Suggested improvements
score: Quality score (0-10)
"""
conn = _get_db()
conn.execute(
"INSERT INTO reviews (file_path, summary, bugs, improvements, score, created_at) "
"VALUES (?, ?, ?, ?, ?, ?)",
(file_path, summary, bugs, improvements, score, datetime.now().isoformat())
)
conn.commit()
count = conn.execute("SELECT COUNT(*) FROM reviews").fetchone()[0]
conn.close()
return f"Review saved. Total reviews in database: {count}"