github.com/rotari-dev/rotari/internal/attachment

Overview

package attachment // import "github.com/rotari-dev/rotari/internal/attachment"

Package attachment coordinates live CLI clients of one run.

Functions

func Attached(paths state.ProjectPaths, runID string) (bool, error)
    Attached reports whether a run has any live client sessions. Sessions whose
    liveness cannot be disproved (notably remote hosts) remain attached.

func Bind(paths state.ProjectPaths, id, runID string) error
    Bind commits the pending initiating session to a run. It also marks that run
    as using session-derived attachment state, replacing the legacy boolean.

func CurrentLaunchOrigin() model.LaunchOrigin
    CurrentLaunchOrigin is the process that ran this rotari command: its parent,
    such as the shell or script, on this host. Like a shell's wait, wait without
    a selector follows the runs that the same process started.

func EnableRun(paths state.ProjectPaths, runID string) error
    EnableRun marks a newly started run as using session-derived attachment
    state. Older runs without this marker retain their lock-boolean fallback.

func Enabled(paths state.ProjectPaths, runID string) bool
    Enabled reports whether a run has session-derived attachment state.

func Forget(paths state.ProjectPaths, id string) error
    Forget removes a stale or handled session record after the caller has
    applied its disconnect policy. It does not remove a live session lock.

func ForgetRun(paths state.ProjectPaths, runID string) error
    ForgetRun removes a deleted run's attachment marker and the session records
    bound to it whose locks are not held. A live client's session is left for
    that client to close.

func IsAttached(paths state.ProjectPaths, runID string) (bool, error)
    IsAttached derives current attachment state, retaining compatibility with
    active runs created before session records were introduced.

func NewID() (string, error)
    NewID returns a collision-resistant identifier safe as one path element.

func SameLaunchOrigin(recorded *model.LaunchOrigin, current model.LaunchOrigin) bool
    SameLaunchOrigin reports whether a run's recorded origin is current: the
    same PID in the same host and PID namespace (state.ProcessIdentity.Locate).
    A start time known on both sides must match, so a reused PID never matches.
    An origin from an earlier rotari, without a namespace, matches on host and
    PID as before.

Types

type Info struct {
	ID         string
	RunID      string
	PID        int
	Host       string
	Disconnect string
	Initiator  bool
	Live       bool
}
    Info describes one live or unexpectedly lost client session.

func Scan(paths state.ProjectPaths, runID string) (live, stale []Info, err error)
    Scan returns live sessions and sessions proved stale on this host. A stale
    initiating session configured to cancel is returned so the supervisor can
    apply that policy; callers should treat scan errors as uncertainty.

type Session struct {
	// Has unexported fields.
}
    Session owns a process-held advisory lock. The lock is released by the
    kernel on process death, including SIGKILL, and remains held while stopped.

func Open(paths state.ProjectPaths, runID, id, disconnectAction string) (*Session, error)
    Open registers a client that attaches to an existing run.

func OpenPending(paths state.ProjectPaths, id, disconnectAction string) (*Session, error)
    OpenPending reserves an initiating client session before run startup.
    Bind associates it with the accepted run without releasing the process lock.

func (session *Session) Close(reason string) error
    Close releases the session and removes its record. An empty reason is used
    by non-initiating wait clients, which do not alter launch history.

func (session *Session) ID() string
    ID returns the stable identifier sent in the run startup request.