session

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package session manages terminal and agent work sessions scoped by git branch and agent identity.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanupStaleSessions added in v0.4.26

func CleanupStaleSessions(database *db.DB, maxAge time.Duration) (int, error)

CleanupStaleSessions removes sessions older than maxAge

func FormatSessionID

func FormatSessionID(database *db.DB, sessionID string) string

FormatSessionID formats a session ID with optional name lookup.

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

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. The expensive process tree walk is cached; env var checks are always re-evaluated.

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(database *db.DB) (*Session, error)

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

func Get

func Get(database *db.DB) (*Session, error)

Get returns the current session without creating one

func GetOrCreate

func GetOrCreate(database *db.DB) (*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(database *db.DB) (*Session, error)

GetWithContextCheck returns the current session and checks if context changed.

func ListSessions added in v0.4.26

func ListSessions(database *db.DB) ([]Session, error)

ListSessions returns all sessions

func SetName

func SetName(database *db.DB, 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