session

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanupStaleSessions added in v0.4.26

func CleanupStaleSessions(baseDir string, maxAge time.Duration) (int, error)

CleanupStaleSessions removes session files older than maxAge (handles nested structure)

func FormatSessionID

func FormatSessionID(baseDir, sessionID string) string

FormatSessionID formats a session ID with optional name lookup. Use this when you only have a session ID string and need to display it. If the session has a name, returns "ses_xxx (name)", otherwise just "ses_xxx".

func GetCurrentBranch added in v0.4.26

func GetCurrentBranch() string

GetCurrentBranch returns the current git branch (exported for display)

func ParseDuration

func ParseDuration(s string) (time.Duration, error)

ParseDuration parses human-readable duration strings

func Save

func Save(baseDir string, sess *Session) error

Save writes the session to disk as JSON (agent-scoped)

Types

type AgentFingerprint added in v0.4.26

type AgentFingerprint struct {
	Type       AgentType
	PID        int
	ExplicitID string // set when TD_SESSION_ID is used
}

AgentFingerprint identifies a specific agent session

func GetAgentFingerprint added in v0.4.26

func GetAgentFingerprint() AgentFingerprint

GetAgentFingerprint detects the agent running this process by walking the process tree

func (AgentFingerprint) String added in v0.4.26

func (af AgentFingerprint) String() string

String returns a filesystem-safe string representation

type AgentType added in v0.4.26

type AgentType string

AgentType identifies the type of AI agent

const (
	AgentClaudeCode AgentType = "claude-code"
	AgentCursor     AgentType = "cursor"
	AgentCodex      AgentType = "codex"
	AgentWindsurf   AgentType = "windsurf"
	AgentZed        AgentType = "zed"
	AgentAider      AgentType = "aider"
	AgentCopilot    AgentType = "copilot"
	AgentGemini     AgentType = "gemini"
	AgentUnknown    AgentType = "unknown"
	AgentTerminal   AgentType = "terminal"
)

type Session

type Session struct {
	ID                string    `json:"id"`
	Name              string    `json:"name,omitempty"`
	Branch            string    `json:"branch,omitempty"`     // git branch for session scoping
	AgentType         string    `json:"agent_type,omitempty"` // agent type (claude-code, cursor, terminal, etc.)
	AgentPID          int       `json:"agent_pid,omitempty"`  // stable parent agent process ID
	ContextID         string    `json:"context_id,omitempty"` // audit only, not used for matching
	PreviousSessionID string    `json:"previous_session_id,omitempty"`
	StartedAt         time.Time `json:"started_at"`
	LastActivity      time.Time `json:"last_activity,omitempty"` // heartbeat for session liveness
	IsNew             bool      `json:"-"`                       // True if session was just created (not persisted)
}

Session represents the current terminal session

func ForceNewSession

func ForceNewSession(baseDir string) (*Session, error)

ForceNewSession creates a new session on the current branch/agent, regardless of existing session

func Get

func Get(baseDir string) (*Session, error)

Get returns the current session without creating one (agent-scoped)

func GetOrCreate

func GetOrCreate(baseDir string) (*Session, error)

GetOrCreate returns the current session for the current git branch and agent. Sessions are scoped by branch + agent fingerprint - same agent on same branch = same session. Creates a new session if none exists for this branch/agent combination.

func GetWithContextCheck

func GetWithContextCheck(baseDir string) (*Session, error)

GetWithContextCheck returns the current session and checks if context changed. If context changed, creates a new session automatically.

func ListSessions added in v0.4.26

func ListSessions(baseDir string) ([]Session, error)

ListSessions returns all sessions (agent-scoped and legacy branch-scoped)

func SetName

func SetName(baseDir string, name string) (*Session, error)

SetName sets the session name

func (*Session) Display

func (s *Session) Display() string

Display returns the session ID with name if set: "ses_abc123 (my-name)" or just "ses_abc123"

func (*Session) DisplayWithAgent added in v0.4.26

func (s *Session) DisplayWithAgent() string

DisplayWithAgent returns session info including agent: "ses_abc123 [claude-code]" or with name

Jump to

Keyboard shortcuts

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