#!/usr/bin/env bash
set -Eeuo pipefail

JS="/home/yeff/public_html/devon/panel/assets/js/panel.runtime.fix.20260408_1.js"

python3 - <<'PY'
from pathlib import Path
import sys

p = Path("/home/yeff/public_html/devon/panel/assets/js/panel.runtime.fix.20260408_1.js")
lines = p.read_text().splitlines()

removed = False
out = []

for i, line in enumerate(lines):
    nxt = lines[i + 1].strip() if i + 1 < len(lines) else ""
    cur = line.strip()

    # remove only the lone closing brace that sits immediately before boot()
    if (not removed) and cur == "}" and nxt == "async function boot() {":
        removed = True
        continue

    out.append(line)

if not removed:
    print("FAIL no stray brace found before async function boot()")
    sys.exit(1)

p.write_text("\n".join(out) + "\n")
print("PASS", p)
PY

echo
echo "=== validation ==="
grep -n 'async function boot' "$JS" || true
grep -n 'boot();' "$JS" || true
nl -ba "$JS" | sed -n '688,756p'
