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
- Variables
- func KeepFresh(ctx context.Context, paths ...string)
- func ToolDirs(goos, home string, getenv func(string) string) []string
- func UIDOwner(uid int) string
- type Layout
- func (l *Layout) EnsureDirs() error
- func (l *Layout) ExpandHome(p string) string
- func (l *Layout) ForeignOwned() *OwnerError
- func (l *Layout) HolderAddr(sessionID string) string
- func (l *Layout) HolderSocketDir() string
- func (l *Layout) ReadWrapperRun() (rec WrapperRunRecord, ok bool)
- func (l *Layout) SessionDataDir(sessionID string) string
- func (l *Layout) WriteWrapperRun(rec WrapperRunRecord)
- type OwnerError
- type WrapperRunRecord
Constants ¶
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.
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 ¶
var ErrForeignOwner = errors.New("stagent location owned by another user")
ErrForeignOwner matches every *OwnerError (errors.Is).
Functions ¶
func KeepFresh ¶ added in v0.3.0
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 ¶
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.
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
// ScreenRules holds the host's overrides of the rules the holder reads
// agents' screens with (screenrules): <Root>/screen-rules/<name>.json
ScreenRules string
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
// Tasks holds the tasks; only the daemon writes it:
// <StateDir>/tasks.json
Tasks string
// SetupApprovals holds the scripts.setup contents the user approved
// for each source checkout (ADR 0023); only the daemon writes it:
// <StateDir>/setup-approvals.json
SetupApprovals string
// Schedules holds the schedules (定期実行) and ScheduleRuns their runs
// (<id>.jsonl); only the daemon writes them: <StateDir>/schedules.json,
// <StateDir>/schedule-runs
Schedules string
ScheduleRuns string
// StoppedAgents holds the agents of live sessions and the stopped
// agents (止まった agent) with the boot they were recorded in; only
// the daemon writes it: <StateDir>/agents.json
StoppedAgents string
UsageIndex string // <StateDir>/usage-index.json — the usage counted from the transcripts; only the daemon writes it
// UsageLimits holds the last value of every limit window (上限の枠),
// per account; only the daemon writes it: <StateDir>/usage-limits.json
UsageLimits string
// UsageAlerts holds what was notified of each limit window (80%,
// 100%, reset), so a restart does not notify it again; only the
// daemon writes it: <StateDir>/usage-alerts.json
UsageAlerts string
// StatusLineMarks holds one file per Claude session whose modification
// time is when `stagent statusline claude` last sent its limit windows
// (it sends at most every 15 s): <StateDir>/statusline
StatusLineMarks 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 ¶
Resolve computes the layout for the current user. It does not create anything; call EnsureDirs for that.
func (*Layout) EnsureDirs ¶
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) ExpandHome ¶ added in v0.14.0
ExpandHome resolves "", "~", "~/..." and `~\...` against Home; any other p is returned as it is.
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 ¶
HolderAddr is the IPC address a session holder listens on.
func (*Layout) HolderSocketDir ¶
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 ¶
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`.