Artifex/agents/reviewer.py
2026-08-15 18:44:26 +07:00

39 lines
1.6 KiB
Python

from __future__ import annotations
from dataclasses import dataclass
from control_plane.agents.models import AgentVersion
from control_plane.projects.models import Task
from control_plane.verification.models import Review
@dataclass(frozen=True)
class ReviewDecision:
status: str
findings: list[dict[str, object]]
summary: str
class Reviewer:
def review(self, task: Task, reviewer: AgentVersion, diff: str, test_status: str) -> Review:
findings: list[dict[str, object]] = []
status = "PASS"
if test_status != "PASS":
status = "REWORK_REQUIRED"
findings.append({"type": "tests_failed", "severity": "high", "message": "Deterministic tests failed"})
if not diff.strip():
status = "REJECTED"
findings.append({"type": "empty_diff", "severity": "high", "message": "No implementation diff exists"})
goal = task.goal.lower()
expects_health_endpoint = "/health" in goal or "health endpoint" in goal or "health route" in goal
if expects_health_endpoint and "/health" not in diff and "path('health'" not in diff and 'path("health"' not in diff:
status = "REWORK_REQUIRED"
findings.append({"type": "missing_health_route", "severity": "high", "message": "Diff does not add /health"})
review = Review.objects.create(
task=task,
reviewer=reviewer,
status=status,
findings=findings,
summary="Implementation quality accepted" if status == "PASS" else "Reviewer requested rework",
)
return review