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

serve

package
v0.10.7 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package serve keeps one vaultmind process warm and answers the CLI's commands from it. A recall `ask` spent about 0.7 s of its 1.6 s loading the embedding model in every new process; a resident process loads it once. The server runs the real command for each request (see cmd's serve), so this package is only the transport: a private Unix socket, one request at a time, an idle timeout.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoServer means nothing answers on the socket; the caller runs the
	// command itself.
	ErrNoServer = errors.New("no vaultmind server is running")
	// ErrAlreadyServing means another server already answers on the socket.
	ErrAlreadyServing = errors.New("a vaultmind server is already running on this socket")
	// ErrUnsafeDir means the socket's directory could be reached by another
	// user; neither side uses a socket there.
	ErrUnsafeDir = errors.New("unsafe socket directory")
)

Functions

func Serve

func Serve(ctx context.Context, sock string, exec Exec, idle time.Duration) error

Serve answers requests on sock until ctx ends or no request arrives for idle, then removes the socket. Requests run one at a time.

func SocketPath

func SocketPath(stateDir, version string) string

SocketPath is where the server for this version listens. The version is in the name, so two installed versions each get their own server and an upgrade never answers from old code. A state dir too deep for a socket path falls back to a short per-user name under the temp dir. Either way the socket's directory must be private to the user (see checkPrivateDir).

Types

type Exec

type Exec func(Request) Response

Exec runs one request.

type Request

type Request struct {
	Args []string          `json:"args"`
	Dir  string            `json:"dir"`
	Env  map[string]string `json:"env"`
}

Request is one CLI invocation: its arguments, working directory and environment.

type Response

type Response struct {
	Stdout []byte `json:"stdout"`
	Stderr []byte `json:"stderr"`
	Code   int    `json:"code"`
}

Response is what the command printed and the exit code it ended with.

func Forward

func Forward(sock string, req Request, connect, total time.Duration) (Response, error)

Forward sends req to the server on sock and returns its response. With no server it returns ErrNoServer at once; a server slower than total is abandoned with an error.

Jump to

Keyboard shortcuts

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