I have been experimenting with similar idea myself. I was curious on how you handle instantiating the terminal state for new clients. Seems like you're storing a buffer [0] of past output, and replaying that?
[0] https://github.com/ekzhang/sshx/blob/91c82d46cde4d1ffa0ae34e...