session

package
v0.1.1-alpha Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package session owns PTY-backed process lifecycles and exposes neutral, typed events. It deliberately has no dependency on Bubble Tea.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClosed = errors.New("PTY session closed")
	// ErrStopUncertain means Relayer requested termination but could not confirm
	// that both the command leader and its PTY process group disappeared. A
	// caller must not start a replacement process while this error is present.
	ErrStopUncertain = errors.New("PTY session stop not confirmed")
)

ErrClosed is returned when an operation targets a PTY that has already been closed or a manager that no longer accepts sessions.

Functions

This section is empty.

Types

type AdapterEvent

type AdapterEvent struct {
	Event adapters.Event
}

AdapterEvent carries the single backend-neutral semantic representation produced by an adapter or by a real session lifecycle transition.

type Error

type Error struct {
	SessionID string
	Err       error
}

Error reports an unexpected error while reading the PTY.

type Event

type Event interface {
	// contains filtered or unexported methods
}

Event is emitted by Manager for asynchronous session state changes. The unexported marker keeps the event set closed while allowing consumers to use type switches over the exported concrete types.

type Exited

type Exited struct {
	SessionID string
	Err       error
}

Exited is retained for source compatibility. Managers now publish a real AdapterEvent with type process_exit instead of emitting this legacy value.

type Info

type Info = terminal.Info

Info remains an alias for compatibility with the original PTY API while every backend now shares terminal.Info.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager is the sole owner of process lifecycles and PTY descriptors.

func NewManager

func NewManager(
	parent context.Context,
	events chan<- Event,
	patterns []intercept.Pattern,
	ringCapacity int,
) (*Manager, error)

NewManager validates every prompt pattern before any process can start.

func NewManagerWithRegistry

func NewManagerWithRegistry(
	parent context.Context,
	events chan<- Event,
	registry *adapters.Registry,
	ringCapacity int,
) (*Manager, error)

NewManagerWithRegistry creates a PTY owner around the application adapter registry. The registry is validated before any process can start and creates independent adapter state for every session.

func (*Manager) BeginShutdown

func (m *Manager) BeginShutdown()

BeginShutdown immediately unblocks essential event senders. Close performs descriptor/process cleanup and joins every owned goroutine.

func (*Manager) Close

func (m *Manager) Close()

func (*Manager) Context

func (m *Manager) Context() context.Context

func (*Manager) Done

func (m *Manager) Done(sessionID string) (<-chan struct{}, error)

Done exposes lifecycle completion without leaking the underlying process or PTY descriptor. The channel is closed before the corresponding process_exit AdapterEvent is emitted.

func (*Manager) Name

func (m *Manager) Name() string

Name identifies the concrete backend without exposing PTY implementation details to the application or TUI.

func (*Manager) Output

func (m *Manager) Output(sessionID string) (string, error)

func (*Manager) PendingEvent

func (m *Manager) PendingEvent(sessionID string) (*adapters.Event, error)

PendingEvent returns an independent copy of the actionable occurrence still awaiting a decision, if any.

func (*Manager) Resize

func (m *Manager) Resize(sessionID string, columns, rows int) error

func (*Manager) Result

func (m *Manager) Result(sessionID string) (exited bool, waitErr error, exitCode *int, err error)

Result returns a stable lifecycle snapshot once Wait has completed.

func (*Manager) Revision

func (m *Manager) Revision(sessionID string) (uint64, error)

Revision is the latest semantic event occurrence sequence for the session.

func (*Manager) SendData

func (m *Manager) SendData(sessionID string, data []byte) error

SendData is the compatibility path for callers that do not yet retain the actionable event ID. It still uses Processor.Resolve so acknowledgement only happens after the exact bytes have been delivered successfully.

func (*Manager) SendDataForEvent

func (m *Manager) SendDataForEvent(sessionID, eventID string, data []byte) error

SendDataForEvent atomically validates the pending occurrence, delivers the exact bytes and acknowledges only after a successful write.

func (*Manager) SendInput

func (m *Manager) SendInput(sessionID string, value string) error

func (*Manager) SendLine

func (m *Manager) SendLine(ctx context.Context, sessionID, line string) error

SendLine is the ordinary-input path. Processor.SendLine atomically confirms that the process is live and no actionable event is pending, then appends exactly one carriage return without acknowledging semantic state.

func (*Manager) Start

func (m *Manager) Start(spec agent.Spec, columns, rows int) (Info, error)

Start validates and launches one direct or explicitly requested shell command with a correctly sized PTY.

func (*Manager) Stop

func (m *Manager) Stop(sessionID string) error

Stop terminates one owned session without affecting its siblings.

type OutputAvailable

type OutputAvailable struct {
	SessionID string
}

OutputAvailable invalidates a consumer's cached output snapshot. The latest bounded snapshot is retrieved with Manager.Output.

Jump to

Keyboard shortcuts

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