tui

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package tui provides the Terminal User Interface for monkey

Index

Constants

View Source
const (
	EnvPriceInput  = "MONKEY_PRICE_INPUT"
	EnvPriceOutput = "MONKEY_PRICE_OUTPUT"
)

Environment variables for overriding model pricing (USD per million tokens).

View Source
const (
	ColorPrimary = "#461914" // Deep Brown-Red
	ColorAccent  = "#A89228" // Antique Gold
)

Primary brand colors. ColorPrimary is the anchor color for persistent UI elements (e.g. input border). ColorAccent is the warm highlight used for active/selected states.

View Source
const (
	ColorUserBorder      = "#8B3A21" // Rust Brown    — warm, personal
	ColorAssistantBorder = "#729B2F" // Leaf Green    — natural, positive
	ColorToolBorder      = "#225057" // Dark Slate    — cool, functional
	ColorSystemBorder    = "#305322" // Forest Green  — subdued, informational
	ColorErrorBorder     = "#BA3F28" // Burnt Orange  — danger/warning
)

Message role border colors.

View Source
const (
	ColorGrayLight = "#AAAAAA" // timer, secondary info
	ColorGrayMid   = "#888888" // muted labels, canceled state
	ColorGrayDark  = "#666666" // picker borders, subdued help text
	ColorGrayDeep  = "#555555" // timestamps, inactive state, faint text
)

Muted gray scale — explicit names instead of ad-hoc hex literals.

View Source
const (
	ColorDiffAdd    = ColorAssistantBorder // green — positive change, same as assistant border
	ColorDiffDel    = ColorErrorBorder     // red — destructive change, same as error border
	ColorDiffHunk   = ColorToolBorder      // cyan — structural/informational, same as tool border
	ColorDiffGutter = ColorGrayDeep        // faint — line numbers recede into the background
)

Diff view colors — derived from the app's existing semantic palette. Using ColorAssistantBorder and ColorToolBorder eliminates the three-greens and GitHub-blue problems: there is now one green and one cyan in the whole app.

View Source
const (
	ColorApprovalModel = ColorAssistantBorder // green — the assistant is acting
	ColorApprovalTool  = ColorToolBorder      // cyan — it is a tool call
)

Tool approval dialog colors, derived from existing semantic tokens.

View Source
const (
	ColorMonkeyDark  = "#2B1200" // very dark brown  — ██ outline
	ColorMonkeyMid   = "#7B4220" // medium brown     — ▒▒ body
	ColorMonkeySkin  = "#7c3400" // warm brown       — ▓▓ skin
	ColorMonkeyLight = "#C49A6C" // warm tan         — ░░ face / underbelly
)

Intro art pixel colors — four tiers of block shading for the monkey sprite.

View Source
const APITimeout = 60 * time.Second

APITimeout is the default timeout for API requests

View Source
const ColorPickerCursor = ColorAccent

ColorPickerCursor is the highlighted-row color in all pickers. Uses ColorAccent so selection reads as "warm highlight", not "assistant message".

Variables

This section is empty.

Functions

func ApeModeActiveStyle

func ApeModeActiveStyle() lipgloss.Style

ApeModeActiveStyle returns accent-color styling for the ape mode indicator when enabled.

func ApeModeInactiveStyle

func ApeModeInactiveStyle() lipgloss.Style

ApeModeInactiveStyle returns grey styling for the ape mode indicator when disabled.

func AssistantMessageStyle

func AssistantMessageStyle(width int) lipgloss.Style

AssistantMessageStyle returns the styling for assistant messages

func ErrorMessageStyle

func ErrorMessageStyle(width int) lipgloss.Style

ErrorMessageStyle returns the styling for error messages

func FilePickerCursorStyle

func FilePickerCursorStyle() lipgloss.Style

FilePickerCursorStyle returns the styling for the highlighted file picker row. Uses ColorPickerCursor (accent) so "selected" reads as a warm highlight, distinct from ColorAssistantBorder which means "assistant message".

