protocol

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package protocol defines wire protocol message types matching @pocketmux/shared.

All struct field names use msgpack tags matching the camelCase names from the TypeScript protocol types. This ensures cross-language compatibility.

Index

Constants

View Source
const MaxMessageSize = 1 << 20 // 1 MiB

MaxMessageSize is the maximum size in bytes for an incoming protocol message. Terminal I/O data is typically < 4KB. This limit provides defense-in-depth against malicious or malformed messages causing memory exhaustion. The WebRTC DataChannel has its own limits, but validating here catches issues regardless of transport.

Variables

This section is empty.

Functions

func Encode

func Encode(msg Message) ([]byte, error)

Encode serializes a protocol message to MessagePack binary.

func IsEvent

func IsEvent(msg Message) bool

IsEvent returns true if the message is a Host → Mobile event.

func IsRequest

func IsRequest(msg Message) bool

IsRequest returns true if the message is a Mobile → Host request.

Types

type AttachRequest

type AttachRequest struct {
	Type        string `msgpack:"type"`
	PaneID      string `msgpack:"paneId"`
	Cols        int    `msgpack:"cols"`
	Rows        int    `msgpack:"rows"`
	Reattach    bool   `msgpack:"reattach,omitempty"`
	Compression string `msgpack:"compression,omitempty"`
}

AttachRequest attaches to a specific pane with the given terminal dimensions.

func (*AttachRequest) MessageType

func (m *AttachRequest) MessageType() string

type AttachedEvent

type AttachedEvent struct {
	Type        string `msgpack:"type"`
	PaneID      string `msgpack:"paneId"`
	Compression string `msgpack:"compression,omitempty"`
}

AttachedEvent confirms successful pane attachment.

func (*AttachedEvent) MessageType

func (m *AttachedEvent) MessageType() string

type CreateSessionRequest added in v0.2.0

type CreateSessionRequest struct {
	Type string `msgpack:"type"`
}

CreateSessionRequest requests creation of a new tmux session.

func (*CreateSessionRequest) MessageType added in v0.2.0

func (m *CreateSessionRequest) MessageType() string

type DetachRequest

type DetachRequest struct {
	Type string `msgpack:"type"`
}

DetachRequest detaches from the currently attached pane.

func (*DetachRequest) MessageType

func (m *DetachRequest) MessageType() string

type DetachedEvent

type DetachedEvent struct {
	Type string `msgpack:"type"`
}

DetachedEvent confirms pane detachment.

func (*DetachedEvent) MessageType

func (m *DetachedEvent) MessageType() string

type ErrorEvent

type ErrorEvent struct {
	Type    string `msgpack:"type"`
	Code    string `msgpack:"code"`
	Message string `msgpack:"message"`
}

ErrorEvent reports an error to the mobile client.

func (*ErrorEvent) MessageType

func (m *ErrorEvent) MessageType() string

type InputRequest

type InputRequest struct {
	Type string `msgpack:"type"`
	Data []byte `msgpack:"data"`
}

InputRequest sends terminal input data (raw bytes) to the attached pane.

func (*InputRequest) MessageType

func (m *InputRequest) MessageType() string

type KillSessionRequest

type KillSessionRequest struct {
	Type    string `msgpack:"type"`
	Session string `msgpack:"session"`
}

KillSessionRequest kills a tmux session by ID.

func (*KillSessionRequest) MessageType

func (m *KillSessionRequest) MessageType() string

type ListSessionsRequest

type ListSessionsRequest struct {
	Type string `msgpack:"type"`
}

ListSessionsRequest requests the full session tree from the host.

func (*ListSessionsRequest) MessageType

func (m *ListSessionsRequest) MessageType() string

type Message

type Message interface {
	MessageType() string
}

Message is implemented by all protocol messages.

func Decode

func Decode(data []byte) (Message, error)

Decode deserializes MessagePack binary to a protocol message. It inspects the "type" field first, then decodes into the correct Go struct. Returns an error if the message exceeds MaxMessageSize.

type OutputCompressor added in v0.0.4

type OutputCompressor struct {
	// contains filtered or unexported fields
}

OutputCompressor wraps a stateful flate.Writer for compressing terminal output across multiple messages. The LZ77 sliding window persists between Compress() calls, allowing repeated patterns (ANSI escapes, shell prompts, common paths) to compress increasingly well over time.

func NewOutputCompressor added in v0.0.4

func NewOutputCompressor() *OutputCompressor

NewOutputCompressor creates a new stateful compressor using deflate level 6.

