26e2baa89c
Before: openTerminal() never closed the previous WebSocket. After A→B→A, two WS connections to session A both wrote to _term → double keystroke echoes. Rapid switches triggered a CONNECTING-state send error and reconnect loop. After: openTerminal() nulls _currentSession, clears reconnect timer, and closes _ws before opening a new connection. connect() event handlers now capture the WS instance in a local const and check 'ws !== _ws' on entry so stale connections silently ignore all events. Tests: three new regression tests verify: - openTerminal() calls close() on the previous WS (Bug 1) - stale open handler does not send on new WS after switch (Bug 2) - stale close handler does not schedule reconnect after switch (Bug 2)