with open('src/app_controller.py', 'r', encoding='utf-8') as f:
    content = f.read()
old = " def load_context_preset(self, name: str) -> models.ContextPreset:\n  presets = self.context_preset_manager.load_all(self.project)\n  if name not in presets:\n   raise KeyError(f\"Context preset '{name}' not found.\")\n  preset = presets[name]"
new = " def load_context_preset(self, name: str) -> models.ContextPreset:\n  presets_result = self.context_preset_manager.load_all(self.project)\n  if not presets_result.ok:\n   raise RuntimeError(f\"Failed to load context presets: {presets_result.errors}\")\n  presets = presets_result.data\n  if name not in presets:\n   raise KeyError(f\"Context preset '{name}' not found.\")\n  preset = presets[name]"
assert old in content, 'old not found'
content = content.replace(old, new)
with open('src/app_controller.py', 'w', encoding='utf-8') as f:
    f.write(content)
print('Done')