func FilePickerStyle

func FilePickerStyle(width int) lipgloss.Style

FilePickerStyle returns the styling for the file picker dropdown border.

func InputStyle

func InputStyle(width, height int) lipgloss.Style

InputStyle returns the styling for the input textarea. Uses ColorAccent so the active input zone is clearly visible all session long.

func LoadFilesCmd

func LoadFilesCmd() tea.Cmd

LoadFilesCmd returns a tea.Cmd that walks the current directory tree and collects relative file paths, skipping hidden directories and vendor/node_modules.

func MessageTimestampStyle

func MessageTimestampStyle(width int) lipgloss.Style

MessageTimestampStyle returns the styling for per-message timestamps: gray, right-aligned.

func RenderAssistantBlock

func RenderAssistantBlock(width int, modelName, content string) string

RenderAssistantBlock renders an assistant message inside a green rounded border with the model name embedded in the top border: ╭─ claude-sonnet-4-5 ──────╮

func RenderIntroBlock

func RenderIntroBlock(width int, title, version, content string) string

RenderIntroBlock renders a two-panel block: left panel sized to fit the ASCII art, right panel taking the remaining space (title + version + help text).

func RenderMarkdown

func RenderMarkdown(content string, width int) string

RenderMarkdown renders markdown-formatted content as ANSI-styled terminal text. Falls back to the original content if rendering fails or width is zero.

func RenderSplitDiff

func RenderSplitDiff(diff string, width int) string

RenderSplitDiff renders a unified diff as two side-by-side panels: "Before" (left, red border) shows context + deleted lines, "After" (right, green border) shows context + added lines. Paired deletion/addition chunks are aligned on the same row.

func RenderToolBlock

func RenderToolBlock(width int, toolName, content string) string

RenderToolBlock renders a tool call message inside a cyan rounded border with the tool name embedded in the top border: ╭─ bash ──────╮

func RenderUserBlock

func RenderUserBlock(width int, content string) string

RenderUserBlock renders a user message inside a purple rounded border with "You" embedded in the top border: ╭─ You ──────╮

func SaveSession

func SaveSession(path, model string, apiMessages []api.Message, messages []Message) error

SaveSession persists the current session to path, creating parent directories as needed.

func SearchMatchStyle

func SearchMatchStyle() lipgloss.Style

SearchMatchStyle returns the styling for the search-match indicator shown above matching messages.

func SendCompactCmd

func SendCompactCmd(client *api.Client, history []Message, timeout time.Duration) tea.Cmd

SendCompactCmd creates a tea.Cmd that sends a summarization request to the API. history is the current display messages used to build the summarization prompt. On success it returns a CompactResponseMsg; on failure a PromptErrorMsg.

func SendPromptCmd

func SendPromptCmd(client *api.Client, apiMessages []api.Message, prompt string) (tea.Cmd, context.CancelFunc)

SendPromptCmd creates a tea.Cmd that sends the conversation history plus the new prompt to the API using the default timeout. apiMessages is the full API-layer history (including tool_use/tool_result from prior turns). The returned CancelFunc can be called to cancel the in-flight request.

func SendPromptCmdWithTimeout

func SendPromptCmdWithTimeout(client *api.Client, apiMessages []api.Message, prompt string, timeout time.Duration, toolCallCh chan<- ToolCallMsg, approvalCh chan<- ToolApprovalRequestMsg, tokenCh chan<- PartialResponseMsg, retryChs ...chan<- RetryingMsg) (tea.Cmd, context.CancelFunc)

SendPromptCmdWithTimeout creates a tea.Cmd that sends the prompt with a per-attempt timeout. apiMessages is the full API-layer history (including tool_use/tool_result from prior turns). The returned CancelFunc can be called to cancel the in-flight request. toolCallCh, if non-nil, receives a ToolCallMsg for each tool call as it completes and is closed when done. approvalCh, if non-nil, enables the approval harness: each tool call sends a ToolApprovalRequestMsg and blocks until the TUI responds. When nil, tools execute without approval. tokenCh, if non-nil, uses the streaming SSE API and receives a PartialResponseMsg for each text token. An optional retryCh receives a RetryingMsg before each retry attempt and is closed when done.

