"""Persistent Task Center store.""" from __future__ import annotations import json from pathlib import Path from typing import Any class TaskStore: def __init__(self, root: str = "runtime/task-center"): self.root = Path(root) self.root.mkdir(parents=True, exist_ok=True) self.path = self.root / "tasks.jsonl" def append(self, task: dict[str, Any]) -> None: with self.path.open("a", encoding="utf-8") as f: f.write(json.dumps(task, ensure_ascii=False) + "\n") def list_all(self) -> list[dict[str, Any]]: if not self.path.exists(): return [] return [json.loads(line) for line in self.path.read_text(encoding="utf-8").splitlines() if line] def latest(self) -> list[dict[str, Any]]: return self.list_all()[-100:] __all__ = ["TaskStore"]