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(key string, 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 ( 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 with key: prove the harness at the last URL it had, or find it through the pointer, open a WebSocket at url/worker, serve until it ends, open again. It never returns. 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. The hello carries the secret as its body, so no list of hellos shows it. An error frame with no id is the harness ending the connection on purpose, and its text is the error.
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"` // hello: what sessions call this worker
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
}