tui

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: Apache-2.0 Imports: 63 Imported by: 0

Documentation

Overview

Package tui presents the Coding Runtime as a terminal-first chat interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, options Options) (returnErr error)

Run owns the terminal Program and closes any acquired Controller after the terminal has been restored.

Types

type AltScreenPolicy added in v0.1.6

type AltScreenPolicy uint8

AltScreenPolicy selects the terminal buffer independently of the layout.

const (
	// AltScreenAuto uses the alternate screen unless the environment is known to
	// limit it.
	AltScreenAuto AltScreenPolicy = iota
	// AltScreenAlways forces the alternate screen.
	AltScreenAlways
	// AltScreenNever draws the layout inline in the main buffer.
	AltScreenNever
)

type Bootstrap

type Bootstrap func(context.Context, bool) (Controller, error)

Bootstrap loads configuration and opens the first Runtime. trustProject is the user's explicit Workspace trust decision.

type BuildStamp added in v0.1.7

type BuildStamp struct {
	Version string
	Commit  string
	Date    string
}

Options contain the CLI-owned resources used by one TUI Program. BuildStamp is the build identity the TUI reports, so a display surface never has to import the CLI that stamped the binary.

type Controller

type Controller interface {
	Prompt(context.Context, ...ai.Message) iter.Seq2[coding.Event, error]
	Continue(context.Context) iter.Seq2[coding.Event, error]
	Resolve(context.Context, approval.Resolution) iter.Seq2[coding.Event, error]
	ResolveQuestion(context.Context, question.Resolution) iter.Seq2[coding.Event, error]
	RejectQuestion(context.Context, string, string) iter.Seq2[coding.Event, error]
	Tree(context.Context) (coding.SessionTree, error)
	PreviewCompaction(context.Context) (coding.CompactionPreview, error)
	Navigate(context.Context, string, bool) iter.Seq2[coding.Event, error]
	Compact(context.Context, coding.CompactionRequest) iter.Seq2[coding.Event, error]
	Steer(...ai.Message) error
	FollowUp(...ai.Message) error
	Cancel() error
	Reload(context.Context) error
	ListWorkspaceFiles(context.Context) (attachment.Snapshot, error)
	ResolveWorkspaceFile(context.Context, attachment.Reference) (attachment.Resolved, error)
	Snapshot() coding.State
	SessionID() string
	History(context.Context, coding.HistoryRequest) (coding.HistoryPage, error)
	Model() runtimecontrol.ModelState
	Capabilities() ai.Capabilities
	Mode() runtimecontrol.ModeState
	SetMode(context.Context, coding.OperatingMode) error
	Permissions() runtimecontrol.PermissionState
	NewFullAccessConfirmation(context.Context, runtimecontrol.PermissionUpdate) (*runtimecontrol.FullAccessConfirmation, error)
	SetPermissions(context.Context, runtimecontrol.PermissionUpdate, ...*runtimecontrol.FullAccessConfirmation) error
	WorkspaceStatus(context.Context) (changes.WorktreeStatus, error)
	Models() []modelcatalog.Entry
	Config() config.Config
	Detached() bool
	ListSessions(context.Context) ([]session.Metadata, error)
	ListAllSessions(context.Context) (session.MetadataListing, error)
	ListSessionSummaries(context.Context) ([]runtimecontrol.SessionSummary, error)
	ListSubagents(context.Context) ([]subagent.Summary, error)
	InspectSubagent(context.Context, string) (subagent.Detail, error)
	InspectSubagentState(context.Context, string) (coding.State, error)
	GenerateTeamProposal(context.Context, coding.TeamProposalPrompt) (coding.TeamProposal, error)
	ReviseTeamProposal(context.Context, string, string) (coding.TeamProposal, error)
	DeclineTeam(context.Context, string) error
	ConfirmTeam(context.Context, coding.TeamConfirmation) (coding.TeamReference, error)
	ReadTeam(context.Context, coding.TeamReadRequest) (coding.TeamView, error)
	SubmitTeamControl(context.Context, coding.TeamControlRequest) (coding.TeamControlReference, error)
	ResolveTeamWorkerApproval(
		context.Context,
		coding.TeamWorkerTarget,
		approval.Resolution,
	) (coding.TeamControlReference, error)
	ResolveTeamWorkerQuestion(
		context.Context,
		coding.TeamWorkerTarget,
		question.Resolution,
	) (coding.TeamControlReference, error)
	RejectTeamWorkerQuestion(
		context.Context,
		coding.TeamWorkerTarget,
		string,
		string,
	) (coding.TeamControlReference, error)
	ObserveTeamWorker(context.Context, coding.TeamWorkerTarget) (coding.EventObservation, error)
	InspectTeamWorkerState(context.Context, coding.TeamWorkerTarget) (coding.State, error)
	DiscoverTeamRecovery(context.Context) ([]coding.TeamRecoveryCandidate, error)
	ResumeTeam(
		context.Context,
		team.ID,
		coding.TeamResumeDecision,
	) (coding.TeamReference, error)
	PrepareTeamIntegration(
		context.Context,
		coding.TeamIntegrationRequest,
	) (coding.TeamIntegrationPreview, error)
	ApplyTeamIntegration(
		context.Context,
		coding.TeamIntegrationApproval,
	) (coding.TeamIntegrationResult, error)
	RejectTeamIntegration(context.Context, coding.TeamIntegrationApproval) error
	TeamIntegrationRecoveries(context.Context) ([]coding.TeamIntegrationRecovery, error)
	RecoverTeamIntegration(
		context.Context,
		coding.TeamIntegrationRecoveryRequest,
	) (coding.TeamIntegrationResult, error)
	CleanupTeam(context.Context, coding.TeamCleanupRequest) (coding.TeamCleanupResult, error)
	Skills(context.Context) (coding.SkillSnapshot, error)
	MCP(context.Context) (coding.MCPSnapshot, error)
	SetSkillEnabled(context.Context, coding.SkillID, bool) error
	WaitSubagent(context.Context, string) (subagent.Result, error)
	CancelSubagent(context.Context, string) error
	NewSession(context.Context) error
	ResumeSession(context.Context, string) error
	ForkSession(context.Context, string) error
	SwitchModel(context.Context, modelcatalog.Selection) error
	Close(context.Context) error
}

