daemon

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 32 Imported by: 0

Documentation

Overview

Package daemon is pi-env's daemon: it gives a Pi Durable host an execution environment on this machine over a framed protocol on stdin and stdout, usually started through ssh as `pi-env serve --token <hex>`.

Ports packages/env/daemon/src/main.rs

Go mapping: the Rust crate is a Go package, and Serve runs one connection. The daemon reuses durable/env/node for `exec` and `watch`, which the Rust crate re-implements as ports of Durable's NodeExecutionEnv; file operations are Go standard library calls with Node's error codes from internal/nodeerrno. The wire protocol is packages/env/docs/protocol.md unchanged.

Index

Constants

View Source
const (
	FrameRequest byte = 1
	FrameResult  byte = 2
	FrameError   byte = 3
	FrameEvent   byte = 4
	FrameCancel  byte = 5
	FramePing    byte = 6
)

Frame types (docs/protocol.md).

View Source
const (
	// MaxFrame is the largest frame either side accepts.
	MaxFrame = 16 * 1024 * 1024
	// MaxPayload is the largest payload a response carries, leaving room for its JSON.
	MaxPayload = MaxFrame - 64*1024
)
View Source
const (
	// Protocol is the wire protocol version.
	Protocol = 1
)

Variables

This section is empty.

Functions

func Serve

func Serve(input io.Reader, output io.Writer, token string, options Options) error

Serve runs one connection: it writes the sync line `PI-ENV <token>`, then answers frames from input on output until input ends. Everything the client started is killed when it returns.

func WriteFrame

func WriteFrame(output io.Writer, frame *Frame) error

WriteFrame writes one frame.

Types

type Failure

type Failure struct {
	Code    string
	Message string
	Syscall string
	Path    string
	// Extra holds more fields for the client, such as spillPath.
	Extra Object
}

Failure is an error with a Node-style code such as ENOENT; messages are diagnostic only.

func (*Failure) Error

func (f *Failure) Error() string

type Frame

type Frame struct {
	Kind byte
	ID   uint32
	// JSON is the decoded JSON of the frame. A frame whose JSON does not parse arrives with a nil JSON and gets an
	// error reply, because the framing itself is intact.
	JSON    any
	Payload []byte
}

Frame is one message: `u32 length | u8 type | u32 id | u32 jsonLength | json | payload`, integers big-endian.

func ReadFrame

func ReadFrame(input io.Reader) (*Frame, error)

ReadFrame reads one frame; it returns nil at a clean end of input.

type Object

type Object = map[string]any

Object is a JSON object.

type Options

type Options struct {
	// Version is what `hello` reports as version: the release the daemon shipped with.
	Version string
	// PingInterval and SilenceLimit default to the protocol's 5 s and 30 s.
	PingInterval time.Duration
	SilenceLimit time.Duration
	// OnSilence runs when the client went silent for the limit, after everything it started was killed; it defaults to
	// exiting the process, as the daemon does.
	OnSilence func()
}

Options configure Serve.

Jump to

Keyboard shortcuts

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