import urllib.request, json, urllib.error, re

# Test dashboard API with the session token from the root page
# First get the root page to find the token
req = urllib.request.Request("http://127.0.0.1:9119/")
try:
    with urllib.request.urlopen(req, timeout=30) as r:
        html = r.read().decode()
        print("root page length:", len(html))
        # Look for token in HTML
        match = re.search(r"window\.__CLAUDE_SESSION_TOKEN__\s*=\s*[\"'](.+?)[\"']", html)
        if match:
            token = match.group(1)
            print("Found token:", token[:20] + "...")
        else:
            print("No token found in HTML")
except Exception as e:
    print("root page error:", e)