MCPcopy Create free account
hub / github.com/OpenOSINT/OpenOSINT / save_session

Function save_session

openosint/session_history.py:38–53  ·  view source on GitHub ↗

Save a session record to disk, pruning oldest files if over MAX_SESSIONS.

(record: SessionRecord)

Source from the content-addressed store, hash-verified

36
37
38def save_session(record: SessionRecord) -> Path:
39 """Save a session record to disk, pruning oldest files if over MAX_SESSIONS."""
40 _ensure_dir()
41 safe_ts = record.timestamp.replace(":", "-")
42 path = HISTORY_DIR / f"{safe_ts}_session.json"
43 path.write_text(json.dumps(asdict(record), indent=2), encoding="utf-8")
44
45 all_files = sorted(HISTORY_DIR.glob("*_session.json"))
46 while len(all_files) > MAX_SESSIONS:
47 try:
48 all_files[0].unlink()
49 except Exception:
50 logger.debug("Failed to prune old session file.", exc_info=True)
51 all_files = all_files[1:]
52
53 return path
54
55
56def load_sessions(limit: int | None = None) -> list[dict[str, Any]]:

Calls 1

_ensure_dirFunction · 0.85