func SessionPath

func SessionPath() string

SessionPath returns the path to the session file, respecting XDG_CONFIG_HOME.

func SpinnerStyle

func SpinnerStyle() lipgloss.Style

SpinnerStyle returns the styling for the loading spinner

func StatusBarModelStyle

func StatusBarModelStyle() lipgloss.Style

StatusBarModelStyle renders the current model name in the status bar.

func StatusBarSepStyle

func StatusBarSepStyle() lipgloss.Style

StatusBarSepStyle renders the "|" separator between status bar segments.

func StatusBarTokenStyle

func StatusBarTokenStyle() lipgloss.Style

StatusBarTokenStyle renders the token count in the status bar.

func SystemMessageStyle

func SystemMessageStyle(width int) lipgloss.Style

SystemMessageStyle returns the styling for system notices (e.g. retry messages)

func TimerStyle

func TimerStyle() lipgloss.Style

TimerStyle returns the styling for the elapsed time indicator

func ToolApprovalCanceledLabelStyle

func ToolApprovalCanceledLabelStyle() lipgloss.Style

ToolApprovalCanceledLabelStyle returns muted gray italic styling for the "Canceled by user" label.

func ToolApprovalDeniedPreviewStyle

func ToolApprovalDeniedPreviewStyle() lipgloss.Style

ToolApprovalDeniedPreviewStyle returns faint gray styling for the preview in a canceled dialog.

func ToolApprovalDeniedToolStyle

func ToolApprovalDeniedToolStyle() lipgloss.Style

ToolApprovalDeniedToolStyle returns muted styling for the tool name in a canceled dialog.

func ToolApprovalModelStyle

func ToolApprovalModelStyle() lipgloss.Style

ToolApprovalModelStyle returns styling for the model name in the approval dialog. Uses ColorApprovalModel (green) — the assistant is the one requesting action.

func ToolApprovalPreviewStyle

func ToolApprovalPreviewStyle() lipgloss.Style

ToolApprovalPreviewStyle returns styling for the bash command preview line.

func ToolApprovalToolStyle

func ToolApprovalToolStyle() lipgloss.Style

ToolApprovalToolStyle returns styling for the tool name in the approval dialog. Uses ColorApprovalTool (cyan) — consistent with tool call borders.

func ToolMessageStyle

func ToolMessageStyle(width int) lipgloss.Style

ToolMessageStyle returns the styling for tool call messages (cyan border)

func UserMessageStyle

func UserMessageStyle(width int) lipgloss.Style

UserMessageStyle returns the styling for user messages

func WaitingStyle

func WaitingStyle() lipgloss.Style

WaitingStyle returns the styling for the idle/waiting prompt shown after cancellation.

Types

type ApprovingExecutor

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

ApprovingExecutor wraps a ToolExecutor and requests user approval before each tool call. It sends a ToolApprovalRequestMsg on approvalCh and blocks until the TUI responds.

func (ApprovingExecutor) ExecuteTool

func (a ApprovingExecutor) ExecuteTool(ctx context.Context, name string, input map[string]any) (string, error)

ExecuteTool requests approval via approvalCh, then delegates to inner on approval. Returns ctx.Err() if the context is cancelled while waiting for the user's decision.

type CommandPicker

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

CommandPicker is a keyboard-navigable dropdown for slash command completion.

func NewCommandPicker

func NewCommandPicker(width int) CommandPicker

NewCommandPicker returns an inactive command picker.

func (*CommandPicker) Activate

func (cp *CommandPicker) Activate()

Activate makes the picker visible.

func (*CommandPicker) Deactivate

func (cp *CommandPicker) Deactivate()

Deactivate hides the picker.

func (CommandPicker) Height

func (cp CommandPicker) Height() int

