tui

package
v1.5.3 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: 14 Imported by: 0

Documentation

Overview

Package tui provides a terminal user interface for PromptArena execution monitoring. It implements a multi-pane display showing active runs, metrics, and logs in real-time.

The model renders the live 3-pane run view (runs / logs / result). Page navigation (conversation drill-down, file browsing) is owned by the hub shell (tui/app): the model exposes the run the user selected via TakeSelectedRun so the hub can push a conversation page onto its stack.

Index

Constants

View Source
const (
	MinTerminalWidth  = 80
	MinTerminalHeight = 24
)

Terminal size requirements

Variables

This section is empty.

Functions

func CheckTerminalSize

func CheckTerminalSize() (width, height int, supported bool, reason string)

CheckTerminalSize checks if the terminal is large enough for TUI mode

func RenderSummary

func RenderSummary(summary *Summary, width int) string

RenderSummary renders the final summary screen for TUI mode

func RenderSummaryCIMode

func RenderSummaryCIMode(summary *Summary) string

RenderSummaryCIMode renders the summary in plain text for CI/non-TUI environments

func Run

func Run(ctx context.Context, model *Model) error

Run starts the TUI application

Types

type AudioLevelMsg added in v1.4.7

type AudioLevelMsg struct {
	UserLevel  float32
	AgentLevel float32
}

AudioLevelMsg carries normalized RMS levels (0.0–1.0) for the level meter.

type ConversationStartedMsg added in v1.1.5

type ConversationStartedMsg struct {
	ConversationID string
	SystemPrompt   string
	Time           time.Time
}

ConversationStartedMsg is sent when a new conversation starts with its system prompt.

type ErrorInfo

type ErrorInfo struct {
	RunID    string
	Scenario string
	Provider string
	Region   string
	Error    string
}

ErrorInfo represents a failed run with details

type EventAdapter added in v1.1.4

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

EventAdapter converts runtime events to bubbletea messages.

func NewEventAdapter added in v1.1.4

func NewEventAdapter(send func(tea.Msg)) *EventAdapter

NewEventAdapter creates an adapter that forwards events via send. A *tea.Program's Send method satisfies func(tea.Msg), so callers pass program.Send to drive a running TUI program.

func NewEventAdapterWithModel added in v1.1.4

func NewEventAdapterWithModel(model *Model) *EventAdapter

NewEventAdapterWithModel creates an adapter for headless mode.

func (*EventAdapter) AttachAudioMonitor added in v1.4.7

func (a *EventAdapter) AttachAudioMonitor(monitor *arenaaudio.Monitor)

AttachAudioMonitor subscribes the TUI adapter to the process-wide audio Monitor's RMS stream. Frames originate from the LocalSink as it consumes samples, so the meter reflects whatever the user is actually hearing — regardless of which run is currently routed to playback.

func (*EventAdapter) HandleEvent added in v1.1.4

func (a *EventAdapter) HandleEvent(event *events.Event)

HandleEvent converts runtime events into TUI messages.

func (*EventAdapter) Subscribe added in v1.1.4

func (a *EventAdapter) Subscribe(bus events.Bus)

Subscribe subscribes the adapter to an event bus.

type LogEntry

type LogEntry struct {
	Timestamp time.Time
	Level     string
	Message   string
}

LogEntry represents a single log line

type MessageCreatedMsg added in v1.1.5

type MessageCreatedMsg struct {
	ConversationID string
	Role           string
	Content        string
	Index          int
	ToolCalls      []MessageToolCall  // Tool calls requested by assistant
	ToolResult     *MessageToolResult // Tool result for tool messages
	Time           time.Time
}

MessageCreatedMsg is sent when a message is created during execution.

type MessageToolCall added in v1.1.5

type MessageToolCall = events.MessageToolCall

MessageToolCall is a type alias for events.MessageToolCall to avoid duplicate definitions.

type MessageToolResult added in v1.1.5

type MessageToolResult = events.MessageToolResult

MessageToolResult is a type alias for events.MessageToolResult to avoid duplicate definitions.

type MessageUpdatedMsg added in v1.1.5

type MessageUpdatedMsg struct {
	ConversationID string
	Index          int
	LatencyMs      int64
	InputTokens    int
	OutputTokens   int
	TotalCost      float64
	Time           time.Time
}

MessageUpdatedMsg is sent when a message is updated with cost/latency info.

type Model

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

Model represents the bubbletea application state for the live run view.

func NewModel

func NewModel(configFile string, totalRuns int) *Model

NewModel creates a new TUI model with the specified configuration file and total run count.

func (*Model) ActiveRuns added in v1.1.4

func (m *Model) ActiveRuns() []RunInfo

ActiveRuns returns a snapshot of active runs for inspection or testing. Safe for concurrent use.

func (*Model) BuildSummary

func (m *Model) BuildSummary(outputDir, htmlReport string) *Summary

BuildSummary creates a Summary from the current model state with output directory and HTML report path. Thread-safe for external callers.

