@liam-public/node-pty-session
v0.1.0
Published
PTY session wrapper and terminal websocket message protocol.
Readme
@liam-public/node-pty-session
PTY session wrapper and terminal websocket message protocol.
import { PtySession, parseClientMsg, encodeServerMsg } from '@liam-public/node-pty-session'
const session = new PtySession({ bin: 'bash', args: ['-l'], cwd: '/srv/work' })
session.onData((d) => ws.send(encodeServerMsg({ t: 'out', d })))
session.onExit((code) => ws.send(encodeServerMsg({ t: 'exit', code })))
ws.on('message', (raw) => {
const msg = parseClientMsg(String(raw))
if (msg?.t === 'in') session.write(msg.d)
if (msg?.t === 'resize') session.resize(msg.cols, msg.rows)
})parseClientMsg is total — it returns null for any malformed frame rather
than throwing, because frames arrive off an untrusted socket.
node-pty needs its native spawn-helper binary. If installs skip build
scripts, run npm rebuild node-pty --build-from-source.
