terminalservice

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package terminalservice runs a real shell session on the local machine. Chains call into this to execute commands and read back real output.

Index

Constants

View Source
const DefaultIdleTimeout = 30 * time.Minute

DefaultIdleTimeout is used when Config.IdleTimeout is unset.

Variables

View Source
var (
	// ErrDisabled is returned when the terminal feature is off.
	ErrDisabled = errors.New("terminal: disabled")
	// ErrNotImplemented is returned on platforms without PTY support (e.g. Windows).
	ErrNotImplemented = errors.New("terminal: not implemented on this platform")
	// ErrSessionNotFound is returned for unknown session IDs.
	ErrSessionNotFound = errors.New("terminal: session not found")
	// ErrTooManySessions is returned when the per-process session slot is occupied.
	ErrTooManySessions = errors.New("terminal: too many concurrent sessions")
)

Functions

func CwdUnderRoot

func CwdUnderRoot(allowedRoot, cwd string) error

CwdUnderRoot ensures cwd is the same as allowedRoot or a subdirectory (after clean/abs).

func ValidateShell

func ValidateShell(shell string) error

ValidateShell returns an error if shell is not in the allowlist.

Types

type Config

type Config struct {
	Enabled      bool
	AllowedRoot  string
	DefaultShell string
	// IdleTimeout is the maximum time a detached session is kept alive.
	// Zero disables idle reaping.
	IdleTimeout time.Duration
}

Config holds terminal service settings.

func ParseEnv

func ParseEnv(terminalEnabled, terminalAllowedRoot, terminalShell, terminalIdleTimeout string) (Config, error)

ParseEnv builds a Config from raw string fields. terminalIdleTimeout accepts any time.ParseDuration string; empty defaults to DefaultIdleTimeout.

type CreateRequest

type CreateRequest struct {
	CWD   string
	Cols  int
	Rows  int
	Shell string // optional; defaults from config
}

CreateRequest is input for an interactive shell session.

type CreateResponse

type CreateResponse struct {
	ID string
}

CreateResponse is returned after a session is allocated.

type ResizeMsg

type ResizeMsg struct {
	Cols int
	Rows int
}

ResizeMsg carries terminal dimension changes from the WebSocket handler.

type Service

type Service interface {
	Create(ctx context.Context, principal string, req CreateRequest) (*CreateResponse, error)
	Close(ctx context.Context, principal, id string) error
	CloseAll(ctx context.Context) error
	Attach(ctx context.Context, principal, id string, conn io.ReadWriteCloser, resizeCh <-chan ResizeMsg) error
	Get(ctx context.Context, principal, id string) (*SessionInfo, error)
	List(ctx context.Context, principal string, createdAtCursor *time.Time, limit int) ([]*SessionInfo, error)
	UpdateGeometry(ctx context.Context, principal, id string, cols, rows int) error
	// ReapIdle closes the session if it has been detached longer than [Config.IdleTimeout].
	// A zero IdleTimeout disables reaping.
	ReapIdle(ctx context.Context) error
}

Service manages PTY-backed terminal sessions.

func New

func New(cfg Config, db libdb.DBManager, nodeInstanceID string) (Service, error)

New constructs a terminal Service. When cfg.Enabled is false, returns NewDisabled with a nil error. db may be nil only when cfg.Enabled is false. Build cfg with ParseEnv.

func NewDisabled

func NewDisabled() Service

NewDisabled returns a service that rejects mutating operations with ErrDisabled (feature off).

func WithActivityTracker

func WithActivityTracker(svc Service, tracker libtracker.ActivityTracker) Service

WithActivityTracker wraps a Service with activity logging.

type SessionInfo

type SessionInfo = terminalstore.Session

SessionInfo is persisted metadata for a terminal session (from DB).

Jump to

Keyboard shortcuts

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