Documentation
¶
Overview ¶
Package worker is the side of a worker that runs code and moves files for a harness over one connection. A frame is one JSON header line, len body bytes, and a newline: the state file record shape, so a frame can be read and logged the same way. The body is never escaped.
Index ¶
- Constants
- Variables
- func Dial(m *mesh.Mesh, l Local)
- func Encode(w io.Writer, f Frame) error
- func File(op, path string) error
- func Install(token string) error
- func Installed() (token string, op *user.User, err error)
- func Serve(conn net.Conn, l Local) error
- func Uninstall() error
- func Work(key string, l Local) error
- type Frame
- type Header
- type Local
Constants ¶
const ( MaxBytes = 50 << 10 MaxLines = 2000 )
Result limits are opencode's: what current models handle in one result. The worker spills output over them to a file; the harness clips what it shows.
const ( Harness = "harness" Port = 7000 )
A worker dials the mesh node the coordinator names Harness, at Port, the port the design names. The port is open on the mesh only, and the name is one the coordinator gives no worker.
const ( Run = "run" Read = "read" Write = "write" Kill = "kill" // end a session's environments Update = "update" // become release Version, then restart Hello = "hello" // first frame on a connection: what the worker is Output = "output" // run: one chunk, in order Result = "result" // run: exit code, path of the whole output when spilled Bytes = "bytes" // read: the file Done = "done" // write, kill, update Error = "error" // any request: text the model reads )
Kinds. The first five go harness to worker; the rest come back. Hello, update, and the done or error that answers an update are the contract every version from v0.1.0 keeps: they are how a worker of another release becomes this one. Workers from before it do not know update and are reinstalled.
const Bin = "/usr/local/bin/mainplane"
Bin is the binary the service runs. It and the state directory are root's: code that runs as the operator cannot replace the service or read its token.
Variables ¶
var Default = map[string][]string{"windows": {"pwsh"}, "linux": {"bash"}, "darwin": {"bash"}}
Default is the interpreter each OS ships with. The first is the default.
Functions ¶
func Dial ¶
Dial makes this machine a worker of the harness on m: dial the harness's node at the address the last map gives it, serve until the connection ends, dial again, until the harness removes this worker. WireGuard proved both ends, so the hello carries no secret. A connection that ends within the longest wait, as a refused hello does, keeps the backoff; only one that held resets it.
func File ¶
File is the helper's side, run as the operator: read copies path to stdout, write copies stdin to path and makes its directory.
func Install ¶
Install makes this machine a worker at every boot: a systemd unit running Bin as root. Logs are in journalctl -u mainplaned.
func Installed ¶
Installed is what install left for the service: the join token and the operator, the user code runs as.
func Serve ¶
Serve answers one harness until the connection ends, then kills every environment. Each request runs in its own goroutine; runs that share an environment queue on it. An error frame with no id is the harness ending the connection on purpose, and its text is the error.
func Uninstall ¶ added in v0.1.1
func Uninstall() error
Uninstall stops the worker and removes its service, what a killed worker left of the mesh, Bin, which is also the CLI, and the state directory with the join token and the mesh keys. Scratch stays: it is the operator's.
Types ¶
type Header ¶
type Header struct {
ID string `json:"id,omitempty"`
Kind string `json:"kind"`
Len int `json:"len"`
Session string `json:"session,omitempty"` // run, kill: environments live per session
Interp string `json:"interp,omitempty"` // run: empty means the worker's first
Timeout int `json:"timeout,omitempty"` // run: seconds before the environment is killed
Path string `json:"path,omitempty"` // read, write
Exit int `json:"exit,omitempty"` // result
Full string `json:"full,omitempty"` // result: file holding all the output, when over the limits
Name string `json:"name,omitempty"` // what sessions call this worker: its mesh name, set by the harness
OS string `json:"os,omitempty"` // hello
Arch string `json:"arch,omitempty"` // hello
Interps []string `json:"interps,omitempty"` // hello: first is the default
Scratch string `json:"scratch,omitempty"` // hello: where spilled output lands
Version string `json:"version,omitempty"` // hello: the release this worker was built from; update: the one to become
}
type Local ¶
Local is what this machine offers: its name, the join secret that lets it join the mesh, where spilled output lands, and which interpreters it has. The first interpreter is the default. Under a root service, Operator is the user code runs and files are touched as; nil is the worker's own user.