Height returns the number of terminal rows occupied by the picker without rendering it. Returns 0 when inactive. Used by syncViewportHeight to avoid a full View() render just to count lines.

func (CommandPicker) IsActive

func (cp CommandPicker) IsActive() bool

IsActive reports whether the picker is visible.

func (CommandPicker) SelectedCommand

func (cp CommandPicker) SelectedCommand() string

SelectedCommand returns the full slash command string (e.g. "/exit") for the currently highlighted entry, or "" when inactive or no match.

func (*CommandPicker) SetQuery

func (cp *CommandPicker) SetQuery(query string)

SetQuery filters commands by fuzzy-matching against the query.

func (*CommandPicker) SetWidth

func (cp *CommandPicker) SetWidth(w int)

SetWidth updates the display width.

func (CommandPicker) Update

func (cp CommandPicker) Update(msg tea.Msg) (CommandPicker, tea.Cmd)

Update handles Up/Down cursor navigation.

func (CommandPicker) View

func (cp CommandPicker) View() string

View renders the command picker dropdown. Returns "" when inactive.

type CompactResponseMsg

type CompactResponseMsg struct {
	Summary string
}

CompactResponseMsg is returned when a /compact summarization request succeeds. Summary holds the condensed conversation text that replaces the message history.

type FilePicker

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

FilePicker is a keyboard-navigable file selection dropdown.

func NewFilePicker

func NewFilePicker(width int) FilePicker

NewFilePicker returns an inactive file picker with the given display width.

func (*FilePicker) Activate

func (fp *FilePicker) Activate()

Activate makes the picker visible.

func (*FilePicker) Deactivate

func (fp *FilePicker) Deactivate()

Deactivate hides the picker.

func (FilePicker) Height

func (fp FilePicker) Height() int

Height returns the number of terminal rows occupied by the picker without rendering it. Returns 0 when inactive. Used by syncViewportHeight to avoid a full View() render just to count lines.

func (FilePicker) IsActive

func (fp FilePicker) IsActive() bool

IsActive reports whether the picker is currently visible.

func (FilePicker) SelectedFile

func (fp FilePicker) SelectedFile() string

SelectedFile returns the currently highlighted file path, or "" if none.

func (*FilePicker) SetFiles

func (fp *FilePicker) SetFiles(files []string)

SetFiles replaces the full file list and resets filtering.

func (*FilePicker) SetQuery

func (fp *FilePicker) SetQuery(query string)

SetQuery filters the list by fuzzy-matching each file path against query. An empty query shows all files.

func (*FilePicker) SetWidth

func (fp *FilePicker) SetWidth(width int)

SetWidth updates the display width.

func (FilePicker) Update

func (fp FilePicker) Update(msg tea.Msg) (FilePicker, tea.Cmd)

Update handles Up/Down cursor navigation.

func (FilePicker) View

func (fp FilePicker) View() string

View renders the picker as a bordered dropdown. Returns "" when inactive.

type FilesLoadedMsg

type FilesLoadedMsg struct {
	Files []string
}

FilesLoadedMsg is sent when the async file walk completes.

type HelpPanel

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

HelpPanel is a static panel listing available input shortcuts.

func NewHelpPanel

func NewHelpPanel(width int) HelpPanel

NewHelpPanel returns an inactive help panel.

func (*HelpPanel) Activate

func (hp *HelpPanel) Activate()

Activate makes the panel visible.

func (*HelpPanel) Deactivate

func (hp *HelpPanel) Deactivate()

Deactivate hides the panel.

func (HelpPanel) IsActive

func (hp HelpPanel) IsActive() bool

IsActive reports whether the panel is visible.

func (*HelpPanel) SetWidth

func (hp *HelpPanel) SetWidth(w int)

SetWidth updates the display width.

func (HelpPanel) View

func (hp HelpPanel) View() string

View renders the help panel. Returns "" when inactive.

type History

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

History manages prompt history persisted to a local file. Navigation mimics bash: Up moves to older entries, Down moves to newer ones.

