Documentation
¶
Index ¶
- Constants
- Variables
- func Encode(msg Message) ([]byte, error)
- func MarshalPayload(v interface{}) ([]byte, error)
- func UnmarshalPayload(data []byte, v interface{}) error
- type ApprovalRequest
- type ApprovalResponse
- type ErrorPayload
- type Message
- type MsgType
- type SessionCreateReq
- type SessionInfo
- type TermResize
Constants ¶
const ( // HeaderSize is type(1) + payload length(2) = 3 bytes. HeaderSize = 3 // SessionIDSize is 16 bytes (UUID without dashes). SessionIDSize = 16 // MaxPayloadSize is the maximum payload size (64KB - 1). MaxPayloadSize = 65535 )
Variables ¶
Functions ¶
func Encode ¶
Encode serializes a Message into binary format:
[1 byte type][2 bytes payload length][N bytes payload]
For terminal messages (TermOutput, TermInput, Scrollback), the payload is:
[16 bytes session ID][raw terminal bytes]
For all other messages, the payload is the raw Payload bytes (typically JSON).
func MarshalPayload ¶
MarshalPayload encodes a typed struct into JSON bytes for use in Message.Payload.
func UnmarshalPayload ¶
UnmarshalPayload decodes JSON bytes from Message.Payload into a typed struct.
Types ¶
type ApprovalRequest ¶
type ApprovalRequest struct {
ID string `json:"id"`
SessionID string `json:"session"`
Prompt string `json:"prompt"`
Context string `json:"context"`
Timestamp int64 `json:"ts"`
}
ApprovalRequest is the payload for MsgApprovalReq.
type ApprovalResponse ¶
ApprovalResponse is the payload for MsgApprovalResp.
type ErrorPayload ¶
ErrorPayload is the payload for MsgError.
type Message ¶
type Message struct {
Type MsgType
SessionID string // 16-byte UUID (no dashes) for term messages, empty for control
Payload []byte
}
Message is the envelope for all protocol messages.
type MsgType ¶
type MsgType uint8
MsgType identifies the type of message sent over WebRTC DataChannel.
const ( MsgTermOutput MsgType = 0x01 // CLI -> Phone: terminal output bytes MsgTermInput MsgType = 0x02 // Phone -> CLI: terminal input bytes MsgTermResize MsgType = 0x03 // Phone -> CLI: resize{rows, cols} MsgApprovalReq MsgType = 0x04 // CLI -> Phone: approval needed MsgApprovalResp MsgType = 0x05 // Phone -> CLI: approved/denied MsgSessionList MsgType = 0x06 // CLI -> Phone: list of sessions MsgSessionCreate MsgType = 0x07 // Phone -> CLI: create new session MsgSessionClose MsgType = 0x08 // Phone -> CLI: close session MsgSessionSwitch MsgType = 0x09 // Phone -> CLI: switch active session MsgScrollback MsgType = 0x0A // CLI -> Phone: scrollback buffer MsgPing MsgType = 0x0B // bidirectional keepalive MsgPong MsgType = 0x0C MsgError MsgType = 0x0F // error notification )
func (MsgType) IsTerminalMsg ¶
IsTerminalMsg returns true if the message carries raw terminal bytes (output or input) where Payload is raw bytes, not JSON.
type SessionCreateReq ¶
SessionCreateReq is the payload for MsgSessionCreate.
type SessionInfo ¶
type SessionInfo struct {
ID string `json:"id"`
Command string `json:"cmd"`
Status string `json:"status"` // "running", "exited"
Created int64 `json:"created"`
}
SessionInfo describes a single PTY session.
type TermResize ¶
TermResize is the payload for MsgTermResize.