A few years ago, I did a prototype that allowed you to do two things in the FreeBSD kernel:
The first was a backwards-compatible content-type negotiation protocol for pipes. If either end did a read / write, it would fail and report that the other end didn’t support content negotiation. But if both did, the sender could provide a list of types it could produce and the receiver could select the one that it wanted. I also made libxo use this, so piping any libxo command to something else could transparently have the target select the text, HTML, XML, or JSON version.
The next part was to add the ability to use the pty layer to create pipes. The pty client could request a new pipe and get an additional communication channel to the terminal emulator. This let you do things like provide HTML-formatted output for the terminal to render in a web view in addition to the text output, to provide screen-reader text for TUIs, and so on.
This is quite easy to tunnel over ssh because ssh already supports multiple channels, you can then wire them either to the host’s version of the pty layer or to some additional out-of-band mechanism.