# -*- coding: utf-8 -*-
"""Fix: add missing ) after VD Set closing ]"""
import re
IDX = r"D:\work buddy\2026-11-05-14-15-52\index_main.html"
html = open(IDX, "r", encoding="utf-8").read()

# Current broken: ...,"details/duke-msec.html"];
# Need: ...,"details/duke-msec.html"]);
old = '"details/duke-msec.html"];'
new = '"details/duke-msec.html"]);'

if old in html:
    html = html.replace(old, new, 1)
    open(IDX, "w", encoding="utf-8").write(html)
    print("OK: added missing ) after VD Set")
else:
    print("Pattern not found; checking...")
    # Find the VD set end and inspect
    m = re.search(r'VERIFIED_DETAILS\s*=\s*new\s*Set\s*\(', html)
    s = m.end()
    d = 1
    i = s
    while i < len(html) and d > 0:
        c = html[i]
        if c == '(': d += 1
        elif c == ')': d -= 1
        i += 1
    print("VD Set ends at", i-1, "context:", repr(html[i-10:i+10]))
