tui

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 73 Imported by: 0

Documentation

Index

Constants

View Source
const AutoModeIcon = "▸"

AutoModeIcon marks auto mode across all surfaces (banner, entry log, exit log). Small right-triangle — reads as "play / run" without the visual weight of the full ▶. Visually distinct from PlanModeIcon (◈) so users glance and know which mode is on.

View Source
const PlanModeIcon = "▸"

PlanModeIcon is the glyph that marks plan mode across all surfaces (banner, entry log, resume log, exit log, plan-file lines, approval card title). Single source of truth so changing the icon is one edit. Triangle (matching AutoModeIcon) so the two modes share a shape — the color is what distinguishes them: auto is accent, plan is warning (orange). Saves the user from learning two glyphs.

View Source
const YoloModeIcon = "⚠"

YoloModeIcon marks the yolo mode overlay across all surfaces. Warning sign — signals "this is the danger setting" visually before any text is read. Red color reinforces the meaning.

Variables

This section is empty.

Functions

func ActiveTheme added in v0.3.0

func ActiveTheme() string

ActiveTheme returns the currently applied theme name. Used by /themes show and the preview header so the user can confirm what they're looking at without re-parsing config.toml.

func ApplyTheme added in v0.3.0

func ApplyTheme(name string) bool

ApplyTheme swaps the active palette and rebuilds every style. An unknown name falls back to the default and returns false so the caller (/themes set, startup loader) can decide whether to log a warning. The TUI's render loop is "everything looks up globals at render time" — the next View() call picks up the new palette automatically. Components that captured a style by value at construction time (textarea prompt, spinner, markdown renderer) need a separate refresh hook; refreshComponentStyles (cmd_themes.go) does that work.

func HighlightCode

func HighlightCode(source, languageHint string) string

HighlightCode runs source through chroma and returns ANSI-colored text. languageHint can be a chroma lexer name ("go", "python") or empty; in either case the helper does its best to detect from content if the hint doesn't match a known lexer. Falls back to plain text when chroma can't tokenize.

Used by the approval modal renderers to make code review easier: the user sees keywords / strings / comments in distinct colors rather than a wall of monochrome text.

func HighlightFromPath

func HighlightFromPath(source, path string) string

HighlightFromPath is the convenience form: derive the language hint from the file extension, then highlight. Used by approval renderers that have a path on hand (edit_file, write_file).

func Run

func Run(ctx context.Context, opts cli.ChatOptions) error

Run wires up session, permissions, adapter, and tools, then drives the Bubbletea program. The non-interactive sibling is oneshot.Run, which shares the same ChatOptions but emits one turn to stdout and exits.

func SysMsg added in v0.4.0

func SysMsg(icon SysIcon, source, event string, detail ...string) string

SysMsg renders the only approved grammar for lightweight system messages:

<icon> <source> · <event> · <detail>

Empty detail parts are skipped so callers can pass optional context without producing doubled separators. The returned string is plain; callers choose styleAuto/styleError/etc. based on severity.

func SysMsgAligned added in v0.4.0

func SysMsgAligned(icon SysIcon, source, event string, detail ...string) string

SysMsgAligned renders the same grammar as SysMsg, but right-pads the source label so adjacent lifecycle rows line up as a small status cluster.

Types

type Config

