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 ¶
- func ColorEnabled() bool
- func FirstSentence(text string) string
- func ToolEmoji(name string) string
- func ToolPreview(name, args string) string
- type Event
- type Renderer
- func (r *Renderer) ContextTrimmed(mode string, count int)
- func (r *Renderer) Error(err error)
- func (r *Renderer) FinalAnswer(text string)
- func (r *Renderer) Iteration(n, maxN int, latency time.Duration, inTokens, outTokens int, turn int)
- func (r *Renderer) MemoryConsolidated(target string, before, after int)
- func (r *Renderer) MemoryEpisode(action, detail string)
- func (r *Renderer) MemoryFact(action, target, content string)
- func (r *Renderer) NarratorMessage(msg string)
- func (r *Renderer) SkillAutoLoaded(names []string)
- func (r *Renderer) SkillDeleted(name string)
- func (r *Renderer) SkillLoaded(names []string)
- func (r *Renderer) SkillSaved(name string)
- func (r *Renderer) SkillSuggested(name, heuristic string)
- func (r *Renderer) Start(task string)
- func (r *Renderer) Summary(inTokens, outTokens, cacheCreate, cacheRead, cached int)
- func (r *Renderer) Thinking(text string)
- func (r *Renderer) ToolCall(name, args string)
- func (r *Renderer) ToolRecovery(tool, detail string)
- func (r *Renderer) ToolResult(output string)
- func (r *Renderer) WithMemoryVerbose(verbose bool) *Renderer
- func (r *Renderer) WithModel(name string) *Renderer
- func (r *Renderer) WithSkillVerbose(verbose bool) *Renderer
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.
func FirstSentence ¶
FirstSentence extracts the first sentence from reasoning/thinking text. Returns a user-facing preview under 20 words. Falls back to truncation if no sentence boundary is found. Returns empty string for empty input. Handles standard punctuation (. ! ?) followed by space or newline, and also handles ellipsis (...) and end-of-input as boundaries.
func ToolEmoji ¶
toolEmoji returns an emoji that visually signals the tool category. Each tool gets an icon matching its domain so users can scan tool traces at a glance without reading every label. ToolEmoji returns an emoji for the given tool name based on its category. Exported so non-renderer consumers (e.g., Telegram bot) can use the same mapping.
func ToolPreview ¶
ToolPreview extracts a meaningful short preview from a tool call's JSON args. Returns a human-readable snippet like "main.go" for read_file, or "go test ./..." for shell. Falls back to a truncated command description.
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 )
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 ¶
New creates a Renderer that writes to w. If color is false, ANSI escape codes are stripped from the output.
func (*Renderer) ContextTrimmed ¶ added in v1.2.0
ContextTrimmed reports that the engine dropped message groups to stay within the model's context window. mode is "proactive" (pre-call budget trim) or "survival" (post-error nuclear trim).
func (*Renderer) FinalAnswer ¶
FinalAnswer prints the model's concluding response with a checkmark emoji.
func (*Renderer) Iteration ¶
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) MemoryConsolidated ¶ added in v1.2.0
MemoryConsolidated prints a fact-consolidation notification (before → after).
func (*Renderer) MemoryEpisode ¶ added in v1.2.0
MemoryEpisode prints an episode-tier lifecycle notification. action is one of "stored", "deduped", "evicted", "promoted", "pending_review".
func (*Renderer) MemoryFact ¶ added in v1.2.0
MemoryFact prints a fact-tier lifecycle notification. action is one of "added", "merged", "replaced", "removed".
func (*Renderer) NarratorMessage ¶
NarratorMessage prints an engaging, human-friendly narration line. Used in "engaging" interaction mode instead of raw tool call output.
func (*Renderer) SkillAutoLoaded ¶
SkillAutoLoaded prints a notification about auto-loaded skills at startup.
func (*Renderer) SkillDeleted ¶
SkillDeleted prints confirmation of a deleted skill.
func (*Renderer) SkillLoaded ¶
SkillLoaded prints a notification about lazy-loaded skills.
func (*Renderer) SkillSaved ¶
SkillSaved prints confirmation of a saved skill.
func (*Renderer) SkillSuggested ¶
SkillSuggested prints a skill suggestion from the learning system.
func (*Renderer) Start ¶
Start is a no-op — session context is now shown via iteration headers and session banners (REPL). Kept for API compatibility.
func (*Renderer) Summary ¶
Summary prints a run summary line with total token and cache statistics. Emitted after the final answer when at least one stat is non-zero. Shows: total input/output tokens, cache creation/read/cached tokens. Uses plain text labels (no symbols) for cross-terminal compatibility.
func (*Renderer) ToolCall ¶
ToolCall prints a tool invocation with a category emoji, name, and compact args.
func (*Renderer) ToolRecovery ¶ added in v1.2.0
ToolRecovery reports that a repeatedly-failing tool triggered an automatic corrective hint so the model changes approach.
func (*Renderer) ToolResult ¶
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) WithMemoryVerbose ¶ added in v1.2.0
WithMemoryVerbose controls whether memory lifecycle notifications (fact add/merge/consolidate, episode store/dedup/evict/promote) and internal agent signals (context trim, tool-failure recovery) are shown. Disabled by default to keep the terminal scannable; enabled by verbose interaction mode.
func (*Renderer) WithSkillVerbose ¶
WithSkillVerbose controls whether skill lifecycle notifications (auto-load, save, suggest, delete) are shown. Disabled by default.