chat

package
v0.0.310 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 47 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpandGlob

func ExpandGlob(pattern string) ([]string, error)

ExpandGlob expands a glob pattern to matching files

func ExpandUserPath added in v0.0.257

func ExpandUserPath(path string) (string, error)

ExpandUserPath expands a leading ~ or ~/ in user-provided file paths before globbing, approval checks, or file reads. Shells do not expand ~ inside the TUI command parser, so slash commands need to do it explicitly.

func FormatFileSize

func FormatFileSize(bytes int64) string

FormatFileSize returns a human-readable file size

func GetBundledServers added in v0.0.55

func GetBundledServers() []mcp.BundledServer

GetBundledServers returns bundled MCP servers (wrapper for mcp package)

func GetParentOptions

func GetParentOptions(path string) []string

GetParentOptions returns the directory and its parents for approval choices

func SaveApprovedDirs

func SaveApprovedDirs(dirs *ApprovedDirs) error

SaveApprovedDirs saves the approved directories to disk

Types

type ApprovalRequestMsg added in v0.0.50

type ApprovalRequestMsg struct {
	Path    string
	IsWrite bool
	IsShell bool
	WorkDir string // directory where a shell command will execute (may be empty)
	DoneCh  chan<- tools.ApprovalResult
}

ApprovalRequestMsg triggers an inline approval prompt.

type ApprovedDirs

type ApprovedDirs struct {
	ApprovedAt  time.Time `json:"approved_at"`
	Directories []string  `json:"directories"`
}

ApprovedDirs stores the list of approved directories

func LoadApprovedDirs

func LoadApprovedDirs() (*ApprovedDirs, error)

LoadApprovedDirs loads the approved directories from disk

func (*ApprovedDirs) AddDirectory

func (d *ApprovedDirs) AddDirectory(dir string) error

AddDirectory adds a directory to the approved list

func (*ApprovedDirs) IsPathApproved

func (d *ApprovedDirs) IsPathApproved(path string) bool

IsPathApproved checks if a path is within an approved directory

func (*ApprovedDirs) RemoveDirectory

func (d *ApprovedDirs) RemoveDirectory(dir string) error

RemoveDirectory removes a directory from the approved list

type AskUserRequestMsg added in v0.0.50

type AskUserRequestMsg struct {
	Questions []tools.AskUserQuestion
	DoneCh    chan<- []tools.AskUserAnswer
}

AskUserRequestMsg triggers an inline ask_user prompt.

type Command

type Command struct {
	Name        string
	Aliases     []string
	Description string
	Usage       string
	Subcommands []Subcommand // Optional subcommands
}

Command represents a slash command

func AllCommands

func AllCommands() []Command

AllCommands returns all available slash commands

func FilterCommands

func FilterCommands(query string) []Command

FilterCommands returns commands matching the query using fuzzy search If query contains a space (e.g., "mcp "), it returns subcommands for that command

type CommandSource

type CommandSource []Command

CommandSource implements fuzzy.Source for command searching

func (CommandSource) Len

func (c CommandSource) Len() int

func (CommandSource) String

func (c CommandSource) String(i int) string

type CompletionsModel

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

CompletionsModel handles the command completions popup

func NewCompletionsModel

func NewCompletionsModel(styles *ui.Styles) *CompletionsModel

NewCompletionsModel creates a new completions model

func (*CompletionsModel) Hide

func (c *CompletionsModel) Hide()

Hide hides the completions popup

func (*CompletionsModel) IsVisible

func (c *CompletionsModel) IsVisible() bool

IsVisible returns whether the popup is visible

func (*CompletionsModel) Selected

func (c *CompletionsModel) Selected() *Command

Selected returns the currently selected command

func (*CompletionsModel) SetItems

func (c *CompletionsModel) SetItems(items []Command)

SetItems sets custom completion items (for dynamic completions like server names)

func (*CompletionsModel) SetQuery

func (c *CompletionsModel) SetQuery(query string)

SetQuery updates the filter query

func (*CompletionsModel) SetSize

func (c *CompletionsModel) SetSize(width, height int)

SetSize updates the dimensions

func (*CompletionsModel) Show

func (c *CompletionsModel) Show()

Show displays the completions popup

func (*CompletionsModel) Update

func (c *CompletionsModel) Update(msg tea.Msg) (*CompletionsModel, tea.Cmd)

Update handles messages

func (*CompletionsModel) View

