DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
Block 2: backend list_all + list_progress + GET /progress endpoint
whf3fd2d8e809b5
diff --git a/deeptutor/api/routers/guided_learning.py b/deeptutor/api/routers/guided_learning.pyindex 1547c4d14..e33b0f9cb 100644--- a/deeptutor/api/routers/guided_learning.py+++ b/deeptutor/api/routers/guided_learning.py@@ -65,6 +65,12 @@ class InitModulesRequest(BaseModel):# ── Endpoints ────────────────────────────────────────────────────────────────[email protected]("/progress")+async def list_all_progress():+ service = get_learning_service()+ return service.list_progress()++@router.get("/progress/{book_id}")async def get_progress(book_id: str):if not book_id or ".." in book_id or "/" in book_id or "\\" in book_id or ":" in book_id:diff --git a/deeptutor/learning/service.py b/deeptutor/learning/service.pyindex 56d32942b..a5712a1b1 100644--- a/deeptutor/learning/service.py+++ b/deeptutor/learning/service.py@@ -113,6 +113,42 @@ class LearningService:progress.mastery_levels[kp_id] = levelprogress.updated_at = time.time()+ def list_progress(self) -> list[dict]:+ """Return summary of all book progress."""+ import logging+ logger = logging.getLogger(__name__)++ book_ids = self._store.list_all()+ summaries = []+ for bid in book_ids:+ try:+ progress = self._store.load(bid)+ if progress is None:+ continue+ # Only count KPs from current modules (exclude stale IDs)+ current_kp_ids = {+ kp.id+ for m in progress.modules+ for kp in m.knowledge_points+ }+ total_kps = len(current_kp_ids)+ mastered = sum(+ 1 for kp_id in current_kp_ids+ if progress.mastery_levels.get(kp_id, 0) >= 0.7+ )+ summaries.append({+ "book_id": progress.book_id,+ "modules_count": len(progress.modules),+ "kp_count": total_kps,+ "current_stage": progress.current_stage.value if progress.current_stage else "",+ "mastered_pct": round(mastered / total_kps * 100) if total_kps else 0,+ "updated_at": progress.updated_at,+ })+ except Exception:+ logger.warning("Failed to load progress for book %s, skipping", bid, exc_info=True)+ continue+ return summaries+def save(self, progress: LearningProgress) -> None:self._store.save(progress)diff --git a/deeptutor/learning/storage.py b/deeptutor/learning/storage.pyindex 908b42a4d..559057fce 100644--- a/deeptutor/learning/storage.py+++ b/deeptutor/learning/storage.py@@ -74,5 +74,13 @@ class LearningStore:return {}return json.loads(path.read_text(encoding="utf-8"))+ def list_all(self) -> list[str]:+ """Return all book_ids that have stored progress."""+ return sorted(+ p.stem+ for p in self._root.glob("*.json")+ if not p.name.startswith(".")+ )+__all__ = ["LearningStore"]