Help us shape the future of Go! Take the 2026 Go Developer Survey

worker

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 26 Imported by: 0

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

View Source
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.

View Source
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.

View Source
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.

View Source
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

View Source
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

func Dial(m *mesh.Mesh, l Local)

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 Encode

func Encode(w io.Writer, f Frame) error

func File

func File(op, path string) error

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

func Install(token string) error

Install makes this machine a worker at every boot: a systemd unit running Bin as root. Logs are in journalctl -u mainplaned.

func Installed

func Installed() (token string, op *user.User, err error)

Installed is what install left for the service: the join token and the operator, the user code runs as.

func Serve

func Serve(conn net.Conn, l Local) error

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.

func Work

func Work(key string, l Local) error

Work is the worker: on the mesh, with its state in the state directory under a service and in scratch when run by hand, and dialing the harness, until the service manager stops it. Then it leaves the mesh, so no address, route, rule or hosts block stays behind.

Types

type Frame

type Frame struct {
	Header
	Body []byte
}

func Decode

func Decode(br *bufio.Reader) (Frame, error)
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

type Local struct {
	Name     string
	Secret   string
	Scratch  string
	Interps  []string
	Operator *user.User
}

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.

Jump to

Keyboard shortcuts

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