func (c *CompletionsModel) View() string

View renders the completions popup

type ContentPos added in v0.0.112

type ContentPos struct {
	Line int // 0-based line in full content string
	Col  int // 0-based visual column
}

ContentPos is a position within the full rendered content.

type DialogItem

type DialogItem struct {
	ID          string
	Label       string
	Description string
	Selected    bool
	Category    string
}

DialogItem represents an item in a dialog list

type DialogModel

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

DialogModel handles modal dialogs

func NewDialogModel

func NewDialogModel(styles *ui.Styles) *DialogModel

NewDialogModel creates a new dialog model

func (*DialogModel) Close

func (d *DialogModel) Close()

Close closes the dialog

func (*DialogModel) Content added in v0.0.224

func (d *DialogModel) Content() string

Content returns the raw content currently displayed by a content dialog.

func (*DialogModel) Cursor

func (d *DialogModel) Cursor() int

Cursor returns the current cursor position

func (*DialogModel) GetDirApprovalPath

func (d *DialogModel) GetDirApprovalPath() string

func (*DialogModel) IsOpen

func (d *DialogModel) IsOpen() bool

IsOpen returns whether a dialog is open

func (*DialogModel) ItemAt

func (d *DialogModel) ItemAt(idx int) *DialogItem

ItemAt returns the item at the given index (0-based)

func (*DialogModel) Query

func (d *DialogModel) Query() string

Query returns the current filter query

func (*DialogModel) Selected

func (d *DialogModel) Selected() *DialogItem

Selected returns the currently highlighted item

func (*DialogModel) SetCursor

func (d *DialogModel) SetCursor(pos int)

SetCursor sets the cursor position, clamping to valid range

func (*DialogModel) SetQuery

func (d *DialogModel) SetQuery(query string)

SetQuery updates the filter query for model picker or MCP picker

func (*DialogModel) SetSize

func (d *DialogModel) SetSize(width, height int)

SetSize updates the dimensions

func (*DialogModel) ShowContent added in v0.0.224

func (d *DialogModel) ShowContent(title, content string)

ShowContent opens a scrollable static content modal.

func (*DialogModel) ShowDirApproval

func (d *DialogModel) ShowDirApproval(filePath string, options []string)

ShowDirApproval opens the directory approval dialog

func (*DialogModel) ShowMCPPicker

func (d *DialogModel) ShowMCPPicker(mcpManager *mcp.Manager)

ShowMCPPicker opens the MCP server picker dialog

func (*DialogModel) ShowModelPicker

func (d *DialogModel) ShowModelPicker(currentProviderModel string, providers []ProviderInfo, recentModels []string)

ShowModelPicker opens the model picker dialog. currentProviderModel is the full "provider:model" identifier of the active model. recentModels is an optional MRU-ordered list of "provider:model" strings; matching items are floated to the top of the list.

func (*DialogModel) ShowSessionList

func (d *DialogModel) ShowSessionList(items []DialogItem, currentSessionID string)

ShowSessionList opens the session list dialog. items should have ID=full session ID, Label=display name.

func (*DialogModel) Type

func (d *DialogModel) Type() DialogType

Type returns the current dialog type

func (*DialogModel) Update

func (d *DialogModel) Update(msg tea.Msg) (*DialogModel, tea.Cmd)

Update handles messages

func (*DialogModel) View

func (d *DialogModel) View() string

View renders the dialog

type DialogType

type DialogType int

DialogType represents the type of dialog

const (
	DialogNone DialogType = iota
	DialogModelPicker
	DialogSessionList
	DialogDirApproval
	DialogMCPPicker
	DialogContent
)

type DirApprovalRequest

type DirApprovalRequest struct {
	Path      string   // The file path that triggered the request
	Options   []string // Directory options to approve
	OnApprove func(dir string)
	OnDeny    func()
}

DirApprovalRequest represents a pending directory approval request

type FileAttachment

type FileAttachment struct {
	Path    string
	Name    string
	Content string
	Size    int64
}

FileAttachment represents an attached file

func AttachFile

func AttachFile(path string) (*FileAttachment, error)

AttachFile reads a file and creates an attachment

type FileCompletion

type FileCompletion struct {
	Path    string
	Name    string
	IsDir   bool
	RelPath string
}

FileCompletion represents a file path completion item

func ListFiles

func ListFiles(dir string, query string) []FileCompletion

