import json from pathlib import Path from typing import Any def _tasks_dir() -> Path: return Path(__file__).resolve().parent.parent / "tasks" def load_tasks(difficulty: str = "easy") -> list[dict[str, Any]]: file_path = _tasks_dir() / f"{difficulty}.json" if not file_path.exists(): raise FileNotFoundError(f"Task file not found: {file_path}") with file_path.open("r", encoding="utf-8") as handle: payload = json.load(handle) if isinstance(payload, dict) and "tasks" in payload: return payload["tasks"] if isinstance(payload, list): return payload raise ValueError(f"Unsupported task format in {file_path}")