session

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrHumanControls = errors.New("human controls session")
	ErrObserveOnly   = errors.New("human is observe-only until takeover")
	ErrAgentControls = errors.New("agent controls session")
)

Concurrency errors for API mapping.

View Source
var ErrNotFound = errors.New("session not found")

ErrNotFound indicates an unknown session ID.

Functions

This section is empty.

Types

type AccessGate

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

AccessGate tracks concurrent agent/human access for one session.

func (*AccessGate) AgentResize

func (g *AccessGate) AgentResize(cols, rows int) error

AgentResize records agent-requested dimensions and checks authority.

func (*AccessGate) AgentWrite

func (g *AccessGate) AgentWrite() error

AgentWrite checks whether agent input is allowed.

func (*AccessGate) Controller

func (g *AccessGate) Controller() Controller

Controller returns the active PTY controller.

func (*AccessGate) HumanResize

func (g *AccessGate) HumanResize() error

HumanResize checks human resize authority.

func (*AccessGate) HumanWrite

func (g *AccessGate) HumanWrite() error

HumanWrite checks whether human input is allowed.

func (*AccessGate) Release

func (g *AccessGate) Release() (cols, rows int, restore bool)

Release returns control to the agent and reports whether agent size should be restored.

func (*AccessGate) Takeover

func (g *AccessGate) Takeover()

Takeover grants human PTY control.

type Controller

type Controller string

Controller identifies who may write to the PTY and resize it (R14, KTD5).

const (
	ControllerAgent Controller = "agent"
	ControllerHuman Controller = "human"
)

type Manager

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

Manager owns active sessions keyed by ID.

func NewManager

func NewManager() *Manager

NewManager creates an empty session manager.

func (*Manager) Close

func (m *Manager) Close(id string) error

Close terminates a session and removes it from the manager.

func (*Manager) CloseExcept

func (m *Manager) CloseExcept(keep map[string]struct{}) ([]string, error)

CloseExcept terminates all sessions whose IDs are not in keep.

func (*Manager) Create

func (m *Manager) Create(workspace string, opts config.Session) (*Session, error)

Create starts a new session in workspace with optional dimension overrides.

func (*Manager) Get

func (m *Manager) Get(id string) (*Session, bool)

Get returns a session by ID.

func (*Manager) List

func (m *Manager) List() []SessionInfo

List returns summaries of all active sessions sorted newest-first by creation time.

func (*Manager) Release

func (m *Manager) Release(id string) error

Release returns PTY control to the agent, restoring last agent size when set (KTD5).

func (*Manager) ResizeAgent

func (m *Manager) ResizeAgent(id string, cols, rows int) error

ResizeAgent updates PTY size when the agent controls the session (R2, R14).

func (*Manager) ResizeHuman

func (m *Manager) ResizeHuman(id string, cols, rows int) error

ResizeHuman updates PTY size when the human controls the session (R14).

func (*Manager) Takeover

func (m *Manager) Takeover(id string) error

Takeover grants human PTY control.

func (*Manager) WriteAgentInput

func (m *Manager) WriteAgentInput(id string, data []byte, raw bool, submit bool) error

WriteAgentInput sends agent bytes when the agent controls the session.

func (*Manager) WriteHumanInput

func (m *Manager) WriteHumanInput(id string, data []byte, raw bool, submit bool) error

WriteHumanInput sends human bytes when the human has taken over.

func (*Manager) WritePTYResponse added in v0.2.0

func (m *Manager) WritePTYResponse(id string, data []byte) error

WritePTYResponse forwards auto-generated terminal replies to the PTY. These bypass observe-only gating so apps like Neovim can query colors in observe mode.

type Session

type Session struct {
	ID                       string
	Workspace                string
	CLIName                  string
	CreatedAt                time.Time
	LastMeaningfulActivityAt time.Time
	PTY                      *pty.Master
	Emulator                 *term.Emulator
	Access                   *AccessGate
	// contains filtered or unexported fields
}

Session is one workspace-bound PTY with a shared emulator (R1).

func (*Session) ReplayForBrowser

func (s *Session) ReplayForBrowser() []byte

ReplayForBrowser prefers raw PTY bytes (preserves truecolor) over emulator serialize.

func (*Session) ReplayRaw

func (s *Session) ReplayRaw() []byte

ReplayRaw returns a copy of recent raw PTY output for browser replay.

func (*Session) ScreenDiffSince

func (s *Session) ScreenDiffSince(since uint64) (term.ScreenDiff, bool)

ScreenDiffSince returns an incremental diff when the client's since version is cached.

func (*Session) ScreenSnapshot

func (s *Session) ScreenSnapshot(includeCells bool) term.ScreenSnapshot

ScreenSnapshot captures the current structured screen, optionally with per-cell detail.

func (*Session) ScreenVersion

func (s *Session) ScreenVersion() uint64

ScreenVersion returns a monotonic counter bumped on PTY output.

func (*Session) SubscribeOutput

func (s *Session) SubscribeOutput(buf int) chan []byte

SubscribeOutput registers for raw PTY output broadcasts (browser WS).

func (*Session) UnsubscribeOutput

func (s *Session) UnsubscribeOutput(ch chan []byte)

UnsubscribeOutput removes a PTY output subscriber.

type SessionInfo

type SessionInfo struct {
	SessionID                string    `json:"session_id"`
	Workspace                string    `json:"workspace"`
	CLI                      string    `json:"cli,omitempty"`
	Cols                     int       `json:"cols"`
	Rows                     int       `json:"rows"`
	Controller               string    `json:"controller"`
	CreatedAt                time.Time `json:"created_at"`
	LastMeaningfulActivityAt time.Time `json:"last_meaningful_activity_at"`
}

SessionInfo is a read-only summary for discovery APIs.

Jump to

Keyboard shortcuts

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