MCPcopy Create free account
hub / github.com/Ishabdullah/Codey-v2 / save_session

Function save_session

core/sessions.py:43–65  ·  view source on GitHub ↗

Save conversation history to disk. Keeps last max_turns turns.

(history: list, project_dir: str = None, max_turns: int = 6)

Source from the content-addressed store, hash-verified

41 return SESSIONS_DIR / f"{name}_{key}.json"
42
43def save_session(history: list, project_dir: str = None, max_turns: int = 6):
44 """Save conversation history to disk. Keeps last max_turns turns."""
45 if not history:
46 return
47 path = _session_path(project_dir)
48 # Keep only recent history and redact secrets
49 keep = history[-max_turns * 2:]
50 safe_history = []
51 for turn in keep:
52 safe_turn = turn.copy()
53 safe_turn["content"] = redact_secrets(turn["content"])
54 safe_history.append(safe_turn)
55
56 data = {
57 "saved_at": datetime.now().isoformat(),
58 "project": project_dir or os.getcwd(),
59 "turns": len(safe_history) // 2,
60 "history": safe_history,
61 }
62 try:
63 path.write_text(json.dumps(data, indent=2), encoding="utf-8")
64 except Exception as e:
65 warning(f"Could not save session: {e}")
66
67def load_session(project_dir: str = None, path: str = None, max_age_hours: int = 2) -> list:
68 """Load conversation history from disk. Returns empty list if stale or missing."""

Callers 2

handle_commandFunction · 0.90
replFunction · 0.90

Calls 4

warningFunction · 0.90
_session_pathFunction · 0.85
redact_secretsFunction · 0.85
appendMethod · 0.80

Tested by

no test coverage detected