session

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const SchemaVersion = 1

SchemaVersion is the current on-disk schema version of sessions.json. Bump this and append a Step to the Plan returned by MigrationPlan() whenever the shape of diskData or Session changes in a non-additive way.

Variables

This section is empty.

Functions

func MigrationPlan

func MigrationPlan() migrate.Plan

MigrationPlan returns the migrate.Plan for sessions.json. Steps is empty at v1 because the initial migration only stamps the version — no content changes are required to turn an unversioned sessions.json into v1.

func SanitizeName

func SanitizeName(name string) string

SanitizeName converts a string into a valid session name by replacing invalid characters with dashes and trimming.

func ValidateName

func ValidateName(name string) error

ValidateName returns an error if name is not a valid session name.

Types

type Session

type Session struct {
	Name             string    `json:"name"`
	UUID             string    `json:"uuid"`
	Mode             string    `json:"mode"`
	Workdir          string    `json:"workdir"`
	CreatedAt        time.Time `json:"created_at"`
	LastAttachedAt   time.Time `json:"last_attached_at,omitempty"`
	LastHealthStatus string    `json:"last_health_status,omitempty"`
	LastHealthAt     time.Time `json:"last_health_at,omitempty"`
}

Session holds metadata for a managed tmux session.

func New

func New(name, workdir, mode string) *Session

New creates a new Session with a generated UUID and current timestamp.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store manages session persistence via a JSON file with flock-based locking.

func NewStore

func NewStore(path string) *Store

NewStore creates a Store for the given file path.

func (*Store) Backup

func (s *Store) Backup() (string, error)

Backup copies sessions.json to sessions.json.bak.<timestamp> and returns the backup path. It acquires the store lock for the duration of the read.

func (*Store) Delete

func (s *Store) Delete(name string) error

Delete removes a session by name.

func (*Store) DeleteAll

func (s *Store) DeleteAll() error

DeleteAll removes all sessions. It automatically creates a backup first so the user can recover from an accidental killall.

func (*Store) Get

func (s *Store) Get(name string) (*Session, error)

Get retrieves a session by name, returning an error if not found.

func (*Store) List

func (s *Store) List() ([]*Session, error)

List returns all sessions.

func (*Store) Names

func (s *Store) Names() ([]string, error)

Names returns all session names (useful for completions).

func (*Store) Rename

func (s *Store) Rename(oldName, newName string) error

Rename renames a session from oldName to newName.

func (*Store) Save

func (s *Store) Save(sess *Session) error

Save adds or updates a session.

func (*Store) UpdateAttached

func (s *Store) UpdateAttached(name string) error

UpdateAttached updates the last attached timestamp of a session.

func (*Store) UpdateHealth

func (s *Store) UpdateHealth(name, status string) error

UpdateHealth updates the health status and timestamp of a session.

func (*Store) UpdateMode

func (s *Store) UpdateMode(name, mode string) error

UpdateMode changes the mode of a session.

Jump to

Keyboard shortcuts

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