Controller is the application control surface consumed by the TUI.

type ExitHandler

type ExitHandler func(ExitInfo) error

ExitHandler runs after terminal restoration and Controller release.

type ExitInfo

type ExitInfo struct {
	SessionID string
	Resumable bool
}

ExitInfo is the resumable conversation left by one normal TUI exit.

type ImageClipboard

type ImageClipboard interface {
	ReadImage(context.Context) ([]byte, error)
}

ImageClipboard is the one-method clipboard boundary consumed by the TUI.

type ImageIngress

type ImageIngress interface {
	Receive(context.Context) (attachment.Image, error)
}

ImageIngress receives validated immutable images from an application-owned bridge such as one remote SSH session.

type Model

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

Model is the root Bubble Tea state machine.

func (*Model) Init

func (m *Model) Init() tea.Cmd

Init starts bootstrap immediately for an already trusted Workspace.

func (*Model) Update

func (m *Model) Update(message tea.Msg) (tea.Model, tea.Cmd)

Update applies terminal input and asynchronous bootstrap results.

func (*Model) View

func (m *Model) View() tea.View

View composes the frame the renderer paints. The framework calls it after every message, and a deferred delta changes none of its inputs, so the composition of those updates is reused instead of repeated. A delivery the subscription already owns is reused the same way.

type Options