type Config struct {
	Cfg         agent.LoopConfig
	Session     *session.Session
	Permissions *permissions.Permissions
	Recall      *recall.Index // optional; nil disables /recall
	ModelName   string
	BaseURL     string
	APIKey      string
	Provider    string
	// ProviderLabel is the catalog identity ("nvidia-nim", "xai") of
	// the active profile, surfaced in the status bar instead of the
	// generic dispatch tag (Provider). Populated by Run() from the
	// loaded config; leave empty when no profile is matched and the
	// renderer falls back to Provider.
	ProviderLabel          string
	ReasoningEffort        string
	EnableWebSearch        bool
	DisableWebSearch       bool
	EnableXSearch          bool
	EnableCodeInterpreter  bool
	SearchAllowedDomains   string
	SearchExcludedDomains  string
	XSearchAllowedHandles  string
	XSearchExcludedHandles string
	XSearchFromDate        string
	XSearchToDate          string
	ProviderProfile        adapter.ProviderProfile
	Cwd                    string
	// BypassPermissions auto-approves every tool call. DANGEROUS — see
	// the flag help on --yolo. Explicit `deny`
	// rules in .yottacode/permissions.json still apply.
	BypassPermissions bool
	Version           string   // e.g. "0.3.0" — shown in the header
	Commit            string   // short SHA the binary was built from; "" when unknown (go run, tarball)
	Dirty             bool     // true when the build had uncommitted changes; renders a "*" beside the commit
	Branch            string   // current git branch (empty if not in a repo)
	GitAhead          int      // commits ahead of upstream/default branch; zero hides the arrow
	GitBehind         int      // commits behind upstream/default branch; zero hides the arrow
	ProjectRoots      []string // roots counting as this project (repo root + its worktree container); auto-recall's project scope matches them and everything below
	SensitiveProject  bool     // this project is marked sensitive: no automatic recall injection at all
	SensitiveRoots    []string // every sensitive root; their sessions never surface in any project's recall
	Worktree          string   // yottacode worktree name when running inside one (empty for main checkout); rendered as a status-line chip
	MemorySummary     string   // "USER", "YOTTA", "USER+YOTTA", "UMEM", "USER+UMEM", or "" if none
	BaseSystemPrompt  string   // pre-memory prompt — needed by /memory reload to recompose
	EmbedClient       *memory.EmbedClient
	LSPManager        *lsp.Manager
	CodeMapProvider   codemap.Provider

	// FileCfg holds tunables loaded from ~/.yottacode/config.toml
	// (context watermarks, retrieval). The TUI reads these at session
	// start and re-reads them on /memory reload.
	FileCfg config.Config

	// Subagents is the session task registry the /subagents slash
	// command inspects. Populated by run.go alongside Agent tool
	// registration; nil disables /subagents (tests that don't wire
	// subagents in are still valid).
	Subagents *subagents.Registry

	// ExperimentalEnabled is the sorted list of experimental feature
	// names switched on this session (experimental.Set.EnabledNames).
	// The /experimental overlay renders the full catalog and marks these
	// on; empty means none are enabled.
	ExperimentalEnabled []string

	// SandboxActive reports whether this session actually constructed a
	// command sandbox at startup. Later config writes do not hot-swap run_bash.
	SandboxActive bool

	// AgentTool is the dispatch tool registered on Cfg.Registry. The
	// TUI keeps a typed reference so the slash command can introspect
	// the resolved agent list, and so the background-done callback
	// can be wired to push events onto the model's session inbox.
	AgentTool *agent.AgentTool

	// CustomCommands is the set of user-authored slash commands
	// loaded from ~/.yottacode/commands/ and <cwd>/.yottacode/commands/
	// at startup. New() builds slashCommand entries from these and
	// stores them on the Model so the dispatcher and /help can see
	// them alongside built-ins.
	CustomCommands []usercmd.Command

	// MCPManager is the live MCP client lifecycle manager, built from
	// config.MCPServers at session start. The /mcp slash command
	// inspects + restarts servers through it. Nil when no servers are
	// configured (the slash command renders "no servers configured").
	MCPManager *mcppkg.Manager

	// Skills is the resolved set of Agent Skills (built-in + user +
	// project) loaded at startup. New() builds slashCommand entries
	// from skills with metadata.slash != "false" so `/<skill-name>`
	// works alongside model-side invocation via the Skill tool.
	Skills []skills.Skill

	// SkillTool is the live Skill dispatch tool registered on
	// Cfg.Registry. The TUI keeps a typed reference so the /skills
	// picker can read SkillTool.All (the universe) and call
	// SkillTool.SetEnabled (the per-session filter). nil disables the
	// /skills picker; the slash command still falls through to the
	// "unknown command" error in that case.
	SkillTool *agent.SkillTool

	// RouterAdapters holds the resolved fast/smart task-routing adapters.
	// RouterMode is the live routing mode. They drive the /router picker and
	// live rewiring without switching the main-thread adapter mid-turn.
	RouterAdapters *cli.RouterAdapters
	RouterMode     string
	Options        cli.ChatOptions

	// SummarizerAdapter routes the /summarize + auto-compaction call to
	// the fast model under cache-safe routing. nil → New() falls back to
	// Cfg.Adapter (the legacy single-adapter behavior).
	SummarizerAdapter agentStreamer
	// SummarizerModel is the fast model's name for routing telemetry;
	// empty when summarization isn't routed.
	SummarizerModel string
}

Config carries everything Run needs to build a Model. Bundling these into a struct is just ergonomics — there are too many fields for a positional argument list to stay readable.

type Model

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

Model is the Bubbletea state for the chat TUI. The TUI runs full-screen (alt-screen): the app owns the whole frame, including a scrollable conversation transcript viewport above the live footer. Native terminal scrollback is unavailable inside alt-screen, so transcript history is kept in transcriptRows and scrolled with PgUp/PgDn/Ctrl+Home/Ctrl+End while mouse capture is enabled only after the conversation starts so wheel scrolling works.

func New

func New(parent context.Context, c Config) Model

New builds a Model wired with the given config.

func (Model) Init

func (m Model) Init() tea.Cmd

func (Model) Update

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

Update is the public Bubbletea entry point. It delegates to update() then resyncs the owned transcript viewport. Single chokepoint keeps the rest of the model from threading viewport size/content bookkeeping by hand.

func (Model) View

func (m Model) View() tea.View

View renders the full-screen frame: the owned, scrollable transcript viewport on top and the live footer (input box + status bar + transient overlays) pinned to the bottom. Alt-screen (like internal/wizard's steps.go) is set declaratively here per Bubbletea v2's per-View pattern, not as a tea.NewProgram option.

Real terminal-background repaint (tea.View.BackgroundColor) rides the same declarative pattern: hasThemeBackground/themeBackground (styles.go) are set by buildStyles, the single chokepoint every theme change already funnels through — startup load, /theme set, and every cursor move in the live-preview theme picker alike — so a theme's real background applies and (via Esc reverting to the prior theme, which re-triggers buildStyles) un-applies with no picker-specific code here. Only set when originalTerminalBackground was actually captured (Init/update's tea.BackgroundColorMsg case) — a terminal that never answered the startup query never gets a blind write attempt, and a non-backgrounded theme falls back to that captured original rather than leaving whatever the last themed pick set.

type SysIcon added in v0.4.0

type SysIcon string

SysIcon is the closed icon set for one-line TUI system lifecycle rows. Keeping the icon choices centralized prevents ad-hoc bracket prefixes such as "mcp" or "lsp:" from drifting back into the transcript.

const (
	SysState    SysIcon = "○"
	SysSuccess  SysIcon = "✓"
	SysProgress SysIcon = "…"
	SysWarning  SysIcon = "⚠"
	SysFailure  SysIcon = "✕"
	SysQueue    SysIcon = "→"
	SysThought  SysIcon = "◦"
	SysReturn   SysIcon = "↩"
	SysContext  SysIcon = "◇"
)

Directories

Path Synopsis
Package themes is the palette registry the TUI's styles.go reads from when (re)building style vars.
Package themes is the palette registry the TUI's styles.go reads from when (re)building style vars.

Jump to

Keyboard shortcuts

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