Update app/orchestrator.py
Browse files- app/orchestrator.py +53 -49
app/orchestrator.py
CHANGED
|
@@ -8,56 +8,60 @@ from app.modules.llm import explain_code, classify_issue, propose_fix
|
|
| 8 |
def analyze_code(code: str, filename: str = "code.py") -> dict:
|
| 9 |
"""
|
| 10 |
Analyze code in any supported language.
|
| 11 |
-
|
| 12 |
-
Args:
|
| 13 |
-
code: Source code to analyze
|
| 14 |
-
filename: Optional filename for language detection
|
| 15 |
-
|
| 16 |
Returns:
|
| 17 |
-
|
| 18 |
"""
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
for issue in analysis_result.issues[:5]:
|
| 37 |
-
cls = classify_issue(issue, code, language)
|
| 38 |
-
classified.append({
|
| 39 |
-
"message": issue.get("message", ""),
|
| 40 |
-
"line": issue.get("line", "?"),
|
| 41 |
-
"symbol": issue.get("symbol", ""),
|
| 42 |
-
"category": cls.get("category", issue.get("category", "style")),
|
| 43 |
-
"severity": cls.get("severity", issue.get("severity", "low")),
|
| 44 |
-
"confidence": cls.get("confidence", 0.5),
|
| 45 |
-
})
|
| 46 |
-
|
| 47 |
-
if cls.get("severity") in ("high", "medium"):
|
| 48 |
-
fix = propose_fix(issue, code, language)
|
| 49 |
-
fixes.append({
|
| 50 |
-
"issue": issue.get("message", ""),
|
| 51 |
"line": issue.get("line", "?"),
|
| 52 |
-
"
|
|
|
|
|
|
|
|
|
|
| 53 |
})
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
def analyze_code(code: str, filename: str = "code.py") -> dict:
|
| 9 |
"""
|
| 10 |
Analyze code in any supported language.
|
| 11 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
Returns:
|
| 13 |
+
dict with explanation, issues, fixes, language info
|
| 14 |
"""
|
| 15 |
+
try:
|
| 16 |
+
language = detect_language(filename)
|
| 17 |
+
display_name = get_display_name(language)
|
| 18 |
+
|
| 19 |
+
analyzer = CodeAnalyzer.create_analyzer(language)
|
| 20 |
+
analysis_result = analyzer.analyze(code)
|
| 21 |
+
|
| 22 |
+
explanation = explain_code(code, language)
|
| 23 |
+
|
| 24 |
+
classified = []
|
| 25 |
+
fixes = []
|
| 26 |
+
|
| 27 |
+
for issue in analysis_result.issues[:5]:
|
| 28 |
+
cls = classify_issue(issue, code, language)
|
| 29 |
+
classified.append({
|
| 30 |
+
"message": issue.get("message", ""),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
"line": issue.get("line", "?"),
|
| 32 |
+
"symbol": issue.get("symbol", ""),
|
| 33 |
+
"category": cls.get("category", issue.get("category", "style")),
|
| 34 |
+
"severity": cls.get("severity", issue.get("severity", "low")),
|
| 35 |
+
"confidence": cls.get("confidence", 0.5),
|
| 36 |
})
|
| 37 |
+
|
| 38 |
+
if cls.get("severity") in ("high", "medium"):
|
| 39 |
+
fix = propose_fix(issue, code, language)
|
| 40 |
+
fixes.append({
|
| 41 |
+
"issue": issue.get("message", ""),
|
| 42 |
+
"line": issue.get("line", "?"),
|
| 43 |
+
"fix": fix,
|
| 44 |
+
})
|
| 45 |
+
|
| 46 |
+
return {
|
| 47 |
+
"language": language,
|
| 48 |
+
"language_display": display_name,
|
| 49 |
+
"explanation": explanation,
|
| 50 |
+
"issues": classified,
|
| 51 |
+
"fixes": fixes,
|
| 52 |
+
"total_issues": analysis_result.total_issues, # now a real attribute
|
| 53 |
+
"has_linter": any(issue.get("symbol") for issue in classified),
|
| 54 |
+
"error": None,
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
except Exception as e:
|
| 58 |
+
return {
|
| 59 |
+
"language": "unknown",
|
| 60 |
+
"language_display": "Unknown",
|
| 61 |
+
"explanation": {},
|
| 62 |
+
"issues": [],
|
| 63 |
+
"fixes": [],
|
| 64 |
+
"total_issues": 0,
|
| 65 |
+
"has_linter": False,
|
| 66 |
+
"error": str(e),
|
| 67 |
+
}
|