func (*OutputCompressor) Close added in v0.0.4

func (c *OutputCompressor) Close() error

Close releases resources held by the compressor.

func (*OutputCompressor) Compress added in v0.0.4

func (c *OutputCompressor) Compress(data []byte) ([]byte, error)

Compress compresses data through the stateful deflate stream. Uses sync flush to emit a sync marker so the decompressor can produce output immediately without waiting for more data. Returns a copy of the compressed bytes (the internal buffer is reused across calls).

type OutputEvent

type OutputEvent struct {
	Type string `msgpack:"type"`
	Data []byte `msgpack:"data"`
}

OutputEvent sends terminal output data (raw bytes) from the attached pane.

func (*OutputEvent) MessageType

func (m *OutputEvent) MessageType() string

type PaneClosedEvent

type PaneClosedEvent struct {
	Type   string `msgpack:"type"`
	PaneID string `msgpack:"paneId"`
}

PaneClosedEvent reports that a specific pane has exited.

func (*PaneClosedEvent) MessageType

func (m *PaneClosedEvent) MessageType() string

type PaneSize

type PaneSize struct {
	Cols int `msgpack:"cols"`
	Rows int `msgpack:"rows"`
}

PaneSize holds terminal dimensions.

type PingRequest

type PingRequest struct {
	Type string `msgpack:"type"`
}

PingRequest is a latency measurement request.

func (*PingRequest) MessageType

func (m *PingRequest) MessageType() string

type PongEvent

type PongEvent struct {
	Type    string `msgpack:"type"`
	Latency int    `msgpack:"latency"`
}

PongEvent responds to a ping with latency measurement.

func (*PongEvent) MessageType

func (m *PongEvent) MessageType() string

type ResizeRequest

type ResizeRequest struct {
	Type string `msgpack:"type"`
	Cols int    `msgpack:"cols"`
	Rows int    `msgpack:"rows"`
}

ResizeRequest resizes the attached pane to the given dimensions.

func (*ResizeRequest) MessageType

func (m *ResizeRequest) MessageType() string

type SessionCreatedEvent added in v0.2.0

type SessionCreatedEvent struct {
	Type    string      `msgpack:"type"`
	Session TmuxSession `msgpack:"session"`
}

SessionCreatedEvent reports that a new tmux session was created.

func (*SessionCreatedEvent) MessageType added in v0.2.0

func (m *SessionCreatedEvent) MessageType() string

type SessionEndedEvent

type SessionEndedEvent struct {
	Type    string `msgpack:"type"`
	Session string `msgpack:"session"`
}

SessionEndedEvent reports a session was killed or exited.

func (*SessionEndedEvent) MessageType

func (m *SessionEndedEvent) MessageType() string

type SessionsEvent

type SessionsEvent struct {
	Type            string        `msgpack:"type"`
	Sessions        []TmuxSession `msgpack:"sessions"`
	AgentVersion    string        `msgpack:"agentVersion,omitempty"`
	UpdateAvailable string        `msgpack:"updateAvailable,omitempty"` // latest version if update available, empty otherwise
}

SessionsEvent returns the full session tree. AgentVersion and UpdateAvailable are optional fields added for update notifications to the mobile app.

func (*SessionsEvent) MessageType

func (m *SessionsEvent) MessageType() string

type TmuxPane

type TmuxPane struct {
	ID             string   `msgpack:"id"`
	Index          int      `msgpack:"index"`
	Active         bool     `msgpack:"active"`
	Size           PaneSize `msgpack:"size"`
	Title          string   `msgpack:"title"`
	CurrentCommand string   `msgpack:"currentCommand"`
}

TmuxPane represents a pane within a tmux window.

type TmuxSession

type TmuxSession struct {
	ID   string `msgpack:"id"`
	Name string `msgpack:"name"`
	// CreatedAt is a Unix timestamp in seconds.
	CreatedAt int64        `msgpack:"createdAt"`
	Windows   []TmuxWindow `msgpack:"windows"`
	// LastActivityAt is a Unix timestamp in seconds.
	LastActivityAt int64 `msgpack:"lastActivityAt"`
	Attached       bool  `msgpack:"attached"`
}

TmuxSession represents a tmux session with its window tree.

type TmuxWindow

type TmuxWindow struct {
	ID     string     `msgpack:"id"`
	Name   string     `msgpack:"name"`
	Index  int        `msgpack:"index"`
	Active bool       `msgpack:"active"`
	Panes  []TmuxPane `msgpack:"panes"`
}

TmuxWindow represents a window within a tmux session.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL