tui

package
v1.2.14 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 79 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SlashCommandDescriptions = map[string]string{
	"/help":        "Show help message",
	"/?":           "Show help message",
	"/sessions":    "List saved sessions",
	"/resume":      "Resume a previous session",
	"/model":       "Open model panel",
	"/impersonate": "Set client identity (impersonate CLI tools)",
	"/provider":    "Open provider manager",
	"/clear":       "Clear conversation",
	"/im":          "Open unified IM channels panel",
	"/qq":          "Manage QQ channel binding",
	"/telegram":    "Manage Telegram channel binding",
	"/tg":          "Manage Telegram channel binding",
	"/pc":          "Manage PC channel binding",
	"/discord":     "Manage Discord channel binding",
	"/feishu":      "Manage Feishu channel binding",
	"/lark":        "Manage Feishu channel binding",
	"/slack":       "Manage Slack channel binding",
	"/dingtalk":    "Manage DingTalk channel binding",
	"/wechat":      "Manage WeChat (iLink) channel binding",
	"/ding":        "Manage DingTalk channel binding",
	"/wecom":       "Manage WeCom (Enterprise WeChat) channel binding",
	"/mattermost":  "Manage Mattermost channel binding",
	"/mm":          "Manage Mattermost channel binding",
	"/matrix":      "Manage Matrix channel binding",
	"/signal":      "Manage Signal channel binding",
	"/irc":         "Manage IRC channel binding",
	"/nostr":       "Manage Nostr channel binding",
	"/twitch":      "Manage Twitch channel binding",
	"/whatsapp":    "Manage WhatsApp channel binding",
	"/wa":          "Alias for /whatsapp",
	"/mcp":         "Show MCP servers",
	"/memory":      "Manage memory",
	"/undo":        "Undo last file edit",
	"/checkpoints": "List checkpoints",
	"/plugins":     "List loaded plugins",
	"/image":       "Attach an image",
	"/init":        "Create GGCODE.md",
	"/harness":     "Run harness workflow commands",
	"/exit":        "Exit ggcode",
	"/quit":        "Exit ggcode",
	"/compact":     "Compress conversation history",
	"/todo":        "View/manage todo list",
	"/status":      "Show current status",
	"/knight":      "Knight auto-evolution commands",
	"/update":      "Update ggcode to the latest release",
	"/restart":     "Restart ggcode (picks up latest binary)",
	"/lang":        "Switch interface language",
	"/skills":      "Browse available skills",
	"/stream":      "Live stream TUI to platforms (YouTube, Bilibili, etc.)",
}

SlashCommandDescriptions provides short descriptions for slash commands.

View Source
var SlashCommandPlaceholders = map[string]string{
	"/model":       "<model-name>",
	"/provider":    "<vendor> [endpoint]",
	"/impersonate": "<cli-tool>",
	"/harness":     "<subcommand>",
	"/knight":      "<subcommand>",
	"/resume":      "<session-id>",
	"/lang":        "<en|zh-CN>",
	"/memory":      "<subcommand>",
	"/image":       "<path>",
	"/skills":      "<skill-name>",
	"/init":        "[path]",
	"/im":          "<subcommand>",
	"/wechat":      "<subcommand>",
	"/stream":      "<start|stop|status|config>",
	"/wecom":       "<subcommand>",
	"/mattermost":  "<subcommand>",
	"/mm":          "<subcommand>",
	"/matrix":      "<subcommand>",
	"/signal":      "<subcommand>",
	"/irc":         "<subcommand>",
	"/nostr":       "<subcommand>",
	"/twitch":      "<subcommand>",
	"/whatsapp":    "",
	"/wa":          "",
	"/restart":     "[debug]",
	"/checkpoints": "[list|restore]",
	"/clear":       "",
	"/compact":     "",
	"/ding":        "<subcommand>",
	"/dingtalk":    "<subcommand>",
	"/discord":     "<subcommand>",
	"/exit":        "",
	"/feishu":      "<subcommand>",
	"/help":        "[command]",
	"/lark":        "<subcommand>",
	"/mcp":         "<subcommand>",
	"/pc":          "<subcommand>",
	"/plugins":     "<subcommand>",
	"/qq":          "<subcommand>",
	"/quit":        "",
	"/sessions":    "[filter]",
	"/slack":       "<subcommand>",
	"/status":      "",
	"/telegram":    "<subcommand>",
	"/tg":          "<subcommand>",
	"/todo":        "<subcommand>",
	"/undo":        "",
	"/update":      "[check|force]",
}

SlashCommandPlaceholders maps commands that accept optional arguments. When Tab-completing these commands, the input is filled with the command plus a trailing space and the placeholder is shown as a hint. Commands NOT in this map are executed immediately on Tab completion.

View Source
var SlashCommands = []string{
	"/help", "/?", "/sessions", "/resume", "/model", "/provider", "/impersonate",
	"/clear", "/im", "/qq", "/telegram", "/tg", "/pc", "/discord", "/feishu", "/lark", "/slack", "/dingtalk", "/ding", "/wechat", "/wecom", "/mattermost", "/mm", "/matrix", "/signal", "/irc", "/nostr", "/twitch", "/whatsapp", "/wa",
	"/mcp", "/memory", "/undo", "/checkpoints", "/plugins",
	"/image", "/init", "/harness", "/exit", "/quit",
	"/compact", "/todo", "/status", "/knight", "/update", "/restart", "/lang", "/skills", "/stream",
}

SlashCommands is the list of all available slash commands.

Functions

func CompleteMention

func CompleteMention(prefix string, workDir string) []string

CompleteMention returns file/directory completions for an @mention prefix. prefix is the text after "@" (e.g., "internal/t" from "@internal/t").

func CompleteSlashCommand

func CompleteSlashCommand(prefix string, customCmds map[string]*commands.Command) []string

CompleteSlashCommand returns matching slash commands for a given prefix.

func ConfirmHomeDir added in v1.1.99

func ConfirmHomeDir(lang Language) bool

ConfirmHomeDir shows a full-screen TUI warning that the user is running from their HOME directory. Returns true if the user wants to continue, false if they want to exit.

func DetectMention

func DetectMention(value string, cursor int) (active bool, prefix string)

DetectMention returns true if the cursor is immediately after a "@" with a path fragment. It returns the path fragment after "@" for completion.

func DetectSlashCommand

func DetectSlashCommand(value string, cursor int) (active bool, prefix string)

DetectSlashCommand returns true if the cursor is at a slash command position. It returns the command fragment after "/" for completion.

func ExpandMentions

func ExpandMentions(input string, workDir string) (string, error)

ExpandMentions reads file contents and directory listings for mentions, returning the expanded message text.

func FormatDiff

func FormatDiff(diff string) string

FormatDiff formats a unified diff for TUI display.

func FormatToolResult

func FormatToolResult(lang Language, msg ToolStatusMsg) string

FormatToolResult formats the closing line when a tool finishes.

func FormatToolStart

func FormatToolStart(msg ToolStatusMsg) string

FormatToolStart formats the header line when a tool begins executing.

func FormatToolStatus

func FormatToolStatus(msg ToolStatusMsg) string

FormatToolStatus formats a tool completion message (legacy compat).

func IsDiffContent

func IsDiffContent(text string) bool

IsDiffContent checks if text looks like a unified diff.

func IsStdoutDead added in v1.1.45

func IsStdoutDead() bool

IsStdoutDead returns true if stdout has been detected as dead.

func RenderMarkdown

func RenderMarkdown(text string) string

RenderMarkdown renders markdown text to ANSI at default width.

func RenderMarkdownWidth added in v1.1.29

func RenderMarkdownWidth(text string, wrap int) string

RenderMarkdownWidth renders markdown text to ANSI at the given width.

Types

type ApprovalMsg

type ApprovalMsg struct {
	ToolName string
	Input    string
	Response chan permission.Decision
}

ApprovalMsg is sent to TUI when agent requests permission.

type AskUserMsg added in v1.1.12

type AskUserMsg struct {
	Request  toolpkg.AskUserRequest
	Response chan toolpkg.AskUserResponse
}

type ConfigView

