env/supervisor
import "github.com/barevoidco/zelk/core/env/supervisor"Package supervisor retains bounded process I/O in an explicitly hosted local service, so interactive agent hosts can restart without losing their jobs. Hosts own the private transport, configured workspace and service lifecycle.
Client
Section titled “Client”type Client struct { // contains filtered or unexported fields}Client attaches to an explicitly owned Service over an injected local HTTP transport. Closing a client leaves jobs owned by the service. The caller owns the HTTP client’s transport. Methods and returned processes are concurrency-safe.
NewClient
Section titled “NewClient”func NewClient(ctx context.Context, httpClient *http.Client, identity string) (*Client, error)NewClient verifies configuration identity before allowing process attachment. httpClient must connect the fixed supervisor hostname to a private local socket; exposing this protocol on an untrusted network is unsupported.
Example
package supervisor_test
import ( "context" "fmt" "net/http" "net/http/httptest"
"github.com/barevoidco/zelk/core/env" "github.com/barevoidco/zelk/core/env/supervisor")
type exampleStarter struct{}
func (exampleStarter) Start(context.Context, env.Cmd) (env.Proc, error) { return nil, env.ErrNotDispatched}
type exampleTransport struct{ handler http.Handler }
func (t exampleTransport) RoundTrip(req *http.Request) (*http.Response, error) { w := httptest.NewRecorder() t.handler.ServeHTTP(w, req) return w.Result(), nil}
func ExampleNewClient() { // An in-memory transport stands in for a host's private Unix socket. service, err := supervisor.New(exampleStarter{}, "/workspace", "workspace-and-confinement", env.Enforcement{}) if err != nil { panic(err) } defer service.Close() client, err := supervisor.NewClient(context.Background(), &http.Client{Transport: exampleTransport{service.Handler()}}, "workspace-and-confinement") if err != nil { panic(err) } jobs, err := client.Jobs(context.Background()) if err != nil { panic(err) } fmt.Println(client.Root(), len(jobs)) // Closing an Agent using this client would leave processes with the service. // Only the independent owner closes the service itself. // Output: /workspace 0}Client.Enforcement
Section titled “Client.Enforcement”func (c *Client) Enforcement() env.EnforcementEnforcement reports the service’s process confinement, checked at attachment.
Client.Jobs
Section titled “Client.Jobs”func (c *Client) Jobs(ctx context.Context) ([]Job, error)Jobs inspects retained process identity, completion and exit without reading output.
Client.Lookup
Section titled “Client.Lookup”func (c *Client) Lookup(ctx context.Context, id env.ProcID) (env.Proc, error)Lookup attaches stdin and retained output to a process generation, or returns env.ErrNotFound for confirmed absence or env.ErrProcessUnobservable for an unconfirmed exit. It never launches a replacement for a lost process.
Client.Root
Section titled “Client.Root”func (c *Client) Root() stringRoot identifies the workspace whose configured launcher owns these processes.
Client.StartPersistent
Section titled “Client.StartPersistent”func (c *Client) StartPersistent(ctx context.Context, key string, cmd env.Cmd) (env.Proc, error)StartPersistent starts an effect once per key during this service generation. Conflicting command reuse or a released key is refused without launching work.
type Job struct { ID env.ProcID Key string Done bool Exit env.Exit Error string}Job is a retained process’s stable identity and observed completion state.
Service
Section titled “Service”type Service struct { // contains filtered or unexported fields}Service owns bounded process I/O independently of any interactive Agent. The host explicitly serves Handler on a private local transport and calls Close before closing the workspace. It never starts a server implicitly. A service restart loses its processes; a new generation cannot impersonate handles from an earlier service. Methods are safe for concurrent use.
func New(starter Starter, root, identity string, profile env.Enforcement) (*Service, error)New returns a service retaining at most 128 processes. identity describes the host’s exact workspace/confinement configuration and is checked on every RPC. The caller retains ownership of starter. Output is bounded to 1 MiB per job. A starter with env.ProcessPresence supplies the absence proof for jobs from an earlier service generation.
Service.Close
Section titled “Service.Close”func (s *Service) Close() errorClose kills and joins every retained process and observation goroutine. Closing a client connection does not close this service or its processes.
Service.Handler
Section titled “Service.Handler”func (s *Service) Handler() http.HandlerHandler exposes the process protocol. Serve it only on a host-owned private local socket: configuration identity prevents accidental cross-workspace attachment but is not an authentication secret or a network security boundary.
Service.Jobs
Section titled “Service.Jobs”func (s *Service) Jobs() []JobJobs returns retained running and finished jobs without consuming output.
Starter
Section titled “Starter”type Starter interface { Start(context.Context, env.Cmd) (env.Proc, error)}Starter starts processes in a host-owned, confined workspace.