chasm-cli 1.5.4

Universal chat session manager - harvest, merge, and analyze AI chat history from VS Code, Cursor, and other editors
Documentation
"""Compare ALL chat-related DB entries between working and broken workspaces."""
import json
import sqlite3
import base64

WORKING_DB = r'C:\Users\adamm\AppData\Roaming\Code\User\workspaceStorage\82cdabb21413f2ff42168423e82c8bdf\state.vscdb'
BROKEN_DB = r'C:\Users\adamm\AppData\Roaming\Code\User\workspaceStorage\5ec71800c69c79b96b06a37e38537907\state.vscdb'

def dump_keys(label, db_path, patterns=None):
    print(f"\n{'='*60}")
    print(f"  {label}")
    print(f"{'='*60}")
    conn = sqlite3.connect(db_path)
    cur = conn.cursor()
    
    # Get ALL keys that contain chat, session, agent, copilot
    cur.execute("SELECT key, length(value) FROM ItemTable ORDER BY key")
    rows = cur.fetchall()
    
    chat_keys = []
    for key, vlen in rows:
        k_lower = key.lower()
        if any(p in k_lower for p in ['chat', 'session', 'agent', 'copilot', 'model.cache']):
            chat_keys.append((key, vlen))
    
    print(f"\nChat/session-related keys ({len(chat_keys)} total):")
    for key, vlen in chat_keys:
        print(f"  {key}: {vlen} bytes")
    
    # Dump the actual values for key ones
    important_keys = [
        'agentSessions.model.cache',
        'chat.ChatSessionStore.index',
        'chat.editor.ChatSessionStore.index',
        'interactive.sessions',
    ]
    
    # Also find any other keys with 'agent' or 'chat' prefix
    for key, vlen in chat_keys:
        if key not in important_keys and vlen < 5000:
            important_keys.append(key)
    
    for key in important_keys:
        cur.execute("SELECT value FROM ItemTable WHERE key=?", (key,))
        row = cur.fetchone()
        if row:
            val = row[0]
            try:
                parsed = json.loads(val)
                formatted = json.dumps(parsed, indent=2)
                if len(formatted) > 2000:
                    formatted = formatted[:2000] + "\n... (truncated)"
                print(f"\n--- {key} ---")
                print(formatted)
            except:
                print(f"\n--- {key} ---")
                print(f"  (raw, {len(val)} bytes): {val[:500]}")
    
    conn.close()

dump_keys("WORKING (chasm)", WORKING_DB)
dump_keys("BROKEN (Agentic)", BROKEN_DB)