import json
import shutil
from datetime import datetime

base_dir = "/home/aryy/.hermes/profiles/finance/backtests/xauusd_2026/hybrid/reviews"
progress_file = f"{base_dir}/manual_replay_progress.json"
backup_file = f"{progress_file}.bak_{datetime.utcnow().strftime('%Y%m%dT%H%M%SZ')}"

shutil.copy2(progress_file, backup_file)

with open(progress_file, "r") as f:
    progress = json.load(f)

# Update cursor
progress["cursor"]["last_processed_index"] = 543
progress["cursor"]["processed_items"] = progress["cursor"].get("processed_items", 0) + 3

# Update the active run stats if available
if progress.get("runs") and len(progress["runs"]) > 0:
    active_run = progress["runs"][-1]
    
    if "stats" not in active_run:
        active_run["stats"] = {"accepted": 0, "rejected": 0, "shadow": 0, "needs_more_context": 0, "total_processed": 0}
    
    active_run["stats"]["needs_more_context"] = active_run["stats"].get("needs_more_context", 0) + 3
    active_run["stats"]["total_processed"] = active_run["stats"].get("total_processed", 0) + 3

with open(progress_file, "w") as f:
    json.dump(progress, f, indent=2)

print(f"Updated cursor to 543. Processed 3 items. Next index will be 544.")
