#!/usr/bin/env bash
set -euo pipefail
ab(){ npx --yes agent-browser --session issue7568-final --cdp 19470 "$@"; }
date -u
ab eval --stdin < /tmp/issue7568-after-evidence/inspect.js
python3 - <<'PY'
from pathlib import Path
import re
p=Path.home()/'.ssh/config';s=p.read_text();s=s.replace('User issue7568-nonexistent','User issue7568-still-nonexistent').replace('Port 24579','Port 24578');p.write_text(s)
PY
date -u
ab eval '(async()=>{const c=JSON.parse(await window.desktopBridge.getConnectionCatalog());const out=[];for(const p of c.profiles.filter(p=>p.target.alias?.includes("long-discovered"))){await window.desktopBridge.disconnectSshEnvironment(p.target);const b=await window.desktopBridge.ensureSshEnvironment(p.target,{issuePairingToken:false});const d=await window.desktopBridge.fetchSshEnvironmentDescriptor(b.httpBaseUrl);const saved=JSON.parse(await window.desktopBridge.getConnectionCatalog()).profiles.find(x=>x.connectionId===p.connectionId);out.push({connectionId:saved.connectionId,environmentId:saved.environmentId,descriptor:d.environmentId??d.id,savedTarget:saved.target,resolvedTarget:b.target});}return out;})()'