type ConfigView struct {
	Vendor            string
	Endpoint          string
	Model             string
	VendorNamesFunc   func() []string
	EndpointNamesFunc func(string) []string
	ModelsForEndpoint func(string, string) []string
}

func (*ConfigView) EndpointNames

func (c *ConfigView) EndpointNames(vendor string) []string

func (*ConfigView) VendorNames

func (c *ConfigView) VendorNames() []string

type DiffConfirmMsg

type DiffConfirmMsg struct {
	FilePath string
	DiffText string
	Response chan bool
}

DiffConfirmMsg is sent to TUI when agent wants user to confirm a file edit diff.

type FullscreenModel

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

FullscreenModel wraps the main Model with alt-screen and viewport support.

func NewFullscreenModel

func NewFullscreenModel(inner Model) FullscreenModel

NewFullscreenModel creates a fullscreen model wrapping the inner model.

func (*FullscreenModel) Fullscreen

func (f *FullscreenModel) Fullscreen() bool

Fullscreen returns whether fullscreen mode is active.

func (FullscreenModel) Init

func (f FullscreenModel) Init() tea.Cmd

Init initializes the fullscreen model.

func (*FullscreenModel) Inner

func (f *FullscreenModel) Inner() *Model

Inner returns a pointer to the inner model.

func (*FullscreenModel) RenderContent

func (f *FullscreenModel) RenderContent() string

RenderContent renders the inner model output content (for viewport). This is exposed so the inner model can be used independently.

func (*FullscreenModel) ToggleFullscreen

func (f *FullscreenModel) ToggleFullscreen()

ToggleFullscreen toggles fullscreen mode.

func (FullscreenModel) Update

func (f FullscreenModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update handles messages for the fullscreen model.

func (FullscreenModel) View

func (f FullscreenModel) View() tea.View

View renders the fullscreen UI.

type HarnessCheckpointConfirmMsg added in v1.1.8

type HarnessCheckpointConfirmMsg struct {
	Checkpoint harness.DirtyWorkspaceCheckpoint
	Response   chan bool
}

type Language

type Language string
const (
	LangEnglish Language = "en"
	LangZhCN    Language = "zh-CN"
)

func NormalizeLanguage added in v1.1.99

func NormalizeLanguage(s string) Language

NormalizeLanguage converts a language string to a Language value. Exported for use by cmd/ggcode.

type MCPInfo

type MCPInfo struct {
	Name          string
	ToolNames     []string
	PromptNames   []string
	ResourceNames []string
	Connected     bool
	Pending       bool
	Error         string
	Transport     string
	Migrated      bool
	Disabled      bool
}

type Mention

type Mention struct {
	Path  string // resolved file/directory path
	IsDir bool
}

Mention represents a parsed @mention reference.

func ParseMentions

func ParseMentions(input string, workDir string) (string, []Mention, error)

ParseMentions extracts @path references from user input. Returns the cleaned message (with @path removed) and list of mentions.

type Model

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

Model is the main Bubble Tea model for the REPL.

func NewModel

func NewModel(a *agent.Agent, policy permission.PermissionPolicy) Model

defaultApprovalOptions returns the standard approval options. streamMsg wraps a string from the agent goroutine.

func (*Model) ExecuteRemoteSlashCommand added in v1.1.32

func (m *Model) ExecuteRemoteSlashCommand(text string) (string, bool)

func (Model) Init

func (m Model) Init() tea.Cmd

func (*Model) Session

func (m *Model) Session() *session.Session

func (*Model) SetA2AHandler added in v1.1.46

func (m *Model) SetA2AHandler(h *a2a.TaskHandler)

SetA2AHandler connects the A2A task handler so the sidebar can show active remote tasks and the event callback updates the TUI.

func (*Model) SetAutoMemory

func (m *Model) SetAutoMemory(am *memory.AutoMemory)

func (*Model) SetAutoMemoryFiles

func (m *Model) SetAutoMemoryFiles(files []string)

func (*Model) SetCommandsManager

func (m *Model) SetCommandsManager(mgr *commands.Manager)

func (*Model) SetConfig

func (m *Model) SetConfig(cfg *config.Config)

func (*Model) SetCustomCommands

func (m *Model) SetCustomCommands(cmds map[string]*commands.Command)

func (*Model) SetIMManager added in v1.1.32

func (m *Model) SetIMManager(mgr *im.Manager)

func (*Model) SetKnight added in v1.1.43

func (m *Model) SetKnight(k *knight.Knight)

func (*Model) SetMCPManager

func (m *Model) SetMCPManager(mgr mcpManager)

func (*Model) SetMCPServers

func (m *Model) SetMCPServers(servers []MCPInfo)

func (*Model) SetPluginManager

func (m *Model) SetPluginManager(mgr *plugin.Manager)

func (*Model) SetProgram

func (m *Model) SetProgram(p *tea.Program)

func (*Model) SetProjectMemoryFiles

func (m *Model) SetProjectMemoryFiles(files []string)

func (*Model) SetProjectMemoryLoading added in v1.0.19

func (m *Model) SetProjectMemoryLoading(loading bool)

func (*Model) SetSession

func (m *Model) SetSession(ses *session.Session, store session.Store)

func (*Model) SetSubAgentManager

func (m *Model) SetSubAgentManager(mgr *subagent.Manager)

func (*Model) SetSystemPromptRebuilder added in v1.1.34

func (m *Model) SetSystemPromptRebuilder(fn func() string)

SetSystemPromptRebuilder sets a callback that rebuilds the full system prompt.

func (*Model) SetUpdateService added in v1.0.17

func (m *Model) SetUpdateService(svc *update.Service)

func (Model) Update

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

func (Model) View

func (m Model) View() tea.View

type OnboardResult added in v1.1.94

type OnboardResult struct {
	Language   string
	VendorID   string
	EndpointID string
	APIKey     string
	Model      string
	Mode       string
	Knight     bool
	A2A        bool
	IMAdapters map[string]config.IMAdapterConfig
}

OnboardResult holds the user's selections from the onboard wizard.

func RunOnboard added in v1.1.94

func RunOnboard(cfg *config.Config) (*OnboardResult, error)

RunOnboard starts the onboard wizard as an independent Bubble Tea program.

type REPL

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

REPL connects the agent to the TUI model.

func NewREPL

func NewREPL(a *agent.Agent, policy permission.PermissionPolicy) *REPL

NewREPL creates a new REPL with optional permission policy.

func (*REPL) InjectRestart added in v1.2.4

func (r *REPL) InjectRestart()

InjectRestart triggers a clean restart via the Bubble Tea event loop. This is the same mechanism used by IM /restart and the TUI /restart slash command.

func (*REPL) InjectWebchatMessage added in v1.1.51

func (r *REPL) InjectWebchatMessage(text string)

InjectWebchatMessage sends a webchat user message into the TUI event loop. The message is handled like a normal user input — if the agent is idle, it starts a new run; if busy, it queues as a pending interruption.

func (*REPL) Program added in v1.1.45

func (r *REPL) Program() *tea.Program

Program returns the underlying tea.Program for external callers that need to send messages.

func (*REPL) Run

func (r *REPL) Run() error

Run starts the REPL event loop.

func (*REPL) SetA2AHandler added in v1.1.46

func (r *REPL) SetA2AHandler(h *a2a.TaskHandler)

SetA2AHandler passes the A2A task handler so the sidebar can show remote tasks.

func (*REPL) SetAskUserTool added in v1.1.12

func (r *REPL) SetAskUserTool(tools *tool.Registry)

func (*REPL) SetAutoMemory

func (r *REPL) SetAutoMemory(am *memory.AutoMemory)

func (*REPL) SetAutoMemoryFiles

func (r *REPL) SetAutoMemoryFiles(files []string)

func (*REPL) SetCheckpointManager

func (r *REPL) SetCheckpointManager(m *checkpoint.Manager)

SetCheckpointManager wires the checkpoint manager into the agent and REPL.

func (*REPL) SetCommandsManager

func (r *REPL) SetCommandsManager(mgr *commands.Manager)

func (*REPL) SetConfig

func (r *REPL) SetConfig(cfg *config.Config)

SetConfig passes the config to the model for /model and /provider commands.

func (*REPL) SetConfigTool added in v1.1.45

func (r *REPL) SetConfigTool(tools *tool.Registry)

SetConfigTool registers the config tool backed by the current config.

func (*REPL) SetCronScheduler added in v1.1.45

func (r *REPL) SetCronScheduler(s *cron.Scheduler, tools *tool.Registry)

SetCronScheduler wires the cron scheduler and registers cron tools.

func (*REPL) SetIMManager added in v1.1.32

func (r *REPL) SetIMManager(mgr *im.Manager)

func (*REPL) SetKnight added in v1.1.43

func (r *REPL) SetKnight(k *knight.Knight)

func (*REPL) SetKnightStartupHint added in v1.1.57

func (r *REPL) SetKnightStartupHint(hint string)

SetKnightStartupHint sets a one-time hint to show in the chat area at startup.

func (*REPL) SetMCPManager

func (r *REPL) SetMCPManager(mgr *plugin.MCPManager)

func (*REPL) SetMCPServers

func (r *REPL) SetMCPServers(servers []MCPInfo)

SetMCPServers passes MCP server info to the TUI model.

func (*REPL) SetPlanModeTools added in v1.1.45

func (r *REPL) SetPlanModeTools(tools *tool.Registry)

SetPlanModeTools registers plan mode tools with a mode switcher that updates both the Model's mode and the ConfigPolicy. The switcher remembers the previous mode so exit_plan_mode can restore it.

func (*REPL) SetPluginManager

func (r *REPL) SetPluginManager(mgr *plugin.Manager)

func (*REPL) SetProjectMemoryFiles

func (r *REPL) SetProjectMemoryFiles(files []string)

func (*REPL) SetProjectMemoryLoader added in v1.0.19

func (r *REPL) SetProjectMemoryLoader(loader func() (string, []string, error))

func (*REPL) SetResumeID

func (r *REPL) SetResumeID(id string)

SetResumeID sets the session ID to resume.

func (*REPL) SetSendMessageTool added in v1.1.45

func (r *REPL) SetSendMessageTool(mgr *subagent.Manager, tools *tool.Registry)

SetSendMessageTool registers the send_message tool for agent communication.

func (*REPL) SetSessionStore

func (r *REPL) SetSessionStore(s session.Store)

SetSessionStore sets the session persistence store.

func (*REPL) SetSkillsChangedHook added in v1.1.84

func (r *REPL) SetSkillsChangedHook(hook func())

func (*REPL) SetSubAgentManager

func (r *REPL) SetSubAgentManager(mgr *subagent.Manager, prov provider.Provider, tools *tool.Registry)

SetSubAgentManager wires the sub-agent manager and registers sub-agent tools.

func (*REPL) SetSwarmManager added in v1.1.45

func (r *REPL) SetSwarmManager(mgr *swarm.Manager, tools *tool.Registry)

SetSwarmManager wires the swarm manager and registers swarm tools.

func (*REPL) SetSystemPromptRebuilder added in v1.1.34

func (r *REPL) SetSystemPromptRebuilder(fn func() string)

SetSystemPromptRebuilder sets a callback that rebuilds the full system prompt when skills or other dynamic parts change.

func (*REPL) SetTaskManager added in v1.1.45

func (r *REPL) SetTaskManager(mgr *task.Manager, tools *tool.Registry)

SetTaskManager wires the task manager and registers task tools.

func (*REPL) SetTaskOutputTool added in v1.1.45

func (r *REPL) SetTaskOutputTool(mgr *subagent.Manager, tools *tool.Registry)

SetTaskOutputTool registers the task_output tool for reading sub-agent results.

func (*REPL) SetUpdateService added in v1.0.17

func (r *REPL) SetUpdateService(svc *update.Service)

func (*REPL) SetWebUIBridge added in v1.1.51

func (r *REPL) SetWebUIBridge(b WebUIEventBroadcaster)

SetWebUIBridge sets the webui event broadcaster for forwarding agent events to webchat subscribers.

func (*REPL) SetWebUIReadyAddr added in v1.1.51

func (r *REPL) SetWebUIReadyAddr(addr, token string)

SetWebUIReadyAddr stores the webui address and auth token to be displayed in the TUI after startup. The actual program.Send happens in the startup goroutine alongside logoMsg to ensure the TUI is ready.

type ToolSpinner

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

ToolSpinner manages spinner state for active tool execution.

func NewToolSpinner

func NewToolSpinner() *ToolSpinner

NewToolSpinner creates a new spinner.

func (*ToolSpinner) CurrentFrame

func (s *ToolSpinner) CurrentFrame() int

CurrentFrame returns the current spinner frame index.

func (*ToolSpinner) Elapsed

func (s *ToolSpinner) Elapsed() time.Duration

Elapsed returns how long the current tool has been running.

func (*ToolSpinner) IsActive

func (s *ToolSpinner) IsActive() bool

IsActive returns whether the spinner is running.

func (*ToolSpinner) Start

func (s *ToolSpinner) Start(label string) tea.Cmd

Start begins the spinner for a tool.

func (*ToolSpinner) Stop

func (s *ToolSpinner) Stop()

Stop ends the spinner.

func (*ToolSpinner) String

func (s *ToolSpinner) String() string

String returns the spinner string with tool name.

func (*ToolSpinner) Update

func (s *ToolSpinner) Update(msg tea.Msg) tea.Cmd

Update handles spinner animation frames.

type ToolStatusMsg

type ToolStatusMsg struct {
	ToolID      string
	ToolName    string
	DisplayName string
	Detail      string
	Activity    string
	Running     bool // true = start, false = done
	Result      string
	RawArgs     string
	Args        string // raw tool arguments summary, used as a fallback only
	IsError     bool
	Elapsed     time.Duration
}

ToolStatusMsg is sent when a tool starts or finishes execution.

type ViewportModel

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

ViewportModel wraps a viewport with auto-follow behavior.

func NewViewportModel

func NewViewportModel(width, height int) ViewportModel

NewViewportModel creates a new viewport model.

func (*ViewportModel) AtBottom

func (v *ViewportModel) AtBottom() bool

AtBottom returns true if the viewport is at the bottom.

func (*ViewportModel) AutoFollow

func (v *ViewportModel) AutoFollow() bool

AutoFollow returns whether auto-follow is enabled.

func (*ViewportModel) Content

func (v *ViewportModel) Content() string

Content returns the current viewport content.

func (*ViewportModel) GotoBottom

func (v *ViewportModel) GotoBottom()

GotoBottom scrolls to the bottom and enables auto-follow.

func (*ViewportModel) ScrollDown

func (v *ViewportModel) ScrollDown(n int)

ScrollDown scrolls down by n lines.

func (ViewportModel) ScrollIndicatorStyle

func (v ViewportModel) ScrollIndicatorStyle() string

ScrollIndicatorStyle returns a styled scroll indicator.

func (*ViewportModel) ScrollUp

func (v *ViewportModel) ScrollUp(n int)

ScrollUp scrolls up by n lines.

func (*ViewportModel) SetContent

func (v *ViewportModel) SetContent(content string)

SetContent sets the viewport content and auto-scrolls to bottom if following.

func (*ViewportModel) SetSize

func (v *ViewportModel) SetSize(width, height int)

SetSize updates the viewport dimensions.

func (*ViewportModel) TotalLineCount

func (v *ViewportModel) TotalLineCount() int

TotalLineCount returns the total number of content lines.

func (ViewportModel) Update

func (v ViewportModel) Update(msg tea.Msg) (ViewportModel, tea.Cmd)

Update handles messages for the viewport.

func (ViewportModel) View

func (v ViewportModel) View() tea.View

View renders the viewport.

func (*ViewportModel) VisibleLineCount

func (v *ViewportModel) VisibleLineCount() int

VisibleLineCount returns the number of visible lines.

func (*ViewportModel) YOffset

func (v *ViewportModel) YOffset() int

YOffset returns the current vertical scroll offset.

type WebUIEventBroadcaster added in v1.1.51

type WebUIEventBroadcaster interface {
	BroadcastEvent(event provider.StreamEvent)
}

MCPInfo holds display info about a connected MCP server. WebUIEventBroadcaster broadcasts agent events to webui subscribers.

Source Files

Jump to

Keyboard shortcuts

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