func LoadHistory

func LoadHistory() History

LoadHistory loads history from ~/.config/monkey/history (respecting XDG_DATA_HOME), creating it if it does not exist.

func (*History) Add

func (h *History) Add(entry string)

Add appends an entry to the history and persists it to disk. Blank entries and consecutive duplicates are ignored.

func (*History) Down

func (h *History) Down() string

Down moves to the next (newer) entry, returning the saved draft when the end is reached.

func (*History) Up

func (h *History) Up(currentInput string) string

Up moves to the previous (older) entry and returns the text to place in the input box. currentInput is saved as the draft the first time Up is pressed.

type Message

type Message struct {
	Role      string
	Content   string
	ToolName  string // set for Role=="tool" messages
	Timestamp time.Time
	Collapsed bool // for tool messages: true when long output is folded
}

Message represents a single message in the conversation

type Model

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

Model is the main bubbletea model for the TUI

func NewModel

func NewModel(client *api.Client) Model

NewModel creates a new TUI model with initialized components

func (*Model) AddMessage

func (m *Model) AddMessage(role, content string)

AddMessage appends a message to the conversation history (pointer receiver to mutate in place)

func (Model) CanSubmit

func (m Model) CanSubmit() bool

CanSubmit returns true when input is non-empty (trimmed) and not loading

func (*Model) ClearInput

func (m *Model) ClearInput()

ClearInput clears the input text (pointer receiver to mutate in place)

func (Model) GetAPIMessages

func (m Model) GetAPIMessages() []api.Message

GetAPIMessages returns the full API-layer message history (includes tool_use/tool_result).

func (Model) GetDimensions

func (m Model) GetDimensions() (int, int)

GetDimensions returns the current width and height

func (Model) GetHistory

func (m Model) GetHistory() []Message

GetHistory returns the conversation history

func (Model) GetInput

func (m Model) GetInput() string

GetInput returns the current input text

func (Model) GetViewportHeight

func (m Model) GetViewportHeight() int

GetViewportHeight returns the current viewport height (for testing).

func (Model) Init

func (m Model) Init() tea.Cmd

Init implements tea.Model

func (Model) IsApeMode

func (m Model) IsApeMode() bool

IsApeMode reports whether tool approval is disabled.

func (Model) IsLoading

func (m Model) IsLoading() bool

IsLoading returns whether the model is in loading state

func (Model) IsTimerRunning

func (m Model) IsTimerRunning() bool

IsTimerRunning returns whether the elapsed timer is active

func (*Model) RestoreSession

func (m *Model) RestoreSession(sess *SessionData)

RestoreSession loads a saved SessionData into the model.

func (*Model) SetDimensions

func (m *Model) SetDimensions(width, height int)

SetDimensions sets the viewport and textarea dimensions (pointer receiver to mutate in place)

func (*Model) SetInput

func (m *Model) SetInput(text string)

SetInput sets the input text (pointer receiver to mutate in place)

func (*Model) SetIntro

func (m *Model) SetIntro(intro string)

SetIntro sets the intro content (ASCII art + version) shown on startup before any messages.

func (*Model) SetIntroTitle

func (m *Model) SetIntroTitle(title string)

SetIntroTitle sets the title displayed in the intro block's border.

func (*Model) SetIntroVersion

func (m *Model) SetIntroVersion(version string)

SetIntroVersion sets the version string displayed next to the title in the intro block's border.

func (*Model) SetLoading

func (m *Model) SetLoading(loading bool)

SetLoading sets the loading state (pointer receiver to mutate in place)

func (*Model) SetModels

func (m *Model) SetModels(models []string)

SetModels sets the available models shown in the /model picker.

func (*Model) SetTimerActive

func (m *Model) SetTimerActive(v bool)

SetTimerActive sets the timer active state and records the start time when activating

func (Model) Update

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

Update implements tea.Model

func (Model) View

func (m Model) View() string

View implements tea.Model

type ModelPicker

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

ModelPicker is a keyboard-navigable list for switching the active model.

