localrun

package
v0.96.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package localrun is the machine-local registry of running gofastr apps. Every App writes one record when its listener binds and removes it when the server stops, so a tool on the same machine (the gofastr-runs example, an agent) can list what is running, where, and how to reach its MCP server, with no port scanning.

Records live in Dir, one owner-only JSON file per run, with the run's process start value in a sidecar file beside it. A run that dies without shutting down leaves its file behind; List drops a record whose process is gone, a pid now held by a newer process included. Registration is best-effort: a run that cannot write its record serves anyway.

Index

Constants

View Source
const (
	// EnvDir overrides the registry directory.
	EnvDir = "GOFASTR_RUNS_DIR"
	// EnvRuns set to "off" (or 0/false/no) stops this process from
	// registering; "on" (or 1/true/yes) makes it register wherever it
	// binds. Unset, the App decides (see App.Start). Listing is
	// unaffected.
	EnvRuns = "GOFASTR_RUNS"
	// EnvOff is EnvRuns under its older name, from when the variable
	// could only turn registration off.
	EnvOff = EnvRuns
)

Variables

This section is empty.

Functions

func Dir

func Dir() (string, error)

Dir is the registry directory: $GOFASTR_RUNS_DIR, else <os.UserConfigDir>/gofastr/runs.

func Disabled

func Disabled() bool

Disabled reports whether this process must not register: EnvOff says so, or it is a test binary, or a process a test binary started, with no EnvDir (tests that start an App must not litter the real registry; a test that exercises it sets EnvDir to a temp dir).

func Forced added in v0.96.0

func Forced() bool

Forced reports whether the environment asks this process to register regardless of where it binds: EnvRuns says "on" (or 1/true/yes). EnvDir only says where the registry is. Disabled still wins.

func Register

func Register(rec Record) (unregister func(), err error)

Register writes rec and returns the func that removes it. It fills ID, PID (this process), ProcStart, Version and a zero Started. URL is required.

func UnderTest added in v0.96.0

func UnderTest() bool

UnderTest reports whether this process is a Go test binary or a process one started (it inherits the marker a test binary sets at init): the dev-loop and quickstart e2e suites run real apps that way.

Types

type Record

type Record struct {
	Version int `json:"version"`
	// ID names the record file: "<pid>-<8 hex>".
	ID   string `json:"id"`
	Name string `json:"name"`
	PID  int    `json:"pid"`
	// ProcStart is the OS's start value for PID (procalive.Identity),
	// so List can tell the run from a later process that got its pid.
	// Zero when the OS would not say; the pid alone decides then. It is
	// kept in "<id>.start" beside the record, not in the JSON: readers
	// built before it decode records strictly, and an unknown field
	// would make them drop every record.
	ProcStart uint64 `json:"-"`
	// URL is the base URL a local client dials: http://127.0.0.1:<port>
	// for a wildcard bind.
	URL string `json:"url"`
	// MCPPath is the path the app serves MCP over HTTP on ("/mcp"),
	// empty when it serves none. Under `gofastr dev` it answers on
	// loopback with no credential; elsewhere the app's own auth
	// applies.
	MCPPath string `json:"mcp_path,omitempty"`
	// MCPCommand, when set, is an argv that speaks stdio MCP to this
	// run (battery/service sets `<exe> service mcp --state-dir <dir>`).
	// An agent should prefer it over MCPPath: it carries its own
	// credential.
	MCPCommand []string `json:"mcp_command,omitempty"`
	// Service is the battery/service Config.ID when the run is a
	// service daemon or its dev run.
	Service string    `json:"service,omitempty"`
	Dev     bool      `json:"dev,omitempty"`
	Dir     string    `json:"dir,omitempty"`
	Exe     string    `json:"exe,omitempty"`
	Started time.Time `json:"started"`
}

Record is one running app.

func List

func List() ([]Record, error)

List returns the records of live runs, newest first. A record whose process has exited is removed on the way, and so is one whose pid a newer process now holds (its start value differs from ProcStart). Files that are not records are skipped. A missing directory is an empty list.

func (Record) MCPURL

func (r Record) MCPURL() string

MCPURL is URL+MCPPath, or "" when the run serves no HTTP MCP.

Jump to

Keyboard shortcuts

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