ListFiles returns files in a directory for completion

type FileCompletionSource

type FileCompletionSource []FileCompletion

FileCompletionSource implements fuzzy.Source for file completions

func (FileCompletionSource) Len

func (f FileCompletionSource) Len() int

func (FileCompletionSource) String

func (f FileCompletionSource) String(i int) string

type FlushBeforeApprovalMsg added in v0.0.35

type FlushBeforeApprovalMsg struct {
	Done chan<- struct{} // Signal when flush is complete
}

FlushBeforeApprovalMsg signals the TUI to flush content to scrollback before releasing the terminal for approval prompts.

type FlushBeforeAskUserMsg added in v0.0.35

type FlushBeforeAskUserMsg struct {
	Done chan<- struct{} // Signal when flush is complete
}

FlushBeforeAskUserMsg signals the TUI to flush content to scrollback before releasing the terminal for ask_user prompts.

type HandoverRequestMsg added in v0.0.147

type HandoverRequestMsg struct {
	Agent  string
	DoneCh chan<- bool
}

HandoverRequestMsg triggers a handover flow from a tool call.

type ImageAttachment added in v0.0.91

type ImageAttachment struct {
	MediaType string
	Data      []byte
}

ImageAttachment represents an image attached to the next outgoing user message.

type KeyMap

type KeyMap struct {
	// Global
	Quit     key.Binding
	Commands key.Binding

	// Editor
	Send        key.Binding
	Newline     key.Binding
	NewlineAlt  key.Binding
	ClearLine   key.Binding
	DeleteWord  key.Binding
	Cancel      key.Binding
	HistoryUp   key.Binding
	HistoryDown key.Binding
	Tab         key.Binding

	// History navigation
	PageUp   key.Binding
	PageDown key.Binding

	// Shortcuts
	Help        key.Binding
	SwitchModel key.Binding
	CycleEffort key.Binding
	ToggleWeb   key.Binding
	ToggleYolo  key.Binding
	Clear       key.Binding
	NewSession  key.Binding
	MCPPicker   key.Binding
	Inspector   key.Binding
	ExpandTools key.Binding
	Copy        key.Binding
}

KeyMap defines keybindings for the chat TUI

func DefaultKeyMap

func DefaultKeyMap() KeyMap

DefaultKeyMap returns the default keybindings

type Model

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

func New

func New(cfg *config.Config, provider llm.Provider, engine *llm.Engine, providerKey string, modelName string, mcpManager *mcp.Manager, maxTurns int, forceExternalSearch bool, disableExternalWebFetch bool, searchEnabled bool, localTools []string, toolsStr string, mcpStr string, showStats bool, initialText string, store session.Store, sess *session.Session, altScreen bool, autoSendQueue []string, autoSendExitOnDone bool, textMode bool, agentName string, platformDeveloperMessage string, yolo bool) *Model

New creates a new chat model. fast-provider aware callers should use NewWithFastProvider.

func NewWithFastProvider added in v0.0.101

func NewWithFastProvider(cfg *config.Config, provider llm.Provider, fastProvider llm.Provider, engine *llm.Engine, providerKey string, modelName string, mcpManager *mcp.Manager, maxTurns int, forceExternalSearch bool, disableExternalWebFetch bool, searchEnabled bool, localTools []string, toolsStr string, mcpStr string, showStats bool, initialText string, store session.Store, sess *session.Session, altScreen bool, autoSendQueue []string, autoSendExitOnDone bool, textMode bool, agentName string, platformDeveloperMessage string, yolo bool) *Model

NewWithFastProvider creates a new chat model with an optional fast provider for control-plane classification tasks.

func (*Model) ExecuteCommand

func (m *Model) ExecuteCommand(input string) (tea.Model, tea.Cmd)

ExecuteCommand handles slash command execution

func (*Model) Init

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

Init initializes the model

func (*Model) ReloadSessionID added in v0.0.102

func (m *Model) ReloadSessionID() string

ReloadSessionID returns the session ID to resume after a reload, if any.

func (*Model) RequestedHandoverAutoSend added in v0.0.134

func (m *Model) RequestedHandoverAutoSend() string

RequestedHandoverAutoSend returns a message to auto-send after handover restart.

func (*Model) RequestedResumeSessionID added in v0.0.97

func (m *Model) RequestedResumeSessionID() string

RequestedResumeSessionID returns a pending session ID to relaunch, if any.