func NewModelPicker

func NewModelPicker(width int) ModelPicker

NewModelPicker returns an inactive model picker.

func (*ModelPicker) Activate

func (mp *ModelPicker) Activate()

Activate makes the picker visible.

func (*ModelPicker) Deactivate

func (mp *ModelPicker) Deactivate()

Deactivate hides the picker.

func (ModelPicker) Height

func (mp ModelPicker) Height() int

Height returns the number of terminal rows occupied by the picker without rendering it. Returns 0 when inactive. Used by syncViewportHeight to avoid a full View() render just to count lines.

func (ModelPicker) IsActive

func (mp ModelPicker) IsActive() bool

IsActive reports whether the picker is visible.

func (ModelPicker) SelectedModel

func (mp ModelPicker) SelectedModel() string

SelectedModel returns the model under the cursor, or "" when inactive or empty.

func (*ModelPicker) SetCursor

func (mp *ModelPicker) SetCursor(model string)

SetCursor positions the cursor on the given model value (0 if not found).

func (*ModelPicker) SetModels

func (mp *ModelPicker) SetModels(models []string)

SetModels sets the available model values.

func (*ModelPicker) SetWidth

func (mp *ModelPicker) SetWidth(w int)

SetWidth updates the display width.

func (ModelPicker) Update

func (mp ModelPicker) Update(msg tea.Msg) (ModelPicker, tea.Cmd)

Update handles Up/Down cursor navigation.

func (ModelPicker) View

func (mp ModelPicker) View() string

View renders the model picker dropdown. Returns "" when inactive.

type PartialResponseMsg

type PartialResponseMsg struct {
	Token string
}

PartialResponseMsg carries a single streamed text token from the assistant.

type PromptCancelledMsg

type PromptCancelledMsg struct{}

PromptCancelledMsg is returned when the in-flight request is cancelled by the user

type PromptErrorMsg

type PromptErrorMsg struct {
	Err error
}

PromptErrorMsg is returned when the API returns an error

type PromptResponseMsg

type PromptResponseMsg struct {
	Response    string
	APIMessages []api.Message // full accumulated history including tool_use/tool_result
	Usage       api.Usage     // token counts for this turn
}

PromptResponseMsg is returned when the API responds successfully

type RetryingMsg

type RetryingMsg struct {
	Attempt int
	Err     error
}

RetryingMsg is sent to the model when the API client is about to retry a failed request.

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

SearchBar provides incremental search over conversation messages. Ctrl+F activates it; Ctrl+N / Ctrl+P cycle matches; Esc dismisses.

func NewSearchBar

func NewSearchBar() SearchBar

NewSearchBar returns an inactive SearchBar.

func (*SearchBar) Activate

func (s *SearchBar) Activate()

Activate makes the search bar visible.

func (SearchBar) CurrentMatchIndex

func (s SearchBar) CurrentMatchIndex() int

CurrentMatchIndex returns the message index of the current match, or -1 when there are no matches.

func (*SearchBar) Deactivate

func (s *SearchBar) Deactivate()

Deactivate hides the search bar and clears state.

func (SearchBar) IsActive

func (s SearchBar) IsActive() bool

IsActive reports whether the search bar is visible.

func (SearchBar) IsMatch

func (s SearchBar) IsMatch(i int) bool

IsMatch reports whether message index i is one of the current matches.

func (SearchBar) MatchCount

func (s SearchBar) MatchCount() int

MatchCount returns the number of matching messages.

func (*SearchBar) NextMatch

func (s *SearchBar) NextMatch()

NextMatch advances the cursor to the next match, wrapping around.

func (*SearchBar) PrevMatch

func (s *SearchBar) PrevMatch()

PrevMatch retreats the cursor to the previous match, wrapping around.

func (SearchBar) Query

func (s SearchBar) Query() string

Query returns the current search string.

func (*SearchBar) SetQuery

func (s *SearchBar) SetQuery(q string, messages []Message)

