"""
Search AG bundle for UI component patterns, specifically:
1. Bot message container classes/selectors
2. Approval button patterns
3. Chat conversation structure
"""
import re, os, 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()
print(f"Bundle size: {len(content)} chars")

# Search for string literals containing relevant UI text
# These are the strings we SEE in the UI, so they must exist in the bundle
ui_strings = [
    'Running', 'command', 'Always run', 'Cancel',
    'Allow', 'Deny', 'content_copy',
    'Accept', 'Reject', 'Approve',
    'AI 대화', 'AI Chat', 'AI Response',
    'keyboard_arrow', 'chevron',
    'Run ', 'Send',
]

print("\n=== UI String contexts (20 chars around match) ===")
for s in ui_strings:
    # Find the string and show surrounding context
    idx = content.find(f'"{s}')
    if idx == -1:
        idx = content.find(f"'{s}")
    if idx == -1:
        idx = content.find(s)
    if idx >= 0:
        start = max(0, idx - 30)
        end = min(len(content), idx + len(s) + 50)
        ctx = content[start:end].replace('\n', ' ')
        print(f"  '{s}': ...{ctx}...")

# Specifically search for "Running" near button/onClick patterns
print("\n=== 'Running' in button context ===")
for m in re.finditer(r'Running.{0,5}command', content):
    start = max(0, m.start() - 100)
    end = min(len(content), m.end() + 100)
    ctx = content[start:end].replace('\n', ' ')
    print(f"  @{m.start()}: ...{ctx[:200]}...")

# Search for className patterns with Tailwind classes
print("\n=== Tailwind class patterns near 'message' or 'chat' ===")
for m in re.finditer(r'"((?:flex|bg-|text-|rounded|p-|m-|w-|h-)[^"]{10,200})"', content):
    cls = m.group(1)
    if any(kw in content[max(0,m.start()-200):m.start()].lower() for kw in ['message', 'chat', 'response', 'bot', 'turn', 'agent']):
        print(f"  {cls[:100]}")

# Most important: search for React component names
print("\n=== React component names containing 'Message', 'Chat', 'Turn', 'Agent' ===")
for m in re.finditer(r'(?:function|class|const|var)\s+([A-Z][a-zA-Z]*(?:Message|Chat|Turn|Agent|Conversation|Response|Approval|Pending)[A-Za-z]*)', content):
    print(f"  {m.group(1)}")

# Search for data attributes
print("\n=== data-* attributes ===")
for m in re.finditer(r'"(data-[a-z-]+)"', content):
    attr = m.group(1)
    if attr not in ('data-vscode-context',):
        print(f"  {attr}")
