tui

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package tui provides interactive terminal UI components for agk CLI.

Index

Constants

View Source
const (
	StatusUnset = "Unset"
	CtrlC       = "ctrl+c"
	KeyUp       = "up"
	KeyDown     = "down"
)

Variables

View Source
var (
	// BoxStyle is the main container style
	BoxStyle = lipgloss.NewStyle().
				Border(lipgloss.RoundedBorder()).
				BorderForeground(primaryColor).
				Padding(0, 1)

	// HeaderStyle for headers
	HeaderStyle = lipgloss.NewStyle().
				Bold(true).
				Foreground(primaryColor).
				Padding(0, 1)

	// TitleStyle for main titles
	TitleStyle = lipgloss.NewStyle().
				Bold(true).
				Foreground(lipgloss.Color("#FFFFFF")).
				Background(primaryColor).
				Padding(0, 2)

	// SectionHeaderStyle for detail view sections
	SectionHeaderStyle = lipgloss.NewStyle().
						Bold(true).
						Foreground(lipgloss.Color("#FFFFFF")).
						Background(secondaryColor).
						Padding(0, 1).
						Margin(1, 0, 0, 0)
)

Box styles

View Source
var (
	// SelectedStyle for selected items
	SelectedStyle = lipgloss.NewStyle().
					Bold(true).
					Foreground(lipgloss.Color("#FFFFFF")).
					Background(secondaryColor)

	// CursorStyle for the cursor indicator
	CursorStyle = lipgloss.NewStyle().
				Foreground(secondaryColor).
				Bold(true)

	// MutedStyle for less important text
	MutedStyle = lipgloss.NewStyle().
				Foreground(mutedColor)

	// SuccessStyle for success indicators
	SuccessStyle = lipgloss.NewStyle().
					Foreground(successColor)

	// ErrorStyle for error indicators
	ErrorStyle = lipgloss.NewStyle().
				Foreground(errorColor)

	// WarningStyle for warnings
	WarningStyle = lipgloss.NewStyle().
					Foreground(warningColor)

	// DurationStyle for duration values
	DurationStyle = lipgloss.NewStyle().
					Foreground(accentColor)

	// AttributeKeyStyle for attribute keys
	AttributeKeyStyle = lipgloss.NewStyle().
						Foreground(secondaryColor)

	// AttributeValueStyle for attribute values
	AttributeValueStyle = lipgloss.NewStyle().
						Foreground(lipgloss.Color("#FFFFFF"))
)

Text styles

View Source
var (
	WorkflowSpanStyle = lipgloss.NewStyle().
						Foreground(lipgloss.Color("#8B5CF6")) // Violet

	AgentSpanStyle = lipgloss.NewStyle().
					Foreground(lipgloss.Color("#3B82F6")) // Blue

	LLMSpanStyle = lipgloss.NewStyle().
					Foreground(lipgloss.Color("#10B981")) // Emerald

	ToolSpanStyle = lipgloss.NewStyle().
					Foreground(lipgloss.Color("#F59E0B")) // Amber
)

Span type styles

View Source
var (
	HelpStyle = lipgloss.NewStyle().
				Foreground(mutedColor).
				Padding(0, 1)

	HelpKeyStyle = lipgloss.NewStyle().
					Foreground(secondaryColor).
					Bold(true)
)

Help bar style

View Source
var (
	LeftPaneStyle = lipgloss.NewStyle().
					Border(lipgloss.NormalBorder(), false, true, false, false).
					BorderForeground(mutedColor).
					Padding(0, 1)

	RightPaneStyle = lipgloss.NewStyle().
					Padding(0, 1)
)

Pane styles for split layout

Functions

func GetSpanStyle

func GetSpanStyle(spanName string) lipgloss.Style

GetSpanStyle returns the appropriate style based on span name

Types

type DetailTab added in v0.2.2

type DetailTab int

DetailTab represents the active tab in the details panel

const (
	TabOverview DetailTab = iota
	TabPrompt
	TabResponse
	TabAttributes
	TabTiming
)

type FocusArea added in v0.2.2

type FocusArea int

FocusArea represents which panel is currently focused

const (
	FocusTree FocusArea = iota
	FocusDetails
	FocusMetadata
)

type MetricsCalculator

type MetricsCalculator struct {
	TotalTokens int
	ErrorCount  int
	Slowest     *SpanNode
	Top3        []*SpanNode
}

func (*MetricsCalculator) ProcessNode

func (mc *MetricsCalculator) ProcessNode(node *SpanNode)

type Model

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