SetQuery updates the search query and recomputes matches from messages. An empty query clears all matches.

type SessionData

type SessionData struct {
	Model       string        `json:"model"`
	APIMessages []api.Message `json:"api_messages"`
	Messages    []Message     `json:"messages"`
}

SessionData is the persisted state for --continue.

func LoadSession

func LoadSession(path string) (*SessionData, error)

LoadSession reads the session file at path and returns the decoded SessionData. Returns (nil, nil) when the file does not exist.

type SlashCommand

type SlashCommand struct {
	Name string // without leading slash, e.g. "exit"
	Desc string
}

SlashCommand represents a supported slash command.

type State

type State int

State represents the current UI state

const (
	StateReady State = iota
	StateLoading
)

type ToolApprovalDialog

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

ToolApprovalDialog is a Yes/No prompt shown when the model wants to run a tool.

func NewToolApprovalDialog

func NewToolApprovalDialog(width int) ToolApprovalDialog

NewToolApprovalDialog returns an inactive approval dialog.

func (*ToolApprovalDialog) Activate

func (d *ToolApprovalDialog) Activate(modelName, toolName, previewText string, responseCh chan<- bool)

Activate shows the dialog for the given model/tool pair with a response channel. previewText is optional additional content shown above the Yes/No prompt (e.g. a diff). The cursor is reset to Yes on each activation.

func (*ToolApprovalDialog) Confirm

func (d *ToolApprovalDialog) Confirm()

Confirm sends the user's decision on responseCh and deactivates the dialog. If the cursor is on "No", sets the denied state so DeniedView can render.

func (*ToolApprovalDialog) Deactivate

func (d *ToolApprovalDialog) Deactivate()

Deactivate hides the dialog and clears the response channel.

func (ToolApprovalDialog) DeniedHeight

func (d ToolApprovalDialog) DeniedHeight() int

DeniedHeight returns the cached row count of DeniedView(). Returns 0 when not in the denied state. The value is computed once in Confirm() when the user selects "No".

func (ToolApprovalDialog) DeniedView

func (d ToolApprovalDialog) DeniedView() string

DeniedView renders a grayed-out version of the dialog after the user cancels a tool. Returns "" when not in the denied state.

func (*ToolApprovalDialog) Deny

func (d *ToolApprovalDialog) Deny()

Deny sends false on responseCh (non-blocking) and deactivates the dialog. Used for cancellation paths where the executor may have already timed out.

func (ToolApprovalDialog) Height

func (d ToolApprovalDialog) Height() int

Height returns the cached row count of View(). Returns 0 when inactive. The value is computed once in Activate() to avoid re-rendering on every syncViewportHeight call.

func (ToolApprovalDialog) IsActive

func (d ToolApprovalDialog) IsActive() bool

IsActive reports whether the dialog is visible.

func (ToolApprovalDialog) IsApproved

func (d ToolApprovalDialog) IsApproved() bool

IsApproved reports whether the cursor is on "Yes".

func (ToolApprovalDialog) IsDenied

func (d ToolApprovalDialog) IsDenied() bool

IsDenied reports whether the user explicitly selected "No" to cancel the tool.

func (*ToolApprovalDialog) SetWidth

func (d *ToolApprovalDialog) SetWidth(w int)

SetWidth updates the display width.

func (ToolApprovalDialog) Update

Update handles Up/Down cursor navigation.

func (ToolApprovalDialog) View

func (d ToolApprovalDialog) View() string

View renders the approval dialog. Returns "" when inactive.

type ToolApprovalRequestMsg

type ToolApprovalRequestMsg struct {
	ModelName  string
	ToolName   string
	Input      map[string]any
	ResponseCh chan<- bool
}

ToolApprovalRequestMsg is sent when the model wants to execute a tool and needs user approval.

type ToolCallMsg

type ToolCallMsg struct {
	ToolCall api.ToolCallResult
}

ToolCallMsg is sent to the model as each tool call completes during the API loop.

Jump to

Keyboard shortcuts

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