Documentation
¶
Overview ¶
Package session manages persistent SSH PTY shell sessions for the MCP terminal tool.
Ownership: the Manager owns every managedSession it stores and the PTY channel inside it. A session is closed when it is replaced (generation change), idles past its TTL, its reader observes EOF, or the Manager shuts down. The idle reaper goroutine is started lazily with the first session and joined by Shutdown.
Index ¶
Constants ¶
const ( DefaultTimeout = 5 * time.Second DefaultIdleTTL = 30 * time.Minute DefaultMaxSessions = 16 DefaultMaxTotalSessions = 64 )
Variables ¶
var ( // ErrSessionBusy is returned when a new command is submitted while the // previous command has not yet reported completion. ErrSessionBusy = errors.New("terminal session is still running a previous command; poll with an empty cmd or send SIGINT/EOF/SIGTERM/SIGKILL first") // ErrSessionInUse is returned when another Execute call is actively waiting // on the session; callers should wait for that call to return or send a // control signal (SIGINT/EOF/SIGTERM/SIGKILL) to interrupt it. ErrSessionInUse = errors.New("another call is currently waiting on this terminal session; wait for it to return or send SIGINT/EOF/SIGTERM/SIGKILL to interrupt") // ErrSessionNotFound is returned when a poll or signal targets a session // that has not been created or has already closed/expired. ErrSessionNotFound = errors.New("terminal session does not exist or has expired") // ErrTooManySessions is returned when the live session limit is reached. ErrTooManySessions = errors.New("too many persistent terminal sessions") // ErrManagerClosed is returned after Shutdown. ErrManagerClosed = errors.New("session manager is shut down") )
Functions ¶
func IsSignalCommand ¶
IsSignalCommand reports whether the command string represents a terminal control signal.
Types ¶
type ExecuteRequest ¶
type ExecuteRequest struct {
Key Key
// Generation identifies the admitted target configuration. A session
// created under a different generation is closed and replaced so that
// configuration or credential changes are never bypassed by reuse.
// Generation is compared by equality only; callers must ensure that no
// requests carrying a stale generation are admitted after a configuration
// update (enforced by the state.Coordinator update barrier).
Generation string
Dialect ssh.LaunchDialect
Dial func(ctx context.Context) (ports.PTYSession, error)
Command string
Cwd string
Timeout time.Duration
}
ExecuteRequest describes a command, signal, or poll operation on a persistent session.
type ExecuteResult ¶
type ExecuteResult struct {
Output string
ExitCode *uint32
State State
Truncated bool
NewSession bool
}
ExecuteResult contains incremental terminal output and completion state.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager maintains active PTY sessions indexed by Key.
func NewManager ¶
NewManager creates a persistent PTY session manager with the given idle TTL.
func (*Manager) Execute ¶
func (m *Manager) Execute(ctx context.Context, req ExecuteRequest) (ExecuteResult, error)
Execute runs a command, sends a control signal, or polls incremental output on the named session.
type State ¶
type State int
State describes what is known about the command after an Execute call.
const ( // StateIdle means no command was in flight (plain poll or signal). StateIdle State = iota // StateCompleted means the completion sentinel was observed; ExitCode is set. StateCompleted // StateRunning means the wait window elapsed before completion. StateRunning // StateLost means the session ended before the completion sentinel was // observed; the command outcome is unknown. StateLost )