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
- func Encode(kind Kind, payload []byte) []byte
- func EncodeJSON(kind Kind, v any) ([]byte, error)
- func ValidIdent(s string) bool
- func ValidateSandboxID(id string) error
- type Capability
- type Conn
- func (c *Conn) Close(reason string) error
- func (c *Conn) CloseNow() error
- func (c *Conn) Ping(ctx context.Context) error
- func (c *Conn) Pump(ctx context.Context, kind Kind, r io.Reader) int64
- func (c *Conn) Recv(ctx context.Context) (Message, error)
- func (c *Conn) Send(ctx context.Context, kind Kind, payload []byte) error
- func (c *Conn) SendJSON(ctx context.Context, kind Kind, v any) error
- type Exit
- type Fatal
- type Hello
- type Kind
- type List
- type Message
Constants ¶
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 )
const ( OpExec = "exec" OpList = "list" )
Operations a sandbox can ask for.
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.
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 EncodeJSON ¶
EncodeJSON tags a JSON-encoded control message.
func ValidIdent ¶
ValidIdent reports whether s is usable as a sandbox id or capability name.
func ValidateSandboxID ¶
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 (*Conn) Ping ¶
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 ¶
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.
type Exit ¶
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.
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 List ¶
type List struct {
Capabilities []Capability `json:"capabilities"`
}
List answers OpList.