Model is the main bubbletea model for the trace viewer

func NewTraceExplorer

func NewTraceExplorer(runs []RunData) Model

NewTraceExplorer creates a trace explorer with multiple runs (for `agk trace` command)

func NewTraceViewer

func NewTraceViewer(runID string, manifest TraceRun, spans []Span) Model

NewTraceViewer creates a new trace viewer model

func NewTraceViewerWithPath

func NewTraceViewerWithPath(runID string, manifest TraceRun, spans []Span, tracePath string) Model

NewTraceViewerWithPath creates a trace viewer with hot reload support

func (Model) Height

func (m Model) Height(h int) Model

Height returns a copy with updated height

func (Model) Init

func (m Model) Init() tea.Cmd

Init initializes the model

func (Model) Update

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update handles messages

func (Model) View

func (m Model) View() string

View renders the model

func (Model) Width

func (m Model) Width(w int) Model

Width returns a copy with updated width

type ParentSpan

type ParentSpan struct {
	TraceID string `json:"TraceID"`
	SpanID  string `json:"SpanID"`
}

ParentSpan contains parent span reference

type RunData

type RunData struct {
	Manifest TraceRun
	Spans    []Span
}

RunData contains a run with its parsed spans

type Span

type Span struct {
	Name                 string                   `json:"Name"`
	StartTime            string                   `json:"StartTime"`
	EndTime              string                   `json:"EndTime"`
	Attributes           []map[string]interface{} `json:"Attributes,omitempty"`
	SpanContext          SpanContext              `json:"SpanContext"`
	Parent               ParentSpan               `json:"Parent"`
	SpanKind             int                      `json:"SpanKind"`
	Status               SpanStatus               `json:"Status"`
	ChildSpanCount       int                      `json:"ChildSpanCount"`
	InstrumentationScope map[string]interface{}   `json:"InstrumentationScope"`
}

Span represents a parsed OpenTelemetry span

func ParseSpans

func ParseSpans(data string) []Span

ParseSpans parses JSONL trace data into spans

func (*Span) GetAllAttributes

func (s *Span) GetAllAttributes() map[string]interface{}

GetAllAttributes returns all attributes as key-value pairs

func (*Span) GetAttribute

func (s *Span) GetAttribute(key string) (interface{}, bool)

GetAttribute gets an attribute value by key

func (*Span) GetFriendlyName

func (s *Span) GetFriendlyName() string

GetFriendlyName returns a user-friendly display name for the span

func (*Span) GetImportantAttributes

func (s *Span) GetImportantAttributes() map[string]interface{}

GetImportantAttributes returns filtered important attributes

func (*Span) GetSpanType

func (s *Span) GetSpanType() string

GetSpanType returns the type of span for styling

func (*Span) IsInternalSpan

func (s *Span) IsInternalSpan() bool

IsInternalSpan returns true if this span should be hidden by default (detail level)

func (*Span) IsWorkflowStep

func (s *Span) IsWorkflowStep() bool

IsWorkflowStep returns true if this span represents a workflow step

type SpanContext

type SpanContext struct {
	TraceID string `json:"TraceID"`
	SpanID  string `json:"SpanID"`
}

SpanContext contains span identification

type SpanNode

type SpanNode struct {
	Span       Span
	Children   []*SpanNode
	Depth      int
	Expanded   bool
	Parent     *SpanNode
	DurationMs int64
}

SpanNode represents a span in the hierarchical tree

func BuildSpanTree

func BuildSpanTree(spans []Span) []*SpanNode

BuildSpanTree builds a hierarchical tree from flat span list

func FlattenTree

func FlattenTree(roots []*SpanNode) []*SpanNode

FlattenTree returns a flat list of visible nodes for display

func (*SpanNode) HasChildren

func (n *SpanNode) HasChildren() bool

HasChildren returns true if the span has children

func (*SpanNode) ToggleExpanded

func (n *SpanNode) ToggleExpanded()

ToggleExpanded toggles the expanded state

type SpanStatus

type SpanStatus struct {
	Code        string `json:"Code"`
	Description string `json:"Description,omitempty"`
}

SpanStatus contains span status

type TraceRun

type TraceRun struct {
	RunID         string
	Command       string
	Status        string
	Duration      float64
	SpanCount     int
	LLMCalls      int
	TotalTokens   int
	EstimatedCost float64
}

TraceRun contains trace run metadata

type ViewMode

type ViewMode int

ViewMode represents the current viewing mode

const (
	RunListView ViewMode = iota
	TreeView
	DetailView
)

Jump to

Keyboard shortcuts

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