with open('/app/working/workspaces/default/build_merged.js', 'r') as f:
    content = f.read()

# Track parentheses depth, find where it becomes unbalanced
depth = 0
in_single = False
in_double = False
in_template = False
in_comment_line = False
in_block_comment = False
last_d1_line = 0

for i, ch in enumerate(content):
    line_num = content[:i].count('\n') + 1
    
    # Skip strings
    if in_single:
        if ch == '\\' and i+1 < len(content):
            continue
        if ch == "'":
            in_single = False
        continue
    if in_double:
        if ch == '\\' and i+1 < len(content):
            continue
        if ch == '"':
            in_double = False
        continue
    if in_template:
        if ch == '`':
            in_template = False
        continue
    
    if ch == "'":
        in_single = True
    elif ch == '"':
        in_double = True
    elif ch == '`':
        in_template = True
    elif ch == '(':
        depth += 1
        last_d1_line = line_num
    elif ch == ')':
        depth -= 1
        if depth < 0:
            print(f"Line {line_num}: depth went NEGATIVE (unmatched closing paren)")
            # Show context
            start = max(0, i-100)
            end = min(len(content), i+100)
            print(f"Context: ...{repr(content[start:end])}...")
            depth = 0

print(f"Final depth: {depth}")
if depth > 0:
    print(f"Last time depth was 1: around line {last_d1_line}")
