"""Find exact data-testid values and step-index context in AG bundle."""
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()

# Find all data-testid literal values
print("=== data-testid values ===")
for m in re.finditer(r'"data-testid"\s*[,:]\s*["`]([^"`]+)["`]', content):
    print(f"  {m.group(1)}")
# Also try template literal pattern
for m in re.finditer(r"'data-testid'\s*[,:]\s*'([^']+)'", content):
    print(f"  {m.group(1)}")
# JSX pattern: data-testid="xxx"  or data-testid={xxx}
for m in re.finditer(r'data-testid[=:]["\'`]([^"\'`]{2,60})["\'`]', content):
    print(f"  {m.group(1)}")

# Find data-step-index context
print("\n=== data-step-index usage context ===")
for m in re.finditer(r'data-step-index', content):
    start = max(0, m.start() - 150)
    end = min(len(content), m.end() + 150)
    ctx = content[start:end].replace('\n', ' ')
    print(f"  ...{ctx}...")

# Find data-status context
print("\n=== data-status usage context ===")
for m in re.finditer(r'"data-status"', content):
    start = max(0, m.start() - 100)
    end = min(len(content), m.end() + 100)
    ctx = content[start:end].replace('\n', ' ')
    print(f"  ...{ctx}...")

# Find "Running" button context - what container wraps it?
print("\n=== 'Running' + 'command' nearby JSX context ===")
for m in re.finditer(r'Running.{0,3}(?:\$\{|`|\+).{0,30}command', content):
    start = max(0, m.start() - 200)
    end = min(len(content), m.end() + 200)
    ctx = content[start:end].replace('\n', ' ')
    print(f"  @{m.start()}: ...{ctx[:400]}...")

# Find "Allow" button context
print("\n=== 'Allow' button context ===")
for m in re.finditer(r'["\'`]Allow["\'`]', content):
    start = max(0, m.start() - 200)
    end = min(len(content), m.end() + 200)
    ctx = content[start:end].replace('\n', ' ')
    print(f"  @{m.start()}: ...{ctx[:400]}...")

# Find markdown rendering context  
print("\n=== Markdown rendering context ===")
for m in re.finditer(r'(?:markdown|prose|rehype|remark)', content[:500000], re.IGNORECASE):
    start = max(0, m.start() - 60)
    end = min(len(content), m.end() + 60)
    ctx = content[start:end].replace('\n', ' ')
    if 'markdown' in ctx.lower() or 'prose' in ctx.lower():
        print(f"  @{m.start()}: ...{ctx}...")

# Find text-ide pattern (old Cascade class naming)
print("\n=== text-ide patterns ===")
for m in re.finditer(r'text-ide-[a-z-]+', content):
    print(f"  {m.group(0)}")
