tui

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: MIT Imports: 49 Imported by: 0

Documentation

Overview

Package tui implements the Bubble Tea TUI for conduit.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RebuildStyles

func RebuildStyles()

RebuildStyles regenerates every package-level style from theme.Active(). Called at init() and after every theme switch via theme.OnChange.

func Run

func Run(version, modelName string, loop *agent.Loop, extras ...any) error

Run starts the full-screen TUI and blocks until the user exits. Variadic tail accepts: *api.Client, *permissions.Gate, *settings.HooksSettings, RunOptions (in any order).

func SummarizeMessages

func SummarizeMessages(history []api.Message, n int) string

SummarizeMessages renders the last n model-visible messages as a plain-text transcript for /memory extract. Tool blocks are flattened so the sub-agent sees a readable conversation, not raw JSON. Exported because cmd/conduit/main.go's auto-extract path also needs it.

Types

type Config

type Config struct {
	Version    string
	ModelName  string
	Loop       *agent.Loop
	Program    **tea.Program
	Commands   *commands.Registry
	APIClient  *api.Client
	MCPManager *mcp.Manager
	Gate       *permissions.Gate

	// AuthErr is non-nil when the TUI started without valid credentials.
	AuthErr error
	// Profile is the user's subscription/account info fetched at startup.
	Profile profile.Info
	// Session is the active transcript session (nil if persistence unavailable).
	Session *session.Session
	// ResumedHistory is pre-loaded history from a --continue session.
	ResumedHistory []api.Message
	// Resumed is true when --continue loaded a prior session.
	Resumed bool
	// LoadAuth reloads credentials + profile after /login.
	LoadAuth func(ctx context.Context) (string, *profile.Info, error)
	// NewAPIClient constructs a fresh client for the given bearer.
	NewAPIClient func(bearer string) *api.Client
	// Live is the shared state bag readable from command callbacks outside
	// the Bubble Tea event loop. Populated by the model on each Update.
	Live *LiveState
}

Config is passed from main to the TUI.

type LiveState

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

LiveState holds a small set of frequently-read Model fields that command callbacks need to access from outside the Bubble Tea event loop. All methods are safe to call from any goroutine.

func (*LiveState) AppendTurnCost

func (s *LiveState) AppendTurnCost(delta float64)

func (*LiveState) EffortLevel

func (s *LiveState) EffortLevel() string

func (*LiveState) FastMode

func (s *LiveState) FastMode() bool

func (*LiveState) ModelName

func (s *LiveState) ModelName() string

func (*LiveState) PermissionMode

func (s *LiveState) PermissionMode() permissions.Mode

func (*LiveState) RateLimitWarning

func (s *LiveState) RateLimitWarning() string

func (*LiveState) SessionFile

func (s *LiveState) SessionFile() string

func (*LiveState) SessionID

func (s *LiveState) SessionID() string

func (*LiveState) SetEffortLevel

func (s *LiveState) SetEffortLevel(level string)

func (*LiveState) SetFastMode

func (s *LiveState) SetFastMode(on bool)

func (*LiveState) SetModelName

func (s *LiveState) SetModelName(name string)

func (*LiveState) SetPermissionMode

func (s *LiveState) SetPermissionMode(m permissions.Mode)

func (*LiveState) SetRateLimitWarning

func (s *LiveState) SetRateLimitWarning(w string)

func (*LiveState) SetSessionFile

func (s *LiveState) SetSessionFile(path string)

func (*LiveState) SetSessionID

func (s *LiveState) SetSessionID(id string)

func (*LiveState) SetTokens

func (s *LiveState) SetTokens(input, output int, costUSD float64)

func (*LiveState) Tokens

func (s *LiveState) Tokens() (input, output int, costUSD float64)

func (*LiveState) TurnCosts

func (s *LiveState) TurnCosts() []float64

type Message

type Message struct {
	Role        Role
	Content     string
	ToolName    string
	WelcomeCard bool // render as the two-panel welcome banner
}

Message is one entry in the displayed conversation.

type Model

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

Model is the Bubble Tea model.

func New

func New(cfg Config) Model

New builds the initial Model.

func (Model) AllBindings

func (m Model) AllBindings() []keybindings.Binding

AllBindings returns the flat binding list from the active resolver, suitable for /keybindings display. Falls back to Defaults() when the resolver is nil.

func (*Model) CopyLastResponse

func (m *Model) CopyLastResponse() string

CopyLastResponse copies the last assistant text to clipboard. Returns "" on success, error message otherwise.

func (*Model) CostSummary

func (m *Model) CostSummary() string

CostSummary returns a human-readable cost/token summary for the /cost command.

func (Model) Init

func (m Model) Init() tea.Cmd

Init starts the blink + spinner tick. Also kicks off the MCP approval picker if any project-scope servers are awaiting consent, and the coordinator-panel tick that drives the active-task footer.

func (*Model) LastThinking

func (m *Model) LastThinking() string

func (*Model) TasksSummary

func (m *Model) TasksSummary() string

TasksSummary returns the list of active tasks for /tasks. Tasks are tracked by the TaskTool — for now we surface the tool messages.

func (*Model) TurnCosts

func (m *Model) TurnCosts() []float64

LastThinking returns the last thinking block text from the assistant. TurnCosts returns a copy of the per-turn cost deltas recorded this session.

func (Model) Update

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update is the Elm update function.

func (Model) View

func (m Model) View() tea.View

View renders the full TUI frame. v2 returns tea.View — internally we still build a string and wrap it via mkView so all the existing rendering/paint logic stays unchanged.

Basic keyboard disambiguation (shift+enter, ctrl+i, etc) is enabled by default in bubbletea v2 — no opt-in required for those keys. The KeyboardEnhancements field below opts into more advanced features: ReportAlternateKeys lets terminals report alternate key values (helps international keyboards), and we leave ReportEventTypes off because we don't need key release events.

type Role

type Role int

Role identifies who sent a message.

const (
	RoleUser Role = iota
	RoleAssistant
	RoleTool
	RoleError
	RoleSystem
)

type RunOptions

type RunOptions struct {
	// AuthErr is non-nil when no credentials were found at startup.
	AuthErr error

	// Profile is the user's account/subscription info fetched at startup.
	Profile profile.Info

	// Session is the active session for transcript persistence.
	Session *session.Session

	// ResumedHistory is the message history loaded from a previous session.
	ResumedHistory []api.Message

	// Resumed is true when --continue loaded a prior session.
	Resumed bool

	// MCPManager is the live MCP connection manager (may be nil).
	MCPManager *mcp.Manager

	// LoadAuth reloads credentials + profile after a successful /login.
	LoadAuth func(ctx context.Context) (string, *profile.Info, error)

	// NewAPIClient constructs a fresh API client for the given bearer token.
	NewAPIClient func(bearer string) *api.Client

	// Interactive tool stubs — the TUI wires their callbacks after startup.
	EnterPlan *planmodetool.EnterPlanMode
	ExitPlan  *planmodetool.ExitPlanMode
	AskUser   *askusertool.AskUserQuestion

	// InitialOutputStyle is the style name to activate at startup (from settings).
	InitialOutputStyle string

	// PluginDirs is the list of installed plugin root directories, used to
	// load plugin-provided output styles (lowest priority — overridden by user/project).
	PluginDirs []string
}

RunOptions carries optional TUI startup parameters passed from main.

Jump to

Keyboard shortcuts

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