type Options struct {
	Input       io.Reader
	Output      io.Writer
	Environment []string
	Workspace   string
	// SessionsDirectory is the store root the Usage page's projection sidecar
	// lives under. An empty value keeps the projection unavailable.
	SessionsDirectory string
	ThemeDirectory    string
	Trusted           bool
	NoColor           bool
	// Screen selects the interactive render layout.
	Screen ScreenMode
	// AltScreen selects the terminal buffer independently of the layout, so a
	// fullscreen layout can still be drawn inline in the main buffer.
	AltScreen AltScreenPolicy
	// MouseReporting enables mouse capture. Cell-motion reporting is used under a
	// multiplexer and all-motion elsewhere.
	MouseReporting bool
	// ExitOutput selects what a normal exit leaves on the main screen:
	// config.ExitOutputTranscript writes the conversation, ExitOutputResumeHint
	// leaves only the resume hint. It is authoritative only with
	// PinPresentation; otherwise the persisted [tui] exit_output decides.
	ExitOutput string
	// PinPresentation makes Screen, AltScreen and MouseReporting authoritative
	// instead of deriving them from the persisted [tui] configuration. The CLI
	// leaves this false so configuration decides; tests and embedded callers set
	// it so a specific presentation can be asserted.
	PinPresentation bool
	Bootstrap       Bootstrap
	Clipboard       ImageClipboard
	ImageIngress    ImageIngress
	OnExit          ExitHandler
	Build           BuildStamp
	StatusLine      []statusline.Item
	SaveStatusLine  StatusLineSaver
	SaveTheme       ThemeSaver
	// SaveText persists Ctrl+X, /copy and /export output. A nil saver keeps the
	// clipboard path and reports that no file fallback is available.
	SaveText TextSaver
	// ClipboardWriter overrides the OSC 52 write a copy performs. A nil writer
	// keeps the terminal path.
	ClipboardWriter TextClipboard
}

type ScreenMode added in v0.1.6

type ScreenMode uint8

ScreenMode selects the interactive render layout.

The render layout (transcript viewport vs. native-history tail) and the terminal buffer (alternate screen vs. main screen) are independent decisions: a full layout drawn inline in the main buffer is a supported combination, not a fallback.

const (
	// ScreenInline keeps the terminal's own scrollback and the mutable tail.
	ScreenInline ScreenMode = iota
	// ScreenFullscreen owns a fixed-height layout and its own scrolling.
	ScreenFullscreen
)

type StatusLineSaver

type StatusLineSaver func(context.Context, []statusline.Item) error

StatusLineSaver atomically persists one complete ordered field selection.

type TextClipboard added in v0.1.8

type TextClipboard func(content string) error

TextClipboard writes copied text to the terminal's clipboard and reports whether the write reached it.

The default is nil, which sends an OSC 52 request through the Program — the only writer allowed to touch the terminal. A caller that owns another route to the clipboard, such as a remote session bridge, supplies its own; it replaces the request for every copy the TUI makes (the drag gesture, Ctrl+X, /copy), and its error is reported instead of being assumed away. An explicit /copy or /export with a path keeps its saver, which is the durable half of that result.

type TextKind added in v0.1.6

type TextKind string

TextKind names the destination policy for operator-requested text, so one saver can serve both the copy fallback and an export.

const (
	// TextKindCopy is the durable fallback for a clipboard copy, which OSC 52
	// cannot confirm.
	TextKindCopy TextKind = "copy"
	// TextKindExport is a requested conversation document.
	TextKindExport TextKind = "export"
)

type TextSaveRequest added in v0.1.6

type TextSaveRequest struct {
	Kind    TextKind
	Path    string
	Content string
}

TextSaveRequest is one operator-requested text write. An empty Path asks the saver for its default destination for Kind.

type TextSaver added in v0.1.6

type TextSaver func(context.Context, TextSaveRequest) (string, error)

TextSaver persists operator-requested text and returns the path it wrote. The TUI never owns destination policy: it hands over the requested path and reports back whatever the saver resolved.

type ThemeSaver

type ThemeSaver func(context.Context, string) error

ThemeSaver persists only the requested theme ID in the active config file.

type TrustError

type TrustError struct {
	Err error
}

TrustError means persisting an explicit Workspace trust decision failed and the Trust Overlay should remain available for retry.

func (*TrustError) Error

func (e *TrustError) Error() string

func (*TrustError) Unwrap

func (e *TrustError) Unwrap() error

Unwrap returns the persistence failure.

Jump to

Keyboard shortcuts

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