paths

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package paths resolves where stagent keeps its binary, state, sockets and scrollback on the current host. Every other package takes a *Layout rather than computing paths itself, so tests and the load bench can isolate a whole installation by setting STAGENT_HOME.

Index

Constants

View Source
const EnvHome = "STAGENT_HOME"

EnvHome overrides the home directory. Tests and the bench point it at a temporary directory; it also namespaces the IPC endpoints so an isolated installation never talks to the real daemon.

View Source
const KeepFreshInterval = time.Hour

KeepFreshInterval is how often KeepFresh touches its paths: well below the age (days) after which tmp cleaners such as systemd-tmpfiles delete unused entries of /tmp.

Variables

View Source
var ErrForeignOwner = errors.New("stagent location owned by another user")

ErrForeignOwner matches every *OwnerError (errors.Is).

Functions

func KeepFresh added in v0.3.0

func KeepFresh(ctx context.Context, paths ...string)

KeepFresh sets the access and modification times of every existing path to now every KeepFreshInterval until ctx is done, so that a tmp cleaner does not delete the run directory or a socket of a process that is still serving. Missing paths and errors are ignored. It is a no-op on Windows: RunDir is not in a temporary directory there, and opening a named pipe path to set its times would connect to the pipe.

func ToolDirs

func ToolDirs(goos, home string, getenv func(string) string) []string

ToolDirs lists the per-user and common install directories of CLI tools (npm/bun/pnpm globals, version managers, Homebrew, …) that are often only on PATH in interactive or login shells — not in the environment an SSH exec channel starts with. goos and getenv are parameters so callers can fake another platform in tests.

func UIDOwner added in v0.7.0

func UIDOwner(uid int) string

UIDOwner names the user with uid for an OwnerError: the user name when it resolves, else the decimal uid.

Types

type Layout

type Layout struct {
	Home     string // user home (or STAGENT_HOME)
	Root     string // <Home>/.ssh-term/agent
	BinDir   string // <Root>/bin
	Bin      string // <BinDir>/stagent[.exe]
	Manifest string // <Root>/manifest.json
	Config   string // <Root>/config.json
	HostID   string // <Root>/host-id — the host's random id (hostid)
	StateDir string // <Root>/state
	EventLog string // <StateDir>/events.log (segments get a numeric suffix)
	Index    string // <StateDir>/index.json — conversation list cache
	// WrapperRun records the last start of `stagent run --handoff=auto`,
	// which only the shell wrappers pass (WrapperRunRecord):
	// <StateDir>/wrapper-run
	WrapperRun string
	// NotifyErrors holds the last failed push per channel:
	// <StateDir>/notify-errors.json
	NotifyErrors string
	// ChatMessages holds the unresolved messages the chat destination
	// took (ids only, never the URL): <StateDir>/chat-messages.json
	ChatMessages string
	DataDir      string // per-session scrollback segments; local disk even when Home is on NFS
	LogDir       string // <Root>/log — stderr of detached processes
	RunDir       string // sockets (unix) / lock and pid files (all OSes), 0700
	DaemonAddr   string // IPC address of the daemon
	UploadsDir   string // <Home>/.ssh-term/uploads — files sent from the app
	// DataOnNetworkFS reports that Home is on a network file system and
	// DataDir was moved to local disk.
	DataOnNetworkFS bool
	// Isolated reports that STAGENT_HOME is set.
	Isolated bool
	// contains filtered or unexported fields
}

Layout is the resolved file-system layout of one installation.

func Resolve

func Resolve() (*Layout, error)

Resolve computes the layout for the current user. It does not create anything; call EnsureDirs for that.

func (*Layout) EnsureDirs

func (l *Layout) EnsureDirs() error

EnsureDirs creates every directory of the layout with owner-only access. A RunDir in the shared temporary directory, and a DataDir moved to the shared local disk (with its per-user parent), are validated instead of repaired (ensurePrivateDir).

func (*Layout) ForeignOwned added in v0.7.0

func (l *Layout) ForeignOwned() *OwnerError

ForeignOwned returns the first directory of l in a shared temporary directory (a shared RunDir, the parent of a relocated DataDir) that exists and belongs to another user, or nil. Unlike EnsureDirs it creates and changes nothing, so doctor and the bridge's hello can call it.

func (*Layout) HolderAddr

func (l *Layout) HolderAddr(sessionID string) string

HolderAddr is the IPC address a session holder listens on.

func (*Layout) HolderSocketDir

func (l *Layout) HolderSocketDir() string

HolderSocketDir is the directory holding holder sockets on unix (empty on Windows, where holders use named pipes). The daemon scans it on start.

func (*Layout) ReadWrapperRun added in v0.4.0

func (l *Layout) ReadWrapperRun() (rec WrapperRunRecord, ok bool)

ReadWrapperRun returns the last record; ok is false when there is none or it is unreadable. A file of stagent before 0.4.0 holds only the time.

func (*Layout) SessionDataDir

func (l *Layout) SessionDataDir(sessionID string) string

SessionDataDir is where one session's scrollback segments live.

func (*Layout) WriteWrapperRun added in v0.4.0

func (l *Layout) WriteWrapperRun(rec WrapperRunRecord)

WriteWrapperRun stores rec. Best effort: errors are ignored, it never holds up the program.

type OwnerError added in v0.7.0

type OwnerError struct {
	Path  string // e.g. /tmp/stagent-1000, \\.\pipe\stagent-<SID>
	Owner string // user name when known, else uid (unix) / SID (Windows)
}

OwnerError reports that a stagent location belongs to another user: a run or data directory in a shared temporary directory, a socket, or a named pipe. Someone created it first, so nothing was read from or sent to it, and it stays unusable until that user or an administrator removes it.

func (*OwnerError) Error added in v0.7.0

func (e *OwnerError) Error() string

func (*OwnerError) Is added in v0.7.0

func (e *OwnerError) Is(target error) bool

type WrapperRunRecord added in v0.4.0

type WrapperRunRecord struct {
	// At is when the program was started, unix ms.
	At int64 `json:"at"`
	// Placement is where `stagent run` ended up after leaving the login
	// session (logind.Escape, Linux): a logind.Placement name, "" when
	// unknown. Whether it outlives logout there depends on logind's
	// settings, so `stagent doctor` judges it with the current ones.
	Placement string `json:"placement,omitempty"`
	// SurvivesLogout says whether `stagent run` swapped its bootstrap port
	// (bootstrap.Swap, macOS), so that it outlives the user's logout; nil
	// when unknown and off macOS.
	SurvivesLogout *bool `json:"survives_logout"`
	// BootstrapError is why the swap failed on macOS; "" otherwise.
	BootstrapError string `json:"bootstrap_error,omitempty"`
}

WrapperRunRecord is the content of Layout.WrapperRun, written at every start through a shell wrapper and read by `stagent doctor`.

Jump to

Keyboard shortcuts

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