func (*Model) SetAgentLister added in v0.0.134

func (m *Model) SetAgentLister(lister func(cfg *config.Config) ([]string, error))

SetAgentLister configures the function used to list available agent names for /handover completions.

func (*Model) SetAgentResolver added in v0.0.134

func (m *Model) SetAgentResolver(resolver func(name string, cfg *config.Config) (*agents.Agent, error))

SetAgentResolver configures the function used to resolve agent names during /handover. The function should match cmd.LoadAgent's signature.

func (*Model) SetApprovalManager added in v0.0.182

func (m *Model) SetApprovalManager(mgr *tools.ApprovalManager)

SetApprovalManager configures the active approval manager used by chat-level controls such as the yolo-mode toggle.

func (*Model) SetCurrentAgent added in v0.0.134

func (m *Model) SetCurrentAgent(agent *agents.Agent)

SetCurrentAgent sets the current agent configuration (used by /handover to check for enable_handover).

func (*Model) SetFooterWarning added in v0.0.236

func (m *Model) SetFooterWarning(content string)

SetFooterWarning sets a warning notice in the chat footer. It is intended for startup/configuration notices emitted before the Bubble Tea program is running.

func (*Model) SetHandoverApprovalManager added in v0.0.134

func (m *Model) SetHandoverApprovalManager(mgr *tools.ApprovalManager)

SetHandoverApprovalManager configures shell approval checks for handover scripts.

func (*Model) SetHandoverAutoSend added in v0.0.134

func (m *Model) SetHandoverAutoSend(text string)

SetHandoverAutoSend sets a message to auto-send on Init (for handover restart).

func (*Model) SetHandoverSystemPromptResolver added in v0.0.305

func (m *Model) SetHandoverSystemPromptResolver(resolver func(agent *agents.Agent, providerKey, modelName string) (string, error))

SetHandoverSystemPromptResolver configures the normal chat-startup prompt pipeline used to resolve the target agent's persisted handover system prompt.

func (*Model) SetProgram added in v0.0.227

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

SetProgram gives the model a handle to the running Bubble Tea program for scheduling raw terminal writes that are discovered during View rendering.

func (*Model) SetRootContext added in v0.0.134

func (m *Model) SetRootContext(ctx context.Context)

SetRootContext configures the parent context for long-running chat commands.

func (*Model) TakePostFrameImageSequence added in v0.0.234

func (m *Model) TakePostFrameImageSequence() string

func (*Model) Update

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

Update handles messages

func (*Model) View

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

View renders the model

func (*Model) WaitStreamDone added in v0.0.153

func (m *Model) WaitStreamDone()

WaitStreamDone blocks until the engine streaming goroutine has exited. It is safe to call when no stream was started (no-op).

func (*Model) WantsReload added in v0.0.102

func (m *Model) WantsReload() bool

WantsReload reports whether the user requested a binary reload via /reload.

func (*Model) YoloModeActive added in v0.0.224

func (m *Model) YoloModeActive() bool

YoloModeActive returns the current effective yolo state, including approval managers that may have been toggled during the session.

type ProviderInfo

type ProviderInfo struct {
	Name   string
	Models []string
}

ProviderInfo holds provider and model information

func GetAvailableProviders

func GetAvailableProviders(cfg *config.Config) []ProviderInfo

GetAvailableProviders returns providers with their models in consistent order If cfg is provided, custom configured providers are also included

type ResumeFromExternalUIMsg added in v0.0.35

type ResumeFromExternalUIMsg struct{}

ResumeFromExternalUIMsg signals that external UI (ask_user/approval) is done

type Selection added in v0.0.112

type Selection struct {
	Active   bool       // true once a drag has started
	Anchor   ContentPos // drag start (fixed)
	Cursor   ContentPos // drag end (follows mouse)
	Dragging bool       // true between press and release
}

Selection tracks mouse-drag selection state in the viewport.

func (Selection) Normalized added in v0.0.112

func (s Selection) Normalized() (start, end ContentPos)

Normalized returns the selection range ordered so start <= end.

type SubagentProgressMsg added in v0.0.42

type SubagentProgressMsg struct {
	CallID string
	Event  tools.SubagentEvent
}

SubagentProgressMsg carries progress events from running subagents.

type Subcommand

type Subcommand struct {
	Name        string
	Description string
}

Subcommand represents a subcommand of a slash command

Jump to

Keyboard shortcuts

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