chasm-cli 1.5.4

Universal chat session manager - harvest, merge, and analyze AI chat history from VS Code, Cursor, and other editors
Documentation
"""Check if VS Code created NEW workspace hashes for the project folders."""
import json, sqlite3, os, time
from pathlib import Path

WS = Path(r"C:\Users\adamm\AppData\Roaming\Code\User\workspaceStorage")

TARGET_FOLDERS = {
    "Agentic": r"C:\Users\adamm\dev\nervosys\desktop\Agentic",
    "AgenticFortress": r"C:\Users\adamm\dev\nervosys\manufacturing\facilities\AgenticFortress",
    "AgentQ": r"C:\Users\adamm\dev\nervosys\desktop\AgentQ",
    "AIModelVault": r"C:\Users\adamm\dev\nervosys\ai\AIModelVault",
    "Cyborg": r"C:\Users\adamm\dev\nervosys\modeling\erp_wms\Cyborg",
    "Hyperlight": r"C:\Users\adamm\dev\nervosys\web\Hyperlight",
    "Framewerx": r"C:\Users\adamm\dev\nervosys\ai\Framewerx",
    "OverwatchGCS": r"C:\Users\adamm\dev\nervosys\commandcontrol\OverwatchGCS",
    "Rodeo": r"C:\Users\adamm\dev\nervosys\cli\Rodeo",
    "SentryWall": r"C:\Users\adamm\dev\nervosys\cybersecurity\SentryWall",
    "XWERX_B001": r"C:\Users\adamm\dev\nervosys\manufacturing\facilities\XWERX_B001",
}

KNOWN_HASHES = {
    "Agentic": "5ec71800c69c79b96b06a37e38537907",
    "AgenticFortress": "724ab159cbc91cdd8242d9b5aa690c3b",
    "AgentQ": "0e71f7221cc2ffe28e938bc38efeb8c5",
    "AIModelVault": "56cb9246fe0ba2d5debb96e9135e5c95",
    "Cyborg": "cc60bfebb242bac1578d7b49a44033db",
    "Hyperlight": "1c25bd214fe52001bcec2ffa40836c82",
    "Framewerx": "c8f466664b769ee6a567242b576fb955",
    "OverwatchGCS": "c7aca0a33bd40b6a718d04f88c333669",
    "Rodeo": "9190fefe3d0b856449a6bdacdca0c1ef",
    "SentryWall": "6c88aa026ece73be4109fe5008915801",
    "XWERX_B001": "05db3446971342e7f6a633a732955575",
}

now = time.time()

print("=" * 70)
print("SCAN: ALL workspace hashes that reference target folders")
print("=" * 70)

# Scan ALL workspace storage directories
folder_to_hashes = {}  # folder_path -> [(hash, modified_time)]

for entry in WS.iterdir():
    if not entry.is_dir():
        continue
    wj = entry / "workspace.json"
    if not wj.exists():
        continue
    try:
        with open(wj, "r", encoding="utf-8") as f:
            data = json.load(f)
        folder = data.get("folder")
        if not folder:
            continue
        
        # Normalize the folder URI
        folder_path = folder
        if folder.startswith("file:///"):
            # Convert file URI to path
            folder_path = folder.replace("file:///", "").replace("/", "\\")
            # Handle URL-encoded characters
            import urllib.parse
            folder_path = urllib.parse.unquote(folder_path)
            # Capitalize drive letter
            if len(folder_path) > 1 and folder_path[1] == ':':
                folder_path = folder_path[0].upper() + folder_path[1:]
        
        # Check if this references any of our target folders
        folder_lower = folder_path.lower().rstrip("\\")
        for name, target in TARGET_FOLDERS.items():
            target_lower = target.lower().rstrip("\\")
            if folder_lower == target_lower or folder_lower.endswith(target_lower.split("\\")[-1]):
                hash_dir = entry.name
                mtime = entry.stat().st_mtime
                age_hours = (now - mtime) / 3600
                
                if name not in folder_to_hashes:
                    folder_to_hashes[name] = []
                folder_to_hashes[name].append((hash_dir, age_hours, folder_path))
    except Exception as e:
        continue

for name in sorted(TARGET_FOLDERS.keys()):
    known = KNOWN_HASHES.get(name, "?")
    matches = folder_to_hashes.get(name, [])
    
    print(f"\n{name} (repaired hash: {known[:12]}...):")
    print(f"  Target: {TARGET_FOLDERS[name]}")
    
    if not matches:
        print(f"  *** NO WORKSPACE HASH FOUND for this folder! ***")
    elif len(matches) == 1:
        h, age, path = matches[0]
        is_known = h == known
        print(f"  Found: {h} (modified {age:.1f}h ago) {'<== REPAIRED' if is_known else '*** DIFFERENT HASH ***'}")
        print(f"    workspace.json folder: {path}")
    else:
        print(f"  MULTIPLE hashes found ({len(matches)}):")
        for h, age, path in sorted(matches, key=lambda x: x[1]):
            is_known = h == known
            print(f"    {h} (modified {age:.1f}h ago) {'<== REPAIRED' if is_known else '*** DIFFERENT ***'}")
            print(f"      folder: {path}")


print("\n" + "=" * 70)
print("CHECK: Most recently modified workspace hash for each project")
print("=" * 70)

# Also look for workspace hashes that were created/modified AFTER our repairs
for name, (h_known, sid) in [("Agentic", ("5ec71800c69c79b96b06a37e38537907", "6be29cba")), 
                               ("Cyborg", ("cc60bfebb242bac1578d7b49a44033db", "527646cd")),
                               ("XWERX_B001", ("05db3446971342e7f6a633a732955575", "6ecda819"))]:
    known_dir = WS / h_known
    if known_dir.exists():
        # Check state.vscdb modification time
        db = known_dir / "state.vscdb"
        if db.exists():
            db_age = (now - db.stat().st_mtime) / 3600
            print(f"\n{name} ({h_known[:12]}): state.vscdb modified {db_age:.1f}h ago")
            
            # Check if index still has our sessions
            conn = sqlite3.connect(str(db))
            cur = conn.cursor()
            cur.execute("SELECT value FROM ItemTable WHERE key='chat.ChatSessionStore.index'")
            row = cur.fetchone()
            if row:
                idx = json.loads(row[0])
                entries = idx.get("entries", {})
                print(f"  Index has {len(entries)} entries")
                for eid, entry in entries.items():
                    empty = entry.get("isEmpty", True)
                    title = entry.get("title", "?")[:40]
                    print(f"    {eid[:8]} empty={empty} \"{title}\"")
            conn.close()
        
        # Check chatSessions directory
        cs = known_dir / "chatSessions"
        if cs.exists():
            files = list(cs.iterdir())
            print(f"  chatSessions/ has {len(files)} files")
        else:
            print(f"  chatSessions/ NOT FOUND!")

print("\n=== DONE ===")