|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from dataclasses import dataclass, field |
| 4 | +from datetime import datetime, timezone |
| 5 | +from typing import Any, Literal |
| 6 | + |
| 7 | +Status = Literal["backlog", "running", "review", "done", "blocked"] |
| 8 | + |
| 9 | + |
| 10 | +def utc_now() -> str: |
| 11 | + return datetime.now(timezone.utc).replace(microsecond=0).isoformat() |
| 12 | + |
| 13 | + |
| 14 | +@dataclass(slots=True) |
| 15 | +class Task: |
| 16 | + id: str |
| 17 | + title: str |
| 18 | + goal: str |
| 19 | + status: Status = "backlog" |
| 20 | + files: list[str] = field(default_factory=list) |
| 21 | + acceptance: list[str] = field(default_factory=list) |
| 22 | + notes: str = "" |
| 23 | + preferred_agent: str = "" |
| 24 | + created_at: str = field(default_factory=utc_now) |
| 25 | + updated_at: str = field(default_factory=utc_now) |
| 26 | + |
| 27 | + @classmethod |
| 28 | + def from_dict(cls, data: dict[str, Any]) -> "Task": |
| 29 | + return cls( |
| 30 | + id=str(data["id"]), |
| 31 | + title=str(data["title"]), |
| 32 | + goal=str(data.get("goal", "")), |
| 33 | + status=data.get("status", "backlog"), |
| 34 | + files=list(data.get("files", [])), |
| 35 | + acceptance=list(data.get("acceptance", [])), |
| 36 | + notes=str(data.get("notes", "")), |
| 37 | + preferred_agent=str(data.get("preferred_agent", "")), |
| 38 | + created_at=str(data.get("created_at", utc_now())), |
| 39 | + updated_at=str(data.get("updated_at", utc_now())), |
| 40 | + ) |
| 41 | + |
| 42 | + def to_dict(self) -> dict[str, Any]: |
| 43 | + return { |
| 44 | + "id": self.id, |
| 45 | + "title": self.title, |
| 46 | + "goal": self.goal, |
| 47 | + "status": self.status, |
| 48 | + "files": self.files, |
| 49 | + "acceptance": self.acceptance, |
| 50 | + "notes": self.notes, |
| 51 | + "preferred_agent": self.preferred_agent, |
| 52 | + "created_at": self.created_at, |
| 53 | + "updated_at": self.updated_at, |
| 54 | + } |
| 55 | + |
| 56 | + |
| 57 | +@dataclass(slots=True) |
| 58 | +class RunRecord: |
| 59 | + id: str |
| 60 | + task_id: str |
| 61 | + agent: str |
| 62 | + command: str |
| 63 | + status: str |
| 64 | + started_at: str |
| 65 | + finished_at: str = "" |
| 66 | + prompt_path: str = "" |
| 67 | + report_path: str = "" |
| 68 | + stdout_path: str = "" |
| 69 | + stderr_path: str = "" |
| 70 | + diff_path: str = "" |
| 71 | + checks: list[dict[str, Any]] = field(default_factory=list) |
| 72 | + |
| 73 | + @classmethod |
| 74 | + def from_dict(cls, data: dict[str, Any]) -> "RunRecord": |
| 75 | + return cls( |
| 76 | + id=str(data["id"]), |
| 77 | + task_id=str(data["task_id"]), |
| 78 | + agent=str(data.get("agent", "manual")), |
| 79 | + command=str(data.get("command", "")), |
| 80 | + status=str(data.get("status", "unknown")), |
| 81 | + started_at=str(data.get("started_at", "")), |
| 82 | + finished_at=str(data.get("finished_at", "")), |
| 83 | + prompt_path=str(data.get("prompt_path", "")), |
| 84 | + report_path=str(data.get("report_path", "")), |
| 85 | + stdout_path=str(data.get("stdout_path", "")), |
| 86 | + stderr_path=str(data.get("stderr_path", "")), |
| 87 | + diff_path=str(data.get("diff_path", "")), |
| 88 | + checks=list(data.get("checks", [])), |
| 89 | + ) |
| 90 | + |
| 91 | + def to_dict(self) -> dict[str, Any]: |
| 92 | + return { |
| 93 | + "id": self.id, |
| 94 | + "task_id": self.task_id, |
| 95 | + "agent": self.agent, |
| 96 | + "command": self.command, |
| 97 | + "status": self.status, |
| 98 | + "started_at": self.started_at, |
| 99 | + "finished_at": self.finished_at, |
| 100 | + "prompt_path": self.prompt_path, |
| 101 | + "report_path": self.report_path, |
| 102 | + "stdout_path": self.stdout_path, |
| 103 | + "stderr_path": self.stderr_path, |
| 104 | + "diff_path": self.diff_path, |
| 105 | + "checks": self.checks, |
| 106 | + } |
0 commit comments