""" apply_sensorium_companion_patch.py — Apply the sensorium companion digest patches. Usage: python patch_v1/apply_sensorium_companion_patch.py Steps: 1. Run merge_patch_parts.py first to create merged_*.py files 2. This script copies merged files over the originals (with backups) 3. heartbeat_mixin.py and app.py require manual patching (see notes) Requirements: pip install pytesseract Pillow sounddevice soundfile faster-whisper # For OCR: install tesseract-ocr system package # On Ubuntu: sudo apt-get install tesseract-ocr # On macOS: brew install tesseract """ import os import shutil import sys PATCH_DIR = "patch_v1" BACKUP_DIR = ".backups/pre_sensorium_patch" # Files that can be fully replaced FULL_REPLACE = { "media_companion_mixin.py": "merged_media_companion_mixin.py", "sensorium_mixin.py": "merged_sensorium_mixin.py", "audition_mixin.py": "merged_audition_mixin.py", } # Files that need manual patching (method replacement or UI addition) MANUAL_PATCH = [ "heartbeat_mixin.py — replace heartbeat_action() method with heartbeat_mixin_patch.py", "app.py — add Settings UI elements from app_settings_patch.py", ] def backup_file(filepath): if not os.path.exists(filepath): return os.makedirs(BACKUP_DIR, exist_ok=True) dest = os.path.join(BACKUP_DIR, os.path.basename(filepath)) shutil.copy2(filepath, dest) print(f" Backed up {filepath} -> {dest}") def apply_full_replace(target, source): src = os.path.join(PATCH_DIR, source) if not os.path.exists(src): print(f" SKIP — source not found: {src}") print(f" Did you run merge_patch_parts.py first?") return False backup_file(target) shutil.copy2(src, target) print(f" Applied {src} -> {target}") return True def main(): print("=== Sir Radix Sensorium Companion Patch ===") print() if not os.path.isdir(PATCH_DIR): print(f"ERROR: Patch directory '{PATCH_DIR}' not found.") sys.exit(1) # Check for merged files merged_exist = any( os.path.exists(os.path.join(PATCH_DIR, f"merged_{name}")) for name in ["media_companion_mixin.py"] ) if not merged_exist: print("WARNING: No merged files found. Run this first:") print(" python patch_v1/merge_patch_parts.py") print() applied = 0 for target, source in FULL_REPLACE.items(): print(f"[{target}]") if apply_full_replace(target, source): applied += 1 print() print(f"Done. {applied}/{len(FULL_REPLACE)} files fully patched.") print() print("Manual patches still needed:") for m in MANUAL_PATCH: print(f" - {m}") print() print("Backups saved to:", BACKUP_DIR) print() print("New dependencies to install:") print(" pip install pytesseract Pillow sounddevice soundfile faster-whisper") print(" # For OCR: sudo apt-get install tesseract-ocr (Linux)") print(" # For OCR: brew install tesseract (macOS)") print() print("After patching:") print(" 1. Review changes: git diff") print(" 2. Test: python check.py") print(" 3. Start daemon and check Settings tab for sensorium toggles") if __name__ == "__main__": main()