from pathlib import Path import re file_path = Path('src/app_controller.py') lines = file_path.read_text(encoding='utf-8').splitlines() # We know the issue starts around line 1405 where `def cb_exit_prior_session(self):` is indented with 2 spaces. # We will unindent everything that has 2 or more spaces back by 1 space, # until we hit a line that is correctly 1-space indented (like `def start_services` or similar, if it exists). # Actually, let's just use a state machine: find `def cb_exit_prior_session` and unindent everything until `def start_services` or end of file. in_bad_block = False for i, line in enumerate(lines): if re.match(r'^ def cb_exit_prior_session\(self\):', line): in_bad_block = True if in_bad_block: if line.startswith(' '): lines[i] = line[1:] elif line.startswith(' '): pass # Keep it if it's already 1 space # Stop if we hit a properly indented class method if in_bad_block and re.match(r'^ def start_services', line): in_bad_block = False file_path.write_text('\n'.join(lines) + '\n', encoding='utf-8') print("Scope repair complete.")