File size: 1,734 Bytes
553fbf7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
MINDI 1.5 Vision-Coder — Error Fixer Agent

Automatically diagnoses and fixes errors from sandbox execution,
lint failures, and type errors in generated code.
"""

from __future__ import annotations

from dataclasses import dataclass, field
from pathlib import Path
from typing import Optional


@dataclass
class ErrorDiagnosis:
    """Structured error information for the fixer agent."""
    error_type: str          # "runtime", "compile", "lint", "type"
    message: str             # Raw error message
    file_path: Optional[str] = None
    line_number: Optional[int] = None
    suggested_fix: Optional[str] = None


@dataclass
class FixResult:
    """Output from an error fix attempt."""
    original_code: str
    fixed_code: str
    errors_found: list[ErrorDiagnosis] = field(default_factory=list)
    errors_fixed: int = 0
    success: bool = False


class ErrorFixer:
    """Agent that diagnoses and fixes code errors automatically."""

    def __init__(self, log_dir: Optional[Path] = None) -> None:
        self.log_dir = log_dir or Path("./logs/error_fixer")
        self.log_dir.mkdir(parents=True, exist_ok=True)

    async def diagnose(self, code: str, error_output: str) -> list[ErrorDiagnosis]:
        """Parse error output and classify errors."""
        # Will be implemented with LLM-based error parsing
        return []

    async def fix(self, code: str, errors: list[ErrorDiagnosis]) -> FixResult:
        """Attempt to fix all diagnosed errors in the code."""
        # Will be implemented with the fine-tuned model
        return FixResult(
            original_code=code,
            fixed_code=code,
            errors_found=errors,
            errors_fixed=0,
            success=False,
        )