fix(webcrt): replay login banner/prompt on attach

Drain and nudge the device prompt after Netmiko login, replay bootstrap stdout when the WebSocket attaches, and surface connect errors in the terminal pane.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-07-29 18:54:59 +08:00
parent 8e3bed562f
commit 30f2db9708
6 changed files with 87 additions and 9 deletions

View file

@ -93,9 +93,27 @@ async def websocket_session(websocket: WebSocket, session_id: str) -> None:
"protocol": sess.protocol,
"cols": sess.cols,
"rows": sess.rows,
"device_type": sess.device_type,
"vendor": sess.vendor,
}
)
# Replay post-login banner/prompt so the UI is not blank until the user presses Enter.
bootstrap = bytes(sess.bootstrap_output or b"")
if bootstrap:
try:
await websocket.send_json(
{"type": "stdout", "data": bootstrap.decode("utf-8", errors="replace")}
)
except Exception:
_log.debug("webcrt bootstrap send failed session=%s", session_id, exc_info=True)
else:
# Last resort: ask the device to redraw the prompt into the live reader.
try:
await asyncio.get_running_loop().run_in_executor(None, sess.write_stdin, "\r")
except Exception:
pass
stop = asyncio.Event()
async def pump_stdout() -> None: