import json
from pathlib import Path

files = [
    Path('experiments/m5/f01-f11-results.json'),
    Path('experiments/portfolio/local-recovery/local-410041/summary.json'),
    Path('experiments/portfolio/cloud-recovery/dur049-aws-20260923-full-0adbac0/network-isolation.json'),
]
terms = ('pass', 'fail', 'stale', 'fenc', 'takeover', 'recover', 'superseded', 'invariant', 'epoch')

def walk(value, path='$'):
    if isinstance(value, dict):
        for key, child in value.items():
            yield from walk(child, f'{path}.{key}')
    elif isinstance(value, list):
        for index, child in enumerate(value):
            yield from walk(child, f'{path}[{index}]')
    else:
        yield path, value

for file in files:
    print(f'\n=== {file} ===')
    if not file.exists():
        print('MISSING')
        continue
    data = json.loads(file.read_text(encoding='utf-8-sig'))
    matches = []
    for path, value in walk(data):
        rendered = str(value)
        haystack = (path + ' ' + rendered).lower()
        if any(term in haystack for term in terms):
            matches.append((path, rendered))
    print(f'matched_scalars={len(matches)}')
    for path, value in matches[:80]:
        print(f'{path} = {value}')
