Documentation
¶
Overview ¶
Package session provides session registry management for tracking active agnt run instances.
Index ¶
- type Session
- type SessionInfo
- type SessionRegistry
- func (r *SessionRegistry) ActiveCount() int64
- func (r *SessionRegistry) CheckHeartbeats()
- func (r *SessionRegistry) FindByDirectory(directory string) (*Session, bool)
- func (r *SessionRegistry) GenerateSessionCode(command string) string
- func (r *SessionRegistry) Get(code string) (*Session, bool)
- func (r *SessionRegistry) Heartbeat(code string) error
- func (r *SessionRegistry) Info() SessionInfo
- func (r *SessionRegistry) List(projectPath string, global bool) []*Session
- func (r *SessionRegistry) ListActive(projectPath string, global bool) []*Session
- func (r *SessionRegistry) Register(session *Session) error
- func (r *SessionRegistry) TotalRegistered() int64
- func (r *SessionRegistry) TotalUnregistered() int64
- func (r *SessionRegistry) Unregister(code string) error
- type SessionStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Session ¶
type Session struct {
Code string `json:"code"` // Unique session identifier (e.g., "claude-1", "dev")
OverlayPath string `json:"overlay_path"` // Unix socket path for overlay
ProjectPath string `json:"project_path"` // Directory where session was started
Command string `json:"command"` // Command being run (e.g., "claude")
Args []string `json:"args"` // Command arguments
StartedAt time.Time `json:"started_at"` // When session started
Status SessionStatus `json:"status"` // Current status
LastSeen time.Time `json:"last_seen"` // Last heartbeat timestamp
// contains filtered or unexported fields
}
Session represents an active agnt run instance.
func (*Session) GetStatus ¶
func (s *Session) GetStatus() SessionStatus
GetStatus returns the current session status.
func (*Session) MarshalJSON ¶
MarshalJSON implements json.Marshaler for Session.
func (*Session) SetStatus ¶
func (s *Session) SetStatus(status SessionStatus)
SetStatus updates the session status.
func (*Session) UpdateLastSeen ¶
func (s *Session) UpdateLastSeen()
UpdateLastSeen updates the last seen timestamp and sets status to active.
type SessionInfo ¶
type SessionInfo struct {
ActiveCount int64 `json:"active_count"`
TotalRegistered int64 `json:"total_registered"`
TotalUnregistered int64 `json:"total_unregistered"`
}
SessionInfo contains statistics about the session registry.
type SessionRegistry ¶
type SessionRegistry struct {
Sessions sync.Map // map[string]*Session
// contains filtered or unexported fields
}
SessionRegistry manages active sessions with lock-free operations.
func NewSessionRegistry ¶
func NewSessionRegistry(heartbeatTimeout time.Duration) *SessionRegistry
NewSessionRegistry creates a new session registry.
func (*SessionRegistry) ActiveCount ¶
func (r *SessionRegistry) ActiveCount() int64
ActiveCount returns the number of active sessions.
func (*SessionRegistry) CheckHeartbeats ¶
func (r *SessionRegistry) CheckHeartbeats()
CheckHeartbeats marks sessions as disconnected if they haven't sent a heartbeat recently.
func (*SessionRegistry) FindByDirectory ¶
func (r *SessionRegistry) FindByDirectory(directory string) (*Session, bool)
FindByDirectory finds an active session whose project path matches the given directory or any of its parent directories. Returns the most specific (deepest) match. This enables auto-attach behavior where MCP clients in subdirectories can find sessions started in parent directories.
func (*SessionRegistry) GenerateSessionCode ¶
func (r *SessionRegistry) GenerateSessionCode(command string) string
GenerateSessionCode generates a unique session code based on command name. Returns codes like "claude-1", "claude-2", etc.
func (*SessionRegistry) Get ¶
func (r *SessionRegistry) Get(code string) (*Session, bool)
Get retrieves a session by code.
func (*SessionRegistry) Heartbeat ¶
func (r *SessionRegistry) Heartbeat(code string) error
Heartbeat updates the last seen time for a session.
func (*SessionRegistry) Info ¶
func (r *SessionRegistry) Info() SessionInfo
Info returns statistics about the session registry.
func (*SessionRegistry) List ¶
func (r *SessionRegistry) List(projectPath string, global bool) []*Session
List returns all sessions, optionally filtered by project path.
func (*SessionRegistry) ListActive ¶
func (r *SessionRegistry) ListActive(projectPath string, global bool) []*Session
ListActive returns only active sessions.
func (*SessionRegistry) Register ¶
func (r *SessionRegistry) Register(session *Session) error
Register adds a new session to the registry.
func (*SessionRegistry) TotalRegistered ¶
func (r *SessionRegistry) TotalRegistered() int64
TotalRegistered returns the total number of sessions registered.
func (*SessionRegistry) TotalUnregistered ¶
func (r *SessionRegistry) TotalUnregistered() int64
TotalUnregistered returns the total number of sessions unregistered.
func (*SessionRegistry) Unregister ¶
func (r *SessionRegistry) Unregister(code string) error
Unregister removes a session from the registry.
type SessionStatus ¶
type SessionStatus string
SessionStatus represents the current state of a session.
const ( // SessionStatusActive indicates the session is running and responsive. SessionStatusActive SessionStatus = "active" // SessionStatusDisconnected indicates the session has not sent a heartbeat recently. SessionStatusDisconnected SessionStatus = "disconnected" )