terminal

package
v0.8.19 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package terminal defines the process-neutral contract implemented by every Relayer terminal backend. It deliberately contains no Bubble Tea, PTY, tmux command or interception code.

Index

Constants

View Source
const MaxLineBytes = adapters.MaxLineBytes

MaxLineBytes is the maximum line size before the core appends one carriage return. It aliases the Processor limit so transports cannot drift.

Variables

View Source
var (
	ErrClosed          = errors.New("terminal backend closed")
	ErrSessionNotFound = errors.New("terminal session not found")
	ErrNotAttachable   = errors.New("terminal session not attachable")
	ErrUnavailable     = errors.New("terminal backend unavailable")
	ErrUnsupported     = errors.New("terminal backend not supported")
	// ErrSessionRunning rejects releasing a session identity while its process
	// may still be alive. A replacement session must never be started under a
	// identity whose previous process has not been proven gone.
	ErrSessionRunning = errors.New("terminal session still running")
	// These aliases preserve one errors.Is identity from the Processor through
	// session, backend, router and presentation boundaries.
	ErrEventPending          = adapters.ErrEventPending
	ErrInvalidLine           = adapters.ErrInvalidLine
	ErrLineUnsupported       = adapters.ErrLineUnsupported
	ErrLineDeliveryUncertain = adapters.ErrLineDeliveryUncertain
)

Functions

This section is empty.

Types

type Backend

type Backend interface {
	Name() string
	Start(context.Context, agent.Spec, Size) (Info, error)
	Send(context.Context, SessionID, []byte) error
	Resize(context.Context, SessionID, Size) error
	Snapshot(context.Context, SessionID) (Snapshot, error)
	AttachCommand(context.Context, SessionID) (*exec.Cmd, error)
	Stop(context.Context, SessionID) error
	Close(context.Context) error
}

Backend is the authoritative terminal boundary used by the application. Implementations own their processes and resources; all potentially blocking operations accept a context. Send transmits data exactly as supplied.

type EventSender

type EventSender interface {
	SendEvent(context.Context, SessionID, string, []byte) error
}

EventSender atomically delivers a decision for the exact pending event. Implementations acknowledge eventID only after data is written successfully.

type Info

type Info struct {
	ID             SessionID
	Name           string
	DisplayCommand string
	Backend        string
	Adapter        string
	Shell          bool
}

Info is immutable, display-safe metadata returned after startup. Backend is always concrete (pty or tmux), never the auto selector.

type LineSender

type LineSender interface {
	SendLine(context.Context, SessionID, string) error
}

LineSender is the optional, atomic ordinary-input boundary. Implementations must reject input while an actionable event is pending and must append the line terminator in the core rather than accepting pre-encoded raw bytes.

type OperationError

type OperationError struct {
	Backend   string
	Operation string
	SessionID SessionID
	Err       error
}

OperationError adds safe context to a backend failure without requiring an implementation to expose command arguments or environment values.

func (*OperationError) Error

func (e *OperationError) Error() string

func (*OperationError) Unwrap

func (e *OperationError) Unwrap() error

type PendingEventProvider

type PendingEventProvider interface {
	PendingEvent(context.Context, SessionID) (*adapters.Event, error)
}

PendingEventProvider returns only cached semantic state. Implementations must not query a process or spawn an external command; Bubble Tea uses this path while reducing an already-delivered event.

type RawSender added in v0.6.0

type RawSender interface {
	SendRaw(context.Context, SessionID, []byte) error
}

RawSender is an optional interface for backends supporting direct raw input streams (interactive terminal emulation, control signals like Ctrl+C, cursor navigation).

type Recorder added in v0.7.0

type Recorder interface {
	StartSession(info Info, size Size, at time.Time)
	RecordOutput(id SessionID, at time.Time, data []byte)
	RecordInput(id SessionID, at time.Time, data []byte)
	RecordResize(id SessionID, at time.Time, size Size)
	FinishSession(id SessionID, at time.Time, exitCode *int)
}

Recorder receives a session transcript. Every method is fire-and-forget: an implementation must never block the caller, never return an error, and never panic. The PTY read loop calls RecordOutput.

type RecorderAware added in v0.7.0

type RecorderAware interface{ SetRecorder(Recorder) }

RecorderAware is implemented by backends that can stream a transcript.

type SessionID

type SessionID = string

SessionID is stable for the lifetime of one Relayer run.

type SessionRemover added in v0.4.0

type SessionRemover interface {
	Remove(context.Context, SessionID) error
}

SessionRemover is the optional per-agent lifecycle capability that releases a fully stopped session identity so a later Start may reuse it. Implementations must prove the previous process is gone before forgetting the session; when that proof is impossible they return ErrSessionRunning and keep the identity locked.

type Size

type Size struct {
	Columns int
	Rows    int
}

Size is the usable character-cell area exposed to the child terminal.

func (Size) Normalize

func (s Size) Normalize() Size

Normalize returns a size accepted by PTY and tmux implementations.

type Snapshot

type Snapshot struct {
	ID       SessionID
	Status   Status
	Running  bool
	Attached bool
	ExitCode *int
	Output   string
	Pending  *adapters.Event
	Revision uint64
}

Snapshot reconciles bounded output, process status and a possible prompt after asynchronous activity such as returning from an attached tmux client.

type Status

type Status string

Status describes both process lifecycle and client attachment state.

const (
	StatusRunning  Status = "running"
	StatusDetached Status = "detached"
	StatusAttached Status = "attached"
	StatusExited   Status = "exited"
	StatusFailed   Status = "failed"
)

Jump to

Keyboard shortcuts

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