import json, os
from rich.console import Console
SESSION_FILE = os.path.expanduser("~/.codehouse_session")

console = Console()

def load_session():
    if os.path.exists(SESSION_FILE):
        try:
            with open(SESSION_FILE, "r", encoding="utf-8") as f:
                return json.load(f)
        except Exception:
            return {}
    return {}

def save_session(obj):
    try:
        with open(SESSION_FILE, "w", encoding="utf-8") as f:
            json.dump(obj, f)
    except Exception as e:
        console.log(f"[yellow]Warning saving session:[/yellow] {e}")
