from pathlib import Path path = Path("app/product/final_product_ui.py") text = path.read_text(encoding="utf-8-sig") text = text.replace("\ufeff", "") stable_js = r''' ''' if "stable-button-recovery-layer" not in text: idx = text.rfind("") if idx == -1: raise RuntimeError("Could not find in final_product_ui.py") text = text[:idx] + stable_js + "\n" + text[idx:] print("Added stable button recovery layer.") else: print("Stable button recovery layer already exists.") path.write_text(text, encoding="utf-8") print("Phase 41B complete.")