Files
Pizza eb9b3fc85b feat: milestone 1 core loop complete
- verifier.py: syntax check via ast.parse, verify_function_present
- queue.py: QUEUE.md parser, status markers [done]/[failed:N]/[skipped]
- driver.py: full run loop — extract, prompt, generate, verify, splice, commit
  - EDIT/CREATE/DELETE/TEST actions
  - retry logic (max 3), auto-commit per task, cost tracking
- cli.py: run/status/plan wired up; plan calls big model to decompose features
- QUEUE.md: example queue with commented-out demo tasks
- pyproject.toml: fix build backend

tinyclaw run --dry-run works end-to-end
2026-04-03 00:19:53 +00:00

53 lines
1.5 KiB
Python

"""Verify Python file integrity after model edits."""
import ast
from dataclasses import dataclass, field
from pathlib import Path
@dataclass
class VerifyResult:
ok: bool
errors: list[str] = field(default_factory=list)
@property
def error(self) -> str:
return "; ".join(self.errors)
def verify(filepath: str) -> VerifyResult:
"""Syntax-check a file on disk."""
path = Path(filepath)
if not path.exists():
return VerifyResult(ok=False, errors=[f"File not found: {filepath}"])
source = path.read_text()
return verify_syntax_string(source, filepath)
def verify_syntax_string(source: str, label: str = "<string>") -> VerifyResult:
"""Syntax-check a code string (not yet written to disk)."""
if not source.strip():
return VerifyResult(ok=False, errors=["Code is empty"])
try:
ast.parse(source, filename=label)
except SyntaxError as e:
return VerifyResult(ok=False, errors=[f"SyntaxError at line {e.lineno}: {e.msg}"])
return VerifyResult(ok=True)
def verify_function_present(filepath: str, func_name: str) -> VerifyResult:
"""Check that func_name still exists in the file after an edit."""
from tinyclaw.extractor import extract_function
try:
extract_function(filepath, func_name)
return VerifyResult(ok=True)
except ValueError as e:
return VerifyResult(ok=False, errors=[str(e)])
except SyntaxError as e:
return VerifyResult(ok=False, errors=[f"SyntaxError: {e}"])