toolcommon

package
v1.88.1 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const EffortGaugeCells = 6

EffortGaugeCells is the fixed cell width of the effort gauge. The six cells map one-to-one onto the six selectable effort levels, so the gauge is lossless: the filled-cell count alone identifies the level, and the color ramp is a secondary cue.

View Source
const LongRunningThreshold = 60 * time.Second

LongRunningThreshold is the duration after which a running tool call displays a warning hint that it may be blocked on external input.

Variables

This section is empty.

Functions

func EffortFillStyle added in v1.88.0

func EffortFillStyle(level effort.Level) lipgloss.Style

EffortFillStyle returns the foreground style for a level's filled cells: a low-to-high ramp (muted → accent → highlight → success → warning) kept as a secondary cue on top of the now-lossless cell count. Colors come from the active theme so the gauge stays theme-aware.

func EffortGauge added in v1.88.0

func EffortGauge(level effort.Level) string

EffortGauge renders the fixed-width six-cell gauge for an effort level: the filled cells take the level's ramp color, the rest are faint. The width is constant across levels so the badge column stays aligned wherever the gauge is shown (roster rows, focus card, agent-details dialog).

func EffortGaugeEmpty added in v1.88.0

func EffortGaugeEmpty() string

EffortGaugeEmpty renders a fully empty, faint six-cell gauge. It marks a model that is capable of thinking but has it switched off ("off"), reading as "capable but disabled" — distinct from a non-capable model, which shows no gauge at all.

func ExtractField

func ExtractField[T any](field func(T) string) func(string) string

ExtractField creates an argument extractor function that parses JSON and extracts a field. The field function receives the parsed args and returns the display string. It supports partial JSON parsing for streaming tool calls.

func FormatTokenCount added in v1.88.0

func FormatTokenCount(count int64) string

FormatTokenCount formats a token count with K/M suffixes for readability (e.g. 8200 → "8.2K", 1500000 → "1.5M"). Values below 1000 are rendered verbatim. This is the canonical implementation shared by the sidebar and the cost/model dialogs.

func FormatToolResult

func FormatToolResult(content string, width int) string

func Icon

func Icon(msg *types.Message, inProgress spinner.Spinner) string

func LongRunningWarning added in v1.41.0

func LongRunningWarning(msg *types.Message) string

LongRunningWarning returns a warning string if the tool call has been running longer than LongRunningThreshold, or empty string otherwise.

func NoArgsRenderer added in v1.53.0

func NoArgsRenderer(msg *types.Message, s spinner.Spinner, sessionState service.SessionStateReader, width, _ int) string

NoArgsRenderer is a Renderer that displays only the tool name and status, without arguments or a result. Useful for tools whose arguments aren't worth surfacing in the UI (e.g. user_prompt, todo helpers).

func ParseArgs

func ParseArgs[T any](args string) (T, error)

ParseArgs unmarshals JSON arguments into a typed struct. Returns an error if parsing fails.

func Pluralize added in v1.53.0

func Pluralize(count int, singular, plural string) string

Pluralize formats a count with its singular or plural form, e.g. Pluralize(1, "file", "files") returns "1 file" while Pluralize(3, "file", "files") returns "3 files".

func RenderFriendlyHeader

func RenderFriendlyHeader(msg *types.Message, s spinner.Spinner) (string, bool)

RenderFriendlyHeader renders a friendly description header if present in the tool call arguments. Returns the rendered header string and true if a friendly description was found, empty string and false otherwise. Custom renderers can use this to show the friendly description before their custom content.

func RenderTool

func RenderTool(msg *types.Message, inProgress spinner.Spinner, args, result string, width int, hideToolResults bool) string

func ThinkingDescription added in v1.88.0

func ThinkingDescription(label string) string

ThinkingDescription returns a human-readable description of a model's thinking-effort wire label, shared by the sidebar focus card and the agent-details dialog so both speak the same vocabulary:

  • an effort level passes through verbatim (e.g. "high", "minimal")
  • "adaptive" stays "adaptive"
  • a decimal token budget becomes "<count> tokens" (e.g. "8.2K tokens")
  • "off" stays "off"
  • an empty label yields "" (the model has no thinking configuration)

func ThinkingGaugeValue added in v1.88.0

func ThinkingGaugeValue(label string) string

ThinkingGaugeValue renders the shared "<marker> <description>" thinking summary used by the sidebar focus card and the agent-details dialog: the effort gauge (or compact marker) followed by the human-readable description from ThinkingDescription. Returns "" when the label carries no thinking configuration. The "off" description is rendered faint to read as disabled.

