control

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 10 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 control is the router's local control channel: JSON lines over a 0600 unix socket. The server pushes a full route.Snapshot on connect and after every change; clients send route.Command values. The TUI and the hook are clients. Nothing from Codex requests (headers, text) is on it.

Index

Constants

View Source
const EnvSocket = "CODEX_ROUTER_CONTROL"

EnvSocket names the environment variable the launcher sets for the hook and the TUI.

View Source
const PublishInterval = 50 * time.Millisecond

PublishInterval is the minimum gap between pushed snapshots per client (20 per second).

View Source
const SocketMode os.FileMode = 0o600

SocketMode is the permission the socket is created with.

View Source
const SocketName = "control.sock"

SocketName is the control socket file inside the runtime dir.

Variables

View Source
var ErrDisconnected = errors.New("control socket disconnected")

ErrDisconnected is returned by Send while the socket is down.

Functions

This section is empty.

Types

type Client

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

Client talks to a Server. It never redials: when the socket is lost, Updates closes and Send returns ErrDisconnected, so the owner redials.

func Dial

func Dial(path string) (*Client, error)

Dial connects to the socket at path. The first connect must succeed.

func (*Client) Close

func (c *Client) Close() error

Close stops the client and closes Updates.

func (*Client) Send

func (c *Client) Send(cmd route.Command) error

Send issues a command and waits for the server's ack. A server-side rejection comes back as an error.

func (*Client) Updates

func (c *Client) Updates() <-chan route.Snapshot

Updates yields every pushed snapshot. When the consumer lags, the oldest queued snapshot is dropped. The channel closes on Close or when the connection is lost.

type Handler

type Handler interface {
	Apply(c route.Command) error
	Snapshot() route.Snapshot
}

Handler is what the server drives; the route engine implements it.

type Message

type Message struct {
	Type     MessageType     `json:"type"`
	Snapshot *route.Snapshot `json:"snapshot,omitempty"`
	Error    string          `json:"error,omitempty"`
}

Message is one server-to-client line.

type MessageType

type MessageType string

MessageType tags a server-to-client line.

const (
	MessageSnapshot MessageType = "snapshot"
	MessageAck      MessageType = "ack"
	MessageError    MessageType = "error"
)

type Server

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

Server is the control socket. It pushes snapshots to every client and applies their commands through the Handler.

func Listen

func Listen(path string, h Handler) (*Server, error)

Listen binds the socket at path with mode 0600, removing a stale socket file and refusing a live one or a non-socket file. The parent dir must not be accessible to group or others: the mode is set right after bind, not at bind, so the dir closes that window.

func (*Server) Close

func (s *Server) Close() error

Close stops accepting, drops all clients and removes the socket file.

func (*Server) Publish

func (s *Server) Publish(snap route.Snapshot)

Publish records the latest snapshot and wakes every client. Bursts coalesce: a client gets the newest snapshot at most once per PublishInterval. A snapshot older than the one held lost a publish race and is dropped.

Jump to

Keyboard shortcuts

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