"""Find the exact JSX structure around Allow/Deny and message-block-bot containers."""
import re, sys, io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')

bundle_path = r"C:\Users\Variet-Worker\AppData\Local\Programs\Antigravity\resources\app\out\jetskiAgent\main.js"
content = open(bundle_path, encoding='utf-8', errors='replace').read()

# 1. Find the FULL Allow/Deny component (larger context)
print("=== Allow/Deny Component (full context) ===")
idx = content.find('label:"Allow"')
if idx >= 0:
    start = max(0, idx - 600)
    end = min(len(content), idx + 500)
    print(content[start:end])
    print("\n" + "="*80)

# 2. Find text-ide-message-block-bot-color full usage
print("\n=== text-ide-message-block-bot-color context ===")
idx = content.find('text-ide-message-block-bot-color')
if idx >= 0:
    start = max(0, idx - 400)
    end = min(len(content), idx + 400)
    print(content[start:end])
    print("\n" + "="*80)

# 3. Find data-step-index full context
print("\n=== data-step-index context ===")
idx = content.find('data-step-index')
if idx >= 0:
    start = max(0, idx - 300)
    end = min(len(content), idx + 300)
    print(content[start:end])
    print("\n" + "="*80)

# 4. Find "Running" commands JSX pattern
print("\n=== Running N command(s) full context ===")
for m in re.finditer(r'Running', content[8000000:9000000], re.IGNORECASE):
    pos = 8000000 + m.start()
    ctx = content[pos-5:pos+60]
    if 'command' in ctx.lower() or 'Command' in ctx:
        start = max(0, pos - 300)
        end = min(len(content), pos + 300)
        print(f"@{pos}: {content[start:end]}")
        print("\n---\n")

# 5. Find the main conversation/chat container structure
print("\n=== Conversation scroll/container patterns ===")
for pat in ['scroll-restoration', 'data-scroll', 'overflow-y-auto.*conversation', 'chatScrollContainer']:
    for m in re.finditer(pat, content, re.IGNORECASE):
        start = max(0, m.start() - 200)
        end = min(len(content), m.end() + 200)
        print(f"Pattern '{pat}' @{m.start()}: ...{content[start:end][:400]}...")
        print()