func ThinkingMarker added in v1.88.0

func ThinkingMarker(label string) string

ThinkingMarker returns the compact visual marker for a thinking wire label, used in the gauge column of the focus card and the agent-details dialog:

  • an effort level → the six-cell effort gauge (colored)
  • "off" → a dim empty gauge
  • "adaptive" → the muted word "auto"
  • a token budget → the token glyph "◉"
  • an empty label → "" (no marker)

Unknown/future level words yield "" so the descriptive value still carries the meaning.

func TruncateText

func TruncateText(text string, maxWidth int) string

TruncateText truncates text to fit within maxWidth, adding an ellipsis if needed. Uses a forward-scanning approach for O(n) complexity instead of O(n²). Note: lipgloss.Width returns the maximum line width for multi-line strings.

func TruncateTextLeft added in v1.88.0

func TruncateTextLeft(text string, maxWidth int) string

TruncateTextLeft truncates text from the left to fit within maxWidth, keeping the tail and prepending an ellipsis when truncation occurs. It mirrors TruncateText's edge cases but is the keep-the-tail counterpart: useful for model identifiers where the informative suffix (e.g. "…sonnet-4-6") should survive. Wraps ansi.TruncateLeft so ANSI escape sequences and wide characters are handled correctly.

func WrapLines

func WrapLines(text string, width int) []string

WrapLines wraps text to fit within the given width. Each line that exceeds the width is split at rune boundaries.

func WrapLinesWords

func WrapLinesWords(text string, width int) []string

WrapLinesWords wraps text to fit within the given width, preferring to break at word boundaries (spaces). If a single word exceeds the width, it falls back to splitting at rune boundaries.

Types

type Base

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

Base provides common boilerplate for tool components. It handles spinner management, sizing, and delegates rendering to a custom function.

func NewBase

func NewBase(msg *types.Message, sessionState service.SessionStateReader, render Renderer) *Base

NewBase creates a new base tool component with the given renderer. Accepts SessionStateReader for read-only access (also accepts *SessionState which implements it).

func NewBaseWithCollapsed

func NewBaseWithCollapsed(msg *types.Message, sessionState service.SessionStateReader, render Renderer, collapsedRender CollapsedRenderer) *Base

NewBaseWithCollapsed creates a new base tool component with both regular and collapsed renderers. Accepts SessionStateReader for read-only access (also accepts *SessionState which implements it).

func (*Base) CollapsedView

func (b *Base) CollapsedView() string

CollapsedView returns a simplified view for use in collapsed reasoning blocks. Falls back to the regular View() if no collapsed renderer is provided.

func (*Base) ExpandedView added in v1.60.0

func (b *Base) ExpandedView() string

ExpandedView returns the regular, full tool renderer.

func (*Base) Init

func (b *Base) Init() tea.Cmd

func (*Base) SetSize

func (b *Base) SetSize(width, height int) tea.Cmd

func (*Base) StopAnimation

func (b *Base) StopAnimation()

StopAnimation stops the spinner animation and unregisters from the animation coordinator. This must be called when the view is removed from the UI to avoid leaked animation subscriptions.

func (*Base) Update

func (b *Base) Update(msg tea.Msg) (layout.Model, tea.Cmd)

func (*Base) View

func (b *Base) View() string

type CollapsedRenderer

type CollapsedRenderer func(msg *types.Message, s spinner.Spinner, sessionState service.SessionStateReader, width, height int) string

CollapsedRenderer is a function that renders a simplified view for collapsed reasoning blocks.

type Renderer

type Renderer func(msg *types.Message, s spinner.Spinner, sessionState service.SessionStateReader, width, height int) string

Renderer is a function that renders a tool call view. It receives the message, spinner, session state reader, and available width/height. Note: Uses SessionStateReader interface for read-only access to session state.

func SimpleRenderer

func SimpleRenderer(extractArg func(args string) string) Renderer

SimpleRenderer creates a renderer that extracts a single string argument and renders it with RenderTool. This covers the most common case where tools just display one argument (like path, command, etc.).

func SimpleRendererWithResult

func SimpleRendererWithResult(
	extractArg func(args string) string,
	extractResult func(msg *types.Message) string,
) Renderer

SimpleRendererWithResult creates a renderer that extracts a single string argument and also shows a result/summary after completion.

Jump to

Keyboard shortcuts

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