localrun

package
v0.94.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 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. A run that dies without shutting down leaves its file behind; List drops a record whose pid is gone. 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"
	// EnvOff set to "off" (or 0/false/no) stops this process from
	// registering. Listing is unaffected.
	EnvOff = "GOFASTR_RUNS"
)

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 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), Version and a zero Started. URL is required.

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"`
	// 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 pid has exited is removed on the way. 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