Documentation
¶
Index ¶
- Variables
- func AvailableThemes() []string
- func ExtractCodeBlocks(text string) string
- func ResetTerminalBackground()
- func SetTerminalBackground(hexColor string)
- func ThemeHex(c color.Color) string
- type App
- func (a *App) AddChangedFile(file string)
- func (a *App) AddMessage(msg Message)
- func (a *App) Ask(ctx context.Context, q Question) (string, error)
- func (a *App) ClearMessages()
- func (a *App) CopyToClipboard(text string) bool
- func (a *App) EmitToolEnd(id, output string, success bool)
- func (a *App) EmitToolStart(id, name, args string)
- func (a *App) ExportSession(outDir, baseName string) (mdPath, htmlPath string, err error)
- func (a *App) Form(ctx context.Context, f Form) ([]string, error)
- func (a *App) GetModelName() string
- func (a *App) GetTheme() Theme
- func (a *App) GetWorkDir() string
- func (a *App) Init() tea.Cmd
- func (a *App) IsSidebarHidden() bool
- func (a *App) LastTPS() float64
- func (a *App) LastTokens() int
- func (a *App) Mode() string
- func (a *App) QueuedMessages() []string
- func (a *App) RegisterCommand(cmd SlashCommand)
- func (a *App) ResetSession()
- func (a *App) RewindLastTurn() (string, bool)
- func (a *App) Run(ctx context.Context) error
- func (a *App) ScanRepoFiles(root string)
- func (a *App) SetChangedFiles(files []string)
- func (a *App) SetContextTokens(used, max int)
- func (a *App) SetMode(mode string)
- func (a *App) SetModelName(name string)
- func (a *App) SetNotification(msg string, ntype NotificationType) tea.Cmd
- func (a *App) SetRepoFiles(files []string)
- func (a *App) SetSidebar(w Widget)
- func (a *App) SetTheme(t Theme)
- func (a *App) SetWorkDir(dir string)
- func (a *App) Submit(input string)
- func (a *App) ToggleSidebar() (*App, tea.Cmd)
- func (a *App) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (a *App) View() tea.View
- type Config
- type Event
- type EventKind
- type EventStreamHandler
- type Field
- type FieldKind
- type Form
- type Item
- type KeyValWidget
- type Message
- type Notification
- type NotificationType
- type Question
- type QuickAction
- type Role
- type SlashCommand
- type Source
- type StatusListWidget
- func (w *StatusListWidget) Render(width, height int) string
- func (w *StatusListWidget) SetItems(items []Item)
- func (w *StatusListWidget) SetVisible(v bool)
- func (w *StatusListWidget) Title() string
- func (w *StatusListWidget) Update(msg tea.Msg) (Widget, tea.Cmd)
- func (w *StatusListWidget) Visible() bool
- type Store
- type StreamHandler
- type Theme
- type ToolCall
- type ToolStatus
- type Widget
Constants ¶
This section is empty.
Variables ¶
var ErrAskCancelled = errors.New("agenttui: question cancelled")
ErrAskCancelled is returned by App.Ask when the user dismisses the prompt.
var ErrNotRunning = errors.New("agenttui: app is not running")
ErrNotRunning is returned by App.Ask when the TUI is not running.
Functions ¶
func AvailableThemes ¶
func AvailableThemes() []string
AvailableThemes returns the identifiers of all built-in themes.
func ExtractCodeBlocks ¶
ExtractCodeBlocks extracts the raw code within markdown fenced code blocks (```...```). If no code fences are found, the original text is returned.
func ResetTerminalBackground ¶
func ResetTerminalBackground()
ResetTerminalBackground restores the terminal emulator window's default background color via OSC 111.
func SetTerminalBackground ¶
func SetTerminalBackground(hexColor string)
SetTerminalBackground updates the terminal emulator window's background color via OSC 11. Most modern terminals (GNOME Terminal, Windows Terminal, Kitty, Alacritty, WezTerm, macOS Terminal, Foot, Ghostty) support this sequence to dynamically adapt their background to the active theme.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App manages the chat application lifecycle and Bubble Tea program.
func (*App) AddChangedFile ¶
AddChangedFile appends a file to the changed files list.
func (*App) AddMessage ¶
AddMessage appends a message to the conversation.
func (*App) Ask ¶
Ask shows q and blocks until the user answers, dismisses it (ErrAskCancelled) or ctx is done. It is safe to call from stream and slash-command handlers, i.e. from any goroutine except the UI loop itself.
func (*App) ClearMessages ¶
func (a *App) ClearMessages()
ClearMessages removes all messages from the conversation transcript.
func (*App) CopyToClipboard ¶
CopyToClipboard copies arbitrary text to the system clipboard.
func (*App) EmitToolEnd ¶
EmitToolEnd updates a tool execution with result.
func (*App) EmitToolStart ¶
EmitToolStart logs a tool beginning execution in the stream.
func (*App) ExportSession ¶
ExportSession writes the conversation history to both Markdown (.md) and standalone HTML (.html). Returns the absolute or relative paths to both generated files.
func (*App) Form ¶
Form shows f and blocks until the user saves it (Enter), dismisses it (ErrAskCancelled) or ctx is done. It returns the field values in order. Same calling rules as Ask: not from the UI goroutine.
func (*App) GetModelName ¶
GetModelName returns the current active model identifier.
func (*App) GetWorkDir ¶
GetWorkDir returns the active workspace path.
func (*App) IsSidebarHidden ¶
IsSidebarHidden reports whether the sidebar is currently hidden.
func (*App) LastTPS ¶ added in v0.3.3
LastTPS returns the tokens per second achieved on the last assistant turn.
func (*App) LastTokens ¶ added in v0.3.3
LastTokens returns the token count of the last assistant turn.
func (*App) QueuedMessages ¶ added in v0.3.3
QueuedMessages returns the messages waiting to be sent, oldest first.
func (*App) RegisterCommand ¶
func (a *App) RegisterCommand(cmd SlashCommand)
RegisterCommand adds or updates a slash command in the registry without duplicates.
func (*App) ResetSession ¶
func (a *App) ResetSession()
ResetSession clears all conversation messages, history, sidebar widgets, changed files, and resets session timer and context counters.
func (*App) RewindLastTurn ¶
RewindLastTurn pops the last assistant response (and any associated tool calls) and the last user prompt from the conversation history, and restores that user prompt back into the input textarea so the user can easily revise and resubmit it.
func (*App) ScanRepoFiles ¶
ScanRepoFiles walks the workspace root and collects files for @file completion.
func (*App) SetChangedFiles ¶
SetChangedFiles updates the list of changed files shown in the sidebar.
func (*App) SetContextTokens ¶
SetContextTokens updates the context window usage indicator. max 0 means the window is unknown: only the used count is shown.
func (*App) SetModelName ¶
SetModelName updates the active model label in the status bar.
func (*App) SetNotification ¶
func (a *App) SetNotification(msg string, ntype NotificationType) tea.Cmd
SetNotification sets a toast notification.
func (*App) SetRepoFiles ¶
SetRepoFiles sets the cached list of workspace files for @file completion.
func (*App) SetSidebar ¶
SetSidebar attaches or replaces a sidecar widget.
func (*App) SetWorkDir ¶
SetWorkDir updates the active workspace path.
func (*App) Submit ¶
Submit feeds input to the app as if the user had typed it and pressed Enter (slash commands included). Safe to call from any goroutine; a no-op before Run.
func (*App) ToggleSidebar ¶
ToggleSidebar switches sidebar visibility on and off. When hidden, chat text expands across full width, allowing clean terminal copy/selection without sidebars.
type Config ¶
type Config struct {
Title string
Subtitle string
ModelName string
WorkDir string
Mode string // e.g. "build" or "plan"
Placeholder string
Theme Theme
Stream StreamHandler
// StreamEvents, when set, takes precedence over Stream.
StreamEvents EventStreamHandler
Store Store // optional session persistence
IgnoreDirs []string // extra directory names skipped by @file completion
Commands []SlashCommand
Sidebar Widget
// SidebarFirst draws the Sidebar widget right under the info rows instead of
// below the context/turns/status block, so it stays visible on short terminals;
// info rows are then drawn compactly, one line each.
SidebarFirst bool
EnableMouse bool
ShowHeader bool
// Presentation hooks, all optional.
Banner []string // ASCII art shown on the empty-transcript welcome screen
QuickActions []QuickAction // command list shown under the banner
// MentionComplete adds candidates (e.g. code symbols) to the @-completion
// popup after the file matches. MentionResolve turns an @name that is not
// a workspace file into text attached to the prompt. Both run on the UI
// goroutine: keep them fast (cache, short timeouts).
MentionComplete func(query string) []string
MentionResolve func(name string) (text string, ok bool)
DisableShell bool // turn off the '!cmd' shell escape (input starting with '!' is sent as a normal prompt)
HideMode bool // hide the build/plan mode badge and info row
HeaderInfo func() string // extra text shown before the model name in the header
HeaderInfoWide func() string // used instead of HeaderInfo while the sidebar is hidden (Ctrl+B) or the terminal is too narrow for it
InfoRows func() [][2]string // replaces the sidebar's built-in mode/model rows
// OnKey sees every key press before the built-in handling (but not while a
// question or form is open). Return true to consume it. It runs on the UI
// goroutine: start a goroutine for anything that blocks, e.g. App.Form.
OnKey func(key string, app *App) bool
}
Config holds initialization parameters for the Agent TUI.
type Event ¶
type Event struct {
Kind EventKind
Text string
ToolID string
ToolName string
ToolArgs string
ToolOutput string
ToolOK bool
Sources []Source
}
Event is one typed item of an agent response stream.
type EventKind ¶
type EventKind int
EventKind identifies the type of a streaming Event.
const ( EventText EventKind = iota // Text: a chunk of answer content EventThinking // Text: a chunk of reasoning EventToolStart // ToolID, ToolName, ToolArgs EventToolEnd // ToolID, ToolOutput, ToolOK EventSources // Sources: passages the answer is grounded in; attached to the assistant message of this turn )
type EventStreamHandler ¶
type EventStreamHandler func(ctx context.Context, prompt string, emit func(Event)) (tokens int, err error)
EventStreamHandler is the typed alternative to StreamHandler. Reasoning and tool calls are reported as separate events instead of being inferred from <think> tags in the text.
type Field ¶
type Field struct {
Label string
Kind FieldKind
Value string
Options []string // FieldChoice; for FieldSlider the ordered preset values (first = min, last = max)
Min, Max float64 // FieldNumber / numeric FieldSlider (ignored when Max <= Min for Number)
Step float64 // FieldNumber / numeric FieldSlider (default 1)
Format string // numeric FieldSlider: printf format for the limits, default "%g"
Hint string // one-line help shown while the field is focused
}
Field is one editable setting of a Form. Values are exchanged as strings: Bool uses "on"/"off", Number uses plain decimal notation.
type FieldKind ¶
type FieldKind int
FieldKind selects how a Form field is edited.
const ( FieldChoice FieldKind = iota // ←/→ cycles through Options FieldNumber // ←/→ changes the value by Step within [Min, Max] FieldBool // ←/→ or Space toggles "on"/"off" FieldText // Enter edits the value in the input box FieldSlider // like Choice/Number but drawn as a bar with its limits; ←/→ clamp at the ends )
type Form ¶
type Form struct {
Title string
Fields []Field
Note string // optional read-only line shown under the fields
}
Form is a settings panel: a list of fields edited in place.
type KeyValWidget ¶
type KeyValWidget struct {
// contains filtered or unexported fields
}
KeyValWidget displays key-value pairs (e.g. system info, index stats).
func NewKeyValWidget ¶
func NewKeyValWidget(title string, theme Theme) *KeyValWidget
NewKeyValWidget creates a key-value widget.
func (*KeyValWidget) Render ¶
func (w *KeyValWidget) Render(width, height int) string
Render renders the key-value widget.
func (*KeyValWidget) SetPairs ¶
func (w *KeyValWidget) SetPairs(pairs [][2]string)
SetPairs updates the key-value pairs.
func (*KeyValWidget) Visible ¶
func (w *KeyValWidget) Visible() bool
Visible returns visibility status.
type Message ¶
type Message struct {
Role Role `json:"role"`
Content string `json:"content"`
Thinking string `json:"thinking,omitempty"`
ThinkingOpen bool `json:"thinking_open,omitempty"`
ThinkingTime time.Duration `json:"thinking_time,omitempty"`
Timestamp time.Time `json:"timestamp"`
Tokens int `json:"tokens,omitempty"`
Duration time.Duration `json:"duration,omitempty"`
TPS float64 `json:"tps,omitempty"`
Sources []Source `json:"sources,omitempty"`
Tool *ToolCall `json:"tool,omitempty"`
}
Message represents a message in the conversation.
type Notification ¶
type Notification struct {
Message string
Type NotificationType
Expires time.Time
}
Notification represents a toast notification in the status bar.
type NotificationType ¶
type NotificationType int
NotificationType defines the severity of a notification.
const ( NotifyInfo NotificationType = iota NotifySuccess NotifyWarning NotifyError )
type Question ¶
type Question struct {
Text string
Detail string // optional background shown under the question
Options []string // empty means free-text answer
Default string // pre-selected option, or the text used on an empty free-text answer
}
Question is a prompt the agent puts to the user. With Options the user picks one (arrows, Enter, or the option number); without them the user types free text into the input box.
type QuickAction ¶
QuickAction is one line of the welcome screen's command list.
type SlashCommand ¶
type SlashCommand struct {
Name string // e.g. "help", "model", "clear"
Description string // Short description shown in autocomplete popup
Usage string // Parameter usage info, e.g. "<model-name>"
Handler func(ctx context.Context, args []string, app *App) (result string, isLocal bool, err error)
}
SlashCommand defines an interactive command starting with '/'.
type Source ¶ added in v0.2.0
type Source struct {
Title string `json:"title"`
Location string `json:"location,omitempty"` // path, URL or line range
Score float64 `json:"score,omitempty"` // 0 hides the score
}
Source is one passage or document an answer is grounded in (RAG citation).
type StatusListWidget ¶
type StatusListWidget struct {
// contains filtered or unexported fields
}
StatusListWidget displays a vertical list of tasks/steps with status icons.
func NewStatusListWidget ¶
func NewStatusListWidget(title string, theme Theme) *StatusListWidget
NewStatusListWidget creates a status list widget.
func (*StatusListWidget) Render ¶
func (w *StatusListWidget) Render(width, height int) string
Render renders the widget into the given dimensions.
func (*StatusListWidget) SetItems ¶
func (w *StatusListWidget) SetItems(items []Item)
SetItems updates the list items.
func (*StatusListWidget) SetVisible ¶
func (w *StatusListWidget) SetVisible(v bool)
SetVisible controls widget visibility.
func (*StatusListWidget) Title ¶
func (w *StatusListWidget) Title() string
Title returns the widget title.
func (*StatusListWidget) Visible ¶
func (w *StatusListWidget) Visible() bool
Visible returns whether the widget is visible.
type Store ¶
Store persists the conversation so a session can be resumed. Load is called once by New; Save after every completed turn.
type StreamHandler ¶
type StreamHandler func(ctx context.Context, prompt string, emit func(chunk string)) (tokens int, err error)
StreamHandler is a streaming function called when the user sends a prompt. It yields chunks via emit() and returns the total tokens or an error when done.
type Theme ¶
type Theme struct {
Name string
Primary color.Color
Secondary color.Color
Accent color.Color
Success color.Color
Warning color.Color
Error color.Color
Info color.Color
Text color.Color
SubText color.Color
Muted color.Color
Border color.Color
BgDark color.Color
// Styles
HeaderTitle lipgloss.Style
HeaderSub lipgloss.Style
UserBubble lipgloss.Style
SystemText lipgloss.Style
ErrorText lipgloss.Style
ToolCard lipgloss.Style
StatusBar lipgloss.Style
Badge lipgloss.Style
PopupBox lipgloss.Style
PopupItem lipgloss.Style
PopupSel lipgloss.Style
}
Theme defines the visual styling tokens for the TUI. Theme defines the visual styling tokens for the TUI.
func CatppuccinTheme ¶
func CatppuccinTheme() Theme
CatppuccinTheme returns the soothing Catppuccin Mocha pastel aesthetic.
func ClaudeTheme ¶
func ClaudeTheme() Theme
ClaudeTheme returns Anthropic Claude Code's signature warm aesthetic.
func DevranTheme ¶
func DevranTheme() Theme
DevranTheme returns the modern deep violet & cyan theme.
func DraculaTheme ¶
func DraculaTheme() Theme
DraculaTheme returns the classic gothic Dracula aesthetic.
func GruvboxTheme ¶
func GruvboxTheme() Theme
GruvboxTheme returns the warm retro aesthetic of Gruvbox Dark.
func OpenCodeTheme ¶
func OpenCodeTheme() Theme
OpenCodeTheme returns the signature OpenCode minimalist pitch black, crisp white, vibrant orange, and zinc gray aesthetic.
func ThemeByName ¶
ThemeByName returns the matching theme by name, defaulting to Claude.
func TokyoNightTheme ¶
func TokyoNightTheme() Theme
TokyoNightTheme returns the neon cyber aesthetic of Tokyo Night.
type ToolCall ¶
type ToolCall struct {
ID string `json:"id"`
Name string `json:"name"`
Args string `json:"args"`
Output string `json:"output,omitempty"`
Status ToolStatus `json:"status"`
Duration time.Duration
Timestamp time.Time
}
ToolCall represents an invoked tool within the chat stream.
type ToolStatus ¶
type ToolStatus int
ToolStatus represents the lifecycle of a tool invocation.
const ( ToolStatusRunning ToolStatus = iota ToolStatusSuccess ToolStatusFailed )