session

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package session manages named execution sessions with isolated state. Sessions allow teams to run multiple independent plan variants without overwriting each other. Each session stores its own state.db in .cloop/sessions/<name>/.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActiveDir

func ActiveDir(workDir string) string

ActiveDir returns the effective state directory:

  • workDir if no session is active
  • workDir/.cloop/sessions/<name> if a session is active

func ActiveName

func ActiveName(workDir string) string

ActiveName returns the currently active session name, or "" for the default.

func DBPath

func DBPath(workDir, name string) string

DBPath returns the absolute path to the session's state.db.

func Dir

func Dir(workDir, name string) string

Dir returns the absolute path to the session directory.

func Remove

func Remove(workDir, name string) error

Remove deletes a session. Returns an error if the session is currently active.

func Switch

func Switch(workDir, name string) error

Switch sets the active session. Pass "" to clear (use default).

The write to .cloop/active_session is atomic — a torn write (crash mid- write, ENOSPC) would leave a 0-byte file, and ActiveName would silently route every subsequent command to the default session, hiding the user's real working state.

Types

type Session

type Session struct {
	Name       string    `json:"name"`
	CreatedAt  time.Time `json:"created_at"`
	StateFile  string    `json:"state_file"`  // relative path from workDir
	ConfigFile string    `json:"config_file"` // relative path from workDir
}

Session describes a named execution session.

func List

func List(workDir string) ([]*Session, error)

List returns all sessions for the given project.

func New

func New(workDir, name string, copyFromDBPath string) (*Session, error)

New creates a new session directory and metadata file. If copyFromDBPath is non-empty, that state.db is copied into the new session.

Runs under sessionMu so two concurrent New("foo") calls can't both pass the existence check and race on the mkdir.

Jump to

Keyboard shortcuts

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