protocol

package
v0.0.0-...-d24c1b3 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package protocol defines the agentfleet wire protocol: the messages a sandbox and a hub exchange over one websocket connection per call.

Every protocol message is one websocket binary message. The first byte is the kind; the rest is the payload — raw bytes for the standard streams, JSON for everything else.

Index

Constants

View Source
const (
	// ChunkSize is how much of a standard stream moves in one message.
	ChunkSize = 32 << 10
	// ReadLimit is the largest message either side accepts. It leaves room
	// for a ChunkSize payload and for control messages to grow.
	ReadLimit = 1 << 20
)
View Source
const (
	OpExec = "exec"
	OpList = "list"
)

Operations a sandbox can ask for.

View Source
const ExitAgentfleet = 125

ExitAgentfleet is the exit code for agentfleet's own failures — an unreachable hub, an unknown capability, a protocol mismatch. Any other code the sandbox reports came from the host binary itself.

View Source
const Version = "agentfleet/1"

Version is the protocol both sides must agree on. A hub rejects any other version by name rather than failing in some stranger way later.

Variables

This section is empty.

Functions

func Encode

func Encode(kind Kind, payload []byte) []byte

Encode tags a payload with its kind.

func EncodeJSON

func EncodeJSON(kind Kind, v any) ([]byte, error)

EncodeJSON tags a JSON-encoded control message.

func ValidIdent

func ValidIdent(s string) bool

ValidIdent reports whether s is usable as a sandbox id or capability name.

func ValidateSandboxID

func ValidateSandboxID(id string) error

ValidateSandboxID checks the id a sandbox announces. A sandbox picks its own id, so the hub applies this to what arrives on the wire and the sandbox's own config applies it before dialling — one rule and one message, because the person who has to fix it reads whichever of the two happens to complain.

Types

type Capability

type Capability struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
}

Capability is one entry of the listing.

type Conn

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

Conn is a websocket carrying protocol messages.

The hub writes from three places at once — the stdout pump, the stderr pump and whoever reports the exit — so writes are serialized here rather than left to chance.

func NewConn

func NewConn(ws *websocket.Conn) *Conn

NewConn wraps a websocket connection.

func (*Conn) Close

func (c *Conn) Close(reason string) error

Close ends the connection politely.

func (*Conn) CloseNow

func (c *Conn) CloseNow() error

CloseNow drops the connection without a handshake.

func (*Conn) Ping

func (c *Conn) Ping(ctx context.Context) error

Ping sends a ping and waits for the pong, so that a peer which vanished without closing its side is noticed. It does not bound how long a call runs.

func (*Conn) Pump

func (c *Conn) Pump(ctx context.Context, kind Kind, r io.Reader) int64

Pump forwards r to the peer as kind messages until r ends or the peer stops listening, and reports how many bytes it moved.

The read buffer reserves its first byte for the kind tag, so a chunk travels from the pipe to the socket without being copied into a second buffer on the way. The websocket library masks into a buffer of its own, so it never writes back into this one.

func (*Conn) Recv

func (c *Conn) Recv(ctx context.Context) (Message, error)

Recv reads the next message.

func (*Conn) Send

func (c *Conn) Send(ctx context.Context, kind Kind, payload []byte) error

Send writes one message.

func (*Conn) SendJSON

func (c *Conn) SendJSON(ctx context.Context, kind Kind, v any) error

SendJSON writes one control message.

type Exit

type Exit struct {
	Code   int `json:"code"`
	Signal int `json:"signal,omitempty"`
}

Exit reports how the host binary ended. Signal is set instead of Code when the binary was killed, and Status turns it into 128+N.

func (Exit) Status

func (e Exit) Status() int

Status is the exit code this ending becomes: a signalled binary is reported as 128+N, the way a shell reports it. The sandbox exits with this and the hub logs it, so the rule lives here rather than in each of them.

type Fatal

type Fatal struct {
	Message string `json:"message"`
}

Fatal is agentfleet itself failing: the sandbox prints Message and exits 125.

type Hello

type Hello struct {
	Protocol string   `json:"protocol"`
	Sandbox  string   `json:"sandbox"`
	Op       string   `json:"op"`
	Name     string   `json:"name,omitempty"`
	Args     []string `json:"args,omitempty"`
}

Hello is the first message of every connection.

type Kind

type Kind byte

Kind is the type tag carried in the first byte of every message.

const (
	KindHello    Kind = 0x01
	KindStdin    Kind = 0x02
	KindStdinEOF Kind = 0x03

	KindStdout Kind = 0x11
	KindStderr Kind = 0x12
	KindExit   Kind = 0x13
	KindFatal  Kind = 0x14
	KindList   Kind = 0x15
)

func (Kind) String

func (k Kind) String() string

type List

type List struct {
	Capabilities []Capability `json:"capabilities"`
}

List answers OpList.

type Message

type Message struct {
	Kind Kind
	Data []byte
}

Message is a decoded wire message. Data is the payload without the tag.

func Decode

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

Decode splits a wire message into its kind and payload.

func (Message) JSON

func (m Message) JSON(v any) error

JSON decodes the payload of a control message.

Jump to

Keyboard shortcuts

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