terminalaccess

package
v1.5.97 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 13 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package terminalaccess keeps GUI terminal permissions separate from both session labels and terminal contents. Only the operator-facing host grants access; model-supplied names are never credentials.

Index

Constants

This section is empty.

Variables

View Source
var ErrDenied = errors.New("terminal access denied")

Functions

func UserShell

func UserShell() []string

UserShell returns the login shell chosen by the person, as terminal apps do.

Types

type Connection

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

Connection is the MyGo terminal's Conn. Input from the terminal view and input from an Agent meet at the same lock before either reaches the PTY.

func NewConnection

func NewConnection(registry *Registry, pane string, source io.ReadWriteCloser, onTakeover func(string)) (*Connection, error)

func (*Connection) AgentWrite

func (c *Connection) AgentWrite(agent string, b []byte) (int, error)

AgentWrite must be called only after the tool's execution and host-control gates approve this exact input. Registry.Use rechecks the current lease.

func (*Connection) AgentWriteChecked

func (c *Connection) AgentWriteChecked(agent string, b []byte, check func() error) (int, error)

AgentWriteChecked performs an additional live-policy check while the pane's input lease is held, directly before writing to the underlying PTY.

func (*Connection) Barrier

func (c *Connection) Barrier(ctx context.Context, send func([]byte)) error

Barrier enqueues an unguessable marker into MyGo's input queue and consumes it here, never forwarding it to the PTY. A timed-out marker remains reserved until it arrives, so it cannot later leak into the person's shell.

func (*Connection) Close

func (c *Connection) Close() error

func (*Connection) Observe

func (c *Connection) Observe(after uint64) (uint64, bool, <-chan struct{})

Observe returns an event only when there is no newer output yet.

func (*Connection) Read

func (c *Connection) Read(b []byte) (int, error)

func (*Connection) Resize

func (c *Connection) Resize(cols, rows int) error

func (*Connection) Revision

func (c *Connection) Revision() (uint64, bool)

Revision and Wait provide event-driven output observation without polling. The caller must authorize reading before and after waiting.

func (*Connection) SetViewLocked

func (c *Connection) SetViewLocked(locked bool)

SetViewLocked is set only after the UI disabled local input and Barrier drained already-queued keystrokes. The terminal can still emit protocol replies while locked; those must not steal an Agent's control lease.

func (*Connection) ViewLocked

func (c *Connection) ViewLocked() bool

func (*Connection) Wait

func (c *Connection) Wait(ctx context.Context, after uint64) (uint64, bool, error)

func (*Connection) Write

func (c *Connection) Write(b []byte) (int, error)

Write is reserved for the local MyGo view and its protocol replies.

type Process

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

Process owns a cross-platform PTY and its child. It is intentionally separate from the terminal emulator, so local and authorized Agent writes go through Connection instead of being queued independently by MyGo.

func StartProcess

func StartProcess(o ProcessOptions) (*Process, error)

StartProcess starts exactly argv in a PTY; it does not authorize a command or create a sandbox. Agent callers must supply a previously authorized envelope.

func (*Process) Close

func (p *Process) Close() error

Close terminates the GUI-owned process and closes its PTY. Attaching to an existing bash TTY uses a different connection whose Close only detaches.

func (*Process) Done

func (p *Process) Done() <-chan struct{}

func (*Process) Read

func (p *Process) Read(b []byte) (int, error)

func (*Process) Resize

func (p *Process) Resize(cols, rows int) error

func (*Process) Write

func (p *Process) Write(b []byte) (int, error)

type ProcessOptions

type ProcessOptions struct {
	Argv    []string
	Dir     string
	Env     []string // nil inherits the user's environment
	Cleanup func()   // invoked after exit, including a failed start
}

type Registry

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

Registry is owned by one GUI process. Agent and pane IDs must be unique for their lifetime and never reused after removal.

func New

func New() *Registry

func (*Registry) Access

func (r *Registry) Access(paneID, agentID string) (read, write bool, owner string)

Access reports an agent's current rights without exposing the identities of other readers. Callers still have to use Use immediately before an action.

func (*Registry) AddAgent

func (r *Registry) AddAgent(id, project string) error

func (*Registry) AddAgentPane

func (r *Registry) AddAgentPane(id, agentID, parentID string) error

AddAgentPane atomically validates the creator and, for a split, its current write lease on the exact parent. A created pane starts with that Agent's read and write access; no later focus or project switch can change its owner.

func (*Registry) AddPane

func (r *Registry) AddPane(id, project string) error

func (*Registry) CanClose

func (r *Registry) CanClose(paneID, agentID string) bool

func (*Registry) Grant

func (r *Registry) Grant(paneID, agentID string, read, write, transfer bool) error

Grant is an operator action. Write access is exclusive: transfer must be explicitly approved when a different agent already holds it. Read and write are independent so granting input does not silently expose past output.

func (*Registry) MarkExited

func (r *Registry) MarkExited(paneID string)

MarkExited revokes input while retaining explicit readers and the creator's ability to close its finished pane. It does not remove the displayed output.

func (*Registry) Owner

func (r *Registry) Owner(paneID string) string

Owner is display-only; authorization must still be checked by Use.

func (*Registry) RemoveAgent

func (r *Registry) RemoveAgent(id string)

func (*Registry) RemoveAgentPane

func (r *Registry) RemoveAgentPane(paneID, agentID string) error

RemoveAgentPane atomically checks the exact live writer before removing the pane. Closing its underlying process happens after the registry lock releases.

func (*Registry) RemovePane

func (r *Registry) RemovePane(id string)

func (*Registry) Revoke

func (r *Registry) Revoke(paneID, agentID string)

func (*Registry) SystemInput

func (r *Registry) SystemInput(paneID string, fn func() error) error

SystemInput serializes terminal-protocol replies while the view is locked to an Agent. The caller must ensure local user input is disabled first.

func (*Registry) TakeBack

func (r *Registry) TakeBack(paneID string)

TakeBack revokes whichever Agent currently has write control without changing separately granted read access.

func (*Registry) Use

func (r *Registry) Use(paneID, agentID string, write bool, fn func() error) error

Use serializes input and rechecks authority immediately before fn. Revocation stops future input; a write already dispatched may finish. The state mutex is not held during a potentially blocking PTY write, so the UI can revoke it.

func (*Registry) UserInput

func (r *Registry) UserInput(paneID string, fn func() error) (string, error)

UserInput takes back exclusive write control before writing bytes from the local terminal view. The same pane lock guards agent writes and transfer, so a queued user write cannot interleave with an authorized agent operation.

func (*Registry) WatchRead

func (r *Registry) WatchRead(paneID, agentID string) (<-chan struct{}, error)

WatchRead returns an event closed when pane permissions or lifecycle change. It checks read access while subscribing, so callers cannot miss revocation.

Jump to

Keyboard shortcuts

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