import os
import json

brain_dir = r"C:\Users\Abhiram P M\.gemini\antigravity-ide\brain"
transcripts = []
for d in os.listdir(brain_dir):
    log_path = os.path.join(brain_dir, d, ".system_generated", "logs", "transcript_full.jsonl")
    if os.path.exists(log_path):
        transcripts.append(log_path)

html_contents = {}

for log_path in transcripts:
    with open(log_path, "r", encoding="utf-8") as f:
        for line in f:
            try:
                step = json.loads(line)
                
                # Check for tool responses
                if step.get("type") == "TOOL_RESPONSE" or step.get("type") == "PLANNER_RESPONSE":
                    content = step.get("content", "")
                    # Usually view_file output is in content for TOOL_RESPONSE
                    if "Showing lines 1 to" in content and "html>" in content.lower():
                        # We might have found an HTML file read
                        # But wait, view_file returns in TOOL_RESPONSE, wait...
                        pass
                
                if "tool_calls" in step:
                    pass
            except:
                pass

# Let's do a simpler text search across all jsonls for "<!DOCTYPE html>" and try to extract the surrounding string
import re
for log_path in transcripts:
    with open(log_path, "r", encoding="utf-8") as f:
        content = f.read()
        # Find all occurrences of DOCTYPE html
        matches = [m.start() for m in re.finditer(r'<!DOCTYPE html>', content, re.IGNORECASE)]
        for m in matches:
            # extract 100 chars around to see
            snippet = content[max(0, m-50):m+100]
            if 'index.html' in snippet or 'Franciscan' in content[m:m+1000]:
                print(f"Found DOCTYPE in {log_path} at {m}")
