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) Render(width int) string
- func (a *AgentToolItem) SetResult(result string)
- func (a *AgentToolItem) SetStatus(s ToolStatus)
- func (a *AgentToolItem) UpdateNested(id string, item Item)
- type AssistantItem
- type BaseToolItem
- func (t *BaseToolItem) Height(width int) int
- func (t *BaseToolItem) ID() string
- func (t *BaseToolItem) Input() string
- func (t *BaseToolItem) Render(width int) string
- func (t *BaseToolItem) RenderBody(width int) string
- func (t *BaseToolItem) RenderParams() 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) 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.
func NewAgentToolItem ¶
func NewAgentToolItem(id, task string, status ToolStatus, styles Styles) *AgentToolItem
NewAgentToolItem creates a new agent tool item.
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) Render ¶
func (a *AgentToolItem) Render(width int) 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) 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) Render ¶
func (a *AssistantItem) Render(width int) string
func (*AssistantItem) SetFinished ¶
func (a *AssistantItem) SetFinished()
SetFinished marks the assistant as done streaming.
func (*AssistantItem) SetText ¶
func (a *AssistantItem) SetText(text string)
SetText updates the assistant content (for streaming).
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.
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 extracts display parameters from the tool input. Override in concrete types for better param extraction.
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 tool name.
type BashToolItem ¶
type BashToolItem struct {
BaseToolItem
// contains filtered or unexported fields
}
BashToolItem renders bash command execution.
func NewBashToolItem ¶
func NewBashToolItem(id, displayName, command string, status ToolStatus, styles Styles) *BashToolItem
func (*BashToolItem) Render ¶
func (t *BashToolItem) Render(width int) string
func (*BashToolItem) RenderBody ¶
func (t *BashToolItem) RenderBody(width int) string
RenderBody uses BashBody style for command output.
func (*BashToolItem) RenderParams ¶
func (t *BashToolItem) RenderParams() string
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
// contains filtered or unexported fields
}
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)
func (*CmdToolItem) Render ¶
func (t *CmdToolItem) Render(width int) string
func (*CmdToolItem) RenderBody ¶
func (t *CmdToolItem) RenderBody(width int) string
RenderBody uses BashBody style for command output.
func (*CmdToolItem) RenderParams ¶
func (t *CmdToolItem) RenderParams() string
type FileToolItem ¶
type FileToolItem struct {
BaseToolItem
// contains filtered or unexported fields
}
FileToolItem renders file read/write/edit operations.
func NewFileToolItem ¶
func NewFileToolItem(id, displayName, filePath string, status ToolStatus, styles Styles) *FileToolItem
NewFileToolItem creates a new file operation tool item.
func (*FileToolItem) Render ¶
func (t *FileToolItem) Render(width int) string
func (*FileToolItem) RenderParams ¶
func (t *FileToolItem) RenderParams() string
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
// contains filtered or unexported fields
}
GitToolItem renders git operations with command-output body.
func (*GitToolItem) Render ¶
func (t *GitToolItem) Render(width int) string
func (*GitToolItem) RenderBody ¶
func (t *GitToolItem) RenderBody(width int) string
RenderBody uses BashBody style for git output (same dark background).
func (*GitToolItem) RenderParams ¶
func (t *GitToolItem) RenderParams() string
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) 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
// contains filtered or unexported fields
}
ListToolItem renders directory listing operations.
func (*ListToolItem) Render ¶
func (t *ListToolItem) Render(width int) string
func (*ListToolItem) RenderParams ¶
func (t *ListToolItem) RenderParams() string
type LspToolItem ¶
type LspToolItem struct {
BaseToolItem
// contains filtered or unexported fields
}
LspToolItem renders LSP operations (hover, definition, references, etc.)
func (*LspToolItem) Render ¶
func (t *LspToolItem) Render(width int) string
func (*LspToolItem) RenderParams ¶
func (t *LspToolItem) RenderParams() string
type SearchToolItem ¶
type SearchToolItem struct {
BaseToolItem
// contains filtered or unexported fields
}
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.
func (*SearchToolItem) Render ¶
func (t *SearchToolItem) Render(width int) string
func (*SearchToolItem) RenderParams ¶
func (t *SearchToolItem) RenderParams() string
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
// 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 ¶
ToolHeader builds the standard tool header line: "✓ ToolName params..." Params are joined and truncated to fit within width.
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) 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
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)
}
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
// contains filtered or unexported fields
}
WebToolItem renders web fetch/search operations.
func (*WebToolItem) Render ¶
func (t *WebToolItem) Render(width int) string
func (*WebToolItem) RenderParams ¶
func (t *WebToolItem) RenderParams() string