import os

target = r"C:\Users\intel\AppData\Local\OptimusRuntime\Labs\AR74\12_ar88_authority_operational_closure\candidate_workspace\app\remediation\self_repair\live_shadow_hook.py"

with open(target, "r", encoding="utf-8") as f:
    content = f.read()

old_fail_block = """                    # AR-88 State Transition: SHADOW_HOOK_FAILED
                    try:
                        default_canonical_task_state_updater({
                            "task_id": tid,
                            "mission_id": snapshot.mission_id,
                            "activity_event": "SHADOW_HOOK_FAILED",
                            "error": str(ex_worker),
                            "message": f"Live shadow repair failed with exception: {ex_worker}",
                        })
                    except Exception:
                        pass"""

new_fail_block = """                    # AR-88 State Transition: SHADOW_HOOK_FAILED
                    try:
                        failed_payload = {
                            "task_id": tid,
                            "mission_id": snapshot.mission_id,
                            "activity_event": "SHADOW_HOOK_FAILED",
                            "status": "FAILED",
                            "error": str(ex_worker),
                            "message": f"Live shadow repair failed with exception: {ex_worker}",
                        }
                        if "operational_tasks" in terminal_rec:
                            failed_payload["operational_tasks"] = terminal_rec["operational_tasks"]
                        effective_updater(failed_payload)
                    except Exception as _ex_fl:
                        logger.debug(f"[LiveShadowHook] Could not record SHADOW_HOOK_FAILED: {_ex_fl}")"""

if old_fail_block in content:
    content = content.replace(old_fail_block, new_fail_block)
    with open(target, "w", encoding="utf-8") as f:
        f.write(content)
    print("SUCCESS: live_shadow_hook.py updated to route SHADOW_HOOK_FAILED through effective_updater!")
else:
    print("ERROR: old_fail_block not found in live_shadow_hook.py")

