Documentation
¶
Index ¶
- Constants
- func FormatBody(content string, width int, maxLines int) (string, bool)
- func FormatJSONResult(raw string) string
- func PrettifyToolName(name string) string
- type AgentToolItem
- func (a *AgentToolItem) AppendNested(item Item)
- func (a *AgentToolItem) Height(width int) int
- func (a *AgentToolItem) ID() string
- func (a *AgentToolItem) Label() string
- func (a *AgentToolItem) Render(width int) string
- func (a *AgentToolItem) Result() string
- func (a *AgentToolItem) SetResult(result string)
- func (a *AgentToolItem) SetStatus(s ToolStatus)
- func (a *AgentToolItem) Status() ToolStatus
- func (a *AgentToolItem) UpdateNested(id string, item Item)
- type AssistantItem
- func (a *AssistantItem) Height(width int) int
- func (a *AssistantItem) ID() string
- func (a *AssistantItem) Reasoning() string
- func (a *AssistantItem) Render(width int) string
- func (a *AssistantItem) SetFinished()
- func (a *AssistantItem) SetReasoning(text string)
- func (a *AssistantItem) SetReasoningFinished()
- func (a *AssistantItem) SetText(text string)
- func (a *AssistantItem) Text() string
- type BaseToolItem
- func (t *BaseToolItem) Height(width int) int
- func (t *BaseToolItem) ID() string
- func (t *BaseToolItem) Input() string
- func (t *BaseToolItem) IsError() bool
- func (t *BaseToolItem) Render(width int) string
- func (t *BaseToolItem) RenderBody(width int) string
- func (t *BaseToolItem) RenderParams() string
- func (t *BaseToolItem) Result() string
- func (t *BaseToolItem) SetResult(result string, isError bool)
- func (t *BaseToolItem) SetStatus(s ToolStatus)
- func (t *BaseToolItem) Status() ToolStatus
- func (t *BaseToolItem) ToolName() string
- type BashToolItem
- type CachedItem
- type CmdToolItem
- type FileToolItem
- type GenericToolItem
- type GitToolItem
- type Item
- type List
- func (l *List) Append(items ...Item)
- func (l *List) AtBottom() bool
- func (l *List) FindByID(id string) Item
- func (l *List) Follow() bool
- func (l *List) Height() int
- func (l *List) ItemAt(idx int) Item
- func (l *List) Len() int
- func (l *List) RemoveByID(id string)
- func (l *List) Render() string
- func (l *List) ScrollDown(n int)
- func (l *List) ScrollToEnd()
- func (l *List) ScrollUp(n int)
- func (l *List) SetFollow(f bool)
- func (l *List) SetItems(items []Item)
- func (l *List) SetSize(width, height int)
- func (l *List) UpdateItem(id string, item Item)
- func (l *List) YOffset() int
- type ListToolItem
- type LspToolItem
- type SearchToolItem
- type SpacerItem
- type Styles
- type SystemItem
- type TodoTask
- type TodoToolItem
- type ToolBodyBehavior
- type ToolContext
- type ToolStatus
- type UserItem
- type WebToolItem
Constants ¶
const ToolBodyMaxLines = 10
ToolBodyMaxLines is the maximum number of body lines shown before truncation.
Variables ¶
This section is empty.
Functions ¶
func FormatBody ¶
FormatBody renders tool body content with optional truncation. For long output, shows the last maxLines lines (users care about the end). Returns the formatted body and whether it was truncated.
func FormatJSONResult ¶
FormatJSONResult parses a JSON string and renders it as human-readable key-value pairs.
func PrettifyToolName ¶
PrettifyToolName converts internal tool names to display names. e.g. "run_command" → "Bash", "read_file" → "Read", "search_files" → "Grep"
Types ¶
type AgentToolItem ¶
type AgentToolItem struct {
CachedItem
// contains filtered or unexported fields
}
AgentToolItem renders a subagent with nested tool calls. AgentToolItem displays a sub-agent's lifecycle in the main chat. The label field holds the sub-agent's name (from description param).
func NewAgentToolItem ¶
func NewAgentToolItem(id, label string, status ToolStatus, styles Styles) *AgentToolItem
NewAgentToolItem creates a new agent tool item. The label parameter is the sub-agent name shown in the header.
func (*AgentToolItem) AppendNested ¶
func (a *AgentToolItem) AppendNested(item Item)
AppendNested adds a nested tool item.
func (*AgentToolItem) Height ¶
func (a *AgentToolItem) Height(width int) int
func (*AgentToolItem) ID ¶
func (a *AgentToolItem) ID() string
func (*AgentToolItem) Label ¶ added in v1.3.22
func (a *AgentToolItem) Label() string
func (*AgentToolItem) Render ¶
func (a *AgentToolItem) Render(width int) string
func (*AgentToolItem) Result ¶ added in v1.3.22
func (a *AgentToolItem) Result() string
func (*AgentToolItem) SetResult ¶
func (a *AgentToolItem) SetResult(result string)
SetResult updates the agent result.
func (*AgentToolItem) SetStatus ¶
func (a *AgentToolItem) SetStatus(s ToolStatus)
SetStatus updates the agent status.
func (*AgentToolItem) Status ¶ added in v1.3.22
func (a *AgentToolItem) Status() ToolStatus
func (*AgentToolItem) UpdateNested ¶
func (a *AgentToolItem) UpdateNested(id string, item Item)
UpdateNested updates a nested item by ID.
type AssistantItem ¶
type AssistantItem struct {
CachedItem
// contains filtered or unexported fields
}
AssistantItem renders an assistant message (supports streaming).
func NewAssistantItem ¶
func NewAssistantItem(id string, styles Styles) *AssistantItem
NewAssistantItem creates a new assistant message item.
func (*AssistantItem) Height ¶
func (a *AssistantItem) Height(width int) int
func (*AssistantItem) ID ¶
func (a *AssistantItem) ID() string
func (*AssistantItem) Reasoning ¶ added in v1.3.7
func (a *AssistantItem) Reasoning() string
Reasoning returns the current reasoning content.
func (*AssistantItem) Render ¶
func (a *AssistantItem) Render(width int) string
func (*AssistantItem) SetFinished ¶
func (a *AssistantItem) SetFinished()
SetFinished marks the assistant as done streaming.
func (*AssistantItem) SetReasoning ¶ added in v1.3.7
func (a *AssistantItem) SetReasoning(text string)
SetReasoning updates the reasoning/thinking content.
func (*AssistantItem) SetReasoningFinished ¶ added in v1.3.7
func (a *AssistantItem) SetReasoningFinished()
SetReasoningFinished collapses reasoning into a one-line summary.
func (*AssistantItem) SetText ¶
func (a *AssistantItem) SetText(text string)
SetText updates the assistant content (for streaming).
func (*AssistantItem) Text ¶ added in v1.3.22
func (a *AssistantItem) Text() string
type BaseToolItem ¶
type BaseToolItem struct {
CachedItem
// contains filtered or unexported fields
}
BaseToolItem provides shared rendering logic for all tool items. Concrete tool types embed this and override RenderBody/RenderParams.
func NewBaseToolItem ¶
func NewBaseToolItem(id, toolName string, status ToolStatus, input string, styles Styles) *BaseToolItem
NewBaseToolItem creates a base tool item.
func (*BaseToolItem) Height ¶
func (t *BaseToolItem) Height(width int) int
func (*BaseToolItem) ID ¶
func (t *BaseToolItem) ID() string
func (*BaseToolItem) Input ¶
func (t *BaseToolItem) Input() string
Input returns the raw input JSON when available, otherwise the display detail.
func (*BaseToolItem) IsError ¶ added in v1.3.22
func (t *BaseToolItem) IsError() bool
IsError reports whether the current result is an error.
func (*BaseToolItem) Render ¶
func (t *BaseToolItem) Render(width int) string
Render produces the full tool output: header + optional body. This is the base implementation. Concrete types should call renderCore with their own params/body overrides.
func (*BaseToolItem) RenderBody ¶
func (t *BaseToolItem) RenderBody(width int) string
RenderBody renders the tool output body. Override in concrete types for specialized body rendering.
func (*BaseToolItem) RenderParams ¶
func (t *BaseToolItem) RenderParams() string
RenderParams returns the display parameters for the tool header.
func (*BaseToolItem) Result ¶ added in v1.3.22
func (t *BaseToolItem) Result() string
Result returns the current rendered tool result body.
func (*BaseToolItem) SetResult ¶
func (t *BaseToolItem) SetResult(result string, isError bool)
SetResult updates the tool result and invalidates cache.
func (*BaseToolItem) SetStatus ¶
func (t *BaseToolItem) SetStatus(s ToolStatus)
SetStatus updates the tool status and invalidates cache.
func (*BaseToolItem) Status ¶
func (t *BaseToolItem) Status() ToolStatus
Status returns the current tool status.
func (*BaseToolItem) ToolName ¶
func (t *BaseToolItem) ToolName() string
ToolName returns the original tool name when available.
type BashToolItem ¶
type BashToolItem struct {
BaseToolItem
}
BashToolItem renders bash command execution. BashToolItem renders bash command execution.
func NewBashToolItem ¶
func NewBashToolItem(id, displayName, command string, status ToolStatus, styles Styles) *BashToolItem
type CachedItem ¶
type CachedItem struct {
// contains filtered or unexported fields
}
CachedItem provides common caching for items whose rendering is expensive. Embed in concrete item types and call GetCached/SetCached/Invalidate.
func (*CachedItem) GetCached ¶
func (c *CachedItem) GetCached(width int) (string, int, bool)
GetCached returns the cached render and height if the width matches. Returns ("", 0, false) on cache miss.
func (*CachedItem) Invalidate ¶
func (c *CachedItem) Invalidate()
Invalidate clears the cache, forcing re-render on next access.
func (*CachedItem) SetCached ¶
func (c *CachedItem) SetCached(rendered string, width, height int)
SetCached stores the rendered output and its height.
type CmdToolItem ¶
type CmdToolItem struct {
BaseToolItem
}
CmdToolItem renders background command lifecycle operations. The detail string comes pre-formatted from describeTool, e.g.:
- start_command: "go build ./..."
- write_command_input: "[abc12345] → y\n" (input text, most important)
- read_command_output: "abc12345"
- wait_command: "abc12345 (30s)"
- stop_command: "abc12345"
- list_commands: "" (no params)
type FileToolItem ¶
type FileToolItem struct {
BaseToolItem
}
FileToolItem renders file read/write/edit operations.
func NewFileToolItem ¶
func NewFileToolItem(id, displayName, filePath string, status ToolStatus, styles Styles, lang string, rawArgs string, toolName string) *FileToolItem
NewFileToolItem creates a new file operation tool item.
type GenericToolItem ¶
type GenericToolItem struct {
BaseToolItem
}
GenericToolItem is a fallback for unrecognized tools.
func NewGenericToolItem ¶
func NewGenericToolItem(id, displayName string, status ToolStatus, detail string, styles Styles) *GenericToolItem
NewGenericToolItem creates a generic tool item.
func NewMarkdownToolItem ¶
func NewMarkdownToolItem(id, displayName string, status ToolStatus, detail string, styles Styles) *GenericToolItem
NewMarkdownToolItem creates a tool item that renders its result as markdown.
type GitToolItem ¶
type GitToolItem struct {
BaseToolItem
}
GitToolItem renders git operations with command-output body.
type Item ¶
type Item interface {
// Render produces the ANSI-styled string for this item at the given width.
Render(width int) string
// ID returns a unique identifier for deduplication and scroll targeting.
ID() string
// Height returns the number of visual lines this item occupies at the given width.
// Used by the virtual list to compute scroll positions without full rendering.
Height(width int) int
}
Item is the core interface for any renderable element in the conversation.
func NewToolItem ¶
func NewToolItem(id string, ctx ToolContext, status ToolStatus, styles Styles) Item
NewToolItem creates the appropriate tool item type based on the ToolContext. The caller (chatStartTool) is responsible for filling Detail from describeTool; NewToolItem uses it directly instead of re-parsing RawArgs.
type List ¶
type List struct {
// contains filtered or unexported fields
}
List is a virtual-scrolling list of Items. Only items visible in the current viewport are rendered.
func (*List) RemoveByID ¶ added in v1.1.90
RemoveByID removes an item by ID. No-op if not found.
func (*List) Render ¶
Render produces the visible portion of the list as a single string. Only items within the viewport are rendered. When follow is active, scroll position is re-synced automatically.
func (*List) ScrollDown ¶
ScrollDown scrolls the viewport by n lines.
func (*List) ScrollToEnd ¶
func (l *List) ScrollToEnd()
ScrollToEnd scrolls to the very bottom and re-enables follow.
func (*List) UpdateItem ¶
UpdateItem replaces the item with the given ID.
type ListToolItem ¶
type ListToolItem struct {
BaseToolItem
}
ListToolItem renders directory listing operations.
type LspToolItem ¶
type LspToolItem struct {
BaseToolItem
}
LspToolItem renders LSP operations (hover, definition, references, etc.)
type SearchToolItem ¶
type SearchToolItem struct {
BaseToolItem
}
SearchToolItem renders grep/glob/ls operations.
func NewSearchToolItem ¶
func NewSearchToolItem(id, displayName, pattern string, status ToolStatus, styles Styles) *SearchToolItem
NewSearchToolItem creates a new search tool item.
type SpacerItem ¶
type SpacerItem struct {
// contains filtered or unexported fields
}
SpacerItem adds vertical space between message groups.
func NewSpacerItem ¶
func NewSpacerItem(height int) *SpacerItem
NewSpacerItem creates a spacer with the given height in lines.
func (*SpacerItem) Height ¶
func (s *SpacerItem) Height(width int) int
func (*SpacerItem) ID ¶
func (s *SpacerItem) ID() string
func (*SpacerItem) Render ¶
func (s *SpacerItem) Render(width int) string
type Styles ¶
type Styles struct {
// User message
UserPrefix string
UserIcon string
UserStyle lipgloss.Style
// Assistant message
AssistantPrefix string
AssistantIcon string
AssistantStyle lipgloss.Style
// Tool name rendering
ToolName lipgloss.Style
// Tool body
ToolBody lipgloss.Style
BashBody lipgloss.Style // command output with subtle background
// System message
SystemPrefix string
SystemStyle lipgloss.Style
// Reasoning / thinking
ReasoningPrefix string
ReasoningStyle lipgloss.Style
// Error
ErrorStyle lipgloss.Style
// Muted
MutedStyle lipgloss.Style
// Spacing
ItemGap int // lines between items
}
Styles holds all rendering styles for the chat package.
func (Styles) ToolHeader ¶
func (Styles) ToolIcon ¶
func (s Styles) ToolIcon(status ToolStatus) string
ToolIcon returns the icon for a given tool status.
func (Styles) ToolIconStyle ¶
func (s Styles) ToolIconStyle(status ToolStatus) string
ToolIconStyle returns a styled icon for the given tool status.
type SystemItem ¶
type SystemItem struct {
CachedItem
// contains filtered or unexported fields
}
SystemItem renders a system/status/info message.
func NewSystemItem ¶
func NewSystemItem(id, text string, styles Styles) *SystemItem
NewSystemItem creates a new system message item.
func (*SystemItem) AppendText ¶ added in v1.2.7
func (s *SystemItem) AppendText(text string)
func (*SystemItem) Height ¶
func (s *SystemItem) Height(width int) int
func (*SystemItem) ID ¶
func (s *SystemItem) ID() string
func (*SystemItem) Render ¶
func (s *SystemItem) Render(width int) string
func (*SystemItem) SetText ¶ added in v1.2.7
func (s *SystemItem) SetText(text string)
func (*SystemItem) Text ¶ added in v1.3.22
func (s *SystemItem) Text() string
type TodoToolItem ¶
type TodoToolItem struct {
CachedItem
// contains filtered or unexported fields
}
TodoToolItem renders a todo/task list.
func NewTodoToolItem ¶
func NewTodoToolItem(id string, tasks []TodoTask, styles Styles, lang string) *TodoToolItem
NewTodoToolItem creates a new todo list tool item.
func (*TodoToolItem) Height ¶
func (t *TodoToolItem) Height(width int) int
func (*TodoToolItem) ID ¶
func (t *TodoToolItem) ID() string
func (*TodoToolItem) Render ¶
func (t *TodoToolItem) Render(width int) string
func (*TodoToolItem) SetTasks ¶
func (t *TodoToolItem) SetTasks(tasks []TodoTask)
SetTasks updates the task list.
type ToolBodyBehavior ¶
type ToolBodyBehavior int
NewBashToolItem creates a new bash tool item. ToolBodyBehavior describes how a tool's result body should be rendered.
const ( BodyDefault ToolBodyBehavior = iota // show result as-is (truncated) BodySuppress // hide body entirely BodyFormatJSON // parse JSON and render as key-value pairs BodyMarkdown // render result as markdown )
func GetToolBodyBehavior ¶
func GetToolBodyBehavior(toolName string) ToolBodyBehavior
GetToolBodyBehavior returns the body rendering behavior for a given tool name.
type ToolContext ¶
type ToolContext struct {
ToolName string // original tool name, e.g. "run_command"
DisplayName string // prettified name, e.g. "Bash"
Detail string // extracted detail, e.g. "go build ./..."
RawArgs string // raw JSON input (for body rendering / fallback)
Lang string // language code, e.g. "zh-CN", "en"
}
ToolContext carries pre-resolved display information from the caller (typically describeTool in the TUI layer). It is the primary data source for tool rendering — the caller is responsible for extracting the right detail from rawArgs, so NewToolItem no longer needs to do JSON parsing.
type ToolStatus ¶
type ToolStatus int
ToolStatus represents the current state of a tool call.
const ( StatusPending ToolStatus = iota StatusRunning StatusSuccess StatusError StatusCanceled )
func (ToolStatus) String ¶
func (s ToolStatus) String() string
String returns a human-readable status name.
type UserItem ¶
type UserItem struct {
CachedItem
// contains filtered or unexported fields
}
UserItem renders a user message with a prefix icon.
func NewUserItem ¶
NewUserItem creates a new user message item.
type WebToolItem ¶
type WebToolItem struct {
BaseToolItem
}
WebToolItem renders web fetch/search operations.