func (*Model) CompletedCount added in v1.1.4

func (m *Model) CompletedCount() int

CompletedCount returns the number of completed runs (success + failure). Safe for concurrent use.

func (*Model) EnableTUIMode added in v1.5.3

func (m *Model) EnableTUIMode()

EnableTUIMode forces the model to render its interactive view regardless of the standalone terminal-size probe. The hub shell (tui/app) owns terminal detection and the bubbletea program, so a model wrapped by a hub Page should always render; the isTUIMode gate only applies to the standalone Run path.

func (*Model) Init

func (m *Model) Init() tea.Cmd

Init initializes the bubbletea model

func (*Model) Logs added in v1.1.4

func (m *Model) Logs() []LogEntry

Logs returns a snapshot of the current log entries. Safe for concurrent use.

func (*Model) SetAudioMonitor added in v1.4.7

func (m *Model) SetAudioMonitor(monitor audioMonitor)

SetAudioMonitor attaches an audio monitor so the TUI can re-route host playback when the user navigates between concurrent runs. Nil-safe. Retained pending hub audio re-wire — see AltairaLabs/PromptKit#1460.

func (*Model) SetStateStore added in v1.1.4

func (m *Model) SetStateStore(store runResultStorer)

SetStateStore attaches a state store for building summaries from run results.

func (*Model) TakeSelectedRun added in v1.5.3

func (m *Model) TakeSelectedRun() (RunInfo, bool)

TakeSelectedRun returns the run the user last selected for drill-down (Enter on the runs pane), clearing the pending selection. The bool reports whether a selection was pending. Safe for concurrent use.

func (*Model) Update

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

Update processes bubbletea messages and updates the model state

func (*Model) View

func (m *Model) View() string

View renders the live 3-pane run view.

type RunCompletedMsg

type RunCompletedMsg struct {
	RunID    string
	Duration time.Duration
	Cost     float64
	Time     time.Time
}

RunCompletedMsg is sent when a run completes successfully.

type RunFailedMsg

type RunFailedMsg struct {
	RunID string
	Error error
	Time  time.Time
}

RunFailedMsg is sent when a run fails with an error.

type RunInfo

type RunInfo struct {
	RunID            string
	Scenario         string
	Provider         string
	Region           string
	Status           RunStatus
	Duration         time.Duration
	Cost             float64
	Error            string
	StartTime        time.Time
	CurrentTurnIndex int
	CurrentTurnRole  string
	Selected         bool
}

RunInfo tracks information about a single run

type RunStartedMsg

type RunStartedMsg struct {
	RunID    string
	Scenario string
	Provider string
	Region   string
	Time     time.Time
}

RunStartedMsg is sent when a run begins execution.

type RunStatus

type RunStatus int

RunStatus represents the current state of a run

const (
	// StatusRunning indicates the run is currently executing
	StatusRunning RunStatus = iota
	// StatusCompleted indicates the run completed successfully
	StatusCompleted
	// StatusFailed indicates the run failed with an error
	StatusFailed
)

type Summary

type Summary struct {
	TotalRuns      int
	SuccessCount   int
	FailedCount    int
	TotalCost      float64
	TotalTokens    int64
	TotalDuration  time.Duration
	AvgDuration    time.Duration
	ProviderCounts map[string]int
	ScenarioCount  int
	Regions        []string
	Errors         []ErrorInfo
	OutputDir      string
	HTMLReport     string

	AssertionTotal  int
	AssertionFailed int
}

Summary represents the final execution summary displayed after all runs complete

type TurnCompletedMsg added in v1.1.4

type TurnCompletedMsg struct {
	RunID     string
	TurnIndex int
	Role      string
	Scenario  string
	Error     error
	Time      time.Time
}

TurnCompletedMsg is sent when a turn completes.

type TurnStartedMsg added in v1.1.4

type TurnStartedMsg struct {
	RunID     string
	TurnIndex int
	Role      string
	Scenario  string
	Time      time.Time
}

TurnStartedMsg is sent when a turn starts.

Directories

Path Synopsis
Package app is declared in page.go; this file adds the App root model.
Package app is declared in page.go; this file adds the App root model.
Package layout provides a pure-geometry layout engine for the Arena TUI.
Package layout provides a pure-geometry layout engine for the Arena TUI.
Package logging provides log interception functionality for the TUI.
Package logging provides log interception functionality for the TUI.
Package pages provides top-level page components for the TUI.
Package pages provides top-level page components for the TUI.
Package panels provides reusable panel components for the TUI.
Package panels provides reusable panel components for the TUI.
Package theme provides centralized styling, colors, and formatting for the TUI.
Package theme provides centralized styling, colors, and formatting for the TUI.
Package viewmodels provides data transformation and presentation logic for TUI views.
Package viewmodels provides data transformation and presentation logic for TUI views.
Package views provides pure rendering components for TUI views.
Package views provides pure rendering components for TUI views.

Jump to

Keyboard shortcuts

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