session

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrExpiredSession = errors.New("session has expired")

ErrExpiredSession is returned by LoadActive when the session's expired_at is set. This is a distinct sentinel from ErrNoSession — both appear in logs and must be distinguishable by humans and by errors.Is callers.

View Source
var ErrNoSession = errors.New("no active session")

ErrNoSession is returned by LoadActive when the .tkt/session file is absent.

Functions

func CountActive

func CountActive(db *sql.DB) (map[models.Role]int, error)

CountActive returns count of non-expired sessions broken down by base role. Keys are models.RoleArchitect and models.RoleImplementer. Roles not present in the result had zero active sessions.

func Create

func Create(role models.Role, name string, db *sql.DB, root string) (*models.Session, error)

Create generates a new ULID, inserts a row into the sessions table, and writes the bare session ULID to the .tkt/session file.

name is the user-supplied session name (may be empty for random word). If non-empty, it must already have been validated by ValidateName.

func CreateSystem

func CreateSystem(role models.Role, db *sql.DB) (*models.Session, error)

CreateSystem inserts a DB-only session row for a built-in system role (e.g. monitor) WITHOUT writing to the .tkt/session file. Used by tkt monitor to own its own session without displacing any user session.

func End

func End(root string, db *sql.DB) (sessionID string, err error)

End marks the current active session as expired by setting expired_at = NOW(). Reads the session ID from the .tkt/session file. Returns ErrNoSession when no session file exists or the file is empty. Calling End on an already-expired session is idempotent — it simply updates expired_at again.

func ExpireByID

func ExpireByID(id string, db *sql.DB) error

ExpireByID sets expired_at = datetime('now') for the session with the given ID. Returns nil if no row matched (idempotent).

func GenerateName added in v0.2.0

func GenerateName(name string) string

GenerateName returns a user-supplied session name or a random word.

func GenerateULID added in v0.2.0

func GenerateULID() string

GenerateULID returns a new session ID.

func LoadActive

func LoadActive(root string, db *sql.DB) (*models.Session, error)

LoadActive reads the active session from the .tkt/session file, looks it up in the DB, updates last_active, and returns the Session.

  • Returns ErrNoSession when the session file does not exist.
  • Returns ErrExpiredSession when expired_at is set on the session row.
  • Returns a wrapped error (not ErrNoSession) when the file exists but the row is gone.

func ValidateName

func ValidateName(name string) error

ValidateName checks that a user-supplied session name conforms to the naming rules:

  • Lowercase alphanumeric + hyphens only
  • No leading or trailing hyphen
  • No consecutive hyphens
  • At least 1 character, at most 32 characters

Returns a descriptive error if the name is invalid, nil otherwise.

Types

This section is empty.

Jump to

Keyboard shortcuts

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