terminal

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package terminal is the terminal gateway plugin: a chat gateway whose "channels" are tabs in the local TUI. It self-registers like any gateway (init → contracts.Register) and implements Gateway + ChannelReader + EventSink so the daemon hub drives it exactly like Discord — polling Read for typed lines and fanning the live event stream to it via Emit. The TUI binds to the active instance through Active().

Index

Constants

View Source
const ChannelID = "terminal"

ChannelID is the default conversation id used by the terminal gateway.

Variables

This section is empty.

Functions

This section is empty.

Types

type Terminal

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

Terminal is the in-process terminal gateway. Typed lines arrive via Submit (tagged with the active channel) and are drained per-channel by the hub through Read; outbound events (EmitTo/Emit/Post/Reply) are forwarded to the TUI as RoutedEvents on Frontend.

func New

func New() *Terminal

New builds an unbound terminal gateway.

func (*Terminal) Archive

func (t *Terminal) Archive(_ context.Context, id string) error

func (*Terminal) BindSessionControl

func (t *Terminal) BindSessionControl(c contracts.SessionControl)

BindSessionControl stores the hub controller so the TUI can drive the session lifecycle (create/close/list) and enumerate sessions for tab labels.

func (*Terminal) ChannelRef

func (t *Terminal) ChannelRef(id string) string

ChannelRef renders a terminal channel id bare: a plain TUI has no mention markup, so the operator just sees the id.

func (*Terminal) Close

func (t *Terminal) Close(name string, force bool) (string, error)

Close tears a session down through the typed SessionControl seam, so the TUI's close action never assembles "session close" flag argv.

func (*Terminal) Commands

func (t *Terminal) Commands() []tui.CommandSpec

Commands is the curated palette advertised to the TUI. Every entry's leading verb is a member of terminalVerbs, so the palette can never surface a command Dispatch would reject; terminal_test.go asserts this invariant.

func (*Terminal) Control

func (t *Terminal) Control() contracts.SessionControl

Control exposes the bound SessionControl to the TUI (nil before bind).

func (*Terminal) CreateUnder

func (t *Terminal) CreateUnder(_ context.Context, _, name string) (string, error)

func (*Terminal) DefaultChannel

func (t *Terminal) DefaultChannel() string

func (*Terminal) Dispatch

func (t *Terminal) Dispatch(args []string) (string, error)

Dispatch forwards an operator argv to the bound SessionControl, prepending --terminal_only when creating a session without an explicit gateway selector so TUI-created sessions bind to this terminal and appear as tabs. The first token is gated against terminalVerbs before it ever reaches the registry.

func (*Terminal) Emit

func (t *Terminal) Emit(e contracts.Event)

Emit (legacy EventSink) routes to the default single channel. The hub calls this when it sees only EventSink; RoutedEventSink takes priority.

func (*Terminal) EmitTo

func (t *Terminal) EmitTo(conv contracts.Conversation, e contracts.Event)

EmitTo routes a turn event to the conversation's tab in the TUI.

func (*Terminal) Enabled

func (t *Terminal) Enabled() bool

func (*Terminal) EnsureChannel

func (t *Terminal) EnsureChannel(context.Context, string, string) (contracts.Channel, error)

func (*Terminal) ForumPost

func (t *Terminal) ForumPost(ctx context.Context, parentID, name, _ string) (string, error)

func (*Terminal) Frontend

func (t *Terminal) Frontend() <-chan tui.RoutedEvent

Frontend yields routed outbound events for the TUI to render.

func (*Terminal) Interrupt

func (t *Terminal) Interrupt(name string) bool

Interrupt cancels a session's in-flight turn through the bound SessionControl, for esc-to-interrupt from the TUI. Reports false when no control is bound or no live session by that name is driving.

func (*Terminal) Kind

func (t *Terminal) Kind(_ context.Context, _ string) (string, error)

func (*Terminal) Manifest

func (t *Terminal) Manifest() contracts.Manifest

func (*Terminal) Menu

func (*Terminal) Post

func (*Terminal) Read

func (t *Terminal) Read(_ context.Context, channelID string, _ int, _ string) ([]contracts.Message, error)

Read drains and returns the lines queued for channelID since the last Read. The hub polls this per-session with the session's own channel, so each session drains only its own input.

func (*Terminal) Reply

func (*Terminal) Resume

func (t *Terminal) Resume(name string) (string, error)

Resume revives an archived session by name through the bound SessionControl, for the /resume picker.

func (*Terminal) RunForeground

func (t *Terminal) RunForeground(ctx context.Context, cancel context.CancelFunc) error

RunForeground satisfies contracts.Foreground: the terminal gateway owns the process's main thread by running its Bubbletea TUI, blocking until the user quits (which calls cancel to tear the daemon down) or ctx is cancelled. The composition root runs this for the one bound gateway that implements Foreground, on an interactive TTY only.

func (*Terminal) Scrollback

func (t *Terminal) Scrollback(name string) []contracts.ScrollbackLine

Scrollback returns a session's recorded history lines through the bound SessionControl (nil until bound), so a reopened tab can seed its scrollback.

func (*Terminal) Send

func (t *Terminal) Send(_ context.Context, channelID, content string) error

func (*Terminal) Sessions

func (t *Terminal) Sessions() []contracts.SessionInfo

Sessions returns the hub's sessions for tab labels (nil until SessionControl is bound — see BindSessionControl).

func (*Terminal) Submit

func (t *Terminal) Submit(channel, text string, attachments []tui.Attachment)

Submit enqueues a line the user typed in the TUI as an inbound message on the given channel (the active tab's session channel). Staged attachments are carried as file:// URLs so the host bridge reads them off local disk instead of a CDN.

func (*Terminal) Unreact

func (t *Terminal) Unreact(context.Context, string, string, string) error

func (*Terminal) UpsertStatusMessage

func (t *Terminal) UpsertStatusMessage(_ context.Context, channelID, _, content string) (string, error)

Directories

Path Synopsis
Package tui renders a gateway's live event stream and captures the operator's input, driving it through the narrow Backend interface.
Package tui renders a gateway's live event stream and captures the operator's input, driving it through the narrow Backend interface.

Jump to

Keyboard shortcuts

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