render

package
v0.16.5 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package render provides emoji-driven terminal rendering for the odek agent loop.

It produces structured output for each phase of the ReAct cycle: thinking, tool calls, tool results, and the final answer. When a Renderer is nil or disabled, no output is produced — this keeps the programmatic API silent and the CLI colorful.

Design

  • Zero dependencies. Uses ANSI escape codes directly.
  • Emoji icons as visual anchors (🧠 🔧 ✅ ❌).
  • Color detection: respects NO_COLOR env var and tty detection.
  • Truncation: tool output is collapsed to one line to keep the terminal scannable during multi-step tool chains.
  • Maintainable: each rendering method is self-contained; adding a new event type requires one constant + one method.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColorEnabled

func ColorEnabled() bool

ColorEnabled returns true when the terminal supports ANSI colors and the user hasn't set NO_COLOR.

Types

type Event

type Event int

Event identifies a point in the agent loop lifecycle. Programmatic consumers can type-switch on Event values.

const (
	// IterStart marks the beginning of an iteration cycle.
	IterStart Event = iota
	// Thinking is the model's reasoning text before tool calls.
	Thinking
	// ToolCall is a tool invocation requested by the model.
	ToolCall
	// ToolResult is the output from a completed tool call.
	ToolResult
	// FinalAnswer is the model's final response (no tool calls).
	FinalAnswer
	// Error is a non-fatal error during the loop.
	Error
)

func (Event) String

func (e Event) String() string

type Renderer

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

Renderer writes formatted agent loop output to an io.Writer. The zero value is usable but won't produce any output — call New() to create a properly initialized Renderer.

func New

func New(w io.Writer, color bool) *Renderer

New creates a Renderer that writes to w. If color is false, ANSI escape codes are stripped from the output.

func (*Renderer) Error

func (r *Renderer) Error(err error)

Error prints a non-fatal loop error with a cross emoji.

func (*Renderer) FinalAnswer

func (r *Renderer) FinalAnswer(text string)

FinalAnswer prints the model's concluding response with a checkmark emoji.

func (*Renderer) Iteration

func (r *Renderer) Iteration(n, maxN int, latency time.Duration, inTokens, outTokens int, turn int)

Iteration prints the cycle header with optional turn statistics and turn number. When turn > 0, shows "Turn N" in the header. When latency > 0 or tokens are reported, a compact stats suffix appears on the same line: [1,247 in · 342 out · 4.1s]

func (*Renderer) Start

func (r *Renderer) Start(task string)

Start prints the session header with task preview.

func (*Renderer) Thinking

func (r *Renderer) Thinking(text string)

Thinking prints the model's reasoning text with a brain emoji.

func (*Renderer) ToolCall

func (r *Renderer) ToolCall(name, args string)

ToolCall prints a tool invocation with wrench emoji, name, and compact args.

func (*Renderer) ToolResult

func (r *Renderer) ToolResult(output string)

ToolResult prints a one-line summary of the tool output in gray. Long output is collapsed to the first line + ellipsis to keep the terminal readable during multi-step tool chains.

func (*Renderer) WithModel

func (r *Renderer) WithModel(name string) *Renderer

WithModel sets the model name displayed in iteration headers.

Jump to

Keyboard shortcuts

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