Return sessions sorted newest-first, optionally capped to `limit`.
(limit: int | None = None)
| 54 | |
| 55 | |
| 56 | def load_sessions(limit: int | None = None) -> list[dict[str, Any]]: |
| 57 | """Return sessions sorted newest-first, optionally capped to `limit`.""" |
| 58 | if not HISTORY_DIR.exists(): |
| 59 | return [] |
| 60 | files = sorted(HISTORY_DIR.glob("*_session.json"), reverse=True) |
| 61 | if limit is not None: |
| 62 | files = files[:limit] |
| 63 | sessions: list[dict[str, Any]] = [] |
| 64 | for session_file in files: |
| 65 | try: |
| 66 | sessions.append(json.loads(session_file.read_text(encoding="utf-8"))) |
| 67 | except Exception: |
| 68 | logger.debug("Failed to read session file: %s", session_file, exc_info=True) |
| 69 | return sessions |
| 70 | |
| 71 | |
| 72 | def count_sessions() -> int: |
no outgoing calls