from pathlib import Path
import shutil
root=Path('/home/lighthouse/esp32-dev/.cache/speech-playback-diagnostics-20261006')
line=next(x for x in (root/'firmware/build/CMakeCache.txt').read_text().splitlines() if x.startswith('SDKCONFIG:'))
p=Path(line.split('=',1)[1]);assert p.is_relative_to(root/'.cache/sdkconfig')
s=p.read_text();assert 'CONFIG_LWIP_TCP_SACK_OUT=y' in s and 'CONFIG_LWIP_TCP_OOSEQ_MAX_PBUFS=12' in s
backup=root/'.cache/speech-diagnostics/sdkconfig-sack12-window64.private';assert not backup.exists();shutil.copyfile(p,backup);backup.chmod(0o600)
old='CONFIG_LWIP_TCP_WND_DEFAULT=65535';assert s.count(old)==1;p.write_text(s.replace(old,'CONFIG_LWIP_TCP_WND_DEFAULT=16384',1))
print('Only TCP receive window changed: 65535 -> 16384; SACK and OOSEQ12 preserved')
